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) || defined (MAC_OS) \
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 };
856 /* Function prototypes. */
858 static void setup_for_ellipsis
P_ ((struct it
*, int));
859 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
860 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
861 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
862 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
863 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
864 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
866 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
868 static void handle_line_prefix
P_ ((struct it
*));
871 static int invisible_text_between_p
P_ ((struct it
*, int, int));
874 static void pint2str
P_ ((char *, int, int));
875 static void pint2hrstr
P_ ((char *, int, int));
876 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
878 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
879 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
880 static void store_mode_line_noprop_char
P_ ((char));
881 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
882 static void x_consider_frame_title
P_ ((Lisp_Object
));
883 static void handle_stop
P_ ((struct it
*));
884 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
885 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
886 static void ensure_echo_area_buffers
P_ ((void));
887 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
888 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
889 static int with_echo_area_buffer
P_ ((struct window
*, int,
890 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
891 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
892 static void clear_garbaged_frames
P_ ((void));
893 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
894 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
895 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
896 static int display_echo_area
P_ ((struct window
*));
897 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
898 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
899 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
900 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
901 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
903 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
904 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
905 static void insert_left_trunc_glyphs
P_ ((struct it
*));
906 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
908 static void extend_face_to_end_of_line
P_ ((struct it
*));
909 static int append_space_for_newline
P_ ((struct it
*, int));
910 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
911 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
912 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
913 static int trailing_whitespace_p
P_ ((int));
914 static int message_log_check_duplicate
P_ ((int, int, int, int));
915 static void push_it
P_ ((struct it
*));
916 static void pop_it
P_ ((struct it
*));
917 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
918 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
919 static void redisplay_internal
P_ ((int));
920 static int echo_area_display
P_ ((int));
921 static void redisplay_windows
P_ ((Lisp_Object
));
922 static void redisplay_window
P_ ((Lisp_Object
, int));
923 static Lisp_Object
redisplay_window_error ();
924 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
925 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
926 static int update_menu_bar
P_ ((struct frame
*, int, int));
927 static int try_window_reusing_current_matrix
P_ ((struct window
*));
928 static int try_window_id
P_ ((struct window
*));
929 static int display_line
P_ ((struct it
*));
930 static int display_mode_lines
P_ ((struct window
*));
931 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
932 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
933 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
934 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
935 static void display_menu_bar
P_ ((struct window
*));
936 static int display_count_lines
P_ ((int, int, int, int, int *));
937 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
938 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
939 static void compute_line_metrics
P_ ((struct it
*));
940 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
941 static int get_overlay_strings
P_ ((struct it
*, int));
942 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
943 static void next_overlay_string
P_ ((struct it
*));
944 static void reseat
P_ ((struct it
*, struct text_pos
, int));
945 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
946 static void back_to_previous_visible_line_start
P_ ((struct it
*));
947 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
948 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
949 static int next_element_from_ellipsis
P_ ((struct it
*));
950 static int next_element_from_display_vector
P_ ((struct it
*));
951 static int next_element_from_string
P_ ((struct it
*));
952 static int next_element_from_c_string
P_ ((struct it
*));
953 static int next_element_from_buffer
P_ ((struct it
*));
954 static int next_element_from_composition
P_ ((struct it
*));
955 static int next_element_from_image
P_ ((struct it
*));
956 static int next_element_from_stretch
P_ ((struct it
*));
957 static void load_overlay_strings
P_ ((struct it
*, int));
958 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
959 struct display_pos
*));
960 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
961 Lisp_Object
, int, int, int, int));
962 static enum move_it_result
963 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
964 enum move_operation_enum
);
965 void move_it_vertically_backward
P_ ((struct it
*, int));
966 static void init_to_row_start
P_ ((struct it
*, struct window
*,
967 struct glyph_row
*));
968 static int init_to_row_end
P_ ((struct it
*, struct window
*,
969 struct glyph_row
*));
970 static void back_to_previous_line_start
P_ ((struct it
*));
971 static int forward_to_next_line_start
P_ ((struct it
*, int *));
972 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
974 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
975 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
976 static int number_of_chars
P_ ((unsigned char *, int));
977 static void compute_stop_pos
P_ ((struct it
*));
978 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
980 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
981 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
982 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
983 Lisp_Object
, Lisp_Object
,
984 struct text_pos
*, int));
985 static int underlying_face_id
P_ ((struct it
*));
986 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
989 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
990 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
992 #ifdef HAVE_WINDOW_SYSTEM
994 static void update_tool_bar
P_ ((struct frame
*, int));
995 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
996 static int redisplay_tool_bar
P_ ((struct frame
*));
997 static void display_tool_bar_line
P_ ((struct it
*, int));
998 static void notice_overwritten_cursor
P_ ((struct window
*,
1000 int, int, int, int));
1004 #endif /* HAVE_WINDOW_SYSTEM */
1007 /***********************************************************************
1008 Window display dimensions
1009 ***********************************************************************/
1011 /* Return the bottom boundary y-position for text lines in window W.
1012 This is the first y position at which a line cannot start.
1013 It is relative to the top of the window.
1015 This is the height of W minus the height of a mode line, if any. */
1018 window_text_bottom_y (w
)
1021 int height
= WINDOW_TOTAL_HEIGHT (w
);
1023 if (WINDOW_WANTS_MODELINE_P (w
))
1024 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1028 /* Return the pixel width of display area AREA of window W. AREA < 0
1029 means return the total width of W, not including fringes to
1030 the left and right of the window. */
1033 window_box_width (w
, area
)
1037 int cols
= XFASTINT (w
->total_cols
);
1040 if (!w
->pseudo_window_p
)
1042 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1044 if (area
== TEXT_AREA
)
1046 if (INTEGERP (w
->left_margin_cols
))
1047 cols
-= XFASTINT (w
->left_margin_cols
);
1048 if (INTEGERP (w
->right_margin_cols
))
1049 cols
-= XFASTINT (w
->right_margin_cols
);
1050 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1052 else if (area
== LEFT_MARGIN_AREA
)
1054 cols
= (INTEGERP (w
->left_margin_cols
)
1055 ? XFASTINT (w
->left_margin_cols
) : 0);
1058 else if (area
== RIGHT_MARGIN_AREA
)
1060 cols
= (INTEGERP (w
->right_margin_cols
)
1061 ? XFASTINT (w
->right_margin_cols
) : 0);
1066 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1070 /* Return the pixel height of the display area of window W, not
1071 including mode lines of W, if any. */
1074 window_box_height (w
)
1077 struct frame
*f
= XFRAME (w
->frame
);
1078 int height
= WINDOW_TOTAL_HEIGHT (w
);
1080 xassert (height
>= 0);
1082 /* Note: the code below that determines the mode-line/header-line
1083 height is essentially the same as that contained in the macro
1084 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1085 the appropriate glyph row has its `mode_line_p' flag set,
1086 and if it doesn't, uses estimate_mode_line_height instead. */
1088 if (WINDOW_WANTS_MODELINE_P (w
))
1090 struct glyph_row
*ml_row
1091 = (w
->current_matrix
&& w
->current_matrix
->rows
1092 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1094 if (ml_row
&& ml_row
->mode_line_p
)
1095 height
-= ml_row
->height
;
1097 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1100 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1102 struct glyph_row
*hl_row
1103 = (w
->current_matrix
&& w
->current_matrix
->rows
1104 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1106 if (hl_row
&& hl_row
->mode_line_p
)
1107 height
-= hl_row
->height
;
1109 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1112 /* With a very small font and a mode-line that's taller than
1113 default, we might end up with a negative height. */
1114 return max (0, height
);
1117 /* Return the window-relative coordinate of the left edge of display
1118 area AREA of window W. AREA < 0 means return the left edge of the
1119 whole window, to the right of the left fringe of W. */
1122 window_box_left_offset (w
, area
)
1128 if (w
->pseudo_window_p
)
1131 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1133 if (area
== TEXT_AREA
)
1134 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1135 + window_box_width (w
, LEFT_MARGIN_AREA
));
1136 else if (area
== RIGHT_MARGIN_AREA
)
1137 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1138 + window_box_width (w
, LEFT_MARGIN_AREA
)
1139 + window_box_width (w
, TEXT_AREA
)
1140 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1142 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1143 else if (area
== LEFT_MARGIN_AREA
1144 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1145 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1151 /* Return the window-relative coordinate of the right edge of display
1152 area AREA of window W. AREA < 0 means return the left edge of the
1153 whole window, to the left of the right fringe of W. */
1156 window_box_right_offset (w
, area
)
1160 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1163 /* Return the frame-relative coordinate of the left edge of display
1164 area AREA of window W. AREA < 0 means return the left edge of the
1165 whole window, to the right of the left fringe of W. */
1168 window_box_left (w
, area
)
1172 struct frame
*f
= XFRAME (w
->frame
);
1175 if (w
->pseudo_window_p
)
1176 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1178 x
= (WINDOW_LEFT_EDGE_X (w
)
1179 + window_box_left_offset (w
, area
));
1185 /* Return the frame-relative coordinate of the right edge of display
1186 area AREA of window W. AREA < 0 means return the left edge of the
1187 whole window, to the left of the right fringe of W. */
1190 window_box_right (w
, area
)
1194 return window_box_left (w
, area
) + window_box_width (w
, area
);
1197 /* Get the bounding box of the display area AREA of window W, without
1198 mode lines, in frame-relative coordinates. AREA < 0 means the
1199 whole window, not including the left and right fringes of
1200 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1201 coordinates of the upper-left corner of the box. Return in
1202 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1205 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1208 int *box_x
, *box_y
, *box_width
, *box_height
;
1211 *box_width
= window_box_width (w
, area
);
1213 *box_height
= window_box_height (w
);
1215 *box_x
= window_box_left (w
, area
);
1218 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1219 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1220 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1225 /* Get the bounding box of the display area AREA of window W, without
1226 mode lines. AREA < 0 means the whole window, not including the
1227 left and right fringe of the window. Return in *TOP_LEFT_X
1228 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1229 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1230 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1234 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1235 bottom_right_x
, bottom_right_y
)
1238 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1240 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1242 *bottom_right_x
+= *top_left_x
;
1243 *bottom_right_y
+= *top_left_y
;
1248 /***********************************************************************
1250 ***********************************************************************/
1252 /* Return the bottom y-position of the line the iterator IT is in.
1253 This can modify IT's settings. */
1259 int line_height
= it
->max_ascent
+ it
->max_descent
;
1260 int line_top_y
= it
->current_y
;
1262 if (line_height
== 0)
1265 line_height
= last_height
;
1266 else if (IT_CHARPOS (*it
) < ZV
)
1268 move_it_by_lines (it
, 1, 1);
1269 line_height
= (it
->max_ascent
|| it
->max_descent
1270 ? it
->max_ascent
+ it
->max_descent
1275 struct glyph_row
*row
= it
->glyph_row
;
1277 /* Use the default character height. */
1278 it
->glyph_row
= NULL
;
1279 it
->what
= IT_CHARACTER
;
1282 PRODUCE_GLYPHS (it
);
1283 line_height
= it
->ascent
+ it
->descent
;
1284 it
->glyph_row
= row
;
1288 return line_top_y
+ line_height
;
1292 /* Return 1 if position CHARPOS is visible in window W.
1293 CHARPOS < 0 means return info about WINDOW_END position.
1294 If visible, set *X and *Y to pixel coordinates of top left corner.
1295 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1296 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1299 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1301 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1304 struct text_pos top
;
1306 struct buffer
*old_buffer
= NULL
;
1311 if (XBUFFER (w
->buffer
) != current_buffer
)
1313 old_buffer
= current_buffer
;
1314 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1317 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1319 /* Compute exact mode line heights. */
1320 if (WINDOW_WANTS_MODELINE_P (w
))
1321 current_mode_line_height
1322 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1323 current_buffer
->mode_line_format
);
1325 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1326 current_header_line_height
1327 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1328 current_buffer
->header_line_format
);
1330 start_display (&it
, w
, top
);
1331 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1332 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1334 /* Note that we may overshoot because of invisible text. */
1335 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1337 int top_x
= it
.current_x
;
1338 int top_y
= it
.current_y
;
1339 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1340 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1342 if (top_y
< window_top_y
)
1343 visible_p
= bottom_y
> window_top_y
;
1344 else if (top_y
< it
.last_visible_y
)
1348 if (it
.method
== GET_FROM_BUFFER
)
1350 Lisp_Object window
, prop
;
1352 XSETWINDOW (window
, w
);
1353 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1354 Qinvisible
, window
);
1356 /* If charpos coincides with invisible text covered with an
1357 ellipsis, use the first glyph of the ellipsis to compute
1358 the pixel positions. */
1359 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1361 struct glyph_row
*row
= it
.glyph_row
;
1362 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1363 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1366 for (; glyph
< end
&& glyph
->charpos
< charpos
; glyph
++)
1367 x
+= glyph
->pixel_width
;
1374 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1375 *rtop
= max (0, window_top_y
- top_y
);
1376 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1377 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1378 - max (top_y
, window_top_y
)));
1387 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1388 move_it_by_lines (&it
, 1, 0);
1389 if (charpos
< IT_CHARPOS (it
)
1390 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1393 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1395 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1396 *rtop
= max (0, -it2
.current_y
);
1397 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1398 - it
.last_visible_y
));
1399 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1401 - max (it2
.current_y
,
1402 WINDOW_HEADER_LINE_HEIGHT (w
))));
1408 set_buffer_internal_1 (old_buffer
);
1410 current_header_line_height
= current_mode_line_height
= -1;
1412 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1413 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1416 /* Debugging code. */
1418 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1419 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1421 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1428 /* Return the next character from STR which is MAXLEN bytes long.
1429 Return in *LEN the length of the character. This is like
1430 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1431 we find one, we return a `?', but with the length of the invalid
1435 string_char_and_length (str
, maxlen
, len
)
1436 const unsigned char *str
;
1441 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1442 if (!CHAR_VALID_P (c
, 1))
1443 /* We may not change the length here because other places in Emacs
1444 don't use this function, i.e. they silently accept invalid
1453 /* Given a position POS containing a valid character and byte position
1454 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1456 static struct text_pos
1457 string_pos_nchars_ahead (pos
, string
, nchars
)
1458 struct text_pos pos
;
1462 xassert (STRINGP (string
) && nchars
>= 0);
1464 if (STRING_MULTIBYTE (string
))
1466 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1467 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1472 string_char_and_length (p
, rest
, &len
);
1473 p
+= len
, rest
-= len
;
1474 xassert (rest
>= 0);
1476 BYTEPOS (pos
) += len
;
1480 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1486 /* Value is the text position, i.e. character and byte position,
1487 for character position CHARPOS in STRING. */
1489 static INLINE
struct text_pos
1490 string_pos (charpos
, string
)
1494 struct text_pos pos
;
1495 xassert (STRINGP (string
));
1496 xassert (charpos
>= 0);
1497 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1502 /* Value is a text position, i.e. character and byte position, for
1503 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1504 means recognize multibyte characters. */
1506 static struct text_pos
1507 c_string_pos (charpos
, s
, multibyte_p
)
1512 struct text_pos pos
;
1514 xassert (s
!= NULL
);
1515 xassert (charpos
>= 0);
1519 int rest
= strlen (s
), len
;
1521 SET_TEXT_POS (pos
, 0, 0);
1524 string_char_and_length (s
, rest
, &len
);
1525 s
+= len
, rest
-= len
;
1526 xassert (rest
>= 0);
1528 BYTEPOS (pos
) += len
;
1532 SET_TEXT_POS (pos
, charpos
, charpos
);
1538 /* Value is the number of characters in C string S. MULTIBYTE_P
1539 non-zero means recognize multibyte characters. */
1542 number_of_chars (s
, multibyte_p
)
1550 int rest
= strlen (s
), len
;
1551 unsigned char *p
= (unsigned char *) s
;
1553 for (nchars
= 0; rest
> 0; ++nchars
)
1555 string_char_and_length (p
, rest
, &len
);
1556 rest
-= len
, p
+= len
;
1560 nchars
= strlen (s
);
1566 /* Compute byte position NEWPOS->bytepos corresponding to
1567 NEWPOS->charpos. POS is a known position in string STRING.
1568 NEWPOS->charpos must be >= POS.charpos. */
1571 compute_string_pos (newpos
, pos
, string
)
1572 struct text_pos
*newpos
, pos
;
1575 xassert (STRINGP (string
));
1576 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1578 if (STRING_MULTIBYTE (string
))
1579 *newpos
= string_pos_nchars_ahead (pos
, string
,
1580 CHARPOS (*newpos
) - CHARPOS (pos
));
1582 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1586 Return an estimation of the pixel height of mode or top lines on
1587 frame F. FACE_ID specifies what line's height to estimate. */
1590 estimate_mode_line_height (f
, face_id
)
1592 enum face_id face_id
;
1594 #ifdef HAVE_WINDOW_SYSTEM
1595 if (FRAME_WINDOW_P (f
))
1597 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1599 /* This function is called so early when Emacs starts that the face
1600 cache and mode line face are not yet initialized. */
1601 if (FRAME_FACE_CACHE (f
))
1603 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1607 height
= FONT_HEIGHT (face
->font
);
1608 if (face
->box_line_width
> 0)
1609 height
+= 2 * face
->box_line_width
;
1620 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1621 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1622 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1623 not force the value into range. */
1626 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1628 register int pix_x
, pix_y
;
1630 NativeRectangle
*bounds
;
1634 #ifdef HAVE_WINDOW_SYSTEM
1635 if (FRAME_WINDOW_P (f
))
1637 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1638 even for negative values. */
1640 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1642 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1644 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1645 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1648 STORE_NATIVE_RECT (*bounds
,
1649 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1650 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1651 FRAME_COLUMN_WIDTH (f
) - 1,
1652 FRAME_LINE_HEIGHT (f
) - 1);
1658 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1659 pix_x
= FRAME_TOTAL_COLS (f
);
1663 else if (pix_y
> FRAME_LINES (f
))
1664 pix_y
= FRAME_LINES (f
);
1674 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1675 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1676 can't tell the positions because W's display is not up to date,
1680 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1683 int *frame_x
, *frame_y
;
1685 #ifdef HAVE_WINDOW_SYSTEM
1686 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1690 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1691 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1693 if (display_completed
)
1695 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1696 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1697 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1703 hpos
+= glyph
->pixel_width
;
1707 /* If first glyph is partially visible, its first visible position is still 0. */
1719 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1720 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1731 #ifdef HAVE_WINDOW_SYSTEM
1733 /* Find the glyph under window-relative coordinates X/Y in window W.
1734 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1735 strings. Return in *HPOS and *VPOS the row and column number of
1736 the glyph found. Return in *AREA the glyph area containing X.
1737 Value is a pointer to the glyph found or null if X/Y is not on
1738 text, or we can't tell because W's current matrix is not up to
1745 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1748 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1750 struct glyph
*glyph
, *end
;
1751 struct glyph_row
*row
= NULL
;
1754 /* Find row containing Y. Give up if some row is not enabled. */
1755 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1757 row
= MATRIX_ROW (w
->current_matrix
, i
);
1758 if (!row
->enabled_p
)
1760 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1767 /* Give up if Y is not in the window. */
1768 if (i
== w
->current_matrix
->nrows
)
1771 /* Get the glyph area containing X. */
1772 if (w
->pseudo_window_p
)
1779 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1781 *area
= LEFT_MARGIN_AREA
;
1782 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1784 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1787 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1791 *area
= RIGHT_MARGIN_AREA
;
1792 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1796 /* Find glyph containing X. */
1797 glyph
= row
->glyphs
[*area
];
1798 end
= glyph
+ row
->used
[*area
];
1800 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1802 x
-= glyph
->pixel_width
;
1812 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1815 *hpos
= glyph
- row
->glyphs
[*area
];
1821 Convert frame-relative x/y to coordinates relative to window W.
1822 Takes pseudo-windows into account. */
1825 frame_to_window_pixel_xy (w
, x
, y
)
1829 if (w
->pseudo_window_p
)
1831 /* A pseudo-window is always full-width, and starts at the
1832 left edge of the frame, plus a frame border. */
1833 struct frame
*f
= XFRAME (w
->frame
);
1834 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1835 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1839 *x
-= WINDOW_LEFT_EDGE_X (w
);
1840 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1845 Return in RECTS[] at most N clipping rectangles for glyph string S.
1846 Return the number of stored rectangles. */
1849 get_glyph_string_clip_rects (s
, rects
, n
)
1850 struct glyph_string
*s
;
1851 NativeRectangle
*rects
;
1859 if (s
->row
->full_width_p
)
1861 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1862 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1863 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1865 /* Unless displaying a mode or menu bar line, which are always
1866 fully visible, clip to the visible part of the row. */
1867 if (s
->w
->pseudo_window_p
)
1868 r
.height
= s
->row
->visible_height
;
1870 r
.height
= s
->height
;
1874 /* This is a text line that may be partially visible. */
1875 r
.x
= window_box_left (s
->w
, s
->area
);
1876 r
.width
= window_box_width (s
->w
, s
->area
);
1877 r
.height
= s
->row
->visible_height
;
1881 if (r
.x
< s
->clip_head
->x
)
1883 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1884 r
.width
-= s
->clip_head
->x
- r
.x
;
1887 r
.x
= s
->clip_head
->x
;
1890 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1892 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1893 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1898 /* If S draws overlapping rows, it's sufficient to use the top and
1899 bottom of the window for clipping because this glyph string
1900 intentionally draws over other lines. */
1901 if (s
->for_overlaps
)
1903 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1904 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1906 /* Alas, the above simple strategy does not work for the
1907 environments with anti-aliased text: if the same text is
1908 drawn onto the same place multiple times, it gets thicker.
1909 If the overlap we are processing is for the erased cursor, we
1910 take the intersection with the rectagle of the cursor. */
1911 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1913 XRectangle rc
, r_save
= r
;
1915 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1916 rc
.y
= s
->w
->phys_cursor
.y
;
1917 rc
.width
= s
->w
->phys_cursor_width
;
1918 rc
.height
= s
->w
->phys_cursor_height
;
1920 x_intersect_rectangles (&r_save
, &rc
, &r
);
1925 /* Don't use S->y for clipping because it doesn't take partially
1926 visible lines into account. For example, it can be negative for
1927 partially visible lines at the top of a window. */
1928 if (!s
->row
->full_width_p
1929 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1930 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1932 r
.y
= max (0, s
->row
->y
);
1934 /* If drawing a tool-bar window, draw it over the internal border
1935 at the top of the window. */
1936 if (WINDOWP (s
->f
->tool_bar_window
)
1937 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1938 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1941 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1943 /* If drawing the cursor, don't let glyph draw outside its
1944 advertised boundaries. Cleartype does this under some circumstances. */
1945 if (s
->hl
== DRAW_CURSOR
)
1947 struct glyph
*glyph
= s
->first_glyph
;
1952 r
.width
-= s
->x
- r
.x
;
1955 r
.width
= min (r
.width
, glyph
->pixel_width
);
1957 /* If r.y is below window bottom, ensure that we still see a cursor. */
1958 height
= min (glyph
->ascent
+ glyph
->descent
,
1959 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1960 max_y
= window_text_bottom_y (s
->w
) - height
;
1961 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1962 if (s
->ybase
- glyph
->ascent
> max_y
)
1969 /* Don't draw cursor glyph taller than our actual glyph. */
1970 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1971 if (height
< r
.height
)
1973 max_y
= r
.y
+ r
.height
;
1974 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1975 r
.height
= min (max_y
- r
.y
, height
);
1982 XRectangle r_save
= r
;
1984 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1988 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1989 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1991 #ifdef CONVERT_FROM_XRECT
1992 CONVERT_FROM_XRECT (r
, *rects
);
2000 /* If we are processing overlapping and allowed to return
2001 multiple clipping rectangles, we exclude the row of the glyph
2002 string from the clipping rectangle. This is to avoid drawing
2003 the same text on the environment with anti-aliasing. */
2004 #ifdef CONVERT_FROM_XRECT
2007 XRectangle
*rs
= rects
;
2009 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2011 if (s
->for_overlaps
& OVERLAPS_PRED
)
2014 if (r
.y
+ r
.height
> row_y
)
2017 rs
[i
].height
= row_y
- r
.y
;
2023 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2026 if (r
.y
< row_y
+ s
->row
->visible_height
)
2028 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2030 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2031 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2040 #ifdef CONVERT_FROM_XRECT
2041 for (i
= 0; i
< n
; i
++)
2042 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2049 Return in *NR the clipping rectangle for glyph string S. */
2052 get_glyph_string_clip_rect (s
, nr
)
2053 struct glyph_string
*s
;
2054 NativeRectangle
*nr
;
2056 get_glyph_string_clip_rects (s
, nr
, 1);
2061 Return the position and height of the phys cursor in window W.
2062 Set w->phys_cursor_width to width of phys cursor.
2066 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2068 struct glyph_row
*row
;
2069 struct glyph
*glyph
;
2070 int *xp
, *yp
, *heightp
;
2072 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2073 int x
, y
, wd
, h
, h0
, y0
;
2075 /* Compute the width of the rectangle to draw. If on a stretch
2076 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2077 rectangle as wide as the glyph, but use a canonical character
2079 wd
= glyph
->pixel_width
- 1;
2084 x
= w
->phys_cursor
.x
;
2091 if (glyph
->type
== STRETCH_GLYPH
2092 && !x_stretch_cursor_p
)
2093 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2094 w
->phys_cursor_width
= wd
;
2096 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2098 /* If y is below window bottom, ensure that we still see a cursor. */
2099 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2101 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2102 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2104 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2107 h
= max (h
- (y0
- y
) + 1, h0
);
2112 y0
= window_text_bottom_y (w
) - h0
;
2120 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2121 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2126 * Remember which glyph the mouse is over.
2130 remember_mouse_glyph (f
, gx
, gy
, rect
)
2133 NativeRectangle
*rect
;
2137 struct glyph_row
*r
, *gr
, *end_row
;
2138 enum window_part part
;
2139 enum glyph_row_area area
;
2140 int x
, y
, width
, height
;
2142 /* Try to determine frame pixel position and size of the glyph under
2143 frame pixel coordinates X/Y on frame F. */
2145 if (!f
->glyphs_initialized_p
2146 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2149 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2150 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2154 w
= XWINDOW (window
);
2155 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2156 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2158 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2159 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2161 if (w
->pseudo_window_p
)
2164 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2170 case ON_LEFT_MARGIN
:
2171 area
= LEFT_MARGIN_AREA
;
2174 case ON_RIGHT_MARGIN
:
2175 area
= RIGHT_MARGIN_AREA
;
2178 case ON_HEADER_LINE
:
2180 gr
= (part
== ON_HEADER_LINE
2181 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2182 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2185 goto text_glyph_row_found
;
2192 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2193 if (r
->y
+ r
->height
> y
)
2199 text_glyph_row_found
:
2202 struct glyph
*g
= gr
->glyphs
[area
];
2203 struct glyph
*end
= g
+ gr
->used
[area
];
2205 height
= gr
->height
;
2206 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2207 if (gx
+ g
->pixel_width
> x
)
2212 if (g
->type
== IMAGE_GLYPH
)
2214 /* Don't remember when mouse is over image, as
2215 image may have hot-spots. */
2216 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2219 width
= g
->pixel_width
;
2223 /* Use nominal char spacing at end of line. */
2225 gx
+= (x
/ width
) * width
;
2228 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2229 gx
+= window_box_left_offset (w
, area
);
2233 /* Use nominal line height at end of window. */
2234 gx
= (x
/ width
) * width
;
2236 gy
+= (y
/ height
) * height
;
2240 case ON_LEFT_FRINGE
:
2241 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2242 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2243 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2244 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2247 case ON_RIGHT_FRINGE
:
2248 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2249 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2250 : window_box_right_offset (w
, TEXT_AREA
));
2251 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2255 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2257 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2258 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2259 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2261 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2265 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2266 if (r
->y
+ r
->height
> y
)
2273 height
= gr
->height
;
2276 /* Use nominal line height at end of window. */
2278 gy
+= (y
/ height
) * height
;
2285 /* If there is no glyph under the mouse, then we divide the screen
2286 into a grid of the smallest glyph in the frame, and use that
2289 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2290 round down even for negative values. */
2296 gx
= (gx
/ width
) * width
;
2297 gy
= (gy
/ height
) * height
;
2302 gx
+= WINDOW_LEFT_EDGE_X (w
);
2303 gy
+= WINDOW_TOP_EDGE_Y (w
);
2306 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2308 /* Visible feedback for debugging. */
2311 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2312 f
->output_data
.x
->normal_gc
,
2313 gx
, gy
, width
, height
);
2319 #endif /* HAVE_WINDOW_SYSTEM */
2322 /***********************************************************************
2323 Lisp form evaluation
2324 ***********************************************************************/
2326 /* Error handler for safe_eval and safe_call. */
2329 safe_eval_handler (arg
)
2332 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2337 /* Evaluate SEXPR and return the result, or nil if something went
2338 wrong. Prevent redisplay during the evaluation. */
2340 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2341 Return the result, or nil if something went wrong. Prevent
2342 redisplay during the evaluation. */
2345 safe_call (nargs
, args
)
2351 if (inhibit_eval_during_redisplay
)
2355 int count
= SPECPDL_INDEX ();
2356 struct gcpro gcpro1
;
2359 gcpro1
.nvars
= nargs
;
2360 specbind (Qinhibit_redisplay
, Qt
);
2361 /* Use Qt to ensure debugger does not run,
2362 so there is no possibility of wanting to redisplay. */
2363 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2366 val
= unbind_to (count
, val
);
2373 /* Call function FN with one argument ARG.
2374 Return the result, or nil if something went wrong. */
2377 safe_call1 (fn
, arg
)
2378 Lisp_Object fn
, arg
;
2380 Lisp_Object args
[2];
2383 return safe_call (2, args
);
2386 static Lisp_Object Qeval
;
2389 safe_eval (Lisp_Object sexpr
)
2391 return safe_call1 (Qeval
, sexpr
);
2394 /* Call function FN with one argument ARG.
2395 Return the result, or nil if something went wrong. */
2398 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2400 Lisp_Object args
[3];
2404 return safe_call (3, args
);
2409 /***********************************************************************
2411 ***********************************************************************/
2415 /* Define CHECK_IT to perform sanity checks on iterators.
2416 This is for debugging. It is too slow to do unconditionally. */
2422 if (it
->method
== GET_FROM_STRING
)
2424 xassert (STRINGP (it
->string
));
2425 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2429 xassert (IT_STRING_CHARPOS (*it
) < 0);
2430 if (it
->method
== GET_FROM_BUFFER
)
2432 /* Check that character and byte positions agree. */
2433 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2438 xassert (it
->current
.dpvec_index
>= 0);
2440 xassert (it
->current
.dpvec_index
< 0);
2443 #define CHECK_IT(IT) check_it ((IT))
2447 #define CHECK_IT(IT) (void) 0
2454 /* Check that the window end of window W is what we expect it
2455 to be---the last row in the current matrix displaying text. */
2458 check_window_end (w
)
2461 if (!MINI_WINDOW_P (w
)
2462 && !NILP (w
->window_end_valid
))
2464 struct glyph_row
*row
;
2465 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2466 XFASTINT (w
->window_end_vpos
)),
2468 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2469 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2473 #define CHECK_WINDOW_END(W) check_window_end ((W))
2475 #else /* not GLYPH_DEBUG */
2477 #define CHECK_WINDOW_END(W) (void) 0
2479 #endif /* not GLYPH_DEBUG */
2483 /***********************************************************************
2484 Iterator initialization
2485 ***********************************************************************/
2487 /* Initialize IT for displaying current_buffer in window W, starting
2488 at character position CHARPOS. CHARPOS < 0 means that no buffer
2489 position is specified which is useful when the iterator is assigned
2490 a position later. BYTEPOS is the byte position corresponding to
2491 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2493 If ROW is not null, calls to produce_glyphs with IT as parameter
2494 will produce glyphs in that row.
2496 BASE_FACE_ID is the id of a base face to use. It must be one of
2497 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2498 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2499 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2501 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2502 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2503 will be initialized to use the corresponding mode line glyph row of
2504 the desired matrix of W. */
2507 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2510 int charpos
, bytepos
;
2511 struct glyph_row
*row
;
2512 enum face_id base_face_id
;
2514 int highlight_region_p
;
2515 enum face_id remapped_base_face_id
= base_face_id
;
2517 /* Some precondition checks. */
2518 xassert (w
!= NULL
&& it
!= NULL
);
2519 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2522 /* If face attributes have been changed since the last redisplay,
2523 free realized faces now because they depend on face definitions
2524 that might have changed. Don't free faces while there might be
2525 desired matrices pending which reference these faces. */
2526 if (face_change_count
&& !inhibit_free_realized_faces
)
2528 face_change_count
= 0;
2529 free_all_realized_faces (Qnil
);
2532 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2533 if (! NILP (Vface_remapping_alist
))
2534 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2536 /* Use one of the mode line rows of W's desired matrix if
2540 if (base_face_id
== MODE_LINE_FACE_ID
2541 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2542 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2543 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2544 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2548 bzero (it
, sizeof *it
);
2549 it
->current
.overlay_string_index
= -1;
2550 it
->current
.dpvec_index
= -1;
2551 it
->base_face_id
= remapped_base_face_id
;
2553 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2555 /* The window in which we iterate over current_buffer: */
2556 XSETWINDOW (it
->window
, w
);
2558 it
->f
= XFRAME (w
->frame
);
2560 /* Extra space between lines (on window systems only). */
2561 if (base_face_id
== DEFAULT_FACE_ID
2562 && FRAME_WINDOW_P (it
->f
))
2564 if (NATNUMP (current_buffer
->extra_line_spacing
))
2565 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2566 else if (FLOATP (current_buffer
->extra_line_spacing
))
2567 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2568 * FRAME_LINE_HEIGHT (it
->f
));
2569 else if (it
->f
->extra_line_spacing
> 0)
2570 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2571 it
->max_extra_line_spacing
= 0;
2574 /* If realized faces have been removed, e.g. because of face
2575 attribute changes of named faces, recompute them. When running
2576 in batch mode, the face cache of the initial frame is null. If
2577 we happen to get called, make a dummy face cache. */
2578 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2579 init_frame_faces (it
->f
);
2580 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2581 recompute_basic_faces (it
->f
);
2583 /* Current value of the `slice', `space-width', and 'height' properties. */
2584 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2585 it
->space_width
= Qnil
;
2586 it
->font_height
= Qnil
;
2587 it
->override_ascent
= -1;
2589 /* Are control characters displayed as `^C'? */
2590 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2592 /* -1 means everything between a CR and the following line end
2593 is invisible. >0 means lines indented more than this value are
2595 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2596 ? XFASTINT (current_buffer
->selective_display
)
2597 : (!NILP (current_buffer
->selective_display
)
2599 it
->selective_display_ellipsis_p
2600 = !NILP (current_buffer
->selective_display_ellipses
);
2602 /* Display table to use. */
2603 it
->dp
= window_display_table (w
);
2605 /* Are multibyte characters enabled in current_buffer? */
2606 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2608 /* Non-zero if we should highlight the region. */
2610 = (!NILP (Vtransient_mark_mode
)
2611 && !NILP (current_buffer
->mark_active
)
2612 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2614 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2615 start and end of a visible region in window IT->w. Set both to
2616 -1 to indicate no region. */
2617 if (highlight_region_p
2618 /* Maybe highlight only in selected window. */
2619 && (/* Either show region everywhere. */
2620 highlight_nonselected_windows
2621 /* Or show region in the selected window. */
2622 || w
== XWINDOW (selected_window
)
2623 /* Or show the region if we are in the mini-buffer and W is
2624 the window the mini-buffer refers to. */
2625 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2626 && WINDOWP (minibuf_selected_window
)
2627 && w
== XWINDOW (minibuf_selected_window
))))
2629 int charpos
= marker_position (current_buffer
->mark
);
2630 it
->region_beg_charpos
= min (PT
, charpos
);
2631 it
->region_end_charpos
= max (PT
, charpos
);
2634 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2636 /* Get the position at which the redisplay_end_trigger hook should
2637 be run, if it is to be run at all. */
2638 if (MARKERP (w
->redisplay_end_trigger
)
2639 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2640 it
->redisplay_end_trigger_charpos
2641 = marker_position (w
->redisplay_end_trigger
);
2642 else if (INTEGERP (w
->redisplay_end_trigger
))
2643 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2645 /* Correct bogus values of tab_width. */
2646 it
->tab_width
= XINT (current_buffer
->tab_width
);
2647 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2650 /* Are lines in the display truncated? */
2651 if (base_face_id
!= DEFAULT_FACE_ID
2652 || XINT (it
->w
->hscroll
)
2653 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2654 && ((!NILP (Vtruncate_partial_width_windows
)
2655 && !INTEGERP (Vtruncate_partial_width_windows
))
2656 || (INTEGERP (Vtruncate_partial_width_windows
)
2657 && (WINDOW_TOTAL_COLS (it
->w
)
2658 < XINT (Vtruncate_partial_width_windows
))))))
2659 it
->line_wrap
= TRUNCATE
;
2660 else if (NILP (current_buffer
->truncate_lines
))
2661 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2662 ? WINDOW_WRAP
: WORD_WRAP
;
2664 it
->line_wrap
= TRUNCATE
;
2666 /* Get dimensions of truncation and continuation glyphs. These are
2667 displayed as fringe bitmaps under X, so we don't need them for such
2669 if (!FRAME_WINDOW_P (it
->f
))
2671 if (it
->line_wrap
== TRUNCATE
)
2673 /* We will need the truncation glyph. */
2674 xassert (it
->glyph_row
== NULL
);
2675 produce_special_glyphs (it
, IT_TRUNCATION
);
2676 it
->truncation_pixel_width
= it
->pixel_width
;
2680 /* We will need the continuation glyph. */
2681 xassert (it
->glyph_row
== NULL
);
2682 produce_special_glyphs (it
, IT_CONTINUATION
);
2683 it
->continuation_pixel_width
= it
->pixel_width
;
2686 /* Reset these values to zero because the produce_special_glyphs
2687 above has changed them. */
2688 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2689 it
->phys_ascent
= it
->phys_descent
= 0;
2692 /* Set this after getting the dimensions of truncation and
2693 continuation glyphs, so that we don't produce glyphs when calling
2694 produce_special_glyphs, above. */
2695 it
->glyph_row
= row
;
2696 it
->area
= TEXT_AREA
;
2698 /* Get the dimensions of the display area. The display area
2699 consists of the visible window area plus a horizontally scrolled
2700 part to the left of the window. All x-values are relative to the
2701 start of this total display area. */
2702 if (base_face_id
!= DEFAULT_FACE_ID
)
2704 /* Mode lines, menu bar in terminal frames. */
2705 it
->first_visible_x
= 0;
2706 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2711 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2712 it
->last_visible_x
= (it
->first_visible_x
2713 + window_box_width (w
, TEXT_AREA
));
2715 /* If we truncate lines, leave room for the truncator glyph(s) at
2716 the right margin. Otherwise, leave room for the continuation
2717 glyph(s). Truncation and continuation glyphs are not inserted
2718 for window-based redisplay. */
2719 if (!FRAME_WINDOW_P (it
->f
))
2721 if (it
->line_wrap
== TRUNCATE
)
2722 it
->last_visible_x
-= it
->truncation_pixel_width
;
2724 it
->last_visible_x
-= it
->continuation_pixel_width
;
2727 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2728 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2731 /* Leave room for a border glyph. */
2732 if (!FRAME_WINDOW_P (it
->f
)
2733 && !WINDOW_RIGHTMOST_P (it
->w
))
2734 it
->last_visible_x
-= 1;
2736 it
->last_visible_y
= window_text_bottom_y (w
);
2738 /* For mode lines and alike, arrange for the first glyph having a
2739 left box line if the face specifies a box. */
2740 if (base_face_id
!= DEFAULT_FACE_ID
)
2744 it
->face_id
= remapped_base_face_id
;
2746 /* If we have a boxed mode line, make the first character appear
2747 with a left box line. */
2748 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2749 if (face
->box
!= FACE_NO_BOX
)
2750 it
->start_of_box_run_p
= 1;
2753 /* If a buffer position was specified, set the iterator there,
2754 getting overlays and face properties from that position. */
2755 if (charpos
>= BUF_BEG (current_buffer
))
2757 it
->end_charpos
= ZV
;
2759 IT_CHARPOS (*it
) = charpos
;
2761 /* Compute byte position if not specified. */
2762 if (bytepos
< charpos
)
2763 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2765 IT_BYTEPOS (*it
) = bytepos
;
2767 it
->start
= it
->current
;
2769 /* Compute faces etc. */
2770 reseat (it
, it
->current
.pos
, 1);
2777 /* Initialize IT for the display of window W with window start POS. */
2780 start_display (it
, w
, pos
)
2783 struct text_pos pos
;
2785 struct glyph_row
*row
;
2786 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2788 row
= w
->desired_matrix
->rows
+ first_vpos
;
2789 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2790 it
->first_vpos
= first_vpos
;
2792 /* Don't reseat to previous visible line start if current start
2793 position is in a string or image. */
2794 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2796 int start_at_line_beg_p
;
2797 int first_y
= it
->current_y
;
2799 /* If window start is not at a line start, skip forward to POS to
2800 get the correct continuation lines width. */
2801 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2802 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2803 if (!start_at_line_beg_p
)
2807 reseat_at_previous_visible_line_start (it
);
2808 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2810 new_x
= it
->current_x
+ it
->pixel_width
;
2812 /* If lines are continued, this line may end in the middle
2813 of a multi-glyph character (e.g. a control character
2814 displayed as \003, or in the middle of an overlay
2815 string). In this case move_it_to above will not have
2816 taken us to the start of the continuation line but to the
2817 end of the continued line. */
2818 if (it
->current_x
> 0
2819 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2820 && (/* And glyph doesn't fit on the line. */
2821 new_x
> it
->last_visible_x
2822 /* Or it fits exactly and we're on a window
2824 || (new_x
== it
->last_visible_x
2825 && FRAME_WINDOW_P (it
->f
))))
2827 if (it
->current
.dpvec_index
>= 0
2828 || it
->current
.overlay_string_index
>= 0)
2830 set_iterator_to_next (it
, 1);
2831 move_it_in_display_line_to (it
, -1, -1, 0);
2834 it
->continuation_lines_width
+= it
->current_x
;
2837 /* We're starting a new display line, not affected by the
2838 height of the continued line, so clear the appropriate
2839 fields in the iterator structure. */
2840 it
->max_ascent
= it
->max_descent
= 0;
2841 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2843 it
->current_y
= first_y
;
2845 it
->current_x
= it
->hpos
= 0;
2849 #if 0 /* Don't assert the following because start_display is sometimes
2850 called intentionally with a window start that is not at a
2851 line start. Please leave this code in as a comment. */
2853 /* Window start should be on a line start, now. */
2854 xassert (it
->continuation_lines_width
2855 || IT_CHARPOS (it
) == BEGV
2856 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2861 /* Return 1 if POS is a position in ellipses displayed for invisible
2862 text. W is the window we display, for text property lookup. */
2865 in_ellipses_for_invisible_text_p (pos
, w
)
2866 struct display_pos
*pos
;
2869 Lisp_Object prop
, window
;
2871 int charpos
= CHARPOS (pos
->pos
);
2873 /* If POS specifies a position in a display vector, this might
2874 be for an ellipsis displayed for invisible text. We won't
2875 get the iterator set up for delivering that ellipsis unless
2876 we make sure that it gets aware of the invisible text. */
2877 if (pos
->dpvec_index
>= 0
2878 && pos
->overlay_string_index
< 0
2879 && CHARPOS (pos
->string_pos
) < 0
2881 && (XSETWINDOW (window
, w
),
2882 prop
= Fget_char_property (make_number (charpos
),
2883 Qinvisible
, window
),
2884 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2886 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2888 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2895 /* Initialize IT for stepping through current_buffer in window W,
2896 starting at position POS that includes overlay string and display
2897 vector/ control character translation position information. Value
2898 is zero if there are overlay strings with newlines at POS. */
2901 init_from_display_pos (it
, w
, pos
)
2904 struct display_pos
*pos
;
2906 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2907 int i
, overlay_strings_with_newlines
= 0;
2909 /* If POS specifies a position in a display vector, this might
2910 be for an ellipsis displayed for invisible text. We won't
2911 get the iterator set up for delivering that ellipsis unless
2912 we make sure that it gets aware of the invisible text. */
2913 if (in_ellipses_for_invisible_text_p (pos
, w
))
2919 /* Keep in mind: the call to reseat in init_iterator skips invisible
2920 text, so we might end up at a position different from POS. This
2921 is only a problem when POS is a row start after a newline and an
2922 overlay starts there with an after-string, and the overlay has an
2923 invisible property. Since we don't skip invisible text in
2924 display_line and elsewhere immediately after consuming the
2925 newline before the row start, such a POS will not be in a string,
2926 but the call to init_iterator below will move us to the
2928 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2930 /* This only scans the current chunk -- it should scan all chunks.
2931 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2932 to 16 in 22.1 to make this a lesser problem. */
2933 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2935 const char *s
= SDATA (it
->overlay_strings
[i
]);
2936 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2938 while (s
< e
&& *s
!= '\n')
2943 overlay_strings_with_newlines
= 1;
2948 /* If position is within an overlay string, set up IT to the right
2950 if (pos
->overlay_string_index
>= 0)
2954 /* If the first overlay string happens to have a `display'
2955 property for an image, the iterator will be set up for that
2956 image, and we have to undo that setup first before we can
2957 correct the overlay string index. */
2958 if (it
->method
== GET_FROM_IMAGE
)
2961 /* We already have the first chunk of overlay strings in
2962 IT->overlay_strings. Load more until the one for
2963 pos->overlay_string_index is in IT->overlay_strings. */
2964 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2966 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2967 it
->current
.overlay_string_index
= 0;
2970 load_overlay_strings (it
, 0);
2971 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2975 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2976 relative_index
= (it
->current
.overlay_string_index
2977 % OVERLAY_STRING_CHUNK_SIZE
);
2978 it
->string
= it
->overlay_strings
[relative_index
];
2979 xassert (STRINGP (it
->string
));
2980 it
->current
.string_pos
= pos
->string_pos
;
2981 it
->method
= GET_FROM_STRING
;
2984 #if 0 /* This is bogus because POS not having an overlay string
2985 position does not mean it's after the string. Example: A
2986 line starting with a before-string and initialization of IT
2987 to the previous row's end position. */
2988 else if (it
->current
.overlay_string_index
>= 0)
2990 /* If POS says we're already after an overlay string ending at
2991 POS, make sure to pop the iterator because it will be in
2992 front of that overlay string. When POS is ZV, we've thereby
2993 also ``processed'' overlay strings at ZV. */
2996 xassert (it
->current
.overlay_string_index
== -1);
2997 xassert (it
->method
== GET_FROM_BUFFER
);
2998 if (CHARPOS (pos
->pos
) == ZV
)
2999 it
->overlay_strings_at_end_processed_p
= 1;
3003 if (CHARPOS (pos
->string_pos
) >= 0)
3005 /* Recorded position is not in an overlay string, but in another
3006 string. This can only be a string from a `display' property.
3007 IT should already be filled with that string. */
3008 it
->current
.string_pos
= pos
->string_pos
;
3009 xassert (STRINGP (it
->string
));
3012 /* Restore position in display vector translations, control
3013 character translations or ellipses. */
3014 if (pos
->dpvec_index
>= 0)
3016 if (it
->dpvec
== NULL
)
3017 get_next_display_element (it
);
3018 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3019 it
->current
.dpvec_index
= pos
->dpvec_index
;
3023 return !overlay_strings_with_newlines
;
3027 /* Initialize IT for stepping through current_buffer in window W
3028 starting at ROW->start. */
3031 init_to_row_start (it
, w
, row
)
3034 struct glyph_row
*row
;
3036 init_from_display_pos (it
, w
, &row
->start
);
3037 it
->start
= row
->start
;
3038 it
->continuation_lines_width
= row
->continuation_lines_width
;
3043 /* Initialize IT for stepping through current_buffer in window W
3044 starting in the line following ROW, i.e. starting at ROW->end.
3045 Value is zero if there are overlay strings with newlines at ROW's
3049 init_to_row_end (it
, w
, row
)
3052 struct glyph_row
*row
;
3056 if (init_from_display_pos (it
, w
, &row
->end
))
3058 if (row
->continued_p
)
3059 it
->continuation_lines_width
3060 = row
->continuation_lines_width
+ row
->pixel_width
;
3071 /***********************************************************************
3073 ***********************************************************************/
3075 /* Called when IT reaches IT->stop_charpos. Handle text property and
3076 overlay changes. Set IT->stop_charpos to the next position where
3083 enum prop_handled handled
;
3084 int handle_overlay_change_p
;
3088 it
->current
.dpvec_index
= -1;
3089 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3090 it
->ignore_overlay_strings_at_pos_p
= 0;
3092 /* Use face of preceding text for ellipsis (if invisible) */
3093 if (it
->selective_display_ellipsis_p
)
3094 it
->saved_face_id
= it
->face_id
;
3098 handled
= HANDLED_NORMALLY
;
3100 /* Call text property handlers. */
3101 for (p
= it_props
; p
->handler
; ++p
)
3103 handled
= p
->handler (it
);
3105 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3107 else if (handled
== HANDLED_RETURN
)
3109 /* We still want to show before and after strings from
3110 overlays even if the actual buffer text is replaced. */
3111 if (!handle_overlay_change_p
|| it
->sp
> 1)
3113 if (!get_overlay_strings_1 (it
, 0, 0))
3115 it
->ignore_overlay_strings_at_pos_p
= 1;
3116 it
->string_from_display_prop_p
= 0;
3117 handle_overlay_change_p
= 0;
3118 handled
= HANDLED_RECOMPUTE_PROPS
;
3121 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3122 handle_overlay_change_p
= 0;
3125 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3127 /* Don't check for overlay strings below when set to deliver
3128 characters from a display vector. */
3129 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3130 handle_overlay_change_p
= 0;
3132 /* Handle overlay changes.
3133 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3134 if it finds overlays. */
3135 if (handle_overlay_change_p
)
3136 handled
= handle_overlay_change (it
);
3139 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3141 /* Determine where to stop next. */
3142 if (handled
== HANDLED_NORMALLY
)
3143 compute_stop_pos (it
);
3147 /* Compute IT->stop_charpos from text property and overlay change
3148 information for IT's current position. */
3151 compute_stop_pos (it
)
3154 register INTERVAL iv
, next_iv
;
3155 Lisp_Object object
, limit
, position
;
3157 /* If nowhere else, stop at the end. */
3158 it
->stop_charpos
= it
->end_charpos
;
3160 if (STRINGP (it
->string
))
3162 /* Strings are usually short, so don't limit the search for
3164 object
= it
->string
;
3166 position
= make_number (IT_STRING_CHARPOS (*it
));
3172 /* If next overlay change is in front of the current stop pos
3173 (which is IT->end_charpos), stop there. Note: value of
3174 next_overlay_change is point-max if no overlay change
3176 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3177 if (charpos
< it
->stop_charpos
)
3178 it
->stop_charpos
= charpos
;
3180 /* If showing the region, we have to stop at the region
3181 start or end because the face might change there. */
3182 if (it
->region_beg_charpos
> 0)
3184 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3185 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3186 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3187 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3190 /* Set up variables for computing the stop position from text
3191 property changes. */
3192 XSETBUFFER (object
, current_buffer
);
3193 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3194 position
= make_number (IT_CHARPOS (*it
));
3198 /* Get the interval containing IT's position. Value is a null
3199 interval if there isn't such an interval. */
3200 iv
= validate_interval_range (object
, &position
, &position
, 0);
3201 if (!NULL_INTERVAL_P (iv
))
3203 Lisp_Object values_here
[LAST_PROP_IDX
];
3206 /* Get properties here. */
3207 for (p
= it_props
; p
->handler
; ++p
)
3208 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3210 /* Look for an interval following iv that has different
3212 for (next_iv
= next_interval (iv
);
3213 (!NULL_INTERVAL_P (next_iv
)
3215 || XFASTINT (limit
) > next_iv
->position
));
3216 next_iv
= next_interval (next_iv
))
3218 for (p
= it_props
; p
->handler
; ++p
)
3220 Lisp_Object new_value
;
3222 new_value
= textget (next_iv
->plist
, *p
->name
);
3223 if (!EQ (values_here
[p
->idx
], new_value
))
3231 if (!NULL_INTERVAL_P (next_iv
))
3233 if (INTEGERP (limit
)
3234 && next_iv
->position
>= XFASTINT (limit
))
3235 /* No text property change up to limit. */
3236 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3238 /* Text properties change in next_iv. */
3239 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3243 xassert (STRINGP (it
->string
)
3244 || (it
->stop_charpos
>= BEGV
3245 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3249 /* Return the position of the next overlay change after POS in
3250 current_buffer. Value is point-max if no overlay change
3251 follows. This is like `next-overlay-change' but doesn't use
3255 next_overlay_change (pos
)
3260 Lisp_Object
*overlays
;
3263 /* Get all overlays at the given position. */
3264 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3266 /* If any of these overlays ends before endpos,
3267 use its ending point instead. */
3268 for (i
= 0; i
< noverlays
; ++i
)
3273 oend
= OVERLAY_END (overlays
[i
]);
3274 oendpos
= OVERLAY_POSITION (oend
);
3275 endpos
= min (endpos
, oendpos
);
3283 /***********************************************************************
3285 ***********************************************************************/
3287 /* Handle changes in the `fontified' property of the current buffer by
3288 calling hook functions from Qfontification_functions to fontify
3291 static enum prop_handled
3292 handle_fontified_prop (it
)
3295 Lisp_Object prop
, pos
;
3296 enum prop_handled handled
= HANDLED_NORMALLY
;
3298 if (!NILP (Vmemory_full
))
3301 /* Get the value of the `fontified' property at IT's current buffer
3302 position. (The `fontified' property doesn't have a special
3303 meaning in strings.) If the value is nil, call functions from
3304 Qfontification_functions. */
3305 if (!STRINGP (it
->string
)
3307 && !NILP (Vfontification_functions
)
3308 && !NILP (Vrun_hooks
)
3309 && (pos
= make_number (IT_CHARPOS (*it
)),
3310 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3311 /* Ignore the special cased nil value always present at EOB since
3312 no amount of fontifying will be able to change it. */
3313 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3315 int count
= SPECPDL_INDEX ();
3318 val
= Vfontification_functions
;
3319 specbind (Qfontification_functions
, Qnil
);
3321 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3322 safe_call1 (val
, pos
);
3325 Lisp_Object globals
, fn
;
3326 struct gcpro gcpro1
, gcpro2
;
3329 GCPRO2 (val
, globals
);
3331 for (; CONSP (val
); val
= XCDR (val
))
3337 /* A value of t indicates this hook has a local
3338 binding; it means to run the global binding too.
3339 In a global value, t should not occur. If it
3340 does, we must ignore it to avoid an endless
3342 for (globals
= Fdefault_value (Qfontification_functions
);
3344 globals
= XCDR (globals
))
3346 fn
= XCAR (globals
);
3348 safe_call1 (fn
, pos
);
3352 safe_call1 (fn
, pos
);
3358 unbind_to (count
, Qnil
);
3360 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3361 something. This avoids an endless loop if they failed to
3362 fontify the text for which reason ever. */
3363 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3364 handled
= HANDLED_RECOMPUTE_PROPS
;
3372 /***********************************************************************
3374 ***********************************************************************/
3376 /* Set up iterator IT from face properties at its current position.
3377 Called from handle_stop. */
3379 static enum prop_handled
3380 handle_face_prop (it
)
3384 EMACS_INT next_stop
;
3386 if (!STRINGP (it
->string
))
3389 = face_at_buffer_position (it
->w
,
3391 it
->region_beg_charpos
,
3392 it
->region_end_charpos
,
3395 + TEXT_PROP_DISTANCE_LIMIT
),
3398 /* Is this a start of a run of characters with box face?
3399 Caveat: this can be called for a freshly initialized
3400 iterator; face_id is -1 in this case. We know that the new
3401 face will not change until limit, i.e. if the new face has a
3402 box, all characters up to limit will have one. But, as
3403 usual, we don't know whether limit is really the end. */
3404 if (new_face_id
!= it
->face_id
)
3406 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3408 /* If new face has a box but old face has not, this is
3409 the start of a run of characters with box, i.e. it has
3410 a shadow on the left side. The value of face_id of the
3411 iterator will be -1 if this is the initial call that gets
3412 the face. In this case, we have to look in front of IT's
3413 position and see whether there is a face != new_face_id. */
3414 it
->start_of_box_run_p
3415 = (new_face
->box
!= FACE_NO_BOX
3416 && (it
->face_id
>= 0
3417 || IT_CHARPOS (*it
) == BEG
3418 || new_face_id
!= face_before_it_pos (it
)));
3419 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3424 int base_face_id
, bufpos
;
3426 Lisp_Object from_overlay
3427 = (it
->current
.overlay_string_index
>= 0
3428 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3431 /* See if we got to this string directly or indirectly from
3432 an overlay property. That includes the before-string or
3433 after-string of an overlay, strings in display properties
3434 provided by an overlay, their text properties, etc.
3436 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3437 if (! NILP (from_overlay
))
3438 for (i
= it
->sp
- 1; i
>= 0; i
--)
3440 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3442 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3443 else if (! NILP (it
->stack
[i
].from_overlay
))
3444 from_overlay
= it
->stack
[i
].from_overlay
;
3446 if (!NILP (from_overlay
))
3450 if (! NILP (from_overlay
))
3452 bufpos
= IT_CHARPOS (*it
);
3453 /* For a string from an overlay, the base face depends
3454 only on text properties and ignores overlays. */
3456 = face_for_overlay_string (it
->w
,
3458 it
->region_beg_charpos
,
3459 it
->region_end_charpos
,
3462 + TEXT_PROP_DISTANCE_LIMIT
),
3470 /* For strings from a `display' property, use the face at
3471 IT's current buffer position as the base face to merge
3472 with, so that overlay strings appear in the same face as
3473 surrounding text, unless they specify their own
3475 base_face_id
= underlying_face_id (it
);
3478 new_face_id
= face_at_string_position (it
->w
,
3480 IT_STRING_CHARPOS (*it
),
3482 it
->region_beg_charpos
,
3483 it
->region_end_charpos
,
3487 #if 0 /* This shouldn't be neccessary. Let's check it. */
3488 /* If IT is used to display a mode line we would really like to
3489 use the mode line face instead of the frame's default face. */
3490 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3491 && new_face_id
== DEFAULT_FACE_ID
)
3492 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3495 /* Is this a start of a run of characters with box? Caveat:
3496 this can be called for a freshly allocated iterator; face_id
3497 is -1 is this case. We know that the new face will not
3498 change until the next check pos, i.e. if the new face has a
3499 box, all characters up to that position will have a
3500 box. But, as usual, we don't know whether that position
3501 is really the end. */
3502 if (new_face_id
!= it
->face_id
)
3504 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3505 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3507 /* If new face has a box but old face hasn't, this is the
3508 start of a run of characters with box, i.e. it has a
3509 shadow on the left side. */
3510 it
->start_of_box_run_p
3511 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3512 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3516 it
->face_id
= new_face_id
;
3517 return HANDLED_NORMALLY
;
3521 /* Return the ID of the face ``underlying'' IT's current position,
3522 which is in a string. If the iterator is associated with a
3523 buffer, return the face at IT's current buffer position.
3524 Otherwise, use the iterator's base_face_id. */
3527 underlying_face_id (it
)
3530 int face_id
= it
->base_face_id
, i
;
3532 xassert (STRINGP (it
->string
));
3534 for (i
= it
->sp
- 1; i
>= 0; --i
)
3535 if (NILP (it
->stack
[i
].string
))
3536 face_id
= it
->stack
[i
].face_id
;
3542 /* Compute the face one character before or after the current position
3543 of IT. BEFORE_P non-zero means get the face in front of IT's
3544 position. Value is the id of the face. */
3547 face_before_or_after_it_pos (it
, before_p
)
3552 EMACS_INT next_check_charpos
;
3553 struct text_pos pos
;
3555 xassert (it
->s
== NULL
);
3557 if (STRINGP (it
->string
))
3559 int bufpos
, base_face_id
;
3561 /* No face change past the end of the string (for the case
3562 we are padding with spaces). No face change before the
3564 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3565 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3568 /* Set pos to the position before or after IT's current position. */
3570 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3572 /* For composition, we must check the character after the
3574 pos
= (it
->what
== IT_COMPOSITION
3575 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3576 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3578 if (it
->current
.overlay_string_index
>= 0)
3579 bufpos
= IT_CHARPOS (*it
);
3583 base_face_id
= underlying_face_id (it
);
3585 /* Get the face for ASCII, or unibyte. */
3586 face_id
= face_at_string_position (it
->w
,
3590 it
->region_beg_charpos
,
3591 it
->region_end_charpos
,
3592 &next_check_charpos
,
3595 /* Correct the face for charsets different from ASCII. Do it
3596 for the multibyte case only. The face returned above is
3597 suitable for unibyte text if IT->string is unibyte. */
3598 if (STRING_MULTIBYTE (it
->string
))
3600 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3601 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3603 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3605 c
= string_char_and_length (p
, rest
, &len
);
3606 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3611 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3612 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3615 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3616 pos
= it
->current
.pos
;
3619 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3622 if (it
->what
== IT_COMPOSITION
)
3623 /* For composition, we must check the position after the
3625 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3627 INC_TEXT_POS (pos
, it
->multibyte_p
);
3630 /* Determine face for CHARSET_ASCII, or unibyte. */
3631 face_id
= face_at_buffer_position (it
->w
,
3633 it
->region_beg_charpos
,
3634 it
->region_end_charpos
,
3635 &next_check_charpos
,
3638 /* Correct the face for charsets different from ASCII. Do it
3639 for the multibyte case only. The face returned above is
3640 suitable for unibyte text if current_buffer is unibyte. */
3641 if (it
->multibyte_p
)
3643 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3644 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3645 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3654 /***********************************************************************
3656 ***********************************************************************/
3658 /* Set up iterator IT from invisible properties at its current
3659 position. Called from handle_stop. */
3661 static enum prop_handled
3662 handle_invisible_prop (it
)
3665 enum prop_handled handled
= HANDLED_NORMALLY
;
3667 if (STRINGP (it
->string
))
3669 extern Lisp_Object Qinvisible
;
3670 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3672 /* Get the value of the invisible text property at the
3673 current position. Value will be nil if there is no such
3675 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3676 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3679 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3681 handled
= HANDLED_RECOMPUTE_PROPS
;
3683 /* Get the position at which the next change of the
3684 invisible text property can be found in IT->string.
3685 Value will be nil if the property value is the same for
3686 all the rest of IT->string. */
3687 XSETINT (limit
, SCHARS (it
->string
));
3688 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3691 /* Text at current position is invisible. The next
3692 change in the property is at position end_charpos.
3693 Move IT's current position to that position. */
3694 if (INTEGERP (end_charpos
)
3695 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3697 struct text_pos old
;
3698 old
= it
->current
.string_pos
;
3699 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3700 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3704 /* The rest of the string is invisible. If this is an
3705 overlay string, proceed with the next overlay string
3706 or whatever comes and return a character from there. */
3707 if (it
->current
.overlay_string_index
>= 0)
3709 next_overlay_string (it
);
3710 /* Don't check for overlay strings when we just
3711 finished processing them. */
3712 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3716 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3717 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3725 EMACS_INT newpos
, next_stop
, start_charpos
;
3726 Lisp_Object pos
, prop
, overlay
;
3728 /* First of all, is there invisible text at this position? */
3729 start_charpos
= IT_CHARPOS (*it
);
3730 pos
= make_number (IT_CHARPOS (*it
));
3731 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3733 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3735 /* If we are on invisible text, skip over it. */
3736 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3738 /* Record whether we have to display an ellipsis for the
3740 int display_ellipsis_p
= invis_p
== 2;
3742 handled
= HANDLED_RECOMPUTE_PROPS
;
3744 /* Loop skipping over invisible text. The loop is left at
3745 ZV or with IT on the first char being visible again. */
3748 /* Try to skip some invisible text. Return value is the
3749 position reached which can be equal to IT's position
3750 if there is nothing invisible here. This skips both
3751 over invisible text properties and overlays with
3752 invisible property. */
3753 newpos
= skip_invisible (IT_CHARPOS (*it
),
3754 &next_stop
, ZV
, it
->window
);
3756 /* If we skipped nothing at all we weren't at invisible
3757 text in the first place. If everything to the end of
3758 the buffer was skipped, end the loop. */
3759 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3763 /* We skipped some characters but not necessarily
3764 all there are. Check if we ended up on visible
3765 text. Fget_char_property returns the property of
3766 the char before the given position, i.e. if we
3767 get invis_p = 0, this means that the char at
3768 newpos is visible. */
3769 pos
= make_number (newpos
);
3770 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3771 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3774 /* If we ended up on invisible text, proceed to
3775 skip starting with next_stop. */
3777 IT_CHARPOS (*it
) = next_stop
;
3779 /* If there are adjacent invisible texts, don't lose the
3780 second one's ellipsis. */
3782 display_ellipsis_p
= 1;
3786 /* The position newpos is now either ZV or on visible text. */
3787 IT_CHARPOS (*it
) = newpos
;
3788 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3790 /* If there are before-strings at the start of invisible
3791 text, and the text is invisible because of a text
3792 property, arrange to show before-strings because 20.x did
3793 it that way. (If the text is invisible because of an
3794 overlay property instead of a text property, this is
3795 already handled in the overlay code.) */
3797 && get_overlay_strings (it
, start_charpos
))
3799 handled
= HANDLED_RECOMPUTE_PROPS
;
3800 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3802 else if (display_ellipsis_p
)
3804 /* Make sure that the glyphs of the ellipsis will get
3805 correct `charpos' values. If we would not update
3806 it->position here, the glyphs would belong to the
3807 last visible character _before_ the invisible
3808 text, which confuses `set_cursor_from_row'.
3810 We use the last invisible position instead of the
3811 first because this way the cursor is always drawn on
3812 the first "." of the ellipsis, whenever PT is inside
3813 the invisible text. Otherwise the cursor would be
3814 placed _after_ the ellipsis when the point is after the
3815 first invisible character. */
3816 if (!STRINGP (it
->object
))
3818 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3819 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3821 setup_for_ellipsis (it
, 0);
3822 /* Let the ellipsis display before
3823 considering any properties of the following char.
3824 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3825 handled
= HANDLED_RETURN
;
3834 /* Make iterator IT return `...' next.
3835 Replaces LEN characters from buffer. */
3838 setup_for_ellipsis (it
, len
)
3842 /* Use the display table definition for `...'. Invalid glyphs
3843 will be handled by the method returning elements from dpvec. */
3844 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3846 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3847 it
->dpvec
= v
->contents
;
3848 it
->dpend
= v
->contents
+ v
->size
;
3852 /* Default `...'. */
3853 it
->dpvec
= default_invis_vector
;
3854 it
->dpend
= default_invis_vector
+ 3;
3857 it
->dpvec_char_len
= len
;
3858 it
->current
.dpvec_index
= 0;
3859 it
->dpvec_face_id
= -1;
3861 /* Remember the current face id in case glyphs specify faces.
3862 IT's face is restored in set_iterator_to_next.
3863 saved_face_id was set to preceding char's face in handle_stop. */
3864 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3865 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3867 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3873 /***********************************************************************
3875 ***********************************************************************/
3877 /* Set up iterator IT from `display' property at its current position.
3878 Called from handle_stop.
3879 We return HANDLED_RETURN if some part of the display property
3880 overrides the display of the buffer text itself.
3881 Otherwise we return HANDLED_NORMALLY. */
3883 static enum prop_handled
3884 handle_display_prop (it
)
3887 Lisp_Object prop
, object
, overlay
;
3888 struct text_pos
*position
;
3889 /* Nonzero if some property replaces the display of the text itself. */
3890 int display_replaced_p
= 0;
3892 if (STRINGP (it
->string
))
3894 object
= it
->string
;
3895 position
= &it
->current
.string_pos
;
3899 XSETWINDOW (object
, it
->w
);
3900 position
= &it
->current
.pos
;
3903 /* Reset those iterator values set from display property values. */
3904 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3905 it
->space_width
= Qnil
;
3906 it
->font_height
= Qnil
;
3909 /* We don't support recursive `display' properties, i.e. string
3910 values that have a string `display' property, that have a string
3911 `display' property etc. */
3912 if (!it
->string_from_display_prop_p
)
3913 it
->area
= TEXT_AREA
;
3915 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3916 Qdisplay
, object
, &overlay
);
3918 return HANDLED_NORMALLY
;
3919 /* Now OVERLAY is the overlay that gave us this property, or nil
3920 if it was a text property. */
3922 if (!STRINGP (it
->string
))
3923 object
= it
->w
->buffer
;
3926 /* Simple properties. */
3927 && !EQ (XCAR (prop
), Qimage
)
3928 && !EQ (XCAR (prop
), Qspace
)
3929 && !EQ (XCAR (prop
), Qwhen
)
3930 && !EQ (XCAR (prop
), Qslice
)
3931 && !EQ (XCAR (prop
), Qspace_width
)
3932 && !EQ (XCAR (prop
), Qheight
)
3933 && !EQ (XCAR (prop
), Qraise
)
3934 /* Marginal area specifications. */
3935 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3936 && !EQ (XCAR (prop
), Qleft_fringe
)
3937 && !EQ (XCAR (prop
), Qright_fringe
)
3938 && !NILP (XCAR (prop
)))
3940 for (; CONSP (prop
); prop
= XCDR (prop
))
3942 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3943 position
, display_replaced_p
))
3945 display_replaced_p
= 1;
3946 /* If some text in a string is replaced, `position' no
3947 longer points to the position of `object'. */
3948 if (STRINGP (object
))
3953 else if (VECTORP (prop
))
3956 for (i
= 0; i
< ASIZE (prop
); ++i
)
3957 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3958 position
, display_replaced_p
))
3960 display_replaced_p
= 1;
3961 /* If some text in a string is replaced, `position' no
3962 longer points to the position of `object'. */
3963 if (STRINGP (object
))
3969 int ret
= handle_single_display_spec (it
, prop
, object
, overlay
,
3971 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3972 return HANDLED_RECOMPUTE_PROPS
;
3974 display_replaced_p
= 1;
3977 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3981 /* Value is the position of the end of the `display' property starting
3982 at START_POS in OBJECT. */
3984 static struct text_pos
3985 display_prop_end (it
, object
, start_pos
)
3988 struct text_pos start_pos
;
3991 struct text_pos end_pos
;
3993 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3994 Qdisplay
, object
, Qnil
);
3995 CHARPOS (end_pos
) = XFASTINT (end
);
3996 if (STRINGP (object
))
3997 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3999 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4005 /* Set up IT from a single `display' specification PROP. OBJECT
4006 is the object in which the `display' property was found. *POSITION
4007 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4008 means that we previously saw a display specification which already
4009 replaced text display with something else, for example an image;
4010 we ignore such properties after the first one has been processed.
4012 OVERLAY is the overlay this `display' property came from,
4013 or nil if it was a text property.
4015 If PROP is a `space' or `image' specification, and in some other
4016 cases too, set *POSITION to the position where the `display'
4019 Value is non-zero if something was found which replaces the display
4020 of buffer or string text. Specifically, the value is -1 if that
4021 "something" is "nothing". */
4024 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4025 display_replaced_before_p
)
4029 Lisp_Object overlay
;
4030 struct text_pos
*position
;
4031 int display_replaced_before_p
;
4034 Lisp_Object location
, value
;
4035 struct text_pos start_pos
, save_pos
;
4038 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4039 If the result is non-nil, use VALUE instead of SPEC. */
4041 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4050 if (!NILP (form
) && !EQ (form
, Qt
))
4052 int count
= SPECPDL_INDEX ();
4053 struct gcpro gcpro1
;
4055 /* Bind `object' to the object having the `display' property, a
4056 buffer or string. Bind `position' to the position in the
4057 object where the property was found, and `buffer-position'
4058 to the current position in the buffer. */
4059 specbind (Qobject
, object
);
4060 specbind (Qposition
, make_number (CHARPOS (*position
)));
4061 specbind (Qbuffer_position
,
4062 make_number (STRINGP (object
)
4063 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4065 form
= safe_eval (form
);
4067 unbind_to (count
, Qnil
);
4073 /* Handle `(height HEIGHT)' specifications. */
4075 && EQ (XCAR (spec
), Qheight
)
4076 && CONSP (XCDR (spec
)))
4078 if (!FRAME_WINDOW_P (it
->f
))
4081 it
->font_height
= XCAR (XCDR (spec
));
4082 if (!NILP (it
->font_height
))
4084 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4085 int new_height
= -1;
4087 if (CONSP (it
->font_height
)
4088 && (EQ (XCAR (it
->font_height
), Qplus
)
4089 || EQ (XCAR (it
->font_height
), Qminus
))
4090 && CONSP (XCDR (it
->font_height
))
4091 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4093 /* `(+ N)' or `(- N)' where N is an integer. */
4094 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4095 if (EQ (XCAR (it
->font_height
), Qplus
))
4097 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4099 else if (FUNCTIONP (it
->font_height
))
4101 /* Call function with current height as argument.
4102 Value is the new height. */
4104 height
= safe_call1 (it
->font_height
,
4105 face
->lface
[LFACE_HEIGHT_INDEX
]);
4106 if (NUMBERP (height
))
4107 new_height
= XFLOATINT (height
);
4109 else if (NUMBERP (it
->font_height
))
4111 /* Value is a multiple of the canonical char height. */
4114 face
= FACE_FROM_ID (it
->f
,
4115 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4116 new_height
= (XFLOATINT (it
->font_height
)
4117 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4121 /* Evaluate IT->font_height with `height' bound to the
4122 current specified height to get the new height. */
4123 int count
= SPECPDL_INDEX ();
4125 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4126 value
= safe_eval (it
->font_height
);
4127 unbind_to (count
, Qnil
);
4129 if (NUMBERP (value
))
4130 new_height
= XFLOATINT (value
);
4134 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4140 /* Handle `(space-width WIDTH)'. */
4142 && EQ (XCAR (spec
), Qspace_width
)
4143 && CONSP (XCDR (spec
)))
4145 if (!FRAME_WINDOW_P (it
->f
))
4148 value
= XCAR (XCDR (spec
));
4149 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4150 it
->space_width
= value
;
4155 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4157 && EQ (XCAR (spec
), Qslice
))
4161 if (!FRAME_WINDOW_P (it
->f
))
4164 if (tem
= XCDR (spec
), CONSP (tem
))
4166 it
->slice
.x
= XCAR (tem
);
4167 if (tem
= XCDR (tem
), CONSP (tem
))
4169 it
->slice
.y
= XCAR (tem
);
4170 if (tem
= XCDR (tem
), CONSP (tem
))
4172 it
->slice
.width
= XCAR (tem
);
4173 if (tem
= XCDR (tem
), CONSP (tem
))
4174 it
->slice
.height
= XCAR (tem
);
4182 /* Handle `(raise FACTOR)'. */
4184 && EQ (XCAR (spec
), Qraise
)
4185 && CONSP (XCDR (spec
)))
4187 if (!FRAME_WINDOW_P (it
->f
))
4190 #ifdef HAVE_WINDOW_SYSTEM
4191 value
= XCAR (XCDR (spec
));
4192 if (NUMBERP (value
))
4194 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4195 it
->voffset
= - (XFLOATINT (value
)
4196 * (FONT_HEIGHT (face
->font
)));
4198 #endif /* HAVE_WINDOW_SYSTEM */
4203 /* Don't handle the other kinds of display specifications
4204 inside a string that we got from a `display' property. */
4205 if (it
->string_from_display_prop_p
)
4208 /* Characters having this form of property are not displayed, so
4209 we have to find the end of the property. */
4210 start_pos
= *position
;
4211 *position
= display_prop_end (it
, object
, start_pos
);
4214 /* Stop the scan at that end position--we assume that all
4215 text properties change there. */
4216 it
->stop_charpos
= position
->charpos
;
4218 /* Handle `(left-fringe BITMAP [FACE])'
4219 and `(right-fringe BITMAP [FACE])'. */
4221 && (EQ (XCAR (spec
), Qleft_fringe
)
4222 || EQ (XCAR (spec
), Qright_fringe
))
4223 && CONSP (XCDR (spec
)))
4225 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4228 if (!FRAME_WINDOW_P (it
->f
))
4229 /* If we return here, POSITION has been advanced
4230 across the text with this property. */
4233 #ifdef HAVE_WINDOW_SYSTEM
4234 value
= XCAR (XCDR (spec
));
4235 if (!SYMBOLP (value
)
4236 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4237 /* If we return here, POSITION has been advanced
4238 across the text with this property. */
4241 if (CONSP (XCDR (XCDR (spec
))))
4243 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4244 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4250 /* Save current settings of IT so that we can restore them
4251 when we are finished with the glyph property value. */
4253 save_pos
= it
->position
;
4254 it
->position
= *position
;
4256 it
->position
= save_pos
;
4258 it
->area
= TEXT_AREA
;
4259 it
->what
= IT_IMAGE
;
4260 it
->image_id
= -1; /* no image */
4261 it
->position
= start_pos
;
4262 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4263 it
->method
= GET_FROM_IMAGE
;
4264 it
->from_overlay
= Qnil
;
4265 it
->face_id
= face_id
;
4267 /* Say that we haven't consumed the characters with
4268 `display' property yet. The call to pop_it in
4269 set_iterator_to_next will clean this up. */
4270 *position
= start_pos
;
4272 if (EQ (XCAR (spec
), Qleft_fringe
))
4274 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4275 it
->left_user_fringe_face_id
= face_id
;
4279 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4280 it
->right_user_fringe_face_id
= face_id
;
4282 #endif /* HAVE_WINDOW_SYSTEM */
4286 /* Prepare to handle `((margin left-margin) ...)',
4287 `((margin right-margin) ...)' and `((margin nil) ...)'
4288 prefixes for display specifications. */
4289 location
= Qunbound
;
4290 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4294 value
= XCDR (spec
);
4296 value
= XCAR (value
);
4299 if (EQ (XCAR (tem
), Qmargin
)
4300 && (tem
= XCDR (tem
),
4301 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4303 || EQ (tem
, Qleft_margin
)
4304 || EQ (tem
, Qright_margin
))))
4308 if (EQ (location
, Qunbound
))
4314 /* After this point, VALUE is the property after any
4315 margin prefix has been stripped. It must be a string,
4316 an image specification, or `(space ...)'.
4318 LOCATION specifies where to display: `left-margin',
4319 `right-margin' or nil. */
4321 valid_p
= (STRINGP (value
)
4322 #ifdef HAVE_WINDOW_SYSTEM
4323 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4324 #endif /* not HAVE_WINDOW_SYSTEM */
4325 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4327 if (valid_p
&& !display_replaced_before_p
)
4329 /* Save current settings of IT so that we can restore them
4330 when we are finished with the glyph property value. */
4331 save_pos
= it
->position
;
4332 it
->position
= *position
;
4334 it
->position
= save_pos
;
4335 it
->from_overlay
= overlay
;
4337 if (NILP (location
))
4338 it
->area
= TEXT_AREA
;
4339 else if (EQ (location
, Qleft_margin
))
4340 it
->area
= LEFT_MARGIN_AREA
;
4342 it
->area
= RIGHT_MARGIN_AREA
;
4344 if (STRINGP (value
))
4346 if (SCHARS (value
) == 0)
4349 return -1; /* Replaced by "", i.e. nothing. */
4352 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4353 it
->current
.overlay_string_index
= -1;
4354 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4355 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4356 it
->method
= GET_FROM_STRING
;
4357 it
->stop_charpos
= 0;
4358 it
->string_from_display_prop_p
= 1;
4359 /* Say that we haven't consumed the characters with
4360 `display' property yet. The call to pop_it in
4361 set_iterator_to_next will clean this up. */
4362 if (BUFFERP (object
))
4363 *position
= start_pos
;
4365 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4367 it
->method
= GET_FROM_STRETCH
;
4369 *position
= it
->position
= start_pos
;
4371 #ifdef HAVE_WINDOW_SYSTEM
4374 it
->what
= IT_IMAGE
;
4375 it
->image_id
= lookup_image (it
->f
, value
);
4376 it
->position
= start_pos
;
4377 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4378 it
->method
= GET_FROM_IMAGE
;
4380 /* Say that we haven't consumed the characters with
4381 `display' property yet. The call to pop_it in
4382 set_iterator_to_next will clean this up. */
4383 *position
= start_pos
;
4385 #endif /* HAVE_WINDOW_SYSTEM */
4390 /* Invalid property or property not supported. Restore
4391 POSITION to what it was before. */
4392 *position
= start_pos
;
4397 /* Check if SPEC is a display sub-property value whose text should be
4398 treated as intangible. */
4401 single_display_spec_intangible_p (prop
)
4404 /* Skip over `when FORM'. */
4405 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4419 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4420 we don't need to treat text as intangible. */
4421 if (EQ (XCAR (prop
), Qmargin
))
4429 || EQ (XCAR (prop
), Qleft_margin
)
4430 || EQ (XCAR (prop
), Qright_margin
))
4434 return (CONSP (prop
)
4435 && (EQ (XCAR (prop
), Qimage
)
4436 || EQ (XCAR (prop
), Qspace
)));
4440 /* Check if PROP is a display property value whose text should be
4441 treated as intangible. */
4444 display_prop_intangible_p (prop
)
4448 && CONSP (XCAR (prop
))
4449 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4451 /* A list of sub-properties. */
4452 while (CONSP (prop
))
4454 if (single_display_spec_intangible_p (XCAR (prop
)))
4459 else if (VECTORP (prop
))
4461 /* A vector of sub-properties. */
4463 for (i
= 0; i
< ASIZE (prop
); ++i
)
4464 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4468 return single_display_spec_intangible_p (prop
);
4474 /* Return 1 if PROP is a display sub-property value containing STRING. */
4477 single_display_spec_string_p (prop
, string
)
4478 Lisp_Object prop
, string
;
4480 if (EQ (string
, prop
))
4483 /* Skip over `when FORM'. */
4484 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4493 /* Skip over `margin LOCATION'. */
4494 if (EQ (XCAR (prop
), Qmargin
))
4505 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4509 /* Return 1 if STRING appears in the `display' property PROP. */
4512 display_prop_string_p (prop
, string
)
4513 Lisp_Object prop
, string
;
4516 && CONSP (XCAR (prop
))
4517 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4519 /* A list of sub-properties. */
4520 while (CONSP (prop
))
4522 if (single_display_spec_string_p (XCAR (prop
), string
))
4527 else if (VECTORP (prop
))
4529 /* A vector of sub-properties. */
4531 for (i
= 0; i
< ASIZE (prop
); ++i
)
4532 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4536 return single_display_spec_string_p (prop
, string
);
4542 /* Determine from which buffer position in W's buffer STRING comes
4543 from. AROUND_CHARPOS is an approximate position where it could
4544 be from. Value is the buffer position or 0 if it couldn't be
4547 W's buffer must be current.
4549 This function is necessary because we don't record buffer positions
4550 in glyphs generated from strings (to keep struct glyph small).
4551 This function may only use code that doesn't eval because it is
4552 called asynchronously from note_mouse_highlight. */
4555 string_buffer_position (w
, string
, around_charpos
)
4560 Lisp_Object limit
, prop
, pos
;
4561 const int MAX_DISTANCE
= 1000;
4564 pos
= make_number (around_charpos
);
4565 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4566 while (!found
&& !EQ (pos
, limit
))
4568 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4569 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4572 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4577 pos
= make_number (around_charpos
);
4578 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4579 while (!found
&& !EQ (pos
, limit
))
4581 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4582 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4585 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4590 return found
? XINT (pos
) : 0;
4595 /***********************************************************************
4596 `composition' property
4597 ***********************************************************************/
4599 static enum prop_handled
4600 handle_auto_composed_prop (it
)
4603 enum prop_handled handled
= HANDLED_NORMALLY
;
4605 if (FUNCTIONP (Vauto_composition_function
))
4607 Lisp_Object val
= Qnil
;
4608 EMACS_INT pos
, limit
= -1;
4610 if (STRINGP (it
->string
))
4611 pos
= IT_STRING_CHARPOS (*it
);
4613 pos
= IT_CHARPOS (*it
);
4615 val
= Fget_text_property (make_number (pos
), Qauto_composed
, it
->string
);
4618 Lisp_Object cmp_prop
;
4619 EMACS_INT cmp_start
, cmp_end
;
4621 if (get_property_and_range (pos
, Qcomposition
, &cmp_prop
,
4622 &cmp_start
, &cmp_end
, it
->string
)
4624 && COMPOSITION_METHOD (cmp_prop
) == COMPOSITION_WITH_GLYPH_STRING
)
4626 Lisp_Object gstring
= COMPOSITION_COMPONENTS (cmp_prop
);
4627 Lisp_Object font_object
= LGSTRING_FONT (gstring
);
4629 if (! EQ (font_object
,
4630 font_at (-1, pos
, FACE_FROM_ID (it
->f
, it
->face_id
),
4631 it
->w
, it
->string
)))
4632 /* We must re-compute the composition for the
4641 /* As Fnext_single_char_property_change is very slow, we
4642 limit the search to the current line. */
4643 if (STRINGP (it
->string
))
4644 limit
= SCHARS (it
->string
);
4646 limit
= find_next_newline_no_quit (pos
, 1);
4647 end
= Fnext_single_char_property_change (make_number (pos
),
4650 make_number (limit
));
4652 if (XINT (end
) < limit
)
4653 /* The current point is auto-composed, but there exist
4654 characters not yet composed beyond the
4655 auto-composed region. There's a possiblity that
4656 the last characters in the region may be newly
4661 if (NILP (val
) && ! STRINGP (it
->string
))
4664 limit
= (STRINGP (it
->string
) ? SCHARS (it
->string
)
4665 : find_next_newline_no_quit (pos
, 1));
4668 int count
= SPECPDL_INDEX ();
4669 Lisp_Object args
[5];
4671 if (FRAME_WINDOW_P (it
->f
))
4672 limit
= font_range (pos
, limit
,
4673 FACE_FROM_ID (it
->f
, it
->face_id
),
4675 args
[0] = Vauto_composition_function
;
4676 specbind (Qauto_composition_function
, Qnil
);
4677 args
[1] = make_number (pos
);
4678 args
[2] = make_number (limit
);
4679 args
[3] = it
->window
;
4680 args
[4] = it
->string
;
4681 safe_call (5, args
);
4682 unbind_to (count
, Qnil
);
4690 /* Set up iterator IT from `composition' property at its current
4691 position. Called from handle_stop. */
4693 static enum prop_handled
4694 handle_composition_prop (it
)
4697 Lisp_Object prop
, string
;
4698 EMACS_INT pos
, pos_byte
, start
, end
;
4699 enum prop_handled handled
= HANDLED_NORMALLY
;
4701 if (STRINGP (it
->string
))
4705 pos
= IT_STRING_CHARPOS (*it
);
4706 pos_byte
= IT_STRING_BYTEPOS (*it
);
4707 string
= it
->string
;
4708 s
= SDATA (string
) + pos_byte
;
4709 it
->c
= STRING_CHAR (s
, 0);
4713 pos
= IT_CHARPOS (*it
);
4714 pos_byte
= IT_BYTEPOS (*it
);
4716 it
->c
= FETCH_CHAR (pos_byte
);
4719 /* If there's a valid composition and point is not inside of the
4720 composition (in the case that the composition is from the current
4721 buffer), draw a glyph composed from the composition components. */
4722 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4723 && COMPOSITION_VALID_P (start
, end
, prop
)
4724 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4730 if (STRINGP (it
->string
))
4731 pos_byte
= string_char_to_byte (it
->string
, start
);
4733 pos_byte
= CHAR_TO_BYTE (start
);
4735 id
= get_composition_id (start
, pos_byte
, end
- start
, prop
, string
);
4739 struct composition
*cmp
= composition_table
[id
];
4741 if (cmp
->glyph_len
== 0)
4744 if (STRINGP (it
->string
))
4746 IT_STRING_CHARPOS (*it
) = end
;
4747 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4752 IT_CHARPOS (*it
) = end
;
4753 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4755 return HANDLED_RECOMPUTE_PROPS
;
4758 it
->stop_charpos
= end
;
4761 it
->method
= GET_FROM_COMPOSITION
;
4763 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4764 /* For a terminal, draw only the first (non-TAB) character
4765 of the components. */
4766 if (composition_table
[id
]->method
== COMPOSITION_WITH_GLYPH_STRING
)
4768 /* FIXME: This doesn't do anything!?! */
4769 Lisp_Object lgstring
= AREF (XHASH_TABLE (composition_hash_table
)
4771 cmp
->hash_index
* 2);
4777 for (i
= 0; i
< cmp
->glyph_len
; i
++)
4778 if ((it
->c
= COMPOSITION_GLYPH (composition_table
[id
], i
))
4784 it
->len
= (STRINGP (it
->string
)
4785 ? string_char_to_byte (it
->string
, end
)
4786 : CHAR_TO_BYTE (end
)) - pos_byte
;
4787 handled
= HANDLED_RETURN
;
4796 /***********************************************************************
4798 ***********************************************************************/
4800 /* The following structure is used to record overlay strings for
4801 later sorting in load_overlay_strings. */
4803 struct overlay_entry
4805 Lisp_Object overlay
;
4812 /* Set up iterator IT from overlay strings at its current position.
4813 Called from handle_stop. */
4815 static enum prop_handled
4816 handle_overlay_change (it
)
4819 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4820 return HANDLED_RECOMPUTE_PROPS
;
4822 return HANDLED_NORMALLY
;
4826 /* Set up the next overlay string for delivery by IT, if there is an
4827 overlay string to deliver. Called by set_iterator_to_next when the
4828 end of the current overlay string is reached. If there are more
4829 overlay strings to display, IT->string and
4830 IT->current.overlay_string_index are set appropriately here.
4831 Otherwise IT->string is set to nil. */
4834 next_overlay_string (it
)
4837 ++it
->current
.overlay_string_index
;
4838 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4840 /* No more overlay strings. Restore IT's settings to what
4841 they were before overlay strings were processed, and
4842 continue to deliver from current_buffer. */
4843 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4847 || it
->method
== GET_FROM_COMPOSITION
4848 || (NILP (it
->string
)
4849 && it
->method
== GET_FROM_BUFFER
4850 && it
->stop_charpos
>= BEGV
4851 && it
->stop_charpos
<= it
->end_charpos
));
4852 it
->current
.overlay_string_index
= -1;
4853 it
->n_overlay_strings
= 0;
4855 /* If we're at the end of the buffer, record that we have
4856 processed the overlay strings there already, so that
4857 next_element_from_buffer doesn't try it again. */
4858 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4859 it
->overlay_strings_at_end_processed_p
= 1;
4861 /* If we have to display `...' for invisible text, set
4862 the iterator up for that. */
4863 if (display_ellipsis_p
)
4864 setup_for_ellipsis (it
, 0);
4868 /* There are more overlay strings to process. If
4869 IT->current.overlay_string_index has advanced to a position
4870 where we must load IT->overlay_strings with more strings, do
4872 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4874 if (it
->current
.overlay_string_index
&& i
== 0)
4875 load_overlay_strings (it
, 0);
4877 /* Initialize IT to deliver display elements from the overlay
4879 it
->string
= it
->overlay_strings
[i
];
4880 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4881 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4882 it
->method
= GET_FROM_STRING
;
4883 it
->stop_charpos
= 0;
4890 /* Compare two overlay_entry structures E1 and E2. Used as a
4891 comparison function for qsort in load_overlay_strings. Overlay
4892 strings for the same position are sorted so that
4894 1. All after-strings come in front of before-strings, except
4895 when they come from the same overlay.
4897 2. Within after-strings, strings are sorted so that overlay strings
4898 from overlays with higher priorities come first.
4900 2. Within before-strings, strings are sorted so that overlay
4901 strings from overlays with higher priorities come last.
4903 Value is analogous to strcmp. */
4907 compare_overlay_entries (e1
, e2
)
4910 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4911 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4914 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4916 /* Let after-strings appear in front of before-strings if
4917 they come from different overlays. */
4918 if (EQ (entry1
->overlay
, entry2
->overlay
))
4919 result
= entry1
->after_string_p
? 1 : -1;
4921 result
= entry1
->after_string_p
? -1 : 1;
4923 else if (entry1
->after_string_p
)
4924 /* After-strings sorted in order of decreasing priority. */
4925 result
= entry2
->priority
- entry1
->priority
;
4927 /* Before-strings sorted in order of increasing priority. */
4928 result
= entry1
->priority
- entry2
->priority
;
4934 /* Load the vector IT->overlay_strings with overlay strings from IT's
4935 current buffer position, or from CHARPOS if that is > 0. Set
4936 IT->n_overlays to the total number of overlay strings found.
4938 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4939 a time. On entry into load_overlay_strings,
4940 IT->current.overlay_string_index gives the number of overlay
4941 strings that have already been loaded by previous calls to this
4944 IT->add_overlay_start contains an additional overlay start
4945 position to consider for taking overlay strings from, if non-zero.
4946 This position comes into play when the overlay has an `invisible'
4947 property, and both before and after-strings. When we've skipped to
4948 the end of the overlay, because of its `invisible' property, we
4949 nevertheless want its before-string to appear.
4950 IT->add_overlay_start will contain the overlay start position
4953 Overlay strings are sorted so that after-string strings come in
4954 front of before-string strings. Within before and after-strings,
4955 strings are sorted by overlay priority. See also function
4956 compare_overlay_entries. */
4959 load_overlay_strings (it
, charpos
)
4963 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4964 Lisp_Object overlay
, window
, str
, invisible
;
4965 struct Lisp_Overlay
*ov
;
4968 int n
= 0, i
, j
, invis_p
;
4969 struct overlay_entry
*entries
4970 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4973 charpos
= IT_CHARPOS (*it
);
4975 /* Append the overlay string STRING of overlay OVERLAY to vector
4976 `entries' which has size `size' and currently contains `n'
4977 elements. AFTER_P non-zero means STRING is an after-string of
4979 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4982 Lisp_Object priority; \
4986 int new_size = 2 * size; \
4987 struct overlay_entry *old = entries; \
4989 (struct overlay_entry *) alloca (new_size \
4990 * sizeof *entries); \
4991 bcopy (old, entries, size * sizeof *entries); \
4995 entries[n].string = (STRING); \
4996 entries[n].overlay = (OVERLAY); \
4997 priority = Foverlay_get ((OVERLAY), Qpriority); \
4998 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4999 entries[n].after_string_p = (AFTER_P); \
5004 /* Process overlay before the overlay center. */
5005 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5007 XSETMISC (overlay
, ov
);
5008 xassert (OVERLAYP (overlay
));
5009 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5010 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5015 /* Skip this overlay if it doesn't start or end at IT's current
5017 if (end
!= charpos
&& start
!= charpos
)
5020 /* Skip this overlay if it doesn't apply to IT->w. */
5021 window
= Foverlay_get (overlay
, Qwindow
);
5022 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5025 /* If the text ``under'' the overlay is invisible, both before-
5026 and after-strings from this overlay are visible; start and
5027 end position are indistinguishable. */
5028 invisible
= Foverlay_get (overlay
, Qinvisible
);
5029 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5031 /* If overlay has a non-empty before-string, record it. */
5032 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5033 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5035 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5037 /* If overlay has a non-empty after-string, record it. */
5038 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5039 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5041 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5044 /* Process overlays after the overlay center. */
5045 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5047 XSETMISC (overlay
, ov
);
5048 xassert (OVERLAYP (overlay
));
5049 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5050 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5052 if (start
> charpos
)
5055 /* Skip this overlay if it doesn't start or end at IT's current
5057 if (end
!= charpos
&& start
!= charpos
)
5060 /* Skip this overlay if it doesn't apply to IT->w. */
5061 window
= Foverlay_get (overlay
, Qwindow
);
5062 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5065 /* If the text ``under'' the overlay is invisible, it has a zero
5066 dimension, and both before- and after-strings apply. */
5067 invisible
= Foverlay_get (overlay
, Qinvisible
);
5068 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5070 /* If overlay has a non-empty before-string, record it. */
5071 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5072 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5074 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5076 /* If overlay has a non-empty after-string, record it. */
5077 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5078 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5080 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5083 #undef RECORD_OVERLAY_STRING
5087 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5089 /* Record the total number of strings to process. */
5090 it
->n_overlay_strings
= n
;
5092 /* IT->current.overlay_string_index is the number of overlay strings
5093 that have already been consumed by IT. Copy some of the
5094 remaining overlay strings to IT->overlay_strings. */
5096 j
= it
->current
.overlay_string_index
;
5097 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5099 it
->overlay_strings
[i
] = entries
[j
].string
;
5100 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5107 /* Get the first chunk of overlay strings at IT's current buffer
5108 position, or at CHARPOS if that is > 0. Value is non-zero if at
5109 least one overlay string was found. */
5112 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5117 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5118 process. This fills IT->overlay_strings with strings, and sets
5119 IT->n_overlay_strings to the total number of strings to process.
5120 IT->pos.overlay_string_index has to be set temporarily to zero
5121 because load_overlay_strings needs this; it must be set to -1
5122 when no overlay strings are found because a zero value would
5123 indicate a position in the first overlay string. */
5124 it
->current
.overlay_string_index
= 0;
5125 load_overlay_strings (it
, charpos
);
5127 /* If we found overlay strings, set up IT to deliver display
5128 elements from the first one. Otherwise set up IT to deliver
5129 from current_buffer. */
5130 if (it
->n_overlay_strings
)
5132 /* Make sure we know settings in current_buffer, so that we can
5133 restore meaningful values when we're done with the overlay
5136 compute_stop_pos (it
);
5137 xassert (it
->face_id
>= 0);
5139 /* Save IT's settings. They are restored after all overlay
5140 strings have been processed. */
5141 xassert (!compute_stop_p
|| it
->sp
== 0);
5144 /* Set up IT to deliver display elements from the first overlay
5146 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5147 it
->string
= it
->overlay_strings
[0];
5148 it
->from_overlay
= Qnil
;
5149 it
->stop_charpos
= 0;
5150 xassert (STRINGP (it
->string
));
5151 it
->end_charpos
= SCHARS (it
->string
);
5152 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5153 it
->method
= GET_FROM_STRING
;
5157 it
->current
.overlay_string_index
= -1;
5162 get_overlay_strings (it
, charpos
)
5167 it
->method
= GET_FROM_BUFFER
;
5169 (void) get_overlay_strings_1 (it
, charpos
, 1);
5173 /* Value is non-zero if we found at least one overlay string. */
5174 return STRINGP (it
->string
);
5179 /***********************************************************************
5180 Saving and restoring state
5181 ***********************************************************************/
5183 /* Save current settings of IT on IT->stack. Called, for example,
5184 before setting up IT for an overlay string, to be able to restore
5185 IT's settings to what they were after the overlay string has been
5192 struct iterator_stack_entry
*p
;
5194 xassert (it
->sp
< IT_STACK_SIZE
);
5195 p
= it
->stack
+ it
->sp
;
5197 p
->stop_charpos
= it
->stop_charpos
;
5198 xassert (it
->face_id
>= 0);
5199 p
->face_id
= it
->face_id
;
5200 p
->string
= it
->string
;
5201 p
->method
= it
->method
;
5202 p
->from_overlay
= it
->from_overlay
;
5205 case GET_FROM_IMAGE
:
5206 p
->u
.image
.object
= it
->object
;
5207 p
->u
.image
.image_id
= it
->image_id
;
5208 p
->u
.image
.slice
= it
->slice
;
5210 case GET_FROM_COMPOSITION
:
5211 p
->u
.comp
.object
= it
->object
;
5212 p
->u
.comp
.c
= it
->c
;
5213 p
->u
.comp
.len
= it
->len
;
5214 p
->u
.comp
.cmp_id
= it
->cmp_id
;
5215 p
->u
.comp
.cmp_len
= it
->cmp_len
;
5217 case GET_FROM_STRETCH
:
5218 p
->u
.stretch
.object
= it
->object
;
5221 p
->position
= it
->position
;
5222 p
->current
= it
->current
;
5223 p
->end_charpos
= it
->end_charpos
;
5224 p
->string_nchars
= it
->string_nchars
;
5226 p
->multibyte_p
= it
->multibyte_p
;
5227 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5228 p
->space_width
= it
->space_width
;
5229 p
->font_height
= it
->font_height
;
5230 p
->voffset
= it
->voffset
;
5231 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5232 p
->display_ellipsis_p
= 0;
5237 /* Restore IT's settings from IT->stack. Called, for example, when no
5238 more overlay strings must be processed, and we return to delivering
5239 display elements from a buffer, or when the end of a string from a
5240 `display' property is reached and we return to delivering display
5241 elements from an overlay string, or from a buffer. */
5247 struct iterator_stack_entry
*p
;
5249 xassert (it
->sp
> 0);
5251 p
= it
->stack
+ it
->sp
;
5252 it
->stop_charpos
= p
->stop_charpos
;
5253 it
->face_id
= p
->face_id
;
5254 it
->current
= p
->current
;
5255 it
->position
= p
->position
;
5256 it
->string
= p
->string
;
5257 it
->from_overlay
= p
->from_overlay
;
5258 if (NILP (it
->string
))
5259 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5260 it
->method
= p
->method
;
5263 case GET_FROM_IMAGE
:
5264 it
->image_id
= p
->u
.image
.image_id
;
5265 it
->object
= p
->u
.image
.object
;
5266 it
->slice
= p
->u
.image
.slice
;
5268 case GET_FROM_COMPOSITION
:
5269 it
->object
= p
->u
.comp
.object
;
5270 it
->c
= p
->u
.comp
.c
;
5271 it
->len
= p
->u
.comp
.len
;
5272 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5273 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5275 case GET_FROM_STRETCH
:
5276 it
->object
= p
->u
.comp
.object
;
5278 case GET_FROM_BUFFER
:
5279 it
->object
= it
->w
->buffer
;
5281 case GET_FROM_STRING
:
5282 it
->object
= it
->string
;
5285 it
->end_charpos
= p
->end_charpos
;
5286 it
->string_nchars
= p
->string_nchars
;
5288 it
->multibyte_p
= p
->multibyte_p
;
5289 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5290 it
->space_width
= p
->space_width
;
5291 it
->font_height
= p
->font_height
;
5292 it
->voffset
= p
->voffset
;
5293 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5298 /***********************************************************************
5300 ***********************************************************************/
5302 /* Set IT's current position to the previous line start. */
5305 back_to_previous_line_start (it
)
5308 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5309 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5313 /* Move IT to the next line start.
5315 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5316 we skipped over part of the text (as opposed to moving the iterator
5317 continuously over the text). Otherwise, don't change the value
5320 Newlines may come from buffer text, overlay strings, or strings
5321 displayed via the `display' property. That's the reason we can't
5322 simply use find_next_newline_no_quit.
5324 Note that this function may not skip over invisible text that is so
5325 because of text properties and immediately follows a newline. If
5326 it would, function reseat_at_next_visible_line_start, when called
5327 from set_iterator_to_next, would effectively make invisible
5328 characters following a newline part of the wrong glyph row, which
5329 leads to wrong cursor motion. */
5332 forward_to_next_line_start (it
, skipped_p
)
5336 int old_selective
, newline_found_p
, n
;
5337 const int MAX_NEWLINE_DISTANCE
= 500;
5339 /* If already on a newline, just consume it to avoid unintended
5340 skipping over invisible text below. */
5341 if (it
->what
== IT_CHARACTER
5343 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5345 set_iterator_to_next (it
, 0);
5350 /* Don't handle selective display in the following. It's (a)
5351 unnecessary because it's done by the caller, and (b) leads to an
5352 infinite recursion because next_element_from_ellipsis indirectly
5353 calls this function. */
5354 old_selective
= it
->selective
;
5357 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5358 from buffer text. */
5359 for (n
= newline_found_p
= 0;
5360 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5361 n
+= STRINGP (it
->string
) ? 0 : 1)
5363 if (!get_next_display_element (it
))
5365 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5366 set_iterator_to_next (it
, 0);
5369 /* If we didn't find a newline near enough, see if we can use a
5371 if (!newline_found_p
)
5373 int start
= IT_CHARPOS (*it
);
5374 int limit
= find_next_newline_no_quit (start
, 1);
5377 xassert (!STRINGP (it
->string
));
5379 /* If there isn't any `display' property in sight, and no
5380 overlays, we can just use the position of the newline in
5382 if (it
->stop_charpos
>= limit
5383 || ((pos
= Fnext_single_property_change (make_number (start
),
5385 Qnil
, make_number (limit
)),
5387 && next_overlay_change (start
) == ZV
))
5389 IT_CHARPOS (*it
) = limit
;
5390 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5391 *skipped_p
= newline_found_p
= 1;
5395 while (get_next_display_element (it
)
5396 && !newline_found_p
)
5398 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5399 set_iterator_to_next (it
, 0);
5404 it
->selective
= old_selective
;
5405 return newline_found_p
;
5409 /* Set IT's current position to the previous visible line start. Skip
5410 invisible text that is so either due to text properties or due to
5411 selective display. Caution: this does not change IT->current_x and
5415 back_to_previous_visible_line_start (it
)
5418 while (IT_CHARPOS (*it
) > BEGV
)
5420 back_to_previous_line_start (it
);
5422 if (IT_CHARPOS (*it
) <= BEGV
)
5425 /* If selective > 0, then lines indented more than that values
5427 if (it
->selective
> 0
5428 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5429 (double) it
->selective
)) /* iftc */
5432 /* Check the newline before point for invisibility. */
5435 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5436 Qinvisible
, it
->window
);
5437 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5441 if (IT_CHARPOS (*it
) <= BEGV
)
5448 Lisp_Object val
, overlay
;
5450 /* If newline is part of a composition, continue from start of composition */
5451 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5452 && beg
< IT_CHARPOS (*it
))
5455 /* If newline is replaced by a display property, find start of overlay
5456 or interval and continue search from that point. */
5458 pos
= --IT_CHARPOS (it2
);
5461 it2
.string_from_display_prop_p
= 0;
5462 if (handle_display_prop (&it2
) == HANDLED_RETURN
5463 && !NILP (val
= get_char_property_and_overlay
5464 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5465 && (OVERLAYP (overlay
)
5466 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5467 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5470 /* Newline is not replaced by anything -- so we are done. */
5476 IT_CHARPOS (*it
) = beg
;
5477 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5481 it
->continuation_lines_width
= 0;
5483 xassert (IT_CHARPOS (*it
) >= BEGV
);
5484 xassert (IT_CHARPOS (*it
) == BEGV
5485 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5490 /* Reseat iterator IT at the previous visible line start. Skip
5491 invisible text that is so either due to text properties or due to
5492 selective display. At the end, update IT's overlay information,
5493 face information etc. */
5496 reseat_at_previous_visible_line_start (it
)
5499 back_to_previous_visible_line_start (it
);
5500 reseat (it
, it
->current
.pos
, 1);
5505 /* Reseat iterator IT on the next visible line start in the current
5506 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5507 preceding the line start. Skip over invisible text that is so
5508 because of selective display. Compute faces, overlays etc at the
5509 new position. Note that this function does not skip over text that
5510 is invisible because of text properties. */
5513 reseat_at_next_visible_line_start (it
, on_newline_p
)
5517 int newline_found_p
, skipped_p
= 0;
5519 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5521 /* Skip over lines that are invisible because they are indented
5522 more than the value of IT->selective. */
5523 if (it
->selective
> 0)
5524 while (IT_CHARPOS (*it
) < ZV
5525 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5526 (double) it
->selective
)) /* iftc */
5528 xassert (IT_BYTEPOS (*it
) == BEGV
5529 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5530 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5533 /* Position on the newline if that's what's requested. */
5534 if (on_newline_p
&& newline_found_p
)
5536 if (STRINGP (it
->string
))
5538 if (IT_STRING_CHARPOS (*it
) > 0)
5540 --IT_STRING_CHARPOS (*it
);
5541 --IT_STRING_BYTEPOS (*it
);
5544 else if (IT_CHARPOS (*it
) > BEGV
)
5548 reseat (it
, it
->current
.pos
, 0);
5552 reseat (it
, it
->current
.pos
, 0);
5559 /***********************************************************************
5560 Changing an iterator's position
5561 ***********************************************************************/
5563 /* Change IT's current position to POS in current_buffer. If FORCE_P
5564 is non-zero, always check for text properties at the new position.
5565 Otherwise, text properties are only looked up if POS >=
5566 IT->check_charpos of a property. */
5569 reseat (it
, pos
, force_p
)
5571 struct text_pos pos
;
5574 int original_pos
= IT_CHARPOS (*it
);
5576 reseat_1 (it
, pos
, 0);
5578 /* Determine where to check text properties. Avoid doing it
5579 where possible because text property lookup is very expensive. */
5581 || CHARPOS (pos
) > it
->stop_charpos
5582 || CHARPOS (pos
) < original_pos
)
5589 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5590 IT->stop_pos to POS, also. */
5593 reseat_1 (it
, pos
, set_stop_p
)
5595 struct text_pos pos
;
5598 /* Don't call this function when scanning a C string. */
5599 xassert (it
->s
== NULL
);
5601 /* POS must be a reasonable value. */
5602 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5604 it
->current
.pos
= it
->position
= pos
;
5605 it
->end_charpos
= ZV
;
5607 it
->current
.dpvec_index
= -1;
5608 it
->current
.overlay_string_index
= -1;
5609 IT_STRING_CHARPOS (*it
) = -1;
5610 IT_STRING_BYTEPOS (*it
) = -1;
5612 it
->string_from_display_prop_p
= 0;
5613 it
->method
= GET_FROM_BUFFER
;
5614 it
->object
= it
->w
->buffer
;
5615 it
->area
= TEXT_AREA
;
5616 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5618 it
->string_from_display_prop_p
= 0;
5619 it
->face_before_selective_p
= 0;
5622 it
->stop_charpos
= CHARPOS (pos
);
5626 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5627 If S is non-null, it is a C string to iterate over. Otherwise,
5628 STRING gives a Lisp string to iterate over.
5630 If PRECISION > 0, don't return more then PRECISION number of
5631 characters from the string.
5633 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5634 characters have been returned. FIELD_WIDTH < 0 means an infinite
5637 MULTIBYTE = 0 means disable processing of multibyte characters,
5638 MULTIBYTE > 0 means enable it,
5639 MULTIBYTE < 0 means use IT->multibyte_p.
5641 IT must be initialized via a prior call to init_iterator before
5642 calling this function. */
5645 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5650 int precision
, field_width
, multibyte
;
5652 /* No region in strings. */
5653 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5655 /* No text property checks performed by default, but see below. */
5656 it
->stop_charpos
= -1;
5658 /* Set iterator position and end position. */
5659 bzero (&it
->current
, sizeof it
->current
);
5660 it
->current
.overlay_string_index
= -1;
5661 it
->current
.dpvec_index
= -1;
5662 xassert (charpos
>= 0);
5664 /* If STRING is specified, use its multibyteness, otherwise use the
5665 setting of MULTIBYTE, if specified. */
5667 it
->multibyte_p
= multibyte
> 0;
5671 xassert (STRINGP (string
));
5672 it
->string
= string
;
5674 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5675 it
->method
= GET_FROM_STRING
;
5676 it
->current
.string_pos
= string_pos (charpos
, string
);
5683 /* Note that we use IT->current.pos, not it->current.string_pos,
5684 for displaying C strings. */
5685 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5686 if (it
->multibyte_p
)
5688 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5689 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5693 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5694 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5697 it
->method
= GET_FROM_C_STRING
;
5700 /* PRECISION > 0 means don't return more than PRECISION characters
5702 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5703 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5705 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5706 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5707 FIELD_WIDTH < 0 means infinite field width. This is useful for
5708 padding with `-' at the end of a mode line. */
5709 if (field_width
< 0)
5710 field_width
= INFINITY
;
5711 if (field_width
> it
->end_charpos
- charpos
)
5712 it
->end_charpos
= charpos
+ field_width
;
5714 /* Use the standard display table for displaying strings. */
5715 if (DISP_TABLE_P (Vstandard_display_table
))
5716 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5718 it
->stop_charpos
= charpos
;
5724 /***********************************************************************
5726 ***********************************************************************/
5728 /* Map enum it_method value to corresponding next_element_from_* function. */
5730 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5732 next_element_from_buffer
,
5733 next_element_from_display_vector
,
5734 next_element_from_composition
,
5735 next_element_from_string
,
5736 next_element_from_c_string
,
5737 next_element_from_image
,
5738 next_element_from_stretch
5741 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5743 /* Load IT's display element fields with information about the next
5744 display element from the current position of IT. Value is zero if
5745 end of buffer (or C string) is reached. */
5747 static struct frame
*last_escape_glyph_frame
= NULL
;
5748 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5749 static int last_escape_glyph_merged_face_id
= 0;
5752 get_next_display_element (it
)
5755 /* Non-zero means that we found a display element. Zero means that
5756 we hit the end of what we iterate over. Performance note: the
5757 function pointer `method' used here turns out to be faster than
5758 using a sequence of if-statements. */
5762 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5764 if (it
->what
== IT_CHARACTER
)
5766 /* Map via display table or translate control characters.
5767 IT->c, IT->len etc. have been set to the next character by
5768 the function call above. If we have a display table, and it
5769 contains an entry for IT->c, translate it. Don't do this if
5770 IT->c itself comes from a display table, otherwise we could
5771 end up in an infinite recursion. (An alternative could be to
5772 count the recursion depth of this function and signal an
5773 error when a certain maximum depth is reached.) Is it worth
5775 if (success_p
&& it
->dpvec
== NULL
)
5780 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5783 struct Lisp_Vector
*v
= XVECTOR (dv
);
5785 /* Return the first character from the display table
5786 entry, if not empty. If empty, don't display the
5787 current character. */
5790 it
->dpvec_char_len
= it
->len
;
5791 it
->dpvec
= v
->contents
;
5792 it
->dpend
= v
->contents
+ v
->size
;
5793 it
->current
.dpvec_index
= 0;
5794 it
->dpvec_face_id
= -1;
5795 it
->saved_face_id
= it
->face_id
;
5796 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5801 set_iterator_to_next (it
, 0);
5806 /* Translate control characters into `\003' or `^C' form.
5807 Control characters coming from a display table entry are
5808 currently not translated because we use IT->dpvec to hold
5809 the translation. This could easily be changed but I
5810 don't believe that it is worth doing.
5812 If it->multibyte_p is nonzero, non-printable non-ASCII
5813 characters are also translated to octal form.
5815 If it->multibyte_p is zero, eight-bit characters that
5816 don't have corresponding multibyte char code are also
5817 translated to octal form. */
5818 else if ((it
->c
< ' '
5819 ? (it
->area
!= TEXT_AREA
5820 /* In mode line, treat \n, \t like other crl chars. */
5822 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5823 || (it
->c
!= '\n' && it
->c
!= '\t'))
5825 ? (!CHAR_PRINTABLE_P (it
->c
)
5826 || (!NILP (Vnobreak_char_display
)
5827 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5828 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5830 && (! unibyte_display_via_language_environment
5831 || (UNIBYTE_CHAR_HAS_MULTIBYTE_P (it
->c
)))))))
5833 /* IT->c is a control character which must be displayed
5834 either as '\003' or as `^C' where the '\\' and '^'
5835 can be defined in the display table. Fill
5836 IT->ctl_chars with glyphs for what we have to
5837 display. Then, set IT->dpvec to these glyphs. */
5840 int face_id
, lface_id
= 0 ;
5843 /* Handle control characters with ^. */
5845 if (it
->c
< 128 && it
->ctl_arrow_p
)
5849 g
= '^'; /* default glyph for Control */
5850 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5852 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5853 && GLYPH_CODE_CHAR_VALID_P (gc
))
5855 g
= GLYPH_CODE_CHAR (gc
);
5856 lface_id
= GLYPH_CODE_FACE (gc
);
5860 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5862 else if (it
->f
== last_escape_glyph_frame
5863 && it
->face_id
== last_escape_glyph_face_id
)
5865 face_id
= last_escape_glyph_merged_face_id
;
5869 /* Merge the escape-glyph face into the current face. */
5870 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5872 last_escape_glyph_frame
= it
->f
;
5873 last_escape_glyph_face_id
= it
->face_id
;
5874 last_escape_glyph_merged_face_id
= face_id
;
5877 XSETINT (it
->ctl_chars
[0], g
);
5878 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5880 goto display_control
;
5883 /* Handle non-break space in the mode where it only gets
5886 if (EQ (Vnobreak_char_display
, Qt
)
5889 /* Merge the no-break-space face into the current face. */
5890 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5894 XSETINT (it
->ctl_chars
[0], ' ');
5896 goto display_control
;
5899 /* Handle sequences that start with the "escape glyph". */
5901 /* the default escape glyph is \. */
5902 escape_glyph
= '\\';
5905 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5906 && GLYPH_CODE_CHAR_VALID_P (gc
))
5908 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5909 lface_id
= GLYPH_CODE_FACE (gc
);
5913 /* The display table specified a face.
5914 Merge it into face_id and also into escape_glyph. */
5915 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5918 else if (it
->f
== last_escape_glyph_frame
5919 && it
->face_id
== last_escape_glyph_face_id
)
5921 face_id
= last_escape_glyph_merged_face_id
;
5925 /* Merge the escape-glyph face into the current face. */
5926 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5928 last_escape_glyph_frame
= it
->f
;
5929 last_escape_glyph_face_id
= it
->face_id
;
5930 last_escape_glyph_merged_face_id
= face_id
;
5933 /* Handle soft hyphens in the mode where they only get
5936 if (EQ (Vnobreak_char_display
, Qt
)
5940 XSETINT (it
->ctl_chars
[0], '-');
5942 goto display_control
;
5945 /* Handle non-break space and soft hyphen
5946 with the escape glyph. */
5948 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5950 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5951 it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5952 XSETINT (it
->ctl_chars
[1], it
->c
);
5954 goto display_control
;
5958 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5962 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5963 if (CHAR_BYTE8_P (it
->c
))
5965 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5968 else if (it
->c
< 256)
5975 /* It's an invalid character, which shouldn't
5976 happen actually, but due to bugs it may
5977 happen. Let's print the char as is, there's
5978 not much meaningful we can do with it. */
5980 str
[1] = it
->c
>> 8;
5981 str
[2] = it
->c
>> 16;
5982 str
[3] = it
->c
>> 24;
5986 for (i
= 0; i
< len
; i
++)
5989 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5990 /* Insert three more glyphs into IT->ctl_chars for
5991 the octal display of the character. */
5992 g
= ((str
[i
] >> 6) & 7) + '0';
5993 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5994 g
= ((str
[i
] >> 3) & 7) + '0';
5995 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5996 g
= (str
[i
] & 7) + '0';
5997 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
6003 /* Set up IT->dpvec and return first character from it. */
6004 it
->dpvec_char_len
= it
->len
;
6005 it
->dpvec
= it
->ctl_chars
;
6006 it
->dpend
= it
->dpvec
+ ctl_len
;
6007 it
->current
.dpvec_index
= 0;
6008 it
->dpvec_face_id
= face_id
;
6009 it
->saved_face_id
= it
->face_id
;
6010 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6017 /* Adjust face id for a multibyte character. There are no multibyte
6018 character in unibyte text. */
6019 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6022 && FRAME_WINDOW_P (it
->f
))
6024 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6025 int pos
= (it
->s
? -1
6026 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6027 : IT_CHARPOS (*it
));
6029 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
6032 /* Is this character the last one of a run of characters with
6033 box? If yes, set IT->end_of_box_run_p to 1. */
6040 it
->end_of_box_run_p
6041 = ((face_id
= face_after_it_pos (it
),
6042 face_id
!= it
->face_id
)
6043 && (face
= FACE_FROM_ID (it
->f
, face_id
),
6044 face
->box
== FACE_NO_BOX
));
6047 /* Value is 0 if end of buffer or string reached. */
6052 /* Move IT to the next display element.
6054 RESEAT_P non-zero means if called on a newline in buffer text,
6055 skip to the next visible line start.
6057 Functions get_next_display_element and set_iterator_to_next are
6058 separate because I find this arrangement easier to handle than a
6059 get_next_display_element function that also increments IT's
6060 position. The way it is we can first look at an iterator's current
6061 display element, decide whether it fits on a line, and if it does,
6062 increment the iterator position. The other way around we probably
6063 would either need a flag indicating whether the iterator has to be
6064 incremented the next time, or we would have to implement a
6065 decrement position function which would not be easy to write. */
6068 set_iterator_to_next (it
, reseat_p
)
6072 /* Reset flags indicating start and end of a sequence of characters
6073 with box. Reset them at the start of this function because
6074 moving the iterator to a new position might set them. */
6075 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6079 case GET_FROM_BUFFER
:
6080 /* The current display element of IT is a character from
6081 current_buffer. Advance in the buffer, and maybe skip over
6082 invisible lines that are so because of selective display. */
6083 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6084 reseat_at_next_visible_line_start (it
, 0);
6087 xassert (it
->len
!= 0);
6088 IT_BYTEPOS (*it
) += it
->len
;
6089 IT_CHARPOS (*it
) += 1;
6090 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6094 case GET_FROM_COMPOSITION
:
6095 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
6096 xassert (it
->sp
> 0);
6098 if (it
->method
== GET_FROM_STRING
)
6100 IT_STRING_BYTEPOS (*it
) += it
->len
;
6101 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
6102 goto consider_string_end
;
6104 else if (it
->method
== GET_FROM_BUFFER
)
6106 IT_BYTEPOS (*it
) += it
->len
;
6107 IT_CHARPOS (*it
) += it
->cmp_len
;
6111 case GET_FROM_C_STRING
:
6112 /* Current display element of IT is from a C string. */
6113 IT_BYTEPOS (*it
) += it
->len
;
6114 IT_CHARPOS (*it
) += 1;
6117 case GET_FROM_DISPLAY_VECTOR
:
6118 /* Current display element of IT is from a display table entry.
6119 Advance in the display table definition. Reset it to null if
6120 end reached, and continue with characters from buffers/
6122 ++it
->current
.dpvec_index
;
6124 /* Restore face of the iterator to what they were before the
6125 display vector entry (these entries may contain faces). */
6126 it
->face_id
= it
->saved_face_id
;
6128 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6130 int recheck_faces
= it
->ellipsis_p
;
6133 it
->method
= GET_FROM_C_STRING
;
6134 else if (STRINGP (it
->string
))
6135 it
->method
= GET_FROM_STRING
;
6138 it
->method
= GET_FROM_BUFFER
;
6139 it
->object
= it
->w
->buffer
;
6143 it
->current
.dpvec_index
= -1;
6145 /* Skip over characters which were displayed via IT->dpvec. */
6146 if (it
->dpvec_char_len
< 0)
6147 reseat_at_next_visible_line_start (it
, 1);
6148 else if (it
->dpvec_char_len
> 0)
6150 if (it
->method
== GET_FROM_STRING
6151 && it
->n_overlay_strings
> 0)
6152 it
->ignore_overlay_strings_at_pos_p
= 1;
6153 it
->len
= it
->dpvec_char_len
;
6154 set_iterator_to_next (it
, reseat_p
);
6157 /* Maybe recheck faces after display vector */
6159 it
->stop_charpos
= IT_CHARPOS (*it
);
6163 case GET_FROM_STRING
:
6164 /* Current display element is a character from a Lisp string. */
6165 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6166 IT_STRING_BYTEPOS (*it
) += it
->len
;
6167 IT_STRING_CHARPOS (*it
) += 1;
6169 consider_string_end
:
6171 if (it
->current
.overlay_string_index
>= 0)
6173 /* IT->string is an overlay string. Advance to the
6174 next, if there is one. */
6175 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6176 next_overlay_string (it
);
6180 /* IT->string is not an overlay string. If we reached
6181 its end, and there is something on IT->stack, proceed
6182 with what is on the stack. This can be either another
6183 string, this time an overlay string, or a buffer. */
6184 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6188 if (it
->method
== GET_FROM_STRING
)
6189 goto consider_string_end
;
6194 case GET_FROM_IMAGE
:
6195 case GET_FROM_STRETCH
:
6196 /* The position etc with which we have to proceed are on
6197 the stack. The position may be at the end of a string,
6198 if the `display' property takes up the whole string. */
6199 xassert (it
->sp
> 0);
6201 if (it
->method
== GET_FROM_STRING
)
6202 goto consider_string_end
;
6206 /* There are no other methods defined, so this should be a bug. */
6210 xassert (it
->method
!= GET_FROM_STRING
6211 || (STRINGP (it
->string
)
6212 && IT_STRING_CHARPOS (*it
) >= 0));
6215 /* Load IT's display element fields with information about the next
6216 display element which comes from a display table entry or from the
6217 result of translating a control character to one of the forms `^C'
6220 IT->dpvec holds the glyphs to return as characters.
6221 IT->saved_face_id holds the face id before the display vector--
6222 it is restored into IT->face_idin set_iterator_to_next. */
6225 next_element_from_display_vector (it
)
6231 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6233 it
->face_id
= it
->saved_face_id
;
6235 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6236 That seemed totally bogus - so I changed it... */
6237 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6239 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6241 it
->c
= GLYPH_CODE_CHAR (gc
);
6242 it
->len
= CHAR_BYTES (it
->c
);
6244 /* The entry may contain a face id to use. Such a face id is
6245 the id of a Lisp face, not a realized face. A face id of
6246 zero means no face is specified. */
6247 if (it
->dpvec_face_id
>= 0)
6248 it
->face_id
= it
->dpvec_face_id
;
6251 int lface_id
= GLYPH_CODE_FACE (gc
);
6253 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6258 /* Display table entry is invalid. Return a space. */
6259 it
->c
= ' ', it
->len
= 1;
6261 /* Don't change position and object of the iterator here. They are
6262 still the values of the character that had this display table
6263 entry or was translated, and that's what we want. */
6264 it
->what
= IT_CHARACTER
;
6269 /* Load IT with the next display element from Lisp string IT->string.
6270 IT->current.string_pos is the current position within the string.
6271 If IT->current.overlay_string_index >= 0, the Lisp string is an
6275 next_element_from_string (it
)
6278 struct text_pos position
;
6280 xassert (STRINGP (it
->string
));
6281 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6282 position
= it
->current
.string_pos
;
6284 /* Time to check for invisible text? */
6285 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6286 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6290 /* Since a handler may have changed IT->method, we must
6292 return GET_NEXT_DISPLAY_ELEMENT (it
);
6295 if (it
->current
.overlay_string_index
>= 0)
6297 /* Get the next character from an overlay string. In overlay
6298 strings, There is no field width or padding with spaces to
6300 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6305 else if (STRING_MULTIBYTE (it
->string
))
6307 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6308 const unsigned char *s
= (SDATA (it
->string
)
6309 + IT_STRING_BYTEPOS (*it
));
6310 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6314 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6320 /* Get the next character from a Lisp string that is not an
6321 overlay string. Such strings come from the mode line, for
6322 example. We may have to pad with spaces, or truncate the
6323 string. See also next_element_from_c_string. */
6324 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6329 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6331 /* Pad with spaces. */
6332 it
->c
= ' ', it
->len
= 1;
6333 CHARPOS (position
) = BYTEPOS (position
) = -1;
6335 else if (STRING_MULTIBYTE (it
->string
))
6337 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6338 const unsigned char *s
= (SDATA (it
->string
)
6339 + IT_STRING_BYTEPOS (*it
));
6340 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6344 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6349 /* Record what we have and where it came from. */
6350 it
->what
= IT_CHARACTER
;
6351 it
->object
= it
->string
;
6352 it
->position
= position
;
6357 /* Load IT with next display element from C string IT->s.
6358 IT->string_nchars is the maximum number of characters to return
6359 from the string. IT->end_charpos may be greater than
6360 IT->string_nchars when this function is called, in which case we
6361 may have to return padding spaces. Value is zero if end of string
6362 reached, including padding spaces. */
6365 next_element_from_c_string (it
)
6371 it
->what
= IT_CHARACTER
;
6372 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6375 /* IT's position can be greater IT->string_nchars in case a field
6376 width or precision has been specified when the iterator was
6378 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6380 /* End of the game. */
6384 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6386 /* Pad with spaces. */
6387 it
->c
= ' ', it
->len
= 1;
6388 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6390 else if (it
->multibyte_p
)
6392 /* Implementation note: The calls to strlen apparently aren't a
6393 performance problem because there is no noticeable performance
6394 difference between Emacs running in unibyte or multibyte mode. */
6395 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6396 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6400 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6406 /* Set up IT to return characters from an ellipsis, if appropriate.
6407 The definition of the ellipsis glyphs may come from a display table
6408 entry. This function Fills IT with the first glyph from the
6409 ellipsis if an ellipsis is to be displayed. */
6412 next_element_from_ellipsis (it
)
6415 if (it
->selective_display_ellipsis_p
)
6416 setup_for_ellipsis (it
, it
->len
);
6419 /* The face at the current position may be different from the
6420 face we find after the invisible text. Remember what it
6421 was in IT->saved_face_id, and signal that it's there by
6422 setting face_before_selective_p. */
6423 it
->saved_face_id
= it
->face_id
;
6424 it
->method
= GET_FROM_BUFFER
;
6425 it
->object
= it
->w
->buffer
;
6426 reseat_at_next_visible_line_start (it
, 1);
6427 it
->face_before_selective_p
= 1;
6430 return GET_NEXT_DISPLAY_ELEMENT (it
);
6434 /* Deliver an image display element. The iterator IT is already
6435 filled with image information (done in handle_display_prop). Value
6440 next_element_from_image (it
)
6443 it
->what
= IT_IMAGE
;
6448 /* Fill iterator IT with next display element from a stretch glyph
6449 property. IT->object is the value of the text property. Value is
6453 next_element_from_stretch (it
)
6456 it
->what
= IT_STRETCH
;
6461 /* Load IT with the next display element from current_buffer. Value
6462 is zero if end of buffer reached. IT->stop_charpos is the next
6463 position at which to stop and check for text properties or buffer
6467 next_element_from_buffer (it
)
6472 /* Check this assumption, otherwise, we would never enter the
6473 if-statement, below. */
6474 xassert (IT_CHARPOS (*it
) >= BEGV
6475 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6477 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6479 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6481 int overlay_strings_follow_p
;
6483 /* End of the game, except when overlay strings follow that
6484 haven't been returned yet. */
6485 if (it
->overlay_strings_at_end_processed_p
)
6486 overlay_strings_follow_p
= 0;
6489 it
->overlay_strings_at_end_processed_p
= 1;
6490 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6493 if (overlay_strings_follow_p
)
6494 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6498 it
->position
= it
->current
.pos
;
6505 return GET_NEXT_DISPLAY_ELEMENT (it
);
6510 /* No face changes, overlays etc. in sight, so just return a
6511 character from current_buffer. */
6514 /* Maybe run the redisplay end trigger hook. Performance note:
6515 This doesn't seem to cost measurable time. */
6516 if (it
->redisplay_end_trigger_charpos
6518 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6519 run_redisplay_end_trigger_hook (it
);
6521 /* Get the next character, maybe multibyte. */
6522 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6523 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6525 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6526 - IT_BYTEPOS (*it
));
6527 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6530 it
->c
= *p
, it
->len
= 1;
6532 /* Record what we have and where it came from. */
6533 it
->what
= IT_CHARACTER
;
6534 it
->object
= it
->w
->buffer
;
6535 it
->position
= it
->current
.pos
;
6537 /* Normally we return the character found above, except when we
6538 really want to return an ellipsis for selective display. */
6543 /* A value of selective > 0 means hide lines indented more
6544 than that number of columns. */
6545 if (it
->selective
> 0
6546 && IT_CHARPOS (*it
) + 1 < ZV
6547 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6548 IT_BYTEPOS (*it
) + 1,
6549 (double) it
->selective
)) /* iftc */
6551 success_p
= next_element_from_ellipsis (it
);
6552 it
->dpvec_char_len
= -1;
6555 else if (it
->c
== '\r' && it
->selective
== -1)
6557 /* A value of selective == -1 means that everything from the
6558 CR to the end of the line is invisible, with maybe an
6559 ellipsis displayed for it. */
6560 success_p
= next_element_from_ellipsis (it
);
6561 it
->dpvec_char_len
= -1;
6566 /* Value is zero if end of buffer reached. */
6567 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6572 /* Run the redisplay end trigger hook for IT. */
6575 run_redisplay_end_trigger_hook (it
)
6578 Lisp_Object args
[3];
6580 /* IT->glyph_row should be non-null, i.e. we should be actually
6581 displaying something, or otherwise we should not run the hook. */
6582 xassert (it
->glyph_row
);
6584 /* Set up hook arguments. */
6585 args
[0] = Qredisplay_end_trigger_functions
;
6586 args
[1] = it
->window
;
6587 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6588 it
->redisplay_end_trigger_charpos
= 0;
6590 /* Since we are *trying* to run these functions, don't try to run
6591 them again, even if they get an error. */
6592 it
->w
->redisplay_end_trigger
= Qnil
;
6593 Frun_hook_with_args (3, args
);
6595 /* Notice if it changed the face of the character we are on. */
6596 handle_face_prop (it
);
6600 /* Deliver a composition display element. The iterator IT is already
6601 filled with composition information (done in
6602 handle_composition_prop). Value is always 1. */
6605 next_element_from_composition (it
)
6608 it
->what
= IT_COMPOSITION
;
6609 it
->position
= (STRINGP (it
->string
)
6610 ? it
->current
.string_pos
6612 if (STRINGP (it
->string
))
6613 it
->object
= it
->string
;
6615 it
->object
= it
->w
->buffer
;
6621 /***********************************************************************
6622 Moving an iterator without producing glyphs
6623 ***********************************************************************/
6625 /* Check if iterator is at a position corresponding to a valid buffer
6626 position after some move_it_ call. */
6628 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6629 ((it)->method == GET_FROM_STRING \
6630 ? IT_STRING_CHARPOS (*it) == 0 \
6634 /* Move iterator IT to a specified buffer or X position within one
6635 line on the display without producing glyphs.
6637 OP should be a bit mask including some or all of these bits:
6638 MOVE_TO_X: Stop on reaching x-position TO_X.
6639 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6640 Regardless of OP's value, stop in reaching the end of the display line.
6642 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6643 This means, in particular, that TO_X includes window's horizontal
6646 The return value has several possible values that
6647 say what condition caused the scan to stop:
6649 MOVE_POS_MATCH_OR_ZV
6650 - when TO_POS or ZV was reached.
6653 -when TO_X was reached before TO_POS or ZV were reached.
6656 - when we reached the end of the display area and the line must
6660 - when we reached the end of the display area and the line is
6664 - when we stopped at a line end, i.e. a newline or a CR and selective
6667 static enum move_it_result
6668 move_it_in_display_line_to (struct it
*it
,
6669 EMACS_INT to_charpos
, int to_x
,
6670 enum move_operation_enum op
)
6672 enum move_it_result result
= MOVE_UNDEFINED
;
6673 struct glyph_row
*saved_glyph_row
;
6674 struct it wrap_it
, atpos_it
, atx_it
;
6677 /* Don't produce glyphs in produce_glyphs. */
6678 saved_glyph_row
= it
->glyph_row
;
6679 it
->glyph_row
= NULL
;
6681 /* Use wrap_it to save a copy of IT wherever a word wrap could
6682 occur. Use atpos_it to save a copy of IT at the desired buffer
6683 position, if found, so that we can scan ahead and check if the
6684 word later overshoots the window edge. Use atx_it similarly, for
6690 #define BUFFER_POS_REACHED_P() \
6691 ((op & MOVE_TO_POS) != 0 \
6692 && BUFFERP (it->object) \
6693 && IT_CHARPOS (*it) >= to_charpos \
6694 && (it->method == GET_FROM_BUFFER \
6695 || (it->method == GET_FROM_DISPLAY_VECTOR \
6696 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6698 /* If there's a line-/wrap-prefix, handle it. */
6699 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6700 && it
->current_y
< it
->last_visible_y
)
6701 handle_line_prefix (it
);
6705 int x
, i
, ascent
= 0, descent
= 0;
6707 /* Utility macro to reset an iterator with x, ascent, and descent. */
6708 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6709 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6710 (IT)->max_descent = descent)
6712 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6714 if ((op
& MOVE_TO_POS
) != 0
6715 && BUFFERP (it
->object
)
6716 && it
->method
== GET_FROM_BUFFER
6717 && IT_CHARPOS (*it
) > to_charpos
)
6719 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6721 result
= MOVE_POS_MATCH_OR_ZV
;
6724 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6725 /* If wrap_it is valid, the current position might be in a
6726 word that is wrapped. So, save the iterator in
6727 atpos_it and continue to see if wrapping happens. */
6731 /* Stop when ZV reached.
6732 We used to stop here when TO_CHARPOS reached as well, but that is
6733 too soon if this glyph does not fit on this line. So we handle it
6734 explicitly below. */
6735 if (!get_next_display_element (it
))
6737 result
= MOVE_POS_MATCH_OR_ZV
;
6741 if (it
->line_wrap
== TRUNCATE
)
6743 if (BUFFER_POS_REACHED_P ())
6745 result
= MOVE_POS_MATCH_OR_ZV
;
6751 if (it
->line_wrap
== WORD_WRAP
)
6753 if (IT_DISPLAYING_WHITESPACE (it
))
6757 /* We have reached a glyph that follows one or more
6758 whitespace characters. If the position is
6759 already found, we are done. */
6760 if (atpos_it
.sp
>= 0)
6763 result
= MOVE_POS_MATCH_OR_ZV
;
6769 result
= MOVE_X_REACHED
;
6772 /* Otherwise, we can wrap here. */
6779 /* Remember the line height for the current line, in case
6780 the next element doesn't fit on the line. */
6781 ascent
= it
->max_ascent
;
6782 descent
= it
->max_descent
;
6784 /* The call to produce_glyphs will get the metrics of the
6785 display element IT is loaded with. Record the x-position
6786 before this display element, in case it doesn't fit on the
6790 PRODUCE_GLYPHS (it
);
6792 if (it
->area
!= TEXT_AREA
)
6794 set_iterator_to_next (it
, 1);
6798 /* The number of glyphs we get back in IT->nglyphs will normally
6799 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6800 character on a terminal frame, or (iii) a line end. For the
6801 second case, IT->nglyphs - 1 padding glyphs will be present
6802 (on X frames, there is only one glyph produced for a
6803 composite character.
6805 The behavior implemented below means, for continuation lines,
6806 that as many spaces of a TAB as fit on the current line are
6807 displayed there. For terminal frames, as many glyphs of a
6808 multi-glyph character are displayed in the current line, too.
6809 This is what the old redisplay code did, and we keep it that
6810 way. Under X, the whole shape of a complex character must
6811 fit on the line or it will be completely displayed in the
6814 Note that both for tabs and padding glyphs, all glyphs have
6818 /* More than one glyph or glyph doesn't fit on line. All
6819 glyphs have the same width. */
6820 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6822 int x_before_this_char
= x
;
6823 int hpos_before_this_char
= it
->hpos
;
6825 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6827 new_x
= x
+ single_glyph_width
;
6829 /* We want to leave anything reaching TO_X to the caller. */
6830 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6832 if (BUFFER_POS_REACHED_P ())
6834 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6835 goto buffer_pos_reached
;
6836 if (atpos_it
.sp
< 0)
6839 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6844 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6847 result
= MOVE_X_REACHED
;
6853 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6858 if (/* Lines are continued. */
6859 it
->line_wrap
!= TRUNCATE
6860 && (/* And glyph doesn't fit on the line. */
6861 new_x
> it
->last_visible_x
6862 /* Or it fits exactly and we're on a window
6864 || (new_x
== it
->last_visible_x
6865 && FRAME_WINDOW_P (it
->f
))))
6867 if (/* IT->hpos == 0 means the very first glyph
6868 doesn't fit on the line, e.g. a wide image. */
6870 || (new_x
== it
->last_visible_x
6871 && FRAME_WINDOW_P (it
->f
)))
6874 it
->current_x
= new_x
;
6876 /* The character's last glyph just barely fits
6878 if (i
== it
->nglyphs
- 1)
6880 /* If this is the destination position,
6881 return a position *before* it in this row,
6882 now that we know it fits in this row. */
6883 if (BUFFER_POS_REACHED_P ())
6885 if (it
->line_wrap
!= WORD_WRAP
6888 it
->hpos
= hpos_before_this_char
;
6889 it
->current_x
= x_before_this_char
;
6890 result
= MOVE_POS_MATCH_OR_ZV
;
6893 if (it
->line_wrap
== WORD_WRAP
6897 atpos_it
.current_x
= x_before_this_char
;
6898 atpos_it
.hpos
= hpos_before_this_char
;
6902 set_iterator_to_next (it
, 1);
6903 #ifdef HAVE_WINDOW_SYSTEM
6904 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6906 if (!get_next_display_element (it
))
6908 result
= MOVE_POS_MATCH_OR_ZV
;
6911 if (BUFFER_POS_REACHED_P ())
6913 if (ITERATOR_AT_END_OF_LINE_P (it
))
6914 result
= MOVE_POS_MATCH_OR_ZV
;
6916 result
= MOVE_LINE_CONTINUED
;
6919 if (ITERATOR_AT_END_OF_LINE_P (it
))
6921 result
= MOVE_NEWLINE_OR_CR
;
6925 #endif /* HAVE_WINDOW_SYSTEM */
6929 IT_RESET_X_ASCENT_DESCENT (it
);
6931 if (wrap_it
.sp
>= 0)
6938 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6940 result
= MOVE_LINE_CONTINUED
;
6944 if (BUFFER_POS_REACHED_P ())
6946 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6947 goto buffer_pos_reached
;
6948 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6951 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6955 if (new_x
> it
->first_visible_x
)
6957 /* Glyph is visible. Increment number of glyphs that
6958 would be displayed. */
6963 if (result
!= MOVE_UNDEFINED
)
6966 else if (BUFFER_POS_REACHED_P ())
6969 IT_RESET_X_ASCENT_DESCENT (it
);
6970 result
= MOVE_POS_MATCH_OR_ZV
;
6973 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6975 /* Stop when TO_X specified and reached. This check is
6976 necessary here because of lines consisting of a line end,
6977 only. The line end will not produce any glyphs and we
6978 would never get MOVE_X_REACHED. */
6979 xassert (it
->nglyphs
== 0);
6980 result
= MOVE_X_REACHED
;
6984 /* Is this a line end? If yes, we're done. */
6985 if (ITERATOR_AT_END_OF_LINE_P (it
))
6987 result
= MOVE_NEWLINE_OR_CR
;
6991 /* The current display element has been consumed. Advance
6993 set_iterator_to_next (it
, 1);
6995 /* Stop if lines are truncated and IT's current x-position is
6996 past the right edge of the window now. */
6997 if (it
->line_wrap
== TRUNCATE
6998 && it
->current_x
>= it
->last_visible_x
)
7000 #ifdef HAVE_WINDOW_SYSTEM
7001 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7003 if (!get_next_display_element (it
)
7004 || BUFFER_POS_REACHED_P ())
7006 result
= MOVE_POS_MATCH_OR_ZV
;
7009 if (ITERATOR_AT_END_OF_LINE_P (it
))
7011 result
= MOVE_NEWLINE_OR_CR
;
7015 #endif /* HAVE_WINDOW_SYSTEM */
7016 result
= MOVE_LINE_TRUNCATED
;
7019 #undef IT_RESET_X_ASCENT_DESCENT
7022 #undef BUFFER_POS_REACHED_P
7024 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7025 restore the saved iterator. */
7026 if (atpos_it
.sp
>= 0)
7028 else if (atx_it
.sp
>= 0)
7033 /* Restore the iterator settings altered at the beginning of this
7035 it
->glyph_row
= saved_glyph_row
;
7039 /* For external use. */
7041 move_it_in_display_line (struct it
*it
,
7042 EMACS_INT to_charpos
, int to_x
,
7043 enum move_operation_enum op
)
7045 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7049 /* Move IT forward until it satisfies one or more of the criteria in
7050 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7052 OP is a bit-mask that specifies where to stop, and in particular,
7053 which of those four position arguments makes a difference. See the
7054 description of enum move_operation_enum.
7056 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7057 screen line, this function will set IT to the next position >
7061 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7063 int to_charpos
, to_x
, to_y
, to_vpos
;
7066 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7072 if (op
& MOVE_TO_VPOS
)
7074 /* If no TO_CHARPOS and no TO_X specified, stop at the
7075 start of the line TO_VPOS. */
7076 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7078 if (it
->vpos
== to_vpos
)
7084 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7088 /* TO_VPOS >= 0 means stop at TO_X in the line at
7089 TO_VPOS, or at TO_POS, whichever comes first. */
7090 if (it
->vpos
== to_vpos
)
7096 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7098 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7103 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7105 /* We have reached TO_X but not in the line we want. */
7106 skip
= move_it_in_display_line_to (it
, to_charpos
,
7108 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7116 else if (op
& MOVE_TO_Y
)
7118 struct it it_backup
;
7120 /* TO_Y specified means stop at TO_X in the line containing
7121 TO_Y---or at TO_CHARPOS if this is reached first. The
7122 problem is that we can't really tell whether the line
7123 contains TO_Y before we have completely scanned it, and
7124 this may skip past TO_X. What we do is to first scan to
7127 If TO_X is not specified, use a TO_X of zero. The reason
7128 is to make the outcome of this function more predictable.
7129 If we didn't use TO_X == 0, we would stop at the end of
7130 the line which is probably not what a caller would expect
7132 skip
= move_it_in_display_line_to (it
, to_charpos
,
7136 | (op
& MOVE_TO_POS
)));
7138 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7139 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7145 /* If TO_X was reached, we would like to know whether TO_Y
7146 is in the line. This can only be said if we know the
7147 total line height which requires us to scan the rest of
7149 if (skip
== MOVE_X_REACHED
)
7151 /* Wait! We can conclude that TO_Y is in the line if
7152 the already scanned glyphs make the line tall enough
7153 because further scanning doesn't make it shorter. */
7154 line_height
= it
->max_ascent
+ it
->max_descent
;
7155 if (to_y
>= it
->current_y
7156 && to_y
< it
->current_y
+ line_height
)
7162 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7163 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7165 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7168 /* Now, decide whether TO_Y is in this line. */
7169 line_height
= it
->max_ascent
+ it
->max_descent
;
7170 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7172 if (to_y
>= it
->current_y
7173 && to_y
< it
->current_y
+ line_height
)
7175 if (skip
== MOVE_X_REACHED
)
7176 /* If TO_Y is in this line and TO_X was reached above,
7177 we scanned too far. We have to restore IT's settings
7178 to the ones before skipping. */
7182 else if (skip
== MOVE_X_REACHED
)
7185 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7192 else if (BUFFERP (it
->object
)
7193 && it
->method
== GET_FROM_BUFFER
7194 && IT_CHARPOS (*it
) >= to_charpos
)
7195 skip
= MOVE_POS_MATCH_OR_ZV
;
7197 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7201 case MOVE_POS_MATCH_OR_ZV
:
7205 case MOVE_NEWLINE_OR_CR
:
7206 set_iterator_to_next (it
, 1);
7207 it
->continuation_lines_width
= 0;
7210 case MOVE_LINE_TRUNCATED
:
7211 it
->continuation_lines_width
= 0;
7212 reseat_at_next_visible_line_start (it
, 0);
7213 if ((op
& MOVE_TO_POS
) != 0
7214 && IT_CHARPOS (*it
) > to_charpos
)
7221 case MOVE_LINE_CONTINUED
:
7222 /* For continued lines ending in a tab, some of the glyphs
7223 associated with the tab are displayed on the current
7224 line. Since it->current_x does not include these glyphs,
7225 we use it->last_visible_x instead. */
7226 it
->continuation_lines_width
+=
7227 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
7234 /* Reset/increment for the next run. */
7235 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7236 it
->current_x
= it
->hpos
= 0;
7237 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7239 last_height
= it
->max_ascent
+ it
->max_descent
;
7240 last_max_ascent
= it
->max_ascent
;
7241 it
->max_ascent
= it
->max_descent
= 0;
7246 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7250 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7252 If DY > 0, move IT backward at least that many pixels. DY = 0
7253 means move IT backward to the preceding line start or BEGV. This
7254 function may move over more than DY pixels if IT->current_y - DY
7255 ends up in the middle of a line; in this case IT->current_y will be
7256 set to the top of the line moved to. */
7259 move_it_vertically_backward (it
, dy
)
7270 start_pos
= IT_CHARPOS (*it
);
7272 /* Estimate how many newlines we must move back. */
7273 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7275 /* Set the iterator's position that many lines back. */
7276 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7277 back_to_previous_visible_line_start (it
);
7279 /* Reseat the iterator here. When moving backward, we don't want
7280 reseat to skip forward over invisible text, set up the iterator
7281 to deliver from overlay strings at the new position etc. So,
7282 use reseat_1 here. */
7283 reseat_1 (it
, it
->current
.pos
, 1);
7285 /* We are now surely at a line start. */
7286 it
->current_x
= it
->hpos
= 0;
7287 it
->continuation_lines_width
= 0;
7289 /* Move forward and see what y-distance we moved. First move to the
7290 start of the next line so that we get its height. We need this
7291 height to be able to tell whether we reached the specified
7294 it2
.max_ascent
= it2
.max_descent
= 0;
7297 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7298 MOVE_TO_POS
| MOVE_TO_VPOS
);
7300 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7301 xassert (IT_CHARPOS (*it
) >= BEGV
);
7304 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7305 xassert (IT_CHARPOS (*it
) >= BEGV
);
7306 /* H is the actual vertical distance from the position in *IT
7307 and the starting position. */
7308 h
= it2
.current_y
- it
->current_y
;
7309 /* NLINES is the distance in number of lines. */
7310 nlines
= it2
.vpos
- it
->vpos
;
7312 /* Correct IT's y and vpos position
7313 so that they are relative to the starting point. */
7319 /* DY == 0 means move to the start of the screen line. The
7320 value of nlines is > 0 if continuation lines were involved. */
7322 move_it_by_lines (it
, nlines
, 1);
7324 /* I think this assert is bogus if buffer contains
7325 invisible text or images. KFS. */
7326 xassert (IT_CHARPOS (*it
) <= start_pos
);
7331 /* The y-position we try to reach, relative to *IT.
7332 Note that H has been subtracted in front of the if-statement. */
7333 int target_y
= it
->current_y
+ h
- dy
;
7334 int y0
= it3
.current_y
;
7335 int y1
= line_bottom_y (&it3
);
7336 int line_height
= y1
- y0
;
7338 /* If we did not reach target_y, try to move further backward if
7339 we can. If we moved too far backward, try to move forward. */
7340 if (target_y
< it
->current_y
7341 /* This is heuristic. In a window that's 3 lines high, with
7342 a line height of 13 pixels each, recentering with point
7343 on the bottom line will try to move -39/2 = 19 pixels
7344 backward. Try to avoid moving into the first line. */
7345 && (it
->current_y
- target_y
7346 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7347 && IT_CHARPOS (*it
) > BEGV
)
7349 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7350 target_y
- it
->current_y
));
7351 dy
= it
->current_y
- target_y
;
7352 goto move_further_back
;
7354 else if (target_y
>= it
->current_y
+ line_height
7355 && IT_CHARPOS (*it
) < ZV
)
7357 /* Should move forward by at least one line, maybe more.
7359 Note: Calling move_it_by_lines can be expensive on
7360 terminal frames, where compute_motion is used (via
7361 vmotion) to do the job, when there are very long lines
7362 and truncate-lines is nil. That's the reason for
7363 treating terminal frames specially here. */
7365 if (!FRAME_WINDOW_P (it
->f
))
7366 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7371 move_it_by_lines (it
, 1, 1);
7373 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7377 /* I think this assert is bogus if buffer contains
7378 invisible text or images. KFS. */
7379 xassert (IT_CHARPOS (*it
) >= BEGV
);
7386 /* Move IT by a specified amount of pixel lines DY. DY negative means
7387 move backwards. DY = 0 means move to start of screen line. At the
7388 end, IT will be on the start of a screen line. */
7391 move_it_vertically (it
, dy
)
7396 move_it_vertically_backward (it
, -dy
);
7399 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7400 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7401 MOVE_TO_POS
| MOVE_TO_Y
);
7402 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7404 /* If buffer ends in ZV without a newline, move to the start of
7405 the line to satisfy the post-condition. */
7406 if (IT_CHARPOS (*it
) == ZV
7408 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7409 move_it_by_lines (it
, 0, 0);
7414 /* Move iterator IT past the end of the text line it is in. */
7417 move_it_past_eol (it
)
7420 enum move_it_result rc
;
7422 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7423 if (rc
== MOVE_NEWLINE_OR_CR
)
7424 set_iterator_to_next (it
, 0);
7428 #if 0 /* Currently not used. */
7430 /* Return non-zero if some text between buffer positions START_CHARPOS
7431 and END_CHARPOS is invisible. IT->window is the window for text
7435 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7437 int start_charpos
, end_charpos
;
7439 Lisp_Object prop
, limit
;
7440 int invisible_found_p
;
7442 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7444 /* Is text at START invisible? */
7445 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7447 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7448 invisible_found_p
= 1;
7451 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7453 make_number (end_charpos
));
7454 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7457 return invisible_found_p
;
7463 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7464 negative means move up. DVPOS == 0 means move to the start of the
7465 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7466 NEED_Y_P is zero, IT->current_y will be left unchanged.
7468 Further optimization ideas: If we would know that IT->f doesn't use
7469 a face with proportional font, we could be faster for
7470 truncate-lines nil. */
7473 move_it_by_lines (it
, dvpos
, need_y_p
)
7475 int dvpos
, need_y_p
;
7477 struct position pos
;
7479 /* The commented-out optimization uses vmotion on terminals. This
7480 gives bad results, because elements like it->what, on which
7481 callers such as pos_visible_p rely, aren't updated. */
7482 /* if (!FRAME_WINDOW_P (it->f))
7484 struct text_pos textpos;
7486 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7487 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7488 reseat (it, textpos, 1);
7489 it->vpos += pos.vpos;
7490 it->current_y += pos.vpos;
7496 /* DVPOS == 0 means move to the start of the screen line. */
7497 move_it_vertically_backward (it
, 0);
7498 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7499 /* Let next call to line_bottom_y calculate real line height */
7504 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7505 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7506 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7511 int start_charpos
, i
;
7513 /* Start at the beginning of the screen line containing IT's
7514 position. This may actually move vertically backwards,
7515 in case of overlays, so adjust dvpos accordingly. */
7517 move_it_vertically_backward (it
, 0);
7520 /* Go back -DVPOS visible lines and reseat the iterator there. */
7521 start_charpos
= IT_CHARPOS (*it
);
7522 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7523 back_to_previous_visible_line_start (it
);
7524 reseat (it
, it
->current
.pos
, 1);
7526 /* Move further back if we end up in a string or an image. */
7527 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7529 /* First try to move to start of display line. */
7531 move_it_vertically_backward (it
, 0);
7533 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7535 /* If start of line is still in string or image,
7536 move further back. */
7537 back_to_previous_visible_line_start (it
);
7538 reseat (it
, it
->current
.pos
, 1);
7542 it
->current_x
= it
->hpos
= 0;
7544 /* Above call may have moved too far if continuation lines
7545 are involved. Scan forward and see if it did. */
7547 it2
.vpos
= it2
.current_y
= 0;
7548 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7549 it
->vpos
-= it2
.vpos
;
7550 it
->current_y
-= it2
.current_y
;
7551 it
->current_x
= it
->hpos
= 0;
7553 /* If we moved too far back, move IT some lines forward. */
7554 if (it2
.vpos
> -dvpos
)
7556 int delta
= it2
.vpos
+ dvpos
;
7558 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7559 /* Move back again if we got too far ahead. */
7560 if (IT_CHARPOS (*it
) >= start_charpos
)
7566 /* Return 1 if IT points into the middle of a display vector. */
7569 in_display_vector_p (it
)
7572 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7573 && it
->current
.dpvec_index
> 0
7574 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7578 /***********************************************************************
7580 ***********************************************************************/
7583 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7587 add_to_log (format
, arg1
, arg2
)
7589 Lisp_Object arg1
, arg2
;
7591 Lisp_Object args
[3];
7592 Lisp_Object msg
, fmt
;
7595 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7598 /* Do nothing if called asynchronously. Inserting text into
7599 a buffer may call after-change-functions and alike and
7600 that would means running Lisp asynchronously. */
7601 if (handling_signal
)
7605 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7607 args
[0] = fmt
= build_string (format
);
7610 msg
= Fformat (3, args
);
7612 len
= SBYTES (msg
) + 1;
7613 SAFE_ALLOCA (buffer
, char *, len
);
7614 bcopy (SDATA (msg
), buffer
, len
);
7616 message_dolog (buffer
, len
- 1, 1, 0);
7623 /* Output a newline in the *Messages* buffer if "needs" one. */
7626 message_log_maybe_newline ()
7628 if (message_log_need_newline
)
7629 message_dolog ("", 0, 1, 0);
7633 /* Add a string M of length NBYTES to the message log, optionally
7634 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7635 nonzero, means interpret the contents of M as multibyte. This
7636 function calls low-level routines in order to bypass text property
7637 hooks, etc. which might not be safe to run.
7639 This may GC (insert may run before/after change hooks),
7640 so the buffer M must NOT point to a Lisp string. */
7643 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7645 int nbytes
, nlflag
, multibyte
;
7647 if (!NILP (Vmemory_full
))
7650 if (!NILP (Vmessage_log_max
))
7652 struct buffer
*oldbuf
;
7653 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7654 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7655 int point_at_end
= 0;
7657 Lisp_Object old_deactivate_mark
, tem
;
7658 struct gcpro gcpro1
;
7660 old_deactivate_mark
= Vdeactivate_mark
;
7661 oldbuf
= current_buffer
;
7662 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7663 current_buffer
->undo_list
= Qt
;
7665 oldpoint
= message_dolog_marker1
;
7666 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7667 oldbegv
= message_dolog_marker2
;
7668 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7669 oldzv
= message_dolog_marker3
;
7670 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7671 GCPRO1 (old_deactivate_mark
);
7679 BEGV_BYTE
= BEG_BYTE
;
7682 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7684 /* Insert the string--maybe converting multibyte to single byte
7685 or vice versa, so that all the text fits the buffer. */
7687 && NILP (current_buffer
->enable_multibyte_characters
))
7689 int i
, c
, char_bytes
;
7690 unsigned char work
[1];
7692 /* Convert a multibyte string to single-byte
7693 for the *Message* buffer. */
7694 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7696 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7697 work
[0] = (ASCII_CHAR_P (c
)
7699 : multibyte_char_to_unibyte (c
, Qnil
));
7700 insert_1_both (work
, 1, 1, 1, 0, 0);
7703 else if (! multibyte
7704 && ! NILP (current_buffer
->enable_multibyte_characters
))
7706 int i
, c
, char_bytes
;
7707 unsigned char *msg
= (unsigned char *) m
;
7708 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7709 /* Convert a single-byte string to multibyte
7710 for the *Message* buffer. */
7711 for (i
= 0; i
< nbytes
; i
++)
7714 c
= unibyte_char_to_multibyte (c
);
7715 char_bytes
= CHAR_STRING (c
, str
);
7716 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7720 insert_1 (m
, nbytes
, 1, 0, 0);
7724 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7725 insert_1 ("\n", 1, 1, 0, 0);
7727 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7729 this_bol_byte
= PT_BYTE
;
7731 /* See if this line duplicates the previous one.
7732 If so, combine duplicates. */
7735 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7737 prev_bol_byte
= PT_BYTE
;
7739 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7740 this_bol
, this_bol_byte
);
7743 del_range_both (prev_bol
, prev_bol_byte
,
7744 this_bol
, this_bol_byte
, 0);
7750 /* If you change this format, don't forget to also
7751 change message_log_check_duplicate. */
7752 sprintf (dupstr
, " [%d times]", dup
);
7753 duplen
= strlen (dupstr
);
7754 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7755 insert_1 (dupstr
, duplen
, 1, 0, 1);
7760 /* If we have more than the desired maximum number of lines
7761 in the *Messages* buffer now, delete the oldest ones.
7762 This is safe because we don't have undo in this buffer. */
7764 if (NATNUMP (Vmessage_log_max
))
7766 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7767 -XFASTINT (Vmessage_log_max
) - 1, 0);
7768 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7771 BEGV
= XMARKER (oldbegv
)->charpos
;
7772 BEGV_BYTE
= marker_byte_position (oldbegv
);
7781 ZV
= XMARKER (oldzv
)->charpos
;
7782 ZV_BYTE
= marker_byte_position (oldzv
);
7786 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7788 /* We can't do Fgoto_char (oldpoint) because it will run some
7790 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7791 XMARKER (oldpoint
)->bytepos
);
7794 unchain_marker (XMARKER (oldpoint
));
7795 unchain_marker (XMARKER (oldbegv
));
7796 unchain_marker (XMARKER (oldzv
));
7798 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7799 set_buffer_internal (oldbuf
);
7801 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7802 message_log_need_newline
= !nlflag
;
7803 Vdeactivate_mark
= old_deactivate_mark
;
7808 /* We are at the end of the buffer after just having inserted a newline.
7809 (Note: We depend on the fact we won't be crossing the gap.)
7810 Check to see if the most recent message looks a lot like the previous one.
7811 Return 0 if different, 1 if the new one should just replace it, or a
7812 value N > 1 if we should also append " [N times]". */
7815 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7816 int prev_bol
, this_bol
;
7817 int prev_bol_byte
, this_bol_byte
;
7820 int len
= Z_BYTE
- 1 - this_bol_byte
;
7822 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7823 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7825 for (i
= 0; i
< len
; i
++)
7827 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7835 if (*p1
++ == ' ' && *p1
++ == '[')
7838 while (*p1
>= '0' && *p1
<= '9')
7839 n
= n
* 10 + *p1
++ - '0';
7840 if (strncmp (p1
, " times]\n", 8) == 0)
7847 /* Display an echo area message M with a specified length of NBYTES
7848 bytes. The string may include null characters. If M is 0, clear
7849 out any existing message, and let the mini-buffer text show
7852 This may GC, so the buffer M must NOT point to a Lisp string. */
7855 message2 (m
, nbytes
, multibyte
)
7860 /* First flush out any partial line written with print. */
7861 message_log_maybe_newline ();
7863 message_dolog (m
, nbytes
, 1, multibyte
);
7864 message2_nolog (m
, nbytes
, multibyte
);
7868 /* The non-logging counterpart of message2. */
7871 message2_nolog (m
, nbytes
, multibyte
)
7873 int nbytes
, multibyte
;
7875 struct frame
*sf
= SELECTED_FRAME ();
7876 message_enable_multibyte
= multibyte
;
7880 if (noninteractive_need_newline
)
7881 putc ('\n', stderr
);
7882 noninteractive_need_newline
= 0;
7884 fwrite (m
, nbytes
, 1, stderr
);
7885 if (cursor_in_echo_area
== 0)
7886 fprintf (stderr
, "\n");
7889 /* A null message buffer means that the frame hasn't really been
7890 initialized yet. Error messages get reported properly by
7891 cmd_error, so this must be just an informative message; toss it. */
7892 else if (INTERACTIVE
7893 && sf
->glyphs_initialized_p
7894 && FRAME_MESSAGE_BUF (sf
))
7896 Lisp_Object mini_window
;
7899 /* Get the frame containing the mini-buffer
7900 that the selected frame is using. */
7901 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7902 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7904 FRAME_SAMPLE_VISIBILITY (f
);
7905 if (FRAME_VISIBLE_P (sf
)
7906 && ! FRAME_VISIBLE_P (f
))
7907 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7911 set_message (m
, Qnil
, nbytes
, multibyte
);
7912 if (minibuffer_auto_raise
)
7913 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7916 clear_message (1, 1);
7918 do_pending_window_change (0);
7919 echo_area_display (1);
7920 do_pending_window_change (0);
7921 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7922 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7927 /* Display an echo area message M with a specified length of NBYTES
7928 bytes. The string may include null characters. If M is not a
7929 string, clear out any existing message, and let the mini-buffer
7932 This function cancels echoing. */
7935 message3 (m
, nbytes
, multibyte
)
7940 struct gcpro gcpro1
;
7943 clear_message (1,1);
7946 /* First flush out any partial line written with print. */
7947 message_log_maybe_newline ();
7953 SAFE_ALLOCA (buffer
, char *, nbytes
);
7954 bcopy (SDATA (m
), buffer
, nbytes
);
7955 message_dolog (buffer
, nbytes
, 1, multibyte
);
7958 message3_nolog (m
, nbytes
, multibyte
);
7964 /* The non-logging version of message3.
7965 This does not cancel echoing, because it is used for echoing.
7966 Perhaps we need to make a separate function for echoing
7967 and make this cancel echoing. */
7970 message3_nolog (m
, nbytes
, multibyte
)
7972 int nbytes
, multibyte
;
7974 struct frame
*sf
= SELECTED_FRAME ();
7975 message_enable_multibyte
= multibyte
;
7979 if (noninteractive_need_newline
)
7980 putc ('\n', stderr
);
7981 noninteractive_need_newline
= 0;
7983 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7984 if (cursor_in_echo_area
== 0)
7985 fprintf (stderr
, "\n");
7988 /* A null message buffer means that the frame hasn't really been
7989 initialized yet. Error messages get reported properly by
7990 cmd_error, so this must be just an informative message; toss it. */
7991 else if (INTERACTIVE
7992 && sf
->glyphs_initialized_p
7993 && FRAME_MESSAGE_BUF (sf
))
7995 Lisp_Object mini_window
;
7999 /* Get the frame containing the mini-buffer
8000 that the selected frame is using. */
8001 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8002 frame
= XWINDOW (mini_window
)->frame
;
8005 FRAME_SAMPLE_VISIBILITY (f
);
8006 if (FRAME_VISIBLE_P (sf
)
8007 && !FRAME_VISIBLE_P (f
))
8008 Fmake_frame_visible (frame
);
8010 if (STRINGP (m
) && SCHARS (m
) > 0)
8012 set_message (NULL
, m
, nbytes
, multibyte
);
8013 if (minibuffer_auto_raise
)
8014 Fraise_frame (frame
);
8015 /* Assume we are not echoing.
8016 (If we are, echo_now will override this.) */
8017 echo_message_buffer
= Qnil
;
8020 clear_message (1, 1);
8022 do_pending_window_change (0);
8023 echo_area_display (1);
8024 do_pending_window_change (0);
8025 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8026 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8031 /* Display a null-terminated echo area message M. If M is 0, clear
8032 out any existing message, and let the mini-buffer text show through.
8034 The buffer M must continue to exist until after the echo area gets
8035 cleared or some other message gets displayed there. Do not pass
8036 text that is stored in a Lisp string. Do not pass text in a buffer
8037 that was alloca'd. */
8043 message2 (m
, (m
? strlen (m
) : 0), 0);
8047 /* The non-logging counterpart of message1. */
8053 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8056 /* Display a message M which contains a single %s
8057 which gets replaced with STRING. */
8060 message_with_string (m
, string
, log
)
8065 CHECK_STRING (string
);
8071 if (noninteractive_need_newline
)
8072 putc ('\n', stderr
);
8073 noninteractive_need_newline
= 0;
8074 fprintf (stderr
, m
, SDATA (string
));
8075 if (cursor_in_echo_area
== 0)
8076 fprintf (stderr
, "\n");
8080 else if (INTERACTIVE
)
8082 /* The frame whose minibuffer we're going to display the message on.
8083 It may be larger than the selected frame, so we need
8084 to use its buffer, not the selected frame's buffer. */
8085 Lisp_Object mini_window
;
8086 struct frame
*f
, *sf
= SELECTED_FRAME ();
8088 /* Get the frame containing the minibuffer
8089 that the selected frame is using. */
8090 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8091 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8093 /* A null message buffer means that the frame hasn't really been
8094 initialized yet. Error messages get reported properly by
8095 cmd_error, so this must be just an informative message; toss it. */
8096 if (FRAME_MESSAGE_BUF (f
))
8098 Lisp_Object args
[2], message
;
8099 struct gcpro gcpro1
, gcpro2
;
8101 args
[0] = build_string (m
);
8102 args
[1] = message
= string
;
8103 GCPRO2 (args
[0], message
);
8106 message
= Fformat (2, args
);
8109 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8111 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8115 /* Print should start at the beginning of the message
8116 buffer next time. */
8117 message_buf_print
= 0;
8123 /* Dump an informative message to the minibuf. If M is 0, clear out
8124 any existing message, and let the mini-buffer text show through. */
8128 message (m
, a1
, a2
, a3
)
8130 EMACS_INT a1
, a2
, a3
;
8136 if (noninteractive_need_newline
)
8137 putc ('\n', stderr
);
8138 noninteractive_need_newline
= 0;
8139 fprintf (stderr
, m
, a1
, a2
, a3
);
8140 if (cursor_in_echo_area
== 0)
8141 fprintf (stderr
, "\n");
8145 else if (INTERACTIVE
)
8147 /* The frame whose mini-buffer we're going to display the message
8148 on. It may be larger than the selected frame, so we need to
8149 use its buffer, not the selected frame's buffer. */
8150 Lisp_Object mini_window
;
8151 struct frame
*f
, *sf
= SELECTED_FRAME ();
8153 /* Get the frame containing the mini-buffer
8154 that the selected frame is using. */
8155 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8156 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8158 /* A null message buffer means that the frame hasn't really been
8159 initialized yet. Error messages get reported properly by
8160 cmd_error, so this must be just an informative message; toss
8162 if (FRAME_MESSAGE_BUF (f
))
8173 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8174 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8176 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8177 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8179 #endif /* NO_ARG_ARRAY */
8181 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8186 /* Print should start at the beginning of the message
8187 buffer next time. */
8188 message_buf_print
= 0;
8194 /* The non-logging version of message. */
8197 message_nolog (m
, a1
, a2
, a3
)
8199 EMACS_INT a1
, a2
, a3
;
8201 Lisp_Object old_log_max
;
8202 old_log_max
= Vmessage_log_max
;
8203 Vmessage_log_max
= Qnil
;
8204 message (m
, a1
, a2
, a3
);
8205 Vmessage_log_max
= old_log_max
;
8209 /* Display the current message in the current mini-buffer. This is
8210 only called from error handlers in process.c, and is not time
8216 if (!NILP (echo_area_buffer
[0]))
8219 string
= Fcurrent_message ();
8220 message3 (string
, SBYTES (string
),
8221 !NILP (current_buffer
->enable_multibyte_characters
));
8226 /* Make sure echo area buffers in `echo_buffers' are live.
8227 If they aren't, make new ones. */
8230 ensure_echo_area_buffers ()
8234 for (i
= 0; i
< 2; ++i
)
8235 if (!BUFFERP (echo_buffer
[i
])
8236 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8239 Lisp_Object old_buffer
;
8242 old_buffer
= echo_buffer
[i
];
8243 sprintf (name
, " *Echo Area %d*", i
);
8244 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8245 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8247 for (j
= 0; j
< 2; ++j
)
8248 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8249 echo_area_buffer
[j
] = echo_buffer
[i
];
8254 /* Call FN with args A1..A4 with either the current or last displayed
8255 echo_area_buffer as current buffer.
8257 WHICH zero means use the current message buffer
8258 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8259 from echo_buffer[] and clear it.
8261 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8262 suitable buffer from echo_buffer[] and clear it.
8264 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8265 that the current message becomes the last displayed one, make
8266 choose a suitable buffer for echo_area_buffer[0], and clear it.
8268 Value is what FN returns. */
8271 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8274 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8280 int this_one
, the_other
, clear_buffer_p
, rc
;
8281 int count
= SPECPDL_INDEX ();
8283 /* If buffers aren't live, make new ones. */
8284 ensure_echo_area_buffers ();
8289 this_one
= 0, the_other
= 1;
8291 this_one
= 1, the_other
= 0;
8294 this_one
= 0, the_other
= 1;
8297 /* We need a fresh one in case the current echo buffer equals
8298 the one containing the last displayed echo area message. */
8299 if (!NILP (echo_area_buffer
[this_one
])
8300 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8301 echo_area_buffer
[this_one
] = Qnil
;
8304 /* Choose a suitable buffer from echo_buffer[] is we don't
8306 if (NILP (echo_area_buffer
[this_one
]))
8308 echo_area_buffer
[this_one
]
8309 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8310 ? echo_buffer
[the_other
]
8311 : echo_buffer
[this_one
]);
8315 buffer
= echo_area_buffer
[this_one
];
8317 /* Don't get confused by reusing the buffer used for echoing
8318 for a different purpose. */
8319 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8322 record_unwind_protect (unwind_with_echo_area_buffer
,
8323 with_echo_area_buffer_unwind_data (w
));
8325 /* Make the echo area buffer current. Note that for display
8326 purposes, it is not necessary that the displayed window's buffer
8327 == current_buffer, except for text property lookup. So, let's
8328 only set that buffer temporarily here without doing a full
8329 Fset_window_buffer. We must also change w->pointm, though,
8330 because otherwise an assertions in unshow_buffer fails, and Emacs
8332 set_buffer_internal_1 (XBUFFER (buffer
));
8336 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8339 current_buffer
->undo_list
= Qt
;
8340 current_buffer
->read_only
= Qnil
;
8341 specbind (Qinhibit_read_only
, Qt
);
8342 specbind (Qinhibit_modification_hooks
, Qt
);
8344 if (clear_buffer_p
&& Z
> BEG
)
8347 xassert (BEGV
>= BEG
);
8348 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8350 rc
= fn (a1
, a2
, a3
, a4
);
8352 xassert (BEGV
>= BEG
);
8353 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8355 unbind_to (count
, Qnil
);
8360 /* Save state that should be preserved around the call to the function
8361 FN called in with_echo_area_buffer. */
8364 with_echo_area_buffer_unwind_data (w
)
8368 Lisp_Object vector
, tmp
;
8370 /* Reduce consing by keeping one vector in
8371 Vwith_echo_area_save_vector. */
8372 vector
= Vwith_echo_area_save_vector
;
8373 Vwith_echo_area_save_vector
= Qnil
;
8376 vector
= Fmake_vector (make_number (7), Qnil
);
8378 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8379 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8380 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8384 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8385 ASET (vector
, i
, w
->buffer
); ++i
;
8386 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8387 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8392 for (; i
< end
; ++i
)
8393 ASET (vector
, i
, Qnil
);
8396 xassert (i
== ASIZE (vector
));
8401 /* Restore global state from VECTOR which was created by
8402 with_echo_area_buffer_unwind_data. */
8405 unwind_with_echo_area_buffer (vector
)
8408 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8409 Vdeactivate_mark
= AREF (vector
, 1);
8410 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8412 if (WINDOWP (AREF (vector
, 3)))
8415 Lisp_Object buffer
, charpos
, bytepos
;
8417 w
= XWINDOW (AREF (vector
, 3));
8418 buffer
= AREF (vector
, 4);
8419 charpos
= AREF (vector
, 5);
8420 bytepos
= AREF (vector
, 6);
8423 set_marker_both (w
->pointm
, buffer
,
8424 XFASTINT (charpos
), XFASTINT (bytepos
));
8427 Vwith_echo_area_save_vector
= vector
;
8432 /* Set up the echo area for use by print functions. MULTIBYTE_P
8433 non-zero means we will print multibyte. */
8436 setup_echo_area_for_printing (multibyte_p
)
8439 /* If we can't find an echo area any more, exit. */
8440 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8443 ensure_echo_area_buffers ();
8445 if (!message_buf_print
)
8447 /* A message has been output since the last time we printed.
8448 Choose a fresh echo area buffer. */
8449 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8450 echo_area_buffer
[0] = echo_buffer
[1];
8452 echo_area_buffer
[0] = echo_buffer
[0];
8454 /* Switch to that buffer and clear it. */
8455 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8456 current_buffer
->truncate_lines
= Qnil
;
8460 int count
= SPECPDL_INDEX ();
8461 specbind (Qinhibit_read_only
, Qt
);
8462 /* Note that undo recording is always disabled. */
8464 unbind_to (count
, Qnil
);
8466 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8468 /* Set up the buffer for the multibyteness we need. */
8470 != !NILP (current_buffer
->enable_multibyte_characters
))
8471 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8473 /* Raise the frame containing the echo area. */
8474 if (minibuffer_auto_raise
)
8476 struct frame
*sf
= SELECTED_FRAME ();
8477 Lisp_Object mini_window
;
8478 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8479 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8482 message_log_maybe_newline ();
8483 message_buf_print
= 1;
8487 if (NILP (echo_area_buffer
[0]))
8489 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8490 echo_area_buffer
[0] = echo_buffer
[1];
8492 echo_area_buffer
[0] = echo_buffer
[0];
8495 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8497 /* Someone switched buffers between print requests. */
8498 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8499 current_buffer
->truncate_lines
= Qnil
;
8505 /* Display an echo area message in window W. Value is non-zero if W's
8506 height is changed. If display_last_displayed_message_p is
8507 non-zero, display the message that was last displayed, otherwise
8508 display the current message. */
8511 display_echo_area (w
)
8514 int i
, no_message_p
, window_height_changed_p
, count
;
8516 /* Temporarily disable garbage collections while displaying the echo
8517 area. This is done because a GC can print a message itself.
8518 That message would modify the echo area buffer's contents while a
8519 redisplay of the buffer is going on, and seriously confuse
8521 count
= inhibit_garbage_collection ();
8523 /* If there is no message, we must call display_echo_area_1
8524 nevertheless because it resizes the window. But we will have to
8525 reset the echo_area_buffer in question to nil at the end because
8526 with_echo_area_buffer will sets it to an empty buffer. */
8527 i
= display_last_displayed_message_p
? 1 : 0;
8528 no_message_p
= NILP (echo_area_buffer
[i
]);
8530 window_height_changed_p
8531 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8532 display_echo_area_1
,
8533 (EMACS_INT
) w
, Qnil
, 0, 0);
8536 echo_area_buffer
[i
] = Qnil
;
8538 unbind_to (count
, Qnil
);
8539 return window_height_changed_p
;
8543 /* Helper for display_echo_area. Display the current buffer which
8544 contains the current echo area message in window W, a mini-window,
8545 a pointer to which is passed in A1. A2..A4 are currently not used.
8546 Change the height of W so that all of the message is displayed.
8547 Value is non-zero if height of W was changed. */
8550 display_echo_area_1 (a1
, a2
, a3
, a4
)
8555 struct window
*w
= (struct window
*) a1
;
8557 struct text_pos start
;
8558 int window_height_changed_p
= 0;
8560 /* Do this before displaying, so that we have a large enough glyph
8561 matrix for the display. If we can't get enough space for the
8562 whole text, display the last N lines. That works by setting w->start. */
8563 window_height_changed_p
= resize_mini_window (w
, 0);
8565 /* Use the starting position chosen by resize_mini_window. */
8566 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8569 clear_glyph_matrix (w
->desired_matrix
);
8570 XSETWINDOW (window
, w
);
8571 try_window (window
, start
, 0);
8573 return window_height_changed_p
;
8577 /* Resize the echo area window to exactly the size needed for the
8578 currently displayed message, if there is one. If a mini-buffer
8579 is active, don't shrink it. */
8582 resize_echo_area_exactly ()
8584 if (BUFFERP (echo_area_buffer
[0])
8585 && WINDOWP (echo_area_window
))
8587 struct window
*w
= XWINDOW (echo_area_window
);
8589 Lisp_Object resize_exactly
;
8591 if (minibuf_level
== 0)
8592 resize_exactly
= Qt
;
8594 resize_exactly
= Qnil
;
8596 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8597 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8600 ++windows_or_buffers_changed
;
8601 ++update_mode_lines
;
8602 redisplay_internal (0);
8608 /* Callback function for with_echo_area_buffer, when used from
8609 resize_echo_area_exactly. A1 contains a pointer to the window to
8610 resize, EXACTLY non-nil means resize the mini-window exactly to the
8611 size of the text displayed. A3 and A4 are not used. Value is what
8612 resize_mini_window returns. */
8615 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8617 Lisp_Object exactly
;
8620 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8624 /* Resize mini-window W to fit the size of its contents. EXACT_P
8625 means size the window exactly to the size needed. Otherwise, it's
8626 only enlarged until W's buffer is empty.
8628 Set W->start to the right place to begin display. If the whole
8629 contents fit, start at the beginning. Otherwise, start so as
8630 to make the end of the contents appear. This is particularly
8631 important for y-or-n-p, but seems desirable generally.
8633 Value is non-zero if the window height has been changed. */
8636 resize_mini_window (w
, exact_p
)
8640 struct frame
*f
= XFRAME (w
->frame
);
8641 int window_height_changed_p
= 0;
8643 xassert (MINI_WINDOW_P (w
));
8645 /* By default, start display at the beginning. */
8646 set_marker_both (w
->start
, w
->buffer
,
8647 BUF_BEGV (XBUFFER (w
->buffer
)),
8648 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8650 /* Don't resize windows while redisplaying a window; it would
8651 confuse redisplay functions when the size of the window they are
8652 displaying changes from under them. Such a resizing can happen,
8653 for instance, when which-func prints a long message while
8654 we are running fontification-functions. We're running these
8655 functions with safe_call which binds inhibit-redisplay to t. */
8656 if (!NILP (Vinhibit_redisplay
))
8659 /* Nil means don't try to resize. */
8660 if (NILP (Vresize_mini_windows
)
8661 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8664 if (!FRAME_MINIBUF_ONLY_P (f
))
8667 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8668 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8669 int height
, max_height
;
8670 int unit
= FRAME_LINE_HEIGHT (f
);
8671 struct text_pos start
;
8672 struct buffer
*old_current_buffer
= NULL
;
8674 if (current_buffer
!= XBUFFER (w
->buffer
))
8676 old_current_buffer
= current_buffer
;
8677 set_buffer_internal (XBUFFER (w
->buffer
));
8680 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8682 /* Compute the max. number of lines specified by the user. */
8683 if (FLOATP (Vmax_mini_window_height
))
8684 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8685 else if (INTEGERP (Vmax_mini_window_height
))
8686 max_height
= XINT (Vmax_mini_window_height
);
8688 max_height
= total_height
/ 4;
8690 /* Correct that max. height if it's bogus. */
8691 max_height
= max (1, max_height
);
8692 max_height
= min (total_height
, max_height
);
8694 /* Find out the height of the text in the window. */
8695 if (it
.line_wrap
== TRUNCATE
)
8700 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8701 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8702 height
= it
.current_y
+ last_height
;
8704 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8705 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8706 height
= (height
+ unit
- 1) / unit
;
8709 /* Compute a suitable window start. */
8710 if (height
> max_height
)
8712 height
= max_height
;
8713 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8714 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8715 start
= it
.current
.pos
;
8718 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8719 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8721 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8723 /* Let it grow only, until we display an empty message, in which
8724 case the window shrinks again. */
8725 if (height
> WINDOW_TOTAL_LINES (w
))
8727 int old_height
= WINDOW_TOTAL_LINES (w
);
8728 freeze_window_starts (f
, 1);
8729 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8730 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8732 else if (height
< WINDOW_TOTAL_LINES (w
)
8733 && (exact_p
|| BEGV
== ZV
))
8735 int old_height
= WINDOW_TOTAL_LINES (w
);
8736 freeze_window_starts (f
, 0);
8737 shrink_mini_window (w
);
8738 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8743 /* Always resize to exact size needed. */
8744 if (height
> WINDOW_TOTAL_LINES (w
))
8746 int old_height
= WINDOW_TOTAL_LINES (w
);
8747 freeze_window_starts (f
, 1);
8748 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8749 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8751 else if (height
< WINDOW_TOTAL_LINES (w
))
8753 int old_height
= WINDOW_TOTAL_LINES (w
);
8754 freeze_window_starts (f
, 0);
8755 shrink_mini_window (w
);
8759 freeze_window_starts (f
, 1);
8760 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8763 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8767 if (old_current_buffer
)
8768 set_buffer_internal (old_current_buffer
);
8771 return window_height_changed_p
;
8775 /* Value is the current message, a string, or nil if there is no
8783 if (!BUFFERP (echo_area_buffer
[0]))
8787 with_echo_area_buffer (0, 0, current_message_1
,
8788 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8790 echo_area_buffer
[0] = Qnil
;
8798 current_message_1 (a1
, a2
, a3
, a4
)
8803 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8806 *msg
= make_buffer_string (BEG
, Z
, 1);
8813 /* Push the current message on Vmessage_stack for later restauration
8814 by restore_message. Value is non-zero if the current message isn't
8815 empty. This is a relatively infrequent operation, so it's not
8816 worth optimizing. */
8822 msg
= current_message ();
8823 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8824 return STRINGP (msg
);
8828 /* Restore message display from the top of Vmessage_stack. */
8835 xassert (CONSP (Vmessage_stack
));
8836 msg
= XCAR (Vmessage_stack
);
8838 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8840 message3_nolog (msg
, 0, 0);
8844 /* Handler for record_unwind_protect calling pop_message. */
8847 pop_message_unwind (dummy
)
8854 /* Pop the top-most entry off Vmessage_stack. */
8859 xassert (CONSP (Vmessage_stack
));
8860 Vmessage_stack
= XCDR (Vmessage_stack
);
8864 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8865 exits. If the stack is not empty, we have a missing pop_message
8869 check_message_stack ()
8871 if (!NILP (Vmessage_stack
))
8876 /* Truncate to NCHARS what will be displayed in the echo area the next
8877 time we display it---but don't redisplay it now. */
8880 truncate_echo_area (nchars
)
8884 echo_area_buffer
[0] = Qnil
;
8885 /* A null message buffer means that the frame hasn't really been
8886 initialized yet. Error messages get reported properly by
8887 cmd_error, so this must be just an informative message; toss it. */
8888 else if (!noninteractive
8890 && !NILP (echo_area_buffer
[0]))
8892 struct frame
*sf
= SELECTED_FRAME ();
8893 if (FRAME_MESSAGE_BUF (sf
))
8894 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8899 /* Helper function for truncate_echo_area. Truncate the current
8900 message to at most NCHARS characters. */
8903 truncate_message_1 (nchars
, a2
, a3
, a4
)
8908 if (BEG
+ nchars
< Z
)
8909 del_range (BEG
+ nchars
, Z
);
8911 echo_area_buffer
[0] = Qnil
;
8916 /* Set the current message to a substring of S or STRING.
8918 If STRING is a Lisp string, set the message to the first NBYTES
8919 bytes from STRING. NBYTES zero means use the whole string. If
8920 STRING is multibyte, the message will be displayed multibyte.
8922 If S is not null, set the message to the first LEN bytes of S. LEN
8923 zero means use the whole string. MULTIBYTE_P non-zero means S is
8924 multibyte. Display the message multibyte in that case.
8926 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8927 to t before calling set_message_1 (which calls insert).
8931 set_message (s
, string
, nbytes
, multibyte_p
)
8934 int nbytes
, multibyte_p
;
8936 message_enable_multibyte
8937 = ((s
&& multibyte_p
)
8938 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8940 with_echo_area_buffer (0, -1, set_message_1
,
8941 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8942 message_buf_print
= 0;
8943 help_echo_showing_p
= 0;
8947 /* Helper function for set_message. Arguments have the same meaning
8948 as there, with A1 corresponding to S and A2 corresponding to STRING
8949 This function is called with the echo area buffer being
8953 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8956 EMACS_INT nbytes
, multibyte_p
;
8958 const char *s
= (const char *) a1
;
8959 Lisp_Object string
= a2
;
8961 /* Change multibyteness of the echo buffer appropriately. */
8962 if (message_enable_multibyte
8963 != !NILP (current_buffer
->enable_multibyte_characters
))
8964 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8966 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8968 /* Insert new message at BEG. */
8969 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8971 if (STRINGP (string
))
8976 nbytes
= SBYTES (string
);
8977 nchars
= string_byte_to_char (string
, nbytes
);
8979 /* This function takes care of single/multibyte conversion. We
8980 just have to ensure that the echo area buffer has the right
8981 setting of enable_multibyte_characters. */
8982 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8987 nbytes
= strlen (s
);
8989 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8991 /* Convert from multi-byte to single-byte. */
8993 unsigned char work
[1];
8995 /* Convert a multibyte string to single-byte. */
8996 for (i
= 0; i
< nbytes
; i
+= n
)
8998 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8999 work
[0] = (ASCII_CHAR_P (c
)
9001 : multibyte_char_to_unibyte (c
, Qnil
));
9002 insert_1_both (work
, 1, 1, 1, 0, 0);
9005 else if (!multibyte_p
9006 && !NILP (current_buffer
->enable_multibyte_characters
))
9008 /* Convert from single-byte to multi-byte. */
9010 const unsigned char *msg
= (const unsigned char *) s
;
9011 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9013 /* Convert a single-byte string to multibyte. */
9014 for (i
= 0; i
< nbytes
; i
++)
9017 c
= unibyte_char_to_multibyte (c
);
9018 n
= CHAR_STRING (c
, str
);
9019 insert_1_both (str
, 1, n
, 1, 0, 0);
9023 insert_1 (s
, nbytes
, 1, 0, 0);
9030 /* Clear messages. CURRENT_P non-zero means clear the current
9031 message. LAST_DISPLAYED_P non-zero means clear the message
9035 clear_message (current_p
, last_displayed_p
)
9036 int current_p
, last_displayed_p
;
9040 echo_area_buffer
[0] = Qnil
;
9041 message_cleared_p
= 1;
9044 if (last_displayed_p
)
9045 echo_area_buffer
[1] = Qnil
;
9047 message_buf_print
= 0;
9050 /* Clear garbaged frames.
9052 This function is used where the old redisplay called
9053 redraw_garbaged_frames which in turn called redraw_frame which in
9054 turn called clear_frame. The call to clear_frame was a source of
9055 flickering. I believe a clear_frame is not necessary. It should
9056 suffice in the new redisplay to invalidate all current matrices,
9057 and ensure a complete redisplay of all windows. */
9060 clear_garbaged_frames ()
9064 Lisp_Object tail
, frame
;
9065 int changed_count
= 0;
9067 FOR_EACH_FRAME (tail
, frame
)
9069 struct frame
*f
= XFRAME (frame
);
9071 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9075 Fredraw_frame (frame
);
9076 f
->force_flush_display_p
= 1;
9078 clear_current_matrices (f
);
9087 ++windows_or_buffers_changed
;
9092 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9093 is non-zero update selected_frame. Value is non-zero if the
9094 mini-windows height has been changed. */
9097 echo_area_display (update_frame_p
)
9100 Lisp_Object mini_window
;
9103 int window_height_changed_p
= 0;
9104 struct frame
*sf
= SELECTED_FRAME ();
9106 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9107 w
= XWINDOW (mini_window
);
9108 f
= XFRAME (WINDOW_FRAME (w
));
9110 /* Don't display if frame is invisible or not yet initialized. */
9111 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9114 #ifdef HAVE_WINDOW_SYSTEM
9115 /* When Emacs starts, selected_frame may be the initial terminal
9116 frame. If we let this through, a message would be displayed on
9118 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9120 #endif /* HAVE_WINDOW_SYSTEM */
9122 /* Redraw garbaged frames. */
9124 clear_garbaged_frames ();
9126 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9128 echo_area_window
= mini_window
;
9129 window_height_changed_p
= display_echo_area (w
);
9130 w
->must_be_updated_p
= 1;
9132 /* Update the display, unless called from redisplay_internal.
9133 Also don't update the screen during redisplay itself. The
9134 update will happen at the end of redisplay, and an update
9135 here could cause confusion. */
9136 if (update_frame_p
&& !redisplaying_p
)
9140 /* If the display update has been interrupted by pending
9141 input, update mode lines in the frame. Due to the
9142 pending input, it might have been that redisplay hasn't
9143 been called, so that mode lines above the echo area are
9144 garbaged. This looks odd, so we prevent it here. */
9145 if (!display_completed
)
9146 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9148 if (window_height_changed_p
9149 /* Don't do this if Emacs is shutting down. Redisplay
9150 needs to run hooks. */
9151 && !NILP (Vrun_hooks
))
9153 /* Must update other windows. Likewise as in other
9154 cases, don't let this update be interrupted by
9156 int count
= SPECPDL_INDEX ();
9157 specbind (Qredisplay_dont_pause
, Qt
);
9158 windows_or_buffers_changed
= 1;
9159 redisplay_internal (0);
9160 unbind_to (count
, Qnil
);
9162 else if (FRAME_WINDOW_P (f
) && n
== 0)
9164 /* Window configuration is the same as before.
9165 Can do with a display update of the echo area,
9166 unless we displayed some mode lines. */
9167 update_single_window (w
, 1);
9168 FRAME_RIF (f
)->flush_display (f
);
9171 update_frame (f
, 1, 1);
9173 /* If cursor is in the echo area, make sure that the next
9174 redisplay displays the minibuffer, so that the cursor will
9175 be replaced with what the minibuffer wants. */
9176 if (cursor_in_echo_area
)
9177 ++windows_or_buffers_changed
;
9180 else if (!EQ (mini_window
, selected_window
))
9181 windows_or_buffers_changed
++;
9183 /* Last displayed message is now the current message. */
9184 echo_area_buffer
[1] = echo_area_buffer
[0];
9185 /* Inform read_char that we're not echoing. */
9186 echo_message_buffer
= Qnil
;
9188 /* Prevent redisplay optimization in redisplay_internal by resetting
9189 this_line_start_pos. This is done because the mini-buffer now
9190 displays the message instead of its buffer text. */
9191 if (EQ (mini_window
, selected_window
))
9192 CHARPOS (this_line_start_pos
) = 0;
9194 return window_height_changed_p
;
9199 /***********************************************************************
9200 Mode Lines and Frame Titles
9201 ***********************************************************************/
9203 /* A buffer for constructing non-propertized mode-line strings and
9204 frame titles in it; allocated from the heap in init_xdisp and
9205 resized as needed in store_mode_line_noprop_char. */
9207 static char *mode_line_noprop_buf
;
9209 /* The buffer's end, and a current output position in it. */
9211 static char *mode_line_noprop_buf_end
;
9212 static char *mode_line_noprop_ptr
;
9214 #define MODE_LINE_NOPROP_LEN(start) \
9215 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9218 MODE_LINE_DISPLAY
= 0,
9224 /* Alist that caches the results of :propertize.
9225 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9226 static Lisp_Object mode_line_proptrans_alist
;
9228 /* List of strings making up the mode-line. */
9229 static Lisp_Object mode_line_string_list
;
9231 /* Base face property when building propertized mode line string. */
9232 static Lisp_Object mode_line_string_face
;
9233 static Lisp_Object mode_line_string_face_prop
;
9236 /* Unwind data for mode line strings */
9238 static Lisp_Object Vmode_line_unwind_vector
;
9241 format_mode_line_unwind_data (struct buffer
*obuf
,
9245 Lisp_Object vector
, tmp
;
9247 /* Reduce consing by keeping one vector in
9248 Vwith_echo_area_save_vector. */
9249 vector
= Vmode_line_unwind_vector
;
9250 Vmode_line_unwind_vector
= Qnil
;
9253 vector
= Fmake_vector (make_number (8), Qnil
);
9255 ASET (vector
, 0, make_number (mode_line_target
));
9256 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9257 ASET (vector
, 2, mode_line_string_list
);
9258 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9259 ASET (vector
, 4, mode_line_string_face
);
9260 ASET (vector
, 5, mode_line_string_face_prop
);
9263 XSETBUFFER (tmp
, obuf
);
9266 ASET (vector
, 6, tmp
);
9267 ASET (vector
, 7, owin
);
9273 unwind_format_mode_line (vector
)
9276 mode_line_target
= XINT (AREF (vector
, 0));
9277 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9278 mode_line_string_list
= AREF (vector
, 2);
9279 if (! EQ (AREF (vector
, 3), Qt
))
9280 mode_line_proptrans_alist
= AREF (vector
, 3);
9281 mode_line_string_face
= AREF (vector
, 4);
9282 mode_line_string_face_prop
= AREF (vector
, 5);
9284 if (!NILP (AREF (vector
, 7)))
9285 /* Select window before buffer, since it may change the buffer. */
9286 Fselect_window (AREF (vector
, 7), Qt
);
9288 if (!NILP (AREF (vector
, 6)))
9290 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9291 ASET (vector
, 6, Qnil
);
9294 Vmode_line_unwind_vector
= vector
;
9299 /* Store a single character C for the frame title in mode_line_noprop_buf.
9300 Re-allocate mode_line_noprop_buf if necessary. */
9304 store_mode_line_noprop_char (char c
)
9306 store_mode_line_noprop_char (c
)
9310 /* If output position has reached the end of the allocated buffer,
9311 double the buffer's size. */
9312 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9314 int len
= MODE_LINE_NOPROP_LEN (0);
9315 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9316 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9317 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9318 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9321 *mode_line_noprop_ptr
++ = c
;
9325 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9326 mode_line_noprop_ptr. STR is the string to store. Do not copy
9327 characters that yield more columns than PRECISION; PRECISION <= 0
9328 means copy the whole string. Pad with spaces until FIELD_WIDTH
9329 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9330 pad. Called from display_mode_element when it is used to build a
9334 store_mode_line_noprop (str
, field_width
, precision
)
9335 const unsigned char *str
;
9336 int field_width
, precision
;
9341 /* Copy at most PRECISION chars from STR. */
9342 nbytes
= strlen (str
);
9343 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9345 store_mode_line_noprop_char (*str
++);
9347 /* Fill up with spaces until FIELD_WIDTH reached. */
9348 while (field_width
> 0
9351 store_mode_line_noprop_char (' ');
9358 /***********************************************************************
9360 ***********************************************************************/
9362 #ifdef HAVE_WINDOW_SYSTEM
9364 /* Set the title of FRAME, if it has changed. The title format is
9365 Vicon_title_format if FRAME is iconified, otherwise it is
9366 frame_title_format. */
9369 x_consider_frame_title (frame
)
9372 struct frame
*f
= XFRAME (frame
);
9374 if (FRAME_WINDOW_P (f
)
9375 || FRAME_MINIBUF_ONLY_P (f
)
9376 || f
->explicit_name
)
9378 /* Do we have more than one visible frame on this X display? */
9385 int count
= SPECPDL_INDEX ();
9387 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9389 Lisp_Object other_frame
= XCAR (tail
);
9390 struct frame
*tf
= XFRAME (other_frame
);
9393 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9394 && !FRAME_MINIBUF_ONLY_P (tf
)
9395 && !EQ (other_frame
, tip_frame
)
9396 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9400 /* Set global variable indicating that multiple frames exist. */
9401 multiple_frames
= CONSP (tail
);
9403 /* Switch to the buffer of selected window of the frame. Set up
9404 mode_line_target so that display_mode_element will output into
9405 mode_line_noprop_buf; then display the title. */
9406 record_unwind_protect (unwind_format_mode_line
,
9407 format_mode_line_unwind_data
9408 (current_buffer
, selected_window
, 0));
9410 Fselect_window (f
->selected_window
, Qt
);
9411 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9412 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9414 mode_line_target
= MODE_LINE_TITLE
;
9415 title_start
= MODE_LINE_NOPROP_LEN (0);
9416 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9417 NULL
, DEFAULT_FACE_ID
);
9418 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9419 len
= MODE_LINE_NOPROP_LEN (title_start
);
9420 title
= mode_line_noprop_buf
+ title_start
;
9421 unbind_to (count
, Qnil
);
9423 /* Set the title only if it's changed. This avoids consing in
9424 the common case where it hasn't. (If it turns out that we've
9425 already wasted too much time by walking through the list with
9426 display_mode_element, then we might need to optimize at a
9427 higher level than this.) */
9428 if (! STRINGP (f
->name
)
9429 || SBYTES (f
->name
) != len
9430 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9431 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9435 #endif /* not HAVE_WINDOW_SYSTEM */
9440 /***********************************************************************
9442 ***********************************************************************/
9445 /* Prepare for redisplay by updating menu-bar item lists when
9446 appropriate. This can call eval. */
9449 prepare_menu_bars ()
9452 struct gcpro gcpro1
, gcpro2
;
9454 Lisp_Object tooltip_frame
;
9456 #ifdef HAVE_WINDOW_SYSTEM
9457 tooltip_frame
= tip_frame
;
9459 tooltip_frame
= Qnil
;
9462 /* Update all frame titles based on their buffer names, etc. We do
9463 this before the menu bars so that the buffer-menu will show the
9464 up-to-date frame titles. */
9465 #ifdef HAVE_WINDOW_SYSTEM
9466 if (windows_or_buffers_changed
|| update_mode_lines
)
9468 Lisp_Object tail
, frame
;
9470 FOR_EACH_FRAME (tail
, frame
)
9473 if (!EQ (frame
, tooltip_frame
)
9474 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9475 x_consider_frame_title (frame
);
9478 #endif /* HAVE_WINDOW_SYSTEM */
9480 /* Update the menu bar item lists, if appropriate. This has to be
9481 done before any actual redisplay or generation of display lines. */
9482 all_windows
= (update_mode_lines
9483 || buffer_shared
> 1
9484 || windows_or_buffers_changed
);
9487 Lisp_Object tail
, frame
;
9488 int count
= SPECPDL_INDEX ();
9489 /* 1 means that update_menu_bar has run its hooks
9490 so any further calls to update_menu_bar shouldn't do so again. */
9491 int menu_bar_hooks_run
= 0;
9493 record_unwind_save_match_data ();
9495 FOR_EACH_FRAME (tail
, frame
)
9499 /* Ignore tooltip frame. */
9500 if (EQ (frame
, tooltip_frame
))
9503 /* If a window on this frame changed size, report that to
9504 the user and clear the size-change flag. */
9505 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9507 Lisp_Object functions
;
9509 /* Clear flag first in case we get an error below. */
9510 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9511 functions
= Vwindow_size_change_functions
;
9512 GCPRO2 (tail
, functions
);
9514 while (CONSP (functions
))
9516 call1 (XCAR (functions
), frame
);
9517 functions
= XCDR (functions
);
9523 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9524 #ifdef HAVE_WINDOW_SYSTEM
9525 update_tool_bar (f
, 0);
9527 mac_update_title_bar (f
, 0);
9533 unbind_to (count
, Qnil
);
9537 struct frame
*sf
= SELECTED_FRAME ();
9538 update_menu_bar (sf
, 1, 0);
9539 #ifdef HAVE_WINDOW_SYSTEM
9540 update_tool_bar (sf
, 1);
9542 mac_update_title_bar (sf
, 1);
9547 /* Motif needs this. See comment in xmenu.c. Turn it off when
9548 pending_menu_activation is not defined. */
9549 #ifdef USE_X_TOOLKIT
9550 pending_menu_activation
= 0;
9555 /* Update the menu bar item list for frame F. This has to be done
9556 before we start to fill in any display lines, because it can call
9559 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9561 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9562 already ran the menu bar hooks for this redisplay, so there
9563 is no need to run them again. The return value is the
9564 updated value of this flag, to pass to the next call. */
9567 update_menu_bar (f
, save_match_data
, hooks_run
)
9569 int save_match_data
;
9573 register struct window
*w
;
9575 /* If called recursively during a menu update, do nothing. This can
9576 happen when, for instance, an activate-menubar-hook causes a
9578 if (inhibit_menubar_update
)
9581 window
= FRAME_SELECTED_WINDOW (f
);
9582 w
= XWINDOW (window
);
9584 #if 0 /* The if statement below this if statement used to include the
9585 condition !NILP (w->update_mode_line), rather than using
9586 update_mode_lines directly, and this if statement may have
9587 been added to make that condition work. Now the if
9588 statement below matches its comment, this isn't needed. */
9589 if (update_mode_lines
)
9590 w
->update_mode_line
= Qt
;
9593 if (FRAME_WINDOW_P (f
)
9595 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9596 || defined (USE_GTK)
9597 FRAME_EXTERNAL_MENU_BAR (f
)
9599 FRAME_MENU_BAR_LINES (f
) > 0
9601 : FRAME_MENU_BAR_LINES (f
) > 0)
9603 /* If the user has switched buffers or windows, we need to
9604 recompute to reflect the new bindings. But we'll
9605 recompute when update_mode_lines is set too; that means
9606 that people can use force-mode-line-update to request
9607 that the menu bar be recomputed. The adverse effect on
9608 the rest of the redisplay algorithm is about the same as
9609 windows_or_buffers_changed anyway. */
9610 if (windows_or_buffers_changed
9611 /* This used to test w->update_mode_line, but we believe
9612 there is no need to recompute the menu in that case. */
9613 || update_mode_lines
9614 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9615 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9616 != !NILP (w
->last_had_star
))
9617 || ((!NILP (Vtransient_mark_mode
)
9618 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9619 != !NILP (w
->region_showing
)))
9621 struct buffer
*prev
= current_buffer
;
9622 int count
= SPECPDL_INDEX ();
9624 specbind (Qinhibit_menubar_update
, Qt
);
9626 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9627 if (save_match_data
)
9628 record_unwind_save_match_data ();
9629 if (NILP (Voverriding_local_map_menu_flag
))
9631 specbind (Qoverriding_terminal_local_map
, Qnil
);
9632 specbind (Qoverriding_local_map
, Qnil
);
9637 /* Run the Lucid hook. */
9638 safe_run_hooks (Qactivate_menubar_hook
);
9640 /* If it has changed current-menubar from previous value,
9641 really recompute the menu-bar from the value. */
9642 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9643 call0 (Qrecompute_lucid_menubar
);
9645 safe_run_hooks (Qmenu_bar_update_hook
);
9650 XSETFRAME (Vmenu_updating_frame
, f
);
9651 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9653 /* Redisplay the menu bar in case we changed it. */
9654 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9655 || defined (USE_GTK)
9656 if (FRAME_WINDOW_P (f
))
9659 /* All frames on Mac OS share the same menubar. So only
9660 the selected frame should be allowed to set it. */
9661 if (f
== SELECTED_FRAME ())
9663 set_frame_menubar (f
, 0, 0);
9666 /* On a terminal screen, the menu bar is an ordinary screen
9667 line, and this makes it get updated. */
9668 w
->update_mode_line
= Qt
;
9669 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9670 /* In the non-toolkit version, the menu bar is an ordinary screen
9671 line, and this makes it get updated. */
9672 w
->update_mode_line
= Qt
;
9673 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9675 unbind_to (count
, Qnil
);
9676 set_buffer_internal_1 (prev
);
9685 /***********************************************************************
9687 ***********************************************************************/
9689 #ifdef HAVE_WINDOW_SYSTEM
9692 Nominal cursor position -- where to draw output.
9693 HPOS and VPOS are window relative glyph matrix coordinates.
9694 X and Y are window relative pixel coordinates. */
9696 struct cursor_pos output_cursor
;
9700 Set the global variable output_cursor to CURSOR. All cursor
9701 positions are relative to updated_window. */
9704 set_output_cursor (cursor
)
9705 struct cursor_pos
*cursor
;
9707 output_cursor
.hpos
= cursor
->hpos
;
9708 output_cursor
.vpos
= cursor
->vpos
;
9709 output_cursor
.x
= cursor
->x
;
9710 output_cursor
.y
= cursor
->y
;
9715 Set a nominal cursor position.
9717 HPOS and VPOS are column/row positions in a window glyph matrix. X
9718 and Y are window text area relative pixel positions.
9720 If this is done during an update, updated_window will contain the
9721 window that is being updated and the position is the future output
9722 cursor position for that window. If updated_window is null, use
9723 selected_window and display the cursor at the given position. */
9726 x_cursor_to (vpos
, hpos
, y
, x
)
9727 int vpos
, hpos
, y
, x
;
9731 /* If updated_window is not set, work on selected_window. */
9735 w
= XWINDOW (selected_window
);
9737 /* Set the output cursor. */
9738 output_cursor
.hpos
= hpos
;
9739 output_cursor
.vpos
= vpos
;
9740 output_cursor
.x
= x
;
9741 output_cursor
.y
= y
;
9743 /* If not called as part of an update, really display the cursor.
9744 This will also set the cursor position of W. */
9745 if (updated_window
== NULL
)
9748 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9749 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9750 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9755 #endif /* HAVE_WINDOW_SYSTEM */
9758 /***********************************************************************
9760 ***********************************************************************/
9762 #ifdef HAVE_WINDOW_SYSTEM
9764 /* Where the mouse was last time we reported a mouse event. */
9766 FRAME_PTR last_mouse_frame
;
9768 /* Tool-bar item index of the item on which a mouse button was pressed
9771 int last_tool_bar_item
;
9774 /* Update the tool-bar item list for frame F. This has to be done
9775 before we start to fill in any display lines. Called from
9776 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9777 and restore it here. */
9780 update_tool_bar (f
, save_match_data
)
9782 int save_match_data
;
9784 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9785 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9787 int do_update
= WINDOWP (f
->tool_bar_window
)
9788 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9796 window
= FRAME_SELECTED_WINDOW (f
);
9797 w
= XWINDOW (window
);
9799 /* If the user has switched buffers or windows, we need to
9800 recompute to reflect the new bindings. But we'll
9801 recompute when update_mode_lines is set too; that means
9802 that people can use force-mode-line-update to request
9803 that the menu bar be recomputed. The adverse effect on
9804 the rest of the redisplay algorithm is about the same as
9805 windows_or_buffers_changed anyway. */
9806 if (windows_or_buffers_changed
9807 || !NILP (w
->update_mode_line
)
9808 || update_mode_lines
9809 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9810 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9811 != !NILP (w
->last_had_star
))
9812 || ((!NILP (Vtransient_mark_mode
)
9813 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9814 != !NILP (w
->region_showing
)))
9816 struct buffer
*prev
= current_buffer
;
9817 int count
= SPECPDL_INDEX ();
9818 Lisp_Object new_tool_bar
;
9820 struct gcpro gcpro1
;
9822 /* Set current_buffer to the buffer of the selected
9823 window of the frame, so that we get the right local
9825 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9827 /* Save match data, if we must. */
9828 if (save_match_data
)
9829 record_unwind_save_match_data ();
9831 /* Make sure that we don't accidentally use bogus keymaps. */
9832 if (NILP (Voverriding_local_map_menu_flag
))
9834 specbind (Qoverriding_terminal_local_map
, Qnil
);
9835 specbind (Qoverriding_local_map
, Qnil
);
9838 GCPRO1 (new_tool_bar
);
9840 /* Build desired tool-bar items from keymaps. */
9841 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9844 /* Redisplay the tool-bar if we changed it. */
9845 if (new_n_tool_bar
!= f
->n_tool_bar_items
9846 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9848 /* Redisplay that happens asynchronously due to an expose event
9849 may access f->tool_bar_items. Make sure we update both
9850 variables within BLOCK_INPUT so no such event interrupts. */
9852 f
->tool_bar_items
= new_tool_bar
;
9853 f
->n_tool_bar_items
= new_n_tool_bar
;
9854 w
->update_mode_line
= Qt
;
9860 unbind_to (count
, Qnil
);
9861 set_buffer_internal_1 (prev
);
9867 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9868 F's desired tool-bar contents. F->tool_bar_items must have
9869 been set up previously by calling prepare_menu_bars. */
9872 build_desired_tool_bar_string (f
)
9875 int i
, size
, size_needed
;
9876 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9877 Lisp_Object image
, plist
, props
;
9879 image
= plist
= props
= Qnil
;
9880 GCPRO3 (image
, plist
, props
);
9882 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9883 Otherwise, make a new string. */
9885 /* The size of the string we might be able to reuse. */
9886 size
= (STRINGP (f
->desired_tool_bar_string
)
9887 ? SCHARS (f
->desired_tool_bar_string
)
9890 /* We need one space in the string for each image. */
9891 size_needed
= f
->n_tool_bar_items
;
9893 /* Reuse f->desired_tool_bar_string, if possible. */
9894 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9895 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9899 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9900 Fremove_text_properties (make_number (0), make_number (size
),
9901 props
, f
->desired_tool_bar_string
);
9904 /* Put a `display' property on the string for the images to display,
9905 put a `menu_item' property on tool-bar items with a value that
9906 is the index of the item in F's tool-bar item vector. */
9907 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9909 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9911 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9912 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9913 int hmargin
, vmargin
, relief
, idx
, end
;
9914 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9916 /* If image is a vector, choose the image according to the
9918 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9919 if (VECTORP (image
))
9923 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9924 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9927 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9928 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9930 xassert (ASIZE (image
) >= idx
);
9931 image
= AREF (image
, idx
);
9936 /* Ignore invalid image specifications. */
9937 if (!valid_image_p (image
))
9940 /* Display the tool-bar button pressed, or depressed. */
9941 plist
= Fcopy_sequence (XCDR (image
));
9943 /* Compute margin and relief to draw. */
9944 relief
= (tool_bar_button_relief
>= 0
9945 ? tool_bar_button_relief
9946 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9947 hmargin
= vmargin
= relief
;
9949 if (INTEGERP (Vtool_bar_button_margin
)
9950 && XINT (Vtool_bar_button_margin
) > 0)
9952 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9953 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9955 else if (CONSP (Vtool_bar_button_margin
))
9957 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9958 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9959 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9961 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9962 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9963 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9966 if (auto_raise_tool_bar_buttons_p
)
9968 /* Add a `:relief' property to the image spec if the item is
9972 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9979 /* If image is selected, display it pressed, i.e. with a
9980 negative relief. If it's not selected, display it with a
9982 plist
= Fplist_put (plist
, QCrelief
,
9984 ? make_number (-relief
)
9985 : make_number (relief
)));
9990 /* Put a margin around the image. */
9991 if (hmargin
|| vmargin
)
9993 if (hmargin
== vmargin
)
9994 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9996 plist
= Fplist_put (plist
, QCmargin
,
9997 Fcons (make_number (hmargin
),
9998 make_number (vmargin
)));
10001 /* If button is not enabled, and we don't have special images
10002 for the disabled state, make the image appear disabled by
10003 applying an appropriate algorithm to it. */
10004 if (!enabled_p
&& idx
< 0)
10005 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10007 /* Put a `display' text property on the string for the image to
10008 display. Put a `menu-item' property on the string that gives
10009 the start of this item's properties in the tool-bar items
10011 image
= Fcons (Qimage
, plist
);
10012 props
= list4 (Qdisplay
, image
,
10013 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10015 /* Let the last image hide all remaining spaces in the tool bar
10016 string. The string can be longer than needed when we reuse a
10017 previous string. */
10018 if (i
+ 1 == f
->n_tool_bar_items
)
10019 end
= SCHARS (f
->desired_tool_bar_string
);
10022 Fadd_text_properties (make_number (i
), make_number (end
),
10023 props
, f
->desired_tool_bar_string
);
10031 /* Display one line of the tool-bar of frame IT->f.
10033 HEIGHT specifies the desired height of the tool-bar line.
10034 If the actual height of the glyph row is less than HEIGHT, the
10035 row's height is increased to HEIGHT, and the icons are centered
10036 vertically in the new height.
10038 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10039 count a final empty row in case the tool-bar width exactly matches
10044 display_tool_bar_line (it
, height
)
10048 struct glyph_row
*row
= it
->glyph_row
;
10049 int max_x
= it
->last_visible_x
;
10050 struct glyph
*last
;
10052 prepare_desired_row (row
);
10053 row
->y
= it
->current_y
;
10055 /* Note that this isn't made use of if the face hasn't a box,
10056 so there's no need to check the face here. */
10057 it
->start_of_box_run_p
= 1;
10059 while (it
->current_x
< max_x
)
10061 int x
, n_glyphs_before
, i
, nglyphs
;
10062 struct it it_before
;
10064 /* Get the next display element. */
10065 if (!get_next_display_element (it
))
10067 /* Don't count empty row if we are counting needed tool-bar lines. */
10068 if (height
< 0 && !it
->hpos
)
10073 /* Produce glyphs. */
10074 n_glyphs_before
= row
->used
[TEXT_AREA
];
10077 PRODUCE_GLYPHS (it
);
10079 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10081 x
= it_before
.current_x
;
10082 while (i
< nglyphs
)
10084 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10086 if (x
+ glyph
->pixel_width
> max_x
)
10088 /* Glyph doesn't fit on line. Backtrack. */
10089 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10091 /* If this is the only glyph on this line, it will never fit on the
10092 toolbar, so skip it. But ensure there is at least one glyph,
10093 so we don't accidentally disable the tool-bar. */
10094 if (n_glyphs_before
== 0
10095 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10101 x
+= glyph
->pixel_width
;
10105 /* Stop at line ends. */
10106 if (ITERATOR_AT_END_OF_LINE_P (it
))
10109 set_iterator_to_next (it
, 1);
10114 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10116 /* Use default face for the border below the tool bar.
10118 FIXME: When auto-resize-tool-bars is grow-only, there is
10119 no additional border below the possibly empty tool-bar lines.
10120 So to make the extra empty lines look "normal", we have to
10121 use the tool-bar face for the border too. */
10122 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10123 it
->face_id
= DEFAULT_FACE_ID
;
10125 extend_face_to_end_of_line (it
);
10126 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10127 last
->right_box_line_p
= 1;
10128 if (last
== row
->glyphs
[TEXT_AREA
])
10129 last
->left_box_line_p
= 1;
10131 /* Make line the desired height and center it vertically. */
10132 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10134 /* Don't add more than one line height. */
10135 height
%= FRAME_LINE_HEIGHT (it
->f
);
10136 it
->max_ascent
+= height
/ 2;
10137 it
->max_descent
+= (height
+ 1) / 2;
10140 compute_line_metrics (it
);
10142 /* If line is empty, make it occupy the rest of the tool-bar. */
10143 if (!row
->displays_text_p
)
10145 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10146 row
->visible_height
= row
->height
;
10147 row
->ascent
= row
->phys_ascent
= 0;
10148 row
->extra_line_spacing
= 0;
10151 row
->full_width_p
= 1;
10152 row
->continued_p
= 0;
10153 row
->truncated_on_left_p
= 0;
10154 row
->truncated_on_right_p
= 0;
10156 it
->current_x
= it
->hpos
= 0;
10157 it
->current_y
+= row
->height
;
10163 /* Max tool-bar height. */
10165 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10166 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10168 /* Value is the number of screen lines needed to make all tool-bar
10169 items of frame F visible. The number of actual rows needed is
10170 returned in *N_ROWS if non-NULL. */
10173 tool_bar_lines_needed (f
, n_rows
)
10177 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10179 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10180 the desired matrix, so use (unused) mode-line row as temporary row to
10181 avoid destroying the first tool-bar row. */
10182 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10184 /* Initialize an iterator for iteration over
10185 F->desired_tool_bar_string in the tool-bar window of frame F. */
10186 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10187 it
.first_visible_x
= 0;
10188 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10189 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10191 while (!ITERATOR_AT_END_P (&it
))
10193 clear_glyph_row (temp_row
);
10194 it
.glyph_row
= temp_row
;
10195 display_tool_bar_line (&it
, -1);
10197 clear_glyph_row (temp_row
);
10199 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10201 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10203 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10207 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10209 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10218 frame
= selected_frame
;
10220 CHECK_FRAME (frame
);
10221 f
= XFRAME (frame
);
10223 if (WINDOWP (f
->tool_bar_window
)
10224 || (w
= XWINDOW (f
->tool_bar_window
),
10225 WINDOW_TOTAL_LINES (w
) > 0))
10227 update_tool_bar (f
, 1);
10228 if (f
->n_tool_bar_items
)
10230 build_desired_tool_bar_string (f
);
10231 nlines
= tool_bar_lines_needed (f
, NULL
);
10235 return make_number (nlines
);
10239 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10240 height should be changed. */
10243 redisplay_tool_bar (f
)
10248 struct glyph_row
*row
;
10250 #if defined (USE_GTK) || USE_MAC_TOOLBAR
10251 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10252 update_frame_tool_bar (f
);
10256 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10257 do anything. This means you must start with tool-bar-lines
10258 non-zero to get the auto-sizing effect. Or in other words, you
10259 can turn off tool-bars by specifying tool-bar-lines zero. */
10260 if (!WINDOWP (f
->tool_bar_window
)
10261 || (w
= XWINDOW (f
->tool_bar_window
),
10262 WINDOW_TOTAL_LINES (w
) == 0))
10265 /* Set up an iterator for the tool-bar window. */
10266 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10267 it
.first_visible_x
= 0;
10268 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10269 row
= it
.glyph_row
;
10271 /* Build a string that represents the contents of the tool-bar. */
10272 build_desired_tool_bar_string (f
);
10273 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10275 if (f
->n_tool_bar_rows
== 0)
10279 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10280 nlines
!= WINDOW_TOTAL_LINES (w
)))
10282 extern Lisp_Object Qtool_bar_lines
;
10284 int old_height
= WINDOW_TOTAL_LINES (w
);
10286 XSETFRAME (frame
, f
);
10287 Fmodify_frame_parameters (frame
,
10288 Fcons (Fcons (Qtool_bar_lines
,
10289 make_number (nlines
)),
10291 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10293 clear_glyph_matrix (w
->desired_matrix
);
10294 fonts_changed_p
= 1;
10300 /* Display as many lines as needed to display all tool-bar items. */
10302 if (f
->n_tool_bar_rows
> 0)
10304 int border
, rows
, height
, extra
;
10306 if (INTEGERP (Vtool_bar_border
))
10307 border
= XINT (Vtool_bar_border
);
10308 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10309 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10310 else if (EQ (Vtool_bar_border
, Qborder_width
))
10311 border
= f
->border_width
;
10317 rows
= f
->n_tool_bar_rows
;
10318 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10319 extra
= it
.last_visible_y
- border
- height
* rows
;
10321 while (it
.current_y
< it
.last_visible_y
)
10324 if (extra
> 0 && rows
-- > 0)
10326 h
= (extra
+ rows
- 1) / rows
;
10329 display_tool_bar_line (&it
, height
+ h
);
10334 while (it
.current_y
< it
.last_visible_y
)
10335 display_tool_bar_line (&it
, 0);
10338 /* It doesn't make much sense to try scrolling in the tool-bar
10339 window, so don't do it. */
10340 w
->desired_matrix
->no_scrolling_p
= 1;
10341 w
->must_be_updated_p
= 1;
10343 if (!NILP (Vauto_resize_tool_bars
))
10345 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10346 int change_height_p
= 0;
10348 /* If we couldn't display everything, change the tool-bar's
10349 height if there is room for more. */
10350 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10351 && it
.current_y
< max_tool_bar_height
)
10352 change_height_p
= 1;
10354 row
= it
.glyph_row
- 1;
10356 /* If there are blank lines at the end, except for a partially
10357 visible blank line at the end that is smaller than
10358 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10359 if (!row
->displays_text_p
10360 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10361 change_height_p
= 1;
10363 /* If row displays tool-bar items, but is partially visible,
10364 change the tool-bar's height. */
10365 if (row
->displays_text_p
10366 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10367 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10368 change_height_p
= 1;
10370 /* Resize windows as needed by changing the `tool-bar-lines'
10371 frame parameter. */
10372 if (change_height_p
)
10374 extern Lisp_Object Qtool_bar_lines
;
10376 int old_height
= WINDOW_TOTAL_LINES (w
);
10378 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10380 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10381 && !f
->minimize_tool_bar_window_p
)
10382 ? (nlines
> old_height
)
10383 : (nlines
!= old_height
));
10384 f
->minimize_tool_bar_window_p
= 0;
10386 if (change_height_p
)
10388 XSETFRAME (frame
, f
);
10389 Fmodify_frame_parameters (frame
,
10390 Fcons (Fcons (Qtool_bar_lines
,
10391 make_number (nlines
)),
10393 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10395 clear_glyph_matrix (w
->desired_matrix
);
10396 f
->n_tool_bar_rows
= nrows
;
10397 fonts_changed_p
= 1;
10404 f
->minimize_tool_bar_window_p
= 0;
10409 /* Get information about the tool-bar item which is displayed in GLYPH
10410 on frame F. Return in *PROP_IDX the index where tool-bar item
10411 properties start in F->tool_bar_items. Value is zero if
10412 GLYPH doesn't display a tool-bar item. */
10415 tool_bar_item_info (f
, glyph
, prop_idx
)
10417 struct glyph
*glyph
;
10424 /* This function can be called asynchronously, which means we must
10425 exclude any possibility that Fget_text_property signals an
10427 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10428 charpos
= max (0, charpos
);
10430 /* Get the text property `menu-item' at pos. The value of that
10431 property is the start index of this item's properties in
10432 F->tool_bar_items. */
10433 prop
= Fget_text_property (make_number (charpos
),
10434 Qmenu_item
, f
->current_tool_bar_string
);
10435 if (INTEGERP (prop
))
10437 *prop_idx
= XINT (prop
);
10447 /* Get information about the tool-bar item at position X/Y on frame F.
10448 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10449 the current matrix of the tool-bar window of F, or NULL if not
10450 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10451 item in F->tool_bar_items. Value is
10453 -1 if X/Y is not on a tool-bar item
10454 0 if X/Y is on the same item that was highlighted before.
10458 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10461 struct glyph
**glyph
;
10462 int *hpos
, *vpos
, *prop_idx
;
10464 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10465 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10468 /* Find the glyph under X/Y. */
10469 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10470 if (*glyph
== NULL
)
10473 /* Get the start of this tool-bar item's properties in
10474 f->tool_bar_items. */
10475 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10478 /* Is mouse on the highlighted item? */
10479 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10480 && *vpos
>= dpyinfo
->mouse_face_beg_row
10481 && *vpos
<= dpyinfo
->mouse_face_end_row
10482 && (*vpos
> dpyinfo
->mouse_face_beg_row
10483 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10484 && (*vpos
< dpyinfo
->mouse_face_end_row
10485 || *hpos
< dpyinfo
->mouse_face_end_col
10486 || dpyinfo
->mouse_face_past_end
))
10494 Handle mouse button event on the tool-bar of frame F, at
10495 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10496 0 for button release. MODIFIERS is event modifiers for button
10500 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10503 unsigned int modifiers
;
10505 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10506 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10507 int hpos
, vpos
, prop_idx
;
10508 struct glyph
*glyph
;
10509 Lisp_Object enabled_p
;
10511 /* If not on the highlighted tool-bar item, return. */
10512 frame_to_window_pixel_xy (w
, &x
, &y
);
10513 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10516 /* If item is disabled, do nothing. */
10517 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10518 if (NILP (enabled_p
))
10523 /* Show item in pressed state. */
10524 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10525 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10526 last_tool_bar_item
= prop_idx
;
10530 Lisp_Object key
, frame
;
10531 struct input_event event
;
10532 EVENT_INIT (event
);
10534 /* Show item in released state. */
10535 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10536 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10538 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10540 XSETFRAME (frame
, f
);
10541 event
.kind
= TOOL_BAR_EVENT
;
10542 event
.frame_or_window
= frame
;
10544 kbd_buffer_store_event (&event
);
10546 event
.kind
= TOOL_BAR_EVENT
;
10547 event
.frame_or_window
= frame
;
10549 event
.modifiers
= modifiers
;
10550 kbd_buffer_store_event (&event
);
10551 last_tool_bar_item
= -1;
10556 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10557 tool-bar window-relative coordinates X/Y. Called from
10558 note_mouse_highlight. */
10561 note_tool_bar_highlight (f
, x
, y
)
10565 Lisp_Object window
= f
->tool_bar_window
;
10566 struct window
*w
= XWINDOW (window
);
10567 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10569 struct glyph
*glyph
;
10570 struct glyph_row
*row
;
10572 Lisp_Object enabled_p
;
10574 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10575 int mouse_down_p
, rc
;
10577 /* Function note_mouse_highlight is called with negative x(y
10578 values when mouse moves outside of the frame. */
10579 if (x
<= 0 || y
<= 0)
10581 clear_mouse_face (dpyinfo
);
10585 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10588 /* Not on tool-bar item. */
10589 clear_mouse_face (dpyinfo
);
10593 /* On same tool-bar item as before. */
10594 goto set_help_echo
;
10596 clear_mouse_face (dpyinfo
);
10598 /* Mouse is down, but on different tool-bar item? */
10599 mouse_down_p
= (dpyinfo
->grabbed
10600 && f
== last_mouse_frame
10601 && FRAME_LIVE_P (f
));
10603 && last_tool_bar_item
!= prop_idx
)
10606 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10607 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10609 /* If tool-bar item is not enabled, don't highlight it. */
10610 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10611 if (!NILP (enabled_p
))
10613 /* Compute the x-position of the glyph. In front and past the
10614 image is a space. We include this in the highlighted area. */
10615 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10616 for (i
= x
= 0; i
< hpos
; ++i
)
10617 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10619 /* Record this as the current active region. */
10620 dpyinfo
->mouse_face_beg_col
= hpos
;
10621 dpyinfo
->mouse_face_beg_row
= vpos
;
10622 dpyinfo
->mouse_face_beg_x
= x
;
10623 dpyinfo
->mouse_face_beg_y
= row
->y
;
10624 dpyinfo
->mouse_face_past_end
= 0;
10626 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10627 dpyinfo
->mouse_face_end_row
= vpos
;
10628 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10629 dpyinfo
->mouse_face_end_y
= row
->y
;
10630 dpyinfo
->mouse_face_window
= window
;
10631 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10633 /* Display it as active. */
10634 show_mouse_face (dpyinfo
, draw
);
10635 dpyinfo
->mouse_face_image_state
= draw
;
10640 /* Set help_echo_string to a help string to display for this tool-bar item.
10641 XTread_socket does the rest. */
10642 help_echo_object
= help_echo_window
= Qnil
;
10643 help_echo_pos
= -1;
10644 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10645 if (NILP (help_echo_string
))
10646 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10649 #endif /* HAVE_WINDOW_SYSTEM */
10653 /************************************************************************
10654 Horizontal scrolling
10655 ************************************************************************/
10657 static int hscroll_window_tree
P_ ((Lisp_Object
));
10658 static int hscroll_windows
P_ ((Lisp_Object
));
10660 /* For all leaf windows in the window tree rooted at WINDOW, set their
10661 hscroll value so that PT is (i) visible in the window, and (ii) so
10662 that it is not within a certain margin at the window's left and
10663 right border. Value is non-zero if any window's hscroll has been
10667 hscroll_window_tree (window
)
10668 Lisp_Object window
;
10670 int hscrolled_p
= 0;
10671 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10672 int hscroll_step_abs
= 0;
10673 double hscroll_step_rel
= 0;
10675 if (hscroll_relative_p
)
10677 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10678 if (hscroll_step_rel
< 0)
10680 hscroll_relative_p
= 0;
10681 hscroll_step_abs
= 0;
10684 else if (INTEGERP (Vhscroll_step
))
10686 hscroll_step_abs
= XINT (Vhscroll_step
);
10687 if (hscroll_step_abs
< 0)
10688 hscroll_step_abs
= 0;
10691 hscroll_step_abs
= 0;
10693 while (WINDOWP (window
))
10695 struct window
*w
= XWINDOW (window
);
10697 if (WINDOWP (w
->hchild
))
10698 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10699 else if (WINDOWP (w
->vchild
))
10700 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10701 else if (w
->cursor
.vpos
>= 0)
10704 int text_area_width
;
10705 struct glyph_row
*current_cursor_row
10706 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10707 struct glyph_row
*desired_cursor_row
10708 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10709 struct glyph_row
*cursor_row
10710 = (desired_cursor_row
->enabled_p
10711 ? desired_cursor_row
10712 : current_cursor_row
);
10714 text_area_width
= window_box_width (w
, TEXT_AREA
);
10716 /* Scroll when cursor is inside this scroll margin. */
10717 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10719 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10720 && ((XFASTINT (w
->hscroll
)
10721 && w
->cursor
.x
<= h_margin
)
10722 || (cursor_row
->enabled_p
10723 && cursor_row
->truncated_on_right_p
10724 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10728 struct buffer
*saved_current_buffer
;
10732 /* Find point in a display of infinite width. */
10733 saved_current_buffer
= current_buffer
;
10734 current_buffer
= XBUFFER (w
->buffer
);
10736 if (w
== XWINDOW (selected_window
))
10737 pt
= BUF_PT (current_buffer
);
10740 pt
= marker_position (w
->pointm
);
10741 pt
= max (BEGV
, pt
);
10745 /* Move iterator to pt starting at cursor_row->start in
10746 a line with infinite width. */
10747 init_to_row_start (&it
, w
, cursor_row
);
10748 it
.last_visible_x
= INFINITY
;
10749 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10750 current_buffer
= saved_current_buffer
;
10752 /* Position cursor in window. */
10753 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10754 hscroll
= max (0, (it
.current_x
10755 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10756 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10757 : (text_area_width
/ 2))))
10758 / FRAME_COLUMN_WIDTH (it
.f
);
10759 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10761 if (hscroll_relative_p
)
10762 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10765 wanted_x
= text_area_width
10766 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10769 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10773 if (hscroll_relative_p
)
10774 wanted_x
= text_area_width
* hscroll_step_rel
10777 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10780 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10782 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10784 /* Don't call Fset_window_hscroll if value hasn't
10785 changed because it will prevent redisplay
10787 if (XFASTINT (w
->hscroll
) != hscroll
)
10789 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10790 w
->hscroll
= make_number (hscroll
);
10799 /* Value is non-zero if hscroll of any leaf window has been changed. */
10800 return hscrolled_p
;
10804 /* Set hscroll so that cursor is visible and not inside horizontal
10805 scroll margins for all windows in the tree rooted at WINDOW. See
10806 also hscroll_window_tree above. Value is non-zero if any window's
10807 hscroll has been changed. If it has, desired matrices on the frame
10808 of WINDOW are cleared. */
10811 hscroll_windows (window
)
10812 Lisp_Object window
;
10814 int hscrolled_p
= hscroll_window_tree (window
);
10816 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10817 return hscrolled_p
;
10822 /************************************************************************
10824 ************************************************************************/
10826 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10827 to a non-zero value. This is sometimes handy to have in a debugger
10832 /* First and last unchanged row for try_window_id. */
10834 int debug_first_unchanged_at_end_vpos
;
10835 int debug_last_unchanged_at_beg_vpos
;
10837 /* Delta vpos and y. */
10839 int debug_dvpos
, debug_dy
;
10841 /* Delta in characters and bytes for try_window_id. */
10843 int debug_delta
, debug_delta_bytes
;
10845 /* Values of window_end_pos and window_end_vpos at the end of
10848 EMACS_INT debug_end_pos
, debug_end_vpos
;
10850 /* Append a string to W->desired_matrix->method. FMT is a printf
10851 format string. A1...A9 are a supplement for a variable-length
10852 argument list. If trace_redisplay_p is non-zero also printf the
10853 resulting string to stderr. */
10856 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10859 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10862 char *method
= w
->desired_matrix
->method
;
10863 int len
= strlen (method
);
10864 int size
= sizeof w
->desired_matrix
->method
;
10865 int remaining
= size
- len
- 1;
10867 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10868 if (len
&& remaining
)
10871 --remaining
, ++len
;
10874 strncpy (method
+ len
, buffer
, remaining
);
10876 if (trace_redisplay_p
)
10877 fprintf (stderr
, "%p (%s): %s\n",
10879 ((BUFFERP (w
->buffer
)
10880 && STRINGP (XBUFFER (w
->buffer
)->name
))
10881 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10886 #endif /* GLYPH_DEBUG */
10889 /* Value is non-zero if all changes in window W, which displays
10890 current_buffer, are in the text between START and END. START is a
10891 buffer position, END is given as a distance from Z. Used in
10892 redisplay_internal for display optimization. */
10895 text_outside_line_unchanged_p (w
, start
, end
)
10899 int unchanged_p
= 1;
10901 /* If text or overlays have changed, see where. */
10902 if (XFASTINT (w
->last_modified
) < MODIFF
10903 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10905 /* Gap in the line? */
10906 if (GPT
< start
|| Z
- GPT
< end
)
10909 /* Changes start in front of the line, or end after it? */
10911 && (BEG_UNCHANGED
< start
- 1
10912 || END_UNCHANGED
< end
))
10915 /* If selective display, can't optimize if changes start at the
10916 beginning of the line. */
10918 && INTEGERP (current_buffer
->selective_display
)
10919 && XINT (current_buffer
->selective_display
) > 0
10920 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10923 /* If there are overlays at the start or end of the line, these
10924 may have overlay strings with newlines in them. A change at
10925 START, for instance, may actually concern the display of such
10926 overlay strings as well, and they are displayed on different
10927 lines. So, quickly rule out this case. (For the future, it
10928 might be desirable to implement something more telling than
10929 just BEG/END_UNCHANGED.) */
10932 if (BEG
+ BEG_UNCHANGED
== start
10933 && overlay_touches_p (start
))
10935 if (END_UNCHANGED
== end
10936 && overlay_touches_p (Z
- end
))
10941 return unchanged_p
;
10945 /* Do a frame update, taking possible shortcuts into account. This is
10946 the main external entry point for redisplay.
10948 If the last redisplay displayed an echo area message and that message
10949 is no longer requested, we clear the echo area or bring back the
10950 mini-buffer if that is in use. */
10955 redisplay_internal (0);
10960 overlay_arrow_string_or_property (var
)
10965 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10968 return Voverlay_arrow_string
;
10971 /* Return 1 if there are any overlay-arrows in current_buffer. */
10973 overlay_arrow_in_current_buffer_p ()
10977 for (vlist
= Voverlay_arrow_variable_list
;
10979 vlist
= XCDR (vlist
))
10981 Lisp_Object var
= XCAR (vlist
);
10984 if (!SYMBOLP (var
))
10986 val
= find_symbol_value (var
);
10988 && current_buffer
== XMARKER (val
)->buffer
)
10995 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10999 overlay_arrows_changed_p ()
11003 for (vlist
= Voverlay_arrow_variable_list
;
11005 vlist
= XCDR (vlist
))
11007 Lisp_Object var
= XCAR (vlist
);
11008 Lisp_Object val
, pstr
;
11010 if (!SYMBOLP (var
))
11012 val
= find_symbol_value (var
);
11013 if (!MARKERP (val
))
11015 if (! EQ (COERCE_MARKER (val
),
11016 Fget (var
, Qlast_arrow_position
))
11017 || ! (pstr
= overlay_arrow_string_or_property (var
),
11018 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11024 /* Mark overlay arrows to be updated on next redisplay. */
11027 update_overlay_arrows (up_to_date
)
11032 for (vlist
= Voverlay_arrow_variable_list
;
11034 vlist
= XCDR (vlist
))
11036 Lisp_Object var
= XCAR (vlist
);
11038 if (!SYMBOLP (var
))
11041 if (up_to_date
> 0)
11043 Lisp_Object val
= find_symbol_value (var
);
11044 Fput (var
, Qlast_arrow_position
,
11045 COERCE_MARKER (val
));
11046 Fput (var
, Qlast_arrow_string
,
11047 overlay_arrow_string_or_property (var
));
11049 else if (up_to_date
< 0
11050 || !NILP (Fget (var
, Qlast_arrow_position
)))
11052 Fput (var
, Qlast_arrow_position
, Qt
);
11053 Fput (var
, Qlast_arrow_string
, Qt
);
11059 /* Return overlay arrow string to display at row.
11060 Return integer (bitmap number) for arrow bitmap in left fringe.
11061 Return nil if no overlay arrow. */
11064 overlay_arrow_at_row (it
, row
)
11066 struct glyph_row
*row
;
11070 for (vlist
= Voverlay_arrow_variable_list
;
11072 vlist
= XCDR (vlist
))
11074 Lisp_Object var
= XCAR (vlist
);
11077 if (!SYMBOLP (var
))
11080 val
= find_symbol_value (var
);
11083 && current_buffer
== XMARKER (val
)->buffer
11084 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11086 if (FRAME_WINDOW_P (it
->f
)
11087 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11089 #ifdef HAVE_WINDOW_SYSTEM
11090 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11093 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11094 return make_number (fringe_bitmap
);
11097 return make_number (-1); /* Use default arrow bitmap */
11099 return overlay_arrow_string_or_property (var
);
11106 /* Return 1 if point moved out of or into a composition. Otherwise
11107 return 0. PREV_BUF and PREV_PT are the last point buffer and
11108 position. BUF and PT are the current point buffer and position. */
11111 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11112 struct buffer
*prev_buf
, *buf
;
11115 EMACS_INT start
, end
;
11117 Lisp_Object buffer
;
11119 XSETBUFFER (buffer
, buf
);
11120 /* Check a composition at the last point if point moved within the
11122 if (prev_buf
== buf
)
11125 /* Point didn't move. */
11128 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11129 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11130 && COMPOSITION_VALID_P (start
, end
, prop
)
11131 && start
< prev_pt
&& end
> prev_pt
)
11132 /* The last point was within the composition. Return 1 iff
11133 point moved out of the composition. */
11134 return (pt
<= start
|| pt
>= end
);
11137 /* Check a composition at the current point. */
11138 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11139 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11140 && COMPOSITION_VALID_P (start
, end
, prop
)
11141 && start
< pt
&& end
> pt
);
11145 /* Reconsider the setting of B->clip_changed which is displayed
11149 reconsider_clip_changes (w
, b
)
11153 if (b
->clip_changed
11154 && !NILP (w
->window_end_valid
)
11155 && w
->current_matrix
->buffer
== b
11156 && w
->current_matrix
->zv
== BUF_ZV (b
)
11157 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11158 b
->clip_changed
= 0;
11160 /* If display wasn't paused, and W is not a tool bar window, see if
11161 point has been moved into or out of a composition. In that case,
11162 we set b->clip_changed to 1 to force updating the screen. If
11163 b->clip_changed has already been set to 1, we can skip this
11165 if (!b
->clip_changed
11166 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11170 if (w
== XWINDOW (selected_window
))
11171 pt
= BUF_PT (current_buffer
);
11173 pt
= marker_position (w
->pointm
);
11175 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11176 || pt
!= XINT (w
->last_point
))
11177 && check_point_in_composition (w
->current_matrix
->buffer
,
11178 XINT (w
->last_point
),
11179 XBUFFER (w
->buffer
), pt
))
11180 b
->clip_changed
= 1;
11185 /* Select FRAME to forward the values of frame-local variables into C
11186 variables so that the redisplay routines can access those values
11190 select_frame_for_redisplay (frame
)
11193 Lisp_Object tail
, symbol
, val
;
11194 Lisp_Object old
= selected_frame
;
11195 struct Lisp_Symbol
*sym
;
11197 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11199 selected_frame
= frame
;
11203 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11204 if (CONSP (XCAR (tail
))
11205 && (symbol
= XCAR (XCAR (tail
)),
11207 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11209 (BUFFER_LOCAL_VALUEP (val
)))
11210 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11211 /* Use find_symbol_value rather than Fsymbol_value
11212 to avoid an error if it is void. */
11213 find_symbol_value (symbol
);
11214 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11218 #define STOP_POLLING \
11219 do { if (! polling_stopped_here) stop_polling (); \
11220 polling_stopped_here = 1; } while (0)
11222 #define RESUME_POLLING \
11223 do { if (polling_stopped_here) start_polling (); \
11224 polling_stopped_here = 0; } while (0)
11227 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11228 response to any user action; therefore, we should preserve the echo
11229 area. (Actually, our caller does that job.) Perhaps in the future
11230 avoid recentering windows if it is not necessary; currently that
11231 causes some problems. */
11234 redisplay_internal (preserve_echo_area
)
11235 int preserve_echo_area
;
11237 struct window
*w
= XWINDOW (selected_window
);
11240 int must_finish
= 0;
11241 struct text_pos tlbufpos
, tlendpos
;
11242 int number_of_visible_frames
;
11245 int polling_stopped_here
= 0;
11246 Lisp_Object old_frame
= selected_frame
;
11248 /* Non-zero means redisplay has to consider all windows on all
11249 frames. Zero means, only selected_window is considered. */
11250 int consider_all_windows_p
;
11252 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11254 /* No redisplay if running in batch mode or frame is not yet fully
11255 initialized, or redisplay is explicitly turned off by setting
11256 Vinhibit_redisplay. */
11258 || !NILP (Vinhibit_redisplay
))
11261 /* Don't examine these until after testing Vinhibit_redisplay.
11262 When Emacs is shutting down, perhaps because its connection to
11263 X has dropped, we should not look at them at all. */
11264 f
= XFRAME (w
->frame
);
11265 sf
= SELECTED_FRAME ();
11267 if (!f
->glyphs_initialized_p
)
11270 /* The flag redisplay_performed_directly_p is set by
11271 direct_output_for_insert when it already did the whole screen
11272 update necessary. */
11273 if (redisplay_performed_directly_p
)
11275 redisplay_performed_directly_p
= 0;
11276 if (!hscroll_windows (selected_window
))
11280 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
11281 if (popup_activated ())
11285 /* I don't think this happens but let's be paranoid. */
11286 if (redisplaying_p
)
11289 /* Record a function that resets redisplaying_p to its old value
11290 when we leave this function. */
11291 count
= SPECPDL_INDEX ();
11292 record_unwind_protect (unwind_redisplay
,
11293 Fcons (make_number (redisplaying_p
), selected_frame
));
11295 specbind (Qinhibit_free_realized_faces
, Qnil
);
11298 Lisp_Object tail
, frame
;
11300 FOR_EACH_FRAME (tail
, frame
)
11302 struct frame
*f
= XFRAME (frame
);
11303 f
->already_hscrolled_p
= 0;
11308 if (!EQ (old_frame
, selected_frame
)
11309 && FRAME_LIVE_P (XFRAME (old_frame
)))
11310 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11311 selected_frame and selected_window to be temporarily out-of-sync so
11312 when we come back here via `goto retry', we need to resync because we
11313 may need to run Elisp code (via prepare_menu_bars). */
11314 select_frame_for_redisplay (old_frame
);
11317 reconsider_clip_changes (w
, current_buffer
);
11318 last_escape_glyph_frame
= NULL
;
11319 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11321 /* If new fonts have been loaded that make a glyph matrix adjustment
11322 necessary, do it. */
11323 if (fonts_changed_p
)
11325 adjust_glyphs (NULL
);
11326 ++windows_or_buffers_changed
;
11327 fonts_changed_p
= 0;
11330 /* If face_change_count is non-zero, init_iterator will free all
11331 realized faces, which includes the faces referenced from current
11332 matrices. So, we can't reuse current matrices in this case. */
11333 if (face_change_count
)
11334 ++windows_or_buffers_changed
;
11336 if (FRAME_TERMCAP_P (sf
)
11337 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11339 /* Since frames on a single ASCII terminal share the same
11340 display area, displaying a different frame means redisplay
11341 the whole thing. */
11342 windows_or_buffers_changed
++;
11343 SET_FRAME_GARBAGED (sf
);
11345 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11347 FRAME_TTY (sf
)->previous_frame
= sf
;
11350 /* Set the visible flags for all frames. Do this before checking
11351 for resized or garbaged frames; they want to know if their frames
11352 are visible. See the comment in frame.h for
11353 FRAME_SAMPLE_VISIBILITY. */
11355 Lisp_Object tail
, frame
;
11357 number_of_visible_frames
= 0;
11359 FOR_EACH_FRAME (tail
, frame
)
11361 struct frame
*f
= XFRAME (frame
);
11363 FRAME_SAMPLE_VISIBILITY (f
);
11364 if (FRAME_VISIBLE_P (f
))
11365 ++number_of_visible_frames
;
11366 clear_desired_matrices (f
);
11371 /* Notice any pending interrupt request to change frame size. */
11372 do_pending_window_change (1);
11374 /* Clear frames marked as garbaged. */
11375 if (frame_garbaged
)
11376 clear_garbaged_frames ();
11378 /* Build menubar and tool-bar items. */
11379 if (NILP (Vmemory_full
))
11380 prepare_menu_bars ();
11382 if (windows_or_buffers_changed
)
11383 update_mode_lines
++;
11385 /* Detect case that we need to write or remove a star in the mode line. */
11386 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11388 w
->update_mode_line
= Qt
;
11389 if (buffer_shared
> 1)
11390 update_mode_lines
++;
11393 /* Avoid invocation of point motion hooks by `current_column' below. */
11394 count1
= SPECPDL_INDEX ();
11395 specbind (Qinhibit_point_motion_hooks
, Qt
);
11397 /* If %c is in the mode line, update it if needed. */
11398 if (!NILP (w
->column_number_displayed
)
11399 /* This alternative quickly identifies a common case
11400 where no change is needed. */
11401 && !(PT
== XFASTINT (w
->last_point
)
11402 && XFASTINT (w
->last_modified
) >= MODIFF
11403 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11404 && (XFASTINT (w
->column_number_displayed
)
11405 != (int) current_column ())) /* iftc */
11406 w
->update_mode_line
= Qt
;
11408 unbind_to (count1
, Qnil
);
11410 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11412 /* The variable buffer_shared is set in redisplay_window and
11413 indicates that we redisplay a buffer in different windows. See
11415 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11416 || cursor_type_changed
);
11418 /* If specs for an arrow have changed, do thorough redisplay
11419 to ensure we remove any arrow that should no longer exist. */
11420 if (overlay_arrows_changed_p ())
11421 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11423 /* Normally the message* functions will have already displayed and
11424 updated the echo area, but the frame may have been trashed, or
11425 the update may have been preempted, so display the echo area
11426 again here. Checking message_cleared_p captures the case that
11427 the echo area should be cleared. */
11428 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11429 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11430 || (message_cleared_p
11431 && minibuf_level
== 0
11432 /* If the mini-window is currently selected, this means the
11433 echo-area doesn't show through. */
11434 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11436 int window_height_changed_p
= echo_area_display (0);
11439 /* If we don't display the current message, don't clear the
11440 message_cleared_p flag, because, if we did, we wouldn't clear
11441 the echo area in the next redisplay which doesn't preserve
11443 if (!display_last_displayed_message_p
)
11444 message_cleared_p
= 0;
11446 if (fonts_changed_p
)
11448 else if (window_height_changed_p
)
11450 consider_all_windows_p
= 1;
11451 ++update_mode_lines
;
11452 ++windows_or_buffers_changed
;
11454 /* If window configuration was changed, frames may have been
11455 marked garbaged. Clear them or we will experience
11456 surprises wrt scrolling. */
11457 if (frame_garbaged
)
11458 clear_garbaged_frames ();
11461 else if (EQ (selected_window
, minibuf_window
)
11462 && (current_buffer
->clip_changed
11463 || XFASTINT (w
->last_modified
) < MODIFF
11464 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11465 && resize_mini_window (w
, 0))
11467 /* Resized active mini-window to fit the size of what it is
11468 showing if its contents might have changed. */
11470 consider_all_windows_p
= 1;
11471 ++windows_or_buffers_changed
;
11472 ++update_mode_lines
;
11474 /* If window configuration was changed, frames may have been
11475 marked garbaged. Clear them or we will experience
11476 surprises wrt scrolling. */
11477 if (frame_garbaged
)
11478 clear_garbaged_frames ();
11482 /* If showing the region, and mark has changed, we must redisplay
11483 the whole window. The assignment to this_line_start_pos prevents
11484 the optimization directly below this if-statement. */
11485 if (((!NILP (Vtransient_mark_mode
)
11486 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11487 != !NILP (w
->region_showing
))
11488 || (!NILP (w
->region_showing
)
11489 && !EQ (w
->region_showing
,
11490 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11491 CHARPOS (this_line_start_pos
) = 0;
11493 /* Optimize the case that only the line containing the cursor in the
11494 selected window has changed. Variables starting with this_ are
11495 set in display_line and record information about the line
11496 containing the cursor. */
11497 tlbufpos
= this_line_start_pos
;
11498 tlendpos
= this_line_end_pos
;
11499 if (!consider_all_windows_p
11500 && CHARPOS (tlbufpos
) > 0
11501 && NILP (w
->update_mode_line
)
11502 && !current_buffer
->clip_changed
11503 && !current_buffer
->prevent_redisplay_optimizations_p
11504 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11505 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11506 /* Make sure recorded data applies to current buffer, etc. */
11507 && this_line_buffer
== current_buffer
11508 && current_buffer
== XBUFFER (w
->buffer
)
11509 && NILP (w
->force_start
)
11510 && NILP (w
->optional_new_start
)
11511 /* Point must be on the line that we have info recorded about. */
11512 && PT
>= CHARPOS (tlbufpos
)
11513 && PT
<= Z
- CHARPOS (tlendpos
)
11514 /* All text outside that line, including its final newline,
11515 must be unchanged */
11516 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11517 CHARPOS (tlendpos
)))
11519 if (CHARPOS (tlbufpos
) > BEGV
11520 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11521 && (CHARPOS (tlbufpos
) == ZV
11522 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11523 /* Former continuation line has disappeared by becoming empty */
11525 else if (XFASTINT (w
->last_modified
) < MODIFF
11526 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11527 || MINI_WINDOW_P (w
))
11529 /* We have to handle the case of continuation around a
11530 wide-column character (See the comment in indent.c around
11533 For instance, in the following case:
11535 -------- Insert --------
11536 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11537 J_I_ ==> J_I_ `^^' are cursors.
11541 As we have to redraw the line above, we should goto cancel. */
11544 int line_height_before
= this_line_pixel_height
;
11546 /* Note that start_display will handle the case that the
11547 line starting at tlbufpos is a continuation lines. */
11548 start_display (&it
, w
, tlbufpos
);
11550 /* Implementation note: It this still necessary? */
11551 if (it
.current_x
!= this_line_start_x
)
11554 TRACE ((stderr
, "trying display optimization 1\n"));
11555 w
->cursor
.vpos
= -1;
11556 overlay_arrow_seen
= 0;
11557 it
.vpos
= this_line_vpos
;
11558 it
.current_y
= this_line_y
;
11559 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11560 display_line (&it
);
11562 /* If line contains point, is not continued,
11563 and ends at same distance from eob as before, we win */
11564 if (w
->cursor
.vpos
>= 0
11565 /* Line is not continued, otherwise this_line_start_pos
11566 would have been set to 0 in display_line. */
11567 && CHARPOS (this_line_start_pos
)
11568 /* Line ends as before. */
11569 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11570 /* Line has same height as before. Otherwise other lines
11571 would have to be shifted up or down. */
11572 && this_line_pixel_height
== line_height_before
)
11574 /* If this is not the window's last line, we must adjust
11575 the charstarts of the lines below. */
11576 if (it
.current_y
< it
.last_visible_y
)
11578 struct glyph_row
*row
11579 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11580 int delta
, delta_bytes
;
11582 if (Z
- CHARPOS (tlendpos
) == ZV
)
11584 /* This line ends at end of (accessible part of)
11585 buffer. There is no newline to count. */
11587 - CHARPOS (tlendpos
)
11588 - MATRIX_ROW_START_CHARPOS (row
));
11589 delta_bytes
= (Z_BYTE
11590 - BYTEPOS (tlendpos
)
11591 - MATRIX_ROW_START_BYTEPOS (row
));
11595 /* This line ends in a newline. Must take
11596 account of the newline and the rest of the
11597 text that follows. */
11599 - CHARPOS (tlendpos
)
11600 - MATRIX_ROW_START_CHARPOS (row
));
11601 delta_bytes
= (Z_BYTE
11602 - BYTEPOS (tlendpos
)
11603 - MATRIX_ROW_START_BYTEPOS (row
));
11606 increment_matrix_positions (w
->current_matrix
,
11607 this_line_vpos
+ 1,
11608 w
->current_matrix
->nrows
,
11609 delta
, delta_bytes
);
11612 /* If this row displays text now but previously didn't,
11613 or vice versa, w->window_end_vpos may have to be
11615 if ((it
.glyph_row
- 1)->displays_text_p
)
11617 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11618 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11620 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11621 && this_line_vpos
> 0)
11622 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11623 w
->window_end_valid
= Qnil
;
11625 /* Update hint: No need to try to scroll in update_window. */
11626 w
->desired_matrix
->no_scrolling_p
= 1;
11629 *w
->desired_matrix
->method
= 0;
11630 debug_method_add (w
, "optimization 1");
11632 #ifdef HAVE_WINDOW_SYSTEM
11633 update_window_fringes (w
, 0);
11640 else if (/* Cursor position hasn't changed. */
11641 PT
== XFASTINT (w
->last_point
)
11642 /* Make sure the cursor was last displayed
11643 in this window. Otherwise we have to reposition it. */
11644 && 0 <= w
->cursor
.vpos
11645 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11649 do_pending_window_change (1);
11651 /* We used to always goto end_of_redisplay here, but this
11652 isn't enough if we have a blinking cursor. */
11653 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11654 goto end_of_redisplay
;
11658 /* If highlighting the region, or if the cursor is in the echo area,
11659 then we can't just move the cursor. */
11660 else if (! (!NILP (Vtransient_mark_mode
)
11661 && !NILP (current_buffer
->mark_active
))
11662 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11663 || highlight_nonselected_windows
)
11664 && NILP (w
->region_showing
)
11665 && NILP (Vshow_trailing_whitespace
)
11666 && !cursor_in_echo_area
)
11669 struct glyph_row
*row
;
11671 /* Skip from tlbufpos to PT and see where it is. Note that
11672 PT may be in invisible text. If so, we will end at the
11673 next visible position. */
11674 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11675 NULL
, DEFAULT_FACE_ID
);
11676 it
.current_x
= this_line_start_x
;
11677 it
.current_y
= this_line_y
;
11678 it
.vpos
= this_line_vpos
;
11680 /* The call to move_it_to stops in front of PT, but
11681 moves over before-strings. */
11682 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11684 if (it
.vpos
== this_line_vpos
11685 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11688 xassert (this_line_vpos
== it
.vpos
);
11689 xassert (this_line_y
== it
.current_y
);
11690 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11692 *w
->desired_matrix
->method
= 0;
11693 debug_method_add (w
, "optimization 3");
11702 /* Text changed drastically or point moved off of line. */
11703 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11706 CHARPOS (this_line_start_pos
) = 0;
11707 consider_all_windows_p
|= buffer_shared
> 1;
11708 ++clear_face_cache_count
;
11709 #ifdef HAVE_WINDOW_SYSTEM
11710 ++clear_image_cache_count
;
11713 /* Build desired matrices, and update the display. If
11714 consider_all_windows_p is non-zero, do it for all windows on all
11715 frames. Otherwise do it for selected_window, only. */
11717 if (consider_all_windows_p
)
11719 Lisp_Object tail
, frame
;
11721 FOR_EACH_FRAME (tail
, frame
)
11722 XFRAME (frame
)->updated_p
= 0;
11724 /* Recompute # windows showing selected buffer. This will be
11725 incremented each time such a window is displayed. */
11728 FOR_EACH_FRAME (tail
, frame
)
11730 struct frame
*f
= XFRAME (frame
);
11732 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11734 if (! EQ (frame
, selected_frame
))
11735 /* Select the frame, for the sake of frame-local
11737 select_frame_for_redisplay (frame
);
11739 /* Mark all the scroll bars to be removed; we'll redeem
11740 the ones we want when we redisplay their windows. */
11741 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11742 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11744 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11745 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11747 /* Any scroll bars which redisplay_windows should have
11748 nuked should now go away. */
11749 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11750 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11752 /* If fonts changed, display again. */
11753 /* ??? rms: I suspect it is a mistake to jump all the way
11754 back to retry here. It should just retry this frame. */
11755 if (fonts_changed_p
)
11758 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11760 /* See if we have to hscroll. */
11761 if (!f
->already_hscrolled_p
)
11763 f
->already_hscrolled_p
= 1;
11764 if (hscroll_windows (f
->root_window
))
11768 /* Prevent various kinds of signals during display
11769 update. stdio is not robust about handling
11770 signals, which can cause an apparent I/O
11772 if (interrupt_input
)
11773 unrequest_sigio ();
11776 /* Update the display. */
11777 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11778 pause
|= update_frame (f
, 0, 0);
11779 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11789 if (!EQ (old_frame
, selected_frame
)
11790 && FRAME_LIVE_P (XFRAME (old_frame
)))
11791 /* We played a bit fast-and-loose above and allowed selected_frame
11792 and selected_window to be temporarily out-of-sync but let's make
11793 sure this stays contained. */
11794 select_frame_for_redisplay (old_frame
);
11795 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11799 /* Do the mark_window_display_accurate after all windows have
11800 been redisplayed because this call resets flags in buffers
11801 which are needed for proper redisplay. */
11802 FOR_EACH_FRAME (tail
, frame
)
11804 struct frame
*f
= XFRAME (frame
);
11807 mark_window_display_accurate (f
->root_window
, 1);
11808 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11809 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11814 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11816 Lisp_Object mini_window
;
11817 struct frame
*mini_frame
;
11819 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11820 /* Use list_of_error, not Qerror, so that
11821 we catch only errors and don't run the debugger. */
11822 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11824 redisplay_window_error
);
11826 /* Compare desired and current matrices, perform output. */
11829 /* If fonts changed, display again. */
11830 if (fonts_changed_p
)
11833 /* Prevent various kinds of signals during display update.
11834 stdio is not robust about handling signals,
11835 which can cause an apparent I/O error. */
11836 if (interrupt_input
)
11837 unrequest_sigio ();
11840 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11842 if (hscroll_windows (selected_window
))
11845 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11846 pause
= update_frame (sf
, 0, 0);
11849 /* We may have called echo_area_display at the top of this
11850 function. If the echo area is on another frame, that may
11851 have put text on a frame other than the selected one, so the
11852 above call to update_frame would not have caught it. Catch
11854 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11855 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11857 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11859 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11860 pause
|= update_frame (mini_frame
, 0, 0);
11861 if (!pause
&& hscroll_windows (mini_window
))
11866 /* If display was paused because of pending input, make sure we do a
11867 thorough update the next time. */
11870 /* Prevent the optimization at the beginning of
11871 redisplay_internal that tries a single-line update of the
11872 line containing the cursor in the selected window. */
11873 CHARPOS (this_line_start_pos
) = 0;
11875 /* Let the overlay arrow be updated the next time. */
11876 update_overlay_arrows (0);
11878 /* If we pause after scrolling, some rows in the current
11879 matrices of some windows are not valid. */
11880 if (!WINDOW_FULL_WIDTH_P (w
)
11881 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11882 update_mode_lines
= 1;
11886 if (!consider_all_windows_p
)
11888 /* This has already been done above if
11889 consider_all_windows_p is set. */
11890 mark_window_display_accurate_1 (w
, 1);
11892 /* Say overlay arrows are up to date. */
11893 update_overlay_arrows (1);
11895 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11896 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11899 update_mode_lines
= 0;
11900 windows_or_buffers_changed
= 0;
11901 cursor_type_changed
= 0;
11904 /* Start SIGIO interrupts coming again. Having them off during the
11905 code above makes it less likely one will discard output, but not
11906 impossible, since there might be stuff in the system buffer here.
11907 But it is much hairier to try to do anything about that. */
11908 if (interrupt_input
)
11912 /* If a frame has become visible which was not before, redisplay
11913 again, so that we display it. Expose events for such a frame
11914 (which it gets when becoming visible) don't call the parts of
11915 redisplay constructing glyphs, so simply exposing a frame won't
11916 display anything in this case. So, we have to display these
11917 frames here explicitly. */
11920 Lisp_Object tail
, frame
;
11923 FOR_EACH_FRAME (tail
, frame
)
11925 int this_is_visible
= 0;
11927 if (XFRAME (frame
)->visible
)
11928 this_is_visible
= 1;
11929 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11930 if (XFRAME (frame
)->visible
)
11931 this_is_visible
= 1;
11933 if (this_is_visible
)
11937 if (new_count
!= number_of_visible_frames
)
11938 windows_or_buffers_changed
++;
11941 /* Change frame size now if a change is pending. */
11942 do_pending_window_change (1);
11944 /* If we just did a pending size change, or have additional
11945 visible frames, redisplay again. */
11946 if (windows_or_buffers_changed
&& !pause
)
11949 /* Clear the face cache eventually. */
11950 if (consider_all_windows_p
)
11952 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11954 clear_face_cache (0);
11955 clear_face_cache_count
= 0;
11957 #ifdef HAVE_WINDOW_SYSTEM
11958 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11960 clear_image_caches (Qnil
);
11961 clear_image_cache_count
= 0;
11963 #endif /* HAVE_WINDOW_SYSTEM */
11967 unbind_to (count
, Qnil
);
11972 /* Redisplay, but leave alone any recent echo area message unless
11973 another message has been requested in its place.
11975 This is useful in situations where you need to redisplay but no
11976 user action has occurred, making it inappropriate for the message
11977 area to be cleared. See tracking_off and
11978 wait_reading_process_output for examples of these situations.
11980 FROM_WHERE is an integer saying from where this function was
11981 called. This is useful for debugging. */
11984 redisplay_preserve_echo_area (from_where
)
11987 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11989 if (!NILP (echo_area_buffer
[1]))
11991 /* We have a previously displayed message, but no current
11992 message. Redisplay the previous message. */
11993 display_last_displayed_message_p
= 1;
11994 redisplay_internal (1);
11995 display_last_displayed_message_p
= 0;
11998 redisplay_internal (1);
12000 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12001 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12002 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12006 /* Function registered with record_unwind_protect in
12007 redisplay_internal. Reset redisplaying_p to the value it had
12008 before redisplay_internal was called, and clear
12009 prevent_freeing_realized_faces_p. It also selects the previously
12010 selected frame, unless it has been deleted (by an X connection
12011 failure during redisplay, for example). */
12014 unwind_redisplay (val
)
12017 Lisp_Object old_redisplaying_p
, old_frame
;
12019 old_redisplaying_p
= XCAR (val
);
12020 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12021 old_frame
= XCDR (val
);
12022 if (! EQ (old_frame
, selected_frame
)
12023 && FRAME_LIVE_P (XFRAME (old_frame
)))
12024 select_frame_for_redisplay (old_frame
);
12029 /* Mark the display of window W as accurate or inaccurate. If
12030 ACCURATE_P is non-zero mark display of W as accurate. If
12031 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12032 redisplay_internal is called. */
12035 mark_window_display_accurate_1 (w
, accurate_p
)
12039 if (BUFFERP (w
->buffer
))
12041 struct buffer
*b
= XBUFFER (w
->buffer
);
12044 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12045 w
->last_overlay_modified
12046 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12048 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12052 b
->clip_changed
= 0;
12053 b
->prevent_redisplay_optimizations_p
= 0;
12055 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12056 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12057 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12058 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12060 w
->current_matrix
->buffer
= b
;
12061 w
->current_matrix
->begv
= BUF_BEGV (b
);
12062 w
->current_matrix
->zv
= BUF_ZV (b
);
12064 w
->last_cursor
= w
->cursor
;
12065 w
->last_cursor_off_p
= w
->cursor_off_p
;
12067 if (w
== XWINDOW (selected_window
))
12068 w
->last_point
= make_number (BUF_PT (b
));
12070 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12076 w
->window_end_valid
= w
->buffer
;
12077 #if 0 /* This is incorrect with variable-height lines. */
12078 xassert (XINT (w
->window_end_vpos
)
12079 < (WINDOW_TOTAL_LINES (w
)
12080 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
12082 w
->update_mode_line
= Qnil
;
12087 /* Mark the display of windows in the window tree rooted at WINDOW as
12088 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12089 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12090 be redisplayed the next time redisplay_internal is called. */
12093 mark_window_display_accurate (window
, accurate_p
)
12094 Lisp_Object window
;
12099 for (; !NILP (window
); window
= w
->next
)
12101 w
= XWINDOW (window
);
12102 mark_window_display_accurate_1 (w
, accurate_p
);
12104 if (!NILP (w
->vchild
))
12105 mark_window_display_accurate (w
->vchild
, accurate_p
);
12106 if (!NILP (w
->hchild
))
12107 mark_window_display_accurate (w
->hchild
, accurate_p
);
12112 update_overlay_arrows (1);
12116 /* Force a thorough redisplay the next time by setting
12117 last_arrow_position and last_arrow_string to t, which is
12118 unequal to any useful value of Voverlay_arrow_... */
12119 update_overlay_arrows (-1);
12124 /* Return value in display table DP (Lisp_Char_Table *) for character
12125 C. Since a display table doesn't have any parent, we don't have to
12126 follow parent. Do not call this function directly but use the
12127 macro DISP_CHAR_VECTOR. */
12130 disp_char_vector (dp
, c
)
12131 struct Lisp_Char_Table
*dp
;
12136 if (ASCII_CHAR_P (c
))
12139 if (SUB_CHAR_TABLE_P (val
))
12140 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12146 XSETCHAR_TABLE (table
, dp
);
12147 val
= char_table_ref (table
, c
);
12156 /***********************************************************************
12158 ***********************************************************************/
12160 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12163 redisplay_windows (window
)
12164 Lisp_Object window
;
12166 while (!NILP (window
))
12168 struct window
*w
= XWINDOW (window
);
12170 if (!NILP (w
->hchild
))
12171 redisplay_windows (w
->hchild
);
12172 else if (!NILP (w
->vchild
))
12173 redisplay_windows (w
->vchild
);
12176 displayed_buffer
= XBUFFER (w
->buffer
);
12177 /* Use list_of_error, not Qerror, so that
12178 we catch only errors and don't run the debugger. */
12179 internal_condition_case_1 (redisplay_window_0
, window
,
12181 redisplay_window_error
);
12189 redisplay_window_error ()
12191 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12196 redisplay_window_0 (window
)
12197 Lisp_Object window
;
12199 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12200 redisplay_window (window
, 0);
12205 redisplay_window_1 (window
)
12206 Lisp_Object window
;
12208 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12209 redisplay_window (window
, 1);
12214 /* Increment GLYPH until it reaches END or CONDITION fails while
12215 adding (GLYPH)->pixel_width to X. */
12217 #define SKIP_GLYPHS(glyph, end, x, condition) \
12220 (x) += (glyph)->pixel_width; \
12223 while ((glyph) < (end) && (condition))
12226 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12227 DELTA is the number of bytes by which positions recorded in ROW
12228 differ from current buffer positions.
12230 Return 0 if cursor is not on this row. 1 otherwise. */
12233 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12235 struct glyph_row
*row
;
12236 struct glyph_matrix
*matrix
;
12237 int delta
, delta_bytes
, dy
, dvpos
;
12239 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12240 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12241 struct glyph
*cursor
= NULL
;
12242 /* The first glyph that starts a sequence of glyphs from string. */
12243 struct glyph
*string_start
;
12244 /* The X coordinate of string_start. */
12245 int string_start_x
;
12246 /* The last known character position. */
12247 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12248 /* The last known character position before string_start. */
12249 int string_before_pos
;
12252 int cursor_from_overlay_pos
= 0;
12253 int pt_old
= PT
- delta
;
12255 /* Skip over glyphs not having an object at the start of the row.
12256 These are special glyphs like truncation marks on terminal
12258 if (row
->displays_text_p
)
12260 && INTEGERP (glyph
->object
)
12261 && glyph
->charpos
< 0)
12263 x
+= glyph
->pixel_width
;
12267 string_start
= NULL
;
12269 && !INTEGERP (glyph
->object
)
12270 && (!BUFFERP (glyph
->object
)
12271 || (last_pos
= glyph
->charpos
) < pt_old
12272 || glyph
->avoid_cursor_p
))
12274 if (! STRINGP (glyph
->object
))
12276 string_start
= NULL
;
12277 x
+= glyph
->pixel_width
;
12279 if (cursor_from_overlay_pos
12280 && last_pos
>= cursor_from_overlay_pos
)
12282 cursor_from_overlay_pos
= 0;
12288 if (string_start
== NULL
)
12290 string_before_pos
= last_pos
;
12291 string_start
= glyph
;
12292 string_start_x
= x
;
12294 /* Skip all glyphs from string. */
12299 if ((cursor
== NULL
|| glyph
> cursor
)
12300 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12301 Qcursor
, (glyph
)->object
),
12303 && (pos
= string_buffer_position (w
, glyph
->object
,
12304 string_before_pos
),
12305 (pos
== 0 /* From overlay */
12306 || pos
== pt_old
)))
12308 /* Estimate overlay buffer position from the buffer
12309 positions of the glyphs before and after the overlay.
12310 Add 1 to last_pos so that if point corresponds to the
12311 glyph right after the overlay, we still use a 'cursor'
12312 property found in that overlay. */
12313 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12314 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12318 x
+= glyph
->pixel_width
;
12321 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12325 if (cursor
!= NULL
)
12330 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12332 /* Scan back over the ellipsis glyphs, decrementing positions. */
12333 while (glyph
> row
->glyphs
[TEXT_AREA
]
12334 && (glyph
- 1)->charpos
== last_pos
)
12335 glyph
--, x
-= glyph
->pixel_width
;
12336 /* That loop always goes one position too far,
12337 including the glyph before the ellipsis.
12338 So scan forward over that one. */
12339 x
+= glyph
->pixel_width
;
12342 else if (string_start
12343 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12345 /* We may have skipped over point because the previous glyphs
12346 are from string. As there's no easy way to know the
12347 character position of the current glyph, find the correct
12348 glyph on point by scanning from string_start again. */
12350 Lisp_Object string
;
12351 struct glyph
*stop
= glyph
;
12354 limit
= make_number (pt_old
+ 1);
12355 glyph
= string_start
;
12356 x
= string_start_x
;
12357 string
= glyph
->object
;
12358 pos
= string_buffer_position (w
, string
, string_before_pos
);
12359 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12360 because we always put cursor after overlay strings. */
12361 while (pos
== 0 && glyph
< stop
)
12363 string
= glyph
->object
;
12364 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12366 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12369 while (glyph
< stop
)
12371 pos
= XINT (Fnext_single_char_property_change
12372 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12375 /* Skip glyphs from the same string. */
12376 string
= glyph
->object
;
12377 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12378 /* Skip glyphs from an overlay. */
12379 while (glyph
< stop
12380 && ! string_buffer_position (w
, glyph
->object
, pos
))
12382 string
= glyph
->object
;
12383 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12387 /* If we reached the end of the line, and end was from a string,
12388 cursor is not on this line. */
12389 if (glyph
== end
&& row
->continued_p
)
12393 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12395 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12396 w
->cursor
.y
= row
->y
+ dy
;
12398 if (w
== XWINDOW (selected_window
))
12400 if (!row
->continued_p
12401 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12404 this_line_buffer
= XBUFFER (w
->buffer
);
12406 CHARPOS (this_line_start_pos
)
12407 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12408 BYTEPOS (this_line_start_pos
)
12409 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12411 CHARPOS (this_line_end_pos
)
12412 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12413 BYTEPOS (this_line_end_pos
)
12414 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12416 this_line_y
= w
->cursor
.y
;
12417 this_line_pixel_height
= row
->height
;
12418 this_line_vpos
= w
->cursor
.vpos
;
12419 this_line_start_x
= row
->x
;
12422 CHARPOS (this_line_start_pos
) = 0;
12429 /* Run window scroll functions, if any, for WINDOW with new window
12430 start STARTP. Sets the window start of WINDOW to that position.
12432 We assume that the window's buffer is really current. */
12434 static INLINE
struct text_pos
12435 run_window_scroll_functions (window
, startp
)
12436 Lisp_Object window
;
12437 struct text_pos startp
;
12439 struct window
*w
= XWINDOW (window
);
12440 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12442 if (current_buffer
!= XBUFFER (w
->buffer
))
12445 if (!NILP (Vwindow_scroll_functions
))
12447 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12448 make_number (CHARPOS (startp
)));
12449 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12450 /* In case the hook functions switch buffers. */
12451 if (current_buffer
!= XBUFFER (w
->buffer
))
12452 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12459 /* Make sure the line containing the cursor is fully visible.
12460 A value of 1 means there is nothing to be done.
12461 (Either the line is fully visible, or it cannot be made so,
12462 or we cannot tell.)
12464 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12465 is higher than window.
12467 A value of 0 means the caller should do scrolling
12468 as if point had gone off the screen. */
12471 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12474 int current_matrix_p
;
12476 struct glyph_matrix
*matrix
;
12477 struct glyph_row
*row
;
12480 if (!make_cursor_line_fully_visible_p
)
12483 /* It's not always possible to find the cursor, e.g, when a window
12484 is full of overlay strings. Don't do anything in that case. */
12485 if (w
->cursor
.vpos
< 0)
12488 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12489 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12491 /* If the cursor row is not partially visible, there's nothing to do. */
12492 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12495 /* If the row the cursor is in is taller than the window's height,
12496 it's not clear what to do, so do nothing. */
12497 window_height
= window_box_height (w
);
12498 if (row
->height
>= window_height
)
12500 if (!force_p
|| MINI_WINDOW_P (w
)
12501 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12507 /* This code used to try to scroll the window just enough to make
12508 the line visible. It returned 0 to say that the caller should
12509 allocate larger glyph matrices. */
12511 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12513 int dy
= row
->height
- row
->visible_height
;
12516 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12518 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12520 int dy
= - (row
->height
- row
->visible_height
);
12523 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12526 /* When we change the cursor y-position of the selected window,
12527 change this_line_y as well so that the display optimization for
12528 the cursor line of the selected window in redisplay_internal uses
12529 the correct y-position. */
12530 if (w
== XWINDOW (selected_window
))
12531 this_line_y
= w
->cursor
.y
;
12533 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12534 redisplay with larger matrices. */
12535 if (matrix
->nrows
< required_matrix_height (w
))
12537 fonts_changed_p
= 1;
12546 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12547 non-zero means only WINDOW is redisplayed in redisplay_internal.
12548 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12549 in redisplay_window to bring a partially visible line into view in
12550 the case that only the cursor has moved.
12552 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12553 last screen line's vertical height extends past the end of the screen.
12557 1 if scrolling succeeded
12559 0 if scrolling didn't find point.
12561 -1 if new fonts have been loaded so that we must interrupt
12562 redisplay, adjust glyph matrices, and try again. */
12568 SCROLLING_NEED_LARGER_MATRICES
12572 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12573 scroll_step
, temp_scroll_step
, last_line_misfit
)
12574 Lisp_Object window
;
12575 int just_this_one_p
;
12576 EMACS_INT scroll_conservatively
, scroll_step
;
12577 int temp_scroll_step
;
12578 int last_line_misfit
;
12580 struct window
*w
= XWINDOW (window
);
12581 struct frame
*f
= XFRAME (w
->frame
);
12582 struct text_pos scroll_margin_pos
;
12583 struct text_pos pos
;
12584 struct text_pos startp
;
12586 Lisp_Object window_end
;
12587 int this_scroll_margin
;
12591 int amount_to_scroll
= 0;
12592 Lisp_Object aggressive
;
12594 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12597 debug_method_add (w
, "try_scrolling");
12600 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12602 /* Compute scroll margin height in pixels. We scroll when point is
12603 within this distance from the top or bottom of the window. */
12604 if (scroll_margin
> 0)
12606 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12607 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12610 this_scroll_margin
= 0;
12612 /* Force scroll_conservatively to have a reasonable value so it doesn't
12613 cause an overflow while computing how much to scroll. */
12614 if (scroll_conservatively
)
12615 scroll_conservatively
= min (scroll_conservatively
,
12616 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12618 /* Compute how much we should try to scroll maximally to bring point
12620 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12621 scroll_max
= max (scroll_step
,
12622 max (scroll_conservatively
, temp_scroll_step
));
12623 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12624 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12625 /* We're trying to scroll because of aggressive scrolling
12626 but no scroll_step is set. Choose an arbitrary one. Maybe
12627 there should be a variable for this. */
12631 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12633 /* Decide whether we have to scroll down. Start at the window end
12634 and move this_scroll_margin up to find the position of the scroll
12636 window_end
= Fwindow_end (window
, Qt
);
12640 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12641 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12643 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12645 start_display (&it
, w
, scroll_margin_pos
);
12646 if (this_scroll_margin
)
12647 move_it_vertically_backward (&it
, this_scroll_margin
);
12648 if (extra_scroll_margin_lines
)
12649 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12650 scroll_margin_pos
= it
.current
.pos
;
12653 if (PT
>= CHARPOS (scroll_margin_pos
))
12657 /* Point is in the scroll margin at the bottom of the window, or
12658 below. Compute a new window start that makes point visible. */
12660 /* Compute the distance from the scroll margin to PT.
12661 Give up if the distance is greater than scroll_max. */
12662 start_display (&it
, w
, scroll_margin_pos
);
12664 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12665 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12667 /* To make point visible, we have to move the window start
12668 down so that the line the cursor is in is visible, which
12669 means we have to add in the height of the cursor line. */
12670 dy
= line_bottom_y (&it
) - y0
;
12672 if (dy
> scroll_max
)
12673 return SCROLLING_FAILED
;
12675 /* Move the window start down. If scrolling conservatively,
12676 move it just enough down to make point visible. If
12677 scroll_step is set, move it down by scroll_step. */
12678 start_display (&it
, w
, startp
);
12680 if (scroll_conservatively
)
12681 /* Set AMOUNT_TO_SCROLL to at least one line,
12682 and at most scroll_conservatively lines. */
12684 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12685 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12686 else if (scroll_step
|| temp_scroll_step
)
12687 amount_to_scroll
= scroll_max
;
12690 aggressive
= current_buffer
->scroll_up_aggressively
;
12691 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12692 if (NUMBERP (aggressive
))
12694 double float_amount
= XFLOATINT (aggressive
) * height
;
12695 amount_to_scroll
= float_amount
;
12696 if (amount_to_scroll
== 0 && float_amount
> 0)
12697 amount_to_scroll
= 1;
12701 if (amount_to_scroll
<= 0)
12702 return SCROLLING_FAILED
;
12704 /* If moving by amount_to_scroll leaves STARTP unchanged,
12705 move it down one screen line. */
12707 move_it_vertically (&it
, amount_to_scroll
);
12708 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12709 move_it_by_lines (&it
, 1, 1);
12710 startp
= it
.current
.pos
;
12714 /* See if point is inside the scroll margin at the top of the
12716 scroll_margin_pos
= startp
;
12717 if (this_scroll_margin
)
12719 start_display (&it
, w
, startp
);
12720 move_it_vertically (&it
, this_scroll_margin
);
12721 scroll_margin_pos
= it
.current
.pos
;
12724 if (PT
< CHARPOS (scroll_margin_pos
))
12726 /* Point is in the scroll margin at the top of the window or
12727 above what is displayed in the window. */
12730 /* Compute the vertical distance from PT to the scroll
12731 margin position. Give up if distance is greater than
12733 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12734 start_display (&it
, w
, pos
);
12736 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12737 it
.last_visible_y
, -1,
12738 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12739 dy
= it
.current_y
- y0
;
12740 if (dy
> scroll_max
)
12741 return SCROLLING_FAILED
;
12743 /* Compute new window start. */
12744 start_display (&it
, w
, startp
);
12746 if (scroll_conservatively
)
12748 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12749 else if (scroll_step
|| temp_scroll_step
)
12750 amount_to_scroll
= scroll_max
;
12753 aggressive
= current_buffer
->scroll_down_aggressively
;
12754 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12755 if (NUMBERP (aggressive
))
12757 double float_amount
= XFLOATINT (aggressive
) * height
;
12758 amount_to_scroll
= float_amount
;
12759 if (amount_to_scroll
== 0 && float_amount
> 0)
12760 amount_to_scroll
= 1;
12764 if (amount_to_scroll
<= 0)
12765 return SCROLLING_FAILED
;
12767 move_it_vertically_backward (&it
, amount_to_scroll
);
12768 startp
= it
.current
.pos
;
12772 /* Run window scroll functions. */
12773 startp
= run_window_scroll_functions (window
, startp
);
12775 /* Display the window. Give up if new fonts are loaded, or if point
12777 if (!try_window (window
, startp
, 0))
12778 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12779 else if (w
->cursor
.vpos
< 0)
12781 clear_glyph_matrix (w
->desired_matrix
);
12782 rc
= SCROLLING_FAILED
;
12786 /* Maybe forget recorded base line for line number display. */
12787 if (!just_this_one_p
12788 || current_buffer
->clip_changed
12789 || BEG_UNCHANGED
< CHARPOS (startp
))
12790 w
->base_line_number
= Qnil
;
12792 /* If cursor ends up on a partially visible line,
12793 treat that as being off the bottom of the screen. */
12794 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12796 clear_glyph_matrix (w
->desired_matrix
);
12797 ++extra_scroll_margin_lines
;
12800 rc
= SCROLLING_SUCCESS
;
12807 /* Compute a suitable window start for window W if display of W starts
12808 on a continuation line. Value is non-zero if a new window start
12811 The new window start will be computed, based on W's width, starting
12812 from the start of the continued line. It is the start of the
12813 screen line with the minimum distance from the old start W->start. */
12816 compute_window_start_on_continuation_line (w
)
12819 struct text_pos pos
, start_pos
;
12820 int window_start_changed_p
= 0;
12822 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12824 /* If window start is on a continuation line... Window start may be
12825 < BEGV in case there's invisible text at the start of the
12826 buffer (M-x rmail, for example). */
12827 if (CHARPOS (start_pos
) > BEGV
12828 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12831 struct glyph_row
*row
;
12833 /* Handle the case that the window start is out of range. */
12834 if (CHARPOS (start_pos
) < BEGV
)
12835 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12836 else if (CHARPOS (start_pos
) > ZV
)
12837 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12839 /* Find the start of the continued line. This should be fast
12840 because scan_buffer is fast (newline cache). */
12841 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12842 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12843 row
, DEFAULT_FACE_ID
);
12844 reseat_at_previous_visible_line_start (&it
);
12846 /* If the line start is "too far" away from the window start,
12847 say it takes too much time to compute a new window start. */
12848 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12849 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12851 int min_distance
, distance
;
12853 /* Move forward by display lines to find the new window
12854 start. If window width was enlarged, the new start can
12855 be expected to be > the old start. If window width was
12856 decreased, the new window start will be < the old start.
12857 So, we're looking for the display line start with the
12858 minimum distance from the old window start. */
12859 pos
= it
.current
.pos
;
12860 min_distance
= INFINITY
;
12861 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12862 distance
< min_distance
)
12864 min_distance
= distance
;
12865 pos
= it
.current
.pos
;
12866 move_it_by_lines (&it
, 1, 0);
12869 /* Set the window start there. */
12870 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12871 window_start_changed_p
= 1;
12875 return window_start_changed_p
;
12879 /* Try cursor movement in case text has not changed in window WINDOW,
12880 with window start STARTP. Value is
12882 CURSOR_MOVEMENT_SUCCESS if successful
12884 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12886 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12887 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12888 we want to scroll as if scroll-step were set to 1. See the code.
12890 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12891 which case we have to abort this redisplay, and adjust matrices
12896 CURSOR_MOVEMENT_SUCCESS
,
12897 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12898 CURSOR_MOVEMENT_MUST_SCROLL
,
12899 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12903 try_cursor_movement (window
, startp
, scroll_step
)
12904 Lisp_Object window
;
12905 struct text_pos startp
;
12908 struct window
*w
= XWINDOW (window
);
12909 struct frame
*f
= XFRAME (w
->frame
);
12910 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12913 if (inhibit_try_cursor_movement
)
12917 /* Handle case where text has not changed, only point, and it has
12918 not moved off the frame. */
12919 if (/* Point may be in this window. */
12920 PT
>= CHARPOS (startp
)
12921 /* Selective display hasn't changed. */
12922 && !current_buffer
->clip_changed
12923 /* Function force-mode-line-update is used to force a thorough
12924 redisplay. It sets either windows_or_buffers_changed or
12925 update_mode_lines. So don't take a shortcut here for these
12927 && !update_mode_lines
12928 && !windows_or_buffers_changed
12929 && !cursor_type_changed
12930 /* Can't use this case if highlighting a region. When a
12931 region exists, cursor movement has to do more than just
12933 && !(!NILP (Vtransient_mark_mode
)
12934 && !NILP (current_buffer
->mark_active
))
12935 && NILP (w
->region_showing
)
12936 && NILP (Vshow_trailing_whitespace
)
12937 /* Right after splitting windows, last_point may be nil. */
12938 && INTEGERP (w
->last_point
)
12939 /* This code is not used for mini-buffer for the sake of the case
12940 of redisplaying to replace an echo area message; since in
12941 that case the mini-buffer contents per se are usually
12942 unchanged. This code is of no real use in the mini-buffer
12943 since the handling of this_line_start_pos, etc., in redisplay
12944 handles the same cases. */
12945 && !EQ (window
, minibuf_window
)
12946 /* When splitting windows or for new windows, it happens that
12947 redisplay is called with a nil window_end_vpos or one being
12948 larger than the window. This should really be fixed in
12949 window.c. I don't have this on my list, now, so we do
12950 approximately the same as the old redisplay code. --gerd. */
12951 && INTEGERP (w
->window_end_vpos
)
12952 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12953 && (FRAME_WINDOW_P (f
)
12954 || !overlay_arrow_in_current_buffer_p ()))
12956 int this_scroll_margin
, top_scroll_margin
;
12957 struct glyph_row
*row
= NULL
;
12960 debug_method_add (w
, "cursor movement");
12963 /* Scroll if point within this distance from the top or bottom
12964 of the window. This is a pixel value. */
12965 this_scroll_margin
= max (0, scroll_margin
);
12966 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12967 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12969 top_scroll_margin
= this_scroll_margin
;
12970 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12971 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12973 /* Start with the row the cursor was displayed during the last
12974 not paused redisplay. Give up if that row is not valid. */
12975 if (w
->last_cursor
.vpos
< 0
12976 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12977 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12980 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12981 if (row
->mode_line_p
)
12983 if (!row
->enabled_p
)
12984 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12987 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12990 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12992 if (PT
> XFASTINT (w
->last_point
))
12994 /* Point has moved forward. */
12995 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12996 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12998 xassert (row
->enabled_p
);
13002 /* The end position of a row equals the start position
13003 of the next row. If PT is there, we would rather
13004 display it in the next line. */
13005 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13006 && MATRIX_ROW_END_CHARPOS (row
) == PT
13007 && !cursor_row_p (w
, row
))
13010 /* If within the scroll margin, scroll. Note that
13011 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13012 the next line would be drawn, and that
13013 this_scroll_margin can be zero. */
13014 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13015 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13016 /* Line is completely visible last line in window
13017 and PT is to be set in the next line. */
13018 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13019 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13020 && !row
->ends_at_zv_p
13021 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13024 else if (PT
< XFASTINT (w
->last_point
))
13026 /* Cursor has to be moved backward. Note that PT >=
13027 CHARPOS (startp) because of the outer if-statement. */
13028 while (!row
->mode_line_p
13029 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13030 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13031 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13032 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13033 row
> w
->current_matrix
->rows
13034 && (row
-1)->ends_in_newline_from_string_p
))))
13035 && (row
->y
> top_scroll_margin
13036 || CHARPOS (startp
) == BEGV
))
13038 xassert (row
->enabled_p
);
13042 /* Consider the following case: Window starts at BEGV,
13043 there is invisible, intangible text at BEGV, so that
13044 display starts at some point START > BEGV. It can
13045 happen that we are called with PT somewhere between
13046 BEGV and START. Try to handle that case. */
13047 if (row
< w
->current_matrix
->rows
13048 || row
->mode_line_p
)
13050 row
= w
->current_matrix
->rows
;
13051 if (row
->mode_line_p
)
13055 /* Due to newlines in overlay strings, we may have to
13056 skip forward over overlay strings. */
13057 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13058 && MATRIX_ROW_END_CHARPOS (row
) == PT
13059 && !cursor_row_p (w
, row
))
13062 /* If within the scroll margin, scroll. */
13063 if (row
->y
< top_scroll_margin
13064 && CHARPOS (startp
) != BEGV
)
13069 /* Cursor did not move. So don't scroll even if cursor line
13070 is partially visible, as it was so before. */
13071 rc
= CURSOR_MOVEMENT_SUCCESS
;
13074 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13075 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13077 /* if PT is not in the glyph row, give up. */
13078 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13080 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13081 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13082 && make_cursor_line_fully_visible_p
)
13084 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13085 && !row
->ends_at_zv_p
13086 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13087 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13088 else if (row
->height
> window_box_height (w
))
13090 /* If we end up in a partially visible line, let's
13091 make it fully visible, except when it's taller
13092 than the window, in which case we can't do much
13095 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13099 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13100 if (!cursor_row_fully_visible_p (w
, 0, 1))
13101 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13103 rc
= CURSOR_MOVEMENT_SUCCESS
;
13107 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13112 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13114 rc
= CURSOR_MOVEMENT_SUCCESS
;
13119 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13120 && MATRIX_ROW_START_CHARPOS (row
) == PT
13121 && cursor_row_p (w
, row
));
13130 set_vertical_scroll_bar (w
)
13133 int start
, end
, whole
;
13135 /* Calculate the start and end positions for the current window.
13136 At some point, it would be nice to choose between scrollbars
13137 which reflect the whole buffer size, with special markers
13138 indicating narrowing, and scrollbars which reflect only the
13141 Note that mini-buffers sometimes aren't displaying any text. */
13142 if (!MINI_WINDOW_P (w
)
13143 || (w
== XWINDOW (minibuf_window
)
13144 && NILP (echo_area_buffer
[0])))
13146 struct buffer
*buf
= XBUFFER (w
->buffer
);
13147 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13148 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13149 /* I don't think this is guaranteed to be right. For the
13150 moment, we'll pretend it is. */
13151 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13155 if (whole
< (end
- start
))
13156 whole
= end
- start
;
13159 start
= end
= whole
= 0;
13161 /* Indicate what this scroll bar ought to be displaying now. */
13162 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13163 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13164 (w
, end
- start
, whole
, start
);
13168 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13169 selected_window is redisplayed.
13171 We can return without actually redisplaying the window if
13172 fonts_changed_p is nonzero. In that case, redisplay_internal will
13176 redisplay_window (window
, just_this_one_p
)
13177 Lisp_Object window
;
13178 int just_this_one_p
;
13180 struct window
*w
= XWINDOW (window
);
13181 struct frame
*f
= XFRAME (w
->frame
);
13182 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13183 struct buffer
*old
= current_buffer
;
13184 struct text_pos lpoint
, opoint
, startp
;
13185 int update_mode_line
;
13188 /* Record it now because it's overwritten. */
13189 int current_matrix_up_to_date_p
= 0;
13190 int used_current_matrix_p
= 0;
13191 /* This is less strict than current_matrix_up_to_date_p.
13192 It indictes that the buffer contents and narrowing are unchanged. */
13193 int buffer_unchanged_p
= 0;
13194 int temp_scroll_step
= 0;
13195 int count
= SPECPDL_INDEX ();
13197 int centering_position
= -1;
13198 int last_line_misfit
= 0;
13199 int beg_unchanged
, end_unchanged
;
13201 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13204 /* W must be a leaf window here. */
13205 xassert (!NILP (w
->buffer
));
13207 *w
->desired_matrix
->method
= 0;
13211 reconsider_clip_changes (w
, buffer
);
13213 /* Has the mode line to be updated? */
13214 update_mode_line
= (!NILP (w
->update_mode_line
)
13215 || update_mode_lines
13216 || buffer
->clip_changed
13217 || buffer
->prevent_redisplay_optimizations_p
);
13219 if (MINI_WINDOW_P (w
))
13221 if (w
== XWINDOW (echo_area_window
)
13222 && !NILP (echo_area_buffer
[0]))
13224 if (update_mode_line
)
13225 /* We may have to update a tty frame's menu bar or a
13226 tool-bar. Example `M-x C-h C-h C-g'. */
13227 goto finish_menu_bars
;
13229 /* We've already displayed the echo area glyphs in this window. */
13230 goto finish_scroll_bars
;
13232 else if ((w
!= XWINDOW (minibuf_window
)
13233 || minibuf_level
== 0)
13234 /* When buffer is nonempty, redisplay window normally. */
13235 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13236 /* Quail displays non-mini buffers in minibuffer window.
13237 In that case, redisplay the window normally. */
13238 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13240 /* W is a mini-buffer window, but it's not active, so clear
13242 int yb
= window_text_bottom_y (w
);
13243 struct glyph_row
*row
;
13246 for (y
= 0, row
= w
->desired_matrix
->rows
;
13248 y
+= row
->height
, ++row
)
13249 blank_row (w
, row
, y
);
13250 goto finish_scroll_bars
;
13253 clear_glyph_matrix (w
->desired_matrix
);
13256 /* Otherwise set up data on this window; select its buffer and point
13258 /* Really select the buffer, for the sake of buffer-local
13260 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13262 current_matrix_up_to_date_p
13263 = (!NILP (w
->window_end_valid
)
13264 && !current_buffer
->clip_changed
13265 && !current_buffer
->prevent_redisplay_optimizations_p
13266 && XFASTINT (w
->last_modified
) >= MODIFF
13267 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13269 /* Run the window-bottom-change-functions
13270 if it is possible that the text on the screen has changed
13271 (either due to modification of the text, or any other reason). */
13272 if (!current_matrix_up_to_date_p
13273 && !NILP (Vwindow_text_change_functions
))
13275 safe_run_hooks (Qwindow_text_change_functions
);
13279 beg_unchanged
= BEG_UNCHANGED
;
13280 end_unchanged
= END_UNCHANGED
;
13282 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13284 specbind (Qinhibit_point_motion_hooks
, Qt
);
13287 = (!NILP (w
->window_end_valid
)
13288 && !current_buffer
->clip_changed
13289 && XFASTINT (w
->last_modified
) >= MODIFF
13290 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13292 /* When windows_or_buffers_changed is non-zero, we can't rely on
13293 the window end being valid, so set it to nil there. */
13294 if (windows_or_buffers_changed
)
13296 /* If window starts on a continuation line, maybe adjust the
13297 window start in case the window's width changed. */
13298 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13299 compute_window_start_on_continuation_line (w
);
13301 w
->window_end_valid
= Qnil
;
13304 /* Some sanity checks. */
13305 CHECK_WINDOW_END (w
);
13306 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13308 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13311 /* If %c is in mode line, update it if needed. */
13312 if (!NILP (w
->column_number_displayed
)
13313 /* This alternative quickly identifies a common case
13314 where no change is needed. */
13315 && !(PT
== XFASTINT (w
->last_point
)
13316 && XFASTINT (w
->last_modified
) >= MODIFF
13317 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13318 && (XFASTINT (w
->column_number_displayed
)
13319 != (int) current_column ())) /* iftc */
13320 update_mode_line
= 1;
13322 /* Count number of windows showing the selected buffer. An indirect
13323 buffer counts as its base buffer. */
13324 if (!just_this_one_p
)
13326 struct buffer
*current_base
, *window_base
;
13327 current_base
= current_buffer
;
13328 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13329 if (current_base
->base_buffer
)
13330 current_base
= current_base
->base_buffer
;
13331 if (window_base
->base_buffer
)
13332 window_base
= window_base
->base_buffer
;
13333 if (current_base
== window_base
)
13337 /* Point refers normally to the selected window. For any other
13338 window, set up appropriate value. */
13339 if (!EQ (window
, selected_window
))
13341 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13342 int new_pt_byte
= marker_byte_position (w
->pointm
);
13346 new_pt_byte
= BEGV_BYTE
;
13347 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13349 else if (new_pt
> (ZV
- 1))
13352 new_pt_byte
= ZV_BYTE
;
13353 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13356 /* We don't use SET_PT so that the point-motion hooks don't run. */
13357 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13360 /* If any of the character widths specified in the display table
13361 have changed, invalidate the width run cache. It's true that
13362 this may be a bit late to catch such changes, but the rest of
13363 redisplay goes (non-fatally) haywire when the display table is
13364 changed, so why should we worry about doing any better? */
13365 if (current_buffer
->width_run_cache
)
13367 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13369 if (! disptab_matches_widthtab (disptab
,
13370 XVECTOR (current_buffer
->width_table
)))
13372 invalidate_region_cache (current_buffer
,
13373 current_buffer
->width_run_cache
,
13375 recompute_width_table (current_buffer
, disptab
);
13379 /* If window-start is screwed up, choose a new one. */
13380 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13383 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13385 /* If someone specified a new starting point but did not insist,
13386 check whether it can be used. */
13387 if (!NILP (w
->optional_new_start
)
13388 && CHARPOS (startp
) >= BEGV
13389 && CHARPOS (startp
) <= ZV
)
13391 w
->optional_new_start
= Qnil
;
13392 start_display (&it
, w
, startp
);
13393 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13394 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13395 if (IT_CHARPOS (it
) == PT
)
13396 w
->force_start
= Qt
;
13397 /* IT may overshoot PT if text at PT is invisible. */
13398 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13399 w
->force_start
= Qt
;
13404 /* Handle case where place to start displaying has been specified,
13405 unless the specified location is outside the accessible range. */
13406 if (!NILP (w
->force_start
)
13407 || w
->frozen_window_start_p
)
13409 /* We set this later on if we have to adjust point. */
13413 w
->force_start
= Qnil
;
13415 w
->window_end_valid
= Qnil
;
13417 /* Forget any recorded base line for line number display. */
13418 if (!buffer_unchanged_p
)
13419 w
->base_line_number
= Qnil
;
13421 /* Redisplay the mode line. Select the buffer properly for that.
13422 Also, run the hook window-scroll-functions
13423 because we have scrolled. */
13424 /* Note, we do this after clearing force_start because
13425 if there's an error, it is better to forget about force_start
13426 than to get into an infinite loop calling the hook functions
13427 and having them get more errors. */
13428 if (!update_mode_line
13429 || ! NILP (Vwindow_scroll_functions
))
13431 update_mode_line
= 1;
13432 w
->update_mode_line
= Qt
;
13433 startp
= run_window_scroll_functions (window
, startp
);
13436 w
->last_modified
= make_number (0);
13437 w
->last_overlay_modified
= make_number (0);
13438 if (CHARPOS (startp
) < BEGV
)
13439 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13440 else if (CHARPOS (startp
) > ZV
)
13441 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13443 /* Redisplay, then check if cursor has been set during the
13444 redisplay. Give up if new fonts were loaded. */
13445 val
= try_window (window
, startp
, 1);
13448 w
->force_start
= Qt
;
13449 clear_glyph_matrix (w
->desired_matrix
);
13450 goto need_larger_matrices
;
13452 /* Point was outside the scroll margins. */
13454 new_vpos
= window_box_height (w
) / 2;
13456 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13458 /* If point does not appear, try to move point so it does
13459 appear. The desired matrix has been built above, so we
13460 can use it here. */
13461 new_vpos
= window_box_height (w
) / 2;
13464 if (!cursor_row_fully_visible_p (w
, 0, 0))
13466 /* Point does appear, but on a line partly visible at end of window.
13467 Move it back to a fully-visible line. */
13468 new_vpos
= window_box_height (w
);
13471 /* If we need to move point for either of the above reasons,
13472 now actually do it. */
13475 struct glyph_row
*row
;
13477 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13478 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13481 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13482 MATRIX_ROW_START_BYTEPOS (row
));
13484 if (w
!= XWINDOW (selected_window
))
13485 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13486 else if (current_buffer
== old
)
13487 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13489 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13491 /* If we are highlighting the region, then we just changed
13492 the region, so redisplay to show it. */
13493 if (!NILP (Vtransient_mark_mode
)
13494 && !NILP (current_buffer
->mark_active
))
13496 clear_glyph_matrix (w
->desired_matrix
);
13497 if (!try_window (window
, startp
, 0))
13498 goto need_larger_matrices
;
13503 debug_method_add (w
, "forced window start");
13508 /* Handle case where text has not changed, only point, and it has
13509 not moved off the frame, and we are not retrying after hscroll.
13510 (current_matrix_up_to_date_p is nonzero when retrying.) */
13511 if (current_matrix_up_to_date_p
13512 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13513 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13517 case CURSOR_MOVEMENT_SUCCESS
:
13518 used_current_matrix_p
= 1;
13521 #if 0 /* try_cursor_movement never returns this value. */
13522 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13523 goto need_larger_matrices
;
13526 case CURSOR_MOVEMENT_MUST_SCROLL
:
13527 goto try_to_scroll
;
13533 /* If current starting point was originally the beginning of a line
13534 but no longer is, find a new starting point. */
13535 else if (!NILP (w
->start_at_line_beg
)
13536 && !(CHARPOS (startp
) <= BEGV
13537 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13540 debug_method_add (w
, "recenter 1");
13545 /* Try scrolling with try_window_id. Value is > 0 if update has
13546 been done, it is -1 if we know that the same window start will
13547 not work. It is 0 if unsuccessful for some other reason. */
13548 else if ((tem
= try_window_id (w
)) != 0)
13551 debug_method_add (w
, "try_window_id %d", tem
);
13554 if (fonts_changed_p
)
13555 goto need_larger_matrices
;
13559 /* Otherwise try_window_id has returned -1 which means that we
13560 don't want the alternative below this comment to execute. */
13562 else if (CHARPOS (startp
) >= BEGV
13563 && CHARPOS (startp
) <= ZV
13564 && PT
>= CHARPOS (startp
)
13565 && (CHARPOS (startp
) < ZV
13566 /* Avoid starting at end of buffer. */
13567 || CHARPOS (startp
) == BEGV
13568 || (XFASTINT (w
->last_modified
) >= MODIFF
13569 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13572 /* If first window line is a continuation line, and window start
13573 is inside the modified region, but the first change is before
13574 current window start, we must select a new window start.
13576 However, if this is the result of a down-mouse event (e.g. by
13577 extending the mouse-drag-overlay), we don't want to select a
13578 new window start, since that would change the position under
13579 the mouse, resulting in an unwanted mouse-movement rather
13580 than a simple mouse-click. */
13581 if (NILP (w
->start_at_line_beg
)
13582 && NILP (do_mouse_tracking
)
13583 && CHARPOS (startp
) > BEGV
13584 && CHARPOS (startp
) > BEG
+ beg_unchanged
13585 && CHARPOS (startp
) <= Z
- end_unchanged
)
13587 w
->force_start
= Qt
;
13588 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13589 compute_window_start_on_continuation_line (w
);
13590 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13595 debug_method_add (w
, "same window start");
13598 /* Try to redisplay starting at same place as before.
13599 If point has not moved off frame, accept the results. */
13600 if (!current_matrix_up_to_date_p
13601 /* Don't use try_window_reusing_current_matrix in this case
13602 because a window scroll function can have changed the
13604 || !NILP (Vwindow_scroll_functions
)
13605 || MINI_WINDOW_P (w
)
13606 || !(used_current_matrix_p
13607 = try_window_reusing_current_matrix (w
)))
13609 IF_DEBUG (debug_method_add (w
, "1"));
13610 if (try_window (window
, startp
, 1) < 0)
13611 /* -1 means we need to scroll.
13612 0 means we need new matrices, but fonts_changed_p
13613 is set in that case, so we will detect it below. */
13614 goto try_to_scroll
;
13617 if (fonts_changed_p
)
13618 goto need_larger_matrices
;
13620 if (w
->cursor
.vpos
>= 0)
13622 if (!just_this_one_p
13623 || current_buffer
->clip_changed
13624 || BEG_UNCHANGED
< CHARPOS (startp
))
13625 /* Forget any recorded base line for line number display. */
13626 w
->base_line_number
= Qnil
;
13628 if (!cursor_row_fully_visible_p (w
, 1, 0))
13630 clear_glyph_matrix (w
->desired_matrix
);
13631 last_line_misfit
= 1;
13633 /* Drop through and scroll. */
13638 clear_glyph_matrix (w
->desired_matrix
);
13643 w
->last_modified
= make_number (0);
13644 w
->last_overlay_modified
= make_number (0);
13646 /* Redisplay the mode line. Select the buffer properly for that. */
13647 if (!update_mode_line
)
13649 update_mode_line
= 1;
13650 w
->update_mode_line
= Qt
;
13653 /* Try to scroll by specified few lines. */
13654 if ((scroll_conservatively
13656 || temp_scroll_step
13657 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13658 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13659 && !current_buffer
->clip_changed
13660 && CHARPOS (startp
) >= BEGV
13661 && CHARPOS (startp
) <= ZV
)
13663 /* The function returns -1 if new fonts were loaded, 1 if
13664 successful, 0 if not successful. */
13665 int rc
= try_scrolling (window
, just_this_one_p
,
13666 scroll_conservatively
,
13668 temp_scroll_step
, last_line_misfit
);
13671 case SCROLLING_SUCCESS
:
13674 case SCROLLING_NEED_LARGER_MATRICES
:
13675 goto need_larger_matrices
;
13677 case SCROLLING_FAILED
:
13685 /* Finally, just choose place to start which centers point */
13688 if (centering_position
< 0)
13689 centering_position
= window_box_height (w
) / 2;
13692 debug_method_add (w
, "recenter");
13695 /* w->vscroll = 0; */
13697 /* Forget any previously recorded base line for line number display. */
13698 if (!buffer_unchanged_p
)
13699 w
->base_line_number
= Qnil
;
13701 /* Move backward half the height of the window. */
13702 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13703 it
.current_y
= it
.last_visible_y
;
13704 move_it_vertically_backward (&it
, centering_position
);
13705 xassert (IT_CHARPOS (it
) >= BEGV
);
13707 /* The function move_it_vertically_backward may move over more
13708 than the specified y-distance. If it->w is small, e.g. a
13709 mini-buffer window, we may end up in front of the window's
13710 display area. Start displaying at the start of the line
13711 containing PT in this case. */
13712 if (it
.current_y
<= 0)
13714 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13715 move_it_vertically_backward (&it
, 0);
13717 /* I think this assert is bogus if buffer contains
13718 invisible text or images. KFS. */
13719 xassert (IT_CHARPOS (it
) <= PT
);
13724 it
.current_x
= it
.hpos
= 0;
13726 /* Set startp here explicitly in case that helps avoid an infinite loop
13727 in case the window-scroll-functions functions get errors. */
13728 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13730 /* Run scroll hooks. */
13731 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13733 /* Redisplay the window. */
13734 if (!current_matrix_up_to_date_p
13735 || windows_or_buffers_changed
13736 || cursor_type_changed
13737 /* Don't use try_window_reusing_current_matrix in this case
13738 because it can have changed the buffer. */
13739 || !NILP (Vwindow_scroll_functions
)
13740 || !just_this_one_p
13741 || MINI_WINDOW_P (w
)
13742 || !(used_current_matrix_p
13743 = try_window_reusing_current_matrix (w
)))
13744 try_window (window
, startp
, 0);
13746 /* If new fonts have been loaded (due to fontsets), give up. We
13747 have to start a new redisplay since we need to re-adjust glyph
13749 if (fonts_changed_p
)
13750 goto need_larger_matrices
;
13752 /* If cursor did not appear assume that the middle of the window is
13753 in the first line of the window. Do it again with the next line.
13754 (Imagine a window of height 100, displaying two lines of height
13755 60. Moving back 50 from it->last_visible_y will end in the first
13757 if (w
->cursor
.vpos
< 0)
13759 if (!NILP (w
->window_end_valid
)
13760 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13762 clear_glyph_matrix (w
->desired_matrix
);
13763 move_it_by_lines (&it
, 1, 0);
13764 try_window (window
, it
.current
.pos
, 0);
13766 else if (PT
< IT_CHARPOS (it
))
13768 clear_glyph_matrix (w
->desired_matrix
);
13769 move_it_by_lines (&it
, -1, 0);
13770 try_window (window
, it
.current
.pos
, 0);
13774 /* Not much we can do about it. */
13778 /* Consider the following case: Window starts at BEGV, there is
13779 invisible, intangible text at BEGV, so that display starts at
13780 some point START > BEGV. It can happen that we are called with
13781 PT somewhere between BEGV and START. Try to handle that case. */
13782 if (w
->cursor
.vpos
< 0)
13784 struct glyph_row
*row
= w
->current_matrix
->rows
;
13785 if (row
->mode_line_p
)
13787 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13790 if (!cursor_row_fully_visible_p (w
, 0, 0))
13792 /* If vscroll is enabled, disable it and try again. */
13796 clear_glyph_matrix (w
->desired_matrix
);
13800 /* If centering point failed to make the whole line visible,
13801 put point at the top instead. That has to make the whole line
13802 visible, if it can be done. */
13803 if (centering_position
== 0)
13806 clear_glyph_matrix (w
->desired_matrix
);
13807 centering_position
= 0;
13813 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13814 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13815 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13818 /* Display the mode line, if we must. */
13819 if ((update_mode_line
13820 /* If window not full width, must redo its mode line
13821 if (a) the window to its side is being redone and
13822 (b) we do a frame-based redisplay. This is a consequence
13823 of how inverted lines are drawn in frame-based redisplay. */
13824 || (!just_this_one_p
13825 && !FRAME_WINDOW_P (f
)
13826 && !WINDOW_FULL_WIDTH_P (w
))
13827 /* Line number to display. */
13828 || INTEGERP (w
->base_line_pos
)
13829 /* Column number is displayed and different from the one displayed. */
13830 || (!NILP (w
->column_number_displayed
)
13831 && (XFASTINT (w
->column_number_displayed
)
13832 != (int) current_column ()))) /* iftc */
13833 /* This means that the window has a mode line. */
13834 && (WINDOW_WANTS_MODELINE_P (w
)
13835 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13837 display_mode_lines (w
);
13839 /* If mode line height has changed, arrange for a thorough
13840 immediate redisplay using the correct mode line height. */
13841 if (WINDOW_WANTS_MODELINE_P (w
)
13842 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13844 fonts_changed_p
= 1;
13845 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13846 = DESIRED_MODE_LINE_HEIGHT (w
);
13849 /* If top line height has changed, arrange for a thorough
13850 immediate redisplay using the correct mode line height. */
13851 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13852 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13854 fonts_changed_p
= 1;
13855 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13856 = DESIRED_HEADER_LINE_HEIGHT (w
);
13859 if (fonts_changed_p
)
13860 goto need_larger_matrices
;
13863 if (!line_number_displayed
13864 && !BUFFERP (w
->base_line_pos
))
13866 w
->base_line_pos
= Qnil
;
13867 w
->base_line_number
= Qnil
;
13872 /* When we reach a frame's selected window, redo the frame's menu bar. */
13873 if (update_mode_line
13874 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13876 int redisplay_menu_p
= 0;
13877 int redisplay_tool_bar_p
= 0;
13879 if (FRAME_WINDOW_P (f
))
13881 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13882 || defined (USE_GTK)
13883 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13885 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13889 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13891 if (redisplay_menu_p
)
13892 display_menu_bar (w
);
13894 #ifdef HAVE_WINDOW_SYSTEM
13895 if (FRAME_WINDOW_P (f
))
13897 #if defined (USE_GTK) || USE_MAC_TOOLBAR
13898 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13900 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13901 && (FRAME_TOOL_BAR_LINES (f
) > 0
13902 || !NILP (Vauto_resize_tool_bars
));
13905 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13907 extern int ignore_mouse_drag_p
;
13908 ignore_mouse_drag_p
= 1;
13914 #ifdef HAVE_WINDOW_SYSTEM
13915 if (FRAME_WINDOW_P (f
)
13916 && update_window_fringes (w
, (just_this_one_p
13917 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13918 || w
->pseudo_window_p
)))
13922 if (draw_window_fringes (w
, 1))
13923 x_draw_vertical_border (w
);
13927 #endif /* HAVE_WINDOW_SYSTEM */
13929 /* We go to this label, with fonts_changed_p nonzero,
13930 if it is necessary to try again using larger glyph matrices.
13931 We have to redeem the scroll bar even in this case,
13932 because the loop in redisplay_internal expects that. */
13933 need_larger_matrices
:
13935 finish_scroll_bars
:
13937 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13939 /* Set the thumb's position and size. */
13940 set_vertical_scroll_bar (w
);
13942 /* Note that we actually used the scroll bar attached to this
13943 window, so it shouldn't be deleted at the end of redisplay. */
13944 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13945 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13948 /* Restore current_buffer and value of point in it. */
13949 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13950 set_buffer_internal_1 (old
);
13951 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13952 shorter. This can be caused by log truncation in *Messages*. */
13953 if (CHARPOS (lpoint
) <= ZV
)
13954 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13956 unbind_to (count
, Qnil
);
13960 /* Build the complete desired matrix of WINDOW with a window start
13961 buffer position POS.
13963 Value is 1 if successful. It is zero if fonts were loaded during
13964 redisplay which makes re-adjusting glyph matrices necessary, and -1
13965 if point would appear in the scroll margins.
13966 (We check that only if CHECK_MARGINS is nonzero. */
13969 try_window (window
, pos
, check_margins
)
13970 Lisp_Object window
;
13971 struct text_pos pos
;
13974 struct window
*w
= XWINDOW (window
);
13976 struct glyph_row
*last_text_row
= NULL
;
13977 struct frame
*f
= XFRAME (w
->frame
);
13979 /* Make POS the new window start. */
13980 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13982 /* Mark cursor position as unknown. No overlay arrow seen. */
13983 w
->cursor
.vpos
= -1;
13984 overlay_arrow_seen
= 0;
13986 /* Initialize iterator and info to start at POS. */
13987 start_display (&it
, w
, pos
);
13989 /* Display all lines of W. */
13990 while (it
.current_y
< it
.last_visible_y
)
13992 if (display_line (&it
))
13993 last_text_row
= it
.glyph_row
- 1;
13994 if (fonts_changed_p
)
13998 /* Don't let the cursor end in the scroll margins. */
14000 && !MINI_WINDOW_P (w
))
14002 int this_scroll_margin
;
14004 this_scroll_margin
= max (0, scroll_margin
);
14005 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14006 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14008 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14009 && w
->cursor
.y
< this_scroll_margin
14010 && CHARPOS (pos
) > BEGV
14011 && IT_CHARPOS (it
) < ZV
)
14012 /* rms: considering make_cursor_line_fully_visible_p here
14013 seems to give wrong results. We don't want to recenter
14014 when the last line is partly visible, we want to allow
14015 that case to be handled in the usual way. */
14016 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
14018 w
->cursor
.vpos
= -1;
14019 clear_glyph_matrix (w
->desired_matrix
);
14024 /* If bottom moved off end of frame, change mode line percentage. */
14025 if (XFASTINT (w
->window_end_pos
) <= 0
14026 && Z
!= IT_CHARPOS (it
))
14027 w
->update_mode_line
= Qt
;
14029 /* Set window_end_pos to the offset of the last character displayed
14030 on the window from the end of current_buffer. Set
14031 window_end_vpos to its row number. */
14034 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14035 w
->window_end_bytepos
14036 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14038 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14040 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14041 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14042 ->displays_text_p
);
14046 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14047 w
->window_end_pos
= make_number (Z
- ZV
);
14048 w
->window_end_vpos
= make_number (0);
14051 /* But that is not valid info until redisplay finishes. */
14052 w
->window_end_valid
= Qnil
;
14058 /************************************************************************
14059 Window redisplay reusing current matrix when buffer has not changed
14060 ************************************************************************/
14062 /* Try redisplay of window W showing an unchanged buffer with a
14063 different window start than the last time it was displayed by
14064 reusing its current matrix. Value is non-zero if successful.
14065 W->start is the new window start. */
14068 try_window_reusing_current_matrix (w
)
14071 struct frame
*f
= XFRAME (w
->frame
);
14072 struct glyph_row
*row
, *bottom_row
;
14075 struct text_pos start
, new_start
;
14076 int nrows_scrolled
, i
;
14077 struct glyph_row
*last_text_row
;
14078 struct glyph_row
*last_reused_text_row
;
14079 struct glyph_row
*start_row
;
14080 int start_vpos
, min_y
, max_y
;
14083 if (inhibit_try_window_reusing
)
14087 if (/* This function doesn't handle terminal frames. */
14088 !FRAME_WINDOW_P (f
)
14089 /* Don't try to reuse the display if windows have been split
14091 || windows_or_buffers_changed
14092 || cursor_type_changed
)
14095 /* Can't do this if region may have changed. */
14096 if ((!NILP (Vtransient_mark_mode
)
14097 && !NILP (current_buffer
->mark_active
))
14098 || !NILP (w
->region_showing
)
14099 || !NILP (Vshow_trailing_whitespace
))
14102 /* If top-line visibility has changed, give up. */
14103 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14104 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14107 /* Give up if old or new display is scrolled vertically. We could
14108 make this function handle this, but right now it doesn't. */
14109 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14110 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14113 /* The variable new_start now holds the new window start. The old
14114 start `start' can be determined from the current matrix. */
14115 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14116 start
= start_row
->start
.pos
;
14117 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14119 /* Clear the desired matrix for the display below. */
14120 clear_glyph_matrix (w
->desired_matrix
);
14122 if (CHARPOS (new_start
) <= CHARPOS (start
))
14126 /* Don't use this method if the display starts with an ellipsis
14127 displayed for invisible text. It's not easy to handle that case
14128 below, and it's certainly not worth the effort since this is
14129 not a frequent case. */
14130 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14133 IF_DEBUG (debug_method_add (w
, "twu1"));
14135 /* Display up to a row that can be reused. The variable
14136 last_text_row is set to the last row displayed that displays
14137 text. Note that it.vpos == 0 if or if not there is a
14138 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14139 start_display (&it
, w
, new_start
);
14140 first_row_y
= it
.current_y
;
14141 w
->cursor
.vpos
= -1;
14142 last_text_row
= last_reused_text_row
= NULL
;
14144 while (it
.current_y
< it
.last_visible_y
14145 && !fonts_changed_p
)
14147 /* If we have reached into the characters in the START row,
14148 that means the line boundaries have changed. So we
14149 can't start copying with the row START. Maybe it will
14150 work to start copying with the following row. */
14151 while (IT_CHARPOS (it
) > CHARPOS (start
))
14153 /* Advance to the next row as the "start". */
14155 start
= start_row
->start
.pos
;
14156 /* If there are no more rows to try, or just one, give up. */
14157 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14158 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14159 || CHARPOS (start
) == ZV
)
14161 clear_glyph_matrix (w
->desired_matrix
);
14165 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14167 /* If we have reached alignment,
14168 we can copy the rest of the rows. */
14169 if (IT_CHARPOS (it
) == CHARPOS (start
))
14172 if (display_line (&it
))
14173 last_text_row
= it
.glyph_row
- 1;
14176 /* A value of current_y < last_visible_y means that we stopped
14177 at the previous window start, which in turn means that we
14178 have at least one reusable row. */
14179 if (it
.current_y
< it
.last_visible_y
)
14181 /* IT.vpos always starts from 0; it counts text lines. */
14182 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14184 /* Find PT if not already found in the lines displayed. */
14185 if (w
->cursor
.vpos
< 0)
14187 int dy
= it
.current_y
- start_row
->y
;
14189 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14190 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14192 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14193 dy
, nrows_scrolled
);
14196 clear_glyph_matrix (w
->desired_matrix
);
14201 /* Scroll the display. Do it before the current matrix is
14202 changed. The problem here is that update has not yet
14203 run, i.e. part of the current matrix is not up to date.
14204 scroll_run_hook will clear the cursor, and use the
14205 current matrix to get the height of the row the cursor is
14207 run
.current_y
= start_row
->y
;
14208 run
.desired_y
= it
.current_y
;
14209 run
.height
= it
.last_visible_y
- it
.current_y
;
14211 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14214 FRAME_RIF (f
)->update_window_begin_hook (w
);
14215 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14216 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14217 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14221 /* Shift current matrix down by nrows_scrolled lines. */
14222 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14223 rotate_matrix (w
->current_matrix
,
14225 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14228 /* Disable lines that must be updated. */
14229 for (i
= 0; i
< nrows_scrolled
; ++i
)
14230 (start_row
+ i
)->enabled_p
= 0;
14232 /* Re-compute Y positions. */
14233 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14234 max_y
= it
.last_visible_y
;
14235 for (row
= start_row
+ nrows_scrolled
;
14239 row
->y
= it
.current_y
;
14240 row
->visible_height
= row
->height
;
14242 if (row
->y
< min_y
)
14243 row
->visible_height
-= min_y
- row
->y
;
14244 if (row
->y
+ row
->height
> max_y
)
14245 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14246 row
->redraw_fringe_bitmaps_p
= 1;
14248 it
.current_y
+= row
->height
;
14250 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14251 last_reused_text_row
= row
;
14252 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14256 /* Disable lines in the current matrix which are now
14257 below the window. */
14258 for (++row
; row
< bottom_row
; ++row
)
14259 row
->enabled_p
= row
->mode_line_p
= 0;
14262 /* Update window_end_pos etc.; last_reused_text_row is the last
14263 reused row from the current matrix containing text, if any.
14264 The value of last_text_row is the last displayed line
14265 containing text. */
14266 if (last_reused_text_row
)
14268 w
->window_end_bytepos
14269 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14271 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14273 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14274 w
->current_matrix
));
14276 else if (last_text_row
)
14278 w
->window_end_bytepos
14279 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14281 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14283 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14287 /* This window must be completely empty. */
14288 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14289 w
->window_end_pos
= make_number (Z
- ZV
);
14290 w
->window_end_vpos
= make_number (0);
14292 w
->window_end_valid
= Qnil
;
14294 /* Update hint: don't try scrolling again in update_window. */
14295 w
->desired_matrix
->no_scrolling_p
= 1;
14298 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14302 else if (CHARPOS (new_start
) > CHARPOS (start
))
14304 struct glyph_row
*pt_row
, *row
;
14305 struct glyph_row
*first_reusable_row
;
14306 struct glyph_row
*first_row_to_display
;
14308 int yb
= window_text_bottom_y (w
);
14310 /* Find the row starting at new_start, if there is one. Don't
14311 reuse a partially visible line at the end. */
14312 first_reusable_row
= start_row
;
14313 while (first_reusable_row
->enabled_p
14314 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14315 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14316 < CHARPOS (new_start
)))
14317 ++first_reusable_row
;
14319 /* Give up if there is no row to reuse. */
14320 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14321 || !first_reusable_row
->enabled_p
14322 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14323 != CHARPOS (new_start
)))
14326 /* We can reuse fully visible rows beginning with
14327 first_reusable_row to the end of the window. Set
14328 first_row_to_display to the first row that cannot be reused.
14329 Set pt_row to the row containing point, if there is any. */
14331 for (first_row_to_display
= first_reusable_row
;
14332 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14333 ++first_row_to_display
)
14335 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14336 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14337 pt_row
= first_row_to_display
;
14340 /* Start displaying at the start of first_row_to_display. */
14341 xassert (first_row_to_display
->y
< yb
);
14342 init_to_row_start (&it
, w
, first_row_to_display
);
14344 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14346 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14348 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14349 + WINDOW_HEADER_LINE_HEIGHT (w
));
14351 /* Display lines beginning with first_row_to_display in the
14352 desired matrix. Set last_text_row to the last row displayed
14353 that displays text. */
14354 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14355 if (pt_row
== NULL
)
14356 w
->cursor
.vpos
= -1;
14357 last_text_row
= NULL
;
14358 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14359 if (display_line (&it
))
14360 last_text_row
= it
.glyph_row
- 1;
14362 /* Give up If point isn't in a row displayed or reused. */
14363 if (w
->cursor
.vpos
< 0)
14365 clear_glyph_matrix (w
->desired_matrix
);
14369 /* If point is in a reused row, adjust y and vpos of the cursor
14373 w
->cursor
.vpos
-= nrows_scrolled
;
14374 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14377 /* Scroll the display. */
14378 run
.current_y
= first_reusable_row
->y
;
14379 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14380 run
.height
= it
.last_visible_y
- run
.current_y
;
14381 dy
= run
.current_y
- run
.desired_y
;
14386 FRAME_RIF (f
)->update_window_begin_hook (w
);
14387 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14388 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14389 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14393 /* Adjust Y positions of reused rows. */
14394 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14395 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14396 max_y
= it
.last_visible_y
;
14397 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14400 row
->visible_height
= row
->height
;
14401 if (row
->y
< min_y
)
14402 row
->visible_height
-= min_y
- row
->y
;
14403 if (row
->y
+ row
->height
> max_y
)
14404 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14405 row
->redraw_fringe_bitmaps_p
= 1;
14408 /* Scroll the current matrix. */
14409 xassert (nrows_scrolled
> 0);
14410 rotate_matrix (w
->current_matrix
,
14412 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14415 /* Disable rows not reused. */
14416 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14417 row
->enabled_p
= 0;
14419 /* Point may have moved to a different line, so we cannot assume that
14420 the previous cursor position is valid; locate the correct row. */
14423 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14424 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14428 w
->cursor
.y
= row
->y
;
14430 if (row
< bottom_row
)
14432 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14433 while (glyph
->charpos
< PT
)
14436 w
->cursor
.x
+= glyph
->pixel_width
;
14442 /* Adjust window end. A null value of last_text_row means that
14443 the window end is in reused rows which in turn means that
14444 only its vpos can have changed. */
14447 w
->window_end_bytepos
14448 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14450 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14452 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14457 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14460 w
->window_end_valid
= Qnil
;
14461 w
->desired_matrix
->no_scrolling_p
= 1;
14464 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14474 /************************************************************************
14475 Window redisplay reusing current matrix when buffer has changed
14476 ************************************************************************/
14478 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14479 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14481 static struct glyph_row
*
14482 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14483 struct glyph_row
*));
14486 /* Return the last row in MATRIX displaying text. If row START is
14487 non-null, start searching with that row. IT gives the dimensions
14488 of the display. Value is null if matrix is empty; otherwise it is
14489 a pointer to the row found. */
14491 static struct glyph_row
*
14492 find_last_row_displaying_text (matrix
, it
, start
)
14493 struct glyph_matrix
*matrix
;
14495 struct glyph_row
*start
;
14497 struct glyph_row
*row
, *row_found
;
14499 /* Set row_found to the last row in IT->w's current matrix
14500 displaying text. The loop looks funny but think of partially
14503 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14504 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14506 xassert (row
->enabled_p
);
14508 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14517 /* Return the last row in the current matrix of W that is not affected
14518 by changes at the start of current_buffer that occurred since W's
14519 current matrix was built. Value is null if no such row exists.
14521 BEG_UNCHANGED us the number of characters unchanged at the start of
14522 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14523 first changed character in current_buffer. Characters at positions <
14524 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14525 when the current matrix was built. */
14527 static struct glyph_row
*
14528 find_last_unchanged_at_beg_row (w
)
14531 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14532 struct glyph_row
*row
;
14533 struct glyph_row
*row_found
= NULL
;
14534 int yb
= window_text_bottom_y (w
);
14536 /* Find the last row displaying unchanged text. */
14537 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14538 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14539 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14542 if (/* If row ends before first_changed_pos, it is unchanged,
14543 except in some case. */
14544 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14545 /* When row ends in ZV and we write at ZV it is not
14547 && !row
->ends_at_zv_p
14548 /* When first_changed_pos is the end of a continued line,
14549 row is not unchanged because it may be no longer
14551 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14552 && (row
->continued_p
14553 || row
->exact_window_width_line_p
)))
14556 /* Stop if last visible row. */
14557 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14565 /* Find the first glyph row in the current matrix of W that is not
14566 affected by changes at the end of current_buffer since the
14567 time W's current matrix was built.
14569 Return in *DELTA the number of chars by which buffer positions in
14570 unchanged text at the end of current_buffer must be adjusted.
14572 Return in *DELTA_BYTES the corresponding number of bytes.
14574 Value is null if no such row exists, i.e. all rows are affected by
14577 static struct glyph_row
*
14578 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14580 int *delta
, *delta_bytes
;
14582 struct glyph_row
*row
;
14583 struct glyph_row
*row_found
= NULL
;
14585 *delta
= *delta_bytes
= 0;
14587 /* Display must not have been paused, otherwise the current matrix
14588 is not up to date. */
14589 eassert (!NILP (w
->window_end_valid
));
14591 /* A value of window_end_pos >= END_UNCHANGED means that the window
14592 end is in the range of changed text. If so, there is no
14593 unchanged row at the end of W's current matrix. */
14594 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14597 /* Set row to the last row in W's current matrix displaying text. */
14598 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14600 /* If matrix is entirely empty, no unchanged row exists. */
14601 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14603 /* The value of row is the last glyph row in the matrix having a
14604 meaningful buffer position in it. The end position of row
14605 corresponds to window_end_pos. This allows us to translate
14606 buffer positions in the current matrix to current buffer
14607 positions for characters not in changed text. */
14608 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14609 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14610 int last_unchanged_pos
, last_unchanged_pos_old
;
14611 struct glyph_row
*first_text_row
14612 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14614 *delta
= Z
- Z_old
;
14615 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14617 /* Set last_unchanged_pos to the buffer position of the last
14618 character in the buffer that has not been changed. Z is the
14619 index + 1 of the last character in current_buffer, i.e. by
14620 subtracting END_UNCHANGED we get the index of the last
14621 unchanged character, and we have to add BEG to get its buffer
14623 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14624 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14626 /* Search backward from ROW for a row displaying a line that
14627 starts at a minimum position >= last_unchanged_pos_old. */
14628 for (; row
> first_text_row
; --row
)
14630 /* This used to abort, but it can happen.
14631 It is ok to just stop the search instead here. KFS. */
14632 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14635 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14640 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14646 /* Make sure that glyph rows in the current matrix of window W
14647 reference the same glyph memory as corresponding rows in the
14648 frame's frame matrix. This function is called after scrolling W's
14649 current matrix on a terminal frame in try_window_id and
14650 try_window_reusing_current_matrix. */
14653 sync_frame_with_window_matrix_rows (w
)
14656 struct frame
*f
= XFRAME (w
->frame
);
14657 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14659 /* Preconditions: W must be a leaf window and full-width. Its frame
14660 must have a frame matrix. */
14661 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14662 xassert (WINDOW_FULL_WIDTH_P (w
));
14663 xassert (!FRAME_WINDOW_P (f
));
14665 /* If W is a full-width window, glyph pointers in W's current matrix
14666 have, by definition, to be the same as glyph pointers in the
14667 corresponding frame matrix. Note that frame matrices have no
14668 marginal areas (see build_frame_matrix). */
14669 window_row
= w
->current_matrix
->rows
;
14670 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14671 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14672 while (window_row
< window_row_end
)
14674 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14675 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14677 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14678 frame_row
->glyphs
[TEXT_AREA
] = start
;
14679 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14680 frame_row
->glyphs
[LAST_AREA
] = end
;
14682 /* Disable frame rows whose corresponding window rows have
14683 been disabled in try_window_id. */
14684 if (!window_row
->enabled_p
)
14685 frame_row
->enabled_p
= 0;
14687 ++window_row
, ++frame_row
;
14692 /* Find the glyph row in window W containing CHARPOS. Consider all
14693 rows between START and END (not inclusive). END null means search
14694 all rows to the end of the display area of W. Value is the row
14695 containing CHARPOS or null. */
14698 row_containing_pos (w
, charpos
, start
, end
, dy
)
14701 struct glyph_row
*start
, *end
;
14704 struct glyph_row
*row
= start
;
14707 /* If we happen to start on a header-line, skip that. */
14708 if (row
->mode_line_p
)
14711 if ((end
&& row
>= end
) || !row
->enabled_p
)
14714 last_y
= window_text_bottom_y (w
) - dy
;
14718 /* Give up if we have gone too far. */
14719 if (end
&& row
>= end
)
14721 /* This formerly returned if they were equal.
14722 I think that both quantities are of a "last plus one" type;
14723 if so, when they are equal, the row is within the screen. -- rms. */
14724 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14727 /* If it is in this row, return this row. */
14728 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14729 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14730 /* The end position of a row equals the start
14731 position of the next row. If CHARPOS is there, we
14732 would rather display it in the next line, except
14733 when this line ends in ZV. */
14734 && !row
->ends_at_zv_p
14735 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14736 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14743 /* Try to redisplay window W by reusing its existing display. W's
14744 current matrix must be up to date when this function is called,
14745 i.e. window_end_valid must not be nil.
14749 1 if display has been updated
14750 0 if otherwise unsuccessful
14751 -1 if redisplay with same window start is known not to succeed
14753 The following steps are performed:
14755 1. Find the last row in the current matrix of W that is not
14756 affected by changes at the start of current_buffer. If no such row
14759 2. Find the first row in W's current matrix that is not affected by
14760 changes at the end of current_buffer. Maybe there is no such row.
14762 3. Display lines beginning with the row + 1 found in step 1 to the
14763 row found in step 2 or, if step 2 didn't find a row, to the end of
14766 4. If cursor is not known to appear on the window, give up.
14768 5. If display stopped at the row found in step 2, scroll the
14769 display and current matrix as needed.
14771 6. Maybe display some lines at the end of W, if we must. This can
14772 happen under various circumstances, like a partially visible line
14773 becoming fully visible, or because newly displayed lines are displayed
14774 in smaller font sizes.
14776 7. Update W's window end information. */
14782 struct frame
*f
= XFRAME (w
->frame
);
14783 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14784 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14785 struct glyph_row
*last_unchanged_at_beg_row
;
14786 struct glyph_row
*first_unchanged_at_end_row
;
14787 struct glyph_row
*row
;
14788 struct glyph_row
*bottom_row
;
14791 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14792 struct text_pos start_pos
;
14794 int first_unchanged_at_end_vpos
= 0;
14795 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14796 struct text_pos start
;
14797 int first_changed_charpos
, last_changed_charpos
;
14800 if (inhibit_try_window_id
)
14804 /* This is handy for debugging. */
14806 #define GIVE_UP(X) \
14808 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14812 #define GIVE_UP(X) return 0
14815 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14817 /* Don't use this for mini-windows because these can show
14818 messages and mini-buffers, and we don't handle that here. */
14819 if (MINI_WINDOW_P (w
))
14822 /* This flag is used to prevent redisplay optimizations. */
14823 if (windows_or_buffers_changed
|| cursor_type_changed
)
14826 /* Verify that narrowing has not changed.
14827 Also verify that we were not told to prevent redisplay optimizations.
14828 It would be nice to further
14829 reduce the number of cases where this prevents try_window_id. */
14830 if (current_buffer
->clip_changed
14831 || current_buffer
->prevent_redisplay_optimizations_p
)
14834 /* Window must either use window-based redisplay or be full width. */
14835 if (!FRAME_WINDOW_P (f
)
14836 && (!FRAME_LINE_INS_DEL_OK (f
)
14837 || !WINDOW_FULL_WIDTH_P (w
)))
14840 /* Give up if point is not known NOT to appear in W. */
14841 if (PT
< CHARPOS (start
))
14844 /* Another way to prevent redisplay optimizations. */
14845 if (XFASTINT (w
->last_modified
) == 0)
14848 /* Verify that window is not hscrolled. */
14849 if (XFASTINT (w
->hscroll
) != 0)
14852 /* Verify that display wasn't paused. */
14853 if (NILP (w
->window_end_valid
))
14856 /* Can't use this if highlighting a region because a cursor movement
14857 will do more than just set the cursor. */
14858 if (!NILP (Vtransient_mark_mode
)
14859 && !NILP (current_buffer
->mark_active
))
14862 /* Likewise if highlighting trailing whitespace. */
14863 if (!NILP (Vshow_trailing_whitespace
))
14866 /* Likewise if showing a region. */
14867 if (!NILP (w
->region_showing
))
14870 /* Can use this if overlay arrow position and or string have changed. */
14871 if (overlay_arrows_changed_p ())
14874 /* When word-wrap is on, adding a space to the first word of a
14875 wrapped line can change the wrap position, altering the line
14876 above it. It might be worthwhile to handle this more
14877 intelligently, but for now just redisplay from scratch. */
14878 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14881 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14882 only if buffer has really changed. The reason is that the gap is
14883 initially at Z for freshly visited files. The code below would
14884 set end_unchanged to 0 in that case. */
14885 if (MODIFF
> SAVE_MODIFF
14886 /* This seems to happen sometimes after saving a buffer. */
14887 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14889 if (GPT
- BEG
< BEG_UNCHANGED
)
14890 BEG_UNCHANGED
= GPT
- BEG
;
14891 if (Z
- GPT
< END_UNCHANGED
)
14892 END_UNCHANGED
= Z
- GPT
;
14895 /* The position of the first and last character that has been changed. */
14896 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14897 last_changed_charpos
= Z
- END_UNCHANGED
;
14899 /* If window starts after a line end, and the last change is in
14900 front of that newline, then changes don't affect the display.
14901 This case happens with stealth-fontification. Note that although
14902 the display is unchanged, glyph positions in the matrix have to
14903 be adjusted, of course. */
14904 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14905 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14906 && ((last_changed_charpos
< CHARPOS (start
)
14907 && CHARPOS (start
) == BEGV
)
14908 || (last_changed_charpos
< CHARPOS (start
) - 1
14909 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14911 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14912 struct glyph_row
*r0
;
14914 /* Compute how many chars/bytes have been added to or removed
14915 from the buffer. */
14916 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14917 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14919 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14921 /* Give up if PT is not in the window. Note that it already has
14922 been checked at the start of try_window_id that PT is not in
14923 front of the window start. */
14924 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14927 /* If window start is unchanged, we can reuse the whole matrix
14928 as is, after adjusting glyph positions. No need to compute
14929 the window end again, since its offset from Z hasn't changed. */
14930 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14931 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14932 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14933 /* PT must not be in a partially visible line. */
14934 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14935 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14937 /* Adjust positions in the glyph matrix. */
14938 if (delta
|| delta_bytes
)
14940 struct glyph_row
*r1
14941 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14942 increment_matrix_positions (w
->current_matrix
,
14943 MATRIX_ROW_VPOS (r0
, current_matrix
),
14944 MATRIX_ROW_VPOS (r1
, current_matrix
),
14945 delta
, delta_bytes
);
14948 /* Set the cursor. */
14949 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14951 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14958 /* Handle the case that changes are all below what is displayed in
14959 the window, and that PT is in the window. This shortcut cannot
14960 be taken if ZV is visible in the window, and text has been added
14961 there that is visible in the window. */
14962 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14963 /* ZV is not visible in the window, or there are no
14964 changes at ZV, actually. */
14965 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14966 || first_changed_charpos
== last_changed_charpos
))
14968 struct glyph_row
*r0
;
14970 /* Give up if PT is not in the window. Note that it already has
14971 been checked at the start of try_window_id that PT is not in
14972 front of the window start. */
14973 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14976 /* If window start is unchanged, we can reuse the whole matrix
14977 as is, without changing glyph positions since no text has
14978 been added/removed in front of the window end. */
14979 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14980 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14981 /* PT must not be in a partially visible line. */
14982 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14983 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14985 /* We have to compute the window end anew since text
14986 can have been added/removed after it. */
14988 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14989 w
->window_end_bytepos
14990 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14992 /* Set the cursor. */
14993 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14995 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15002 /* Give up if window start is in the changed area.
15004 The condition used to read
15006 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15008 but why that was tested escapes me at the moment. */
15009 if (CHARPOS (start
) >= first_changed_charpos
15010 && CHARPOS (start
) <= last_changed_charpos
)
15013 /* Check that window start agrees with the start of the first glyph
15014 row in its current matrix. Check this after we know the window
15015 start is not in changed text, otherwise positions would not be
15017 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15018 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15021 /* Give up if the window ends in strings. Overlay strings
15022 at the end are difficult to handle, so don't try. */
15023 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15024 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15027 /* Compute the position at which we have to start displaying new
15028 lines. Some of the lines at the top of the window might be
15029 reusable because they are not displaying changed text. Find the
15030 last row in W's current matrix not affected by changes at the
15031 start of current_buffer. Value is null if changes start in the
15032 first line of window. */
15033 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15034 if (last_unchanged_at_beg_row
)
15036 /* Avoid starting to display in the moddle of a character, a TAB
15037 for instance. This is easier than to set up the iterator
15038 exactly, and it's not a frequent case, so the additional
15039 effort wouldn't really pay off. */
15040 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15041 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15042 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15043 --last_unchanged_at_beg_row
;
15045 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15048 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15050 start_pos
= it
.current
.pos
;
15052 /* Start displaying new lines in the desired matrix at the same
15053 vpos we would use in the current matrix, i.e. below
15054 last_unchanged_at_beg_row. */
15055 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15057 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15058 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15060 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15064 /* There are no reusable lines at the start of the window.
15065 Start displaying in the first text line. */
15066 start_display (&it
, w
, start
);
15067 it
.vpos
= it
.first_vpos
;
15068 start_pos
= it
.current
.pos
;
15071 /* Find the first row that is not affected by changes at the end of
15072 the buffer. Value will be null if there is no unchanged row, in
15073 which case we must redisplay to the end of the window. delta
15074 will be set to the value by which buffer positions beginning with
15075 first_unchanged_at_end_row have to be adjusted due to text
15077 first_unchanged_at_end_row
15078 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15079 IF_DEBUG (debug_delta
= delta
);
15080 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15082 /* Set stop_pos to the buffer position up to which we will have to
15083 display new lines. If first_unchanged_at_end_row != NULL, this
15084 is the buffer position of the start of the line displayed in that
15085 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15086 that we don't stop at a buffer position. */
15088 if (first_unchanged_at_end_row
)
15090 xassert (last_unchanged_at_beg_row
== NULL
15091 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15093 /* If this is a continuation line, move forward to the next one
15094 that isn't. Changes in lines above affect this line.
15095 Caution: this may move first_unchanged_at_end_row to a row
15096 not displaying text. */
15097 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15098 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15099 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15100 < it
.last_visible_y
))
15101 ++first_unchanged_at_end_row
;
15103 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15104 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15105 >= it
.last_visible_y
))
15106 first_unchanged_at_end_row
= NULL
;
15109 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15111 first_unchanged_at_end_vpos
15112 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15113 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15116 else if (last_unchanged_at_beg_row
== NULL
)
15122 /* Either there is no unchanged row at the end, or the one we have
15123 now displays text. This is a necessary condition for the window
15124 end pos calculation at the end of this function. */
15125 xassert (first_unchanged_at_end_row
== NULL
15126 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15128 debug_last_unchanged_at_beg_vpos
15129 = (last_unchanged_at_beg_row
15130 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15132 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15134 #endif /* GLYPH_DEBUG != 0 */
15137 /* Display new lines. Set last_text_row to the last new line
15138 displayed which has text on it, i.e. might end up as being the
15139 line where the window_end_vpos is. */
15140 w
->cursor
.vpos
= -1;
15141 last_text_row
= NULL
;
15142 overlay_arrow_seen
= 0;
15143 while (it
.current_y
< it
.last_visible_y
15144 && !fonts_changed_p
15145 && (first_unchanged_at_end_row
== NULL
15146 || IT_CHARPOS (it
) < stop_pos
))
15148 if (display_line (&it
))
15149 last_text_row
= it
.glyph_row
- 1;
15152 if (fonts_changed_p
)
15156 /* Compute differences in buffer positions, y-positions etc. for
15157 lines reused at the bottom of the window. Compute what we can
15159 if (first_unchanged_at_end_row
15160 /* No lines reused because we displayed everything up to the
15161 bottom of the window. */
15162 && it
.current_y
< it
.last_visible_y
)
15165 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15167 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15168 run
.current_y
= first_unchanged_at_end_row
->y
;
15169 run
.desired_y
= run
.current_y
+ dy
;
15170 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15174 delta
= delta_bytes
= dvpos
= dy
15175 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15176 first_unchanged_at_end_row
= NULL
;
15178 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15181 /* Find the cursor if not already found. We have to decide whether
15182 PT will appear on this window (it sometimes doesn't, but this is
15183 not a very frequent case.) This decision has to be made before
15184 the current matrix is altered. A value of cursor.vpos < 0 means
15185 that PT is either in one of the lines beginning at
15186 first_unchanged_at_end_row or below the window. Don't care for
15187 lines that might be displayed later at the window end; as
15188 mentioned, this is not a frequent case. */
15189 if (w
->cursor
.vpos
< 0)
15191 /* Cursor in unchanged rows at the top? */
15192 if (PT
< CHARPOS (start_pos
)
15193 && last_unchanged_at_beg_row
)
15195 row
= row_containing_pos (w
, PT
,
15196 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15197 last_unchanged_at_beg_row
+ 1, 0);
15199 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15202 /* Start from first_unchanged_at_end_row looking for PT. */
15203 else if (first_unchanged_at_end_row
)
15205 row
= row_containing_pos (w
, PT
- delta
,
15206 first_unchanged_at_end_row
, NULL
, 0);
15208 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15209 delta_bytes
, dy
, dvpos
);
15212 /* Give up if cursor was not found. */
15213 if (w
->cursor
.vpos
< 0)
15215 clear_glyph_matrix (w
->desired_matrix
);
15220 /* Don't let the cursor end in the scroll margins. */
15222 int this_scroll_margin
, cursor_height
;
15224 this_scroll_margin
= max (0, scroll_margin
);
15225 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15226 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15227 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15229 if ((w
->cursor
.y
< this_scroll_margin
15230 && CHARPOS (start
) > BEGV
)
15231 /* Old redisplay didn't take scroll margin into account at the bottom,
15232 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15233 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15234 ? cursor_height
+ this_scroll_margin
15235 : 1)) > it
.last_visible_y
)
15237 w
->cursor
.vpos
= -1;
15238 clear_glyph_matrix (w
->desired_matrix
);
15243 /* Scroll the display. Do it before changing the current matrix so
15244 that xterm.c doesn't get confused about where the cursor glyph is
15246 if (dy
&& run
.height
)
15250 if (FRAME_WINDOW_P (f
))
15252 FRAME_RIF (f
)->update_window_begin_hook (w
);
15253 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15254 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15255 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15259 /* Terminal frame. In this case, dvpos gives the number of
15260 lines to scroll by; dvpos < 0 means scroll up. */
15261 int first_unchanged_at_end_vpos
15262 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15263 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15264 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15265 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15266 + window_internal_height (w
));
15268 /* Perform the operation on the screen. */
15271 /* Scroll last_unchanged_at_beg_row to the end of the
15272 window down dvpos lines. */
15273 set_terminal_window (f
, end
);
15275 /* On dumb terminals delete dvpos lines at the end
15276 before inserting dvpos empty lines. */
15277 if (!FRAME_SCROLL_REGION_OK (f
))
15278 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15280 /* Insert dvpos empty lines in front of
15281 last_unchanged_at_beg_row. */
15282 ins_del_lines (f
, from
, dvpos
);
15284 else if (dvpos
< 0)
15286 /* Scroll up last_unchanged_at_beg_vpos to the end of
15287 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15288 set_terminal_window (f
, end
);
15290 /* Delete dvpos lines in front of
15291 last_unchanged_at_beg_vpos. ins_del_lines will set
15292 the cursor to the given vpos and emit |dvpos| delete
15294 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15296 /* On a dumb terminal insert dvpos empty lines at the
15298 if (!FRAME_SCROLL_REGION_OK (f
))
15299 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15302 set_terminal_window (f
, 0);
15308 /* Shift reused rows of the current matrix to the right position.
15309 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15311 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15312 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15315 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15316 bottom_vpos
, dvpos
);
15317 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15320 else if (dvpos
> 0)
15322 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15323 bottom_vpos
, dvpos
);
15324 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15325 first_unchanged_at_end_vpos
+ dvpos
, 0);
15328 /* For frame-based redisplay, make sure that current frame and window
15329 matrix are in sync with respect to glyph memory. */
15330 if (!FRAME_WINDOW_P (f
))
15331 sync_frame_with_window_matrix_rows (w
);
15333 /* Adjust buffer positions in reused rows. */
15334 if (delta
|| delta_bytes
)
15335 increment_matrix_positions (current_matrix
,
15336 first_unchanged_at_end_vpos
+ dvpos
,
15337 bottom_vpos
, delta
, delta_bytes
);
15339 /* Adjust Y positions. */
15341 shift_glyph_matrix (w
, current_matrix
,
15342 first_unchanged_at_end_vpos
+ dvpos
,
15345 if (first_unchanged_at_end_row
)
15347 first_unchanged_at_end_row
+= dvpos
;
15348 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15349 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15350 first_unchanged_at_end_row
= NULL
;
15353 /* If scrolling up, there may be some lines to display at the end of
15355 last_text_row_at_end
= NULL
;
15358 /* Scrolling up can leave for example a partially visible line
15359 at the end of the window to be redisplayed. */
15360 /* Set last_row to the glyph row in the current matrix where the
15361 window end line is found. It has been moved up or down in
15362 the matrix by dvpos. */
15363 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15364 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15366 /* If last_row is the window end line, it should display text. */
15367 xassert (last_row
->displays_text_p
);
15369 /* If window end line was partially visible before, begin
15370 displaying at that line. Otherwise begin displaying with the
15371 line following it. */
15372 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15374 init_to_row_start (&it
, w
, last_row
);
15375 it
.vpos
= last_vpos
;
15376 it
.current_y
= last_row
->y
;
15380 init_to_row_end (&it
, w
, last_row
);
15381 it
.vpos
= 1 + last_vpos
;
15382 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15386 /* We may start in a continuation line. If so, we have to
15387 get the right continuation_lines_width and current_x. */
15388 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15389 it
.hpos
= it
.current_x
= 0;
15391 /* Display the rest of the lines at the window end. */
15392 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15393 while (it
.current_y
< it
.last_visible_y
15394 && !fonts_changed_p
)
15396 /* Is it always sure that the display agrees with lines in
15397 the current matrix? I don't think so, so we mark rows
15398 displayed invalid in the current matrix by setting their
15399 enabled_p flag to zero. */
15400 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15401 if (display_line (&it
))
15402 last_text_row_at_end
= it
.glyph_row
- 1;
15406 /* Update window_end_pos and window_end_vpos. */
15407 if (first_unchanged_at_end_row
15408 && !last_text_row_at_end
)
15410 /* Window end line if one of the preserved rows from the current
15411 matrix. Set row to the last row displaying text in current
15412 matrix starting at first_unchanged_at_end_row, after
15414 xassert (first_unchanged_at_end_row
->displays_text_p
);
15415 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15416 first_unchanged_at_end_row
);
15417 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15419 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15420 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15422 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15423 xassert (w
->window_end_bytepos
>= 0);
15424 IF_DEBUG (debug_method_add (w
, "A"));
15426 else if (last_text_row_at_end
)
15429 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15430 w
->window_end_bytepos
15431 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15433 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15434 xassert (w
->window_end_bytepos
>= 0);
15435 IF_DEBUG (debug_method_add (w
, "B"));
15437 else if (last_text_row
)
15439 /* We have displayed either to the end of the window or at the
15440 end of the window, i.e. the last row with text is to be found
15441 in the desired matrix. */
15443 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15444 w
->window_end_bytepos
15445 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15447 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15448 xassert (w
->window_end_bytepos
>= 0);
15450 else if (first_unchanged_at_end_row
== NULL
15451 && last_text_row
== NULL
15452 && last_text_row_at_end
== NULL
)
15454 /* Displayed to end of window, but no line containing text was
15455 displayed. Lines were deleted at the end of the window. */
15456 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15457 int vpos
= XFASTINT (w
->window_end_vpos
);
15458 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15459 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15462 row
== NULL
&& vpos
>= first_vpos
;
15463 --vpos
, --current_row
, --desired_row
)
15465 if (desired_row
->enabled_p
)
15467 if (desired_row
->displays_text_p
)
15470 else if (current_row
->displays_text_p
)
15474 xassert (row
!= NULL
);
15475 w
->window_end_vpos
= make_number (vpos
+ 1);
15476 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15477 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15478 xassert (w
->window_end_bytepos
>= 0);
15479 IF_DEBUG (debug_method_add (w
, "C"));
15484 #if 0 /* This leads to problems, for instance when the cursor is
15485 at ZV, and the cursor line displays no text. */
15486 /* Disable rows below what's displayed in the window. This makes
15487 debugging easier. */
15488 enable_glyph_matrix_rows (current_matrix
,
15489 XFASTINT (w
->window_end_vpos
) + 1,
15493 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15494 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15496 /* Record that display has not been completed. */
15497 w
->window_end_valid
= Qnil
;
15498 w
->desired_matrix
->no_scrolling_p
= 1;
15506 /***********************************************************************
15507 More debugging support
15508 ***********************************************************************/
15512 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15513 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15514 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15517 /* Dump the contents of glyph matrix MATRIX on stderr.
15519 GLYPHS 0 means don't show glyph contents.
15520 GLYPHS 1 means show glyphs in short form
15521 GLYPHS > 1 means show glyphs in long form. */
15524 dump_glyph_matrix (matrix
, glyphs
)
15525 struct glyph_matrix
*matrix
;
15529 for (i
= 0; i
< matrix
->nrows
; ++i
)
15530 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15534 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15535 the glyph row and area where the glyph comes from. */
15538 dump_glyph (row
, glyph
, area
)
15539 struct glyph_row
*row
;
15540 struct glyph
*glyph
;
15543 if (glyph
->type
== CHAR_GLYPH
)
15546 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15547 glyph
- row
->glyphs
[TEXT_AREA
],
15550 (BUFFERP (glyph
->object
)
15552 : (STRINGP (glyph
->object
)
15555 glyph
->pixel_width
,
15557 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15561 glyph
->left_box_line_p
,
15562 glyph
->right_box_line_p
);
15564 else if (glyph
->type
== STRETCH_GLYPH
)
15567 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15568 glyph
- row
->glyphs
[TEXT_AREA
],
15571 (BUFFERP (glyph
->object
)
15573 : (STRINGP (glyph
->object
)
15576 glyph
->pixel_width
,
15580 glyph
->left_box_line_p
,
15581 glyph
->right_box_line_p
);
15583 else if (glyph
->type
== IMAGE_GLYPH
)
15586 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15587 glyph
- row
->glyphs
[TEXT_AREA
],
15590 (BUFFERP (glyph
->object
)
15592 : (STRINGP (glyph
->object
)
15595 glyph
->pixel_width
,
15599 glyph
->left_box_line_p
,
15600 glyph
->right_box_line_p
);
15602 else if (glyph
->type
== COMPOSITE_GLYPH
)
15605 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15606 glyph
- row
->glyphs
[TEXT_AREA
],
15609 (BUFFERP (glyph
->object
)
15611 : (STRINGP (glyph
->object
)
15614 glyph
->pixel_width
,
15618 glyph
->left_box_line_p
,
15619 glyph
->right_box_line_p
);
15624 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15625 GLYPHS 0 means don't show glyph contents.
15626 GLYPHS 1 means show glyphs in short form
15627 GLYPHS > 1 means show glyphs in long form. */
15630 dump_glyph_row (row
, vpos
, glyphs
)
15631 struct glyph_row
*row
;
15636 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15637 fprintf (stderr
, "======================================================================\n");
15639 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15640 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15642 MATRIX_ROW_START_CHARPOS (row
),
15643 MATRIX_ROW_END_CHARPOS (row
),
15644 row
->used
[TEXT_AREA
],
15645 row
->contains_overlapping_glyphs_p
,
15647 row
->truncated_on_left_p
,
15648 row
->truncated_on_right_p
,
15650 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15651 row
->displays_text_p
,
15654 row
->ends_in_middle_of_char_p
,
15655 row
->starts_in_middle_of_char_p
,
15661 row
->visible_height
,
15664 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15665 row
->end
.overlay_string_index
,
15666 row
->continuation_lines_width
);
15667 fprintf (stderr
, "%9d %5d\n",
15668 CHARPOS (row
->start
.string_pos
),
15669 CHARPOS (row
->end
.string_pos
));
15670 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15671 row
->end
.dpvec_index
);
15678 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15680 struct glyph
*glyph
= row
->glyphs
[area
];
15681 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15683 /* Glyph for a line end in text. */
15684 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15687 if (glyph
< glyph_end
)
15688 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15690 for (; glyph
< glyph_end
; ++glyph
)
15691 dump_glyph (row
, glyph
, area
);
15694 else if (glyphs
== 1)
15698 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15700 char *s
= (char *) alloca (row
->used
[area
] + 1);
15703 for (i
= 0; i
< row
->used
[area
]; ++i
)
15705 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15706 if (glyph
->type
== CHAR_GLYPH
15707 && glyph
->u
.ch
< 0x80
15708 && glyph
->u
.ch
>= ' ')
15709 s
[i
] = glyph
->u
.ch
;
15715 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15721 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15722 Sdump_glyph_matrix
, 0, 1, "p",
15723 doc
: /* Dump the current matrix of the selected window to stderr.
15724 Shows contents of glyph row structures. With non-nil
15725 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15726 glyphs in short form, otherwise show glyphs in long form. */)
15728 Lisp_Object glyphs
;
15730 struct window
*w
= XWINDOW (selected_window
);
15731 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15733 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15734 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15735 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15736 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15737 fprintf (stderr
, "=============================================\n");
15738 dump_glyph_matrix (w
->current_matrix
,
15739 NILP (glyphs
) ? 0 : XINT (glyphs
));
15744 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15745 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15748 struct frame
*f
= XFRAME (selected_frame
);
15749 dump_glyph_matrix (f
->current_matrix
, 1);
15754 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15755 doc
: /* Dump glyph row ROW to stderr.
15756 GLYPH 0 means don't dump glyphs.
15757 GLYPH 1 means dump glyphs in short form.
15758 GLYPH > 1 or omitted means dump glyphs in long form. */)
15760 Lisp_Object row
, glyphs
;
15762 struct glyph_matrix
*matrix
;
15765 CHECK_NUMBER (row
);
15766 matrix
= XWINDOW (selected_window
)->current_matrix
;
15768 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15769 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15771 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15776 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15777 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15778 GLYPH 0 means don't dump glyphs.
15779 GLYPH 1 means dump glyphs in short form.
15780 GLYPH > 1 or omitted means dump glyphs in long form. */)
15782 Lisp_Object row
, glyphs
;
15784 struct frame
*sf
= SELECTED_FRAME ();
15785 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15788 CHECK_NUMBER (row
);
15790 if (vpos
>= 0 && vpos
< m
->nrows
)
15791 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15792 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15797 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15798 doc
: /* Toggle tracing of redisplay.
15799 With ARG, turn tracing on if and only if ARG is positive. */)
15804 trace_redisplay_p
= !trace_redisplay_p
;
15807 arg
= Fprefix_numeric_value (arg
);
15808 trace_redisplay_p
= XINT (arg
) > 0;
15815 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15816 doc
: /* Like `format', but print result to stderr.
15817 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15822 Lisp_Object s
= Fformat (nargs
, args
);
15823 fprintf (stderr
, "%s", SDATA (s
));
15827 #endif /* GLYPH_DEBUG */
15831 /***********************************************************************
15832 Building Desired Matrix Rows
15833 ***********************************************************************/
15835 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15836 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15838 static struct glyph_row
*
15839 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15841 Lisp_Object overlay_arrow_string
;
15843 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15844 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15845 struct buffer
*old
= current_buffer
;
15846 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15847 int arrow_len
= SCHARS (overlay_arrow_string
);
15848 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15849 const unsigned char *p
;
15852 int n_glyphs_before
;
15854 set_buffer_temp (buffer
);
15855 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15856 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15857 SET_TEXT_POS (it
.position
, 0, 0);
15859 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15861 while (p
< arrow_end
)
15863 Lisp_Object face
, ilisp
;
15865 /* Get the next character. */
15867 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15869 it
.c
= *p
, it
.len
= 1;
15872 /* Get its face. */
15873 ilisp
= make_number (p
- arrow_string
);
15874 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15875 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15877 /* Compute its width, get its glyphs. */
15878 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15879 SET_TEXT_POS (it
.position
, -1, -1);
15880 PRODUCE_GLYPHS (&it
);
15882 /* If this character doesn't fit any more in the line, we have
15883 to remove some glyphs. */
15884 if (it
.current_x
> it
.last_visible_x
)
15886 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15891 set_buffer_temp (old
);
15892 return it
.glyph_row
;
15896 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15897 glyphs are only inserted for terminal frames since we can't really
15898 win with truncation glyphs when partially visible glyphs are
15899 involved. Which glyphs to insert is determined by
15900 produce_special_glyphs. */
15903 insert_left_trunc_glyphs (it
)
15906 struct it truncate_it
;
15907 struct glyph
*from
, *end
, *to
, *toend
;
15909 xassert (!FRAME_WINDOW_P (it
->f
));
15911 /* Get the truncation glyphs. */
15913 truncate_it
.current_x
= 0;
15914 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15915 truncate_it
.glyph_row
= &scratch_glyph_row
;
15916 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15917 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15918 truncate_it
.object
= make_number (0);
15919 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15921 /* Overwrite glyphs from IT with truncation glyphs. */
15922 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15923 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15924 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15925 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15930 /* There may be padding glyphs left over. Overwrite them too. */
15931 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15933 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15939 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15943 /* Compute the pixel height and width of IT->glyph_row.
15945 Most of the time, ascent and height of a display line will be equal
15946 to the max_ascent and max_height values of the display iterator
15947 structure. This is not the case if
15949 1. We hit ZV without displaying anything. In this case, max_ascent
15950 and max_height will be zero.
15952 2. We have some glyphs that don't contribute to the line height.
15953 (The glyph row flag contributes_to_line_height_p is for future
15954 pixmap extensions).
15956 The first case is easily covered by using default values because in
15957 these cases, the line height does not really matter, except that it
15958 must not be zero. */
15961 compute_line_metrics (it
)
15964 struct glyph_row
*row
= it
->glyph_row
;
15967 if (FRAME_WINDOW_P (it
->f
))
15969 int i
, min_y
, max_y
;
15971 /* The line may consist of one space only, that was added to
15972 place the cursor on it. If so, the row's height hasn't been
15974 if (row
->height
== 0)
15976 if (it
->max_ascent
+ it
->max_descent
== 0)
15977 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15978 row
->ascent
= it
->max_ascent
;
15979 row
->height
= it
->max_ascent
+ it
->max_descent
;
15980 row
->phys_ascent
= it
->max_phys_ascent
;
15981 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15982 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15985 /* Compute the width of this line. */
15986 row
->pixel_width
= row
->x
;
15987 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15988 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15990 xassert (row
->pixel_width
>= 0);
15991 xassert (row
->ascent
>= 0 && row
->height
> 0);
15993 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15994 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15996 /* If first line's physical ascent is larger than its logical
15997 ascent, use the physical ascent, and make the row taller.
15998 This makes accented characters fully visible. */
15999 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16000 && row
->phys_ascent
> row
->ascent
)
16002 row
->height
+= row
->phys_ascent
- row
->ascent
;
16003 row
->ascent
= row
->phys_ascent
;
16006 /* Compute how much of the line is visible. */
16007 row
->visible_height
= row
->height
;
16009 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16010 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16012 if (row
->y
< min_y
)
16013 row
->visible_height
-= min_y
- row
->y
;
16014 if (row
->y
+ row
->height
> max_y
)
16015 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16019 row
->pixel_width
= row
->used
[TEXT_AREA
];
16020 if (row
->continued_p
)
16021 row
->pixel_width
-= it
->continuation_pixel_width
;
16022 else if (row
->truncated_on_right_p
)
16023 row
->pixel_width
-= it
->truncation_pixel_width
;
16024 row
->ascent
= row
->phys_ascent
= 0;
16025 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16026 row
->extra_line_spacing
= 0;
16029 /* Compute a hash code for this row. */
16031 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16032 for (i
= 0; i
< row
->used
[area
]; ++i
)
16033 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16034 + row
->glyphs
[area
][i
].u
.val
16035 + row
->glyphs
[area
][i
].face_id
16036 + row
->glyphs
[area
][i
].padding_p
16037 + (row
->glyphs
[area
][i
].type
<< 2));
16039 it
->max_ascent
= it
->max_descent
= 0;
16040 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16044 /* Append one space to the glyph row of iterator IT if doing a
16045 window-based redisplay. The space has the same face as
16046 IT->face_id. Value is non-zero if a space was added.
16048 This function is called to make sure that there is always one glyph
16049 at the end of a glyph row that the cursor can be set on under
16050 window-systems. (If there weren't such a glyph we would not know
16051 how wide and tall a box cursor should be displayed).
16053 At the same time this space let's a nicely handle clearing to the
16054 end of the line if the row ends in italic text. */
16057 append_space_for_newline (it
, default_face_p
)
16059 int default_face_p
;
16061 if (FRAME_WINDOW_P (it
->f
))
16063 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16065 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16066 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16068 /* Save some values that must not be changed.
16069 Must save IT->c and IT->len because otherwise
16070 ITERATOR_AT_END_P wouldn't work anymore after
16071 append_space_for_newline has been called. */
16072 enum display_element_type saved_what
= it
->what
;
16073 int saved_c
= it
->c
, saved_len
= it
->len
;
16074 int saved_x
= it
->current_x
;
16075 int saved_face_id
= it
->face_id
;
16076 struct text_pos saved_pos
;
16077 Lisp_Object saved_object
;
16080 saved_object
= it
->object
;
16081 saved_pos
= it
->position
;
16083 it
->what
= IT_CHARACTER
;
16084 bzero (&it
->position
, sizeof it
->position
);
16085 it
->object
= make_number (0);
16089 if (default_face_p
)
16090 it
->face_id
= DEFAULT_FACE_ID
;
16091 else if (it
->face_before_selective_p
)
16092 it
->face_id
= it
->saved_face_id
;
16093 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16094 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16096 PRODUCE_GLYPHS (it
);
16098 it
->override_ascent
= -1;
16099 it
->constrain_row_ascent_descent_p
= 0;
16100 it
->current_x
= saved_x
;
16101 it
->object
= saved_object
;
16102 it
->position
= saved_pos
;
16103 it
->what
= saved_what
;
16104 it
->face_id
= saved_face_id
;
16105 it
->len
= saved_len
;
16115 /* Extend the face of the last glyph in the text area of IT->glyph_row
16116 to the end of the display line. Called from display_line.
16117 If the glyph row is empty, add a space glyph to it so that we
16118 know the face to draw. Set the glyph row flag fill_line_p. */
16121 extend_face_to_end_of_line (it
)
16125 struct frame
*f
= it
->f
;
16127 /* If line is already filled, do nothing. */
16128 if (it
->current_x
>= it
->last_visible_x
)
16131 /* Face extension extends the background and box of IT->face_id
16132 to the end of the line. If the background equals the background
16133 of the frame, we don't have to do anything. */
16134 if (it
->face_before_selective_p
)
16135 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16137 face
= FACE_FROM_ID (f
, it
->face_id
);
16139 if (FRAME_WINDOW_P (f
)
16140 && it
->glyph_row
->displays_text_p
16141 && face
->box
== FACE_NO_BOX
16142 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16146 /* Set the glyph row flag indicating that the face of the last glyph
16147 in the text area has to be drawn to the end of the text area. */
16148 it
->glyph_row
->fill_line_p
= 1;
16150 /* If current character of IT is not ASCII, make sure we have the
16151 ASCII face. This will be automatically undone the next time
16152 get_next_display_element returns a multibyte character. Note
16153 that the character will always be single byte in unibyte text. */
16154 if (!ASCII_CHAR_P (it
->c
))
16156 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16159 if (FRAME_WINDOW_P (f
))
16161 /* If the row is empty, add a space with the current face of IT,
16162 so that we know which face to draw. */
16163 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16165 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16166 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16167 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16172 /* Save some values that must not be changed. */
16173 int saved_x
= it
->current_x
;
16174 struct text_pos saved_pos
;
16175 Lisp_Object saved_object
;
16176 enum display_element_type saved_what
= it
->what
;
16177 int saved_face_id
= it
->face_id
;
16179 saved_object
= it
->object
;
16180 saved_pos
= it
->position
;
16182 it
->what
= IT_CHARACTER
;
16183 bzero (&it
->position
, sizeof it
->position
);
16184 it
->object
= make_number (0);
16187 it
->face_id
= face
->id
;
16189 PRODUCE_GLYPHS (it
);
16191 while (it
->current_x
<= it
->last_visible_x
)
16192 PRODUCE_GLYPHS (it
);
16194 /* Don't count these blanks really. It would let us insert a left
16195 truncation glyph below and make us set the cursor on them, maybe. */
16196 it
->current_x
= saved_x
;
16197 it
->object
= saved_object
;
16198 it
->position
= saved_pos
;
16199 it
->what
= saved_what
;
16200 it
->face_id
= saved_face_id
;
16205 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16206 trailing whitespace. */
16209 trailing_whitespace_p (charpos
)
16212 int bytepos
= CHAR_TO_BYTE (charpos
);
16215 while (bytepos
< ZV_BYTE
16216 && (c
= FETCH_CHAR (bytepos
),
16217 c
== ' ' || c
== '\t'))
16220 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16222 if (bytepos
!= PT_BYTE
)
16229 /* Highlight trailing whitespace, if any, in ROW. */
16232 highlight_trailing_whitespace (f
, row
)
16234 struct glyph_row
*row
;
16236 int used
= row
->used
[TEXT_AREA
];
16240 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16241 struct glyph
*glyph
= start
+ used
- 1;
16243 /* Skip over glyphs inserted to display the cursor at the
16244 end of a line, for extending the face of the last glyph
16245 to the end of the line on terminals, and for truncation
16246 and continuation glyphs. */
16247 while (glyph
>= start
16248 && glyph
->type
== CHAR_GLYPH
16249 && INTEGERP (glyph
->object
))
16252 /* If last glyph is a space or stretch, and it's trailing
16253 whitespace, set the face of all trailing whitespace glyphs in
16254 IT->glyph_row to `trailing-whitespace'. */
16256 && BUFFERP (glyph
->object
)
16257 && (glyph
->type
== STRETCH_GLYPH
16258 || (glyph
->type
== CHAR_GLYPH
16259 && glyph
->u
.ch
== ' '))
16260 && trailing_whitespace_p (glyph
->charpos
))
16262 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16266 while (glyph
>= start
16267 && BUFFERP (glyph
->object
)
16268 && (glyph
->type
== STRETCH_GLYPH
16269 || (glyph
->type
== CHAR_GLYPH
16270 && glyph
->u
.ch
== ' ')))
16271 (glyph
--)->face_id
= face_id
;
16277 /* Value is non-zero if glyph row ROW in window W should be
16278 used to hold the cursor. */
16281 cursor_row_p (w
, row
)
16283 struct glyph_row
*row
;
16285 int cursor_row_p
= 1;
16287 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16289 /* Suppose the row ends on a string.
16290 Unless the row is continued, that means it ends on a newline
16291 in the string. If it's anything other than a display string
16292 (e.g. a before-string from an overlay), we don't want the
16293 cursor there. (This heuristic seems to give the optimal
16294 behavior for the various types of multi-line strings.) */
16295 if (CHARPOS (row
->end
.string_pos
) >= 0)
16297 if (row
->continued_p
)
16301 /* Check for `display' property. */
16302 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16303 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16304 struct glyph
*glyph
;
16307 for (glyph
= end
; glyph
>= beg
; --glyph
)
16308 if (STRINGP (glyph
->object
))
16311 = Fget_char_property (make_number (PT
),
16315 && display_prop_string_p (prop
, glyph
->object
));
16320 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16322 /* If the row ends in middle of a real character,
16323 and the line is continued, we want the cursor here.
16324 That's because MATRIX_ROW_END_CHARPOS would equal
16325 PT if PT is before the character. */
16326 if (!row
->ends_in_ellipsis_p
)
16327 cursor_row_p
= row
->continued_p
;
16329 /* If the row ends in an ellipsis, then
16330 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16331 We want that position to be displayed after the ellipsis. */
16334 /* If the row ends at ZV, display the cursor at the end of that
16335 row instead of at the start of the row below. */
16336 else if (row
->ends_at_zv_p
)
16342 return cursor_row_p
;
16347 /* Push the display property PROP so that it will be rendered at the
16348 current position in IT. */
16351 push_display_prop (struct it
*it
, Lisp_Object prop
)
16355 /* Never display a cursor on the prefix. */
16356 it
->avoid_cursor_p
= 1;
16358 if (STRINGP (prop
))
16360 if (SCHARS (prop
) == 0)
16367 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16368 it
->current
.overlay_string_index
= -1;
16369 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16370 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16371 it
->method
= GET_FROM_STRING
;
16372 it
->stop_charpos
= 0;
16374 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16376 it
->method
= GET_FROM_STRETCH
;
16379 #ifdef HAVE_WINDOW_SYSTEM
16380 else if (IMAGEP (prop
))
16382 it
->what
= IT_IMAGE
;
16383 it
->image_id
= lookup_image (it
->f
, prop
);
16384 it
->method
= GET_FROM_IMAGE
;
16386 #endif /* HAVE_WINDOW_SYSTEM */
16389 pop_it (it
); /* bogus display property, give up */
16394 /* Return the character-property PROP at the current position in IT. */
16397 get_it_property (it
, prop
)
16401 Lisp_Object position
;
16403 if (STRINGP (it
->object
))
16404 position
= make_number (IT_STRING_CHARPOS (*it
));
16405 else if (BUFFERP (it
->object
))
16406 position
= make_number (IT_CHARPOS (*it
));
16410 return Fget_char_property (position
, prop
, it
->object
);
16413 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16416 handle_line_prefix (struct it
*it
)
16418 Lisp_Object prefix
;
16419 if (it
->continuation_lines_width
> 0)
16421 prefix
= get_it_property (it
, Qwrap_prefix
);
16423 prefix
= Vwrap_prefix
;
16427 prefix
= get_it_property (it
, Qline_prefix
);
16429 prefix
= Vline_prefix
;
16431 if (! NILP (prefix
))
16432 push_display_prop (it
, prefix
);
16437 /* Construct the glyph row IT->glyph_row in the desired matrix of
16438 IT->w from text at the current position of IT. See dispextern.h
16439 for an overview of struct it. Value is non-zero if
16440 IT->glyph_row displays text, as opposed to a line displaying ZV
16447 struct glyph_row
*row
= it
->glyph_row
;
16448 Lisp_Object overlay_arrow_string
;
16450 int may_wrap
= 0, wrap_x
;
16451 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16452 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16453 int wrap_row_extra_line_spacing
;
16455 /* We always start displaying at hpos zero even if hscrolled. */
16456 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16458 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16459 >= it
->w
->desired_matrix
->nrows
)
16461 it
->w
->nrows_scale_factor
++;
16462 fonts_changed_p
= 1;
16466 /* Is IT->w showing the region? */
16467 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16469 /* Clear the result glyph row and enable it. */
16470 prepare_desired_row (row
);
16472 row
->y
= it
->current_y
;
16473 row
->start
= it
->start
;
16474 row
->continuation_lines_width
= it
->continuation_lines_width
;
16475 row
->displays_text_p
= 1;
16476 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16477 it
->starts_in_middle_of_char_p
= 0;
16479 /* Arrange the overlays nicely for our purposes. Usually, we call
16480 display_line on only one line at a time, in which case this
16481 can't really hurt too much, or we call it on lines which appear
16482 one after another in the buffer, in which case all calls to
16483 recenter_overlay_lists but the first will be pretty cheap. */
16484 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16486 /* Move over display elements that are not visible because we are
16487 hscrolled. This may stop at an x-position < IT->first_visible_x
16488 if the first glyph is partially visible or if we hit a line end. */
16489 if (it
->current_x
< it
->first_visible_x
)
16491 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16492 MOVE_TO_POS
| MOVE_TO_X
);
16496 /* We only do this when not calling `move_it_in_display_line_to'
16497 above, because move_it_in_display_line_to calls
16498 handle_line_prefix itself. */
16499 handle_line_prefix (it
);
16502 /* Get the initial row height. This is either the height of the
16503 text hscrolled, if there is any, or zero. */
16504 row
->ascent
= it
->max_ascent
;
16505 row
->height
= it
->max_ascent
+ it
->max_descent
;
16506 row
->phys_ascent
= it
->max_phys_ascent
;
16507 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16508 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16510 /* Loop generating characters. The loop is left with IT on the next
16511 character to display. */
16514 int n_glyphs_before
, hpos_before
, x_before
;
16516 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16518 /* Retrieve the next thing to display. Value is zero if end of
16520 if (!get_next_display_element (it
))
16522 /* Maybe add a space at the end of this line that is used to
16523 display the cursor there under X. Set the charpos of the
16524 first glyph of blank lines not corresponding to any text
16526 #ifdef HAVE_WINDOW_SYSTEM
16527 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16528 row
->exact_window_width_line_p
= 1;
16530 #endif /* HAVE_WINDOW_SYSTEM */
16531 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16532 || row
->used
[TEXT_AREA
] == 0)
16534 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16535 row
->displays_text_p
= 0;
16537 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16538 && (!MINI_WINDOW_P (it
->w
)
16539 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16540 row
->indicate_empty_line_p
= 1;
16543 it
->continuation_lines_width
= 0;
16544 row
->ends_at_zv_p
= 1;
16548 /* Now, get the metrics of what we want to display. This also
16549 generates glyphs in `row' (which is IT->glyph_row). */
16550 n_glyphs_before
= row
->used
[TEXT_AREA
];
16553 /* Remember the line height so far in case the next element doesn't
16554 fit on the line. */
16555 if (it
->line_wrap
!= TRUNCATE
)
16557 ascent
= it
->max_ascent
;
16558 descent
= it
->max_descent
;
16559 phys_ascent
= it
->max_phys_ascent
;
16560 phys_descent
= it
->max_phys_descent
;
16562 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16564 if (IT_DISPLAYING_WHITESPACE (it
))
16570 wrap_row_used
= row
->used
[TEXT_AREA
];
16571 wrap_row_ascent
= row
->ascent
;
16572 wrap_row_height
= row
->height
;
16573 wrap_row_phys_ascent
= row
->phys_ascent
;
16574 wrap_row_phys_height
= row
->phys_height
;
16575 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16581 PRODUCE_GLYPHS (it
);
16583 /* If this display element was in marginal areas, continue with
16585 if (it
->area
!= TEXT_AREA
)
16587 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16588 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16589 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16590 row
->phys_height
= max (row
->phys_height
,
16591 it
->max_phys_ascent
+ it
->max_phys_descent
);
16592 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16593 it
->max_extra_line_spacing
);
16594 set_iterator_to_next (it
, 1);
16598 /* Does the display element fit on the line? If we truncate
16599 lines, we should draw past the right edge of the window. If
16600 we don't truncate, we want to stop so that we can display the
16601 continuation glyph before the right margin. If lines are
16602 continued, there are two possible strategies for characters
16603 resulting in more than 1 glyph (e.g. tabs): Display as many
16604 glyphs as possible in this line and leave the rest for the
16605 continuation line, or display the whole element in the next
16606 line. Original redisplay did the former, so we do it also. */
16607 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16608 hpos_before
= it
->hpos
;
16611 if (/* Not a newline. */
16613 /* Glyphs produced fit entirely in the line. */
16614 && it
->current_x
< it
->last_visible_x
)
16616 it
->hpos
+= nglyphs
;
16617 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16618 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16619 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16620 row
->phys_height
= max (row
->phys_height
,
16621 it
->max_phys_ascent
+ it
->max_phys_descent
);
16622 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16623 it
->max_extra_line_spacing
);
16624 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16625 row
->x
= x
- it
->first_visible_x
;
16630 struct glyph
*glyph
;
16632 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16634 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16635 new_x
= x
+ glyph
->pixel_width
;
16637 if (/* Lines are continued. */
16638 it
->line_wrap
!= TRUNCATE
16639 && (/* Glyph doesn't fit on the line. */
16640 new_x
> it
->last_visible_x
16641 /* Or it fits exactly on a window system frame. */
16642 || (new_x
== it
->last_visible_x
16643 && FRAME_WINDOW_P (it
->f
))))
16645 /* End of a continued line. */
16648 || (new_x
== it
->last_visible_x
16649 && FRAME_WINDOW_P (it
->f
)))
16651 /* Current glyph is the only one on the line or
16652 fits exactly on the line. We must continue
16653 the line because we can't draw the cursor
16654 after the glyph. */
16655 row
->continued_p
= 1;
16656 it
->current_x
= new_x
;
16657 it
->continuation_lines_width
+= new_x
;
16659 if (i
== nglyphs
- 1)
16661 /* If line-wrap is on, check if a previous
16662 wrap point was found. */
16663 if (wrap_row_used
> 0
16664 /* Even if there is a previous wrap
16665 point, continue the line here as
16666 usual, if (i) the previous character
16667 was a space or tab AND (ii) the
16668 current character is not. */
16670 || IT_DISPLAYING_WHITESPACE (it
)))
16673 set_iterator_to_next (it
, 1);
16674 #ifdef HAVE_WINDOW_SYSTEM
16675 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16677 if (!get_next_display_element (it
))
16679 row
->exact_window_width_line_p
= 1;
16680 it
->continuation_lines_width
= 0;
16681 row
->continued_p
= 0;
16682 row
->ends_at_zv_p
= 1;
16684 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16686 row
->continued_p
= 0;
16687 row
->exact_window_width_line_p
= 1;
16690 #endif /* HAVE_WINDOW_SYSTEM */
16693 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16694 && !FRAME_WINDOW_P (it
->f
))
16696 /* A padding glyph that doesn't fit on this line.
16697 This means the whole character doesn't fit
16699 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16701 /* Fill the rest of the row with continuation
16702 glyphs like in 20.x. */
16703 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16704 < row
->glyphs
[1 + TEXT_AREA
])
16705 produce_special_glyphs (it
, IT_CONTINUATION
);
16707 row
->continued_p
= 1;
16708 it
->current_x
= x_before
;
16709 it
->continuation_lines_width
+= x_before
;
16711 /* Restore the height to what it was before the
16712 element not fitting on the line. */
16713 it
->max_ascent
= ascent
;
16714 it
->max_descent
= descent
;
16715 it
->max_phys_ascent
= phys_ascent
;
16716 it
->max_phys_descent
= phys_descent
;
16718 else if (wrap_row_used
> 0)
16722 it
->continuation_lines_width
+= wrap_x
;
16723 row
->used
[TEXT_AREA
] = wrap_row_used
;
16724 row
->ascent
= wrap_row_ascent
;
16725 row
->height
= wrap_row_height
;
16726 row
->phys_ascent
= wrap_row_phys_ascent
;
16727 row
->phys_height
= wrap_row_phys_height
;
16728 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16729 row
->continued_p
= 1;
16730 row
->ends_at_zv_p
= 0;
16731 row
->exact_window_width_line_p
= 0;
16732 it
->continuation_lines_width
+= x
;
16734 /* Make sure that a non-default face is extended
16735 up to the right margin of the window. */
16736 extend_face_to_end_of_line (it
);
16738 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16740 /* A TAB that extends past the right edge of the
16741 window. This produces a single glyph on
16742 window system frames. We leave the glyph in
16743 this row and let it fill the row, but don't
16744 consume the TAB. */
16745 it
->continuation_lines_width
+= it
->last_visible_x
;
16746 row
->ends_in_middle_of_char_p
= 1;
16747 row
->continued_p
= 1;
16748 glyph
->pixel_width
= it
->last_visible_x
- x
;
16749 it
->starts_in_middle_of_char_p
= 1;
16753 /* Something other than a TAB that draws past
16754 the right edge of the window. Restore
16755 positions to values before the element. */
16756 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16758 /* Display continuation glyphs. */
16759 if (!FRAME_WINDOW_P (it
->f
))
16760 produce_special_glyphs (it
, IT_CONTINUATION
);
16761 row
->continued_p
= 1;
16763 it
->current_x
= x_before
;
16764 it
->continuation_lines_width
+= x
;
16765 extend_face_to_end_of_line (it
);
16767 if (nglyphs
> 1 && i
> 0)
16769 row
->ends_in_middle_of_char_p
= 1;
16770 it
->starts_in_middle_of_char_p
= 1;
16773 /* Restore the height to what it was before the
16774 element not fitting on the line. */
16775 it
->max_ascent
= ascent
;
16776 it
->max_descent
= descent
;
16777 it
->max_phys_ascent
= phys_ascent
;
16778 it
->max_phys_descent
= phys_descent
;
16783 else if (new_x
> it
->first_visible_x
)
16785 /* Increment number of glyphs actually displayed. */
16788 if (x
< it
->first_visible_x
)
16789 /* Glyph is partially visible, i.e. row starts at
16790 negative X position. */
16791 row
->x
= x
- it
->first_visible_x
;
16795 /* Glyph is completely off the left margin of the
16796 window. This should not happen because of the
16797 move_it_in_display_line at the start of this
16798 function, unless the text display area of the
16799 window is empty. */
16800 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16804 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16805 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16806 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16807 row
->phys_height
= max (row
->phys_height
,
16808 it
->max_phys_ascent
+ it
->max_phys_descent
);
16809 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16810 it
->max_extra_line_spacing
);
16812 /* End of this display line if row is continued. */
16813 if (row
->continued_p
|| row
->ends_at_zv_p
)
16818 /* Is this a line end? If yes, we're also done, after making
16819 sure that a non-default face is extended up to the right
16820 margin of the window. */
16821 if (ITERATOR_AT_END_OF_LINE_P (it
))
16823 int used_before
= row
->used
[TEXT_AREA
];
16825 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16827 #ifdef HAVE_WINDOW_SYSTEM
16828 /* Add a space at the end of the line that is used to
16829 display the cursor there. */
16830 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16831 append_space_for_newline (it
, 0);
16832 #endif /* HAVE_WINDOW_SYSTEM */
16834 /* Extend the face to the end of the line. */
16835 extend_face_to_end_of_line (it
);
16837 /* Make sure we have the position. */
16838 if (used_before
== 0)
16839 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16841 /* Consume the line end. This skips over invisible lines. */
16842 set_iterator_to_next (it
, 1);
16843 it
->continuation_lines_width
= 0;
16847 /* Proceed with next display element. Note that this skips
16848 over lines invisible because of selective display. */
16849 set_iterator_to_next (it
, 1);
16851 /* If we truncate lines, we are done when the last displayed
16852 glyphs reach past the right margin of the window. */
16853 if (it
->line_wrap
== TRUNCATE
16854 && (FRAME_WINDOW_P (it
->f
)
16855 ? (it
->current_x
>= it
->last_visible_x
)
16856 : (it
->current_x
> it
->last_visible_x
)))
16858 /* Maybe add truncation glyphs. */
16859 if (!FRAME_WINDOW_P (it
->f
))
16863 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16864 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16867 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16869 row
->used
[TEXT_AREA
] = i
;
16870 produce_special_glyphs (it
, IT_TRUNCATION
);
16873 #ifdef HAVE_WINDOW_SYSTEM
16876 /* Don't truncate if we can overflow newline into fringe. */
16877 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16879 if (!get_next_display_element (it
))
16881 it
->continuation_lines_width
= 0;
16882 row
->ends_at_zv_p
= 1;
16883 row
->exact_window_width_line_p
= 1;
16886 if (ITERATOR_AT_END_OF_LINE_P (it
))
16888 row
->exact_window_width_line_p
= 1;
16889 goto at_end_of_line
;
16893 #endif /* HAVE_WINDOW_SYSTEM */
16895 row
->truncated_on_right_p
= 1;
16896 it
->continuation_lines_width
= 0;
16897 reseat_at_next_visible_line_start (it
, 0);
16898 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16899 it
->hpos
= hpos_before
;
16900 it
->current_x
= x_before
;
16905 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16906 at the left window margin. */
16907 if (it
->first_visible_x
16908 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16910 if (!FRAME_WINDOW_P (it
->f
))
16911 insert_left_trunc_glyphs (it
);
16912 row
->truncated_on_left_p
= 1;
16915 /* If the start of this line is the overlay arrow-position, then
16916 mark this glyph row as the one containing the overlay arrow.
16917 This is clearly a mess with variable size fonts. It would be
16918 better to let it be displayed like cursors under X. */
16919 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16920 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16921 !NILP (overlay_arrow_string
)))
16923 /* Overlay arrow in window redisplay is a fringe bitmap. */
16924 if (STRINGP (overlay_arrow_string
))
16926 struct glyph_row
*arrow_row
16927 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16928 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16929 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16930 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16931 struct glyph
*p2
, *end
;
16933 /* Copy the arrow glyphs. */
16934 while (glyph
< arrow_end
)
16937 /* Throw away padding glyphs. */
16939 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16940 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16946 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16951 xassert (INTEGERP (overlay_arrow_string
));
16952 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16954 overlay_arrow_seen
= 1;
16957 /* Compute pixel dimensions of this line. */
16958 compute_line_metrics (it
);
16960 /* Remember the position at which this line ends. */
16961 row
->end
= it
->current
;
16963 /* Record whether this row ends inside an ellipsis. */
16964 row
->ends_in_ellipsis_p
16965 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16966 && it
->ellipsis_p
);
16968 /* Save fringe bitmaps in this row. */
16969 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16970 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16971 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16972 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16974 it
->left_user_fringe_bitmap
= 0;
16975 it
->left_user_fringe_face_id
= 0;
16976 it
->right_user_fringe_bitmap
= 0;
16977 it
->right_user_fringe_face_id
= 0;
16979 /* Maybe set the cursor. */
16980 if (it
->w
->cursor
.vpos
< 0
16981 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16982 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16983 && cursor_row_p (it
->w
, row
))
16984 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16986 /* Highlight trailing whitespace. */
16987 if (!NILP (Vshow_trailing_whitespace
))
16988 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16990 /* Prepare for the next line. This line starts horizontally at (X
16991 HPOS) = (0 0). Vertical positions are incremented. As a
16992 convenience for the caller, IT->glyph_row is set to the next
16994 it
->current_x
= it
->hpos
= 0;
16995 it
->current_y
+= row
->height
;
16998 it
->start
= it
->current
;
16999 return row
->displays_text_p
;
17004 /***********************************************************************
17006 ***********************************************************************/
17008 /* Redisplay the menu bar in the frame for window W.
17010 The menu bar of X frames that don't have X toolkit support is
17011 displayed in a special window W->frame->menu_bar_window.
17013 The menu bar of terminal frames is treated specially as far as
17014 glyph matrices are concerned. Menu bar lines are not part of
17015 windows, so the update is done directly on the frame matrix rows
17016 for the menu bar. */
17019 display_menu_bar (w
)
17022 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17027 /* Don't do all this for graphical frames. */
17029 if (FRAME_W32_P (f
))
17032 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17037 if (FRAME_MAC_P (f
))
17041 #ifdef USE_X_TOOLKIT
17042 xassert (!FRAME_WINDOW_P (f
));
17043 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17044 it
.first_visible_x
= 0;
17045 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17046 #else /* not USE_X_TOOLKIT */
17047 if (FRAME_WINDOW_P (f
))
17049 /* Menu bar lines are displayed in the desired matrix of the
17050 dummy window menu_bar_window. */
17051 struct window
*menu_w
;
17052 xassert (WINDOWP (f
->menu_bar_window
));
17053 menu_w
= XWINDOW (f
->menu_bar_window
);
17054 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17056 it
.first_visible_x
= 0;
17057 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17061 /* This is a TTY frame, i.e. character hpos/vpos are used as
17063 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17065 it
.first_visible_x
= 0;
17066 it
.last_visible_x
= FRAME_COLS (f
);
17068 #endif /* not USE_X_TOOLKIT */
17070 if (! mode_line_inverse_video
)
17071 /* Force the menu-bar to be displayed in the default face. */
17072 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17074 /* Clear all rows of the menu bar. */
17075 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17077 struct glyph_row
*row
= it
.glyph_row
+ i
;
17078 clear_glyph_row (row
);
17079 row
->enabled_p
= 1;
17080 row
->full_width_p
= 1;
17083 /* Display all items of the menu bar. */
17084 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17085 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17087 Lisp_Object string
;
17089 /* Stop at nil string. */
17090 string
= AREF (items
, i
+ 1);
17094 /* Remember where item was displayed. */
17095 ASET (items
, i
+ 3, make_number (it
.hpos
));
17097 /* Display the item, pad with one space. */
17098 if (it
.current_x
< it
.last_visible_x
)
17099 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17100 SCHARS (string
) + 1, 0, 0, -1);
17103 /* Fill out the line with spaces. */
17104 if (it
.current_x
< it
.last_visible_x
)
17105 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17107 /* Compute the total height of the lines. */
17108 compute_line_metrics (&it
);
17113 /***********************************************************************
17115 ***********************************************************************/
17117 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17118 FORCE is non-zero, redisplay mode lines unconditionally.
17119 Otherwise, redisplay only mode lines that are garbaged. Value is
17120 the number of windows whose mode lines were redisplayed. */
17123 redisplay_mode_lines (window
, force
)
17124 Lisp_Object window
;
17129 while (!NILP (window
))
17131 struct window
*w
= XWINDOW (window
);
17133 if (WINDOWP (w
->hchild
))
17134 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17135 else if (WINDOWP (w
->vchild
))
17136 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17138 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17139 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17141 struct text_pos lpoint
;
17142 struct buffer
*old
= current_buffer
;
17144 /* Set the window's buffer for the mode line display. */
17145 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17146 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17148 /* Point refers normally to the selected window. For any
17149 other window, set up appropriate value. */
17150 if (!EQ (window
, selected_window
))
17152 struct text_pos pt
;
17154 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17155 if (CHARPOS (pt
) < BEGV
)
17156 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17157 else if (CHARPOS (pt
) > (ZV
- 1))
17158 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17160 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17163 /* Display mode lines. */
17164 clear_glyph_matrix (w
->desired_matrix
);
17165 if (display_mode_lines (w
))
17168 w
->must_be_updated_p
= 1;
17171 /* Restore old settings. */
17172 set_buffer_internal_1 (old
);
17173 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17183 /* Display the mode and/or top line of window W. Value is the number
17184 of mode lines displayed. */
17187 display_mode_lines (w
)
17190 Lisp_Object old_selected_window
, old_selected_frame
;
17193 old_selected_frame
= selected_frame
;
17194 selected_frame
= w
->frame
;
17195 old_selected_window
= selected_window
;
17196 XSETWINDOW (selected_window
, w
);
17198 /* These will be set while the mode line specs are processed. */
17199 line_number_displayed
= 0;
17200 w
->column_number_displayed
= Qnil
;
17202 if (WINDOW_WANTS_MODELINE_P (w
))
17204 struct window
*sel_w
= XWINDOW (old_selected_window
);
17206 /* Select mode line face based on the real selected window. */
17207 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17208 current_buffer
->mode_line_format
);
17212 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17214 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17215 current_buffer
->header_line_format
);
17219 selected_frame
= old_selected_frame
;
17220 selected_window
= old_selected_window
;
17225 /* Display mode or top line of window W. FACE_ID specifies which line
17226 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
17227 FORMAT is the mode line format to display. Value is the pixel
17228 height of the mode line displayed. */
17231 display_mode_line (w
, face_id
, format
)
17233 enum face_id face_id
;
17234 Lisp_Object format
;
17238 int count
= SPECPDL_INDEX ();
17240 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17241 /* Don't extend on a previously drawn mode-line.
17242 This may happen if called from pos_visible_p. */
17243 it
.glyph_row
->enabled_p
= 0;
17244 prepare_desired_row (it
.glyph_row
);
17246 it
.glyph_row
->mode_line_p
= 1;
17248 if (! mode_line_inverse_video
)
17249 /* Force the mode-line to be displayed in the default face. */
17250 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17252 record_unwind_protect (unwind_format_mode_line
,
17253 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17255 mode_line_target
= MODE_LINE_DISPLAY
;
17257 /* Temporarily make frame's keyboard the current kboard so that
17258 kboard-local variables in the mode_line_format will get the right
17260 push_kboard (FRAME_KBOARD (it
.f
));
17261 record_unwind_save_match_data ();
17262 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17265 unbind_to (count
, Qnil
);
17267 /* Fill up with spaces. */
17268 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17270 compute_line_metrics (&it
);
17271 it
.glyph_row
->full_width_p
= 1;
17272 it
.glyph_row
->continued_p
= 0;
17273 it
.glyph_row
->truncated_on_left_p
= 0;
17274 it
.glyph_row
->truncated_on_right_p
= 0;
17276 /* Make a 3D mode-line have a shadow at its right end. */
17277 face
= FACE_FROM_ID (it
.f
, face_id
);
17278 extend_face_to_end_of_line (&it
);
17279 if (face
->box
!= FACE_NO_BOX
)
17281 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17282 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17283 last
->right_box_line_p
= 1;
17286 return it
.glyph_row
->height
;
17289 /* Move element ELT in LIST to the front of LIST.
17290 Return the updated list. */
17293 move_elt_to_front (elt
, list
)
17294 Lisp_Object elt
, list
;
17296 register Lisp_Object tail
, prev
;
17297 register Lisp_Object tem
;
17301 while (CONSP (tail
))
17307 /* Splice out the link TAIL. */
17309 list
= XCDR (tail
);
17311 Fsetcdr (prev
, XCDR (tail
));
17313 /* Now make it the first. */
17314 Fsetcdr (tail
, list
);
17319 tail
= XCDR (tail
);
17323 /* Not found--return unchanged LIST. */
17327 /* Contribute ELT to the mode line for window IT->w. How it
17328 translates into text depends on its data type.
17330 IT describes the display environment in which we display, as usual.
17332 DEPTH is the depth in recursion. It is used to prevent
17333 infinite recursion here.
17335 FIELD_WIDTH is the number of characters the display of ELT should
17336 occupy in the mode line, and PRECISION is the maximum number of
17337 characters to display from ELT's representation. See
17338 display_string for details.
17340 Returns the hpos of the end of the text generated by ELT.
17342 PROPS is a property list to add to any string we encounter.
17344 If RISKY is nonzero, remove (disregard) any properties in any string
17345 we encounter, and ignore :eval and :propertize.
17347 The global variable `mode_line_target' determines whether the
17348 output is passed to `store_mode_line_noprop',
17349 `store_mode_line_string', or `display_string'. */
17352 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17355 int field_width
, precision
;
17356 Lisp_Object elt
, props
;
17359 int n
= 0, field
, prec
;
17364 elt
= build_string ("*too-deep*");
17368 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17372 /* A string: output it and check for %-constructs within it. */
17376 if (SCHARS (elt
) > 0
17377 && (!NILP (props
) || risky
))
17379 Lisp_Object oprops
, aelt
;
17380 oprops
= Ftext_properties_at (make_number (0), elt
);
17382 /* If the starting string's properties are not what
17383 we want, translate the string. Also, if the string
17384 is risky, do that anyway. */
17386 if (NILP (Fequal (props
, oprops
)) || risky
)
17388 /* If the starting string has properties,
17389 merge the specified ones onto the existing ones. */
17390 if (! NILP (oprops
) && !risky
)
17394 oprops
= Fcopy_sequence (oprops
);
17396 while (CONSP (tem
))
17398 oprops
= Fplist_put (oprops
, XCAR (tem
),
17399 XCAR (XCDR (tem
)));
17400 tem
= XCDR (XCDR (tem
));
17405 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17406 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17408 /* AELT is what we want. Move it to the front
17409 without consing. */
17411 mode_line_proptrans_alist
17412 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17418 /* If AELT has the wrong props, it is useless.
17419 so get rid of it. */
17421 mode_line_proptrans_alist
17422 = Fdelq (aelt
, mode_line_proptrans_alist
);
17424 elt
= Fcopy_sequence (elt
);
17425 Fset_text_properties (make_number (0), Flength (elt
),
17427 /* Add this item to mode_line_proptrans_alist. */
17428 mode_line_proptrans_alist
17429 = Fcons (Fcons (elt
, props
),
17430 mode_line_proptrans_alist
);
17431 /* Truncate mode_line_proptrans_alist
17432 to at most 50 elements. */
17433 tem
= Fnthcdr (make_number (50),
17434 mode_line_proptrans_alist
);
17436 XSETCDR (tem
, Qnil
);
17445 prec
= precision
- n
;
17446 switch (mode_line_target
)
17448 case MODE_LINE_NOPROP
:
17449 case MODE_LINE_TITLE
:
17450 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17452 case MODE_LINE_STRING
:
17453 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17455 case MODE_LINE_DISPLAY
:
17456 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17457 0, prec
, 0, STRING_MULTIBYTE (elt
));
17464 /* Handle the non-literal case. */
17466 while ((precision
<= 0 || n
< precision
)
17467 && SREF (elt
, offset
) != 0
17468 && (mode_line_target
!= MODE_LINE_DISPLAY
17469 || it
->current_x
< it
->last_visible_x
))
17471 int last_offset
= offset
;
17473 /* Advance to end of string or next format specifier. */
17474 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17477 if (offset
- 1 != last_offset
)
17479 int nchars
, nbytes
;
17481 /* Output to end of string or up to '%'. Field width
17482 is length of string. Don't output more than
17483 PRECISION allows us. */
17486 prec
= c_string_width (SDATA (elt
) + last_offset
,
17487 offset
- last_offset
, precision
- n
,
17490 switch (mode_line_target
)
17492 case MODE_LINE_NOPROP
:
17493 case MODE_LINE_TITLE
:
17494 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17496 case MODE_LINE_STRING
:
17498 int bytepos
= last_offset
;
17499 int charpos
= string_byte_to_char (elt
, bytepos
);
17500 int endpos
= (precision
<= 0
17501 ? string_byte_to_char (elt
, offset
)
17502 : charpos
+ nchars
);
17504 n
+= store_mode_line_string (NULL
,
17505 Fsubstring (elt
, make_number (charpos
),
17506 make_number (endpos
)),
17510 case MODE_LINE_DISPLAY
:
17512 int bytepos
= last_offset
;
17513 int charpos
= string_byte_to_char (elt
, bytepos
);
17515 if (precision
<= 0)
17516 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17517 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17519 STRING_MULTIBYTE (elt
));
17524 else /* c == '%' */
17526 int percent_position
= offset
;
17528 /* Get the specified minimum width. Zero means
17531 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17532 field
= field
* 10 + c
- '0';
17534 /* Don't pad beyond the total padding allowed. */
17535 if (field_width
- n
> 0 && field
> field_width
- n
)
17536 field
= field_width
- n
;
17538 /* Note that either PRECISION <= 0 or N < PRECISION. */
17539 prec
= precision
- n
;
17542 n
+= display_mode_element (it
, depth
, field
, prec
,
17543 Vglobal_mode_string
, props
,
17548 int bytepos
, charpos
;
17549 unsigned char *spec
;
17551 bytepos
= percent_position
;
17552 charpos
= (STRING_MULTIBYTE (elt
)
17553 ? string_byte_to_char (elt
, bytepos
)
17556 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17558 switch (mode_line_target
)
17560 case MODE_LINE_NOPROP
:
17561 case MODE_LINE_TITLE
:
17562 n
+= store_mode_line_noprop (spec
, field
, prec
);
17564 case MODE_LINE_STRING
:
17566 int len
= strlen (spec
);
17567 Lisp_Object tem
= make_string (spec
, len
);
17568 props
= Ftext_properties_at (make_number (charpos
), elt
);
17569 /* Should only keep face property in props */
17570 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17573 case MODE_LINE_DISPLAY
:
17575 int nglyphs_before
, nwritten
;
17577 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17578 nwritten
= display_string (spec
, Qnil
, elt
,
17583 /* Assign to the glyphs written above the
17584 string where the `%x' came from, position
17588 struct glyph
*glyph
17589 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17593 for (i
= 0; i
< nwritten
; ++i
)
17595 glyph
[i
].object
= elt
;
17596 glyph
[i
].charpos
= charpos
;
17613 /* A symbol: process the value of the symbol recursively
17614 as if it appeared here directly. Avoid error if symbol void.
17615 Special case: if value of symbol is a string, output the string
17618 register Lisp_Object tem
;
17620 /* If the variable is not marked as risky to set
17621 then its contents are risky to use. */
17622 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17625 tem
= Fboundp (elt
);
17628 tem
= Fsymbol_value (elt
);
17629 /* If value is a string, output that string literally:
17630 don't check for % within it. */
17634 if (!EQ (tem
, elt
))
17636 /* Give up right away for nil or t. */
17646 register Lisp_Object car
, tem
;
17648 /* A cons cell: five distinct cases.
17649 If first element is :eval or :propertize, do something special.
17650 If first element is a string or a cons, process all the elements
17651 and effectively concatenate them.
17652 If first element is a negative number, truncate displaying cdr to
17653 at most that many characters. If positive, pad (with spaces)
17654 to at least that many characters.
17655 If first element is a symbol, process the cadr or caddr recursively
17656 according to whether the symbol's value is non-nil or nil. */
17658 if (EQ (car
, QCeval
))
17660 /* An element of the form (:eval FORM) means evaluate FORM
17661 and use the result as mode line elements. */
17666 if (CONSP (XCDR (elt
)))
17669 spec
= safe_eval (XCAR (XCDR (elt
)));
17670 n
+= display_mode_element (it
, depth
, field_width
- n
,
17671 precision
- n
, spec
, props
,
17675 else if (EQ (car
, QCpropertize
))
17677 /* An element of the form (:propertize ELT PROPS...)
17678 means display ELT but applying properties PROPS. */
17683 if (CONSP (XCDR (elt
)))
17684 n
+= display_mode_element (it
, depth
, field_width
- n
,
17685 precision
- n
, XCAR (XCDR (elt
)),
17686 XCDR (XCDR (elt
)), risky
);
17688 else if (SYMBOLP (car
))
17690 tem
= Fboundp (car
);
17694 /* elt is now the cdr, and we know it is a cons cell.
17695 Use its car if CAR has a non-nil value. */
17698 tem
= Fsymbol_value (car
);
17705 /* Symbol's value is nil (or symbol is unbound)
17706 Get the cddr of the original list
17707 and if possible find the caddr and use that. */
17711 else if (!CONSP (elt
))
17716 else if (INTEGERP (car
))
17718 register int lim
= XINT (car
);
17722 /* Negative int means reduce maximum width. */
17723 if (precision
<= 0)
17726 precision
= min (precision
, -lim
);
17730 /* Padding specified. Don't let it be more than
17731 current maximum. */
17733 lim
= min (precision
, lim
);
17735 /* If that's more padding than already wanted, queue it.
17736 But don't reduce padding already specified even if
17737 that is beyond the current truncation point. */
17738 field_width
= max (lim
, field_width
);
17742 else if (STRINGP (car
) || CONSP (car
))
17744 register int limit
= 50;
17745 /* Limit is to protect against circular lists. */
17748 && (precision
<= 0 || n
< precision
))
17750 n
+= display_mode_element (it
, depth
,
17751 /* Do padding only after the last
17752 element in the list. */
17753 (! CONSP (XCDR (elt
))
17756 precision
- n
, XCAR (elt
),
17766 elt
= build_string ("*invalid*");
17770 /* Pad to FIELD_WIDTH. */
17771 if (field_width
> 0 && n
< field_width
)
17773 switch (mode_line_target
)
17775 case MODE_LINE_NOPROP
:
17776 case MODE_LINE_TITLE
:
17777 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17779 case MODE_LINE_STRING
:
17780 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17782 case MODE_LINE_DISPLAY
:
17783 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17792 /* Store a mode-line string element in mode_line_string_list.
17794 If STRING is non-null, display that C string. Otherwise, the Lisp
17795 string LISP_STRING is displayed.
17797 FIELD_WIDTH is the minimum number of output glyphs to produce.
17798 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17799 with spaces. FIELD_WIDTH <= 0 means don't pad.
17801 PRECISION is the maximum number of characters to output from
17802 STRING. PRECISION <= 0 means don't truncate the string.
17804 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17805 properties to the string.
17807 PROPS are the properties to add to the string.
17808 The mode_line_string_face face property is always added to the string.
17812 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17814 Lisp_Object lisp_string
;
17823 if (string
!= NULL
)
17825 len
= strlen (string
);
17826 if (precision
> 0 && len
> precision
)
17828 lisp_string
= make_string (string
, len
);
17830 props
= mode_line_string_face_prop
;
17831 else if (!NILP (mode_line_string_face
))
17833 Lisp_Object face
= Fplist_get (props
, Qface
);
17834 props
= Fcopy_sequence (props
);
17836 face
= mode_line_string_face
;
17838 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17839 props
= Fplist_put (props
, Qface
, face
);
17841 Fadd_text_properties (make_number (0), make_number (len
),
17842 props
, lisp_string
);
17846 len
= XFASTINT (Flength (lisp_string
));
17847 if (precision
> 0 && len
> precision
)
17850 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17853 if (!NILP (mode_line_string_face
))
17857 props
= Ftext_properties_at (make_number (0), lisp_string
);
17858 face
= Fplist_get (props
, Qface
);
17860 face
= mode_line_string_face
;
17862 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17863 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17865 lisp_string
= Fcopy_sequence (lisp_string
);
17868 Fadd_text_properties (make_number (0), make_number (len
),
17869 props
, lisp_string
);
17874 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17878 if (field_width
> len
)
17880 field_width
-= len
;
17881 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17883 Fadd_text_properties (make_number (0), make_number (field_width
),
17884 props
, lisp_string
);
17885 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17893 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17895 doc
: /* Format a string out of a mode line format specification.
17896 First arg FORMAT specifies the mode line format (see `mode-line-format'
17897 for details) to use.
17899 Optional second arg FACE specifies the face property to put
17900 on all characters for which no face is specified.
17901 The value t means whatever face the window's mode line currently uses
17902 \(either `mode-line' or `mode-line-inactive', depending).
17903 A value of nil means the default is no face property.
17904 If FACE is an integer, the value string has no text properties.
17906 Optional third and fourth args WINDOW and BUFFER specify the window
17907 and buffer to use as the context for the formatting (defaults
17908 are the selected window and the window's buffer). */)
17909 (format
, face
, window
, buffer
)
17910 Lisp_Object format
, face
, window
, buffer
;
17915 struct buffer
*old_buffer
= NULL
;
17917 int no_props
= INTEGERP (face
);
17918 int count
= SPECPDL_INDEX ();
17920 int string_start
= 0;
17923 window
= selected_window
;
17924 CHECK_WINDOW (window
);
17925 w
= XWINDOW (window
);
17928 buffer
= w
->buffer
;
17929 CHECK_BUFFER (buffer
);
17931 /* Make formatting the modeline a non-op when noninteractive, otherwise
17932 there will be problems later caused by a partially initialized frame. */
17933 if (NILP (format
) || noninteractive
)
17934 return empty_unibyte_string
;
17942 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17943 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17947 face_id
= DEFAULT_FACE_ID
;
17949 if (XBUFFER (buffer
) != current_buffer
)
17950 old_buffer
= current_buffer
;
17952 /* Save things including mode_line_proptrans_alist,
17953 and set that to nil so that we don't alter the outer value. */
17954 record_unwind_protect (unwind_format_mode_line
,
17955 format_mode_line_unwind_data
17956 (old_buffer
, selected_window
, 1));
17957 mode_line_proptrans_alist
= Qnil
;
17959 Fselect_window (window
, Qt
);
17961 set_buffer_internal_1 (XBUFFER (buffer
));
17963 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17967 mode_line_target
= MODE_LINE_NOPROP
;
17968 mode_line_string_face_prop
= Qnil
;
17969 mode_line_string_list
= Qnil
;
17970 string_start
= MODE_LINE_NOPROP_LEN (0);
17974 mode_line_target
= MODE_LINE_STRING
;
17975 mode_line_string_list
= Qnil
;
17976 mode_line_string_face
= face
;
17977 mode_line_string_face_prop
17978 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17981 push_kboard (FRAME_KBOARD (it
.f
));
17982 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17987 len
= MODE_LINE_NOPROP_LEN (string_start
);
17988 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17992 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17993 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17994 empty_unibyte_string
);
17997 unbind_to (count
, Qnil
);
18001 /* Write a null-terminated, right justified decimal representation of
18002 the positive integer D to BUF using a minimal field width WIDTH. */
18005 pint2str (buf
, width
, d
)
18006 register char *buf
;
18007 register int width
;
18010 register char *p
= buf
;
18018 *p
++ = d
% 10 + '0';
18023 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18034 /* Write a null-terminated, right justified decimal and "human
18035 readable" representation of the nonnegative integer D to BUF using
18036 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18038 static const char power_letter
[] =
18052 pint2hrstr (buf
, width
, d
)
18057 /* We aim to represent the nonnegative integer D as
18058 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18061 /* -1 means: do not use TENTHS. */
18065 /* Length of QUOTIENT.TENTHS as a string. */
18071 if (1000 <= quotient
)
18073 /* Scale to the appropriate EXPONENT. */
18076 remainder
= quotient
% 1000;
18080 while (1000 <= quotient
);
18082 /* Round to nearest and decide whether to use TENTHS or not. */
18085 tenths
= remainder
/ 100;
18086 if (50 <= remainder
% 100)
18093 if (quotient
== 10)
18101 if (500 <= remainder
)
18103 if (quotient
< 999)
18114 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18115 if (tenths
== -1 && quotient
<= 99)
18122 p
= psuffix
= buf
+ max (width
, length
);
18124 /* Print EXPONENT. */
18126 *psuffix
++ = power_letter
[exponent
];
18129 /* Print TENTHS. */
18132 *--p
= '0' + tenths
;
18136 /* Print QUOTIENT. */
18139 int digit
= quotient
% 10;
18140 *--p
= '0' + digit
;
18142 while ((quotient
/= 10) != 0);
18144 /* Print leading spaces. */
18149 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18150 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18151 type of CODING_SYSTEM. Return updated pointer into BUF. */
18153 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18156 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18157 Lisp_Object coding_system
;
18158 register char *buf
;
18162 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18163 const unsigned char *eol_str
;
18165 /* The EOL conversion we are using. */
18166 Lisp_Object eoltype
;
18168 val
= CODING_SYSTEM_SPEC (coding_system
);
18171 if (!VECTORP (val
)) /* Not yet decided. */
18176 eoltype
= eol_mnemonic_undecided
;
18177 /* Don't mention EOL conversion if it isn't decided. */
18182 Lisp_Object eolvalue
;
18184 attrs
= AREF (val
, 0);
18185 eolvalue
= AREF (val
, 2);
18188 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18192 /* The EOL conversion that is normal on this system. */
18194 if (NILP (eolvalue
)) /* Not yet decided. */
18195 eoltype
= eol_mnemonic_undecided
;
18196 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18197 eoltype
= eol_mnemonic_undecided
;
18198 else /* eolvalue is Qunix, Qdos, or Qmac. */
18199 eoltype
= (EQ (eolvalue
, Qunix
)
18200 ? eol_mnemonic_unix
18201 : (EQ (eolvalue
, Qdos
) == 1
18202 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18208 /* Mention the EOL conversion if it is not the usual one. */
18209 if (STRINGP (eoltype
))
18211 eol_str
= SDATA (eoltype
);
18212 eol_str_len
= SBYTES (eoltype
);
18214 else if (CHARACTERP (eoltype
))
18216 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18217 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18222 eol_str
= invalid_eol_type
;
18223 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18225 bcopy (eol_str
, buf
, eol_str_len
);
18226 buf
+= eol_str_len
;
18232 /* Return a string for the output of a mode line %-spec for window W,
18233 generated by character C. PRECISION >= 0 means don't return a
18234 string longer than that value. FIELD_WIDTH > 0 means pad the
18235 string returned with spaces to that value. Return 1 in *MULTIBYTE
18236 if the result is multibyte text.
18238 Note we operate on the current buffer for most purposes,
18239 the exception being w->base_line_pos. */
18241 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18244 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
18247 int field_width
, precision
;
18251 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18252 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18253 struct buffer
*b
= current_buffer
;
18261 if (!NILP (b
->read_only
))
18263 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18268 /* This differs from %* only for a modified read-only buffer. */
18269 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18271 if (!NILP (b
->read_only
))
18276 /* This differs from %* in ignoring read-only-ness. */
18277 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18289 if (command_loop_level
> 5)
18291 p
= decode_mode_spec_buf
;
18292 for (i
= 0; i
< command_loop_level
; i
++)
18295 return decode_mode_spec_buf
;
18303 if (command_loop_level
> 5)
18305 p
= decode_mode_spec_buf
;
18306 for (i
= 0; i
< command_loop_level
; i
++)
18309 return decode_mode_spec_buf
;
18316 /* Let lots_of_dashes be a string of infinite length. */
18317 if (mode_line_target
== MODE_LINE_NOPROP
||
18318 mode_line_target
== MODE_LINE_STRING
)
18320 if (field_width
<= 0
18321 || field_width
> sizeof (lots_of_dashes
))
18323 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18324 decode_mode_spec_buf
[i
] = '-';
18325 decode_mode_spec_buf
[i
] = '\0';
18326 return decode_mode_spec_buf
;
18329 return lots_of_dashes
;
18337 /* %c and %l are ignored in `frame-title-format'.
18338 (In redisplay_internal, the frame title is drawn _before_ the
18339 windows are updated, so the stuff which depends on actual
18340 window contents (such as %l) may fail to render properly, or
18341 even crash emacs.) */
18342 if (mode_line_target
== MODE_LINE_TITLE
)
18346 int col
= (int) current_column (); /* iftc */
18347 w
->column_number_displayed
= make_number (col
);
18348 pint2str (decode_mode_spec_buf
, field_width
, col
);
18349 return decode_mode_spec_buf
;
18353 #ifndef SYSTEM_MALLOC
18355 if (NILP (Vmemory_full
))
18358 return "!MEM FULL! ";
18365 /* %F displays the frame name. */
18366 if (!NILP (f
->title
))
18367 return (char *) SDATA (f
->title
);
18368 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18369 return (char *) SDATA (f
->name
);
18378 int size
= ZV
- BEGV
;
18379 pint2str (decode_mode_spec_buf
, field_width
, size
);
18380 return decode_mode_spec_buf
;
18385 int size
= ZV
- BEGV
;
18386 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18387 return decode_mode_spec_buf
;
18392 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18393 int topline
, nlines
, junk
, height
;
18395 /* %c and %l are ignored in `frame-title-format'. */
18396 if (mode_line_target
== MODE_LINE_TITLE
)
18399 startpos
= XMARKER (w
->start
)->charpos
;
18400 startpos_byte
= marker_byte_position (w
->start
);
18401 height
= WINDOW_TOTAL_LINES (w
);
18403 /* If we decided that this buffer isn't suitable for line numbers,
18404 don't forget that too fast. */
18405 if (EQ (w
->base_line_pos
, w
->buffer
))
18407 /* But do forget it, if the window shows a different buffer now. */
18408 else if (BUFFERP (w
->base_line_pos
))
18409 w
->base_line_pos
= Qnil
;
18411 /* If the buffer is very big, don't waste time. */
18412 if (INTEGERP (Vline_number_display_limit
)
18413 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18415 w
->base_line_pos
= Qnil
;
18416 w
->base_line_number
= Qnil
;
18420 if (INTEGERP (w
->base_line_number
)
18421 && INTEGERP (w
->base_line_pos
)
18422 && XFASTINT (w
->base_line_pos
) <= startpos
)
18424 line
= XFASTINT (w
->base_line_number
);
18425 linepos
= XFASTINT (w
->base_line_pos
);
18426 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18431 linepos
= BUF_BEGV (b
);
18432 linepos_byte
= BUF_BEGV_BYTE (b
);
18435 /* Count lines from base line to window start position. */
18436 nlines
= display_count_lines (linepos
, linepos_byte
,
18440 topline
= nlines
+ line
;
18442 /* Determine a new base line, if the old one is too close
18443 or too far away, or if we did not have one.
18444 "Too close" means it's plausible a scroll-down would
18445 go back past it. */
18446 if (startpos
== BUF_BEGV (b
))
18448 w
->base_line_number
= make_number (topline
);
18449 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18451 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18452 || linepos
== BUF_BEGV (b
))
18454 int limit
= BUF_BEGV (b
);
18455 int limit_byte
= BUF_BEGV_BYTE (b
);
18457 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18459 if (startpos
- distance
> limit
)
18461 limit
= startpos
- distance
;
18462 limit_byte
= CHAR_TO_BYTE (limit
);
18465 nlines
= display_count_lines (startpos
, startpos_byte
,
18467 - (height
* 2 + 30),
18469 /* If we couldn't find the lines we wanted within
18470 line_number_display_limit_width chars per line,
18471 give up on line numbers for this window. */
18472 if (position
== limit_byte
&& limit
== startpos
- distance
)
18474 w
->base_line_pos
= w
->buffer
;
18475 w
->base_line_number
= Qnil
;
18479 w
->base_line_number
= make_number (topline
- nlines
);
18480 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18483 /* Now count lines from the start pos to point. */
18484 nlines
= display_count_lines (startpos
, startpos_byte
,
18485 PT_BYTE
, PT
, &junk
);
18487 /* Record that we did display the line number. */
18488 line_number_displayed
= 1;
18490 /* Make the string to show. */
18491 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18492 return decode_mode_spec_buf
;
18495 char* p
= decode_mode_spec_buf
;
18496 int pad
= field_width
- 2;
18502 return decode_mode_spec_buf
;
18508 obj
= b
->mode_name
;
18512 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18518 int pos
= marker_position (w
->start
);
18519 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18521 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18523 if (pos
<= BUF_BEGV (b
))
18528 else if (pos
<= BUF_BEGV (b
))
18532 if (total
> 1000000)
18533 /* Do it differently for a large value, to avoid overflow. */
18534 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18536 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18537 /* We can't normally display a 3-digit number,
18538 so get us a 2-digit number that is close. */
18541 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18542 return decode_mode_spec_buf
;
18546 /* Display percentage of size above the bottom of the screen. */
18549 int toppos
= marker_position (w
->start
);
18550 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18551 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18553 if (botpos
>= BUF_ZV (b
))
18555 if (toppos
<= BUF_BEGV (b
))
18562 if (total
> 1000000)
18563 /* Do it differently for a large value, to avoid overflow. */
18564 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18566 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18567 /* We can't normally display a 3-digit number,
18568 so get us a 2-digit number that is close. */
18571 if (toppos
<= BUF_BEGV (b
))
18572 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18574 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18575 return decode_mode_spec_buf
;
18580 /* status of process */
18581 obj
= Fget_buffer_process (Fcurrent_buffer ());
18583 return "no process";
18584 #ifdef subprocesses
18585 obj
= Fsymbol_name (Fprocess_status (obj
));
18592 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18599 case 't': /* indicate TEXT or BINARY */
18600 #ifdef MODE_LINE_BINARY_TEXT
18601 return MODE_LINE_BINARY_TEXT (b
);
18607 /* coding-system (not including end-of-line format) */
18609 /* coding-system (including end-of-line type) */
18611 int eol_flag
= (c
== 'Z');
18612 char *p
= decode_mode_spec_buf
;
18614 if (! FRAME_WINDOW_P (f
))
18616 /* No need to mention EOL here--the terminal never needs
18617 to do EOL conversion. */
18618 p
= decode_mode_spec_coding (CODING_ID_NAME
18619 (FRAME_KEYBOARD_CODING (f
)->id
),
18621 p
= decode_mode_spec_coding (CODING_ID_NAME
18622 (FRAME_TERMINAL_CODING (f
)->id
),
18625 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18628 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18629 #ifdef subprocesses
18630 obj
= Fget_buffer_process (Fcurrent_buffer ());
18631 if (PROCESSP (obj
))
18633 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18635 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18638 #endif /* subprocesses */
18641 return decode_mode_spec_buf
;
18647 *multibyte
= STRING_MULTIBYTE (obj
);
18648 return (char *) SDATA (obj
);
18655 /* Count up to COUNT lines starting from START / START_BYTE.
18656 But don't go beyond LIMIT_BYTE.
18657 Return the number of lines thus found (always nonnegative).
18659 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18662 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18663 int start
, start_byte
, limit_byte
, count
;
18666 register unsigned char *cursor
;
18667 unsigned char *base
;
18669 register int ceiling
;
18670 register unsigned char *ceiling_addr
;
18671 int orig_count
= count
;
18673 /* If we are not in selective display mode,
18674 check only for newlines. */
18675 int selective_display
= (!NILP (current_buffer
->selective_display
)
18676 && !INTEGERP (current_buffer
->selective_display
));
18680 while (start_byte
< limit_byte
)
18682 ceiling
= BUFFER_CEILING_OF (start_byte
);
18683 ceiling
= min (limit_byte
- 1, ceiling
);
18684 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18685 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18688 if (selective_display
)
18689 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18692 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18695 if (cursor
!= ceiling_addr
)
18699 start_byte
+= cursor
- base
+ 1;
18700 *byte_pos_ptr
= start_byte
;
18704 if (++cursor
== ceiling_addr
)
18710 start_byte
+= cursor
- base
;
18715 while (start_byte
> limit_byte
)
18717 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18718 ceiling
= max (limit_byte
, ceiling
);
18719 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18720 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18723 if (selective_display
)
18724 while (--cursor
!= ceiling_addr
18725 && *cursor
!= '\n' && *cursor
!= 015)
18728 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18731 if (cursor
!= ceiling_addr
)
18735 start_byte
+= cursor
- base
+ 1;
18736 *byte_pos_ptr
= start_byte
;
18737 /* When scanning backwards, we should
18738 not count the newline posterior to which we stop. */
18739 return - orig_count
- 1;
18745 /* Here we add 1 to compensate for the last decrement
18746 of CURSOR, which took it past the valid range. */
18747 start_byte
+= cursor
- base
+ 1;
18751 *byte_pos_ptr
= limit_byte
;
18754 return - orig_count
+ count
;
18755 return orig_count
- count
;
18761 /***********************************************************************
18763 ***********************************************************************/
18765 /* Display a NUL-terminated string, starting with index START.
18767 If STRING is non-null, display that C string. Otherwise, the Lisp
18768 string LISP_STRING is displayed.
18770 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18771 FACE_STRING. Display STRING or LISP_STRING with the face at
18772 FACE_STRING_POS in FACE_STRING:
18774 Display the string in the environment given by IT, but use the
18775 standard display table, temporarily.
18777 FIELD_WIDTH is the minimum number of output glyphs to produce.
18778 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18779 with spaces. If STRING has more characters, more than FIELD_WIDTH
18780 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18782 PRECISION is the maximum number of characters to output from
18783 STRING. PRECISION < 0 means don't truncate the string.
18785 This is roughly equivalent to printf format specifiers:
18787 FIELD_WIDTH PRECISION PRINTF
18788 ----------------------------------------
18794 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18795 display them, and < 0 means obey the current buffer's value of
18796 enable_multibyte_characters.
18798 Value is the number of columns displayed. */
18801 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18802 start
, it
, field_width
, precision
, max_x
, multibyte
)
18803 unsigned char *string
;
18804 Lisp_Object lisp_string
;
18805 Lisp_Object face_string
;
18806 EMACS_INT face_string_pos
;
18809 int field_width
, precision
, max_x
;
18812 int hpos_at_start
= it
->hpos
;
18813 int saved_face_id
= it
->face_id
;
18814 struct glyph_row
*row
= it
->glyph_row
;
18816 /* Initialize the iterator IT for iteration over STRING beginning
18817 with index START. */
18818 reseat_to_string (it
, string
, lisp_string
, start
,
18819 precision
, field_width
, multibyte
);
18821 /* If displaying STRING, set up the face of the iterator
18822 from LISP_STRING, if that's given. */
18823 if (STRINGP (face_string
))
18829 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18830 0, it
->region_beg_charpos
,
18831 it
->region_end_charpos
,
18832 &endptr
, it
->base_face_id
, 0);
18833 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18834 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18837 /* Set max_x to the maximum allowed X position. Don't let it go
18838 beyond the right edge of the window. */
18840 max_x
= it
->last_visible_x
;
18842 max_x
= min (max_x
, it
->last_visible_x
);
18844 /* Skip over display elements that are not visible. because IT->w is
18846 if (it
->current_x
< it
->first_visible_x
)
18847 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18848 MOVE_TO_POS
| MOVE_TO_X
);
18850 row
->ascent
= it
->max_ascent
;
18851 row
->height
= it
->max_ascent
+ it
->max_descent
;
18852 row
->phys_ascent
= it
->max_phys_ascent
;
18853 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18854 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18856 /* This condition is for the case that we are called with current_x
18857 past last_visible_x. */
18858 while (it
->current_x
< max_x
)
18860 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18862 /* Get the next display element. */
18863 if (!get_next_display_element (it
))
18866 /* Produce glyphs. */
18867 x_before
= it
->current_x
;
18868 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18869 PRODUCE_GLYPHS (it
);
18871 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18874 while (i
< nglyphs
)
18876 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18878 if (it
->line_wrap
!= TRUNCATE
18879 && x
+ glyph
->pixel_width
> max_x
)
18881 /* End of continued line or max_x reached. */
18882 if (CHAR_GLYPH_PADDING_P (*glyph
))
18884 /* A wide character is unbreakable. */
18885 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18886 it
->current_x
= x_before
;
18890 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18895 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18897 /* Glyph is at least partially visible. */
18899 if (x
< it
->first_visible_x
)
18900 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18904 /* Glyph is off the left margin of the display area.
18905 Should not happen. */
18909 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18910 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18911 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18912 row
->phys_height
= max (row
->phys_height
,
18913 it
->max_phys_ascent
+ it
->max_phys_descent
);
18914 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18915 it
->max_extra_line_spacing
);
18916 x
+= glyph
->pixel_width
;
18920 /* Stop if max_x reached. */
18924 /* Stop at line ends. */
18925 if (ITERATOR_AT_END_OF_LINE_P (it
))
18927 it
->continuation_lines_width
= 0;
18931 set_iterator_to_next (it
, 1);
18933 /* Stop if truncating at the right edge. */
18934 if (it
->line_wrap
== TRUNCATE
18935 && it
->current_x
>= it
->last_visible_x
)
18937 /* Add truncation mark, but don't do it if the line is
18938 truncated at a padding space. */
18939 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18941 if (!FRAME_WINDOW_P (it
->f
))
18945 if (it
->current_x
> it
->last_visible_x
)
18947 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18948 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18950 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18952 row
->used
[TEXT_AREA
] = i
;
18953 produce_special_glyphs (it
, IT_TRUNCATION
);
18956 produce_special_glyphs (it
, IT_TRUNCATION
);
18958 it
->glyph_row
->truncated_on_right_p
= 1;
18964 /* Maybe insert a truncation at the left. */
18965 if (it
->first_visible_x
18966 && IT_CHARPOS (*it
) > 0)
18968 if (!FRAME_WINDOW_P (it
->f
))
18969 insert_left_trunc_glyphs (it
);
18970 it
->glyph_row
->truncated_on_left_p
= 1;
18973 it
->face_id
= saved_face_id
;
18975 /* Value is number of columns displayed. */
18976 return it
->hpos
- hpos_at_start
;
18981 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18982 appears as an element of LIST or as the car of an element of LIST.
18983 If PROPVAL is a list, compare each element against LIST in that
18984 way, and return 1/2 if any element of PROPVAL is found in LIST.
18985 Otherwise return 0. This function cannot quit.
18986 The return value is 2 if the text is invisible but with an ellipsis
18987 and 1 if it's invisible and without an ellipsis. */
18990 invisible_p (propval
, list
)
18991 register Lisp_Object propval
;
18994 register Lisp_Object tail
, proptail
;
18996 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18998 register Lisp_Object tem
;
19000 if (EQ (propval
, tem
))
19002 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19003 return NILP (XCDR (tem
)) ? 1 : 2;
19006 if (CONSP (propval
))
19008 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19010 Lisp_Object propelt
;
19011 propelt
= XCAR (proptail
);
19012 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19014 register Lisp_Object tem
;
19016 if (EQ (propelt
, tem
))
19018 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19019 return NILP (XCDR (tem
)) ? 1 : 2;
19027 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19028 doc
: /* Non-nil if the property makes the text invisible.
19029 POS-OR-PROP can be a marker or number, in which case it is taken to be
19030 a position in the current buffer and the value of the `invisible' property
19031 is checked; or it can be some other value, which is then presumed to be the
19032 value of the `invisible' property of the text of interest.
19033 The non-nil value returned can be t for truly invisible text or something
19034 else if the text is replaced by an ellipsis. */)
19036 Lisp_Object pos_or_prop
;
19039 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19040 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19042 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19043 return (invis
== 0 ? Qnil
19045 : make_number (invis
));
19048 /* Calculate a width or height in pixels from a specification using
19049 the following elements:
19052 NUM - a (fractional) multiple of the default font width/height
19053 (NUM) - specifies exactly NUM pixels
19054 UNIT - a fixed number of pixels, see below.
19055 ELEMENT - size of a display element in pixels, see below.
19056 (NUM . SPEC) - equals NUM * SPEC
19057 (+ SPEC SPEC ...) - add pixel values
19058 (- SPEC SPEC ...) - subtract pixel values
19059 (- SPEC) - negate pixel value
19062 INT or FLOAT - a number constant
19063 SYMBOL - use symbol's (buffer local) variable binding.
19066 in - pixels per inch *)
19067 mm - pixels per 1/1000 meter *)
19068 cm - pixels per 1/100 meter *)
19069 width - width of current font in pixels.
19070 height - height of current font in pixels.
19072 *) using the ratio(s) defined in display-pixels-per-inch.
19076 left-fringe - left fringe width in pixels
19077 right-fringe - right fringe width in pixels
19079 left-margin - left margin width in pixels
19080 right-margin - right margin width in pixels
19082 scroll-bar - scroll-bar area width in pixels
19086 Pixels corresponding to 5 inches:
19089 Total width of non-text areas on left side of window (if scroll-bar is on left):
19090 '(space :width (+ left-fringe left-margin scroll-bar))
19092 Align to first text column (in header line):
19093 '(space :align-to 0)
19095 Align to middle of text area minus half the width of variable `my-image'
19096 containing a loaded image:
19097 '(space :align-to (0.5 . (- text my-image)))
19099 Width of left margin minus width of 1 character in the default font:
19100 '(space :width (- left-margin 1))
19102 Width of left margin minus width of 2 characters in the current font:
19103 '(space :width (- left-margin (2 . width)))
19105 Center 1 character over left-margin (in header line):
19106 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19108 Different ways to express width of left fringe plus left margin minus one pixel:
19109 '(space :width (- (+ left-fringe left-margin) (1)))
19110 '(space :width (+ left-fringe left-margin (- (1))))
19111 '(space :width (+ left-fringe left-margin (-1)))
19115 #define NUMVAL(X) \
19116 ((INTEGERP (X) || FLOATP (X)) \
19121 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19126 int width_p
, *align_to
;
19130 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19131 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19134 return OK_PIXELS (0);
19136 xassert (FRAME_LIVE_P (it
->f
));
19138 if (SYMBOLP (prop
))
19140 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19142 char *unit
= SDATA (SYMBOL_NAME (prop
));
19144 if (unit
[0] == 'i' && unit
[1] == 'n')
19146 else if (unit
[0] == 'm' && unit
[1] == 'm')
19148 else if (unit
[0] == 'c' && unit
[1] == 'm')
19155 #ifdef HAVE_WINDOW_SYSTEM
19156 if (FRAME_WINDOW_P (it
->f
)
19158 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19159 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19161 return OK_PIXELS (ppi
/ pixels
);
19164 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19165 || (CONSP (Vdisplay_pixels_per_inch
)
19167 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19168 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19170 return OK_PIXELS (ppi
/ pixels
);
19176 #ifdef HAVE_WINDOW_SYSTEM
19177 if (EQ (prop
, Qheight
))
19178 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19179 if (EQ (prop
, Qwidth
))
19180 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19182 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19183 return OK_PIXELS (1);
19186 if (EQ (prop
, Qtext
))
19187 return OK_PIXELS (width_p
19188 ? window_box_width (it
->w
, TEXT_AREA
)
19189 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19191 if (align_to
&& *align_to
< 0)
19194 if (EQ (prop
, Qleft
))
19195 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19196 if (EQ (prop
, Qright
))
19197 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19198 if (EQ (prop
, Qcenter
))
19199 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19200 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19201 if (EQ (prop
, Qleft_fringe
))
19202 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19203 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19204 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19205 if (EQ (prop
, Qright_fringe
))
19206 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19207 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19208 : window_box_right_offset (it
->w
, TEXT_AREA
));
19209 if (EQ (prop
, Qleft_margin
))
19210 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19211 if (EQ (prop
, Qright_margin
))
19212 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19213 if (EQ (prop
, Qscroll_bar
))
19214 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19216 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19217 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19218 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19223 if (EQ (prop
, Qleft_fringe
))
19224 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19225 if (EQ (prop
, Qright_fringe
))
19226 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19227 if (EQ (prop
, Qleft_margin
))
19228 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19229 if (EQ (prop
, Qright_margin
))
19230 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19231 if (EQ (prop
, Qscroll_bar
))
19232 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19235 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19238 if (INTEGERP (prop
) || FLOATP (prop
))
19240 int base_unit
= (width_p
19241 ? FRAME_COLUMN_WIDTH (it
->f
)
19242 : FRAME_LINE_HEIGHT (it
->f
));
19243 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19248 Lisp_Object car
= XCAR (prop
);
19249 Lisp_Object cdr
= XCDR (prop
);
19253 #ifdef HAVE_WINDOW_SYSTEM
19254 if (FRAME_WINDOW_P (it
->f
)
19255 && valid_image_p (prop
))
19257 int id
= lookup_image (it
->f
, prop
);
19258 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19260 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19263 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19269 while (CONSP (cdr
))
19271 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19272 font
, width_p
, align_to
))
19275 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19280 if (EQ (car
, Qminus
))
19282 return OK_PIXELS (pixels
);
19285 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19288 if (INTEGERP (car
) || FLOATP (car
))
19291 pixels
= XFLOATINT (car
);
19293 return OK_PIXELS (pixels
);
19294 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19295 font
, width_p
, align_to
))
19296 return OK_PIXELS (pixels
* fact
);
19307 /***********************************************************************
19309 ***********************************************************************/
19311 #ifdef HAVE_WINDOW_SYSTEM
19316 dump_glyph_string (s
)
19317 struct glyph_string
*s
;
19319 fprintf (stderr
, "glyph string\n");
19320 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19321 s
->x
, s
->y
, s
->width
, s
->height
);
19322 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19323 fprintf (stderr
, " hl = %d\n", s
->hl
);
19324 fprintf (stderr
, " left overhang = %d, right = %d\n",
19325 s
->left_overhang
, s
->right_overhang
);
19326 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19327 fprintf (stderr
, " extends to end of line = %d\n",
19328 s
->extends_to_end_of_line_p
);
19329 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19330 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19333 #endif /* GLYPH_DEBUG */
19335 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19336 of XChar2b structures for S; it can't be allocated in
19337 init_glyph_string because it must be allocated via `alloca'. W
19338 is the window on which S is drawn. ROW and AREA are the glyph row
19339 and area within the row from which S is constructed. START is the
19340 index of the first glyph structure covered by S. HL is a
19341 face-override for drawing S. */
19344 #define OPTIONAL_HDC(hdc) hdc,
19345 #define DECLARE_HDC(hdc) HDC hdc;
19346 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19347 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19350 #ifndef OPTIONAL_HDC
19351 #define OPTIONAL_HDC(hdc)
19352 #define DECLARE_HDC(hdc)
19353 #define ALLOCATE_HDC(hdc, f)
19354 #define RELEASE_HDC(hdc, f)
19358 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19359 struct glyph_string
*s
;
19363 struct glyph_row
*row
;
19364 enum glyph_row_area area
;
19366 enum draw_glyphs_face hl
;
19368 bzero (s
, sizeof *s
);
19370 s
->f
= XFRAME (w
->frame
);
19374 s
->display
= FRAME_X_DISPLAY (s
->f
);
19375 s
->window
= FRAME_X_WINDOW (s
->f
);
19376 s
->char2b
= char2b
;
19380 s
->first_glyph
= row
->glyphs
[area
] + start
;
19381 s
->height
= row
->height
;
19382 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19384 /* Display the internal border below the tool-bar window. */
19385 if (WINDOWP (s
->f
->tool_bar_window
)
19386 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19387 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19389 s
->ybase
= s
->y
+ row
->ascent
;
19393 /* Append the list of glyph strings with head H and tail T to the list
19394 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19397 append_glyph_string_lists (head
, tail
, h
, t
)
19398 struct glyph_string
**head
, **tail
;
19399 struct glyph_string
*h
, *t
;
19413 /* Prepend the list of glyph strings with head H and tail T to the
19414 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19418 prepend_glyph_string_lists (head
, tail
, h
, t
)
19419 struct glyph_string
**head
, **tail
;
19420 struct glyph_string
*h
, *t
;
19434 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19435 Set *HEAD and *TAIL to the resulting list. */
19438 append_glyph_string (head
, tail
, s
)
19439 struct glyph_string
**head
, **tail
;
19440 struct glyph_string
*s
;
19442 s
->next
= s
->prev
= NULL
;
19443 append_glyph_string_lists (head
, tail
, s
, s
);
19447 /* Get face and two-byte form of character C in face FACE_ID on frame
19448 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19449 means we want to display multibyte text. DISPLAY_P non-zero means
19450 make sure that X resources for the face returned are allocated.
19451 Value is a pointer to a realized face that is ready for display if
19452 DISPLAY_P is non-zero. */
19454 static INLINE
struct face
*
19455 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19459 int multibyte_p
, display_p
;
19461 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19465 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19467 if (code
!= FONT_INVALID_CODE
)
19468 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19470 STORE_XCHAR2B (char2b
, 0, 0);
19473 /* Make sure X resources of the face are allocated. */
19474 #ifdef HAVE_X_WINDOWS
19478 xassert (face
!= NULL
);
19479 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19486 /* Get face and two-byte form of character glyph GLYPH on frame F.
19487 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19488 a pointer to a realized face that is ready for display. */
19490 static INLINE
struct face
*
19491 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19493 struct glyph
*glyph
;
19499 xassert (glyph
->type
== CHAR_GLYPH
);
19500 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19507 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19509 if (code
!= FONT_INVALID_CODE
)
19510 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19512 STORE_XCHAR2B (char2b
, 0, 0);
19515 /* Make sure X resources of the face are allocated. */
19516 xassert (face
!= NULL
);
19517 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19522 /* Fill glyph string S with composition components specified by S->cmp.
19524 BASE_FACE is the base face of the composition.
19525 S->gidx is the index of the first component for S.
19527 OVERLAPS non-zero means S should draw the foreground only, and use
19528 its physical height for clipping. See also draw_glyphs.
19530 Value is the index of a component not in S. */
19533 fill_composite_glyph_string (s
, base_face
, overlaps
)
19534 struct glyph_string
*s
;
19535 struct face
*base_face
;
19542 s
->for_overlaps
= overlaps
;
19544 if (s
->cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
19546 Lisp_Object gstring
19547 = AREF (XHASH_TABLE (composition_hash_table
)->key_and_value
,
19548 s
->cmp
->hash_index
* 2);
19550 s
->face
= base_face
;
19551 s
->font
= base_face
->font
;
19552 for (i
= 0, s
->nchars
= 0; i
< s
->cmp
->glyph_len
; i
++, s
->nchars
++)
19554 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
19556 XChar2b
* store_pos
;
19559 code
= LGLYPH_CODE (g
);
19560 store_pos
= s
->char2b
+ i
;
19561 STORE_XCHAR2B (store_pos
, code
>> 8, code
& 0xFF);
19563 s
->width
= s
->cmp
->pixel_width
;
19567 /* For all glyphs of this composition, starting at the offset
19568 S->gidx, until we reach the end of the definition or encounter a
19569 glyph that requires the different face, add it to S. */
19574 for (i
= s
->gidx
; i
< s
->cmp
->glyph_len
; i
++)
19576 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19580 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19583 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19584 s
->char2b
+ i
, 1, 1);
19590 s
->font
= s
->face
->font
;
19592 else if (s
->face
!= face
)
19599 /* All glyph strings for the same composition has the same width,
19600 i.e. the width set for the first component of the composition. */
19601 s
->width
= s
->first_glyph
->pixel_width
;
19604 /* If the specified font could not be loaded, use the frame's
19605 default font, but record the fact that we couldn't load it in
19606 the glyph string so that we can draw rectangles for the
19607 characters of the glyph string. */
19608 if (s
->font
== NULL
)
19610 s
->font_not_found_p
= 1;
19611 s
->font
= FRAME_FONT (s
->f
);
19614 /* Adjust base line for subscript/superscript text. */
19615 s
->ybase
+= s
->first_glyph
->voffset
;
19617 /* This glyph string must always be drawn with 16-bit functions. */
19620 return s
->gidx
+ s
->nchars
;
19624 /* Fill glyph string S from a sequence of character glyphs.
19626 FACE_ID is the face id of the string. START is the index of the
19627 first glyph to consider, END is the index of the last + 1.
19628 OVERLAPS non-zero means S should draw the foreground only, and use
19629 its physical height for clipping. See also draw_glyphs.
19631 Value is the index of the first glyph not in S. */
19634 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19635 struct glyph_string
*s
;
19637 int start
, end
, overlaps
;
19639 struct glyph
*glyph
, *last
;
19641 int glyph_not_available_p
;
19643 xassert (s
->f
== XFRAME (s
->w
->frame
));
19644 xassert (s
->nchars
== 0);
19645 xassert (start
>= 0 && end
> start
);
19647 s
->for_overlaps
= overlaps
,
19648 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19649 last
= s
->row
->glyphs
[s
->area
] + end
;
19650 voffset
= glyph
->voffset
;
19651 s
->padding_p
= glyph
->padding_p
;
19652 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19654 while (glyph
< last
19655 && glyph
->type
== CHAR_GLYPH
19656 && glyph
->voffset
== voffset
19657 /* Same face id implies same font, nowadays. */
19658 && glyph
->face_id
== face_id
19659 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19663 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19664 s
->char2b
+ s
->nchars
,
19666 s
->two_byte_p
= two_byte_p
;
19668 xassert (s
->nchars
<= end
- start
);
19669 s
->width
+= glyph
->pixel_width
;
19670 if (glyph
++->padding_p
!= s
->padding_p
)
19674 s
->font
= s
->face
->font
;
19676 /* If the specified font could not be loaded, use the frame's font,
19677 but record the fact that we couldn't load it in
19678 S->font_not_found_p so that we can draw rectangles for the
19679 characters of the glyph string. */
19680 if (s
->font
== NULL
|| glyph_not_available_p
)
19682 s
->font_not_found_p
= 1;
19683 s
->font
= FRAME_FONT (s
->f
);
19686 /* Adjust base line for subscript/superscript text. */
19687 s
->ybase
+= voffset
;
19689 xassert (s
->face
&& s
->face
->gc
);
19690 return glyph
- s
->row
->glyphs
[s
->area
];
19694 /* Fill glyph string S from image glyph S->first_glyph. */
19697 fill_image_glyph_string (s
)
19698 struct glyph_string
*s
;
19700 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19701 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19703 s
->slice
= s
->first_glyph
->slice
;
19704 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19705 s
->font
= s
->face
->font
;
19706 s
->width
= s
->first_glyph
->pixel_width
;
19708 /* Adjust base line for subscript/superscript text. */
19709 s
->ybase
+= s
->first_glyph
->voffset
;
19713 /* Fill glyph string S from a sequence of stretch glyphs.
19715 ROW is the glyph row in which the glyphs are found, AREA is the
19716 area within the row. START is the index of the first glyph to
19717 consider, END is the index of the last + 1.
19719 Value is the index of the first glyph not in S. */
19722 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19723 struct glyph_string
*s
;
19724 struct glyph_row
*row
;
19725 enum glyph_row_area area
;
19728 struct glyph
*glyph
, *last
;
19729 int voffset
, face_id
;
19731 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19733 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19734 last
= s
->row
->glyphs
[s
->area
] + end
;
19735 face_id
= glyph
->face_id
;
19736 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19737 s
->font
= s
->face
->font
;
19738 s
->width
= glyph
->pixel_width
;
19740 voffset
= glyph
->voffset
;
19744 && glyph
->type
== STRETCH_GLYPH
19745 && glyph
->voffset
== voffset
19746 && glyph
->face_id
== face_id
);
19748 s
->width
+= glyph
->pixel_width
;
19750 /* Adjust base line for subscript/superscript text. */
19751 s
->ybase
+= voffset
;
19753 /* The case that face->gc == 0 is handled when drawing the glyph
19754 string by calling PREPARE_FACE_FOR_DISPLAY. */
19756 return glyph
- s
->row
->glyphs
[s
->area
];
19759 static struct font_metrics
*
19760 get_per_char_metric (f
, font
, char2b
)
19765 static struct font_metrics metrics
;
19766 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19767 struct font
*fontp
;
19769 if (! font
|| code
== FONT_INVALID_CODE
)
19771 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19776 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19777 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19778 assumed to be zero. */
19781 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19782 struct glyph
*glyph
;
19786 *left
= *right
= 0;
19788 if (glyph
->type
== CHAR_GLYPH
)
19792 struct font_metrics
*pcm
;
19794 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19795 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19797 if (pcm
->rbearing
> pcm
->width
)
19798 *right
= pcm
->rbearing
- pcm
->width
;
19799 if (pcm
->lbearing
< 0)
19800 *left
= -pcm
->lbearing
;
19803 else if (glyph
->type
== COMPOSITE_GLYPH
)
19805 struct composition
*cmp
= composition_table
[glyph
->u
.cmp_id
];
19807 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19808 *left
= - cmp
->lbearing
;
19813 /* Return the index of the first glyph preceding glyph string S that
19814 is overwritten by S because of S's left overhang. Value is -1
19815 if no glyphs are overwritten. */
19818 left_overwritten (s
)
19819 struct glyph_string
*s
;
19823 if (s
->left_overhang
)
19826 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19827 int first
= s
->first_glyph
- glyphs
;
19829 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19830 x
-= glyphs
[i
].pixel_width
;
19841 /* Return the index of the first glyph preceding glyph string S that
19842 is overwriting S because of its right overhang. Value is -1 if no
19843 glyph in front of S overwrites S. */
19846 left_overwriting (s
)
19847 struct glyph_string
*s
;
19850 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19851 int first
= s
->first_glyph
- glyphs
;
19855 for (i
= first
- 1; i
>= 0; --i
)
19858 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19861 x
-= glyphs
[i
].pixel_width
;
19868 /* Return the index of the last glyph following glyph string S that is
19869 not overwritten by S because of S's right overhang. Value is -1 if
19870 no such glyph is found. */
19873 right_overwritten (s
)
19874 struct glyph_string
*s
;
19878 if (s
->right_overhang
)
19881 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19882 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19883 int end
= s
->row
->used
[s
->area
];
19885 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19886 x
+= glyphs
[i
].pixel_width
;
19895 /* Return the index of the last glyph following glyph string S that
19896 overwrites S because of its left overhang. Value is negative
19897 if no such glyph is found. */
19900 right_overwriting (s
)
19901 struct glyph_string
*s
;
19904 int end
= s
->row
->used
[s
->area
];
19905 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19906 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19910 for (i
= first
; i
< end
; ++i
)
19913 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19916 x
+= glyphs
[i
].pixel_width
;
19923 /* Set background width of glyph string S. START is the index of the
19924 first glyph following S. LAST_X is the right-most x-position + 1
19925 in the drawing area. */
19928 set_glyph_string_background_width (s
, start
, last_x
)
19929 struct glyph_string
*s
;
19933 /* If the face of this glyph string has to be drawn to the end of
19934 the drawing area, set S->extends_to_end_of_line_p. */
19936 if (start
== s
->row
->used
[s
->area
]
19937 && s
->area
== TEXT_AREA
19938 && ((s
->row
->fill_line_p
19939 && (s
->hl
== DRAW_NORMAL_TEXT
19940 || s
->hl
== DRAW_IMAGE_RAISED
19941 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19942 || s
->hl
== DRAW_MOUSE_FACE
))
19943 s
->extends_to_end_of_line_p
= 1;
19945 /* If S extends its face to the end of the line, set its
19946 background_width to the distance to the right edge of the drawing
19948 if (s
->extends_to_end_of_line_p
)
19949 s
->background_width
= last_x
- s
->x
+ 1;
19951 s
->background_width
= s
->width
;
19955 /* Compute overhangs and x-positions for glyph string S and its
19956 predecessors, or successors. X is the starting x-position for S.
19957 BACKWARD_P non-zero means process predecessors. */
19960 compute_overhangs_and_x (s
, x
, backward_p
)
19961 struct glyph_string
*s
;
19969 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19970 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19980 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19981 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19991 /* The following macros are only called from draw_glyphs below.
19992 They reference the following parameters of that function directly:
19993 `w', `row', `area', and `overlap_p'
19994 as well as the following local variables:
19995 `s', `f', and `hdc' (in W32) */
19998 /* On W32, silently add local `hdc' variable to argument list of
19999 init_glyph_string. */
20000 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20001 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20003 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20004 init_glyph_string (s, char2b, w, row, area, start, hl)
20007 /* Add a glyph string for a stretch glyph to the list of strings
20008 between HEAD and TAIL. START is the index of the stretch glyph in
20009 row area AREA of glyph row ROW. END is the index of the last glyph
20010 in that glyph row area. X is the current output position assigned
20011 to the new glyph string constructed. HL overrides that face of the
20012 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20013 is the right-most x-position of the drawing area. */
20015 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20016 and below -- keep them on one line. */
20017 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20020 s = (struct glyph_string *) alloca (sizeof *s); \
20021 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20022 START = fill_stretch_glyph_string (s, row, area, START, END); \
20023 append_glyph_string (&HEAD, &TAIL, s); \
20029 /* Add a glyph string for an image glyph to the list of strings
20030 between HEAD and TAIL. START is the index of the image glyph in
20031 row area AREA of glyph row ROW. END is the index of the last glyph
20032 in that glyph row area. X is the current output position assigned
20033 to the new glyph string constructed. HL overrides that face of the
20034 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20035 is the right-most x-position of the drawing area. */
20037 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20040 s = (struct glyph_string *) alloca (sizeof *s); \
20041 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20042 fill_image_glyph_string (s); \
20043 append_glyph_string (&HEAD, &TAIL, s); \
20050 /* Add a glyph string for a sequence of character glyphs to the list
20051 of strings between HEAD and TAIL. START is the index of the first
20052 glyph in row area AREA of glyph row ROW that is part of the new
20053 glyph string. END is the index of the last glyph in that glyph row
20054 area. X is the current output position assigned to the new glyph
20055 string constructed. HL overrides that face of the glyph; e.g. it
20056 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20057 right-most x-position of the drawing area. */
20059 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20065 face_id = (row)->glyphs[area][START].face_id; \
20067 s = (struct glyph_string *) alloca (sizeof *s); \
20068 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20069 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20070 append_glyph_string (&HEAD, &TAIL, s); \
20072 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20077 /* Add a glyph string for a composite sequence to the list of strings
20078 between HEAD and TAIL. START is the index of the first glyph in
20079 row area AREA of glyph row ROW that is part of the new glyph
20080 string. END is the index of the last glyph in that glyph row area.
20081 X is the current output position assigned to the new glyph string
20082 constructed. HL overrides that face of the glyph; e.g. it is
20083 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20084 x-position of the drawing area. */
20086 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20088 int face_id = (row)->glyphs[area][START].face_id; \
20089 struct face *base_face = FACE_FROM_ID (f, face_id); \
20090 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
20091 struct composition *cmp = composition_table[cmp_id]; \
20093 struct glyph_string *first_s; \
20096 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20098 /* Make glyph_strings for each glyph sequence that is drawable by \
20099 the same face, and append them to HEAD/TAIL. */ \
20100 for (n = 0; n < cmp->glyph_len;) \
20102 s = (struct glyph_string *) alloca (sizeof *s); \
20103 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20104 append_glyph_string (&(HEAD), &(TAIL), s); \
20110 n = fill_composite_glyph_string (s, base_face, overlaps); \
20118 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20119 of AREA of glyph row ROW on window W between indices START and END.
20120 HL overrides the face for drawing glyph strings, e.g. it is
20121 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20122 x-positions of the drawing area.
20124 This is an ugly monster macro construct because we must use alloca
20125 to allocate glyph strings (because draw_glyphs can be called
20126 asynchronously). */
20128 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20131 HEAD = TAIL = NULL; \
20132 while (START < END) \
20134 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20135 switch (first_glyph->type) \
20138 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20142 case COMPOSITE_GLYPH: \
20143 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20147 case STRETCH_GLYPH: \
20148 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20152 case IMAGE_GLYPH: \
20153 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20163 set_glyph_string_background_width (s, START, LAST_X); \
20171 /* Draw glyphs between START and END in AREA of ROW on window W,
20172 starting at x-position X. X is relative to AREA in W. HL is a
20173 face-override with the following meaning:
20175 DRAW_NORMAL_TEXT draw normally
20176 DRAW_CURSOR draw in cursor face
20177 DRAW_MOUSE_FACE draw in mouse face.
20178 DRAW_INVERSE_VIDEO draw in mode line face
20179 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20180 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20182 If OVERLAPS is non-zero, draw only the foreground of characters and
20183 clip to the physical height of ROW. Non-zero value also defines
20184 the overlapping part to be drawn:
20186 OVERLAPS_PRED overlap with preceding rows
20187 OVERLAPS_SUCC overlap with succeeding rows
20188 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20189 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20191 Value is the x-position reached, relative to AREA of W. */
20194 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20197 struct glyph_row
*row
;
20198 enum glyph_row_area area
;
20199 EMACS_INT start
, end
;
20200 enum draw_glyphs_face hl
;
20203 struct glyph_string
*head
, *tail
;
20204 struct glyph_string
*s
;
20205 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20206 int i
, j
, x_reached
, last_x
, area_left
= 0;
20207 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20210 ALLOCATE_HDC (hdc
, f
);
20212 /* Let's rather be paranoid than getting a SEGV. */
20213 end
= min (end
, row
->used
[area
]);
20214 start
= max (0, start
);
20215 start
= min (end
, start
);
20217 /* Translate X to frame coordinates. Set last_x to the right
20218 end of the drawing area. */
20219 if (row
->full_width_p
)
20221 /* X is relative to the left edge of W, without scroll bars
20223 area_left
= WINDOW_LEFT_EDGE_X (w
);
20224 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20228 area_left
= window_box_left (w
, area
);
20229 last_x
= area_left
+ window_box_width (w
, area
);
20233 /* Build a doubly-linked list of glyph_string structures between
20234 head and tail from what we have to draw. Note that the macro
20235 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20236 the reason we use a separate variable `i'. */
20238 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20240 x_reached
= tail
->x
+ tail
->background_width
;
20244 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20245 the row, redraw some glyphs in front or following the glyph
20246 strings built above. */
20247 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20249 struct glyph_string
*h
, *t
;
20250 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20251 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20254 /* If mouse highlighting is on, we may need to draw adjacent
20255 glyphs using mouse-face highlighting. */
20256 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20258 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20260 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20261 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20263 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20265 check_mouse_face
= 1;
20266 mouse_beg_col
= (row
== mouse_beg_row
)
20267 ? dpyinfo
->mouse_face_beg_col
: 0;
20268 mouse_end_col
= (row
== mouse_end_row
)
20269 ? dpyinfo
->mouse_face_end_col
20270 : row
->used
[TEXT_AREA
];
20274 /* Compute overhangs for all glyph strings. */
20275 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20276 for (s
= head
; s
; s
= s
->next
)
20277 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20279 /* Prepend glyph strings for glyphs in front of the first glyph
20280 string that are overwritten because of the first glyph
20281 string's left overhang. The background of all strings
20282 prepended must be drawn because the first glyph string
20284 i
= left_overwritten (head
);
20287 enum draw_glyphs_face overlap_hl
;
20289 /* If this row contains mouse highlighting, attempt to draw
20290 the overlapped glyphs with the correct highlight. This
20291 code fails if the overlap encompasses more than one glyph
20292 and mouse-highlight spans only some of these glyphs.
20293 However, making it work perfectly involves a lot more
20294 code, and I don't know if the pathological case occurs in
20295 practice, so we'll stick to this for now. --- cyd */
20296 if (check_mouse_face
20297 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20298 overlap_hl
= DRAW_MOUSE_FACE
;
20300 overlap_hl
= DRAW_NORMAL_TEXT
;
20303 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20304 overlap_hl
, dummy_x
, last_x
);
20305 compute_overhangs_and_x (t
, head
->x
, 1);
20306 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20310 /* Prepend glyph strings for glyphs in front of the first glyph
20311 string that overwrite that glyph string because of their
20312 right overhang. For these strings, only the foreground must
20313 be drawn, because it draws over the glyph string at `head'.
20314 The background must not be drawn because this would overwrite
20315 right overhangs of preceding glyphs for which no glyph
20317 i
= left_overwriting (head
);
20320 enum draw_glyphs_face overlap_hl
;
20322 if (check_mouse_face
20323 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20324 overlap_hl
= DRAW_MOUSE_FACE
;
20326 overlap_hl
= DRAW_NORMAL_TEXT
;
20329 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20330 overlap_hl
, dummy_x
, last_x
);
20331 for (s
= h
; s
; s
= s
->next
)
20332 s
->background_filled_p
= 1;
20333 compute_overhangs_and_x (t
, head
->x
, 1);
20334 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20337 /* Append glyphs strings for glyphs following the last glyph
20338 string tail that are overwritten by tail. The background of
20339 these strings has to be drawn because tail's foreground draws
20341 i
= right_overwritten (tail
);
20344 enum draw_glyphs_face overlap_hl
;
20346 if (check_mouse_face
20347 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20348 overlap_hl
= DRAW_MOUSE_FACE
;
20350 overlap_hl
= DRAW_NORMAL_TEXT
;
20352 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20353 overlap_hl
, x
, last_x
);
20354 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20355 append_glyph_string_lists (&head
, &tail
, h
, t
);
20359 /* Append glyph strings for glyphs following the last glyph
20360 string tail that overwrite tail. The foreground of such
20361 glyphs has to be drawn because it writes into the background
20362 of tail. The background must not be drawn because it could
20363 paint over the foreground of following glyphs. */
20364 i
= right_overwriting (tail
);
20367 enum draw_glyphs_face overlap_hl
;
20368 if (check_mouse_face
20369 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20370 overlap_hl
= DRAW_MOUSE_FACE
;
20372 overlap_hl
= DRAW_NORMAL_TEXT
;
20375 i
++; /* We must include the Ith glyph. */
20376 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20377 overlap_hl
, x
, last_x
);
20378 for (s
= h
; s
; s
= s
->next
)
20379 s
->background_filled_p
= 1;
20380 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20381 append_glyph_string_lists (&head
, &tail
, h
, t
);
20383 if (clip_head
|| clip_tail
)
20384 for (s
= head
; s
; s
= s
->next
)
20386 s
->clip_head
= clip_head
;
20387 s
->clip_tail
= clip_tail
;
20391 /* Draw all strings. */
20392 for (s
= head
; s
; s
= s
->next
)
20393 FRAME_RIF (f
)->draw_glyph_string (s
);
20395 if (area
== TEXT_AREA
20396 && !row
->full_width_p
20397 /* When drawing overlapping rows, only the glyph strings'
20398 foreground is drawn, which doesn't erase a cursor
20402 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20403 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20404 : (tail
? tail
->x
+ tail
->background_width
: x
));
20408 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20409 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20412 /* Value is the x-position up to which drawn, relative to AREA of W.
20413 This doesn't include parts drawn because of overhangs. */
20414 if (row
->full_width_p
)
20415 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20417 x_reached
-= area_left
;
20419 RELEASE_HDC (hdc
, f
);
20424 /* Expand row matrix if too narrow. Don't expand if area
20427 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20429 if (!fonts_changed_p \
20430 && (it->glyph_row->glyphs[area] \
20431 < it->glyph_row->glyphs[area + 1])) \
20433 it->w->ncols_scale_factor++; \
20434 fonts_changed_p = 1; \
20438 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20439 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20445 struct glyph
*glyph
;
20446 enum glyph_row_area area
= it
->area
;
20448 xassert (it
->glyph_row
);
20449 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20451 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20452 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20454 glyph
->charpos
= CHARPOS (it
->position
);
20455 glyph
->object
= it
->object
;
20456 if (it
->pixel_width
> 0)
20458 glyph
->pixel_width
= it
->pixel_width
;
20459 glyph
->padding_p
= 0;
20463 /* Assure at least 1-pixel width. Otherwise, cursor can't
20464 be displayed correctly. */
20465 glyph
->pixel_width
= 1;
20466 glyph
->padding_p
= 1;
20468 glyph
->ascent
= it
->ascent
;
20469 glyph
->descent
= it
->descent
;
20470 glyph
->voffset
= it
->voffset
;
20471 glyph
->type
= CHAR_GLYPH
;
20472 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20473 glyph
->multibyte_p
= it
->multibyte_p
;
20474 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20475 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20476 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20477 || it
->phys_descent
> it
->descent
);
20478 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20479 glyph
->face_id
= it
->face_id
;
20480 glyph
->u
.ch
= it
->char_to_display
;
20481 glyph
->slice
= null_glyph_slice
;
20482 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20483 ++it
->glyph_row
->used
[area
];
20486 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20489 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
20490 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20493 append_composite_glyph (it
)
20496 struct glyph
*glyph
;
20497 enum glyph_row_area area
= it
->area
;
20499 xassert (it
->glyph_row
);
20501 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20502 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20504 glyph
->charpos
= CHARPOS (it
->position
);
20505 glyph
->object
= it
->object
;
20506 glyph
->pixel_width
= it
->pixel_width
;
20507 glyph
->ascent
= it
->ascent
;
20508 glyph
->descent
= it
->descent
;
20509 glyph
->voffset
= it
->voffset
;
20510 glyph
->type
= COMPOSITE_GLYPH
;
20511 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20512 glyph
->multibyte_p
= it
->multibyte_p
;
20513 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20514 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20515 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20516 || it
->phys_descent
> it
->descent
);
20517 glyph
->padding_p
= 0;
20518 glyph
->glyph_not_available_p
= 0;
20519 glyph
->face_id
= it
->face_id
;
20520 glyph
->u
.cmp_id
= it
->cmp_id
;
20521 glyph
->slice
= null_glyph_slice
;
20522 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20523 ++it
->glyph_row
->used
[area
];
20526 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20530 /* Change IT->ascent and IT->height according to the setting of
20534 take_vertical_position_into_account (it
)
20539 if (it
->voffset
< 0)
20540 /* Increase the ascent so that we can display the text higher
20542 it
->ascent
-= it
->voffset
;
20544 /* Increase the descent so that we can display the text lower
20546 it
->descent
+= it
->voffset
;
20551 /* Produce glyphs/get display metrics for the image IT is loaded with.
20552 See the description of struct display_iterator in dispextern.h for
20553 an overview of struct display_iterator. */
20556 produce_image_glyph (it
)
20561 int glyph_ascent
, crop
;
20562 struct glyph_slice slice
;
20564 xassert (it
->what
== IT_IMAGE
);
20566 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20568 /* Make sure X resources of the face is loaded. */
20569 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20571 if (it
->image_id
< 0)
20573 /* Fringe bitmap. */
20574 it
->ascent
= it
->phys_ascent
= 0;
20575 it
->descent
= it
->phys_descent
= 0;
20576 it
->pixel_width
= 0;
20581 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20583 /* Make sure X resources of the image is loaded. */
20584 prepare_image_for_display (it
->f
, img
);
20586 slice
.x
= slice
.y
= 0;
20587 slice
.width
= img
->width
;
20588 slice
.height
= img
->height
;
20590 if (INTEGERP (it
->slice
.x
))
20591 slice
.x
= XINT (it
->slice
.x
);
20592 else if (FLOATP (it
->slice
.x
))
20593 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20595 if (INTEGERP (it
->slice
.y
))
20596 slice
.y
= XINT (it
->slice
.y
);
20597 else if (FLOATP (it
->slice
.y
))
20598 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20600 if (INTEGERP (it
->slice
.width
))
20601 slice
.width
= XINT (it
->slice
.width
);
20602 else if (FLOATP (it
->slice
.width
))
20603 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20605 if (INTEGERP (it
->slice
.height
))
20606 slice
.height
= XINT (it
->slice
.height
);
20607 else if (FLOATP (it
->slice
.height
))
20608 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20610 if (slice
.x
>= img
->width
)
20611 slice
.x
= img
->width
;
20612 if (slice
.y
>= img
->height
)
20613 slice
.y
= img
->height
;
20614 if (slice
.x
+ slice
.width
>= img
->width
)
20615 slice
.width
= img
->width
- slice
.x
;
20616 if (slice
.y
+ slice
.height
> img
->height
)
20617 slice
.height
= img
->height
- slice
.y
;
20619 if (slice
.width
== 0 || slice
.height
== 0)
20622 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20624 it
->descent
= slice
.height
- glyph_ascent
;
20626 it
->descent
+= img
->vmargin
;
20627 if (slice
.y
+ slice
.height
== img
->height
)
20628 it
->descent
+= img
->vmargin
;
20629 it
->phys_descent
= it
->descent
;
20631 it
->pixel_width
= slice
.width
;
20633 it
->pixel_width
+= img
->hmargin
;
20634 if (slice
.x
+ slice
.width
== img
->width
)
20635 it
->pixel_width
+= img
->hmargin
;
20637 /* It's quite possible for images to have an ascent greater than
20638 their height, so don't get confused in that case. */
20639 if (it
->descent
< 0)
20642 #if 0 /* this breaks image tiling */
20643 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
20644 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
20645 if (face_ascent
> it
->ascent
)
20646 it
->ascent
= it
->phys_ascent
= face_ascent
;
20651 if (face
->box
!= FACE_NO_BOX
)
20653 if (face
->box_line_width
> 0)
20656 it
->ascent
+= face
->box_line_width
;
20657 if (slice
.y
+ slice
.height
== img
->height
)
20658 it
->descent
+= face
->box_line_width
;
20661 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20662 it
->pixel_width
+= eabs (face
->box_line_width
);
20663 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20664 it
->pixel_width
+= eabs (face
->box_line_width
);
20667 take_vertical_position_into_account (it
);
20669 /* Automatically crop wide image glyphs at right edge so we can
20670 draw the cursor on same display row. */
20671 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20672 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20674 it
->pixel_width
-= crop
;
20675 slice
.width
-= crop
;
20680 struct glyph
*glyph
;
20681 enum glyph_row_area area
= it
->area
;
20683 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20684 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20686 glyph
->charpos
= CHARPOS (it
->position
);
20687 glyph
->object
= it
->object
;
20688 glyph
->pixel_width
= it
->pixel_width
;
20689 glyph
->ascent
= glyph_ascent
;
20690 glyph
->descent
= it
->descent
;
20691 glyph
->voffset
= it
->voffset
;
20692 glyph
->type
= IMAGE_GLYPH
;
20693 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20694 glyph
->multibyte_p
= it
->multibyte_p
;
20695 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20696 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20697 glyph
->overlaps_vertically_p
= 0;
20698 glyph
->padding_p
= 0;
20699 glyph
->glyph_not_available_p
= 0;
20700 glyph
->face_id
= it
->face_id
;
20701 glyph
->u
.img_id
= img
->id
;
20702 glyph
->slice
= slice
;
20703 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20704 ++it
->glyph_row
->used
[area
];
20707 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20712 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20713 of the glyph, WIDTH and HEIGHT are the width and height of the
20714 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20717 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20719 Lisp_Object object
;
20723 struct glyph
*glyph
;
20724 enum glyph_row_area area
= it
->area
;
20726 xassert (ascent
>= 0 && ascent
<= height
);
20728 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20729 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20731 glyph
->charpos
= CHARPOS (it
->position
);
20732 glyph
->object
= object
;
20733 glyph
->pixel_width
= width
;
20734 glyph
->ascent
= ascent
;
20735 glyph
->descent
= height
- ascent
;
20736 glyph
->voffset
= it
->voffset
;
20737 glyph
->type
= STRETCH_GLYPH
;
20738 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20739 glyph
->multibyte_p
= it
->multibyte_p
;
20740 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20741 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20742 glyph
->overlaps_vertically_p
= 0;
20743 glyph
->padding_p
= 0;
20744 glyph
->glyph_not_available_p
= 0;
20745 glyph
->face_id
= it
->face_id
;
20746 glyph
->u
.stretch
.ascent
= ascent
;
20747 glyph
->u
.stretch
.height
= height
;
20748 glyph
->slice
= null_glyph_slice
;
20749 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20750 ++it
->glyph_row
->used
[area
];
20753 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20757 /* Produce a stretch glyph for iterator IT. IT->object is the value
20758 of the glyph property displayed. The value must be a list
20759 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20762 1. `:width WIDTH' specifies that the space should be WIDTH *
20763 canonical char width wide. WIDTH may be an integer or floating
20766 2. `:relative-width FACTOR' specifies that the width of the stretch
20767 should be computed from the width of the first character having the
20768 `glyph' property, and should be FACTOR times that width.
20770 3. `:align-to HPOS' specifies that the space should be wide enough
20771 to reach HPOS, a value in canonical character units.
20773 Exactly one of the above pairs must be present.
20775 4. `:height HEIGHT' specifies that the height of the stretch produced
20776 should be HEIGHT, measured in canonical character units.
20778 5. `:relative-height FACTOR' specifies that the height of the
20779 stretch should be FACTOR times the height of the characters having
20780 the glyph property.
20782 Either none or exactly one of 4 or 5 must be present.
20784 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20785 of the stretch should be used for the ascent of the stretch.
20786 ASCENT must be in the range 0 <= ASCENT <= 100. */
20789 produce_stretch_glyph (it
)
20792 /* (space :width WIDTH :height HEIGHT ...) */
20793 Lisp_Object prop
, plist
;
20794 int width
= 0, height
= 0, align_to
= -1;
20795 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20798 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20799 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20801 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20803 /* List should start with `space'. */
20804 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20805 plist
= XCDR (it
->object
);
20807 /* Compute the width of the stretch. */
20808 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20809 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20811 /* Absolute width `:width WIDTH' specified and valid. */
20812 zero_width_ok_p
= 1;
20815 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20818 /* Relative width `:relative-width FACTOR' specified and valid.
20819 Compute the width of the characters having the `glyph'
20822 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20825 if (it
->multibyte_p
)
20827 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20828 - IT_BYTEPOS (*it
));
20829 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20832 it2
.c
= *p
, it2
.len
= 1;
20834 it2
.glyph_row
= NULL
;
20835 it2
.what
= IT_CHARACTER
;
20836 x_produce_glyphs (&it2
);
20837 width
= NUMVAL (prop
) * it2
.pixel_width
;
20839 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20840 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20842 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20843 align_to
= (align_to
< 0
20845 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20846 else if (align_to
< 0)
20847 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20848 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20849 zero_width_ok_p
= 1;
20852 /* Nothing specified -> width defaults to canonical char width. */
20853 width
= FRAME_COLUMN_WIDTH (it
->f
);
20855 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20858 /* Compute height. */
20859 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20860 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20863 zero_height_ok_p
= 1;
20865 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20867 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20869 height
= FONT_HEIGHT (font
);
20871 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20874 /* Compute percentage of height used for ascent. If
20875 `:ascent ASCENT' is present and valid, use that. Otherwise,
20876 derive the ascent from the font in use. */
20877 if (prop
= Fplist_get (plist
, QCascent
),
20878 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20879 ascent
= height
* NUMVAL (prop
) / 100.0;
20880 else if (!NILP (prop
)
20881 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20882 ascent
= min (max (0, (int)tem
), height
);
20884 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20886 if (width
> 0 && it
->line_wrap
!= TRUNCATE
20887 && it
->current_x
+ width
> it
->last_visible_x
)
20888 width
= it
->last_visible_x
- it
->current_x
- 1;
20890 if (width
> 0 && height
> 0 && it
->glyph_row
)
20892 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20893 if (!STRINGP (object
))
20894 object
= it
->w
->buffer
;
20895 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20898 it
->pixel_width
= width
;
20899 it
->ascent
= it
->phys_ascent
= ascent
;
20900 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20901 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20903 take_vertical_position_into_account (it
);
20906 /* Calculate line-height and line-spacing properties.
20907 An integer value specifies explicit pixel value.
20908 A float value specifies relative value to current face height.
20909 A cons (float . face-name) specifies relative value to
20910 height of specified face font.
20912 Returns height in pixels, or nil. */
20916 calc_line_height_property (it
, val
, font
, boff
, override
)
20920 int boff
, override
;
20922 Lisp_Object face_name
= Qnil
;
20923 int ascent
, descent
, height
;
20925 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20930 face_name
= XCAR (val
);
20932 if (!NUMBERP (val
))
20933 val
= make_number (1);
20934 if (NILP (face_name
))
20936 height
= it
->ascent
+ it
->descent
;
20941 if (NILP (face_name
))
20943 font
= FRAME_FONT (it
->f
);
20944 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20946 else if (EQ (face_name
, Qt
))
20955 face_id
= lookup_named_face (it
->f
, face_name
, 0);
20957 return make_number (-1);
20959 face
= FACE_FROM_ID (it
->f
, face_id
);
20962 return make_number (-1);
20963 boff
= font
->baseline_offset
;
20964 if (font
->vertical_centering
)
20965 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20968 ascent
= FONT_BASE (font
) + boff
;
20969 descent
= FONT_DESCENT (font
) - boff
;
20973 it
->override_ascent
= ascent
;
20974 it
->override_descent
= descent
;
20975 it
->override_boff
= boff
;
20978 height
= ascent
+ descent
;
20982 height
= (int)(XFLOAT_DATA (val
) * height
);
20983 else if (INTEGERP (val
))
20984 height
*= XINT (val
);
20986 return make_number (height
);
20991 Produce glyphs/get display metrics for the display element IT is
20992 loaded with. See the description of struct it in dispextern.h
20993 for an overview of struct it. */
20996 x_produce_glyphs (it
)
20999 int extra_line_spacing
= it
->extra_line_spacing
;
21001 it
->glyph_not_available_p
= 0;
21003 if (it
->what
== IT_CHARACTER
)
21007 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21008 struct font_metrics
*pcm
;
21009 int font_not_found_p
;
21010 int boff
; /* baseline offset */
21011 /* We may change it->multibyte_p upon unibyte<->multibyte
21012 conversion. So, save the current value now and restore it
21015 Note: It seems that we don't have to record multibyte_p in
21016 struct glyph because the character code itself tells if or
21017 not the character is multibyte. Thus, in the future, we must
21018 consider eliminating the field `multibyte_p' in the struct
21020 int saved_multibyte_p
= it
->multibyte_p
;
21022 /* Maybe translate single-byte characters to multibyte, or the
21024 it
->char_to_display
= it
->c
;
21025 if (!ASCII_BYTE_P (it
->c
)
21026 && ! it
->multibyte_p
)
21028 if (SINGLE_BYTE_CHAR_P (it
->c
)
21029 && unibyte_display_via_language_environment
)
21030 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
21031 if (! SINGLE_BYTE_CHAR_P (it
->char_to_display
))
21033 it
->multibyte_p
= 1;
21034 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21036 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21040 /* Get font to use. Encode IT->char_to_display. */
21041 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21042 &char2b
, it
->multibyte_p
, 0);
21045 /* When no suitable font found, use the default font. */
21046 font_not_found_p
= font
== NULL
;
21047 if (font_not_found_p
)
21049 font
= FRAME_FONT (it
->f
);
21050 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21054 boff
= font
->baseline_offset
;
21055 if (font
->vertical_centering
)
21056 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21059 if (it
->char_to_display
>= ' '
21060 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21062 /* Either unibyte or ASCII. */
21067 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21069 if (it
->override_ascent
>= 0)
21071 it
->ascent
= it
->override_ascent
;
21072 it
->descent
= it
->override_descent
;
21073 boff
= it
->override_boff
;
21077 it
->ascent
= FONT_BASE (font
) + boff
;
21078 it
->descent
= FONT_DESCENT (font
) - boff
;
21083 it
->phys_ascent
= pcm
->ascent
+ boff
;
21084 it
->phys_descent
= pcm
->descent
- boff
;
21085 it
->pixel_width
= pcm
->width
;
21089 it
->glyph_not_available_p
= 1;
21090 it
->phys_ascent
= it
->ascent
;
21091 it
->phys_descent
= it
->descent
;
21092 it
->pixel_width
= FONT_WIDTH (font
);
21095 if (it
->constrain_row_ascent_descent_p
)
21097 if (it
->descent
> it
->max_descent
)
21099 it
->ascent
+= it
->descent
- it
->max_descent
;
21100 it
->descent
= it
->max_descent
;
21102 if (it
->ascent
> it
->max_ascent
)
21104 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21105 it
->ascent
= it
->max_ascent
;
21107 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21108 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21109 extra_line_spacing
= 0;
21112 /* If this is a space inside a region of text with
21113 `space-width' property, change its width. */
21114 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21116 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21118 /* If face has a box, add the box thickness to the character
21119 height. If character has a box line to the left and/or
21120 right, add the box line width to the character's width. */
21121 if (face
->box
!= FACE_NO_BOX
)
21123 int thick
= face
->box_line_width
;
21127 it
->ascent
+= thick
;
21128 it
->descent
+= thick
;
21133 if (it
->start_of_box_run_p
)
21134 it
->pixel_width
+= thick
;
21135 if (it
->end_of_box_run_p
)
21136 it
->pixel_width
+= thick
;
21139 /* If face has an overline, add the height of the overline
21140 (1 pixel) and a 1 pixel margin to the character height. */
21141 if (face
->overline_p
)
21142 it
->ascent
+= overline_margin
;
21144 if (it
->constrain_row_ascent_descent_p
)
21146 if (it
->ascent
> it
->max_ascent
)
21147 it
->ascent
= it
->max_ascent
;
21148 if (it
->descent
> it
->max_descent
)
21149 it
->descent
= it
->max_descent
;
21152 take_vertical_position_into_account (it
);
21154 /* If we have to actually produce glyphs, do it. */
21159 /* Translate a space with a `space-width' property
21160 into a stretch glyph. */
21161 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21162 / FONT_HEIGHT (font
));
21163 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21164 it
->ascent
+ it
->descent
, ascent
);
21169 /* If characters with lbearing or rbearing are displayed
21170 in this line, record that fact in a flag of the
21171 glyph row. This is used to optimize X output code. */
21172 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21173 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21175 if (! stretched_p
&& it
->pixel_width
== 0)
21176 /* We assure that all visible glyphs have at least 1-pixel
21178 it
->pixel_width
= 1;
21180 else if (it
->char_to_display
== '\n')
21182 /* A newline has no width but we need the height of the line.
21183 But if previous part of the line set a height, don't
21184 increase that height */
21186 Lisp_Object height
;
21187 Lisp_Object total_height
= Qnil
;
21189 it
->override_ascent
= -1;
21190 it
->pixel_width
= 0;
21193 height
= get_it_property(it
, Qline_height
);
21194 /* Split (line-height total-height) list */
21196 && CONSP (XCDR (height
))
21197 && NILP (XCDR (XCDR (height
))))
21199 total_height
= XCAR (XCDR (height
));
21200 height
= XCAR (height
);
21202 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21204 if (it
->override_ascent
>= 0)
21206 it
->ascent
= it
->override_ascent
;
21207 it
->descent
= it
->override_descent
;
21208 boff
= it
->override_boff
;
21212 it
->ascent
= FONT_BASE (font
) + boff
;
21213 it
->descent
= FONT_DESCENT (font
) - boff
;
21216 if (EQ (height
, Qt
))
21218 if (it
->descent
> it
->max_descent
)
21220 it
->ascent
+= it
->descent
- it
->max_descent
;
21221 it
->descent
= it
->max_descent
;
21223 if (it
->ascent
> it
->max_ascent
)
21225 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21226 it
->ascent
= it
->max_ascent
;
21228 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21229 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21230 it
->constrain_row_ascent_descent_p
= 1;
21231 extra_line_spacing
= 0;
21235 Lisp_Object spacing
;
21237 it
->phys_ascent
= it
->ascent
;
21238 it
->phys_descent
= it
->descent
;
21240 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21241 && face
->box
!= FACE_NO_BOX
21242 && face
->box_line_width
> 0)
21244 it
->ascent
+= face
->box_line_width
;
21245 it
->descent
+= face
->box_line_width
;
21248 && XINT (height
) > it
->ascent
+ it
->descent
)
21249 it
->ascent
= XINT (height
) - it
->descent
;
21251 if (!NILP (total_height
))
21252 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21255 spacing
= get_it_property(it
, Qline_spacing
);
21256 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21258 if (INTEGERP (spacing
))
21260 extra_line_spacing
= XINT (spacing
);
21261 if (!NILP (total_height
))
21262 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21266 else if (it
->char_to_display
== '\t')
21268 int tab_width
= it
->tab_width
* font
->space_width
;
21269 int x
= it
->current_x
+ it
->continuation_lines_width
;
21270 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21272 /* If the distance from the current position to the next tab
21273 stop is less than a space character width, use the
21274 tab stop after that. */
21275 if (next_tab_x
- x
< font
->space_width
)
21276 next_tab_x
+= tab_width
;
21278 it
->pixel_width
= next_tab_x
- x
;
21280 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21281 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21285 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21286 it
->ascent
+ it
->descent
, it
->ascent
);
21291 /* A multi-byte character. Assume that the display width of the
21292 character is the width of the character multiplied by the
21293 width of the font. */
21295 /* If we found a font, this font should give us the right
21296 metrics. If we didn't find a font, use the frame's
21297 default font and calculate the width of the character by
21298 multiplying the width of font by the width of the
21301 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21303 if (font_not_found_p
|| !pcm
)
21305 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21307 if (char_width
== 0)
21308 /* This is a non spacing character. But, as we are
21309 going to display an empty box, the box must occupy
21310 at least one column. */
21312 it
->glyph_not_available_p
= 1;
21313 it
->pixel_width
= FRAME_COLUMN_WIDTH (it
->f
) * char_width
;
21314 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21315 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21319 it
->pixel_width
= pcm
->width
;
21320 it
->phys_ascent
= pcm
->ascent
+ boff
;
21321 it
->phys_descent
= pcm
->descent
- boff
;
21323 && (pcm
->lbearing
< 0
21324 || pcm
->rbearing
> pcm
->width
))
21325 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21328 it
->ascent
= FONT_BASE (font
) + boff
;
21329 it
->descent
= FONT_DESCENT (font
) - boff
;
21330 if (face
->box
!= FACE_NO_BOX
)
21332 int thick
= face
->box_line_width
;
21336 it
->ascent
+= thick
;
21337 it
->descent
+= thick
;
21342 if (it
->start_of_box_run_p
)
21343 it
->pixel_width
+= thick
;
21344 if (it
->end_of_box_run_p
)
21345 it
->pixel_width
+= thick
;
21348 /* If face has an overline, add the height of the overline
21349 (1 pixel) and a 1 pixel margin to the character height. */
21350 if (face
->overline_p
)
21351 it
->ascent
+= overline_margin
;
21353 take_vertical_position_into_account (it
);
21355 if (it
->ascent
< 0)
21357 if (it
->descent
< 0)
21362 if (it
->pixel_width
== 0)
21363 /* We assure that all visible glyphs have at least 1-pixel
21365 it
->pixel_width
= 1;
21367 it
->multibyte_p
= saved_multibyte_p
;
21369 else if (it
->what
== IT_COMPOSITION
)
21371 /* Note: A composition is represented as one glyph in the
21372 glyph matrix. There are no padding glyphs.
21374 Important is that pixel_width, ascent, and descent are the
21375 values of what is drawn by draw_glyphs (i.e. the values of
21376 the overall glyphs composed). */
21377 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21378 int boff
; /* baseline offset */
21379 struct composition
*cmp
= composition_table
[it
->cmp_id
];
21380 int glyph_len
= cmp
->glyph_len
;
21381 struct font
*font
= face
->font
;
21385 if (cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
21387 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21388 font_prepare_composition (cmp
, it
->f
);
21391 /* If we have not yet calculated pixel size data of glyphs of
21392 the composition for the current face font, calculate them
21393 now. Theoretically, we have to check all fonts for the
21394 glyphs, but that requires much time and memory space. So,
21395 here we check only the font of the first glyph. This leads
21396 to incorrect display, but it's very rare, and C-l (recenter)
21397 can correct the display anyway. */
21398 if (! cmp
->font
|| cmp
->font
!= font
)
21400 /* Ascent and descent of the font of the first character
21401 of this composition (adjusted by baseline offset).
21402 Ascent and descent of overall glyphs should not be less
21403 than them respectively. */
21404 int font_ascent
, font_descent
, font_height
;
21405 /* Bounding box of the overall glyphs. */
21406 int leftmost
, rightmost
, lowest
, highest
;
21407 int lbearing
, rbearing
;
21408 int i
, width
, ascent
, descent
;
21409 int left_padded
= 0, right_padded
= 0;
21413 struct font_metrics
*pcm
;
21414 int font_not_found_p
;
21417 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21418 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21420 if (glyph_len
< cmp
->glyph_len
)
21422 for (i
= 0; i
< glyph_len
; i
++)
21424 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21426 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21431 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21432 : IT_CHARPOS (*it
));
21433 /* When no suitable font found, use the default font. */
21434 font_not_found_p
= font
== NULL
;
21435 if (font_not_found_p
)
21437 face
= face
->ascii_face
;
21440 boff
= font
->baseline_offset
;
21441 if (font
->vertical_centering
)
21442 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21443 font_ascent
= FONT_BASE (font
) + boff
;
21444 font_descent
= FONT_DESCENT (font
) - boff
;
21445 font_height
= FONT_HEIGHT (font
);
21447 cmp
->font
= (void *) font
;
21450 if (! font_not_found_p
)
21452 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21453 &char2b
, it
->multibyte_p
, 0);
21454 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21457 /* Initialize the bounding box. */
21460 width
= pcm
->width
;
21461 ascent
= pcm
->ascent
;
21462 descent
= pcm
->descent
;
21463 lbearing
= pcm
->lbearing
;
21464 rbearing
= pcm
->rbearing
;
21468 width
= FONT_WIDTH (font
);
21469 ascent
= FONT_BASE (font
);
21470 descent
= FONT_DESCENT (font
);
21477 lowest
= - descent
+ boff
;
21478 highest
= ascent
+ boff
;
21480 if (! font_not_found_p
21481 && font
->default_ascent
21482 && CHAR_TABLE_P (Vuse_default_ascent
)
21483 && !NILP (Faref (Vuse_default_ascent
,
21484 make_number (it
->char_to_display
))))
21485 highest
= font
->default_ascent
+ boff
;
21487 /* Draw the first glyph at the normal position. It may be
21488 shifted to right later if some other glyphs are drawn
21490 cmp
->offsets
[i
* 2] = 0;
21491 cmp
->offsets
[i
* 2 + 1] = boff
;
21492 cmp
->lbearing
= lbearing
;
21493 cmp
->rbearing
= rbearing
;
21495 /* Set cmp->offsets for the remaining glyphs. */
21496 for (i
++; i
< glyph_len
; i
++)
21498 int left
, right
, btm
, top
;
21499 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21501 struct face
*this_face
;
21506 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21507 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21508 font
= this_face
->font
;
21514 this_boff
= font
->baseline_offset
;
21515 if (font
->vertical_centering
)
21516 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21517 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21518 &char2b
, it
->multibyte_p
, 0);
21519 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21522 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21525 width
= pcm
->width
;
21526 ascent
= pcm
->ascent
;
21527 descent
= pcm
->descent
;
21528 lbearing
= pcm
->lbearing
;
21529 rbearing
= pcm
->rbearing
;
21530 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21532 /* Relative composition with or without
21533 alternate chars. */
21534 left
= (leftmost
+ rightmost
- width
) / 2;
21535 btm
= - descent
+ boff
;
21536 if (font
->relative_compose
21537 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21538 || NILP (Faref (Vignore_relative_composition
,
21539 make_number (ch
)))))
21542 if (- descent
>= font
->relative_compose
)
21543 /* One extra pixel between two glyphs. */
21545 else if (ascent
<= 0)
21546 /* One extra pixel between two glyphs. */
21547 btm
= lowest
- 1 - ascent
- descent
;
21552 /* A composition rule is specified by an integer
21553 value that encodes global and new reference
21554 points (GREF and NREF). GREF and NREF are
21555 specified by numbers as below:
21557 0---1---2 -- ascent
21561 9--10--11 -- center
21563 ---3---4---5--- baseline
21565 6---7---8 -- descent
21567 int rule
= COMPOSITION_RULE (cmp
, i
);
21568 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21570 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21571 grefx
= gref
% 3, nrefx
= nref
% 3;
21572 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21574 xoff
= font_height
* (xoff
- 128) / 256;
21576 yoff
= font_height
* (yoff
- 128) / 256;
21579 + grefx
* (rightmost
- leftmost
) / 2
21580 - nrefx
* width
/ 2
21583 btm
= ((grefy
== 0 ? highest
21585 : grefy
== 2 ? lowest
21586 : (highest
+ lowest
) / 2)
21587 - (nrefy
== 0 ? ascent
+ descent
21588 : nrefy
== 1 ? descent
- boff
21590 : (ascent
+ descent
) / 2)
21594 cmp
->offsets
[i
* 2] = left
;
21595 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21597 /* Update the bounding box of the overall glyphs. */
21600 right
= left
+ width
;
21601 if (left
< leftmost
)
21603 if (right
> rightmost
)
21606 top
= btm
+ descent
+ ascent
;
21612 if (cmp
->lbearing
> left
+ lbearing
)
21613 cmp
->lbearing
= left
+ lbearing
;
21614 if (cmp
->rbearing
< left
+ rbearing
)
21615 cmp
->rbearing
= left
+ rbearing
;
21619 /* If there are glyphs whose x-offsets are negative,
21620 shift all glyphs to the right and make all x-offsets
21624 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21625 cmp
->offsets
[i
* 2] -= leftmost
;
21626 rightmost
-= leftmost
;
21627 cmp
->lbearing
-= leftmost
;
21628 cmp
->rbearing
-= leftmost
;
21631 if (left_padded
&& cmp
->lbearing
< 0)
21633 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21634 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21635 rightmost
-= cmp
->lbearing
;
21636 cmp
->rbearing
-= cmp
->lbearing
;
21639 if (right_padded
&& rightmost
< cmp
->rbearing
)
21641 rightmost
= cmp
->rbearing
;
21644 cmp
->pixel_width
= rightmost
;
21645 cmp
->ascent
= highest
;
21646 cmp
->descent
= - lowest
;
21647 if (cmp
->ascent
< font_ascent
)
21648 cmp
->ascent
= font_ascent
;
21649 if (cmp
->descent
< font_descent
)
21650 cmp
->descent
= font_descent
;
21654 && (cmp
->lbearing
< 0
21655 || cmp
->rbearing
> cmp
->pixel_width
))
21656 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21658 it
->pixel_width
= cmp
->pixel_width
;
21659 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21660 it
->descent
= it
->phys_descent
= cmp
->descent
;
21661 if (face
->box
!= FACE_NO_BOX
)
21663 int thick
= face
->box_line_width
;
21667 it
->ascent
+= thick
;
21668 it
->descent
+= thick
;
21673 if (it
->start_of_box_run_p
)
21674 it
->pixel_width
+= thick
;
21675 if (it
->end_of_box_run_p
)
21676 it
->pixel_width
+= thick
;
21679 /* If face has an overline, add the height of the overline
21680 (1 pixel) and a 1 pixel margin to the character height. */
21681 if (face
->overline_p
)
21682 it
->ascent
+= overline_margin
;
21684 take_vertical_position_into_account (it
);
21685 if (it
->ascent
< 0)
21687 if (it
->descent
< 0)
21691 append_composite_glyph (it
);
21693 else if (it
->what
== IT_IMAGE
)
21694 produce_image_glyph (it
);
21695 else if (it
->what
== IT_STRETCH
)
21696 produce_stretch_glyph (it
);
21698 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21699 because this isn't true for images with `:ascent 100'. */
21700 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21701 if (it
->area
== TEXT_AREA
)
21702 it
->current_x
+= it
->pixel_width
;
21704 if (extra_line_spacing
> 0)
21706 it
->descent
+= extra_line_spacing
;
21707 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21708 it
->max_extra_line_spacing
= extra_line_spacing
;
21711 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21712 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21713 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21714 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21718 Output LEN glyphs starting at START at the nominal cursor position.
21719 Advance the nominal cursor over the text. The global variable
21720 updated_window contains the window being updated, updated_row is
21721 the glyph row being updated, and updated_area is the area of that
21722 row being updated. */
21725 x_write_glyphs (start
, len
)
21726 struct glyph
*start
;
21731 xassert (updated_window
&& updated_row
);
21734 /* Write glyphs. */
21736 hpos
= start
- updated_row
->glyphs
[updated_area
];
21737 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21738 updated_row
, updated_area
,
21740 DRAW_NORMAL_TEXT
, 0);
21742 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21743 if (updated_area
== TEXT_AREA
21744 && updated_window
->phys_cursor_on_p
21745 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21746 && updated_window
->phys_cursor
.hpos
>= hpos
21747 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21748 updated_window
->phys_cursor_on_p
= 0;
21752 /* Advance the output cursor. */
21753 output_cursor
.hpos
+= len
;
21754 output_cursor
.x
= x
;
21759 Insert LEN glyphs from START at the nominal cursor position. */
21762 x_insert_glyphs (start
, len
)
21763 struct glyph
*start
;
21768 int line_height
, shift_by_width
, shifted_region_width
;
21769 struct glyph_row
*row
;
21770 struct glyph
*glyph
;
21771 int frame_x
, frame_y
;
21774 xassert (updated_window
&& updated_row
);
21776 w
= updated_window
;
21777 f
= XFRAME (WINDOW_FRAME (w
));
21779 /* Get the height of the line we are in. */
21781 line_height
= row
->height
;
21783 /* Get the width of the glyphs to insert. */
21784 shift_by_width
= 0;
21785 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21786 shift_by_width
+= glyph
->pixel_width
;
21788 /* Get the width of the region to shift right. */
21789 shifted_region_width
= (window_box_width (w
, updated_area
)
21794 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21795 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21797 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21798 line_height
, shift_by_width
);
21800 /* Write the glyphs. */
21801 hpos
= start
- row
->glyphs
[updated_area
];
21802 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21804 DRAW_NORMAL_TEXT
, 0);
21806 /* Advance the output cursor. */
21807 output_cursor
.hpos
+= len
;
21808 output_cursor
.x
+= shift_by_width
;
21814 Erase the current text line from the nominal cursor position
21815 (inclusive) to pixel column TO_X (exclusive). The idea is that
21816 everything from TO_X onward is already erased.
21818 TO_X is a pixel position relative to updated_area of
21819 updated_window. TO_X == -1 means clear to the end of this area. */
21822 x_clear_end_of_line (to_x
)
21826 struct window
*w
= updated_window
;
21827 int max_x
, min_y
, max_y
;
21828 int from_x
, from_y
, to_y
;
21830 xassert (updated_window
&& updated_row
);
21831 f
= XFRAME (w
->frame
);
21833 if (updated_row
->full_width_p
)
21834 max_x
= WINDOW_TOTAL_WIDTH (w
);
21836 max_x
= window_box_width (w
, updated_area
);
21837 max_y
= window_text_bottom_y (w
);
21839 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21840 of window. For TO_X > 0, truncate to end of drawing area. */
21846 to_x
= min (to_x
, max_x
);
21848 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21850 /* Notice if the cursor will be cleared by this operation. */
21851 if (!updated_row
->full_width_p
)
21852 notice_overwritten_cursor (w
, updated_area
,
21853 output_cursor
.x
, -1,
21855 MATRIX_ROW_BOTTOM_Y (updated_row
));
21857 from_x
= output_cursor
.x
;
21859 /* Translate to frame coordinates. */
21860 if (updated_row
->full_width_p
)
21862 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21863 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21867 int area_left
= window_box_left (w
, updated_area
);
21868 from_x
+= area_left
;
21872 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21873 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21874 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21876 /* Prevent inadvertently clearing to end of the X window. */
21877 if (to_x
> from_x
&& to_y
> from_y
)
21880 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21881 to_x
- from_x
, to_y
- from_y
);
21886 #endif /* HAVE_WINDOW_SYSTEM */
21890 /***********************************************************************
21892 ***********************************************************************/
21894 /* Value is the internal representation of the specified cursor type
21895 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21896 of the bar cursor. */
21898 static enum text_cursor_kinds
21899 get_specified_cursor_type (arg
, width
)
21903 enum text_cursor_kinds type
;
21908 if (EQ (arg
, Qbox
))
21909 return FILLED_BOX_CURSOR
;
21911 if (EQ (arg
, Qhollow
))
21912 return HOLLOW_BOX_CURSOR
;
21914 if (EQ (arg
, Qbar
))
21921 && EQ (XCAR (arg
), Qbar
)
21922 && INTEGERP (XCDR (arg
))
21923 && XINT (XCDR (arg
)) >= 0)
21925 *width
= XINT (XCDR (arg
));
21929 if (EQ (arg
, Qhbar
))
21932 return HBAR_CURSOR
;
21936 && EQ (XCAR (arg
), Qhbar
)
21937 && INTEGERP (XCDR (arg
))
21938 && XINT (XCDR (arg
)) >= 0)
21940 *width
= XINT (XCDR (arg
));
21941 return HBAR_CURSOR
;
21944 /* Treat anything unknown as "hollow box cursor".
21945 It was bad to signal an error; people have trouble fixing
21946 .Xdefaults with Emacs, when it has something bad in it. */
21947 type
= HOLLOW_BOX_CURSOR
;
21952 /* Set the default cursor types for specified frame. */
21954 set_frame_cursor_types (f
, arg
)
21961 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21962 FRAME_CURSOR_WIDTH (f
) = width
;
21964 /* By default, set up the blink-off state depending on the on-state. */
21966 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21969 FRAME_BLINK_OFF_CURSOR (f
)
21970 = get_specified_cursor_type (XCDR (tem
), &width
);
21971 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21974 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21978 /* Return the cursor we want to be displayed in window W. Return
21979 width of bar/hbar cursor through WIDTH arg. Return with
21980 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21981 (i.e. if the `system caret' should track this cursor).
21983 In a mini-buffer window, we want the cursor only to appear if we
21984 are reading input from this window. For the selected window, we
21985 want the cursor type given by the frame parameter or buffer local
21986 setting of cursor-type. If explicitly marked off, draw no cursor.
21987 In all other cases, we want a hollow box cursor. */
21989 static enum text_cursor_kinds
21990 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21992 struct glyph
*glyph
;
21994 int *active_cursor
;
21996 struct frame
*f
= XFRAME (w
->frame
);
21997 struct buffer
*b
= XBUFFER (w
->buffer
);
21998 int cursor_type
= DEFAULT_CURSOR
;
21999 Lisp_Object alt_cursor
;
22000 int non_selected
= 0;
22002 *active_cursor
= 1;
22005 if (cursor_in_echo_area
22006 && FRAME_HAS_MINIBUF_P (f
)
22007 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22009 if (w
== XWINDOW (echo_area_window
))
22011 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22013 *width
= FRAME_CURSOR_WIDTH (f
);
22014 return FRAME_DESIRED_CURSOR (f
);
22017 return get_specified_cursor_type (b
->cursor_type
, width
);
22020 *active_cursor
= 0;
22024 /* Detect a nonselected window or nonselected frame. */
22025 else if (w
!= XWINDOW (f
->selected_window
)
22026 #ifdef HAVE_WINDOW_SYSTEM
22027 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22031 *active_cursor
= 0;
22033 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22039 /* Never display a cursor in a window in which cursor-type is nil. */
22040 if (NILP (b
->cursor_type
))
22043 /* Get the normal cursor type for this window. */
22044 if (EQ (b
->cursor_type
, Qt
))
22046 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22047 *width
= FRAME_CURSOR_WIDTH (f
);
22050 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22052 /* Use cursor-in-non-selected-windows instead
22053 for non-selected window or frame. */
22056 alt_cursor
= b
->cursor_in_non_selected_windows
;
22057 if (!EQ (Qt
, alt_cursor
))
22058 return get_specified_cursor_type (alt_cursor
, width
);
22059 /* t means modify the normal cursor type. */
22060 if (cursor_type
== FILLED_BOX_CURSOR
)
22061 cursor_type
= HOLLOW_BOX_CURSOR
;
22062 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22064 return cursor_type
;
22067 /* Use normal cursor if not blinked off. */
22068 if (!w
->cursor_off_p
)
22070 #ifdef HAVE_WINDOW_SYSTEM
22071 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22073 if (cursor_type
== FILLED_BOX_CURSOR
)
22075 /* Using a block cursor on large images can be very annoying.
22076 So use a hollow cursor for "large" images.
22077 If image is not transparent (no mask), also use hollow cursor. */
22078 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22079 if (img
!= NULL
&& IMAGEP (img
->spec
))
22081 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22082 where N = size of default frame font size.
22083 This should cover most of the "tiny" icons people may use. */
22085 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22086 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22087 cursor_type
= HOLLOW_BOX_CURSOR
;
22090 else if (cursor_type
!= NO_CURSOR
)
22092 /* Display current only supports BOX and HOLLOW cursors for images.
22093 So for now, unconditionally use a HOLLOW cursor when cursor is
22094 not a solid box cursor. */
22095 cursor_type
= HOLLOW_BOX_CURSOR
;
22099 return cursor_type
;
22102 /* Cursor is blinked off, so determine how to "toggle" it. */
22104 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22105 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22106 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22108 /* Then see if frame has specified a specific blink off cursor type. */
22109 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22111 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22112 return FRAME_BLINK_OFF_CURSOR (f
);
22116 /* Some people liked having a permanently visible blinking cursor,
22117 while others had very strong opinions against it. So it was
22118 decided to remove it. KFS 2003-09-03 */
22120 /* Finally perform built-in cursor blinking:
22121 filled box <-> hollow box
22122 wide [h]bar <-> narrow [h]bar
22123 narrow [h]bar <-> no cursor
22124 other type <-> no cursor */
22126 if (cursor_type
== FILLED_BOX_CURSOR
)
22127 return HOLLOW_BOX_CURSOR
;
22129 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22132 return cursor_type
;
22140 #ifdef HAVE_WINDOW_SYSTEM
22142 /* Notice when the text cursor of window W has been completely
22143 overwritten by a drawing operation that outputs glyphs in AREA
22144 starting at X0 and ending at X1 in the line starting at Y0 and
22145 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22146 the rest of the line after X0 has been written. Y coordinates
22147 are window-relative. */
22150 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22152 enum glyph_row_area area
;
22153 int x0
, y0
, x1
, y1
;
22155 int cx0
, cx1
, cy0
, cy1
;
22156 struct glyph_row
*row
;
22158 if (!w
->phys_cursor_on_p
)
22160 if (area
!= TEXT_AREA
)
22163 if (w
->phys_cursor
.vpos
< 0
22164 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22165 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22166 !(row
->enabled_p
&& row
->displays_text_p
)))
22169 if (row
->cursor_in_fringe_p
)
22171 row
->cursor_in_fringe_p
= 0;
22172 draw_fringe_bitmap (w
, row
, 0);
22173 w
->phys_cursor_on_p
= 0;
22177 cx0
= w
->phys_cursor
.x
;
22178 cx1
= cx0
+ w
->phys_cursor_width
;
22179 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22182 /* The cursor image will be completely removed from the
22183 screen if the output area intersects the cursor area in
22184 y-direction. When we draw in [y0 y1[, and some part of
22185 the cursor is at y < y0, that part must have been drawn
22186 before. When scrolling, the cursor is erased before
22187 actually scrolling, so we don't come here. When not
22188 scrolling, the rows above the old cursor row must have
22189 changed, and in this case these rows must have written
22190 over the cursor image.
22192 Likewise if part of the cursor is below y1, with the
22193 exception of the cursor being in the first blank row at
22194 the buffer and window end because update_text_area
22195 doesn't draw that row. (Except when it does, but
22196 that's handled in update_text_area.) */
22198 cy0
= w
->phys_cursor
.y
;
22199 cy1
= cy0
+ w
->phys_cursor_height
;
22200 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22203 w
->phys_cursor_on_p
= 0;
22206 #endif /* HAVE_WINDOW_SYSTEM */
22209 /************************************************************************
22211 ************************************************************************/
22213 #ifdef HAVE_WINDOW_SYSTEM
22216 Fix the display of area AREA of overlapping row ROW in window W
22217 with respect to the overlapping part OVERLAPS. */
22220 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22222 struct glyph_row
*row
;
22223 enum glyph_row_area area
;
22231 for (i
= 0; i
< row
->used
[area
];)
22233 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22235 int start
= i
, start_x
= x
;
22239 x
+= row
->glyphs
[area
][i
].pixel_width
;
22242 while (i
< row
->used
[area
]
22243 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22245 draw_glyphs (w
, start_x
, row
, area
,
22247 DRAW_NORMAL_TEXT
, overlaps
);
22251 x
+= row
->glyphs
[area
][i
].pixel_width
;
22261 Draw the cursor glyph of window W in glyph row ROW. See the
22262 comment of draw_glyphs for the meaning of HL. */
22265 draw_phys_cursor_glyph (w
, row
, hl
)
22267 struct glyph_row
*row
;
22268 enum draw_glyphs_face hl
;
22270 /* If cursor hpos is out of bounds, don't draw garbage. This can
22271 happen in mini-buffer windows when switching between echo area
22272 glyphs and mini-buffer. */
22273 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22275 int on_p
= w
->phys_cursor_on_p
;
22277 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22278 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22280 w
->phys_cursor_on_p
= on_p
;
22282 if (hl
== DRAW_CURSOR
)
22283 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22284 /* When we erase the cursor, and ROW is overlapped by other
22285 rows, make sure that these overlapping parts of other rows
22287 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22289 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22291 if (row
> w
->current_matrix
->rows
22292 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22293 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22294 OVERLAPS_ERASED_CURSOR
);
22296 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22297 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22298 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22299 OVERLAPS_ERASED_CURSOR
);
22306 Erase the image of a cursor of window W from the screen. */
22309 erase_phys_cursor (w
)
22312 struct frame
*f
= XFRAME (w
->frame
);
22313 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22314 int hpos
= w
->phys_cursor
.hpos
;
22315 int vpos
= w
->phys_cursor
.vpos
;
22316 int mouse_face_here_p
= 0;
22317 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22318 struct glyph_row
*cursor_row
;
22319 struct glyph
*cursor_glyph
;
22320 enum draw_glyphs_face hl
;
22322 /* No cursor displayed or row invalidated => nothing to do on the
22324 if (w
->phys_cursor_type
== NO_CURSOR
)
22325 goto mark_cursor_off
;
22327 /* VPOS >= active_glyphs->nrows means that window has been resized.
22328 Don't bother to erase the cursor. */
22329 if (vpos
>= active_glyphs
->nrows
)
22330 goto mark_cursor_off
;
22332 /* If row containing cursor is marked invalid, there is nothing we
22334 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22335 if (!cursor_row
->enabled_p
)
22336 goto mark_cursor_off
;
22338 /* If line spacing is > 0, old cursor may only be partially visible in
22339 window after split-window. So adjust visible height. */
22340 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22341 window_text_bottom_y (w
) - cursor_row
->y
);
22343 /* If row is completely invisible, don't attempt to delete a cursor which
22344 isn't there. This can happen if cursor is at top of a window, and
22345 we switch to a buffer with a header line in that window. */
22346 if (cursor_row
->visible_height
<= 0)
22347 goto mark_cursor_off
;
22349 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22350 if (cursor_row
->cursor_in_fringe_p
)
22352 cursor_row
->cursor_in_fringe_p
= 0;
22353 draw_fringe_bitmap (w
, cursor_row
, 0);
22354 goto mark_cursor_off
;
22357 /* This can happen when the new row is shorter than the old one.
22358 In this case, either draw_glyphs or clear_end_of_line
22359 should have cleared the cursor. Note that we wouldn't be
22360 able to erase the cursor in this case because we don't have a
22361 cursor glyph at hand. */
22362 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22363 goto mark_cursor_off
;
22365 /* If the cursor is in the mouse face area, redisplay that when
22366 we clear the cursor. */
22367 if (! NILP (dpyinfo
->mouse_face_window
)
22368 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22369 && (vpos
> dpyinfo
->mouse_face_beg_row
22370 || (vpos
== dpyinfo
->mouse_face_beg_row
22371 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22372 && (vpos
< dpyinfo
->mouse_face_end_row
22373 || (vpos
== dpyinfo
->mouse_face_end_row
22374 && hpos
< dpyinfo
->mouse_face_end_col
))
22375 /* Don't redraw the cursor's spot in mouse face if it is at the
22376 end of a line (on a newline). The cursor appears there, but
22377 mouse highlighting does not. */
22378 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22379 mouse_face_here_p
= 1;
22381 /* Maybe clear the display under the cursor. */
22382 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22385 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22388 cursor_glyph
= get_phys_cursor_glyph (w
);
22389 if (cursor_glyph
== NULL
)
22390 goto mark_cursor_off
;
22392 width
= cursor_glyph
->pixel_width
;
22393 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22394 x
= w
->phys_cursor
.x
;
22396 width
-= left_x
- x
;
22397 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22398 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22399 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22402 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22405 /* Erase the cursor by redrawing the character underneath it. */
22406 if (mouse_face_here_p
)
22407 hl
= DRAW_MOUSE_FACE
;
22409 hl
= DRAW_NORMAL_TEXT
;
22410 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22413 w
->phys_cursor_on_p
= 0;
22414 w
->phys_cursor_type
= NO_CURSOR
;
22419 Display or clear cursor of window W. If ON is zero, clear the
22420 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22421 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22424 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22426 int on
, hpos
, vpos
, x
, y
;
22428 struct frame
*f
= XFRAME (w
->frame
);
22429 int new_cursor_type
;
22430 int new_cursor_width
;
22432 struct glyph_row
*glyph_row
;
22433 struct glyph
*glyph
;
22435 /* This is pointless on invisible frames, and dangerous on garbaged
22436 windows and frames; in the latter case, the frame or window may
22437 be in the midst of changing its size, and x and y may be off the
22439 if (! FRAME_VISIBLE_P (f
)
22440 || FRAME_GARBAGED_P (f
)
22441 || vpos
>= w
->current_matrix
->nrows
22442 || hpos
>= w
->current_matrix
->matrix_w
)
22445 /* If cursor is off and we want it off, return quickly. */
22446 if (!on
&& !w
->phys_cursor_on_p
)
22449 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22450 /* If cursor row is not enabled, we don't really know where to
22451 display the cursor. */
22452 if (!glyph_row
->enabled_p
)
22454 w
->phys_cursor_on_p
= 0;
22459 if (!glyph_row
->exact_window_width_line_p
22460 || hpos
< glyph_row
->used
[TEXT_AREA
])
22461 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22463 xassert (interrupt_input_blocked
);
22465 /* Set new_cursor_type to the cursor we want to be displayed. */
22466 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22467 &new_cursor_width
, &active_cursor
);
22469 /* If cursor is currently being shown and we don't want it to be or
22470 it is in the wrong place, or the cursor type is not what we want,
22472 if (w
->phys_cursor_on_p
22474 || w
->phys_cursor
.x
!= x
22475 || w
->phys_cursor
.y
!= y
22476 || new_cursor_type
!= w
->phys_cursor_type
22477 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22478 && new_cursor_width
!= w
->phys_cursor_width
)))
22479 erase_phys_cursor (w
);
22481 /* Don't check phys_cursor_on_p here because that flag is only set
22482 to zero in some cases where we know that the cursor has been
22483 completely erased, to avoid the extra work of erasing the cursor
22484 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22485 still not be visible, or it has only been partly erased. */
22488 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22489 w
->phys_cursor_height
= glyph_row
->height
;
22491 /* Set phys_cursor_.* before x_draw_.* is called because some
22492 of them may need the information. */
22493 w
->phys_cursor
.x
= x
;
22494 w
->phys_cursor
.y
= glyph_row
->y
;
22495 w
->phys_cursor
.hpos
= hpos
;
22496 w
->phys_cursor
.vpos
= vpos
;
22499 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22500 new_cursor_type
, new_cursor_width
,
22501 on
, active_cursor
);
22505 /* Switch the display of W's cursor on or off, according to the value
22509 update_window_cursor (w
, on
)
22513 /* Don't update cursor in windows whose frame is in the process
22514 of being deleted. */
22515 if (w
->current_matrix
)
22518 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22519 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22525 /* Call update_window_cursor with parameter ON_P on all leaf windows
22526 in the window tree rooted at W. */
22529 update_cursor_in_window_tree (w
, on_p
)
22535 if (!NILP (w
->hchild
))
22536 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22537 else if (!NILP (w
->vchild
))
22538 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22540 update_window_cursor (w
, on_p
);
22542 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22548 Display the cursor on window W, or clear it, according to ON_P.
22549 Don't change the cursor's position. */
22552 x_update_cursor (f
, on_p
)
22556 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22561 Clear the cursor of window W to background color, and mark the
22562 cursor as not shown. This is used when the text where the cursor
22563 is is about to be rewritten. */
22569 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22570 update_window_cursor (w
, 0);
22575 Display the active region described by mouse_face_* according to DRAW. */
22578 show_mouse_face (dpyinfo
, draw
)
22579 Display_Info
*dpyinfo
;
22580 enum draw_glyphs_face draw
;
22582 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22583 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22585 if (/* If window is in the process of being destroyed, don't bother
22587 w
->current_matrix
!= NULL
22588 /* Don't update mouse highlight if hidden */
22589 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22590 /* Recognize when we are called to operate on rows that don't exist
22591 anymore. This can happen when a window is split. */
22592 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22594 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22595 struct glyph_row
*row
, *first
, *last
;
22597 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22598 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22600 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22602 int start_hpos
, end_hpos
, start_x
;
22604 /* For all but the first row, the highlight starts at column 0. */
22607 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22608 start_x
= dpyinfo
->mouse_face_beg_x
;
22617 end_hpos
= dpyinfo
->mouse_face_end_col
;
22620 end_hpos
= row
->used
[TEXT_AREA
];
22621 if (draw
== DRAW_NORMAL_TEXT
)
22622 row
->fill_line_p
= 1; /* Clear to end of line */
22625 if (end_hpos
> start_hpos
)
22627 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22628 start_hpos
, end_hpos
,
22632 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22636 /* When we've written over the cursor, arrange for it to
22637 be displayed again. */
22638 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22641 display_and_set_cursor (w
, 1,
22642 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22643 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22648 /* Change the mouse cursor. */
22649 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22650 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22651 else if (draw
== DRAW_MOUSE_FACE
)
22652 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22654 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22658 Clear out the mouse-highlighted active region.
22659 Redraw it un-highlighted first. Value is non-zero if mouse
22660 face was actually drawn unhighlighted. */
22663 clear_mouse_face (dpyinfo
)
22664 Display_Info
*dpyinfo
;
22668 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22670 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22674 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22675 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22676 dpyinfo
->mouse_face_window
= Qnil
;
22677 dpyinfo
->mouse_face_overlay
= Qnil
;
22683 Non-zero if physical cursor of window W is within mouse face. */
22686 cursor_in_mouse_face_p (w
)
22689 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22690 int in_mouse_face
= 0;
22692 if (WINDOWP (dpyinfo
->mouse_face_window
)
22693 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22695 int hpos
= w
->phys_cursor
.hpos
;
22696 int vpos
= w
->phys_cursor
.vpos
;
22698 if (vpos
>= dpyinfo
->mouse_face_beg_row
22699 && vpos
<= dpyinfo
->mouse_face_end_row
22700 && (vpos
> dpyinfo
->mouse_face_beg_row
22701 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22702 && (vpos
< dpyinfo
->mouse_face_end_row
22703 || hpos
< dpyinfo
->mouse_face_end_col
22704 || dpyinfo
->mouse_face_past_end
))
22708 return in_mouse_face
;
22714 /* Find the glyph matrix position of buffer position CHARPOS in window
22715 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
22716 current glyphs must be up to date. If CHARPOS is above window
22717 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22718 of last line in W. In the row containing CHARPOS, stop before glyphs
22719 having STOP as object. */
22721 #if 1 /* This is a version of fast_find_position that's more correct
22722 in the presence of hscrolling, for example. I didn't install
22723 it right away because the problem fixed is minor, it failed
22724 in 20.x as well, and I think it's too risky to install
22725 so near the release of 21.1. 2001-09-25 gerd. */
22727 #ifndef HAVE_CARBON
22731 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22734 int *hpos
, *vpos
, *x
, *y
;
22737 struct glyph_row
*row
, *first
;
22738 struct glyph
*glyph
, *end
;
22741 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22742 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22747 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22751 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22754 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22758 /* If whole rows or last part of a row came from a display overlay,
22759 row_containing_pos will skip over such rows because their end pos
22760 equals the start pos of the overlay or interval.
22762 Move back if we have a STOP object and previous row's
22763 end glyph came from STOP. */
22766 struct glyph_row
*prev
;
22767 while ((prev
= row
- 1, prev
>= first
)
22768 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22769 && prev
->used
[TEXT_AREA
] > 0)
22771 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22772 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22773 while (--glyph
>= beg
22774 && INTEGERP (glyph
->object
));
22776 || !EQ (stop
, glyph
->object
))
22784 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22786 glyph
= row
->glyphs
[TEXT_AREA
];
22787 end
= glyph
+ row
->used
[TEXT_AREA
];
22789 /* Skip over glyphs not having an object at the start of the row.
22790 These are special glyphs like truncation marks on terminal
22792 if (row
->displays_text_p
)
22794 && INTEGERP (glyph
->object
)
22795 && !EQ (stop
, glyph
->object
)
22796 && glyph
->charpos
< 0)
22798 *x
+= glyph
->pixel_width
;
22803 && !INTEGERP (glyph
->object
)
22804 && !EQ (stop
, glyph
->object
)
22805 && (!BUFFERP (glyph
->object
)
22806 || glyph
->charpos
< charpos
))
22808 *x
+= glyph
->pixel_width
;
22812 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22819 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22822 int *hpos
, *vpos
, *x
, *y
;
22827 int maybe_next_line_p
= 0;
22828 int line_start_position
;
22829 int yb
= window_text_bottom_y (w
);
22830 struct glyph_row
*row
, *best_row
;
22831 int row_vpos
, best_row_vpos
;
22834 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22835 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22837 while (row
->y
< yb
)
22839 if (row
->used
[TEXT_AREA
])
22840 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22842 line_start_position
= 0;
22844 if (line_start_position
> pos
)
22846 /* If the position sought is the end of the buffer,
22847 don't include the blank lines at the bottom of the window. */
22848 else if (line_start_position
== pos
22849 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22851 maybe_next_line_p
= 1;
22854 else if (line_start_position
> 0)
22857 best_row_vpos
= row_vpos
;
22860 if (row
->y
+ row
->height
>= yb
)
22867 /* Find the right column within BEST_ROW. */
22869 current_x
= best_row
->x
;
22870 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22872 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22873 int charpos
= glyph
->charpos
;
22875 if (BUFFERP (glyph
->object
))
22877 if (charpos
== pos
)
22880 *vpos
= best_row_vpos
;
22885 else if (charpos
> pos
)
22888 else if (EQ (glyph
->object
, stop
))
22893 current_x
+= glyph
->pixel_width
;
22896 /* If we're looking for the end of the buffer,
22897 and we didn't find it in the line we scanned,
22898 use the start of the following line. */
22899 if (maybe_next_line_p
)
22904 current_x
= best_row
->x
;
22907 *vpos
= best_row_vpos
;
22908 *hpos
= lastcol
+ 1;
22917 /* Find the position of the glyph for position POS in OBJECT in
22918 window W's current matrix, and return in *X, *Y the pixel
22919 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22921 RIGHT_P non-zero means return the position of the right edge of the
22922 glyph, RIGHT_P zero means return the left edge position.
22924 If no glyph for POS exists in the matrix, return the position of
22925 the glyph with the next smaller position that is in the matrix, if
22926 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22927 exists in the matrix, return the position of the glyph with the
22928 next larger position in OBJECT.
22930 Value is non-zero if a glyph was found. */
22933 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22936 Lisp_Object object
;
22937 int *hpos
, *vpos
, *x
, *y
;
22940 int yb
= window_text_bottom_y (w
);
22941 struct glyph_row
*r
;
22942 struct glyph
*best_glyph
= NULL
;
22943 struct glyph_row
*best_row
= NULL
;
22946 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22947 r
->enabled_p
&& r
->y
< yb
;
22950 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22951 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22954 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22955 if (EQ (g
->object
, object
))
22957 if (g
->charpos
== pos
)
22964 else if (best_glyph
== NULL
22965 || ((eabs (g
->charpos
- pos
)
22966 < eabs (best_glyph
->charpos
- pos
))
22969 : g
->charpos
> pos
)))
22983 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22987 *x
+= best_glyph
->pixel_width
;
22992 *vpos
= best_row
- w
->current_matrix
->rows
;
22995 return best_glyph
!= NULL
;
22999 /* See if position X, Y is within a hot-spot of an image. */
23002 on_hot_spot_p (hot_spot
, x
, y
)
23003 Lisp_Object hot_spot
;
23006 if (!CONSP (hot_spot
))
23009 if (EQ (XCAR (hot_spot
), Qrect
))
23011 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23012 Lisp_Object rect
= XCDR (hot_spot
);
23016 if (!CONSP (XCAR (rect
)))
23018 if (!CONSP (XCDR (rect
)))
23020 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23022 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23024 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23026 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23030 else if (EQ (XCAR (hot_spot
), Qcircle
))
23032 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23033 Lisp_Object circ
= XCDR (hot_spot
);
23034 Lisp_Object lr
, lx0
, ly0
;
23036 && CONSP (XCAR (circ
))
23037 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23038 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23039 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23041 double r
= XFLOATINT (lr
);
23042 double dx
= XINT (lx0
) - x
;
23043 double dy
= XINT (ly0
) - y
;
23044 return (dx
* dx
+ dy
* dy
<= r
* r
);
23047 else if (EQ (XCAR (hot_spot
), Qpoly
))
23049 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23050 if (VECTORP (XCDR (hot_spot
)))
23052 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23053 Lisp_Object
*poly
= v
->contents
;
23057 Lisp_Object lx
, ly
;
23060 /* Need an even number of coordinates, and at least 3 edges. */
23061 if (n
< 6 || n
& 1)
23064 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23065 If count is odd, we are inside polygon. Pixels on edges
23066 may or may not be included depending on actual geometry of the
23068 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23069 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23071 x0
= XINT (lx
), y0
= XINT (ly
);
23072 for (i
= 0; i
< n
; i
+= 2)
23074 int x1
= x0
, y1
= y0
;
23075 if ((lx
= poly
[i
], !INTEGERP (lx
))
23076 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23078 x0
= XINT (lx
), y0
= XINT (ly
);
23080 /* Does this segment cross the X line? */
23088 if (y
> y0
&& y
> y1
)
23090 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23100 find_hot_spot (map
, x
, y
)
23104 while (CONSP (map
))
23106 if (CONSP (XCAR (map
))
23107 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23115 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23117 doc
: /* Lookup in image map MAP coordinates X and Y.
23118 An image map is an alist where each element has the format (AREA ID PLIST).
23119 An AREA is specified as either a rectangle, a circle, or a polygon:
23120 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23121 pixel coordinates of the upper left and bottom right corners.
23122 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23123 and the radius of the circle; r may be a float or integer.
23124 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23125 vector describes one corner in the polygon.
23126 Returns the alist element for the first matching AREA in MAP. */)
23137 return find_hot_spot (map
, XINT (x
), XINT (y
));
23141 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23143 define_frame_cursor1 (f
, cursor
, pointer
)
23146 Lisp_Object pointer
;
23148 /* Do not change cursor shape while dragging mouse. */
23149 if (!NILP (do_mouse_tracking
))
23152 if (!NILP (pointer
))
23154 if (EQ (pointer
, Qarrow
))
23155 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23156 else if (EQ (pointer
, Qhand
))
23157 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23158 else if (EQ (pointer
, Qtext
))
23159 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23160 else if (EQ (pointer
, intern ("hdrag")))
23161 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23162 #ifdef HAVE_X_WINDOWS
23163 else if (EQ (pointer
, intern ("vdrag")))
23164 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23166 else if (EQ (pointer
, intern ("hourglass")))
23167 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23168 else if (EQ (pointer
, Qmodeline
))
23169 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23171 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23174 if (cursor
!= No_Cursor
)
23175 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23178 /* Take proper action when mouse has moved to the mode or header line
23179 or marginal area AREA of window W, x-position X and y-position Y.
23180 X is relative to the start of the text display area of W, so the
23181 width of bitmap areas and scroll bars must be subtracted to get a
23182 position relative to the start of the mode line. */
23185 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23186 Lisp_Object window
;
23188 enum window_part area
;
23190 struct window
*w
= XWINDOW (window
);
23191 struct frame
*f
= XFRAME (w
->frame
);
23192 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23193 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23194 Lisp_Object pointer
= Qnil
;
23195 int charpos
, dx
, dy
, width
, height
;
23196 Lisp_Object string
, object
= Qnil
;
23197 Lisp_Object pos
, help
;
23199 Lisp_Object mouse_face
;
23200 int original_x_pixel
= x
;
23201 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23202 struct glyph_row
*row
;
23204 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23209 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23210 &object
, &dx
, &dy
, &width
, &height
);
23212 row
= (area
== ON_MODE_LINE
23213 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23214 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23217 if (row
->mode_line_p
&& row
->enabled_p
)
23219 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23220 end
= glyph
+ row
->used
[TEXT_AREA
];
23222 for (x0
= original_x_pixel
;
23223 glyph
< end
&& x0
>= glyph
->pixel_width
;
23225 x0
-= glyph
->pixel_width
;
23233 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23234 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23235 &object
, &dx
, &dy
, &width
, &height
);
23240 if (IMAGEP (object
))
23242 Lisp_Object image_map
, hotspot
;
23243 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23245 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23247 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23249 Lisp_Object area_id
, plist
;
23251 area_id
= XCAR (hotspot
);
23252 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23253 If so, we could look for mouse-enter, mouse-leave
23254 properties in PLIST (and do something...). */
23255 hotspot
= XCDR (hotspot
);
23256 if (CONSP (hotspot
)
23257 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23259 pointer
= Fplist_get (plist
, Qpointer
);
23260 if (NILP (pointer
))
23262 help
= Fplist_get (plist
, Qhelp_echo
);
23265 help_echo_string
= help
;
23266 /* Is this correct? ++kfs */
23267 XSETWINDOW (help_echo_window
, w
);
23268 help_echo_object
= w
->buffer
;
23269 help_echo_pos
= charpos
;
23273 if (NILP (pointer
))
23274 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23277 if (STRINGP (string
))
23279 pos
= make_number (charpos
);
23280 /* If we're on a string with `help-echo' text property, arrange
23281 for the help to be displayed. This is done by setting the
23282 global variable help_echo_string to the help string. */
23285 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23288 help_echo_string
= help
;
23289 XSETWINDOW (help_echo_window
, w
);
23290 help_echo_object
= string
;
23291 help_echo_pos
= charpos
;
23295 if (NILP (pointer
))
23296 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23298 /* Change the mouse pointer according to what is under X/Y. */
23299 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23302 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23303 if (!KEYMAPP (map
))
23304 map
= Fget_text_property (pos
, Qkeymap
, string
);
23305 if (!KEYMAPP (map
))
23306 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23309 /* Change the mouse face according to what is under X/Y. */
23310 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23311 if (!NILP (mouse_face
)
23312 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23317 struct glyph
* tmp_glyph
;
23321 int total_pixel_width
;
23326 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23327 Qmouse_face
, string
, Qnil
);
23329 b
= make_number (0);
23331 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23333 e
= make_number (SCHARS (string
));
23335 /* Calculate the position(glyph position: GPOS) of GLYPH in
23336 displayed string. GPOS is different from CHARPOS.
23338 CHARPOS is the position of glyph in internal string
23339 object. A mode line string format has structures which
23340 is converted to a flatten by emacs lisp interpreter.
23341 The internal string is an element of the structures.
23342 The displayed string is the flatten string. */
23344 if (glyph
> row_start_glyph
)
23346 tmp_glyph
= glyph
- 1;
23347 while (tmp_glyph
>= row_start_glyph
23348 && tmp_glyph
->charpos
>= XINT (b
)
23349 && EQ (tmp_glyph
->object
, glyph
->object
))
23356 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23357 displayed string holding GLYPH.
23359 GSEQ_LENGTH is different from SCHARS (STRING).
23360 SCHARS (STRING) returns the length of the internal string. */
23361 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23362 tmp_glyph
->charpos
< XINT (e
);
23363 tmp_glyph
++, gseq_length
++)
23365 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23369 total_pixel_width
= 0;
23370 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23371 total_pixel_width
+= tmp_glyph
->pixel_width
;
23373 /* Pre calculation of re-rendering position */
23375 hpos
= (area
== ON_MODE_LINE
23376 ? (w
->current_matrix
)->nrows
- 1
23379 /* If the re-rendering position is included in the last
23380 re-rendering area, we should do nothing. */
23381 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23382 && dpyinfo
->mouse_face_beg_col
<= vpos
23383 && vpos
< dpyinfo
->mouse_face_end_col
23384 && dpyinfo
->mouse_face_beg_row
== hpos
)
23387 if (clear_mouse_face (dpyinfo
))
23388 cursor
= No_Cursor
;
23390 dpyinfo
->mouse_face_beg_col
= vpos
;
23391 dpyinfo
->mouse_face_beg_row
= hpos
;
23393 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23394 dpyinfo
->mouse_face_beg_y
= 0;
23396 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23397 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23399 dpyinfo
->mouse_face_end_x
= 0;
23400 dpyinfo
->mouse_face_end_y
= 0;
23402 dpyinfo
->mouse_face_past_end
= 0;
23403 dpyinfo
->mouse_face_window
= window
;
23405 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23408 glyph
->face_id
, 1);
23409 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23411 if (NILP (pointer
))
23414 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23415 clear_mouse_face (dpyinfo
);
23417 define_frame_cursor1 (f
, cursor
, pointer
);
23422 Take proper action when the mouse has moved to position X, Y on
23423 frame F as regards highlighting characters that have mouse-face
23424 properties. Also de-highlighting chars where the mouse was before.
23425 X and Y can be negative or out of range. */
23428 note_mouse_highlight (f
, x
, y
)
23432 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23433 enum window_part part
;
23434 Lisp_Object window
;
23436 Cursor cursor
= No_Cursor
;
23437 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23440 /* When a menu is active, don't highlight because this looks odd. */
23441 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
23442 if (popup_activated ())
23446 if (NILP (Vmouse_highlight
)
23447 || !f
->glyphs_initialized_p
)
23450 dpyinfo
->mouse_face_mouse_x
= x
;
23451 dpyinfo
->mouse_face_mouse_y
= y
;
23452 dpyinfo
->mouse_face_mouse_frame
= f
;
23454 if (dpyinfo
->mouse_face_defer
)
23457 if (gc_in_progress
)
23459 dpyinfo
->mouse_face_deferred_gc
= 1;
23463 /* Which window is that in? */
23464 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23466 /* If we were displaying active text in another window, clear that.
23467 Also clear if we move out of text area in same window. */
23468 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23469 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23470 && !NILP (dpyinfo
->mouse_face_window
)))
23471 clear_mouse_face (dpyinfo
);
23473 /* Not on a window -> return. */
23474 if (!WINDOWP (window
))
23477 /* Reset help_echo_string. It will get recomputed below. */
23478 help_echo_string
= Qnil
;
23480 /* Convert to window-relative pixel coordinates. */
23481 w
= XWINDOW (window
);
23482 frame_to_window_pixel_xy (w
, &x
, &y
);
23484 /* Handle tool-bar window differently since it doesn't display a
23486 if (EQ (window
, f
->tool_bar_window
))
23488 note_tool_bar_highlight (f
, x
, y
);
23492 /* Mouse is on the mode, header line or margin? */
23493 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23494 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23496 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23500 if (part
== ON_VERTICAL_BORDER
)
23502 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23503 help_echo_string
= build_string ("drag-mouse-1: resize");
23505 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23506 || part
== ON_SCROLL_BAR
)
23507 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23509 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23511 /* Are we in a window whose display is up to date?
23512 And verify the buffer's text has not changed. */
23513 b
= XBUFFER (w
->buffer
);
23514 if (part
== ON_TEXT
23515 && EQ (w
->window_end_valid
, w
->buffer
)
23516 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23517 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23519 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23520 struct glyph
*glyph
;
23521 Lisp_Object object
;
23522 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23523 Lisp_Object
*overlay_vec
= NULL
;
23525 struct buffer
*obuf
;
23526 int obegv
, ozv
, same_region
;
23528 /* Find the glyph under X/Y. */
23529 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23531 /* Look for :pointer property on image. */
23532 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23534 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23535 if (img
!= NULL
&& IMAGEP (img
->spec
))
23537 Lisp_Object image_map
, hotspot
;
23538 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23540 && (hotspot
= find_hot_spot (image_map
,
23541 glyph
->slice
.x
+ dx
,
23542 glyph
->slice
.y
+ dy
),
23544 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23546 Lisp_Object area_id
, plist
;
23548 area_id
= XCAR (hotspot
);
23549 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23550 If so, we could look for mouse-enter, mouse-leave
23551 properties in PLIST (and do something...). */
23552 hotspot
= XCDR (hotspot
);
23553 if (CONSP (hotspot
)
23554 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23556 pointer
= Fplist_get (plist
, Qpointer
);
23557 if (NILP (pointer
))
23559 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23560 if (!NILP (help_echo_string
))
23562 help_echo_window
= window
;
23563 help_echo_object
= glyph
->object
;
23564 help_echo_pos
= glyph
->charpos
;
23568 if (NILP (pointer
))
23569 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23573 /* Clear mouse face if X/Y not over text. */
23575 || area
!= TEXT_AREA
23576 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23578 if (clear_mouse_face (dpyinfo
))
23579 cursor
= No_Cursor
;
23580 if (NILP (pointer
))
23582 if (area
!= TEXT_AREA
)
23583 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23585 pointer
= Vvoid_text_area_pointer
;
23590 pos
= glyph
->charpos
;
23591 object
= glyph
->object
;
23592 if (!STRINGP (object
) && !BUFFERP (object
))
23595 /* If we get an out-of-range value, return now; avoid an error. */
23596 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23599 /* Make the window's buffer temporarily current for
23600 overlays_at and compute_char_face. */
23601 obuf
= current_buffer
;
23602 current_buffer
= b
;
23608 /* Is this char mouse-active or does it have help-echo? */
23609 position
= make_number (pos
);
23611 if (BUFFERP (object
))
23613 /* Put all the overlays we want in a vector in overlay_vec. */
23614 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23615 /* Sort overlays into increasing priority order. */
23616 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23621 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23622 && vpos
>= dpyinfo
->mouse_face_beg_row
23623 && vpos
<= dpyinfo
->mouse_face_end_row
23624 && (vpos
> dpyinfo
->mouse_face_beg_row
23625 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23626 && (vpos
< dpyinfo
->mouse_face_end_row
23627 || hpos
< dpyinfo
->mouse_face_end_col
23628 || dpyinfo
->mouse_face_past_end
));
23631 cursor
= No_Cursor
;
23633 /* Check mouse-face highlighting. */
23635 /* If there exists an overlay with mouse-face overlapping
23636 the one we are currently highlighting, we have to
23637 check if we enter the overlapping overlay, and then
23638 highlight only that. */
23639 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23640 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23642 /* Find the highest priority overlay that has a mouse-face
23645 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23647 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23648 if (!NILP (mouse_face
))
23649 overlay
= overlay_vec
[i
];
23652 /* If we're actually highlighting the same overlay as
23653 before, there's no need to do that again. */
23654 if (!NILP (overlay
)
23655 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23656 goto check_help_echo
;
23658 dpyinfo
->mouse_face_overlay
= overlay
;
23660 /* Clear the display of the old active region, if any. */
23661 if (clear_mouse_face (dpyinfo
))
23662 cursor
= No_Cursor
;
23664 /* If no overlay applies, get a text property. */
23665 if (NILP (overlay
))
23666 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23668 /* Handle the overlay case. */
23669 if (!NILP (overlay
))
23671 /* Find the range of text around this char that
23672 should be active. */
23673 Lisp_Object before
, after
;
23676 before
= Foverlay_start (overlay
);
23677 after
= Foverlay_end (overlay
);
23678 /* Record this as the current active region. */
23679 fast_find_position (w
, XFASTINT (before
),
23680 &dpyinfo
->mouse_face_beg_col
,
23681 &dpyinfo
->mouse_face_beg_row
,
23682 &dpyinfo
->mouse_face_beg_x
,
23683 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23685 dpyinfo
->mouse_face_past_end
23686 = !fast_find_position (w
, XFASTINT (after
),
23687 &dpyinfo
->mouse_face_end_col
,
23688 &dpyinfo
->mouse_face_end_row
,
23689 &dpyinfo
->mouse_face_end_x
,
23690 &dpyinfo
->mouse_face_end_y
, Qnil
);
23691 dpyinfo
->mouse_face_window
= window
;
23693 dpyinfo
->mouse_face_face_id
23694 = face_at_buffer_position (w
, pos
, 0, 0,
23696 !dpyinfo
->mouse_face_hidden
);
23698 /* Display it as active. */
23699 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23700 cursor
= No_Cursor
;
23702 /* Handle the text property case. */
23703 else if (!NILP (mouse_face
) && BUFFERP (object
))
23705 /* Find the range of text around this char that
23706 should be active. */
23707 Lisp_Object before
, after
, beginning
, end
;
23710 beginning
= Fmarker_position (w
->start
);
23711 end
= make_number (BUF_Z (XBUFFER (object
))
23712 - XFASTINT (w
->window_end_pos
));
23714 = Fprevious_single_property_change (make_number (pos
+ 1),
23716 object
, beginning
);
23718 = Fnext_single_property_change (position
, Qmouse_face
,
23721 /* Record this as the current active region. */
23722 fast_find_position (w
, XFASTINT (before
),
23723 &dpyinfo
->mouse_face_beg_col
,
23724 &dpyinfo
->mouse_face_beg_row
,
23725 &dpyinfo
->mouse_face_beg_x
,
23726 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23727 dpyinfo
->mouse_face_past_end
23728 = !fast_find_position (w
, XFASTINT (after
),
23729 &dpyinfo
->mouse_face_end_col
,
23730 &dpyinfo
->mouse_face_end_row
,
23731 &dpyinfo
->mouse_face_end_x
,
23732 &dpyinfo
->mouse_face_end_y
, Qnil
);
23733 dpyinfo
->mouse_face_window
= window
;
23735 if (BUFFERP (object
))
23736 dpyinfo
->mouse_face_face_id
23737 = face_at_buffer_position (w
, pos
, 0, 0,
23739 !dpyinfo
->mouse_face_hidden
);
23741 /* Display it as active. */
23742 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23743 cursor
= No_Cursor
;
23745 else if (!NILP (mouse_face
) && STRINGP (object
))
23750 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23753 e
= Fnext_single_property_change (position
, Qmouse_face
,
23756 b
= make_number (0);
23758 e
= make_number (SCHARS (object
) - 1);
23760 fast_find_string_pos (w
, XINT (b
), object
,
23761 &dpyinfo
->mouse_face_beg_col
,
23762 &dpyinfo
->mouse_face_beg_row
,
23763 &dpyinfo
->mouse_face_beg_x
,
23764 &dpyinfo
->mouse_face_beg_y
, 0);
23765 fast_find_string_pos (w
, XINT (e
), object
,
23766 &dpyinfo
->mouse_face_end_col
,
23767 &dpyinfo
->mouse_face_end_row
,
23768 &dpyinfo
->mouse_face_end_x
,
23769 &dpyinfo
->mouse_face_end_y
, 1);
23770 dpyinfo
->mouse_face_past_end
= 0;
23771 dpyinfo
->mouse_face_window
= window
;
23772 dpyinfo
->mouse_face_face_id
23773 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23774 glyph
->face_id
, 1);
23775 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23776 cursor
= No_Cursor
;
23778 else if (STRINGP (object
) && NILP (mouse_face
))
23780 /* A string which doesn't have mouse-face, but
23781 the text ``under'' it might have. */
23782 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23783 int start
= MATRIX_ROW_START_CHARPOS (r
);
23785 pos
= string_buffer_position (w
, object
, start
);
23787 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23791 if (!NILP (mouse_face
) && !NILP (overlay
))
23793 Lisp_Object before
= Foverlay_start (overlay
);
23794 Lisp_Object after
= Foverlay_end (overlay
);
23797 /* Note that we might not be able to find position
23798 BEFORE in the glyph matrix if the overlay is
23799 entirely covered by a `display' property. In
23800 this case, we overshoot. So let's stop in
23801 the glyph matrix before glyphs for OBJECT. */
23802 fast_find_position (w
, XFASTINT (before
),
23803 &dpyinfo
->mouse_face_beg_col
,
23804 &dpyinfo
->mouse_face_beg_row
,
23805 &dpyinfo
->mouse_face_beg_x
,
23806 &dpyinfo
->mouse_face_beg_y
,
23809 dpyinfo
->mouse_face_past_end
23810 = !fast_find_position (w
, XFASTINT (after
),
23811 &dpyinfo
->mouse_face_end_col
,
23812 &dpyinfo
->mouse_face_end_row
,
23813 &dpyinfo
->mouse_face_end_x
,
23814 &dpyinfo
->mouse_face_end_y
,
23816 dpyinfo
->mouse_face_window
= window
;
23817 dpyinfo
->mouse_face_face_id
23818 = face_at_buffer_position (w
, pos
, 0, 0,
23820 !dpyinfo
->mouse_face_hidden
);
23822 /* Display it as active. */
23823 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23824 cursor
= No_Cursor
;
23831 /* Look for a `help-echo' property. */
23832 if (NILP (help_echo_string
)) {
23833 Lisp_Object help
, overlay
;
23835 /* Check overlays first. */
23836 help
= overlay
= Qnil
;
23837 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23839 overlay
= overlay_vec
[i
];
23840 help
= Foverlay_get (overlay
, Qhelp_echo
);
23845 help_echo_string
= help
;
23846 help_echo_window
= window
;
23847 help_echo_object
= overlay
;
23848 help_echo_pos
= pos
;
23852 Lisp_Object object
= glyph
->object
;
23853 int charpos
= glyph
->charpos
;
23855 /* Try text properties. */
23856 if (STRINGP (object
)
23858 && charpos
< SCHARS (object
))
23860 help
= Fget_text_property (make_number (charpos
),
23861 Qhelp_echo
, object
);
23864 /* If the string itself doesn't specify a help-echo,
23865 see if the buffer text ``under'' it does. */
23866 struct glyph_row
*r
23867 = MATRIX_ROW (w
->current_matrix
, vpos
);
23868 int start
= MATRIX_ROW_START_CHARPOS (r
);
23869 int pos
= string_buffer_position (w
, object
, start
);
23872 help
= Fget_char_property (make_number (pos
),
23873 Qhelp_echo
, w
->buffer
);
23877 object
= w
->buffer
;
23882 else if (BUFFERP (object
)
23885 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23890 help_echo_string
= help
;
23891 help_echo_window
= window
;
23892 help_echo_object
= object
;
23893 help_echo_pos
= charpos
;
23898 /* Look for a `pointer' property. */
23899 if (NILP (pointer
))
23901 /* Check overlays first. */
23902 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23903 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23905 if (NILP (pointer
))
23907 Lisp_Object object
= glyph
->object
;
23908 int charpos
= glyph
->charpos
;
23910 /* Try text properties. */
23911 if (STRINGP (object
)
23913 && charpos
< SCHARS (object
))
23915 pointer
= Fget_text_property (make_number (charpos
),
23917 if (NILP (pointer
))
23919 /* If the string itself doesn't specify a pointer,
23920 see if the buffer text ``under'' it does. */
23921 struct glyph_row
*r
23922 = MATRIX_ROW (w
->current_matrix
, vpos
);
23923 int start
= MATRIX_ROW_START_CHARPOS (r
);
23924 int pos
= string_buffer_position (w
, object
, start
);
23926 pointer
= Fget_char_property (make_number (pos
),
23927 Qpointer
, w
->buffer
);
23930 else if (BUFFERP (object
)
23933 pointer
= Fget_text_property (make_number (charpos
),
23940 current_buffer
= obuf
;
23945 define_frame_cursor1 (f
, cursor
, pointer
);
23950 Clear any mouse-face on window W. This function is part of the
23951 redisplay interface, and is called from try_window_id and similar
23952 functions to ensure the mouse-highlight is off. */
23955 x_clear_window_mouse_face (w
)
23958 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23959 Lisp_Object window
;
23962 XSETWINDOW (window
, w
);
23963 if (EQ (window
, dpyinfo
->mouse_face_window
))
23964 clear_mouse_face (dpyinfo
);
23970 Just discard the mouse face information for frame F, if any.
23971 This is used when the size of F is changed. */
23974 cancel_mouse_face (f
)
23977 Lisp_Object window
;
23978 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23980 window
= dpyinfo
->mouse_face_window
;
23981 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23983 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23984 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23985 dpyinfo
->mouse_face_window
= Qnil
;
23990 #endif /* HAVE_WINDOW_SYSTEM */
23993 /***********************************************************************
23995 ***********************************************************************/
23997 #ifdef HAVE_WINDOW_SYSTEM
23999 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24000 which intersects rectangle R. R is in window-relative coordinates. */
24003 expose_area (w
, row
, r
, area
)
24005 struct glyph_row
*row
;
24007 enum glyph_row_area area
;
24009 struct glyph
*first
= row
->glyphs
[area
];
24010 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24011 struct glyph
*last
;
24012 int first_x
, start_x
, x
;
24014 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24015 /* If row extends face to end of line write the whole line. */
24016 draw_glyphs (w
, 0, row
, area
,
24017 0, row
->used
[area
],
24018 DRAW_NORMAL_TEXT
, 0);
24021 /* Set START_X to the window-relative start position for drawing glyphs of
24022 AREA. The first glyph of the text area can be partially visible.
24023 The first glyphs of other areas cannot. */
24024 start_x
= window_box_left_offset (w
, area
);
24026 if (area
== TEXT_AREA
)
24029 /* Find the first glyph that must be redrawn. */
24031 && x
+ first
->pixel_width
< r
->x
)
24033 x
+= first
->pixel_width
;
24037 /* Find the last one. */
24041 && x
< r
->x
+ r
->width
)
24043 x
+= last
->pixel_width
;
24049 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24050 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24051 DRAW_NORMAL_TEXT
, 0);
24056 /* Redraw the parts of the glyph row ROW on window W intersecting
24057 rectangle R. R is in window-relative coordinates. Value is
24058 non-zero if mouse-face was overwritten. */
24061 expose_line (w
, row
, r
)
24063 struct glyph_row
*row
;
24066 xassert (row
->enabled_p
);
24068 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24069 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24070 0, row
->used
[TEXT_AREA
],
24071 DRAW_NORMAL_TEXT
, 0);
24074 if (row
->used
[LEFT_MARGIN_AREA
])
24075 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24076 if (row
->used
[TEXT_AREA
])
24077 expose_area (w
, row
, r
, TEXT_AREA
);
24078 if (row
->used
[RIGHT_MARGIN_AREA
])
24079 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24080 draw_row_fringe_bitmaps (w
, row
);
24083 return row
->mouse_face_p
;
24087 /* Redraw those parts of glyphs rows during expose event handling that
24088 overlap other rows. Redrawing of an exposed line writes over parts
24089 of lines overlapping that exposed line; this function fixes that.
24091 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24092 row in W's current matrix that is exposed and overlaps other rows.
24093 LAST_OVERLAPPING_ROW is the last such row. */
24096 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24098 struct glyph_row
*first_overlapping_row
;
24099 struct glyph_row
*last_overlapping_row
;
24102 struct glyph_row
*row
;
24104 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24105 if (row
->overlapping_p
)
24107 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24110 if (row
->used
[LEFT_MARGIN_AREA
])
24111 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24113 if (row
->used
[TEXT_AREA
])
24114 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24116 if (row
->used
[RIGHT_MARGIN_AREA
])
24117 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24123 /* Return non-zero if W's cursor intersects rectangle R. */
24126 phys_cursor_in_rect_p (w
, r
)
24130 XRectangle cr
, result
;
24131 struct glyph
*cursor_glyph
;
24132 struct glyph_row
*row
;
24134 if (w
->phys_cursor
.vpos
>= 0
24135 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24136 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24138 && row
->cursor_in_fringe_p
)
24140 /* Cursor is in the fringe. */
24141 cr
.x
= window_box_right_offset (w
,
24142 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24143 ? RIGHT_MARGIN_AREA
24146 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24147 cr
.height
= row
->height
;
24148 return x_intersect_rectangles (&cr
, r
, &result
);
24151 cursor_glyph
= get_phys_cursor_glyph (w
);
24154 /* r is relative to W's box, but w->phys_cursor.x is relative
24155 to left edge of W's TEXT area. Adjust it. */
24156 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24157 cr
.y
= w
->phys_cursor
.y
;
24158 cr
.width
= cursor_glyph
->pixel_width
;
24159 cr
.height
= w
->phys_cursor_height
;
24160 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24161 I assume the effect is the same -- and this is portable. */
24162 return x_intersect_rectangles (&cr
, r
, &result
);
24164 /* If we don't understand the format, pretend we're not in the hot-spot. */
24170 Draw a vertical window border to the right of window W if W doesn't
24171 have vertical scroll bars. */
24174 x_draw_vertical_border (w
)
24177 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24179 /* We could do better, if we knew what type of scroll-bar the adjacent
24180 windows (on either side) have... But we don't :-(
24181 However, I think this works ok. ++KFS 2003-04-25 */
24183 /* Redraw borders between horizontally adjacent windows. Don't
24184 do it for frames with vertical scroll bars because either the
24185 right scroll bar of a window, or the left scroll bar of its
24186 neighbor will suffice as a border. */
24187 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24190 if (!WINDOW_RIGHTMOST_P (w
)
24191 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24193 int x0
, x1
, y0
, y1
;
24195 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24198 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24201 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24203 else if (!WINDOW_LEFTMOST_P (w
)
24204 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24206 int x0
, x1
, y0
, y1
;
24208 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24211 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24214 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24219 /* Redraw the part of window W intersection rectangle FR. Pixel
24220 coordinates in FR are frame-relative. Call this function with
24221 input blocked. Value is non-zero if the exposure overwrites
24225 expose_window (w
, fr
)
24229 struct frame
*f
= XFRAME (w
->frame
);
24231 int mouse_face_overwritten_p
= 0;
24233 /* If window is not yet fully initialized, do nothing. This can
24234 happen when toolkit scroll bars are used and a window is split.
24235 Reconfiguring the scroll bar will generate an expose for a newly
24237 if (w
->current_matrix
== NULL
)
24240 /* When we're currently updating the window, display and current
24241 matrix usually don't agree. Arrange for a thorough display
24243 if (w
== updated_window
)
24245 SET_FRAME_GARBAGED (f
);
24249 /* Frame-relative pixel rectangle of W. */
24250 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24251 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24252 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24253 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24255 if (x_intersect_rectangles (fr
, &wr
, &r
))
24257 int yb
= window_text_bottom_y (w
);
24258 struct glyph_row
*row
;
24259 int cursor_cleared_p
;
24260 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24262 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24263 r
.x
, r
.y
, r
.width
, r
.height
));
24265 /* Convert to window coordinates. */
24266 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24267 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24269 /* Turn off the cursor. */
24270 if (!w
->pseudo_window_p
24271 && phys_cursor_in_rect_p (w
, &r
))
24273 x_clear_cursor (w
);
24274 cursor_cleared_p
= 1;
24277 cursor_cleared_p
= 0;
24279 /* Update lines intersecting rectangle R. */
24280 first_overlapping_row
= last_overlapping_row
= NULL
;
24281 for (row
= w
->current_matrix
->rows
;
24286 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24288 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24289 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24290 || (r
.y
>= y0
&& r
.y
< y1
)
24291 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24293 /* A header line may be overlapping, but there is no need
24294 to fix overlapping areas for them. KFS 2005-02-12 */
24295 if (row
->overlapping_p
&& !row
->mode_line_p
)
24297 if (first_overlapping_row
== NULL
)
24298 first_overlapping_row
= row
;
24299 last_overlapping_row
= row
;
24303 if (expose_line (w
, row
, &r
))
24304 mouse_face_overwritten_p
= 1;
24307 else if (row
->overlapping_p
)
24309 /* We must redraw a row overlapping the exposed area. */
24311 ? y0
+ row
->phys_height
> r
.y
24312 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24314 if (first_overlapping_row
== NULL
)
24315 first_overlapping_row
= row
;
24316 last_overlapping_row
= row
;
24324 /* Display the mode line if there is one. */
24325 if (WINDOW_WANTS_MODELINE_P (w
)
24326 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24328 && row
->y
< r
.y
+ r
.height
)
24330 if (expose_line (w
, row
, &r
))
24331 mouse_face_overwritten_p
= 1;
24334 if (!w
->pseudo_window_p
)
24336 /* Fix the display of overlapping rows. */
24337 if (first_overlapping_row
)
24338 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24341 /* Draw border between windows. */
24342 x_draw_vertical_border (w
);
24344 /* Turn the cursor on again. */
24345 if (cursor_cleared_p
)
24346 update_window_cursor (w
, 1);
24350 return mouse_face_overwritten_p
;
24355 /* Redraw (parts) of all windows in the window tree rooted at W that
24356 intersect R. R contains frame pixel coordinates. Value is
24357 non-zero if the exposure overwrites mouse-face. */
24360 expose_window_tree (w
, r
)
24364 struct frame
*f
= XFRAME (w
->frame
);
24365 int mouse_face_overwritten_p
= 0;
24367 while (w
&& !FRAME_GARBAGED_P (f
))
24369 if (!NILP (w
->hchild
))
24370 mouse_face_overwritten_p
24371 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24372 else if (!NILP (w
->vchild
))
24373 mouse_face_overwritten_p
24374 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24376 mouse_face_overwritten_p
|= expose_window (w
, r
);
24378 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24381 return mouse_face_overwritten_p
;
24386 Redisplay an exposed area of frame F. X and Y are the upper-left
24387 corner of the exposed rectangle. W and H are width and height of
24388 the exposed area. All are pixel values. W or H zero means redraw
24389 the entire frame. */
24392 expose_frame (f
, x
, y
, w
, h
)
24397 int mouse_face_overwritten_p
= 0;
24399 TRACE ((stderr
, "expose_frame "));
24401 /* No need to redraw if frame will be redrawn soon. */
24402 if (FRAME_GARBAGED_P (f
))
24404 TRACE ((stderr
, " garbaged\n"));
24408 /* If basic faces haven't been realized yet, there is no point in
24409 trying to redraw anything. This can happen when we get an expose
24410 event while Emacs is starting, e.g. by moving another window. */
24411 if (FRAME_FACE_CACHE (f
) == NULL
24412 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24414 TRACE ((stderr
, " no faces\n"));
24418 if (w
== 0 || h
== 0)
24421 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24422 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24432 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24433 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24435 if (WINDOWP (f
->tool_bar_window
))
24436 mouse_face_overwritten_p
24437 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24439 #ifdef HAVE_X_WINDOWS
24441 #ifndef USE_X_TOOLKIT
24442 if (WINDOWP (f
->menu_bar_window
))
24443 mouse_face_overwritten_p
24444 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24445 #endif /* not USE_X_TOOLKIT */
24449 /* Some window managers support a focus-follows-mouse style with
24450 delayed raising of frames. Imagine a partially obscured frame,
24451 and moving the mouse into partially obscured mouse-face on that
24452 frame. The visible part of the mouse-face will be highlighted,
24453 then the WM raises the obscured frame. With at least one WM, KDE
24454 2.1, Emacs is not getting any event for the raising of the frame
24455 (even tried with SubstructureRedirectMask), only Expose events.
24456 These expose events will draw text normally, i.e. not
24457 highlighted. Which means we must redo the highlight here.
24458 Subsume it under ``we love X''. --gerd 2001-08-15 */
24459 /* Included in Windows version because Windows most likely does not
24460 do the right thing if any third party tool offers
24461 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24462 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24464 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24465 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24467 int x
= dpyinfo
->mouse_face_mouse_x
;
24468 int y
= dpyinfo
->mouse_face_mouse_y
;
24469 clear_mouse_face (dpyinfo
);
24470 note_mouse_highlight (f
, x
, y
);
24477 Determine the intersection of two rectangles R1 and R2. Return
24478 the intersection in *RESULT. Value is non-zero if RESULT is not
24482 x_intersect_rectangles (r1
, r2
, result
)
24483 XRectangle
*r1
, *r2
, *result
;
24485 XRectangle
*left
, *right
;
24486 XRectangle
*upper
, *lower
;
24487 int intersection_p
= 0;
24489 /* Rearrange so that R1 is the left-most rectangle. */
24491 left
= r1
, right
= r2
;
24493 left
= r2
, right
= r1
;
24495 /* X0 of the intersection is right.x0, if this is inside R1,
24496 otherwise there is no intersection. */
24497 if (right
->x
<= left
->x
+ left
->width
)
24499 result
->x
= right
->x
;
24501 /* The right end of the intersection is the minimum of the
24502 the right ends of left and right. */
24503 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24506 /* Same game for Y. */
24508 upper
= r1
, lower
= r2
;
24510 upper
= r2
, lower
= r1
;
24512 /* The upper end of the intersection is lower.y0, if this is inside
24513 of upper. Otherwise, there is no intersection. */
24514 if (lower
->y
<= upper
->y
+ upper
->height
)
24516 result
->y
= lower
->y
;
24518 /* The lower end of the intersection is the minimum of the lower
24519 ends of upper and lower. */
24520 result
->height
= (min (lower
->y
+ lower
->height
,
24521 upper
->y
+ upper
->height
)
24523 intersection_p
= 1;
24527 return intersection_p
;
24530 #endif /* HAVE_WINDOW_SYSTEM */
24533 /***********************************************************************
24535 ***********************************************************************/
24540 Vwith_echo_area_save_vector
= Qnil
;
24541 staticpro (&Vwith_echo_area_save_vector
);
24543 Vmessage_stack
= Qnil
;
24544 staticpro (&Vmessage_stack
);
24546 Qinhibit_redisplay
= intern ("inhibit-redisplay");
24547 staticpro (&Qinhibit_redisplay
);
24549 message_dolog_marker1
= Fmake_marker ();
24550 staticpro (&message_dolog_marker1
);
24551 message_dolog_marker2
= Fmake_marker ();
24552 staticpro (&message_dolog_marker2
);
24553 message_dolog_marker3
= Fmake_marker ();
24554 staticpro (&message_dolog_marker3
);
24557 defsubr (&Sdump_frame_glyph_matrix
);
24558 defsubr (&Sdump_glyph_matrix
);
24559 defsubr (&Sdump_glyph_row
);
24560 defsubr (&Sdump_tool_bar_row
);
24561 defsubr (&Strace_redisplay
);
24562 defsubr (&Strace_to_stderr
);
24564 #ifdef HAVE_WINDOW_SYSTEM
24565 defsubr (&Stool_bar_lines_needed
);
24566 defsubr (&Slookup_image_map
);
24568 defsubr (&Sformat_mode_line
);
24569 defsubr (&Sinvisible_p
);
24571 staticpro (&Qmenu_bar_update_hook
);
24572 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
24574 staticpro (&Qoverriding_terminal_local_map
);
24575 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
24577 staticpro (&Qoverriding_local_map
);
24578 Qoverriding_local_map
= intern ("overriding-local-map");
24580 staticpro (&Qwindow_scroll_functions
);
24581 Qwindow_scroll_functions
= intern ("window-scroll-functions");
24583 staticpro (&Qwindow_text_change_functions
);
24584 Qwindow_text_change_functions
= intern ("window-text-change-functions");
24586 staticpro (&Qredisplay_end_trigger_functions
);
24587 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
24589 staticpro (&Qinhibit_point_motion_hooks
);
24590 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
24592 Qeval
= intern ("eval");
24593 staticpro (&Qeval
);
24595 QCdata
= intern (":data");
24596 staticpro (&QCdata
);
24597 Qdisplay
= intern ("display");
24598 staticpro (&Qdisplay
);
24599 Qspace_width
= intern ("space-width");
24600 staticpro (&Qspace_width
);
24601 Qraise
= intern ("raise");
24602 staticpro (&Qraise
);
24603 Qslice
= intern ("slice");
24604 staticpro (&Qslice
);
24605 Qspace
= intern ("space");
24606 staticpro (&Qspace
);
24607 Qmargin
= intern ("margin");
24608 staticpro (&Qmargin
);
24609 Qpointer
= intern ("pointer");
24610 staticpro (&Qpointer
);
24611 Qleft_margin
= intern ("left-margin");
24612 staticpro (&Qleft_margin
);
24613 Qright_margin
= intern ("right-margin");
24614 staticpro (&Qright_margin
);
24615 Qcenter
= intern ("center");
24616 staticpro (&Qcenter
);
24617 Qline_height
= intern ("line-height");
24618 staticpro (&Qline_height
);
24619 QCalign_to
= intern (":align-to");
24620 staticpro (&QCalign_to
);
24621 QCrelative_width
= intern (":relative-width");
24622 staticpro (&QCrelative_width
);
24623 QCrelative_height
= intern (":relative-height");
24624 staticpro (&QCrelative_height
);
24625 QCeval
= intern (":eval");
24626 staticpro (&QCeval
);
24627 QCpropertize
= intern (":propertize");
24628 staticpro (&QCpropertize
);
24629 QCfile
= intern (":file");
24630 staticpro (&QCfile
);
24631 Qfontified
= intern ("fontified");
24632 staticpro (&Qfontified
);
24633 Qfontification_functions
= intern ("fontification-functions");
24634 staticpro (&Qfontification_functions
);
24635 Qtrailing_whitespace
= intern ("trailing-whitespace");
24636 staticpro (&Qtrailing_whitespace
);
24637 Qescape_glyph
= intern ("escape-glyph");
24638 staticpro (&Qescape_glyph
);
24639 Qnobreak_space
= intern ("nobreak-space");
24640 staticpro (&Qnobreak_space
);
24641 Qimage
= intern ("image");
24642 staticpro (&Qimage
);
24643 QCmap
= intern (":map");
24644 staticpro (&QCmap
);
24645 QCpointer
= intern (":pointer");
24646 staticpro (&QCpointer
);
24647 Qrect
= intern ("rect");
24648 staticpro (&Qrect
);
24649 Qcircle
= intern ("circle");
24650 staticpro (&Qcircle
);
24651 Qpoly
= intern ("poly");
24652 staticpro (&Qpoly
);
24653 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24654 staticpro (&Qmessage_truncate_lines
);
24655 Qgrow_only
= intern ("grow-only");
24656 staticpro (&Qgrow_only
);
24657 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24658 staticpro (&Qinhibit_menubar_update
);
24659 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24660 staticpro (&Qinhibit_eval_during_redisplay
);
24661 Qposition
= intern ("position");
24662 staticpro (&Qposition
);
24663 Qbuffer_position
= intern ("buffer-position");
24664 staticpro (&Qbuffer_position
);
24665 Qobject
= intern ("object");
24666 staticpro (&Qobject
);
24667 Qbar
= intern ("bar");
24669 Qhbar
= intern ("hbar");
24670 staticpro (&Qhbar
);
24671 Qbox
= intern ("box");
24673 Qhollow
= intern ("hollow");
24674 staticpro (&Qhollow
);
24675 Qhand
= intern ("hand");
24676 staticpro (&Qhand
);
24677 Qarrow
= intern ("arrow");
24678 staticpro (&Qarrow
);
24679 Qtext
= intern ("text");
24680 staticpro (&Qtext
);
24681 Qrisky_local_variable
= intern ("risky-local-variable");
24682 staticpro (&Qrisky_local_variable
);
24683 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24684 staticpro (&Qinhibit_free_realized_faces
);
24686 list_of_error
= Fcons (Fcons (intern ("error"),
24687 Fcons (intern ("void-variable"), Qnil
)),
24689 staticpro (&list_of_error
);
24691 Qlast_arrow_position
= intern ("last-arrow-position");
24692 staticpro (&Qlast_arrow_position
);
24693 Qlast_arrow_string
= intern ("last-arrow-string");
24694 staticpro (&Qlast_arrow_string
);
24696 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24697 staticpro (&Qoverlay_arrow_string
);
24698 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24699 staticpro (&Qoverlay_arrow_bitmap
);
24701 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24702 staticpro (&echo_buffer
[0]);
24703 staticpro (&echo_buffer
[1]);
24705 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24706 staticpro (&echo_area_buffer
[0]);
24707 staticpro (&echo_area_buffer
[1]);
24709 Vmessages_buffer_name
= build_string ("*Messages*");
24710 staticpro (&Vmessages_buffer_name
);
24712 mode_line_proptrans_alist
= Qnil
;
24713 staticpro (&mode_line_proptrans_alist
);
24714 mode_line_string_list
= Qnil
;
24715 staticpro (&mode_line_string_list
);
24716 mode_line_string_face
= Qnil
;
24717 staticpro (&mode_line_string_face
);
24718 mode_line_string_face_prop
= Qnil
;
24719 staticpro (&mode_line_string_face_prop
);
24720 Vmode_line_unwind_vector
= Qnil
;
24721 staticpro (&Vmode_line_unwind_vector
);
24723 help_echo_string
= Qnil
;
24724 staticpro (&help_echo_string
);
24725 help_echo_object
= Qnil
;
24726 staticpro (&help_echo_object
);
24727 help_echo_window
= Qnil
;
24728 staticpro (&help_echo_window
);
24729 previous_help_echo_string
= Qnil
;
24730 staticpro (&previous_help_echo_string
);
24731 help_echo_pos
= -1;
24733 #ifdef HAVE_WINDOW_SYSTEM
24734 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24735 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24736 For example, if a block cursor is over a tab, it will be drawn as
24737 wide as that tab on the display. */);
24738 x_stretch_cursor_p
= 0;
24741 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24742 doc
: /* *Non-nil means highlight trailing whitespace.
24743 The face used for trailing whitespace is `trailing-whitespace'. */);
24744 Vshow_trailing_whitespace
= Qnil
;
24746 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24747 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24748 A value of t means highlight the character itself (for nobreak space,
24749 use face `nobreak-space').
24750 A value of nil means no highlighting.
24751 Other values mean display the escape glyph followed by an ordinary
24752 space or ordinary hyphen. */);
24753 Vnobreak_char_display
= Qt
;
24755 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24756 doc
: /* *The pointer shape to show in void text areas.
24757 A value of nil means to show the text pointer. Other options are `arrow',
24758 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24759 Vvoid_text_area_pointer
= Qarrow
;
24761 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24762 doc
: /* Non-nil means don't actually do any redisplay.
24763 This is used for internal purposes. */);
24764 Vinhibit_redisplay
= Qnil
;
24766 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24767 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24768 Vglobal_mode_string
= Qnil
;
24770 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24771 doc
: /* Marker for where to display an arrow on top of the buffer text.
24772 This must be the beginning of a line in order to work.
24773 See also `overlay-arrow-string'. */);
24774 Voverlay_arrow_position
= Qnil
;
24776 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24777 doc
: /* String to display as an arrow in non-window frames.
24778 See also `overlay-arrow-position'. */);
24779 Voverlay_arrow_string
= build_string ("=>");
24781 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24782 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24783 The symbols on this list are examined during redisplay to determine
24784 where to display overlay arrows. */);
24785 Voverlay_arrow_variable_list
24786 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24788 DEFVAR_INT ("scroll-step", &scroll_step
,
24789 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24790 If that fails to bring point back on frame, point is centered instead.
24791 If this is zero, point is always centered after it moves off frame.
24792 If you want scrolling to always be a line at a time, you should set
24793 `scroll-conservatively' to a large value rather than set this to 1. */);
24795 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24796 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24797 If point moves off-screen, redisplay will scroll by up to
24798 `scroll-conservatively' lines in order to bring point just barely
24799 onto the screen again. If that cannot be done, then redisplay
24800 recenters point as usual.
24802 A value of zero means always recenter point if it moves off screen. */);
24803 scroll_conservatively
= 0;
24805 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24806 doc
: /* *Number of lines of margin at the top and bottom of a window.
24807 Recenter the window whenever point gets within this many lines
24808 of the top or bottom of the window. */);
24811 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24812 doc
: /* Pixels per inch value for non-window system displays.
24813 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24814 Vdisplay_pixels_per_inch
= make_float (72.0);
24817 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24820 DEFVAR_LISP ("truncate-partial-width-windows",
24821 &Vtruncate_partial_width_windows
,
24822 doc
: /* Non-nil means truncate lines in windows with less than the frame width.
24823 For an integer value, truncate lines in each window with less than the
24824 full frame width, provided the window width is less than that integer;
24825 otherwise, respect the value of `truncate-lines'.
24827 For any other non-nil value, truncate lines in all windows with
24828 less than the full frame width.
24830 A value of nil means to respect the value of `truncate-lines'. */);
24831 Vtruncate_partial_width_windows
= make_number (30);
24833 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24834 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24835 Any other value means to use the appropriate face, `mode-line',
24836 `header-line', or `menu' respectively. */);
24837 mode_line_inverse_video
= 1;
24839 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24840 doc
: /* *Maximum buffer size for which line number should be displayed.
24841 If the buffer is bigger than this, the line number does not appear
24842 in the mode line. A value of nil means no limit. */);
24843 Vline_number_display_limit
= Qnil
;
24845 DEFVAR_INT ("line-number-display-limit-width",
24846 &line_number_display_limit_width
,
24847 doc
: /* *Maximum line width (in characters) for line number display.
24848 If the average length of the lines near point is bigger than this, then the
24849 line number may be omitted from the mode line. */);
24850 line_number_display_limit_width
= 200;
24852 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24853 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24854 highlight_nonselected_windows
= 0;
24856 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24857 doc
: /* Non-nil if more than one frame is visible on this display.
24858 Minibuffer-only frames don't count, but iconified frames do.
24859 This variable is not guaranteed to be accurate except while processing
24860 `frame-title-format' and `icon-title-format'. */);
24862 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24863 doc
: /* Template for displaying the title bar of visible frames.
24864 \(Assuming the window manager supports this feature.)
24866 This variable has the same structure as `mode-line-format', except that
24867 the %c and %l constructs are ignored. It is used only on frames for
24868 which no explicit name has been set \(see `modify-frame-parameters'). */);
24870 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24871 doc
: /* Template for displaying the title bar of an iconified frame.
24872 \(Assuming the window manager supports this feature.)
24873 This variable has the same structure as `mode-line-format' (which see),
24874 and is used only on frames for which no explicit name has been set
24875 \(see `modify-frame-parameters'). */);
24877 = Vframe_title_format
24878 = Fcons (intern ("multiple-frames"),
24879 Fcons (build_string ("%b"),
24880 Fcons (Fcons (empty_unibyte_string
,
24881 Fcons (intern ("invocation-name"),
24882 Fcons (build_string ("@"),
24883 Fcons (intern ("system-name"),
24887 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24888 doc
: /* Maximum number of lines to keep in the message log buffer.
24889 If nil, disable message logging. If t, log messages but don't truncate
24890 the buffer when it becomes large. */);
24891 Vmessage_log_max
= make_number (100);
24893 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24894 doc
: /* Functions called before redisplay, if window sizes have changed.
24895 The value should be a list of functions that take one argument.
24896 Just before redisplay, for each frame, if any of its windows have changed
24897 size since the last redisplay, or have been split or deleted,
24898 all the functions in the list are called, with the frame as argument. */);
24899 Vwindow_size_change_functions
= Qnil
;
24901 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24902 doc
: /* List of functions to call before redisplaying a window with scrolling.
24903 Each function is called with two arguments, the window
24904 and its new display-start position. Note that the value of `window-end'
24905 is not valid when these functions are called. */);
24906 Vwindow_scroll_functions
= Qnil
;
24908 DEFVAR_LISP ("window-text-change-functions",
24909 &Vwindow_text_change_functions
,
24910 doc
: /* Functions to call in redisplay when text in the window might change. */);
24911 Vwindow_text_change_functions
= Qnil
;
24913 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24914 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24915 Each function is called with two arguments, the window and the end trigger value.
24916 See `set-window-redisplay-end-trigger'. */);
24917 Vredisplay_end_trigger_functions
= Qnil
;
24919 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24920 doc
: /* *Non-nil means autoselect window with mouse pointer.
24921 If nil, do not autoselect windows.
24922 A positive number means delay autoselection by that many seconds: a
24923 window is autoselected only after the mouse has remained in that
24924 window for the duration of the delay.
24925 A negative number has a similar effect, but causes windows to be
24926 autoselected only after the mouse has stopped moving. \(Because of
24927 the way Emacs compares mouse events, you will occasionally wait twice
24928 that time before the window gets selected.\)
24929 Any other value means to autoselect window instantaneously when the
24930 mouse pointer enters it.
24932 Autoselection selects the minibuffer only if it is active, and never
24933 unselects the minibuffer if it is active.
24935 When customizing this variable make sure that the actual value of
24936 `focus-follows-mouse' matches the behavior of your window manager. */);
24937 Vmouse_autoselect_window
= Qnil
;
24939 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24940 doc
: /* *Non-nil means automatically resize tool-bars.
24941 This dynamically changes the tool-bar's height to the minimum height
24942 that is needed to make all tool-bar items visible.
24943 If value is `grow-only', the tool-bar's height is only increased
24944 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24945 Vauto_resize_tool_bars
= Qt
;
24947 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24948 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24949 auto_raise_tool_bar_buttons_p
= 1;
24951 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24952 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24953 make_cursor_line_fully_visible_p
= 1;
24955 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24956 doc
: /* *Border below tool-bar in pixels.
24957 If an integer, use it as the height of the border.
24958 If it is one of `internal-border-width' or `border-width', use the
24959 value of the corresponding frame parameter.
24960 Otherwise, no border is added below the tool-bar. */);
24961 Vtool_bar_border
= Qinternal_border_width
;
24963 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24964 doc
: /* *Margin around tool-bar buttons in pixels.
24965 If an integer, use that for both horizontal and vertical margins.
24966 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24967 HORZ specifying the horizontal margin, and VERT specifying the
24968 vertical margin. */);
24969 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24971 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24972 doc
: /* *Relief thickness of tool-bar buttons. */);
24973 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24975 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24976 doc
: /* List of functions to call to fontify regions of text.
24977 Each function is called with one argument POS. Functions must
24978 fontify a region starting at POS in the current buffer, and give
24979 fontified regions the property `fontified'. */);
24980 Vfontification_functions
= Qnil
;
24981 Fmake_variable_buffer_local (Qfontification_functions
);
24983 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24984 &unibyte_display_via_language_environment
,
24985 doc
: /* *Non-nil means display unibyte text according to language environment.
24986 Specifically this means that unibyte non-ASCII characters
24987 are displayed by converting them to the equivalent multibyte characters
24988 according to the current language environment. As a result, they are
24989 displayed according to the current fontset. */);
24990 unibyte_display_via_language_environment
= 0;
24992 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24993 doc
: /* *Maximum height for resizing mini-windows.
24994 If a float, it specifies a fraction of the mini-window frame's height.
24995 If an integer, it specifies a number of lines. */);
24996 Vmax_mini_window_height
= make_float (0.25);
24998 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24999 doc
: /* *How to resize mini-windows.
25000 A value of nil means don't automatically resize mini-windows.
25001 A value of t means resize them to fit the text displayed in them.
25002 A value of `grow-only', the default, means let mini-windows grow
25003 only, until their display becomes empty, at which point the windows
25004 go back to their normal size. */);
25005 Vresize_mini_windows
= Qgrow_only
;
25007 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25008 doc
: /* Alist specifying how to blink the cursor off.
25009 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25010 `cursor-type' frame-parameter or variable equals ON-STATE,
25011 comparing using `equal', Emacs uses OFF-STATE to specify
25012 how to blink it off. ON-STATE and OFF-STATE are values for
25013 the `cursor-type' frame parameter.
25015 If a frame's ON-STATE has no entry in this list,
25016 the frame's other specifications determine how to blink the cursor off. */);
25017 Vblink_cursor_alist
= Qnil
;
25019 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25020 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25021 automatic_hscrolling_p
= 1;
25022 Qauto_hscroll_mode
= intern ("auto-hscroll-mode");
25023 staticpro (&Qauto_hscroll_mode
);
25025 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25026 doc
: /* *How many columns away from the window edge point is allowed to get
25027 before automatic hscrolling will horizontally scroll the window. */);
25028 hscroll_margin
= 5;
25030 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25031 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25032 When point is less than `hscroll-margin' columns from the window
25033 edge, automatic hscrolling will scroll the window by the amount of columns
25034 determined by this variable. If its value is a positive integer, scroll that
25035 many columns. If it's a positive floating-point number, it specifies the
25036 fraction of the window's width to scroll. If it's nil or zero, point will be
25037 centered horizontally after the scroll. Any other value, including negative
25038 numbers, are treated as if the value were zero.
25040 Automatic hscrolling always moves point outside the scroll margin, so if
25041 point was more than scroll step columns inside the margin, the window will
25042 scroll more than the value given by the scroll step.
25044 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25045 and `scroll-right' overrides this variable's effect. */);
25046 Vhscroll_step
= make_number (0);
25048 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25049 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25050 Bind this around calls to `message' to let it take effect. */);
25051 message_truncate_lines
= 0;
25053 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25054 doc
: /* Normal hook run to update the menu bar definitions.
25055 Redisplay runs this hook before it redisplays the menu bar.
25056 This is used to update submenus such as Buffers,
25057 whose contents depend on various data. */);
25058 Vmenu_bar_update_hook
= Qnil
;
25060 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25061 doc
: /* Frame for which we are updating a menu.
25062 The enable predicate for a menu binding should check this variable. */);
25063 Vmenu_updating_frame
= Qnil
;
25065 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25066 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25067 inhibit_menubar_update
= 0;
25069 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25070 doc
: /* Prefix added to the beginning of all continuation lines at display-time.
25071 May be a string, an image, or a stretch-glyph such as used by the
25072 `display' text-property.
25074 This variable is overridden by any `wrap-prefix' text-property.
25076 To add a prefix to non-continuation lines, use the `line-prefix' variable. */);
25077 Vwrap_prefix
= Qnil
;
25078 staticpro (&Qwrap_prefix
);
25079 Qwrap_prefix
= intern ("wrap-prefix");
25080 Fmake_variable_buffer_local (Qwrap_prefix
);
25082 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25083 doc
: /* Prefix added to the beginning of all non-continuation lines at display-time.
25084 May be a string, an image, or a stretch-glyph such as used by the
25085 `display' text-property.
25087 This variable is overridden by any `line-prefix' text-property.
25089 To add a prefix to continuation lines, use the `wrap-prefix' variable. */);
25090 Vline_prefix
= Qnil
;
25091 staticpro (&Qline_prefix
);
25092 Qline_prefix
= intern ("line-prefix");
25093 Fmake_variable_buffer_local (Qline_prefix
);
25095 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25096 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25097 inhibit_eval_during_redisplay
= 0;
25099 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25100 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25101 inhibit_free_realized_faces
= 0;
25104 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25105 doc
: /* Inhibit try_window_id display optimization. */);
25106 inhibit_try_window_id
= 0;
25108 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25109 doc
: /* Inhibit try_window_reusing display optimization. */);
25110 inhibit_try_window_reusing
= 0;
25112 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25113 doc
: /* Inhibit try_cursor_movement display optimization. */);
25114 inhibit_try_cursor_movement
= 0;
25115 #endif /* GLYPH_DEBUG */
25117 DEFVAR_INT ("overline-margin", &overline_margin
,
25118 doc
: /* *Space between overline and text, in pixels.
25119 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25120 margin to the caracter height. */);
25121 overline_margin
= 2;
25123 DEFVAR_INT ("underline-minimum-offset",
25124 &underline_minimum_offset
,
25125 doc
: /* Minimum distance between baseline and underline.
25126 This can improve legibility of underlined text at small font sizes,
25127 particularly when using variable `x-use-underline-position-properties'
25128 with fonts that specify an UNDERLINE_POSITION relatively close to the
25129 baseline. The default value is 1. */);
25130 underline_minimum_offset
= 1;
25134 /* Initialize this module when Emacs starts. */
25139 Lisp_Object root_window
;
25140 struct window
*mini_w
;
25142 current_header_line_height
= current_mode_line_height
= -1;
25144 CHARPOS (this_line_start_pos
) = 0;
25146 mini_w
= XWINDOW (minibuf_window
);
25147 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25149 if (!noninteractive
)
25151 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25154 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25155 set_window_height (root_window
,
25156 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25158 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25159 set_window_height (minibuf_window
, 1, 0);
25161 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25162 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25164 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25165 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25166 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25168 /* The default ellipsis glyphs `...'. */
25169 for (i
= 0; i
< 3; ++i
)
25170 default_invis_vector
[i
] = make_number ('.');
25174 /* Allocate the buffer for frame titles.
25175 Also used for `format-mode-line'. */
25177 mode_line_noprop_buf
= (char *) xmalloc (size
);
25178 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25179 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25180 mode_line_target
= MODE_LINE_DISPLAY
;
25183 help_echo_showing_p
= 0;
25187 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25188 (do not change this comment) */