1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997, 1998,
4 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5 2010 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code.
37 The following diagram shows how redisplay code is invoked. As you
38 can see, Lisp calls redisplay and vice versa. Under window systems
39 like X, some portions of the redisplay code are also called
40 asynchronously during mouse movement or expose events. It is very
41 important that these code parts do NOT use the C library (malloc,
42 free) because many C libraries under Unix are not reentrant. They
43 may also NOT call functions of the Lisp interpreter which could
44 change the interpreter's state. If you don't follow these rules,
45 you will encounter bugs which are very hard to explain.
47 +--------------+ redisplay +----------------+
48 | Lisp machine |---------------->| Redisplay code |<--+
49 +--------------+ (xdisp.c) +----------------+ |
51 +----------------------------------+ |
52 Don't use this path when called |
55 expose_window (asynchronous) |
57 X expose events -----+
59 What does redisplay do? Obviously, it has to figure out somehow what
60 has been changed since the last time the display has been updated,
61 and to make these changes visible. Preferably it would do that in
62 a moderately intelligent way, i.e. fast.
64 Changes in buffer text can be deduced from window and buffer
65 structures, and from some global variables like `beg_unchanged' and
66 `end_unchanged'. The contents of the display are additionally
67 recorded in a `glyph matrix', a two-dimensional matrix of glyph
68 structures. Each row in such a matrix corresponds to a line on the
69 display, and each glyph in a row corresponds to a column displaying
70 a character, an image, or what else. This matrix is called the
71 `current glyph matrix' or `current matrix' in redisplay
74 For buffer parts that have been changed since the last update, a
75 second glyph matrix is constructed, the so called `desired glyph
76 matrix' or short `desired matrix'. Current and desired matrix are
77 then compared to find a cheap way to update the display, e.g. by
78 reusing part of the display by scrolling lines.
80 You will find a lot of redisplay optimizations when you start
81 looking at the innards of redisplay. The overall goal of all these
82 optimizations is to make redisplay fast because it is done
83 frequently. Some of these optimizations are implemented by the
88 This function tries to update the display if the text in the
89 window did not change and did not scroll, only point moved, and
90 it did not move off the displayed portion of the text.
92 . try_window_reusing_current_matrix
94 This function reuses the current matrix of a window when text
95 has not changed, but the window start changed (e.g., due to
100 This function attempts to redisplay a window by reusing parts of
101 its existing display. It finds and reuses the part that was not
102 changed, and redraws the rest.
106 This function performs the full redisplay of a single window
107 assuming that its fonts were not changed and that the cursor
108 will not end up in the scroll margins. (Loading fonts requires
109 re-adjustment of dimensions of glyph matrices, which makes this
110 method impossible to use.)
112 These optimizations are tried in sequence (some can be skipped if
113 it is known that they are not applicable). If none of the
114 optimizations were successful, redisplay calls redisplay_windows,
115 which performs a full redisplay of all windows.
119 Desired matrices are always built per Emacs window. The function
120 `display_line' is the central function to look at if you are
121 interested. It constructs one row in a desired matrix given an
122 iterator structure containing both a buffer position and a
123 description of the environment in which the text is to be
124 displayed. But this is too early, read on.
126 Characters and pixmaps displayed for a range of buffer text depend
127 on various settings of buffers and windows, on overlays and text
128 properties, on display tables, on selective display. The good news
129 is that all this hairy stuff is hidden behind a small set of
130 interface functions taking an iterator structure (struct it)
133 Iteration over things to be displayed is then simple. It is
134 started by initializing an iterator with a call to init_iterator.
135 Calls to get_next_display_element fill the iterator structure with
136 relevant information about the next thing to display. Calls to
137 set_iterator_to_next move the iterator to the next thing.
139 Besides this, an iterator also contains information about the
140 display environment in which glyphs for display elements are to be
141 produced. It has fields for the width and height of the display,
142 the information whether long lines are truncated or continued, a
143 current X and Y position, and lots of other stuff you can better
146 Glyphs in a desired matrix are normally constructed in a loop
147 calling get_next_display_element and then PRODUCE_GLYPHS. The call
148 to PRODUCE_GLYPHS will fill the iterator structure with pixel
149 information about the element being displayed and at the same time
150 produce glyphs for it. If the display element fits on the line
151 being displayed, set_iterator_to_next is called next, otherwise the
152 glyphs produced are discarded. The function display_line is the
153 workhorse of filling glyph rows in the desired matrix with glyphs.
154 In addition to producing glyphs, it also handles line truncation
155 and continuation, word wrap, and cursor positioning (for the
156 latter, see also set_cursor_from_row).
160 That just couldn't be all, could it? What about terminal types not
161 supporting operations on sub-windows of the screen? To update the
162 display on such a terminal, window-based glyph matrices are not
163 well suited. To be able to reuse part of the display (scrolling
164 lines up and down), we must instead have a view of the whole
165 screen. This is what `frame matrices' are for. They are a trick.
167 Frames on terminals like above have a glyph pool. Windows on such
168 a frame sub-allocate their glyph memory from their frame's glyph
169 pool. The frame itself is given its own glyph matrices. By
170 coincidence---or maybe something else---rows in window glyph
171 matrices are slices of corresponding rows in frame matrices. Thus
172 writing to window matrices implicitly updates a frame matrix which
173 provides us with the view of the whole screen that we originally
174 wanted to have without having to move many bytes around. To be
175 honest, there is a little bit more done, but not much more. If you
176 plan to extend that code, take a look at dispnew.c. The function
177 build_frame_matrix is a good starting point.
179 Bidirectional display.
181 Bidirectional display adds quite some hair to this already complex
182 design. The good news are that a large portion of that hairy stuff
183 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
184 reordering engine which is called by set_iterator_to_next and
185 returns the next character to display in the visual order. See
186 commentary on bidi.c for more details. As far as redisplay is
187 concerned, the effect of calling bidi_move_to_visually_next, the
188 main interface of the reordering engine, is that the iterator gets
189 magically placed on the buffer or string position that is to be
190 displayed next. In other words, a linear iteration through the
191 buffer/string is replaced with a non-linear one. All the rest of
192 the redisplay is oblivious to the bidi reordering.
194 Well, almost oblivious---there are still complications, most of
195 them due to the fact that buffer and string positions no longer
196 change monotonously with glyph indices in a glyph row. Moreover,
197 for continued lines, the buffer positions may not even be
198 monotonously changing with vertical positions. Also, accounting
199 for face changes, overlays, etc. becomes more complex because
200 non-linear iteration could potentially skip many positions with
201 changes, and then cross them again on the way back...
203 One other prominent effect of bidirectional display is that some
204 paragraphs of text need to be displayed starting at the right
205 margin of the window---the so-called right-to-left, or R2L
206 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
207 which have their reversed_p flag set. The bidi reordering engine
208 produces characters in such rows starting from the character which
209 should be the rightmost on display. PRODUCE_GLYPHS then reverses
210 the order, when it fills up the glyph row whose reversed_p flag is
211 set, by prepending each new glyph to what is already there, instead
212 of appending it. When the glyph row is complete, the function
213 extend_face_to_end_of_line fills the empty space to the left of the
214 leftmost character with special glyphs, which will display as,
215 well, empty. On text terminals, these special glyphs are simply
216 blank characters. On graphics terminals, there's a single stretch
217 glyph of a suitably computed width. Both the blanks and the
218 stretch glyph are given the face of the background of the line.
219 This way, the terminal-specific back-end can still draw the glyphs
220 left to right, even for R2L lines.
222 Bidirectional display and character compositions
224 Some scripts cannot be displayed by drawing each character
225 individually, because adjacent characters change each other's shape
226 on display. For example, Arabic and Indic scripts belong to this
229 Emacs display supports this by providing "character compositions",
230 most of which is implemented in composite.c. During the buffer
231 scan that delivers characters to PRODUCE_GLYPHS, if the next
232 character to be delivered is a composed character, the iteration
233 calls composition_reseat_it and next_element_from_composition. If
234 they succeed to compose the character with one or more of the
235 following characters, the whole sequence of characters that where
236 composed is recorded in the `struct composition_it' object that is
237 part of the buffer iterator. The composed sequence could produce
238 one or more font glyphs (called "grapheme clusters") on the screen.
239 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
240 in the direction corresponding to the current bidi scan direction
241 (recorded in the scan_dir member of the `struct bidi_it' object
242 that is part of the buffer iterator). In particular, if the bidi
243 iterator currently scans the buffer backwards, the grapheme
244 clusters are delivered back to front. This reorders the grapheme
245 clusters as appropriate for the current bidi context. Note that
246 this means that the grapheme clusters are always stored in the
247 LGSTRING object (see composite.c) in the logical order.
249 Moving an iterator in bidirectional text
250 without producing glyphs
252 Note one important detail mentioned above: that the bidi reordering
253 engine, driven by the iterator, produces characters in R2L rows
254 starting at the character that will be the rightmost on display.
255 As far as the iterator is concerned, the geometry of such rows is
256 still left to right, i.e. the iterator "thinks" the first character
257 is at the leftmost pixel position. The iterator does not know that
258 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
259 delivers. This is important when functions from the the move_it_*
260 family are used to get to certain screen position or to match
261 screen coordinates with buffer coordinates: these functions use the
262 iterator geometry, which is left to right even in R2L paragraphs.
263 This works well with most callers of move_it_*, because they need
264 to get to a specific column, and columns are still numbered in the
265 reading order, i.e. the rightmost character in a R2L paragraph is
266 still column zero. But some callers do not get well with this; a
267 notable example is mouse clicks that need to find the character
268 that corresponds to certain pixel coordinates. See
269 buffer_posn_from_coords in dispnew.c for how this is handled. */
277 #include "keyboard.h"
280 #include "termchar.h"
281 #include "dispextern.h"
283 #include "character.h"
286 #include "commands.h"
290 #include "termhooks.h"
291 #include "termopts.h"
292 #include "intervals.h"
295 #include "region-cache.h"
298 #include "blockinput.h"
300 #ifdef HAVE_X_WINDOWS
315 #ifndef FRAME_X_OUTPUT
316 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
319 #define INFINITY 10000000
321 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
322 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
323 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
324 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
325 Lisp_Object Qinhibit_point_motion_hooks
;
326 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
327 Lisp_Object Qfontified
;
328 Lisp_Object Qgrow_only
;
329 Lisp_Object Qinhibit_eval_during_redisplay
;
330 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
331 Lisp_Object Qright_to_left
, Qleft_to_right
;
334 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
337 Lisp_Object Qarrow
, Qhand
, Qtext
;
339 Lisp_Object Qrisky_local_variable
;
341 /* Holds the list (error). */
342 Lisp_Object list_of_error
;
344 /* Functions called to fontify regions of text. */
346 Lisp_Object Vfontification_functions
;
347 Lisp_Object Qfontification_functions
;
349 /* Non-nil means automatically select any window when the mouse
350 cursor moves into it. */
351 Lisp_Object Vmouse_autoselect_window
;
353 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
354 Lisp_Object Vline_prefix
, Qline_prefix
;
356 /* Non-zero means draw tool bar buttons raised when the mouse moves
359 int auto_raise_tool_bar_buttons_p
;
361 /* Non-zero means to reposition window if cursor line is only partially visible. */
363 int make_cursor_line_fully_visible_p
;
365 /* Margin below tool bar in pixels. 0 or nil means no margin.
366 If value is `internal-border-width' or `border-width',
367 the corresponding frame parameter is used. */
369 Lisp_Object Vtool_bar_border
;
371 /* Margin around tool bar buttons in pixels. */
373 Lisp_Object Vtool_bar_button_margin
;
375 /* Thickness of shadow to draw around tool bar buttons. */
377 EMACS_INT tool_bar_button_relief
;
379 /* Non-nil means automatically resize tool-bars so that all tool-bar
380 items are visible, and no blank lines remain.
382 If value is `grow-only', only make tool-bar bigger. */
384 Lisp_Object Vauto_resize_tool_bars
;
386 /* Type of tool bar. Can be symbols image, text, both or both-hroiz. */
388 Lisp_Object Vtool_bar_style
;
390 /* Maximum number of characters a label can have to be shown. */
392 EMACS_INT tool_bar_max_label_size
;
394 /* Non-zero means draw block and hollow cursor as wide as the glyph
395 under it. For example, if a block cursor is over a tab, it will be
396 drawn as wide as that tab on the display. */
398 int x_stretch_cursor_p
;
400 /* Non-nil means don't actually do any redisplay. */
402 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
404 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
406 int inhibit_eval_during_redisplay
;
408 /* Names of text properties relevant for redisplay. */
410 Lisp_Object Qdisplay
;
412 /* Symbols used in text property values. */
414 Lisp_Object Vdisplay_pixels_per_inch
;
415 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
416 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
419 Lisp_Object Qmargin
, Qpointer
;
420 Lisp_Object Qline_height
;
422 /* Non-nil means highlight trailing whitespace. */
424 Lisp_Object Vshow_trailing_whitespace
;
426 /* Non-nil means escape non-break space and hyphens. */
428 Lisp_Object Vnobreak_char_display
;
430 #ifdef HAVE_WINDOW_SYSTEM
432 /* Test if overflow newline into fringe. Called with iterator IT
433 at or past right window margin, and with IT->current_x set. */
435 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
436 (!NILP (Voverflow_newline_into_fringe) \
437 && FRAME_WINDOW_P ((IT)->f) \
438 && ((IT)->bidi_it.paragraph_dir == R2L \
439 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
440 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
441 && (IT)->current_x == (IT)->last_visible_x \
442 && (IT)->line_wrap != WORD_WRAP)
444 #else /* !HAVE_WINDOW_SYSTEM */
445 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
446 #endif /* HAVE_WINDOW_SYSTEM */
448 /* Test if the display element loaded in IT is a space or tab
449 character. This is used to determine word wrapping. */
451 #define IT_DISPLAYING_WHITESPACE(it) \
452 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
454 /* Non-nil means show the text cursor in void text areas
455 i.e. in blank areas after eol and eob. This used to be
456 the default in 21.3. */
458 Lisp_Object Vvoid_text_area_pointer
;
460 /* Name of the face used to highlight trailing whitespace. */
462 Lisp_Object Qtrailing_whitespace
;
464 /* Name and number of the face used to highlight escape glyphs. */
466 Lisp_Object Qescape_glyph
;
468 /* Name and number of the face used to highlight non-breaking spaces. */
470 Lisp_Object Qnobreak_space
;
472 /* The symbol `image' which is the car of the lists used to represent
473 images in Lisp. Also a tool bar style. */
477 /* The image map types. */
478 Lisp_Object QCmap
, QCpointer
;
479 Lisp_Object Qrect
, Qcircle
, Qpoly
;
481 /* Tool bar styles */
482 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
484 /* Non-zero means print newline to stdout before next mini-buffer
487 int noninteractive_need_newline
;
489 /* Non-zero means print newline to message log before next message. */
491 static int message_log_need_newline
;
493 /* Three markers that message_dolog uses.
494 It could allocate them itself, but that causes trouble
495 in handling memory-full errors. */
496 static Lisp_Object message_dolog_marker1
;
497 static Lisp_Object message_dolog_marker2
;
498 static Lisp_Object message_dolog_marker3
;
500 /* The buffer position of the first character appearing entirely or
501 partially on the line of the selected window which contains the
502 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
503 redisplay optimization in redisplay_internal. */
505 static struct text_pos this_line_start_pos
;
507 /* Number of characters past the end of the line above, including the
508 terminating newline. */
510 static struct text_pos this_line_end_pos
;
512 /* The vertical positions and the height of this line. */
514 static int this_line_vpos
;
515 static int this_line_y
;
516 static int this_line_pixel_height
;
518 /* X position at which this display line starts. Usually zero;
519 negative if first character is partially visible. */
521 static int this_line_start_x
;
523 /* Buffer that this_line_.* variables are referring to. */
525 static struct buffer
*this_line_buffer
;
527 /* Nonzero means truncate lines in all windows less wide than the
530 Lisp_Object Vtruncate_partial_width_windows
;
532 /* A flag to control how to display unibyte 8-bit character. */
534 int unibyte_display_via_language_environment
;
536 /* Nonzero means we have more than one non-mini-buffer-only frame.
537 Not guaranteed to be accurate except while parsing
538 frame-title-format. */
542 Lisp_Object Vglobal_mode_string
;
545 /* List of variables (symbols) which hold markers for overlay arrows.
546 The symbols on this list are examined during redisplay to determine
547 where to display overlay arrows. */
549 Lisp_Object Voverlay_arrow_variable_list
;
551 /* Marker for where to display an arrow on top of the buffer text. */
553 Lisp_Object Voverlay_arrow_position
;
555 /* String to display for the arrow. Only used on terminal frames. */
557 Lisp_Object Voverlay_arrow_string
;
559 /* Values of those variables at last redisplay are stored as
560 properties on `overlay-arrow-position' symbol. However, if
561 Voverlay_arrow_position is a marker, last-arrow-position is its
562 numerical position. */
564 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
566 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
567 properties on a symbol in overlay-arrow-variable-list. */
569 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
571 /* Like mode-line-format, but for the title bar on a visible frame. */
573 Lisp_Object Vframe_title_format
;
575 /* Like mode-line-format, but for the title bar on an iconified frame. */
577 Lisp_Object Vicon_title_format
;
579 /* List of functions to call when a window's size changes. These
580 functions get one arg, a frame on which one or more windows' sizes
583 static Lisp_Object Vwindow_size_change_functions
;
585 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
587 /* Nonzero if an overlay arrow has been displayed in this window. */
589 static int overlay_arrow_seen
;
591 /* Nonzero means highlight the region even in nonselected windows. */
593 int highlight_nonselected_windows
;
595 /* If cursor motion alone moves point off frame, try scrolling this
596 many lines up or down if that will bring it back. */
598 static EMACS_INT scroll_step
;
600 /* Nonzero means scroll just far enough to bring point back on the
601 screen, when appropriate. */
603 static EMACS_INT scroll_conservatively
;
605 /* Recenter the window whenever point gets within this many lines of
606 the top or bottom of the window. This value is translated into a
607 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
608 that there is really a fixed pixel height scroll margin. */
610 EMACS_INT scroll_margin
;
612 /* Number of windows showing the buffer of the selected window (or
613 another buffer with the same base buffer). keyboard.c refers to
618 /* Vector containing glyphs for an ellipsis `...'. */
620 static Lisp_Object default_invis_vector
[3];
622 /* Zero means display the mode-line/header-line/menu-bar in the default face
623 (this slightly odd definition is for compatibility with previous versions
624 of emacs), non-zero means display them using their respective faces.
626 This variable is deprecated. */
628 int mode_line_inverse_video
;
630 /* Prompt to display in front of the mini-buffer contents. */
632 Lisp_Object minibuf_prompt
;
634 /* Width of current mini-buffer prompt. Only set after display_line
635 of the line that contains the prompt. */
637 int minibuf_prompt_width
;
639 /* This is the window where the echo area message was displayed. It
640 is always a mini-buffer window, but it may not be the same window
641 currently active as a mini-buffer. */
643 Lisp_Object echo_area_window
;
645 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
646 pushes the current message and the value of
647 message_enable_multibyte on the stack, the function restore_message
648 pops the stack and displays MESSAGE again. */
650 Lisp_Object Vmessage_stack
;
652 /* Nonzero means multibyte characters were enabled when the echo area
653 message was specified. */
655 int message_enable_multibyte
;
657 /* Nonzero if we should redraw the mode lines on the next redisplay. */
659 int update_mode_lines
;
661 /* Nonzero if window sizes or contents have changed since last
662 redisplay that finished. */
664 int windows_or_buffers_changed
;
666 /* Nonzero means a frame's cursor type has been changed. */
668 int cursor_type_changed
;
670 /* Nonzero after display_mode_line if %l was used and it displayed a
673 int line_number_displayed
;
675 /* Maximum buffer size for which to display line numbers. */
677 Lisp_Object Vline_number_display_limit
;
679 /* Line width to consider when repositioning for line number display. */
681 static EMACS_INT line_number_display_limit_width
;
683 /* Number of lines to keep in the message log buffer. t means
684 infinite. nil means don't log at all. */
686 Lisp_Object Vmessage_log_max
;
688 /* The name of the *Messages* buffer, a string. */
690 static Lisp_Object Vmessages_buffer_name
;
692 /* Current, index 0, and last displayed echo area message. Either
693 buffers from echo_buffers, or nil to indicate no message. */
695 Lisp_Object echo_area_buffer
[2];
697 /* The buffers referenced from echo_area_buffer. */
699 static Lisp_Object echo_buffer
[2];
701 /* A vector saved used in with_area_buffer to reduce consing. */
703 static Lisp_Object Vwith_echo_area_save_vector
;
705 /* Non-zero means display_echo_area should display the last echo area
706 message again. Set by redisplay_preserve_echo_area. */
708 static int display_last_displayed_message_p
;
710 /* Nonzero if echo area is being used by print; zero if being used by
713 int message_buf_print
;
715 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
717 Lisp_Object Qinhibit_menubar_update
;
718 int inhibit_menubar_update
;
720 /* When evaluating expressions from menu bar items (enable conditions,
721 for instance), this is the frame they are being processed for. */
723 Lisp_Object Vmenu_updating_frame
;
725 /* Maximum height for resizing mini-windows. Either a float
726 specifying a fraction of the available height, or an integer
727 specifying a number of lines. */
729 Lisp_Object Vmax_mini_window_height
;
731 /* Non-zero means messages should be displayed with truncated
732 lines instead of being continued. */
734 int message_truncate_lines
;
735 Lisp_Object Qmessage_truncate_lines
;
737 /* Set to 1 in clear_message to make redisplay_internal aware
738 of an emptied echo area. */
740 static int message_cleared_p
;
742 /* How to blink the default frame cursor off. */
743 Lisp_Object Vblink_cursor_alist
;
745 /* A scratch glyph row with contents used for generating truncation
746 glyphs. Also used in direct_output_for_insert. */
748 #define MAX_SCRATCH_GLYPHS 100
749 struct glyph_row scratch_glyph_row
;
750 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
752 /* Ascent and height of the last line processed by move_it_to. */
754 static int last_max_ascent
, last_height
;
756 /* Non-zero if there's a help-echo in the echo area. */
758 int help_echo_showing_p
;
760 /* If >= 0, computed, exact values of mode-line and header-line height
761 to use in the macros CURRENT_MODE_LINE_HEIGHT and
762 CURRENT_HEADER_LINE_HEIGHT. */
764 int current_mode_line_height
, current_header_line_height
;
766 /* The maximum distance to look ahead for text properties. Values
767 that are too small let us call compute_char_face and similar
768 functions too often which is expensive. Values that are too large
769 let us call compute_char_face and alike too often because we
770 might not be interested in text properties that far away. */
772 #define TEXT_PROP_DISTANCE_LIMIT 100
776 /* Variables to turn off display optimizations from Lisp. */
778 int inhibit_try_window_id
, inhibit_try_window_reusing
;
779 int inhibit_try_cursor_movement
;
781 /* Non-zero means print traces of redisplay if compiled with
784 int trace_redisplay_p
;
786 #endif /* GLYPH_DEBUG */
788 #ifdef DEBUG_TRACE_MOVE
789 /* Non-zero means trace with TRACE_MOVE to stderr. */
792 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
794 #define TRACE_MOVE(x) (void) 0
797 /* Non-zero means automatically scroll windows horizontally to make
800 int automatic_hscrolling_p
;
801 Lisp_Object Qauto_hscroll_mode
;
803 /* How close to the margin can point get before the window is scrolled
805 EMACS_INT hscroll_margin
;
807 /* How much to scroll horizontally when point is inside the above margin. */
808 Lisp_Object Vhscroll_step
;
810 /* The variable `resize-mini-windows'. If nil, don't resize
811 mini-windows. If t, always resize them to fit the text they
812 display. If `grow-only', let mini-windows grow only until they
815 Lisp_Object Vresize_mini_windows
;
817 /* Buffer being redisplayed -- for redisplay_window_error. */
819 struct buffer
*displayed_buffer
;
821 /* Space between overline and text. */
823 EMACS_INT overline_margin
;
825 /* Require underline to be at least this many screen pixels below baseline
826 This to avoid underline "merging" with the base of letters at small
827 font sizes, particularly when x_use_underline_position_properties is on. */
829 EMACS_INT underline_minimum_offset
;
831 /* Value returned from text property handlers (see below). */
836 HANDLED_RECOMPUTE_PROPS
,
837 HANDLED_OVERLAY_STRING_CONSUMED
,
841 /* A description of text properties that redisplay is interested
846 /* The name of the property. */
849 /* A unique index for the property. */
852 /* A handler function called to set up iterator IT from the property
853 at IT's current position. Value is used to steer handle_stop. */
854 enum prop_handled (*handler
) (struct it
*it
);
857 static enum prop_handled
handle_face_prop (struct it
*);
858 static enum prop_handled
handle_invisible_prop (struct it
*);
859 static enum prop_handled
handle_display_prop (struct it
*);
860 static enum prop_handled
handle_composition_prop (struct it
*);
861 static enum prop_handled
handle_overlay_change (struct it
*);
862 static enum prop_handled
handle_fontified_prop (struct it
*);
864 /* Properties handled by iterators. */
866 static struct props it_props
[] =
868 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
869 /* Handle `face' before `display' because some sub-properties of
870 `display' need to know the face. */
871 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
872 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
873 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
874 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
878 /* Value is the position described by X. If X is a marker, value is
879 the marker_position of X. Otherwise, value is X. */
881 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
883 /* Enumeration returned by some move_it_.* functions internally. */
887 /* Not used. Undefined value. */
890 /* Move ended at the requested buffer position or ZV. */
891 MOVE_POS_MATCH_OR_ZV
,
893 /* Move ended at the requested X pixel position. */
896 /* Move within a line ended at the end of a line that must be
900 /* Move within a line ended at the end of a line that would
901 be displayed truncated. */
904 /* Move within a line ended at a line end. */
908 /* This counter is used to clear the face cache every once in a while
909 in redisplay_internal. It is incremented for each redisplay.
910 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
913 #define CLEAR_FACE_CACHE_COUNT 500
914 static int clear_face_cache_count
;
916 /* Similarly for the image cache. */
918 #ifdef HAVE_WINDOW_SYSTEM
919 #define CLEAR_IMAGE_CACHE_COUNT 101
920 static int clear_image_cache_count
;
922 /* Null glyph slice */
923 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
926 /* Non-zero while redisplay_internal is in progress. */
930 /* Non-zero means don't free realized faces. Bound while freeing
931 realized faces is dangerous because glyph matrices might still
934 int inhibit_free_realized_faces
;
935 Lisp_Object Qinhibit_free_realized_faces
;
937 /* If a string, XTread_socket generates an event to display that string.
938 (The display is done in read_char.) */
940 Lisp_Object help_echo_string
;
941 Lisp_Object help_echo_window
;
942 Lisp_Object help_echo_object
;
943 EMACS_INT help_echo_pos
;
945 /* Temporary variable for XTread_socket. */
947 Lisp_Object previous_help_echo_string
;
949 /* Platform-independent portion of hourglass implementation. */
951 /* Non-zero means we're allowed to display a hourglass pointer. */
952 int display_hourglass_p
;
954 /* Non-zero means an hourglass cursor is currently shown. */
955 int hourglass_shown_p
;
957 /* If non-null, an asynchronous timer that, when it expires, displays
958 an hourglass cursor on all frames. */
959 struct atimer
*hourglass_atimer
;
961 /* Number of seconds to wait before displaying an hourglass cursor. */
962 Lisp_Object Vhourglass_delay
;
964 /* Name of the face used to display glyphless characters. */
965 Lisp_Object Qglyphless_char
;
967 /* Char-table to control the display of glyphless characters. */
968 Lisp_Object Vglyphless_char_display
;
970 /* Symbol for the purpose of Vglyphless_char_display. */
971 Lisp_Object Qglyphless_char_display
;
973 /* Method symbols for Vglyphless_char_display. */
974 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
976 /* Default pixel width of `thin-space' display method. */
977 #define THIN_SPACE_WIDTH 1
979 /* Default number of seconds to wait before displaying an hourglass
981 #define DEFAULT_HOURGLASS_DELAY 1
984 /* Function prototypes. */
986 static void setup_for_ellipsis (struct it
*, int);
987 static void mark_window_display_accurate_1 (struct window
*, int);
988 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
989 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
990 static int cursor_row_p (struct window
*, struct glyph_row
*);
991 static int redisplay_mode_lines (Lisp_Object
, int);
992 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
994 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
996 static void handle_line_prefix (struct it
*);
998 static void pint2str (char *, int, int);
999 static void pint2hrstr (char *, int, int);
1000 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
1002 static void reconsider_clip_changes (struct window
*, struct buffer
*);
1003 static int text_outside_line_unchanged_p (struct window
*,
1004 EMACS_INT
, EMACS_INT
);
1005 static void store_mode_line_noprop_char (char);
1006 static int store_mode_line_noprop (const unsigned char *, int, int);
1007 static void handle_stop (struct it
*);
1008 static void handle_stop_backwards (struct it
*, EMACS_INT
);
1009 static int single_display_spec_intangible_p (Lisp_Object
);
1010 static void ensure_echo_area_buffers (void);
1011 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
1012 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
1013 static int with_echo_area_buffer (struct window
*, int,
1014 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
1015 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
1016 static void clear_garbaged_frames (void);
1017 static int current_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
1018 static int truncate_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
1019 static int set_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
1020 static int display_echo_area (struct window
*);
1021 static int display_echo_area_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
1022 static int resize_mini_window_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
1023 static Lisp_Object
unwind_redisplay (Lisp_Object
);
1024 static int string_char_and_length (const unsigned char *, int *);
1025 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
1027 static int compute_window_start_on_continuation_line (struct window
*);
1028 static Lisp_Object
safe_eval_handler (Lisp_Object
);
1029 static void insert_left_trunc_glyphs (struct it
*);
1030 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
1032 static void extend_face_to_end_of_line (struct it
*);
1033 static int append_space_for_newline (struct it
*, int);
1034 static int cursor_row_fully_visible_p (struct window
*, int, int);
1035 static int try_scrolling (Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int);
1036 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
1037 static int trailing_whitespace_p (EMACS_INT
);
1038 static int message_log_check_duplicate (EMACS_INT
, EMACS_INT
,
1039 EMACS_INT
, EMACS_INT
);
1040 static void push_it (struct it
*);
1041 static void pop_it (struct it
*);
1042 static void sync_frame_with_window_matrix_rows (struct window
*);
1043 static void select_frame_for_redisplay (Lisp_Object
);
1044 static void redisplay_internal (int);
1045 static int echo_area_display (int);
1046 static void redisplay_windows (Lisp_Object
);
1047 static void redisplay_window (Lisp_Object
, int);
1048 static Lisp_Object
redisplay_window_error (Lisp_Object
);
1049 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
1050 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
1051 static int update_menu_bar (struct frame
*, int, int);
1052 static int try_window_reusing_current_matrix (struct window
*);
1053 static int try_window_id (struct window
*);
1054 static int display_line (struct it
*);
1055 static int display_mode_lines (struct window
*);
1056 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
1057 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
1058 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
1059 static const char *decode_mode_spec (struct window
*, int, int, int,
1061 static void display_menu_bar (struct window
*);
1062 static int display_count_lines (EMACS_INT
, EMACS_INT
, EMACS_INT
, int,
1064 static int display_string (const unsigned char *, Lisp_Object
, Lisp_Object
,
1065 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int);
1066 static void compute_line_metrics (struct it
*);
1067 static void run_redisplay_end_trigger_hook (struct it
*);
1068 static int get_overlay_strings (struct it
*, EMACS_INT
);
1069 static int get_overlay_strings_1 (struct it
*, EMACS_INT
, int);
1070 static void next_overlay_string (struct it
*);
1071 static void reseat (struct it
*, struct text_pos
, int);
1072 static void reseat_1 (struct it
*, struct text_pos
, int);
1073 static void back_to_previous_visible_line_start (struct it
*);
1074 void reseat_at_previous_visible_line_start (struct it
*);
1075 static void reseat_at_next_visible_line_start (struct it
*, int);
1076 static int next_element_from_ellipsis (struct it
*);
1077 static int next_element_from_display_vector (struct it
*);
1078 static int next_element_from_string (struct it
*);
1079 static int next_element_from_c_string (struct it
*);
1080 static int next_element_from_buffer (struct it
*);
1081 static int next_element_from_composition (struct it
*);
1082 static int next_element_from_image (struct it
*);
1083 static int next_element_from_stretch (struct it
*);
1084 static void load_overlay_strings (struct it
*, EMACS_INT
);
1085 static int init_from_display_pos (struct it
*, struct window
*,
1086 struct display_pos
*);
1087 static void reseat_to_string (struct it
*, const unsigned char *,
1088 Lisp_Object
, EMACS_INT
, EMACS_INT
, int, int);
1089 static enum move_it_result
1090 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
1091 enum move_operation_enum
);
1092 void move_it_vertically_backward (struct it
*, int);
1093 static void init_to_row_start (struct it
*, struct window
*,
1094 struct glyph_row
*);
1095 static int init_to_row_end (struct it
*, struct window
*,
1096 struct glyph_row
*);
1097 static void back_to_previous_line_start (struct it
*);
1098 static int forward_to_next_line_start (struct it
*, int *);
1099 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
1100 Lisp_Object
, EMACS_INT
);
1101 static struct text_pos
string_pos (EMACS_INT
, Lisp_Object
);
1102 static struct text_pos
c_string_pos (EMACS_INT
, const unsigned char *, int);
1103 static EMACS_INT
number_of_chars (const unsigned char *, int);
1104 static void compute_stop_pos (struct it
*);
1105 static void compute_string_pos (struct text_pos
*, struct text_pos
,
1107 static int face_before_or_after_it_pos (struct it
*, int);
1108 static EMACS_INT
next_overlay_change (EMACS_INT
);
1109 static int handle_single_display_spec (struct it
*, Lisp_Object
,
1110 Lisp_Object
, Lisp_Object
,
1111 struct text_pos
*, int);
1112 static int underlying_face_id (struct it
*);
1113 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
1116 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1117 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1119 #ifdef HAVE_WINDOW_SYSTEM
1121 static void x_consider_frame_title (Lisp_Object
);
1122 static int tool_bar_lines_needed (struct frame
*, int *);
1123 static void update_tool_bar (struct frame
*, int);
1124 static void build_desired_tool_bar_string (struct frame
*f
);
1125 static int redisplay_tool_bar (struct frame
*);
1126 static void display_tool_bar_line (struct it
*, int);
1127 static void notice_overwritten_cursor (struct window
*,
1128 enum glyph_row_area
,
1129 int, int, int, int);
1130 static void append_stretch_glyph (struct it
*, Lisp_Object
,
1134 #endif /* HAVE_WINDOW_SYSTEM */
1136 static int coords_in_mouse_face_p (struct window
*, int, int);
1140 /***********************************************************************
1141 Window display dimensions
1142 ***********************************************************************/
1144 /* Return the bottom boundary y-position for text lines in window W.
1145 This is the first y position at which a line cannot start.
1146 It is relative to the top of the window.
1148 This is the height of W minus the height of a mode line, if any. */
1151 window_text_bottom_y (struct window
*w
)
1153 int height
= WINDOW_TOTAL_HEIGHT (w
);
1155 if (WINDOW_WANTS_MODELINE_P (w
))
1156 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1160 /* Return the pixel width of display area AREA of window W. AREA < 0
1161 means return the total width of W, not including fringes to
1162 the left and right of the window. */
1165 window_box_width (struct window
*w
, int area
)
1167 int cols
= XFASTINT (w
->total_cols
);
1170 if (!w
->pseudo_window_p
)
1172 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1174 if (area
== TEXT_AREA
)
1176 if (INTEGERP (w
->left_margin_cols
))
1177 cols
-= XFASTINT (w
->left_margin_cols
);
1178 if (INTEGERP (w
->right_margin_cols
))
1179 cols
-= XFASTINT (w
->right_margin_cols
);
1180 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1182 else if (area
== LEFT_MARGIN_AREA
)
1184 cols
= (INTEGERP (w
->left_margin_cols
)
1185 ? XFASTINT (w
->left_margin_cols
) : 0);
1188 else if (area
== RIGHT_MARGIN_AREA
)
1190 cols
= (INTEGERP (w
->right_margin_cols
)
1191 ? XFASTINT (w
->right_margin_cols
) : 0);
1196 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1200 /* Return the pixel height of the display area of window W, not
1201 including mode lines of W, if any. */
1204 window_box_height (struct window
*w
)
1206 struct frame
*f
= XFRAME (w
->frame
);
1207 int height
= WINDOW_TOTAL_HEIGHT (w
);
1209 xassert (height
>= 0);
1211 /* Note: the code below that determines the mode-line/header-line
1212 height is essentially the same as that contained in the macro
1213 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1214 the appropriate glyph row has its `mode_line_p' flag set,
1215 and if it doesn't, uses estimate_mode_line_height instead. */
1217 if (WINDOW_WANTS_MODELINE_P (w
))
1219 struct glyph_row
*ml_row
1220 = (w
->current_matrix
&& w
->current_matrix
->rows
1221 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1223 if (ml_row
&& ml_row
->mode_line_p
)
1224 height
-= ml_row
->height
;
1226 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1229 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1231 struct glyph_row
*hl_row
1232 = (w
->current_matrix
&& w
->current_matrix
->rows
1233 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1235 if (hl_row
&& hl_row
->mode_line_p
)
1236 height
-= hl_row
->height
;
1238 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1241 /* With a very small font and a mode-line that's taller than
1242 default, we might end up with a negative height. */
1243 return max (0, height
);
1246 /* Return the window-relative coordinate of the left edge of display
1247 area AREA of window W. AREA < 0 means return the left edge of the
1248 whole window, to the right of the left fringe of W. */
1251 window_box_left_offset (struct window
*w
, int area
)
1255 if (w
->pseudo_window_p
)
1258 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1260 if (area
== TEXT_AREA
)
1261 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1262 + window_box_width (w
, LEFT_MARGIN_AREA
));
1263 else if (area
== RIGHT_MARGIN_AREA
)
1264 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1265 + window_box_width (w
, LEFT_MARGIN_AREA
)
1266 + window_box_width (w
, TEXT_AREA
)
1267 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1269 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1270 else if (area
== LEFT_MARGIN_AREA
1271 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1272 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1278 /* Return the window-relative coordinate of the right edge of display
1279 area AREA of window W. AREA < 0 means return the right edge of the
1280 whole window, to the left of the right fringe of W. */
1283 window_box_right_offset (struct window
*w
, int area
)
1285 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1288 /* Return the frame-relative coordinate of the left edge of display
1289 area AREA of window W. AREA < 0 means return the left edge of the
1290 whole window, to the right of the left fringe of W. */
1293 window_box_left (struct window
*w
, int area
)
1295 struct frame
*f
= XFRAME (w
->frame
);
1298 if (w
->pseudo_window_p
)
1299 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1301 x
= (WINDOW_LEFT_EDGE_X (w
)
1302 + window_box_left_offset (w
, area
));
1308 /* Return the frame-relative coordinate of the right edge of display
1309 area AREA of window W. AREA < 0 means return the right edge of the
1310 whole window, to the left of the right fringe of W. */
1313 window_box_right (struct window
*w
, int area
)
1315 return window_box_left (w
, area
) + window_box_width (w
, area
);
1318 /* Get the bounding box of the display area AREA of window W, without
1319 mode lines, in frame-relative coordinates. AREA < 0 means the
1320 whole window, not including the left and right fringes of
1321 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1322 coordinates of the upper-left corner of the box. Return in
1323 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1326 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1327 int *box_width
, int *box_height
)
1330 *box_width
= window_box_width (w
, area
);
1332 *box_height
= window_box_height (w
);
1334 *box_x
= window_box_left (w
, area
);
1337 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1338 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1339 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1344 /* Get the bounding box of the display area AREA of window W, without
1345 mode lines. AREA < 0 means the whole window, not including the
1346 left and right fringe of the window. Return in *TOP_LEFT_X
1347 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1348 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1349 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1353 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1354 int *bottom_right_x
, int *bottom_right_y
)
1356 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1358 *bottom_right_x
+= *top_left_x
;
1359 *bottom_right_y
+= *top_left_y
;
1364 /***********************************************************************
1366 ***********************************************************************/
1368 /* Return the bottom y-position of the line the iterator IT is in.
1369 This can modify IT's settings. */
1372 line_bottom_y (struct it
*it
)
1374 int line_height
= it
->max_ascent
+ it
->max_descent
;
1375 int line_top_y
= it
->current_y
;
1377 if (line_height
== 0)
1380 line_height
= last_height
;
1381 else if (IT_CHARPOS (*it
) < ZV
)
1383 move_it_by_lines (it
, 1, 1);
1384 line_height
= (it
->max_ascent
|| it
->max_descent
1385 ? it
->max_ascent
+ it
->max_descent
1390 struct glyph_row
*row
= it
->glyph_row
;
1392 /* Use the default character height. */
1393 it
->glyph_row
= NULL
;
1394 it
->what
= IT_CHARACTER
;
1397 PRODUCE_GLYPHS (it
);
1398 line_height
= it
->ascent
+ it
->descent
;
1399 it
->glyph_row
= row
;
1403 return line_top_y
+ line_height
;
1407 /* Return 1 if position CHARPOS is visible in window W.
1408 CHARPOS < 0 means return info about WINDOW_END position.
1409 If visible, set *X and *Y to pixel coordinates of top left corner.
1410 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1411 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1414 pos_visible_p (struct window
*w
, EMACS_INT charpos
, int *x
, int *y
,
1415 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1418 struct text_pos top
;
1420 struct buffer
*old_buffer
= NULL
;
1422 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1425 if (XBUFFER (w
->buffer
) != current_buffer
)
1427 old_buffer
= current_buffer
;
1428 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1431 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1433 /* Compute exact mode line heights. */
1434 if (WINDOW_WANTS_MODELINE_P (w
))
1435 current_mode_line_height
1436 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1437 current_buffer
->mode_line_format
);
1439 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1440 current_header_line_height
1441 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1442 current_buffer
->header_line_format
);
1444 start_display (&it
, w
, top
);
1445 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1446 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1448 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1450 /* We have reached CHARPOS, or passed it. How the call to
1451 move_it_to can overshoot: (i) If CHARPOS is on invisible
1452 text, move_it_to stops at the end of the invisible text,
1453 after CHARPOS. (ii) If CHARPOS is in a display vector,
1454 move_it_to stops on its last glyph. */
1455 int top_x
= it
.current_x
;
1456 int top_y
= it
.current_y
;
1457 enum it_method it_method
= it
.method
;
1458 /* Calling line_bottom_y may change it.method, it.position, etc. */
1459 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1460 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1462 if (top_y
< window_top_y
)
1463 visible_p
= bottom_y
> window_top_y
;
1464 else if (top_y
< it
.last_visible_y
)
1468 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1470 /* We stopped on the last glyph of a display vector.
1471 Try and recompute. Hack alert! */
1472 if (charpos
< 2 || top
.charpos
>= charpos
)
1473 top_x
= it
.glyph_row
->x
;
1477 start_display (&it2
, w
, top
);
1478 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1479 get_next_display_element (&it2
);
1480 PRODUCE_GLYPHS (&it2
);
1481 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1482 || it2
.current_x
> it2
.last_visible_x
)
1483 top_x
= it
.glyph_row
->x
;
1486 top_x
= it2
.current_x
;
1487 top_y
= it2
.current_y
;
1493 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1494 *rtop
= max (0, window_top_y
- top_y
);
1495 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1496 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1497 - max (top_y
, window_top_y
)));
1506 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1507 move_it_by_lines (&it
, 1, 0);
1508 if (charpos
< IT_CHARPOS (it
)
1509 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1512 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1514 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1515 *rtop
= max (0, -it2
.current_y
);
1516 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1517 - it
.last_visible_y
));
1518 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1520 - max (it2
.current_y
,
1521 WINDOW_HEADER_LINE_HEIGHT (w
))));
1527 set_buffer_internal_1 (old_buffer
);
1529 current_header_line_height
= current_mode_line_height
= -1;
1531 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1532 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1535 /* Debugging code. */
1537 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1538 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1540 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1547 /* Return the next character from STR which is MAXLEN bytes long.
1548 Return in *LEN the length of the character. This is like
1549 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1550 we find one, we return a `?', but with the length of the invalid
1554 string_char_and_length (const unsigned char *str
, int *len
)
1558 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1559 if (!CHAR_VALID_P (c
, 1))
1560 /* We may not change the length here because other places in Emacs
1561 don't use this function, i.e. they silently accept invalid
1570 /* Given a position POS containing a valid character and byte position
1571 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1573 static struct text_pos
1574 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, EMACS_INT nchars
)
1576 xassert (STRINGP (string
) && nchars
>= 0);
1578 if (STRING_MULTIBYTE (string
))
1580 EMACS_INT rest
= SBYTES (string
) - BYTEPOS (pos
);
1581 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1586 string_char_and_length (p
, &len
);
1587 p
+= len
, rest
-= len
;
1588 xassert (rest
>= 0);
1590 BYTEPOS (pos
) += len
;
1594 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1600 /* Value is the text position, i.e. character and byte position,
1601 for character position CHARPOS in STRING. */
1603 static INLINE
struct text_pos
1604 string_pos (EMACS_INT charpos
, Lisp_Object string
)
1606 struct text_pos pos
;
1607 xassert (STRINGP (string
));
1608 xassert (charpos
>= 0);
1609 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1614 /* Value is a text position, i.e. character and byte position, for
1615 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1616 means recognize multibyte characters. */
1618 static struct text_pos
1619 c_string_pos (EMACS_INT charpos
, const unsigned char *s
, int multibyte_p
)
1621 struct text_pos pos
;
1623 xassert (s
!= NULL
);
1624 xassert (charpos
>= 0);
1628 EMACS_INT rest
= strlen (s
);
1631 SET_TEXT_POS (pos
, 0, 0);
1634 string_char_and_length (s
, &len
);
1635 s
+= len
, rest
-= len
;
1636 xassert (rest
>= 0);
1638 BYTEPOS (pos
) += len
;
1642 SET_TEXT_POS (pos
, charpos
, charpos
);
1648 /* Value is the number of characters in C string S. MULTIBYTE_P
1649 non-zero means recognize multibyte characters. */
1652 number_of_chars (const unsigned char *s
, int multibyte_p
)
1658 EMACS_INT rest
= strlen (s
);
1660 unsigned char *p
= (unsigned char *) s
;
1662 for (nchars
= 0; rest
> 0; ++nchars
)
1664 string_char_and_length (p
, &len
);
1665 rest
-= len
, p
+= len
;
1669 nchars
= strlen (s
);
1675 /* Compute byte position NEWPOS->bytepos corresponding to
1676 NEWPOS->charpos. POS is a known position in string STRING.
1677 NEWPOS->charpos must be >= POS.charpos. */
1680 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1682 xassert (STRINGP (string
));
1683 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1685 if (STRING_MULTIBYTE (string
))
1686 *newpos
= string_pos_nchars_ahead (pos
, string
,
1687 CHARPOS (*newpos
) - CHARPOS (pos
));
1689 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1693 Return an estimation of the pixel height of mode or header lines on
1694 frame F. FACE_ID specifies what line's height to estimate. */
1697 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1699 #ifdef HAVE_WINDOW_SYSTEM
1700 if (FRAME_WINDOW_P (f
))
1702 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1704 /* This function is called so early when Emacs starts that the face
1705 cache and mode line face are not yet initialized. */
1706 if (FRAME_FACE_CACHE (f
))
1708 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1712 height
= FONT_HEIGHT (face
->font
);
1713 if (face
->box_line_width
> 0)
1714 height
+= 2 * face
->box_line_width
;
1725 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1726 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1727 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1728 not force the value into range. */
1731 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1732 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1735 #ifdef HAVE_WINDOW_SYSTEM
1736 if (FRAME_WINDOW_P (f
))
1738 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1739 even for negative values. */
1741 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1743 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1745 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1746 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1749 STORE_NATIVE_RECT (*bounds
,
1750 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1751 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1752 FRAME_COLUMN_WIDTH (f
) - 1,
1753 FRAME_LINE_HEIGHT (f
) - 1);
1759 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1760 pix_x
= FRAME_TOTAL_COLS (f
);
1764 else if (pix_y
> FRAME_LINES (f
))
1765 pix_y
= FRAME_LINES (f
);
1775 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1776 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1777 can't tell the positions because W's display is not up to date,
1781 glyph_to_pixel_coords (struct window
*w
, int hpos
, int vpos
,
1782 int *frame_x
, int *frame_y
)
1784 #ifdef HAVE_WINDOW_SYSTEM
1785 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1789 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1790 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1792 if (display_completed
)
1794 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1795 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1796 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1802 hpos
+= glyph
->pixel_width
;
1806 /* If first glyph is partially visible, its first visible position is still 0. */
1818 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1819 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1830 /* Find the glyph under window-relative coordinates X/Y in window W.
1831 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1832 strings. Return in *HPOS and *VPOS the row and column number of
1833 the glyph found. Return in *AREA the glyph area containing X.
1834 Value is a pointer to the glyph found or null if X/Y is not on
1835 text, or we can't tell because W's current matrix is not up to
1840 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1841 int *dx
, int *dy
, int *area
)
1843 struct glyph
*glyph
, *end
;
1844 struct glyph_row
*row
= NULL
;
1847 /* Find row containing Y. Give up if some row is not enabled. */
1848 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1850 row
= MATRIX_ROW (w
->current_matrix
, i
);
1851 if (!row
->enabled_p
)
1853 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1860 /* Give up if Y is not in the window. */
1861 if (i
== w
->current_matrix
->nrows
)
1864 /* Get the glyph area containing X. */
1865 if (w
->pseudo_window_p
)
1872 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1874 *area
= LEFT_MARGIN_AREA
;
1875 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1877 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1880 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1884 *area
= RIGHT_MARGIN_AREA
;
1885 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1889 /* Find glyph containing X. */
1890 glyph
= row
->glyphs
[*area
];
1891 end
= glyph
+ row
->used
[*area
];
1893 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1895 x
-= glyph
->pixel_width
;
1905 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1908 *hpos
= glyph
- row
->glyphs
[*area
];
1913 Convert frame-relative x/y to coordinates relative to window W.
1914 Takes pseudo-windows into account. */
1917 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1919 if (w
->pseudo_window_p
)
1921 /* A pseudo-window is always full-width, and starts at the
1922 left edge of the frame, plus a frame border. */
1923 struct frame
*f
= XFRAME (w
->frame
);
1924 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1925 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1929 *x
-= WINDOW_LEFT_EDGE_X (w
);
1930 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1934 #ifdef HAVE_WINDOW_SYSTEM
1937 Return in RECTS[] at most N clipping rectangles for glyph string S.
1938 Return the number of stored rectangles. */
1941 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1948 if (s
->row
->full_width_p
)
1950 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1951 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1952 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1954 /* Unless displaying a mode or menu bar line, which are always
1955 fully visible, clip to the visible part of the row. */
1956 if (s
->w
->pseudo_window_p
)
1957 r
.height
= s
->row
->visible_height
;
1959 r
.height
= s
->height
;
1963 /* This is a text line that may be partially visible. */
1964 r
.x
= window_box_left (s
->w
, s
->area
);
1965 r
.width
= window_box_width (s
->w
, s
->area
);
1966 r
.height
= s
->row
->visible_height
;
1970 if (r
.x
< s
->clip_head
->x
)
1972 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1973 r
.width
-= s
->clip_head
->x
- r
.x
;
1976 r
.x
= s
->clip_head
->x
;
1979 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1981 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1982 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1987 /* If S draws overlapping rows, it's sufficient to use the top and
1988 bottom of the window for clipping because this glyph string
1989 intentionally draws over other lines. */
1990 if (s
->for_overlaps
)
1992 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1993 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1995 /* Alas, the above simple strategy does not work for the
1996 environments with anti-aliased text: if the same text is
1997 drawn onto the same place multiple times, it gets thicker.
1998 If the overlap we are processing is for the erased cursor, we
1999 take the intersection with the rectagle of the cursor. */
2000 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2002 XRectangle rc
, r_save
= r
;
2004 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2005 rc
.y
= s
->w
->phys_cursor
.y
;
2006 rc
.width
= s
->w
->phys_cursor_width
;
2007 rc
.height
= s
->w
->phys_cursor_height
;
2009 x_intersect_rectangles (&r_save
, &rc
, &r
);
2014 /* Don't use S->y for clipping because it doesn't take partially
2015 visible lines into account. For example, it can be negative for
2016 partially visible lines at the top of a window. */
2017 if (!s
->row
->full_width_p
2018 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2019 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2021 r
.y
= max (0, s
->row
->y
);
2024 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2026 /* If drawing the cursor, don't let glyph draw outside its
2027 advertised boundaries. Cleartype does this under some circumstances. */
2028 if (s
->hl
== DRAW_CURSOR
)
2030 struct glyph
*glyph
= s
->first_glyph
;
2035 r
.width
-= s
->x
- r
.x
;
2038 r
.width
= min (r
.width
, glyph
->pixel_width
);
2040 /* If r.y is below window bottom, ensure that we still see a cursor. */
2041 height
= min (glyph
->ascent
+ glyph
->descent
,
2042 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2043 max_y
= window_text_bottom_y (s
->w
) - height
;
2044 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2045 if (s
->ybase
- glyph
->ascent
> max_y
)
2052 /* Don't draw cursor glyph taller than our actual glyph. */
2053 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2054 if (height
< r
.height
)
2056 max_y
= r
.y
+ r
.height
;
2057 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2058 r
.height
= min (max_y
- r
.y
, height
);
2065 XRectangle r_save
= r
;
2067 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2071 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2072 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2074 #ifdef CONVERT_FROM_XRECT
2075 CONVERT_FROM_XRECT (r
, *rects
);
2083 /* If we are processing overlapping and allowed to return
2084 multiple clipping rectangles, we exclude the row of the glyph
2085 string from the clipping rectangle. This is to avoid drawing
2086 the same text on the environment with anti-aliasing. */
2087 #ifdef CONVERT_FROM_XRECT
2090 XRectangle
*rs
= rects
;
2092 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2094 if (s
->for_overlaps
& OVERLAPS_PRED
)
2097 if (r
.y
+ r
.height
> row_y
)
2100 rs
[i
].height
= row_y
- r
.y
;
2106 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2109 if (r
.y
< row_y
+ s
->row
->visible_height
)
2111 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2113 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2114 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2123 #ifdef CONVERT_FROM_XRECT
2124 for (i
= 0; i
< n
; i
++)
2125 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2132 Return in *NR the clipping rectangle for glyph string S. */
2135 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2137 get_glyph_string_clip_rects (s
, nr
, 1);
2142 Return the position and height of the phys cursor in window W.
2143 Set w->phys_cursor_width to width of phys cursor.
2147 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2148 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2150 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2151 int x
, y
, wd
, h
, h0
, y0
;
2153 /* Compute the width of the rectangle to draw. If on a stretch
2154 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2155 rectangle as wide as the glyph, but use a canonical character
2157 wd
= glyph
->pixel_width
- 1;
2158 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2162 x
= w
->phys_cursor
.x
;
2169 if (glyph
->type
== STRETCH_GLYPH
2170 && !x_stretch_cursor_p
)
2171 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2172 w
->phys_cursor_width
= wd
;
2174 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2176 /* If y is below window bottom, ensure that we still see a cursor. */
2177 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2179 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2180 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2182 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2185 h
= max (h
- (y0
- y
) + 1, h0
);
2190 y0
= window_text_bottom_y (w
) - h0
;
2198 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2199 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2204 * Remember which glyph the mouse is over.
2208 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2212 struct glyph_row
*r
, *gr
, *end_row
;
2213 enum window_part part
;
2214 enum glyph_row_area area
;
2215 int x
, y
, width
, height
;
2217 /* Try to determine frame pixel position and size of the glyph under
2218 frame pixel coordinates X/Y on frame F. */
2220 if (!f
->glyphs_initialized_p
2221 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2224 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2225 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2229 w
= XWINDOW (window
);
2230 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2231 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2233 x
= window_relative_x_coord (w
, part
, gx
);
2234 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2236 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2237 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2239 if (w
->pseudo_window_p
)
2242 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2248 case ON_LEFT_MARGIN
:
2249 area
= LEFT_MARGIN_AREA
;
2252 case ON_RIGHT_MARGIN
:
2253 area
= RIGHT_MARGIN_AREA
;
2256 case ON_HEADER_LINE
:
2258 gr
= (part
== ON_HEADER_LINE
2259 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2260 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2263 goto text_glyph_row_found
;
2270 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2271 if (r
->y
+ r
->height
> y
)
2277 text_glyph_row_found
:
2280 struct glyph
*g
= gr
->glyphs
[area
];
2281 struct glyph
*end
= g
+ gr
->used
[area
];
2283 height
= gr
->height
;
2284 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2285 if (gx
+ g
->pixel_width
> x
)
2290 if (g
->type
== IMAGE_GLYPH
)
2292 /* Don't remember when mouse is over image, as
2293 image may have hot-spots. */
2294 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2297 width
= g
->pixel_width
;
2301 /* Use nominal char spacing at end of line. */
2303 gx
+= (x
/ width
) * width
;
2306 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2307 gx
+= window_box_left_offset (w
, area
);
2311 /* Use nominal line height at end of window. */
2312 gx
= (x
/ width
) * width
;
2314 gy
+= (y
/ height
) * height
;
2318 case ON_LEFT_FRINGE
:
2319 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2320 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2321 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2322 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2325 case ON_RIGHT_FRINGE
:
2326 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2327 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2328 : window_box_right_offset (w
, TEXT_AREA
));
2329 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2333 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2335 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2336 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2337 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2339 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2343 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2344 if (r
->y
+ r
->height
> y
)
2351 height
= gr
->height
;
2354 /* Use nominal line height at end of window. */
2356 gy
+= (y
/ height
) * height
;
2363 /* If there is no glyph under the mouse, then we divide the screen
2364 into a grid of the smallest glyph in the frame, and use that
2367 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2368 round down even for negative values. */
2374 gx
= (gx
/ width
) * width
;
2375 gy
= (gy
/ height
) * height
;
2380 gx
+= WINDOW_LEFT_EDGE_X (w
);
2381 gy
+= WINDOW_TOP_EDGE_Y (w
);
2384 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2386 /* Visible feedback for debugging. */
2389 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2390 f
->output_data
.x
->normal_gc
,
2391 gx
, gy
, width
, height
);
2397 #endif /* HAVE_WINDOW_SYSTEM */
2400 /***********************************************************************
2401 Lisp form evaluation
2402 ***********************************************************************/
2404 /* Error handler for safe_eval and safe_call. */
2407 safe_eval_handler (Lisp_Object arg
)
2409 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2414 /* Evaluate SEXPR and return the result, or nil if something went
2415 wrong. Prevent redisplay during the evaluation. */
2417 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2418 Return the result, or nil if something went wrong. Prevent
2419 redisplay during the evaluation. */
2422 safe_call (int nargs
, Lisp_Object
*args
)
2426 if (inhibit_eval_during_redisplay
)
2430 int count
= SPECPDL_INDEX ();
2431 struct gcpro gcpro1
;
2434 gcpro1
.nvars
= nargs
;
2435 specbind (Qinhibit_redisplay
, Qt
);
2436 /* Use Qt to ensure debugger does not run,
2437 so there is no possibility of wanting to redisplay. */
2438 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2441 val
= unbind_to (count
, val
);
2448 /* Call function FN with one argument ARG.
2449 Return the result, or nil if something went wrong. */
2452 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2454 Lisp_Object args
[2];
2457 return safe_call (2, args
);
2460 static Lisp_Object Qeval
;
2463 safe_eval (Lisp_Object sexpr
)
2465 return safe_call1 (Qeval
, sexpr
);
2468 /* Call function FN with one argument ARG.
2469 Return the result, or nil if something went wrong. */
2472 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2474 Lisp_Object args
[3];
2478 return safe_call (3, args
);
2483 /***********************************************************************
2485 ***********************************************************************/
2489 /* Define CHECK_IT to perform sanity checks on iterators.
2490 This is for debugging. It is too slow to do unconditionally. */
2496 if (it
->method
== GET_FROM_STRING
)
2498 xassert (STRINGP (it
->string
));
2499 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2503 xassert (IT_STRING_CHARPOS (*it
) < 0);
2504 if (it
->method
== GET_FROM_BUFFER
)
2506 /* Check that character and byte positions agree. */
2507 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2512 xassert (it
->current
.dpvec_index
>= 0);
2514 xassert (it
->current
.dpvec_index
< 0);
2517 #define CHECK_IT(IT) check_it ((IT))
2521 #define CHECK_IT(IT) (void) 0
2528 /* Check that the window end of window W is what we expect it
2529 to be---the last row in the current matrix displaying text. */
2532 check_window_end (w
)
2535 if (!MINI_WINDOW_P (w
)
2536 && !NILP (w
->window_end_valid
))
2538 struct glyph_row
*row
;
2539 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2540 XFASTINT (w
->window_end_vpos
)),
2542 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2543 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2547 #define CHECK_WINDOW_END(W) check_window_end ((W))
2549 #else /* not GLYPH_DEBUG */
2551 #define CHECK_WINDOW_END(W) (void) 0
2553 #endif /* not GLYPH_DEBUG */
2557 /***********************************************************************
2558 Iterator initialization
2559 ***********************************************************************/
2561 /* Initialize IT for displaying current_buffer in window W, starting
2562 at character position CHARPOS. CHARPOS < 0 means that no buffer
2563 position is specified which is useful when the iterator is assigned
2564 a position later. BYTEPOS is the byte position corresponding to
2565 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2567 If ROW is not null, calls to produce_glyphs with IT as parameter
2568 will produce glyphs in that row.
2570 BASE_FACE_ID is the id of a base face to use. It must be one of
2571 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2572 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2573 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2575 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2576 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2577 will be initialized to use the corresponding mode line glyph row of
2578 the desired matrix of W. */
2581 init_iterator (struct it
*it
, struct window
*w
,
2582 EMACS_INT charpos
, EMACS_INT bytepos
,
2583 struct glyph_row
*row
, enum face_id base_face_id
)
2585 int highlight_region_p
;
2586 enum face_id remapped_base_face_id
= base_face_id
;
2588 /* Some precondition checks. */
2589 xassert (w
!= NULL
&& it
!= NULL
);
2590 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2593 /* If face attributes have been changed since the last redisplay,
2594 free realized faces now because they depend on face definitions
2595 that might have changed. Don't free faces while there might be
2596 desired matrices pending which reference these faces. */
2597 if (face_change_count
&& !inhibit_free_realized_faces
)
2599 face_change_count
= 0;
2600 free_all_realized_faces (Qnil
);
2603 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2604 if (! NILP (Vface_remapping_alist
))
2605 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2607 /* Use one of the mode line rows of W's desired matrix if
2611 if (base_face_id
== MODE_LINE_FACE_ID
2612 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2613 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2614 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2615 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2619 memset (it
, 0, sizeof *it
);
2620 it
->current
.overlay_string_index
= -1;
2621 it
->current
.dpvec_index
= -1;
2622 it
->base_face_id
= remapped_base_face_id
;
2624 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2626 /* The window in which we iterate over current_buffer: */
2627 XSETWINDOW (it
->window
, w
);
2629 it
->f
= XFRAME (w
->frame
);
2633 /* Extra space between lines (on window systems only). */
2634 if (base_face_id
== DEFAULT_FACE_ID
2635 && FRAME_WINDOW_P (it
->f
))
2637 if (NATNUMP (current_buffer
->extra_line_spacing
))
2638 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2639 else if (FLOATP (current_buffer
->extra_line_spacing
))
2640 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2641 * FRAME_LINE_HEIGHT (it
->f
));
2642 else if (it
->f
->extra_line_spacing
> 0)
2643 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2644 it
->max_extra_line_spacing
= 0;
2647 /* If realized faces have been removed, e.g. because of face
2648 attribute changes of named faces, recompute them. When running
2649 in batch mode, the face cache of the initial frame is null. If
2650 we happen to get called, make a dummy face cache. */
2651 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2652 init_frame_faces (it
->f
);
2653 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2654 recompute_basic_faces (it
->f
);
2656 /* Current value of the `slice', `space-width', and 'height' properties. */
2657 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2658 it
->space_width
= Qnil
;
2659 it
->font_height
= Qnil
;
2660 it
->override_ascent
= -1;
2662 /* Are control characters displayed as `^C'? */
2663 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2665 /* -1 means everything between a CR and the following line end
2666 is invisible. >0 means lines indented more than this value are
2668 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2669 ? XFASTINT (current_buffer
->selective_display
)
2670 : (!NILP (current_buffer
->selective_display
)
2672 it
->selective_display_ellipsis_p
2673 = !NILP (current_buffer
->selective_display_ellipses
);
2675 /* Display table to use. */
2676 it
->dp
= window_display_table (w
);
2678 /* Are multibyte characters enabled in current_buffer? */
2679 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2681 /* Do we need to reorder bidirectional text? Not if this is a
2682 unibyte buffer: by definition, none of the single-byte characters
2683 are strong R2L, so no reordering is needed. And bidi.c doesn't
2684 support unibyte buffers anyway. */
2686 = !NILP (current_buffer
->bidi_display_reordering
) && it
->multibyte_p
;
2688 /* Non-zero if we should highlight the region. */
2690 = (!NILP (Vtransient_mark_mode
)
2691 && !NILP (current_buffer
->mark_active
)
2692 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2694 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2695 start and end of a visible region in window IT->w. Set both to
2696 -1 to indicate no region. */
2697 if (highlight_region_p
2698 /* Maybe highlight only in selected window. */
2699 && (/* Either show region everywhere. */
2700 highlight_nonselected_windows
2701 /* Or show region in the selected window. */
2702 || w
== XWINDOW (selected_window
)
2703 /* Or show the region if we are in the mini-buffer and W is
2704 the window the mini-buffer refers to. */
2705 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2706 && WINDOWP (minibuf_selected_window
)
2707 && w
== XWINDOW (minibuf_selected_window
))))
2709 EMACS_INT charpos
= marker_position (current_buffer
->mark
);
2710 it
->region_beg_charpos
= min (PT
, charpos
);
2711 it
->region_end_charpos
= max (PT
, charpos
);
2714 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2716 /* Get the position at which the redisplay_end_trigger hook should
2717 be run, if it is to be run at all. */
2718 if (MARKERP (w
->redisplay_end_trigger
)
2719 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2720 it
->redisplay_end_trigger_charpos
2721 = marker_position (w
->redisplay_end_trigger
);
2722 else if (INTEGERP (w
->redisplay_end_trigger
))
2723 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2725 /* Correct bogus values of tab_width. */
2726 it
->tab_width
= XINT (current_buffer
->tab_width
);
2727 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2730 /* Are lines in the display truncated? */
2731 if (base_face_id
!= DEFAULT_FACE_ID
2732 || XINT (it
->w
->hscroll
)
2733 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2734 && ((!NILP (Vtruncate_partial_width_windows
)
2735 && !INTEGERP (Vtruncate_partial_width_windows
))
2736 || (INTEGERP (Vtruncate_partial_width_windows
)
2737 && (WINDOW_TOTAL_COLS (it
->w
)
2738 < XINT (Vtruncate_partial_width_windows
))))))
2739 it
->line_wrap
= TRUNCATE
;
2740 else if (NILP (current_buffer
->truncate_lines
))
2741 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2742 ? WINDOW_WRAP
: WORD_WRAP
;
2744 it
->line_wrap
= TRUNCATE
;
2746 /* Get dimensions of truncation and continuation glyphs. These are
2747 displayed as fringe bitmaps under X, so we don't need them for such
2749 if (!FRAME_WINDOW_P (it
->f
))
2751 if (it
->line_wrap
== TRUNCATE
)
2753 /* We will need the truncation glyph. */
2754 xassert (it
->glyph_row
== NULL
);
2755 produce_special_glyphs (it
, IT_TRUNCATION
);
2756 it
->truncation_pixel_width
= it
->pixel_width
;
2760 /* We will need the continuation glyph. */
2761 xassert (it
->glyph_row
== NULL
);
2762 produce_special_glyphs (it
, IT_CONTINUATION
);
2763 it
->continuation_pixel_width
= it
->pixel_width
;
2766 /* Reset these values to zero because the produce_special_glyphs
2767 above has changed them. */
2768 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2769 it
->phys_ascent
= it
->phys_descent
= 0;
2772 /* Set this after getting the dimensions of truncation and
2773 continuation glyphs, so that we don't produce glyphs when calling
2774 produce_special_glyphs, above. */
2775 it
->glyph_row
= row
;
2776 it
->area
= TEXT_AREA
;
2778 /* Forget any previous info about this row being reversed. */
2780 it
->glyph_row
->reversed_p
= 0;
2782 /* Get the dimensions of the display area. The display area
2783 consists of the visible window area plus a horizontally scrolled
2784 part to the left of the window. All x-values are relative to the
2785 start of this total display area. */
2786 if (base_face_id
!= DEFAULT_FACE_ID
)
2788 /* Mode lines, menu bar in terminal frames. */
2789 it
->first_visible_x
= 0;
2790 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2795 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2796 it
->last_visible_x
= (it
->first_visible_x
2797 + window_box_width (w
, TEXT_AREA
));
2799 /* If we truncate lines, leave room for the truncator glyph(s) at
2800 the right margin. Otherwise, leave room for the continuation
2801 glyph(s). Truncation and continuation glyphs are not inserted
2802 for window-based redisplay. */
2803 if (!FRAME_WINDOW_P (it
->f
))
2805 if (it
->line_wrap
== TRUNCATE
)
2806 it
->last_visible_x
-= it
->truncation_pixel_width
;
2808 it
->last_visible_x
-= it
->continuation_pixel_width
;
2811 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2812 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2815 /* Leave room for a border glyph. */
2816 if (!FRAME_WINDOW_P (it
->f
)
2817 && !WINDOW_RIGHTMOST_P (it
->w
))
2818 it
->last_visible_x
-= 1;
2820 it
->last_visible_y
= window_text_bottom_y (w
);
2822 /* For mode lines and alike, arrange for the first glyph having a
2823 left box line if the face specifies a box. */
2824 if (base_face_id
!= DEFAULT_FACE_ID
)
2828 it
->face_id
= remapped_base_face_id
;
2830 /* If we have a boxed mode line, make the first character appear
2831 with a left box line. */
2832 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2833 if (face
->box
!= FACE_NO_BOX
)
2834 it
->start_of_box_run_p
= 1;
2837 /* If we are to reorder bidirectional text, init the bidi
2841 /* Note the paragraph direction that this buffer wants to
2843 if (EQ (current_buffer
->bidi_paragraph_direction
, Qleft_to_right
))
2844 it
->paragraph_embedding
= L2R
;
2845 else if (EQ (current_buffer
->bidi_paragraph_direction
, Qright_to_left
))
2846 it
->paragraph_embedding
= R2L
;
2848 it
->paragraph_embedding
= NEUTRAL_DIR
;
2849 bidi_init_it (charpos
, bytepos
, &it
->bidi_it
);
2852 /* If a buffer position was specified, set the iterator there,
2853 getting overlays and face properties from that position. */
2854 if (charpos
>= BUF_BEG (current_buffer
))
2856 it
->end_charpos
= ZV
;
2858 IT_CHARPOS (*it
) = charpos
;
2860 /* Compute byte position if not specified. */
2861 if (bytepos
< charpos
)
2862 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2864 IT_BYTEPOS (*it
) = bytepos
;
2866 it
->start
= it
->current
;
2868 /* Compute faces etc. */
2869 reseat (it
, it
->current
.pos
, 1);
2876 /* Initialize IT for the display of window W with window start POS. */
2879 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2881 struct glyph_row
*row
;
2882 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2884 row
= w
->desired_matrix
->rows
+ first_vpos
;
2885 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2886 it
->first_vpos
= first_vpos
;
2888 /* Don't reseat to previous visible line start if current start
2889 position is in a string or image. */
2890 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2892 int start_at_line_beg_p
;
2893 int first_y
= it
->current_y
;
2895 /* If window start is not at a line start, skip forward to POS to
2896 get the correct continuation lines width. */
2897 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2898 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2899 if (!start_at_line_beg_p
)
2903 reseat_at_previous_visible_line_start (it
);
2904 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2906 new_x
= it
->current_x
+ it
->pixel_width
;
2908 /* If lines are continued, this line may end in the middle
2909 of a multi-glyph character (e.g. a control character
2910 displayed as \003, or in the middle of an overlay
2911 string). In this case move_it_to above will not have
2912 taken us to the start of the continuation line but to the
2913 end of the continued line. */
2914 if (it
->current_x
> 0
2915 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2916 && (/* And glyph doesn't fit on the line. */
2917 new_x
> it
->last_visible_x
2918 /* Or it fits exactly and we're on a window
2920 || (new_x
== it
->last_visible_x
2921 && FRAME_WINDOW_P (it
->f
))))
2923 if (it
->current
.dpvec_index
>= 0
2924 || it
->current
.overlay_string_index
>= 0)
2926 set_iterator_to_next (it
, 1);
2927 move_it_in_display_line_to (it
, -1, -1, 0);
2930 it
->continuation_lines_width
+= it
->current_x
;
2933 /* We're starting a new display line, not affected by the
2934 height of the continued line, so clear the appropriate
2935 fields in the iterator structure. */
2936 it
->max_ascent
= it
->max_descent
= 0;
2937 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2939 it
->current_y
= first_y
;
2941 it
->current_x
= it
->hpos
= 0;
2947 /* Return 1 if POS is a position in ellipses displayed for invisible
2948 text. W is the window we display, for text property lookup. */
2951 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2953 Lisp_Object prop
, window
;
2955 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2957 /* If POS specifies a position in a display vector, this might
2958 be for an ellipsis displayed for invisible text. We won't
2959 get the iterator set up for delivering that ellipsis unless
2960 we make sure that it gets aware of the invisible text. */
2961 if (pos
->dpvec_index
>= 0
2962 && pos
->overlay_string_index
< 0
2963 && CHARPOS (pos
->string_pos
) < 0
2965 && (XSETWINDOW (window
, w
),
2966 prop
= Fget_char_property (make_number (charpos
),
2967 Qinvisible
, window
),
2968 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2970 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2972 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2979 /* Initialize IT for stepping through current_buffer in window W,
2980 starting at position POS that includes overlay string and display
2981 vector/ control character translation position information. Value
2982 is zero if there are overlay strings with newlines at POS. */
2985 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2987 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2988 int i
, overlay_strings_with_newlines
= 0;
2990 /* If POS specifies a position in a display vector, this might
2991 be for an ellipsis displayed for invisible text. We won't
2992 get the iterator set up for delivering that ellipsis unless
2993 we make sure that it gets aware of the invisible text. */
2994 if (in_ellipses_for_invisible_text_p (pos
, w
))
3000 /* Keep in mind: the call to reseat in init_iterator skips invisible
3001 text, so we might end up at a position different from POS. This
3002 is only a problem when POS is a row start after a newline and an
3003 overlay starts there with an after-string, and the overlay has an
3004 invisible property. Since we don't skip invisible text in
3005 display_line and elsewhere immediately after consuming the
3006 newline before the row start, such a POS will not be in a string,
3007 but the call to init_iterator below will move us to the
3009 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3011 /* This only scans the current chunk -- it should scan all chunks.
3012 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3013 to 16 in 22.1 to make this a lesser problem. */
3014 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3016 const char *s
= SDATA (it
->overlay_strings
[i
]);
3017 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3019 while (s
< e
&& *s
!= '\n')
3024 overlay_strings_with_newlines
= 1;
3029 /* If position is within an overlay string, set up IT to the right
3031 if (pos
->overlay_string_index
>= 0)
3035 /* If the first overlay string happens to have a `display'
3036 property for an image, the iterator will be set up for that
3037 image, and we have to undo that setup first before we can
3038 correct the overlay string index. */
3039 if (it
->method
== GET_FROM_IMAGE
)
3042 /* We already have the first chunk of overlay strings in
3043 IT->overlay_strings. Load more until the one for
3044 pos->overlay_string_index is in IT->overlay_strings. */
3045 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3047 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3048 it
->current
.overlay_string_index
= 0;
3051 load_overlay_strings (it
, 0);
3052 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3056 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3057 relative_index
= (it
->current
.overlay_string_index
3058 % OVERLAY_STRING_CHUNK_SIZE
);
3059 it
->string
= it
->overlay_strings
[relative_index
];
3060 xassert (STRINGP (it
->string
));
3061 it
->current
.string_pos
= pos
->string_pos
;
3062 it
->method
= GET_FROM_STRING
;
3065 if (CHARPOS (pos
->string_pos
) >= 0)
3067 /* Recorded position is not in an overlay string, but in another
3068 string. This can only be a string from a `display' property.
3069 IT should already be filled with that string. */
3070 it
->current
.string_pos
= pos
->string_pos
;
3071 xassert (STRINGP (it
->string
));
3074 /* Restore position in display vector translations, control
3075 character translations or ellipses. */
3076 if (pos
->dpvec_index
>= 0)
3078 if (it
->dpvec
== NULL
)
3079 get_next_display_element (it
);
3080 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3081 it
->current
.dpvec_index
= pos
->dpvec_index
;
3085 return !overlay_strings_with_newlines
;
3089 /* Initialize IT for stepping through current_buffer in window W
3090 starting at ROW->start. */
3093 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3095 init_from_display_pos (it
, w
, &row
->start
);
3096 it
->start
= row
->start
;
3097 it
->continuation_lines_width
= row
->continuation_lines_width
;
3102 /* Initialize IT for stepping through current_buffer in window W
3103 starting in the line following ROW, i.e. starting at ROW->end.
3104 Value is zero if there are overlay strings with newlines at ROW's
3108 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3112 if (init_from_display_pos (it
, w
, &row
->end
))
3114 if (row
->continued_p
)
3115 it
->continuation_lines_width
3116 = row
->continuation_lines_width
+ row
->pixel_width
;
3127 /***********************************************************************
3129 ***********************************************************************/
3131 /* Called when IT reaches IT->stop_charpos. Handle text property and
3132 overlay changes. Set IT->stop_charpos to the next position where
3136 handle_stop (struct it
*it
)
3138 enum prop_handled handled
;
3139 int handle_overlay_change_p
;
3143 it
->current
.dpvec_index
= -1;
3144 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3145 it
->ignore_overlay_strings_at_pos_p
= 0;
3148 /* Use face of preceding text for ellipsis (if invisible) */
3149 if (it
->selective_display_ellipsis_p
)
3150 it
->saved_face_id
= it
->face_id
;
3154 handled
= HANDLED_NORMALLY
;
3156 /* Call text property handlers. */
3157 for (p
= it_props
; p
->handler
; ++p
)
3159 handled
= p
->handler (it
);
3161 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3163 else if (handled
== HANDLED_RETURN
)
3165 /* We still want to show before and after strings from
3166 overlays even if the actual buffer text is replaced. */
3167 if (!handle_overlay_change_p
3169 || !get_overlay_strings_1 (it
, 0, 0))
3172 setup_for_ellipsis (it
, 0);
3173 /* When handling a display spec, we might load an
3174 empty string. In that case, discard it here. We
3175 used to discard it in handle_single_display_spec,
3176 but that causes get_overlay_strings_1, above, to
3177 ignore overlay strings that we must check. */
3178 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3182 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3186 it
->ignore_overlay_strings_at_pos_p
= 1;
3187 it
->string_from_display_prop_p
= 0;
3188 handle_overlay_change_p
= 0;
3190 handled
= HANDLED_RECOMPUTE_PROPS
;
3193 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3194 handle_overlay_change_p
= 0;
3197 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3199 /* Don't check for overlay strings below when set to deliver
3200 characters from a display vector. */
3201 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3202 handle_overlay_change_p
= 0;
3204 /* Handle overlay changes.
3205 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3206 if it finds overlays. */
3207 if (handle_overlay_change_p
)
3208 handled
= handle_overlay_change (it
);
3213 setup_for_ellipsis (it
, 0);
3217 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3219 /* Determine where to stop next. */
3220 if (handled
== HANDLED_NORMALLY
)
3221 compute_stop_pos (it
);
3225 /* Compute IT->stop_charpos from text property and overlay change
3226 information for IT's current position. */
3229 compute_stop_pos (struct it
*it
)
3231 register INTERVAL iv
, next_iv
;
3232 Lisp_Object object
, limit
, position
;
3233 EMACS_INT charpos
, bytepos
;
3235 /* If nowhere else, stop at the end. */
3236 it
->stop_charpos
= it
->end_charpos
;
3238 if (STRINGP (it
->string
))
3240 /* Strings are usually short, so don't limit the search for
3242 object
= it
->string
;
3244 charpos
= IT_STRING_CHARPOS (*it
);
3245 bytepos
= IT_STRING_BYTEPOS (*it
);
3251 /* If next overlay change is in front of the current stop pos
3252 (which is IT->end_charpos), stop there. Note: value of
3253 next_overlay_change is point-max if no overlay change
3255 charpos
= IT_CHARPOS (*it
);
3256 bytepos
= IT_BYTEPOS (*it
);
3257 pos
= next_overlay_change (charpos
);
3258 if (pos
< it
->stop_charpos
)
3259 it
->stop_charpos
= pos
;
3261 /* If showing the region, we have to stop at the region
3262 start or end because the face might change there. */
3263 if (it
->region_beg_charpos
> 0)
3265 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3266 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3267 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3268 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3271 /* Set up variables for computing the stop position from text
3272 property changes. */
3273 XSETBUFFER (object
, current_buffer
);
3274 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3277 /* Get the interval containing IT's position. Value is a null
3278 interval if there isn't such an interval. */
3279 position
= make_number (charpos
);
3280 iv
= validate_interval_range (object
, &position
, &position
, 0);
3281 if (!NULL_INTERVAL_P (iv
))
3283 Lisp_Object values_here
[LAST_PROP_IDX
];
3286 /* Get properties here. */
3287 for (p
= it_props
; p
->handler
; ++p
)
3288 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3290 /* Look for an interval following iv that has different
3292 for (next_iv
= next_interval (iv
);
3293 (!NULL_INTERVAL_P (next_iv
)
3295 || XFASTINT (limit
) > next_iv
->position
));
3296 next_iv
= next_interval (next_iv
))
3298 for (p
= it_props
; p
->handler
; ++p
)
3300 Lisp_Object new_value
;
3302 new_value
= textget (next_iv
->plist
, *p
->name
);
3303 if (!EQ (values_here
[p
->idx
], new_value
))
3311 if (!NULL_INTERVAL_P (next_iv
))
3313 if (INTEGERP (limit
)
3314 && next_iv
->position
>= XFASTINT (limit
))
3315 /* No text property change up to limit. */
3316 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3318 /* Text properties change in next_iv. */
3319 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3323 if (it
->cmp_it
.id
< 0)
3325 EMACS_INT stoppos
= it
->end_charpos
;
3327 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3329 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3330 stoppos
, it
->string
);
3333 xassert (STRINGP (it
->string
)
3334 || (it
->stop_charpos
>= BEGV
3335 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3339 /* Return the position of the next overlay change after POS in
3340 current_buffer. Value is point-max if no overlay change
3341 follows. This is like `next-overlay-change' but doesn't use
3345 next_overlay_change (EMACS_INT pos
)
3349 Lisp_Object
*overlays
;
3352 /* Get all overlays at the given position. */
3353 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3355 /* If any of these overlays ends before endpos,
3356 use its ending point instead. */
3357 for (i
= 0; i
< noverlays
; ++i
)
3362 oend
= OVERLAY_END (overlays
[i
]);
3363 oendpos
= OVERLAY_POSITION (oend
);
3364 endpos
= min (endpos
, oendpos
);
3372 /***********************************************************************
3374 ***********************************************************************/
3376 /* Handle changes in the `fontified' property of the current buffer by
3377 calling hook functions from Qfontification_functions to fontify
3380 static enum prop_handled
3381 handle_fontified_prop (struct it
*it
)
3383 Lisp_Object prop
, pos
;
3384 enum prop_handled handled
= HANDLED_NORMALLY
;
3386 if (!NILP (Vmemory_full
))
3389 /* Get the value of the `fontified' property at IT's current buffer
3390 position. (The `fontified' property doesn't have a special
3391 meaning in strings.) If the value is nil, call functions from
3392 Qfontification_functions. */
3393 if (!STRINGP (it
->string
)
3395 && !NILP (Vfontification_functions
)
3396 && !NILP (Vrun_hooks
)
3397 && (pos
= make_number (IT_CHARPOS (*it
)),
3398 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3399 /* Ignore the special cased nil value always present at EOB since
3400 no amount of fontifying will be able to change it. */
3401 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3403 int count
= SPECPDL_INDEX ();
3406 val
= Vfontification_functions
;
3407 specbind (Qfontification_functions
, Qnil
);
3409 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3410 safe_call1 (val
, pos
);
3413 Lisp_Object globals
, fn
;
3414 struct gcpro gcpro1
, gcpro2
;
3417 GCPRO2 (val
, globals
);
3419 for (; CONSP (val
); val
= XCDR (val
))
3425 /* A value of t indicates this hook has a local
3426 binding; it means to run the global binding too.
3427 In a global value, t should not occur. If it
3428 does, we must ignore it to avoid an endless
3430 for (globals
= Fdefault_value (Qfontification_functions
);
3432 globals
= XCDR (globals
))
3434 fn
= XCAR (globals
);
3436 safe_call1 (fn
, pos
);
3440 safe_call1 (fn
, pos
);
3446 unbind_to (count
, Qnil
);
3448 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3449 something. This avoids an endless loop if they failed to
3450 fontify the text for which reason ever. */
3451 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3452 handled
= HANDLED_RECOMPUTE_PROPS
;
3460 /***********************************************************************
3462 ***********************************************************************/
3464 /* Set up iterator IT from face properties at its current position.
3465 Called from handle_stop. */
3467 static enum prop_handled
3468 handle_face_prop (struct it
*it
)
3471 EMACS_INT next_stop
;
3473 if (!STRINGP (it
->string
))
3476 = face_at_buffer_position (it
->w
,
3478 it
->region_beg_charpos
,
3479 it
->region_end_charpos
,
3482 + TEXT_PROP_DISTANCE_LIMIT
),
3483 0, it
->base_face_id
);
3485 /* Is this a start of a run of characters with box face?
3486 Caveat: this can be called for a freshly initialized
3487 iterator; face_id is -1 in this case. We know that the new
3488 face will not change until limit, i.e. if the new face has a
3489 box, all characters up to limit will have one. But, as
3490 usual, we don't know whether limit is really the end. */
3491 if (new_face_id
!= it
->face_id
)
3493 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3495 /* If new face has a box but old face has not, this is
3496 the start of a run of characters with box, i.e. it has
3497 a shadow on the left side. The value of face_id of the
3498 iterator will be -1 if this is the initial call that gets
3499 the face. In this case, we have to look in front of IT's
3500 position and see whether there is a face != new_face_id. */
3501 it
->start_of_box_run_p
3502 = (new_face
->box
!= FACE_NO_BOX
3503 && (it
->face_id
>= 0
3504 || IT_CHARPOS (*it
) == BEG
3505 || new_face_id
!= face_before_it_pos (it
)));
3506 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3514 Lisp_Object from_overlay
3515 = (it
->current
.overlay_string_index
>= 0
3516 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3519 /* See if we got to this string directly or indirectly from
3520 an overlay property. That includes the before-string or
3521 after-string of an overlay, strings in display properties
3522 provided by an overlay, their text properties, etc.
3524 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3525 if (! NILP (from_overlay
))
3526 for (i
= it
->sp
- 1; i
>= 0; i
--)
3528 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3530 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3531 else if (! NILP (it
->stack
[i
].from_overlay
))
3532 from_overlay
= it
->stack
[i
].from_overlay
;
3534 if (!NILP (from_overlay
))
3538 if (! NILP (from_overlay
))
3540 bufpos
= IT_CHARPOS (*it
);
3541 /* For a string from an overlay, the base face depends
3542 only on text properties and ignores overlays. */
3544 = face_for_overlay_string (it
->w
,
3546 it
->region_beg_charpos
,
3547 it
->region_end_charpos
,
3550 + TEXT_PROP_DISTANCE_LIMIT
),
3558 /* For strings from a `display' property, use the face at
3559 IT's current buffer position as the base face to merge
3560 with, so that overlay strings appear in the same face as
3561 surrounding text, unless they specify their own
3563 base_face_id
= underlying_face_id (it
);
3566 new_face_id
= face_at_string_position (it
->w
,
3568 IT_STRING_CHARPOS (*it
),
3570 it
->region_beg_charpos
,
3571 it
->region_end_charpos
,
3575 /* Is this a start of a run of characters with box? Caveat:
3576 this can be called for a freshly allocated iterator; face_id
3577 is -1 is this case. We know that the new face will not
3578 change until the next check pos, i.e. if the new face has a
3579 box, all characters up to that position will have a
3580 box. But, as usual, we don't know whether that position
3581 is really the end. */
3582 if (new_face_id
!= it
->face_id
)
3584 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3585 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3587 /* If new face has a box but old face hasn't, this is the
3588 start of a run of characters with box, i.e. it has a
3589 shadow on the left side. */
3590 it
->start_of_box_run_p
3591 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3592 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3596 it
->face_id
= new_face_id
;
3597 return HANDLED_NORMALLY
;
3601 /* Return the ID of the face ``underlying'' IT's current position,
3602 which is in a string. If the iterator is associated with a
3603 buffer, return the face at IT's current buffer position.
3604 Otherwise, use the iterator's base_face_id. */
3607 underlying_face_id (struct it
*it
)
3609 int face_id
= it
->base_face_id
, i
;
3611 xassert (STRINGP (it
->string
));
3613 for (i
= it
->sp
- 1; i
>= 0; --i
)
3614 if (NILP (it
->stack
[i
].string
))
3615 face_id
= it
->stack
[i
].face_id
;
3621 /* Compute the face one character before or after the current position
3622 of IT. BEFORE_P non-zero means get the face in front of IT's
3623 position. Value is the id of the face. */
3626 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3629 EMACS_INT next_check_charpos
;
3630 struct text_pos pos
;
3632 xassert (it
->s
== NULL
);
3634 if (STRINGP (it
->string
))
3639 /* No face change past the end of the string (for the case
3640 we are padding with spaces). No face change before the
3642 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3643 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3646 /* Set pos to the position before or after IT's current position. */
3648 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3650 /* For composition, we must check the character after the
3652 pos
= (it
->what
== IT_COMPOSITION
3653 ? string_pos (IT_STRING_CHARPOS (*it
)
3654 + it
->cmp_it
.nchars
, it
->string
)
3655 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3657 if (it
->current
.overlay_string_index
>= 0)
3658 bufpos
= IT_CHARPOS (*it
);
3662 base_face_id
= underlying_face_id (it
);
3664 /* Get the face for ASCII, or unibyte. */
3665 face_id
= face_at_string_position (it
->w
,
3669 it
->region_beg_charpos
,
3670 it
->region_end_charpos
,
3671 &next_check_charpos
,
3674 /* Correct the face for charsets different from ASCII. Do it
3675 for the multibyte case only. The face returned above is
3676 suitable for unibyte text if IT->string is unibyte. */
3677 if (STRING_MULTIBYTE (it
->string
))
3679 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3681 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3683 c
= string_char_and_length (p
, &len
);
3684 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3689 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3690 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3693 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3694 pos
= it
->current
.pos
;
3697 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3700 if (it
->what
== IT_COMPOSITION
)
3701 /* For composition, we must check the position after the
3703 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3705 INC_TEXT_POS (pos
, it
->multibyte_p
);
3708 /* Determine face for CHARSET_ASCII, or unibyte. */
3709 face_id
= face_at_buffer_position (it
->w
,
3711 it
->region_beg_charpos
,
3712 it
->region_end_charpos
,
3713 &next_check_charpos
,
3716 /* Correct the face for charsets different from ASCII. Do it
3717 for the multibyte case only. The face returned above is
3718 suitable for unibyte text if current_buffer is unibyte. */
3719 if (it
->multibyte_p
)
3721 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3722 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3723 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3732 /***********************************************************************
3734 ***********************************************************************/
3736 /* Set up iterator IT from invisible properties at its current
3737 position. Called from handle_stop. */
3739 static enum prop_handled
3740 handle_invisible_prop (struct it
*it
)
3742 enum prop_handled handled
= HANDLED_NORMALLY
;
3744 if (STRINGP (it
->string
))
3746 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3748 /* Get the value of the invisible text property at the
3749 current position. Value will be nil if there is no such
3751 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3752 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3755 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3757 handled
= HANDLED_RECOMPUTE_PROPS
;
3759 /* Get the position at which the next change of the
3760 invisible text property can be found in IT->string.
3761 Value will be nil if the property value is the same for
3762 all the rest of IT->string. */
3763 XSETINT (limit
, SCHARS (it
->string
));
3764 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3767 /* Text at current position is invisible. The next
3768 change in the property is at position end_charpos.
3769 Move IT's current position to that position. */
3770 if (INTEGERP (end_charpos
)
3771 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3773 struct text_pos old
;
3774 old
= it
->current
.string_pos
;
3775 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3776 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3780 /* The rest of the string is invisible. If this is an
3781 overlay string, proceed with the next overlay string
3782 or whatever comes and return a character from there. */
3783 if (it
->current
.overlay_string_index
>= 0)
3785 next_overlay_string (it
);
3786 /* Don't check for overlay strings when we just
3787 finished processing them. */
3788 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3792 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3793 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3801 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3802 Lisp_Object pos
, prop
, overlay
;
3804 /* First of all, is there invisible text at this position? */
3805 tem
= start_charpos
= IT_CHARPOS (*it
);
3806 pos
= make_number (tem
);
3807 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3809 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3811 /* If we are on invisible text, skip over it. */
3812 if (invis_p
&& start_charpos
< it
->end_charpos
)
3814 /* Record whether we have to display an ellipsis for the
3816 int display_ellipsis_p
= invis_p
== 2;
3818 handled
= HANDLED_RECOMPUTE_PROPS
;
3820 /* Loop skipping over invisible text. The loop is left at
3821 ZV or with IT on the first char being visible again. */
3824 /* Try to skip some invisible text. Return value is the
3825 position reached which can be equal to where we start
3826 if there is nothing invisible there. This skips both
3827 over invisible text properties and overlays with
3828 invisible property. */
3829 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3831 /* If we skipped nothing at all we weren't at invisible
3832 text in the first place. If everything to the end of
3833 the buffer was skipped, end the loop. */
3834 if (newpos
== tem
|| newpos
>= ZV
)
3838 /* We skipped some characters but not necessarily
3839 all there are. Check if we ended up on visible
3840 text. Fget_char_property returns the property of
3841 the char before the given position, i.e. if we
3842 get invis_p = 0, this means that the char at
3843 newpos is visible. */
3844 pos
= make_number (newpos
);
3845 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3846 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3849 /* If we ended up on invisible text, proceed to
3850 skip starting with next_stop. */
3854 /* If there are adjacent invisible texts, don't lose the
3855 second one's ellipsis. */
3857 display_ellipsis_p
= 1;
3861 /* The position newpos is now either ZV or on visible text. */
3862 if (it
->bidi_p
&& newpos
< ZV
)
3864 /* With bidi iteration, the region of invisible text
3865 could start and/or end in the middle of a non-base
3866 embedding level. Therefore, we need to skip
3867 invisible text using the bidi iterator, starting at
3868 IT's current position, until we find ourselves
3869 outside the invisible text. Skipping invisible text
3870 _after_ bidi iteration avoids affecting the visual
3871 order of the displayed text when invisible properties
3872 are added or removed. */
3873 if (it
->bidi_it
.first_elt
)
3875 /* If we were `reseat'ed to a new paragraph,
3876 determine the paragraph base direction. We need
3877 to do it now because next_element_from_buffer may
3878 not have a chance to do it, if we are going to
3879 skip any text at the beginning, which resets the
3881 bidi_paragraph_init (it
->paragraph_embedding
,
3886 bidi_move_to_visually_next (&it
->bidi_it
);
3888 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3889 && it
->bidi_it
.charpos
< newpos
);
3890 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3891 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3892 /* If we overstepped NEWPOS, record its position in the
3893 iterator, so that we skip invisible text if later the
3894 bidi iteration lands us in the invisible region
3896 if (IT_CHARPOS (*it
) >= newpos
)
3897 it
->prev_stop
= newpos
;
3901 IT_CHARPOS (*it
) = newpos
;
3902 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3905 /* If there are before-strings at the start of invisible
3906 text, and the text is invisible because of a text
3907 property, arrange to show before-strings because 20.x did
3908 it that way. (If the text is invisible because of an
3909 overlay property instead of a text property, this is
3910 already handled in the overlay code.) */
3912 && get_overlay_strings (it
, it
->stop_charpos
))
3914 handled
= HANDLED_RECOMPUTE_PROPS
;
3915 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3917 else if (display_ellipsis_p
)
3919 /* Make sure that the glyphs of the ellipsis will get
3920 correct `charpos' values. If we would not update
3921 it->position here, the glyphs would belong to the
3922 last visible character _before_ the invisible
3923 text, which confuses `set_cursor_from_row'.
3925 We use the last invisible position instead of the
3926 first because this way the cursor is always drawn on
3927 the first "." of the ellipsis, whenever PT is inside
3928 the invisible text. Otherwise the cursor would be
3929 placed _after_ the ellipsis when the point is after the
3930 first invisible character. */
3931 if (!STRINGP (it
->object
))
3933 it
->position
.charpos
= newpos
- 1;
3934 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3937 /* Let the ellipsis display before
3938 considering any properties of the following char.
3939 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3940 handled
= HANDLED_RETURN
;
3949 /* Make iterator IT return `...' next.
3950 Replaces LEN characters from buffer. */
3953 setup_for_ellipsis (struct it
*it
, int len
)
3955 /* Use the display table definition for `...'. Invalid glyphs
3956 will be handled by the method returning elements from dpvec. */
3957 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3959 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3960 it
->dpvec
= v
->contents
;
3961 it
->dpend
= v
->contents
+ v
->size
;
3965 /* Default `...'. */
3966 it
->dpvec
= default_invis_vector
;
3967 it
->dpend
= default_invis_vector
+ 3;
3970 it
->dpvec_char_len
= len
;
3971 it
->current
.dpvec_index
= 0;
3972 it
->dpvec_face_id
= -1;
3974 /* Remember the current face id in case glyphs specify faces.
3975 IT's face is restored in set_iterator_to_next.
3976 saved_face_id was set to preceding char's face in handle_stop. */
3977 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3978 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3980 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3986 /***********************************************************************
3988 ***********************************************************************/
3990 /* Set up iterator IT from `display' property at its current position.
3991 Called from handle_stop.
3992 We return HANDLED_RETURN if some part of the display property
3993 overrides the display of the buffer text itself.
3994 Otherwise we return HANDLED_NORMALLY. */
3996 static enum prop_handled
3997 handle_display_prop (struct it
*it
)
3999 Lisp_Object prop
, object
, overlay
;
4000 struct text_pos
*position
;
4001 /* Nonzero if some property replaces the display of the text itself. */
4002 int display_replaced_p
= 0;
4004 if (STRINGP (it
->string
))
4006 object
= it
->string
;
4007 position
= &it
->current
.string_pos
;
4011 XSETWINDOW (object
, it
->w
);
4012 position
= &it
->current
.pos
;
4015 /* Reset those iterator values set from display property values. */
4016 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4017 it
->space_width
= Qnil
;
4018 it
->font_height
= Qnil
;
4021 /* We don't support recursive `display' properties, i.e. string
4022 values that have a string `display' property, that have a string
4023 `display' property etc. */
4024 if (!it
->string_from_display_prop_p
)
4025 it
->area
= TEXT_AREA
;
4027 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
4028 Qdisplay
, object
, &overlay
);
4030 return HANDLED_NORMALLY
;
4031 /* Now OVERLAY is the overlay that gave us this property, or nil
4032 if it was a text property. */
4034 if (!STRINGP (it
->string
))
4035 object
= it
->w
->buffer
;
4038 /* Simple properties. */
4039 && !EQ (XCAR (prop
), Qimage
)
4040 && !EQ (XCAR (prop
), Qspace
)
4041 && !EQ (XCAR (prop
), Qwhen
)
4042 && !EQ (XCAR (prop
), Qslice
)
4043 && !EQ (XCAR (prop
), Qspace_width
)
4044 && !EQ (XCAR (prop
), Qheight
)
4045 && !EQ (XCAR (prop
), Qraise
)
4046 /* Marginal area specifications. */
4047 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
4048 && !EQ (XCAR (prop
), Qleft_fringe
)
4049 && !EQ (XCAR (prop
), Qright_fringe
)
4050 && !NILP (XCAR (prop
)))
4052 for (; CONSP (prop
); prop
= XCDR (prop
))
4054 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
4055 position
, display_replaced_p
))
4057 display_replaced_p
= 1;
4058 /* If some text in a string is replaced, `position' no
4059 longer points to the position of `object'. */
4060 if (STRINGP (object
))
4065 else if (VECTORP (prop
))
4068 for (i
= 0; i
< ASIZE (prop
); ++i
)
4069 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4070 position
, display_replaced_p
))
4072 display_replaced_p
= 1;
4073 /* If some text in a string is replaced, `position' no
4074 longer points to the position of `object'. */
4075 if (STRINGP (object
))
4081 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4083 display_replaced_p
= 1;
4086 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4090 /* Value is the position of the end of the `display' property starting
4091 at START_POS in OBJECT. */
4093 static struct text_pos
4094 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4097 struct text_pos end_pos
;
4099 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4100 Qdisplay
, object
, Qnil
);
4101 CHARPOS (end_pos
) = XFASTINT (end
);
4102 if (STRINGP (object
))
4103 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4105 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4111 /* Set up IT from a single `display' specification PROP. OBJECT
4112 is the object in which the `display' property was found. *POSITION
4113 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4114 means that we previously saw a display specification which already
4115 replaced text display with something else, for example an image;
4116 we ignore such properties after the first one has been processed.
4118 OVERLAY is the overlay this `display' property came from,
4119 or nil if it was a text property.
4121 If PROP is a `space' or `image' specification, and in some other
4122 cases too, set *POSITION to the position where the `display'
4125 Value is non-zero if something was found which replaces the display
4126 of buffer or string text. */
4129 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4130 Lisp_Object overlay
, struct text_pos
*position
,
4131 int display_replaced_before_p
)
4134 Lisp_Object location
, value
;
4135 struct text_pos start_pos
, save_pos
;
4138 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4139 If the result is non-nil, use VALUE instead of SPEC. */
4141 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4150 if (!NILP (form
) && !EQ (form
, Qt
))
4152 int count
= SPECPDL_INDEX ();
4153 struct gcpro gcpro1
;
4155 /* Bind `object' to the object having the `display' property, a
4156 buffer or string. Bind `position' to the position in the
4157 object where the property was found, and `buffer-position'
4158 to the current position in the buffer. */
4159 specbind (Qobject
, object
);
4160 specbind (Qposition
, make_number (CHARPOS (*position
)));
4161 specbind (Qbuffer_position
,
4162 make_number (STRINGP (object
)
4163 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4165 form
= safe_eval (form
);
4167 unbind_to (count
, Qnil
);
4173 /* Handle `(height HEIGHT)' specifications. */
4175 && EQ (XCAR (spec
), Qheight
)
4176 && CONSP (XCDR (spec
)))
4178 if (!FRAME_WINDOW_P (it
->f
))
4181 it
->font_height
= XCAR (XCDR (spec
));
4182 if (!NILP (it
->font_height
))
4184 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4185 int new_height
= -1;
4187 if (CONSP (it
->font_height
)
4188 && (EQ (XCAR (it
->font_height
), Qplus
)
4189 || EQ (XCAR (it
->font_height
), Qminus
))
4190 && CONSP (XCDR (it
->font_height
))
4191 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4193 /* `(+ N)' or `(- N)' where N is an integer. */
4194 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4195 if (EQ (XCAR (it
->font_height
), Qplus
))
4197 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4199 else if (FUNCTIONP (it
->font_height
))
4201 /* Call function with current height as argument.
4202 Value is the new height. */
4204 height
= safe_call1 (it
->font_height
,
4205 face
->lface
[LFACE_HEIGHT_INDEX
]);
4206 if (NUMBERP (height
))
4207 new_height
= XFLOATINT (height
);
4209 else if (NUMBERP (it
->font_height
))
4211 /* Value is a multiple of the canonical char height. */
4214 face
= FACE_FROM_ID (it
->f
,
4215 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4216 new_height
= (XFLOATINT (it
->font_height
)
4217 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4221 /* Evaluate IT->font_height with `height' bound to the
4222 current specified height to get the new height. */
4223 int count
= SPECPDL_INDEX ();
4225 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4226 value
= safe_eval (it
->font_height
);
4227 unbind_to (count
, Qnil
);
4229 if (NUMBERP (value
))
4230 new_height
= XFLOATINT (value
);
4234 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4240 /* Handle `(space-width WIDTH)'. */
4242 && EQ (XCAR (spec
), Qspace_width
)
4243 && CONSP (XCDR (spec
)))
4245 if (!FRAME_WINDOW_P (it
->f
))
4248 value
= XCAR (XCDR (spec
));
4249 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4250 it
->space_width
= value
;
4255 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4257 && EQ (XCAR (spec
), Qslice
))
4261 if (!FRAME_WINDOW_P (it
->f
))
4264 if (tem
= XCDR (spec
), CONSP (tem
))
4266 it
->slice
.x
= XCAR (tem
);
4267 if (tem
= XCDR (tem
), CONSP (tem
))
4269 it
->slice
.y
= XCAR (tem
);
4270 if (tem
= XCDR (tem
), CONSP (tem
))
4272 it
->slice
.width
= XCAR (tem
);
4273 if (tem
= XCDR (tem
), CONSP (tem
))
4274 it
->slice
.height
= XCAR (tem
);
4282 /* Handle `(raise FACTOR)'. */
4284 && EQ (XCAR (spec
), Qraise
)
4285 && CONSP (XCDR (spec
)))
4287 if (!FRAME_WINDOW_P (it
->f
))
4290 #ifdef HAVE_WINDOW_SYSTEM
4291 value
= XCAR (XCDR (spec
));
4292 if (NUMBERP (value
))
4294 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4295 it
->voffset
= - (XFLOATINT (value
)
4296 * (FONT_HEIGHT (face
->font
)));
4298 #endif /* HAVE_WINDOW_SYSTEM */
4303 /* Don't handle the other kinds of display specifications
4304 inside a string that we got from a `display' property. */
4305 if (it
->string_from_display_prop_p
)
4308 /* Characters having this form of property are not displayed, so
4309 we have to find the end of the property. */
4310 start_pos
= *position
;
4311 *position
= display_prop_end (it
, object
, start_pos
);
4314 /* Stop the scan at that end position--we assume that all
4315 text properties change there. */
4316 it
->stop_charpos
= position
->charpos
;
4318 /* Handle `(left-fringe BITMAP [FACE])'
4319 and `(right-fringe BITMAP [FACE])'. */
4321 && (EQ (XCAR (spec
), Qleft_fringe
)
4322 || EQ (XCAR (spec
), Qright_fringe
))
4323 && CONSP (XCDR (spec
)))
4325 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4328 if (!FRAME_WINDOW_P (it
->f
))
4329 /* If we return here, POSITION has been advanced
4330 across the text with this property. */
4333 #ifdef HAVE_WINDOW_SYSTEM
4334 value
= XCAR (XCDR (spec
));
4335 if (!SYMBOLP (value
)
4336 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4337 /* If we return here, POSITION has been advanced
4338 across the text with this property. */
4341 if (CONSP (XCDR (XCDR (spec
))))
4343 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4344 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4350 /* Save current settings of IT so that we can restore them
4351 when we are finished with the glyph property value. */
4353 save_pos
= it
->position
;
4354 it
->position
= *position
;
4356 it
->position
= save_pos
;
4358 it
->area
= TEXT_AREA
;
4359 it
->what
= IT_IMAGE
;
4360 it
->image_id
= -1; /* no image */
4361 it
->position
= start_pos
;
4362 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4363 it
->method
= GET_FROM_IMAGE
;
4364 it
->from_overlay
= Qnil
;
4365 it
->face_id
= face_id
;
4367 /* Say that we haven't consumed the characters with
4368 `display' property yet. The call to pop_it in
4369 set_iterator_to_next will clean this up. */
4370 *position
= start_pos
;
4372 if (EQ (XCAR (spec
), Qleft_fringe
))
4374 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4375 it
->left_user_fringe_face_id
= face_id
;
4379 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4380 it
->right_user_fringe_face_id
= face_id
;
4382 #endif /* HAVE_WINDOW_SYSTEM */
4386 /* Prepare to handle `((margin left-margin) ...)',
4387 `((margin right-margin) ...)' and `((margin nil) ...)'
4388 prefixes for display specifications. */
4389 location
= Qunbound
;
4390 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4394 value
= XCDR (spec
);
4396 value
= XCAR (value
);
4399 if (EQ (XCAR (tem
), Qmargin
)
4400 && (tem
= XCDR (tem
),
4401 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4403 || EQ (tem
, Qleft_margin
)
4404 || EQ (tem
, Qright_margin
))))
4408 if (EQ (location
, Qunbound
))
4414 /* After this point, VALUE is the property after any
4415 margin prefix has been stripped. It must be a string,
4416 an image specification, or `(space ...)'.
4418 LOCATION specifies where to display: `left-margin',
4419 `right-margin' or nil. */
4421 valid_p
= (STRINGP (value
)
4422 #ifdef HAVE_WINDOW_SYSTEM
4423 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4424 #endif /* not HAVE_WINDOW_SYSTEM */
4425 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4427 if (valid_p
&& !display_replaced_before_p
)
4429 /* Save current settings of IT so that we can restore them
4430 when we are finished with the glyph property value. */
4431 save_pos
= it
->position
;
4432 it
->position
= *position
;
4434 it
->position
= save_pos
;
4435 it
->from_overlay
= overlay
;
4437 if (NILP (location
))
4438 it
->area
= TEXT_AREA
;
4439 else if (EQ (location
, Qleft_margin
))
4440 it
->area
= LEFT_MARGIN_AREA
;
4442 it
->area
= RIGHT_MARGIN_AREA
;
4444 if (STRINGP (value
))
4447 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4448 it
->current
.overlay_string_index
= -1;
4449 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4450 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4451 it
->method
= GET_FROM_STRING
;
4452 it
->stop_charpos
= 0;
4453 it
->string_from_display_prop_p
= 1;
4454 /* Say that we haven't consumed the characters with
4455 `display' property yet. The call to pop_it in
4456 set_iterator_to_next will clean this up. */
4457 if (BUFFERP (object
))
4458 *position
= start_pos
;
4460 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4462 it
->method
= GET_FROM_STRETCH
;
4464 *position
= it
->position
= start_pos
;
4466 #ifdef HAVE_WINDOW_SYSTEM
4469 it
->what
= IT_IMAGE
;
4470 it
->image_id
= lookup_image (it
->f
, value
);
4471 it
->position
= start_pos
;
4472 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4473 it
->method
= GET_FROM_IMAGE
;
4475 /* Say that we haven't consumed the characters with
4476 `display' property yet. The call to pop_it in
4477 set_iterator_to_next will clean this up. */
4478 *position
= start_pos
;
4480 #endif /* HAVE_WINDOW_SYSTEM */
4485 /* Invalid property or property not supported. Restore
4486 POSITION to what it was before. */
4487 *position
= start_pos
;
4492 /* Check if SPEC is a display sub-property value whose text should be
4493 treated as intangible. */
4496 single_display_spec_intangible_p (Lisp_Object prop
)
4498 /* Skip over `when FORM'. */
4499 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4513 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4514 we don't need to treat text as intangible. */
4515 if (EQ (XCAR (prop
), Qmargin
))
4523 || EQ (XCAR (prop
), Qleft_margin
)
4524 || EQ (XCAR (prop
), Qright_margin
))
4528 return (CONSP (prop
)
4529 && (EQ (XCAR (prop
), Qimage
)
4530 || EQ (XCAR (prop
), Qspace
)));
4534 /* Check if PROP is a display property value whose text should be
4535 treated as intangible. */
4538 display_prop_intangible_p (Lisp_Object prop
)
4541 && CONSP (XCAR (prop
))
4542 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4544 /* A list of sub-properties. */
4545 while (CONSP (prop
))
4547 if (single_display_spec_intangible_p (XCAR (prop
)))
4552 else if (VECTORP (prop
))
4554 /* A vector of sub-properties. */
4556 for (i
= 0; i
< ASIZE (prop
); ++i
)
4557 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4561 return single_display_spec_intangible_p (prop
);
4567 /* Return 1 if PROP is a display sub-property value containing STRING. */
4570 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4572 if (EQ (string
, prop
))
4575 /* Skip over `when FORM'. */
4576 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4585 /* Skip over `margin LOCATION'. */
4586 if (EQ (XCAR (prop
), Qmargin
))
4597 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4601 /* Return 1 if STRING appears in the `display' property PROP. */
4604 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4607 && CONSP (XCAR (prop
))
4608 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4610 /* A list of sub-properties. */
4611 while (CONSP (prop
))
4613 if (single_display_spec_string_p (XCAR (prop
), string
))
4618 else if (VECTORP (prop
))
4620 /* A vector of sub-properties. */
4622 for (i
= 0; i
< ASIZE (prop
); ++i
)
4623 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4627 return single_display_spec_string_p (prop
, string
);
4632 /* Look for STRING in overlays and text properties in W's buffer,
4633 between character positions FROM and TO (excluding TO).
4634 BACK_P non-zero means look back (in this case, TO is supposed to be
4636 Value is the first character position where STRING was found, or
4637 zero if it wasn't found before hitting TO.
4639 W's buffer must be current.
4641 This function may only use code that doesn't eval because it is
4642 called asynchronously from note_mouse_highlight. */
4645 string_buffer_position_lim (struct window
*w
, Lisp_Object string
,
4646 EMACS_INT from
, EMACS_INT to
, int back_p
)
4648 Lisp_Object limit
, prop
, pos
;
4651 pos
= make_number (from
);
4653 if (!back_p
) /* looking forward */
4655 limit
= make_number (min (to
, ZV
));
4656 while (!found
&& !EQ (pos
, limit
))
4658 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4659 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4662 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4666 else /* looking back */
4668 limit
= make_number (max (to
, BEGV
));
4669 while (!found
&& !EQ (pos
, limit
))
4671 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4672 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4675 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4680 return found
? XINT (pos
) : 0;
4683 /* Determine which buffer position in W's buffer STRING comes from.
4684 AROUND_CHARPOS is an approximate position where it could come from.
4685 Value is the buffer position or 0 if it couldn't be determined.
4687 W's buffer must be current.
4689 This function is necessary because we don't record buffer positions
4690 in glyphs generated from strings (to keep struct glyph small).
4691 This function may only use code that doesn't eval because it is
4692 called asynchronously from note_mouse_highlight. */
4695 string_buffer_position (struct window
*w
, Lisp_Object string
, EMACS_INT around_charpos
)
4697 const int MAX_DISTANCE
= 1000;
4698 EMACS_INT found
= string_buffer_position_lim (w
, string
, around_charpos
,
4699 around_charpos
+ MAX_DISTANCE
,
4703 found
= string_buffer_position_lim (w
, string
, around_charpos
,
4704 around_charpos
- MAX_DISTANCE
, 1);
4710 /***********************************************************************
4711 `composition' property
4712 ***********************************************************************/
4714 /* Set up iterator IT from `composition' property at its current
4715 position. Called from handle_stop. */
4717 static enum prop_handled
4718 handle_composition_prop (struct it
*it
)
4720 Lisp_Object prop
, string
;
4721 EMACS_INT pos
, pos_byte
, start
, end
;
4723 if (STRINGP (it
->string
))
4727 pos
= IT_STRING_CHARPOS (*it
);
4728 pos_byte
= IT_STRING_BYTEPOS (*it
);
4729 string
= it
->string
;
4730 s
= SDATA (string
) + pos_byte
;
4731 it
->c
= STRING_CHAR (s
);
4735 pos
= IT_CHARPOS (*it
);
4736 pos_byte
= IT_BYTEPOS (*it
);
4738 it
->c
= FETCH_CHAR (pos_byte
);
4741 /* If there's a valid composition and point is not inside of the
4742 composition (in the case that the composition is from the current
4743 buffer), draw a glyph composed from the composition components. */
4744 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4745 && COMPOSITION_VALID_P (start
, end
, prop
)
4746 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4750 if (STRINGP (it
->string
))
4751 pos_byte
= string_char_to_byte (it
->string
, start
);
4753 pos_byte
= CHAR_TO_BYTE (start
);
4755 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4758 if (it
->cmp_it
.id
>= 0)
4761 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4762 it
->cmp_it
.nglyphs
= -1;
4766 return HANDLED_NORMALLY
;
4771 /***********************************************************************
4773 ***********************************************************************/
4775 /* The following structure is used to record overlay strings for
4776 later sorting in load_overlay_strings. */
4778 struct overlay_entry
4780 Lisp_Object overlay
;
4787 /* Set up iterator IT from overlay strings at its current position.
4788 Called from handle_stop. */
4790 static enum prop_handled
4791 handle_overlay_change (struct it
*it
)
4793 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4794 return HANDLED_RECOMPUTE_PROPS
;
4796 return HANDLED_NORMALLY
;
4800 /* Set up the next overlay string for delivery by IT, if there is an
4801 overlay string to deliver. Called by set_iterator_to_next when the
4802 end of the current overlay string is reached. If there are more
4803 overlay strings to display, IT->string and
4804 IT->current.overlay_string_index are set appropriately here.
4805 Otherwise IT->string is set to nil. */
4808 next_overlay_string (struct it
*it
)
4810 ++it
->current
.overlay_string_index
;
4811 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4813 /* No more overlay strings. Restore IT's settings to what
4814 they were before overlay strings were processed, and
4815 continue to deliver from current_buffer. */
4817 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4820 || (NILP (it
->string
)
4821 && it
->method
== GET_FROM_BUFFER
4822 && it
->stop_charpos
>= BEGV
4823 && it
->stop_charpos
<= it
->end_charpos
));
4824 it
->current
.overlay_string_index
= -1;
4825 it
->n_overlay_strings
= 0;
4827 /* If we're at the end of the buffer, record that we have
4828 processed the overlay strings there already, so that
4829 next_element_from_buffer doesn't try it again. */
4830 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4831 it
->overlay_strings_at_end_processed_p
= 1;
4835 /* There are more overlay strings to process. If
4836 IT->current.overlay_string_index has advanced to a position
4837 where we must load IT->overlay_strings with more strings, do
4839 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4841 if (it
->current
.overlay_string_index
&& i
== 0)
4842 load_overlay_strings (it
, 0);
4844 /* Initialize IT to deliver display elements from the overlay
4846 it
->string
= it
->overlay_strings
[i
];
4847 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4848 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4849 it
->method
= GET_FROM_STRING
;
4850 it
->stop_charpos
= 0;
4851 if (it
->cmp_it
.stop_pos
>= 0)
4852 it
->cmp_it
.stop_pos
= 0;
4859 /* Compare two overlay_entry structures E1 and E2. Used as a
4860 comparison function for qsort in load_overlay_strings. Overlay
4861 strings for the same position are sorted so that
4863 1. All after-strings come in front of before-strings, except
4864 when they come from the same overlay.
4866 2. Within after-strings, strings are sorted so that overlay strings
4867 from overlays with higher priorities come first.
4869 2. Within before-strings, strings are sorted so that overlay
4870 strings from overlays with higher priorities come last.
4872 Value is analogous to strcmp. */
4876 compare_overlay_entries (const void *e1
, const void *e2
)
4878 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4879 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4882 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4884 /* Let after-strings appear in front of before-strings if
4885 they come from different overlays. */
4886 if (EQ (entry1
->overlay
, entry2
->overlay
))
4887 result
= entry1
->after_string_p
? 1 : -1;
4889 result
= entry1
->after_string_p
? -1 : 1;
4891 else if (entry1
->after_string_p
)
4892 /* After-strings sorted in order of decreasing priority. */
4893 result
= entry2
->priority
- entry1
->priority
;
4895 /* Before-strings sorted in order of increasing priority. */
4896 result
= entry1
->priority
- entry2
->priority
;
4902 /* Load the vector IT->overlay_strings with overlay strings from IT's
4903 current buffer position, or from CHARPOS if that is > 0. Set
4904 IT->n_overlays to the total number of overlay strings found.
4906 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4907 a time. On entry into load_overlay_strings,
4908 IT->current.overlay_string_index gives the number of overlay
4909 strings that have already been loaded by previous calls to this
4912 IT->add_overlay_start contains an additional overlay start
4913 position to consider for taking overlay strings from, if non-zero.
4914 This position comes into play when the overlay has an `invisible'
4915 property, and both before and after-strings. When we've skipped to
4916 the end of the overlay, because of its `invisible' property, we
4917 nevertheless want its before-string to appear.
4918 IT->add_overlay_start will contain the overlay start position
4921 Overlay strings are sorted so that after-string strings come in
4922 front of before-string strings. Within before and after-strings,
4923 strings are sorted by overlay priority. See also function
4924 compare_overlay_entries. */
4927 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4929 Lisp_Object overlay
, window
, str
, invisible
;
4930 struct Lisp_Overlay
*ov
;
4931 EMACS_INT start
, end
;
4933 int n
= 0, i
, j
, invis_p
;
4934 struct overlay_entry
*entries
4935 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4938 charpos
= IT_CHARPOS (*it
);
4940 /* Append the overlay string STRING of overlay OVERLAY to vector
4941 `entries' which has size `size' and currently contains `n'
4942 elements. AFTER_P non-zero means STRING is an after-string of
4944 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4947 Lisp_Object priority; \
4951 int new_size = 2 * size; \
4952 struct overlay_entry *old = entries; \
4954 (struct overlay_entry *) alloca (new_size \
4955 * sizeof *entries); \
4956 memcpy (entries, old, size * sizeof *entries); \
4960 entries[n].string = (STRING); \
4961 entries[n].overlay = (OVERLAY); \
4962 priority = Foverlay_get ((OVERLAY), Qpriority); \
4963 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4964 entries[n].after_string_p = (AFTER_P); \
4969 /* Process overlay before the overlay center. */
4970 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4972 XSETMISC (overlay
, ov
);
4973 xassert (OVERLAYP (overlay
));
4974 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4975 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4980 /* Skip this overlay if it doesn't start or end at IT's current
4982 if (end
!= charpos
&& start
!= charpos
)
4985 /* Skip this overlay if it doesn't apply to IT->w. */
4986 window
= Foverlay_get (overlay
, Qwindow
);
4987 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4990 /* If the text ``under'' the overlay is invisible, both before-
4991 and after-strings from this overlay are visible; start and
4992 end position are indistinguishable. */
4993 invisible
= Foverlay_get (overlay
, Qinvisible
);
4994 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4996 /* If overlay has a non-empty before-string, record it. */
4997 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4998 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5000 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5002 /* If overlay has a non-empty after-string, record it. */
5003 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5004 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5006 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5009 /* Process overlays after the overlay center. */
5010 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5012 XSETMISC (overlay
, ov
);
5013 xassert (OVERLAYP (overlay
));
5014 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5015 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5017 if (start
> charpos
)
5020 /* Skip this overlay if it doesn't start or end at IT's current
5022 if (end
!= charpos
&& start
!= charpos
)
5025 /* Skip this overlay if it doesn't apply to IT->w. */
5026 window
= Foverlay_get (overlay
, Qwindow
);
5027 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5030 /* If the text ``under'' the overlay is invisible, it has a zero
5031 dimension, and both before- and after-strings apply. */
5032 invisible
= Foverlay_get (overlay
, Qinvisible
);
5033 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5035 /* If overlay has a non-empty before-string, record it. */
5036 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5037 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5039 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5041 /* If overlay has a non-empty after-string, record it. */
5042 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5043 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5045 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5048 #undef RECORD_OVERLAY_STRING
5052 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5054 /* Record the total number of strings to process. */
5055 it
->n_overlay_strings
= n
;
5057 /* IT->current.overlay_string_index is the number of overlay strings
5058 that have already been consumed by IT. Copy some of the
5059 remaining overlay strings to IT->overlay_strings. */
5061 j
= it
->current
.overlay_string_index
;
5062 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5064 it
->overlay_strings
[i
] = entries
[j
].string
;
5065 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5072 /* Get the first chunk of overlay strings at IT's current buffer
5073 position, or at CHARPOS if that is > 0. Value is non-zero if at
5074 least one overlay string was found. */
5077 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
5079 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5080 process. This fills IT->overlay_strings with strings, and sets
5081 IT->n_overlay_strings to the total number of strings to process.
5082 IT->pos.overlay_string_index has to be set temporarily to zero
5083 because load_overlay_strings needs this; it must be set to -1
5084 when no overlay strings are found because a zero value would
5085 indicate a position in the first overlay string. */
5086 it
->current
.overlay_string_index
= 0;
5087 load_overlay_strings (it
, charpos
);
5089 /* If we found overlay strings, set up IT to deliver display
5090 elements from the first one. Otherwise set up IT to deliver
5091 from current_buffer. */
5092 if (it
->n_overlay_strings
)
5094 /* Make sure we know settings in current_buffer, so that we can
5095 restore meaningful values when we're done with the overlay
5098 compute_stop_pos (it
);
5099 xassert (it
->face_id
>= 0);
5101 /* Save IT's settings. They are restored after all overlay
5102 strings have been processed. */
5103 xassert (!compute_stop_p
|| it
->sp
== 0);
5105 /* When called from handle_stop, there might be an empty display
5106 string loaded. In that case, don't bother saving it. */
5107 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5110 /* Set up IT to deliver display elements from the first overlay
5112 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5113 it
->string
= it
->overlay_strings
[0];
5114 it
->from_overlay
= Qnil
;
5115 it
->stop_charpos
= 0;
5116 xassert (STRINGP (it
->string
));
5117 it
->end_charpos
= SCHARS (it
->string
);
5118 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5119 it
->method
= GET_FROM_STRING
;
5123 it
->current
.overlay_string_index
= -1;
5128 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5131 it
->method
= GET_FROM_BUFFER
;
5133 (void) get_overlay_strings_1 (it
, charpos
, 1);
5137 /* Value is non-zero if we found at least one overlay string. */
5138 return STRINGP (it
->string
);
5143 /***********************************************************************
5144 Saving and restoring state
5145 ***********************************************************************/
5147 /* Save current settings of IT on IT->stack. Called, for example,
5148 before setting up IT for an overlay string, to be able to restore
5149 IT's settings to what they were after the overlay string has been
5153 push_it (struct it
*it
)
5155 struct iterator_stack_entry
*p
;
5157 xassert (it
->sp
< IT_STACK_SIZE
);
5158 p
= it
->stack
+ it
->sp
;
5160 p
->stop_charpos
= it
->stop_charpos
;
5161 p
->prev_stop
= it
->prev_stop
;
5162 p
->base_level_stop
= it
->base_level_stop
;
5163 p
->cmp_it
= it
->cmp_it
;
5164 xassert (it
->face_id
>= 0);
5165 p
->face_id
= it
->face_id
;
5166 p
->string
= it
->string
;
5167 p
->method
= it
->method
;
5168 p
->from_overlay
= it
->from_overlay
;
5171 case GET_FROM_IMAGE
:
5172 p
->u
.image
.object
= it
->object
;
5173 p
->u
.image
.image_id
= it
->image_id
;
5174 p
->u
.image
.slice
= it
->slice
;
5176 case GET_FROM_STRETCH
:
5177 p
->u
.stretch
.object
= it
->object
;
5180 p
->position
= it
->position
;
5181 p
->current
= it
->current
;
5182 p
->end_charpos
= it
->end_charpos
;
5183 p
->string_nchars
= it
->string_nchars
;
5185 p
->multibyte_p
= it
->multibyte_p
;
5186 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5187 p
->space_width
= it
->space_width
;
5188 p
->font_height
= it
->font_height
;
5189 p
->voffset
= it
->voffset
;
5190 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5191 p
->display_ellipsis_p
= 0;
5192 p
->line_wrap
= it
->line_wrap
;
5197 iterate_out_of_display_property (struct it
*it
)
5199 /* Maybe initialize paragraph direction. If we are at the beginning
5200 of a new paragraph, next_element_from_buffer may not have a
5201 chance to do that. */
5202 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
5203 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5204 /* prev_stop can be zero, so check against BEGV as well. */
5205 while (it
->bidi_it
.charpos
>= BEGV
5206 && it
->prev_stop
<= it
->bidi_it
.charpos
5207 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5208 bidi_move_to_visually_next (&it
->bidi_it
);
5209 /* Record the stop_pos we just crossed, for when we cross it
5211 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5212 it
->prev_stop
= CHARPOS (it
->position
);
5213 /* If we ended up not where pop_it put us, resync IT's
5214 positional members with the bidi iterator. */
5215 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5217 SET_TEXT_POS (it
->position
,
5218 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5219 it
->current
.pos
= it
->position
;
5223 /* Restore IT's settings from IT->stack. Called, for example, when no
5224 more overlay strings must be processed, and we return to delivering
5225 display elements from a buffer, or when the end of a string from a
5226 `display' property is reached and we return to delivering display
5227 elements from an overlay string, or from a buffer. */
5230 pop_it (struct it
*it
)
5232 struct iterator_stack_entry
*p
;
5234 xassert (it
->sp
> 0);
5236 p
= it
->stack
+ it
->sp
;
5237 it
->stop_charpos
= p
->stop_charpos
;
5238 it
->prev_stop
= p
->prev_stop
;
5239 it
->base_level_stop
= p
->base_level_stop
;
5240 it
->cmp_it
= p
->cmp_it
;
5241 it
->face_id
= p
->face_id
;
5242 it
->current
= p
->current
;
5243 it
->position
= p
->position
;
5244 it
->string
= p
->string
;
5245 it
->from_overlay
= p
->from_overlay
;
5246 if (NILP (it
->string
))
5247 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5248 it
->method
= p
->method
;
5251 case GET_FROM_IMAGE
:
5252 it
->image_id
= p
->u
.image
.image_id
;
5253 it
->object
= p
->u
.image
.object
;
5254 it
->slice
= p
->u
.image
.slice
;
5256 case GET_FROM_STRETCH
:
5257 it
->object
= p
->u
.comp
.object
;
5259 case GET_FROM_BUFFER
:
5260 it
->object
= it
->w
->buffer
;
5263 /* Bidi-iterate until we get out of the portion of text, if
5264 any, covered by a `display' text property or an overlay
5265 with `display' property. (We cannot just jump there,
5266 because the internal coherency of the bidi iterator state
5267 can not be preserved across such jumps.) We also must
5268 determine the paragraph base direction if the overlay we
5269 just processed is at the beginning of a new
5271 iterate_out_of_display_property (it
);
5274 case GET_FROM_STRING
:
5275 it
->object
= it
->string
;
5277 case GET_FROM_DISPLAY_VECTOR
:
5279 it
->method
= GET_FROM_C_STRING
;
5280 else if (STRINGP (it
->string
))
5281 it
->method
= GET_FROM_STRING
;
5284 it
->method
= GET_FROM_BUFFER
;
5285 it
->object
= it
->w
->buffer
;
5288 it
->end_charpos
= p
->end_charpos
;
5289 it
->string_nchars
= p
->string_nchars
;
5291 it
->multibyte_p
= p
->multibyte_p
;
5292 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5293 it
->space_width
= p
->space_width
;
5294 it
->font_height
= p
->font_height
;
5295 it
->voffset
= p
->voffset
;
5296 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5297 it
->line_wrap
= p
->line_wrap
;
5302 /***********************************************************************
5304 ***********************************************************************/
5306 /* Set IT's current position to the previous line start. */
5309 back_to_previous_line_start (struct it
*it
)
5311 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5312 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5316 /* Move IT to the next line start.
5318 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5319 we skipped over part of the text (as opposed to moving the iterator
5320 continuously over the text). Otherwise, don't change the value
5323 Newlines may come from buffer text, overlay strings, or strings
5324 displayed via the `display' property. That's the reason we can't
5325 simply use find_next_newline_no_quit.
5327 Note that this function may not skip over invisible text that is so
5328 because of text properties and immediately follows a newline. If
5329 it would, function reseat_at_next_visible_line_start, when called
5330 from set_iterator_to_next, would effectively make invisible
5331 characters following a newline part of the wrong glyph row, which
5332 leads to wrong cursor motion. */
5335 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5337 int old_selective
, newline_found_p
, n
;
5338 const int MAX_NEWLINE_DISTANCE
= 500;
5340 /* If already on a newline, just consume it to avoid unintended
5341 skipping over invisible text below. */
5342 if (it
->what
== IT_CHARACTER
5344 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5346 set_iterator_to_next (it
, 0);
5351 /* Don't handle selective display in the following. It's (a)
5352 unnecessary because it's done by the caller, and (b) leads to an
5353 infinite recursion because next_element_from_ellipsis indirectly
5354 calls this function. */
5355 old_selective
= it
->selective
;
5358 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5359 from buffer text. */
5360 for (n
= newline_found_p
= 0;
5361 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5362 n
+= STRINGP (it
->string
) ? 0 : 1)
5364 if (!get_next_display_element (it
))
5366 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5367 set_iterator_to_next (it
, 0);
5370 /* If we didn't find a newline near enough, see if we can use a
5372 if (!newline_found_p
)
5374 EMACS_INT start
= IT_CHARPOS (*it
);
5375 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5378 xassert (!STRINGP (it
->string
));
5380 /* If there isn't any `display' property in sight, and no
5381 overlays, we can just use the position of the newline in
5383 if (it
->stop_charpos
>= limit
5384 || ((pos
= Fnext_single_property_change (make_number (start
),
5386 Qnil
, make_number (limit
)),
5388 && next_overlay_change (start
) == ZV
))
5390 IT_CHARPOS (*it
) = limit
;
5391 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5392 *skipped_p
= newline_found_p
= 1;
5396 while (get_next_display_element (it
)
5397 && !newline_found_p
)
5399 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5400 set_iterator_to_next (it
, 0);
5405 it
->selective
= old_selective
;
5406 return newline_found_p
;
5410 /* Set IT's current position to the previous visible line start. Skip
5411 invisible text that is so either due to text properties or due to
5412 selective display. Caution: this does not change IT->current_x and
5416 back_to_previous_visible_line_start (struct it
*it
)
5418 while (IT_CHARPOS (*it
) > BEGV
)
5420 back_to_previous_line_start (it
);
5422 if (IT_CHARPOS (*it
) <= BEGV
)
5425 /* If selective > 0, then lines indented more than its value are
5427 if (it
->selective
> 0
5428 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5429 (double) it
->selective
)) /* iftc */
5432 /* Check the newline before point for invisibility. */
5435 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5436 Qinvisible
, it
->window
);
5437 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5441 if (IT_CHARPOS (*it
) <= BEGV
)
5448 Lisp_Object val
, overlay
;
5450 /* If newline is part of a composition, continue from start of composition */
5451 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5452 && beg
< IT_CHARPOS (*it
))
5455 /* If newline is replaced by a display property, find start of overlay
5456 or interval and continue search from that point. */
5458 pos
= --IT_CHARPOS (it2
);
5461 it2
.string_from_display_prop_p
= 0;
5462 if (handle_display_prop (&it2
) == HANDLED_RETURN
5463 && !NILP (val
= get_char_property_and_overlay
5464 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5465 && (OVERLAYP (overlay
)
5466 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5467 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5470 /* Newline is not replaced by anything -- so we are done. */
5476 IT_CHARPOS (*it
) = beg
;
5477 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5481 it
->continuation_lines_width
= 0;
5483 xassert (IT_CHARPOS (*it
) >= BEGV
);
5484 xassert (IT_CHARPOS (*it
) == BEGV
5485 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5490 /* Reseat iterator IT at the previous visible line start. Skip
5491 invisible text that is so either due to text properties or due to
5492 selective display. At the end, update IT's overlay information,
5493 face information etc. */
5496 reseat_at_previous_visible_line_start (struct it
*it
)
5498 back_to_previous_visible_line_start (it
);
5499 reseat (it
, it
->current
.pos
, 1);
5504 /* Reseat iterator IT on the next visible line start in the current
5505 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5506 preceding the line start. Skip over invisible text that is so
5507 because of selective display. Compute faces, overlays etc at the
5508 new position. Note that this function does not skip over text that
5509 is invisible because of text properties. */
5512 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5514 int newline_found_p
, skipped_p
= 0;
5516 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5518 /* Skip over lines that are invisible because they are indented
5519 more than the value of IT->selective. */
5520 if (it
->selective
> 0)
5521 while (IT_CHARPOS (*it
) < ZV
5522 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5523 (double) it
->selective
)) /* iftc */
5525 xassert (IT_BYTEPOS (*it
) == BEGV
5526 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5527 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5530 /* Position on the newline if that's what's requested. */
5531 if (on_newline_p
&& newline_found_p
)
5533 if (STRINGP (it
->string
))
5535 if (IT_STRING_CHARPOS (*it
) > 0)
5537 --IT_STRING_CHARPOS (*it
);
5538 --IT_STRING_BYTEPOS (*it
);
5541 else if (IT_CHARPOS (*it
) > BEGV
)
5545 reseat (it
, it
->current
.pos
, 0);
5549 reseat (it
, it
->current
.pos
, 0);
5556 /***********************************************************************
5557 Changing an iterator's position
5558 ***********************************************************************/
5560 /* Change IT's current position to POS in current_buffer. If FORCE_P
5561 is non-zero, always check for text properties at the new position.
5562 Otherwise, text properties are only looked up if POS >=
5563 IT->check_charpos of a property. */
5566 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5568 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5570 reseat_1 (it
, pos
, 0);
5572 /* Determine where to check text properties. Avoid doing it
5573 where possible because text property lookup is very expensive. */
5575 || CHARPOS (pos
) > it
->stop_charpos
5576 || CHARPOS (pos
) < original_pos
)
5580 /* For bidi iteration, we need to prime prev_stop and
5581 base_level_stop with our best estimations. */
5582 if (CHARPOS (pos
) < it
->prev_stop
)
5584 handle_stop_backwards (it
, BEGV
);
5585 if (CHARPOS (pos
) < it
->base_level_stop
)
5586 it
->base_level_stop
= 0;
5588 else if (CHARPOS (pos
) > it
->stop_charpos
5589 && it
->stop_charpos
>= BEGV
)
5590 handle_stop_backwards (it
, it
->stop_charpos
);
5597 it
->prev_stop
= it
->base_level_stop
= 0;
5606 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5607 IT->stop_pos to POS, also. */
5610 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5612 /* Don't call this function when scanning a C string. */
5613 xassert (it
->s
== NULL
);
5615 /* POS must be a reasonable value. */
5616 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5618 it
->current
.pos
= it
->position
= pos
;
5619 it
->end_charpos
= ZV
;
5621 it
->current
.dpvec_index
= -1;
5622 it
->current
.overlay_string_index
= -1;
5623 IT_STRING_CHARPOS (*it
) = -1;
5624 IT_STRING_BYTEPOS (*it
) = -1;
5626 it
->string_from_display_prop_p
= 0;
5627 it
->method
= GET_FROM_BUFFER
;
5628 it
->object
= it
->w
->buffer
;
5629 it
->area
= TEXT_AREA
;
5630 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5632 it
->string_from_display_prop_p
= 0;
5633 it
->face_before_selective_p
= 0;
5636 it
->bidi_it
.first_elt
= 1;
5637 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5642 it
->stop_charpos
= CHARPOS (pos
);
5643 it
->base_level_stop
= CHARPOS (pos
);
5648 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5649 If S is non-null, it is a C string to iterate over. Otherwise,
5650 STRING gives a Lisp string to iterate over.
5652 If PRECISION > 0, don't return more then PRECISION number of
5653 characters from the string.
5655 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5656 characters have been returned. FIELD_WIDTH < 0 means an infinite
5659 MULTIBYTE = 0 means disable processing of multibyte characters,
5660 MULTIBYTE > 0 means enable it,
5661 MULTIBYTE < 0 means use IT->multibyte_p.
5663 IT must be initialized via a prior call to init_iterator before
5664 calling this function. */
5667 reseat_to_string (struct it
*it
, const unsigned char *s
, Lisp_Object string
,
5668 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5671 /* No region in strings. */
5672 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5674 /* No text property checks performed by default, but see below. */
5675 it
->stop_charpos
= -1;
5677 /* Set iterator position and end position. */
5678 memset (&it
->current
, 0, sizeof it
->current
);
5679 it
->current
.overlay_string_index
= -1;
5680 it
->current
.dpvec_index
= -1;
5681 xassert (charpos
>= 0);
5683 /* If STRING is specified, use its multibyteness, otherwise use the
5684 setting of MULTIBYTE, if specified. */
5686 it
->multibyte_p
= multibyte
> 0;
5690 xassert (STRINGP (string
));
5691 it
->string
= string
;
5693 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5694 it
->method
= GET_FROM_STRING
;
5695 it
->current
.string_pos
= string_pos (charpos
, string
);
5702 /* Note that we use IT->current.pos, not it->current.string_pos,
5703 for displaying C strings. */
5704 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5705 if (it
->multibyte_p
)
5707 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5708 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5712 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5713 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5716 it
->method
= GET_FROM_C_STRING
;
5719 /* PRECISION > 0 means don't return more than PRECISION characters
5721 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5722 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5724 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5725 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5726 FIELD_WIDTH < 0 means infinite field width. This is useful for
5727 padding with `-' at the end of a mode line. */
5728 if (field_width
< 0)
5729 field_width
= INFINITY
;
5730 if (field_width
> it
->end_charpos
- charpos
)
5731 it
->end_charpos
= charpos
+ field_width
;
5733 /* Use the standard display table for displaying strings. */
5734 if (DISP_TABLE_P (Vstandard_display_table
))
5735 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5737 it
->stop_charpos
= charpos
;
5738 if (s
== NULL
&& it
->multibyte_p
)
5740 EMACS_INT endpos
= SCHARS (it
->string
);
5741 if (endpos
> it
->end_charpos
)
5742 endpos
= it
->end_charpos
;
5743 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5751 /***********************************************************************
5753 ***********************************************************************/
5755 /* Map enum it_method value to corresponding next_element_from_* function. */
5757 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5759 next_element_from_buffer
,
5760 next_element_from_display_vector
,
5761 next_element_from_string
,
5762 next_element_from_c_string
,
5763 next_element_from_image
,
5764 next_element_from_stretch
5767 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5770 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5771 (possibly with the following characters). */
5773 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5774 ((IT)->cmp_it.id >= 0 \
5775 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5776 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5777 END_CHARPOS, (IT)->w, \
5778 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5782 /* Lookup the char-table Vglyphless_char_display for character C (-1
5783 if we want information for no-font case), and return the display
5784 method symbol. By side-effect, update it->what and
5785 it->glyphless_method. This function is called from
5786 get_next_display_element for each character element, and from
5787 x_produce_glyphs when no suitable font was found. */
5790 lookup_glyphless_char_display (int c
, struct it
*it
)
5792 Lisp_Object glyphless_method
= Qnil
;
5794 if (CHAR_TABLE_P (Vglyphless_char_display
)
5795 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5796 glyphless_method
= (c
>= 0
5797 ? CHAR_TABLE_REF (Vglyphless_char_display
, c
)
5798 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
5800 if (NILP (glyphless_method
))
5803 /* The default is to display the character by a proper font. */
5805 /* The default for the no-font case is to display an empty box. */
5806 glyphless_method
= Qempty_box
;
5808 if (EQ (glyphless_method
, Qzero_width
))
5811 return glyphless_method
;
5812 /* This method can't be used for the no-font case. */
5813 glyphless_method
= Qempty_box
;
5815 if (EQ (glyphless_method
, Qthin_space
))
5816 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5817 else if (EQ (glyphless_method
, Qempty_box
))
5818 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5819 else if (EQ (glyphless_method
, Qhex_code
))
5820 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5821 else if (STRINGP (glyphless_method
))
5822 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5825 /* Invalid value. We use the default method. */
5826 glyphless_method
= Qnil
;
5829 it
->what
= IT_GLYPHLESS
;
5830 return glyphless_method
;
5833 /* Load IT's display element fields with information about the next
5834 display element from the current position of IT. Value is zero if
5835 end of buffer (or C string) is reached. */
5837 static struct frame
*last_escape_glyph_frame
= NULL
;
5838 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5839 static int last_escape_glyph_merged_face_id
= 0;
5841 struct frame
*last_glyphless_glyph_frame
= NULL
;
5842 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
5843 int last_glyphless_glyph_merged_face_id
= 0;
5846 get_next_display_element (struct it
*it
)
5848 /* Non-zero means that we found a display element. Zero means that
5849 we hit the end of what we iterate over. Performance note: the
5850 function pointer `method' used here turns out to be faster than
5851 using a sequence of if-statements. */
5855 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5857 if (it
->what
== IT_CHARACTER
)
5859 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5860 and only if (a) the resolved directionality of that character
5862 /* FIXME: Do we need an exception for characters from display
5864 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5865 it
->c
= bidi_mirror_char (it
->c
);
5866 /* Map via display table or translate control characters.
5867 IT->c, IT->len etc. have been set to the next character by
5868 the function call above. If we have a display table, and it
5869 contains an entry for IT->c, translate it. Don't do this if
5870 IT->c itself comes from a display table, otherwise we could
5871 end up in an infinite recursion. (An alternative could be to
5872 count the recursion depth of this function and signal an
5873 error when a certain maximum depth is reached.) Is it worth
5875 if (success_p
&& it
->dpvec
== NULL
)
5878 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5879 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5880 nbsp_or_shy
= char_is_other
;
5881 int c
= it
->c
; /* This is the character to display. */
5883 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
5885 xassert (SINGLE_BYTE_CHAR_P (c
));
5886 if (unibyte_display_via_language_environment
)
5888 c
= DECODE_CHAR (unibyte
, c
);
5890 c
= BYTE8_TO_CHAR (it
->c
);
5893 c
= BYTE8_TO_CHAR (it
->c
);
5897 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
5900 struct Lisp_Vector
*v
= XVECTOR (dv
);
5902 /* Return the first character from the display table
5903 entry, if not empty. If empty, don't display the
5904 current character. */
5907 it
->dpvec_char_len
= it
->len
;
5908 it
->dpvec
= v
->contents
;
5909 it
->dpend
= v
->contents
+ v
->size
;
5910 it
->current
.dpvec_index
= 0;
5911 it
->dpvec_face_id
= -1;
5912 it
->saved_face_id
= it
->face_id
;
5913 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5918 set_iterator_to_next (it
, 0);
5923 if (! NILP (lookup_glyphless_char_display (c
, it
)))
5925 if (it
->what
== IT_GLYPHLESS
)
5927 /* Don't display this character. */
5928 set_iterator_to_next (it
, 0);
5932 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
5933 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
5934 : c
== 0xAD ? char_is_soft_hyphen
5937 /* Translate control characters into `\003' or `^C' form.
5938 Control characters coming from a display table entry are
5939 currently not translated because we use IT->dpvec to hold
5940 the translation. This could easily be changed but I
5941 don't believe that it is worth doing.
5943 NBSP and SOFT-HYPEN are property translated too.
5945 Non-printable characters and raw-byte characters are also
5946 translated to octal form. */
5947 if (((c
< ' ' || c
== 127) /* ASCII control chars */
5948 ? (it
->area
!= TEXT_AREA
5949 /* In mode line, treat \n, \t like other crl chars. */
5952 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5953 || (c
!= '\n' && c
!= '\t'))
5956 || ! CHAR_PRINTABLE_P (c
))))
5958 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
5959 or a non-printable character which must be displayed
5960 either as '\003' or as `^C' where the '\\' and '^'
5961 can be defined in the display table. Fill
5962 IT->ctl_chars with glyphs for what we have to
5963 display. Then, set IT->dpvec to these glyphs. */
5966 int face_id
, lface_id
= 0 ;
5969 /* Handle control characters with ^. */
5971 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
5975 g
= '^'; /* default glyph for Control */
5976 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5978 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5979 && GLYPH_CODE_CHAR_VALID_P (gc
))
5981 g
= GLYPH_CODE_CHAR (gc
);
5982 lface_id
= GLYPH_CODE_FACE (gc
);
5986 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5988 else if (it
->f
== last_escape_glyph_frame
5989 && it
->face_id
== last_escape_glyph_face_id
)
5991 face_id
= last_escape_glyph_merged_face_id
;
5995 /* Merge the escape-glyph face into the current face. */
5996 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5998 last_escape_glyph_frame
= it
->f
;
5999 last_escape_glyph_face_id
= it
->face_id
;
6000 last_escape_glyph_merged_face_id
= face_id
;
6003 XSETINT (it
->ctl_chars
[0], g
);
6004 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6006 goto display_control
;
6009 /* Handle non-break space in the mode where it only gets
6012 if (EQ (Vnobreak_char_display
, Qt
)
6013 && nbsp_or_shy
== char_is_nbsp
)
6015 /* Merge the no-break-space face into the current face. */
6016 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6020 XSETINT (it
->ctl_chars
[0], ' ');
6022 goto display_control
;
6025 /* Handle sequences that start with the "escape glyph". */
6027 /* the default escape glyph is \. */
6028 escape_glyph
= '\\';
6031 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6032 && GLYPH_CODE_CHAR_VALID_P (gc
))
6034 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6035 lface_id
= GLYPH_CODE_FACE (gc
);
6039 /* The display table specified a face.
6040 Merge it into face_id and also into escape_glyph. */
6041 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6044 else if (it
->f
== last_escape_glyph_frame
6045 && it
->face_id
== last_escape_glyph_face_id
)
6047 face_id
= last_escape_glyph_merged_face_id
;
6051 /* Merge the escape-glyph face into the current face. */
6052 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6054 last_escape_glyph_frame
= it
->f
;
6055 last_escape_glyph_face_id
= it
->face_id
;
6056 last_escape_glyph_merged_face_id
= face_id
;
6059 /* Handle soft hyphens in the mode where they only get
6062 if (EQ (Vnobreak_char_display
, Qt
)
6063 && nbsp_or_shy
== char_is_soft_hyphen
)
6065 XSETINT (it
->ctl_chars
[0], '-');
6067 goto display_control
;
6070 /* Handle non-break space and soft hyphen
6071 with the escape glyph. */
6075 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6076 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6077 XSETINT (it
->ctl_chars
[1], c
);
6079 goto display_control
;
6086 if (CHAR_BYTE8_P (c
))
6087 /* Display \200 instead of \17777600. */
6088 c
= CHAR_TO_BYTE8 (c
);
6089 len
= sprintf (str
, "%03o", c
);
6091 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6092 for (i
= 0; i
< len
; i
++)
6093 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6098 /* Set up IT->dpvec and return first character from it. */
6099 it
->dpvec_char_len
= it
->len
;
6100 it
->dpvec
= it
->ctl_chars
;
6101 it
->dpend
= it
->dpvec
+ ctl_len
;
6102 it
->current
.dpvec_index
= 0;
6103 it
->dpvec_face_id
= face_id
;
6104 it
->saved_face_id
= it
->face_id
;
6105 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6109 it
->char_to_display
= c
;
6113 it
->char_to_display
= it
->c
;
6117 #ifdef HAVE_WINDOW_SYSTEM
6118 /* Adjust face id for a multibyte character. There are no multibyte
6119 character in unibyte text. */
6120 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6123 && FRAME_WINDOW_P (it
->f
))
6125 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6127 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6129 /* Automatic composition with glyph-string. */
6130 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6132 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6136 EMACS_INT pos
= (it
->s
? -1
6137 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6138 : IT_CHARPOS (*it
));
6140 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
6147 /* Is this character the last one of a run of characters with
6148 box? If yes, set IT->end_of_box_run_p to 1. */
6152 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6154 int face_id
= underlying_face_id (it
);
6155 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6159 if (face
->box
== FACE_NO_BOX
)
6161 /* If the box comes from face properties in a
6162 display string, check faces in that string. */
6163 int string_face_id
= face_after_it_pos (it
);
6164 it
->end_of_box_run_p
6165 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6168 /* Otherwise, the box comes from the underlying face.
6169 If this is the last string character displayed, check
6170 the next buffer location. */
6171 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6172 && (it
->current
.overlay_string_index
6173 == it
->n_overlay_strings
- 1))
6177 struct text_pos pos
= it
->current
.pos
;
6178 INC_TEXT_POS (pos
, it
->multibyte_p
);
6180 next_face_id
= face_at_buffer_position
6181 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6182 it
->region_end_charpos
, &ignore
,
6183 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6185 it
->end_of_box_run_p
6186 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6193 int face_id
= face_after_it_pos (it
);
6194 it
->end_of_box_run_p
6195 = (face_id
!= it
->face_id
6196 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6200 /* Value is 0 if end of buffer or string reached. */
6205 /* Move IT to the next display element.
6207 RESEAT_P non-zero means if called on a newline in buffer text,
6208 skip to the next visible line start.
6210 Functions get_next_display_element and set_iterator_to_next are
6211 separate because I find this arrangement easier to handle than a
6212 get_next_display_element function that also increments IT's
6213 position. The way it is we can first look at an iterator's current
6214 display element, decide whether it fits on a line, and if it does,
6215 increment the iterator position. The other way around we probably
6216 would either need a flag indicating whether the iterator has to be
6217 incremented the next time, or we would have to implement a
6218 decrement position function which would not be easy to write. */
6221 set_iterator_to_next (struct it
*it
, int reseat_p
)
6223 /* Reset flags indicating start and end of a sequence of characters
6224 with box. Reset them at the start of this function because
6225 moving the iterator to a new position might set them. */
6226 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6230 case GET_FROM_BUFFER
:
6231 /* The current display element of IT is a character from
6232 current_buffer. Advance in the buffer, and maybe skip over
6233 invisible lines that are so because of selective display. */
6234 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6235 reseat_at_next_visible_line_start (it
, 0);
6236 else if (it
->cmp_it
.id
>= 0)
6238 /* We are currently getting glyphs from a composition. */
6243 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6244 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6245 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6247 it
->cmp_it
.from
= it
->cmp_it
.to
;
6252 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6254 it
->end_charpos
, Qnil
);
6257 else if (! it
->cmp_it
.reversed_p
)
6259 /* Composition created while scanning forward. */
6260 /* Update IT's char/byte positions to point to the first
6261 character of the next grapheme cluster, or to the
6262 character visually after the current composition. */
6263 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6264 bidi_move_to_visually_next (&it
->bidi_it
);
6265 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6266 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6268 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6270 /* Proceed to the next grapheme cluster. */
6271 it
->cmp_it
.from
= it
->cmp_it
.to
;
6275 /* No more grapheme clusters in this composition.
6276 Find the next stop position. */
6277 EMACS_INT stop
= it
->end_charpos
;
6278 if (it
->bidi_it
.scan_dir
< 0)
6279 /* Now we are scanning backward and don't know
6282 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6283 IT_BYTEPOS (*it
), stop
, Qnil
);
6288 /* Composition created while scanning backward. */
6289 /* Update IT's char/byte positions to point to the last
6290 character of the previous grapheme cluster, or the
6291 character visually after the current composition. */
6292 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6293 bidi_move_to_visually_next (&it
->bidi_it
);
6294 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6295 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6296 if (it
->cmp_it
.from
> 0)
6298 /* Proceed to the previous grapheme cluster. */
6299 it
->cmp_it
.to
= it
->cmp_it
.from
;
6303 /* No more grapheme clusters in this composition.
6304 Find the next stop position. */
6305 EMACS_INT stop
= it
->end_charpos
;
6306 if (it
->bidi_it
.scan_dir
< 0)
6307 /* Now we are scanning backward and don't know
6310 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6311 IT_BYTEPOS (*it
), stop
, Qnil
);
6317 xassert (it
->len
!= 0);
6321 IT_BYTEPOS (*it
) += it
->len
;
6322 IT_CHARPOS (*it
) += 1;
6326 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6327 /* If this is a new paragraph, determine its base
6328 direction (a.k.a. its base embedding level). */
6329 if (it
->bidi_it
.new_paragraph
)
6330 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6331 bidi_move_to_visually_next (&it
->bidi_it
);
6332 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6333 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6334 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6336 /* As the scan direction was changed, we must
6337 re-compute the stop position for composition. */
6338 EMACS_INT stop
= it
->end_charpos
;
6339 if (it
->bidi_it
.scan_dir
< 0)
6341 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6342 IT_BYTEPOS (*it
), stop
, Qnil
);
6345 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6349 case GET_FROM_C_STRING
:
6350 /* Current display element of IT is from a C string. */
6351 IT_BYTEPOS (*it
) += it
->len
;
6352 IT_CHARPOS (*it
) += 1;
6355 case GET_FROM_DISPLAY_VECTOR
:
6356 /* Current display element of IT is from a display table entry.
6357 Advance in the display table definition. Reset it to null if
6358 end reached, and continue with characters from buffers/
6360 ++it
->current
.dpvec_index
;
6362 /* Restore face of the iterator to what they were before the
6363 display vector entry (these entries may contain faces). */
6364 it
->face_id
= it
->saved_face_id
;
6366 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6368 int recheck_faces
= it
->ellipsis_p
;
6371 it
->method
= GET_FROM_C_STRING
;
6372 else if (STRINGP (it
->string
))
6373 it
->method
= GET_FROM_STRING
;
6376 it
->method
= GET_FROM_BUFFER
;
6377 it
->object
= it
->w
->buffer
;
6381 it
->current
.dpvec_index
= -1;
6383 /* Skip over characters which were displayed via IT->dpvec. */
6384 if (it
->dpvec_char_len
< 0)
6385 reseat_at_next_visible_line_start (it
, 1);
6386 else if (it
->dpvec_char_len
> 0)
6388 if (it
->method
== GET_FROM_STRING
6389 && it
->n_overlay_strings
> 0)
6390 it
->ignore_overlay_strings_at_pos_p
= 1;
6391 it
->len
= it
->dpvec_char_len
;
6392 set_iterator_to_next (it
, reseat_p
);
6395 /* Maybe recheck faces after display vector */
6397 it
->stop_charpos
= IT_CHARPOS (*it
);
6401 case GET_FROM_STRING
:
6402 /* Current display element is a character from a Lisp string. */
6403 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6404 if (it
->cmp_it
.id
>= 0)
6406 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6407 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6408 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6409 it
->cmp_it
.from
= it
->cmp_it
.to
;
6413 composition_compute_stop_pos (&it
->cmp_it
,
6414 IT_STRING_CHARPOS (*it
),
6415 IT_STRING_BYTEPOS (*it
),
6416 it
->end_charpos
, it
->string
);
6421 IT_STRING_BYTEPOS (*it
) += it
->len
;
6422 IT_STRING_CHARPOS (*it
) += 1;
6425 consider_string_end
:
6427 if (it
->current
.overlay_string_index
>= 0)
6429 /* IT->string is an overlay string. Advance to the
6430 next, if there is one. */
6431 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6434 next_overlay_string (it
);
6436 setup_for_ellipsis (it
, 0);
6441 /* IT->string is not an overlay string. If we reached
6442 its end, and there is something on IT->stack, proceed
6443 with what is on the stack. This can be either another
6444 string, this time an overlay string, or a buffer. */
6445 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6449 if (it
->method
== GET_FROM_STRING
)
6450 goto consider_string_end
;
6455 case GET_FROM_IMAGE
:
6456 case GET_FROM_STRETCH
:
6457 /* The position etc with which we have to proceed are on
6458 the stack. The position may be at the end of a string,
6459 if the `display' property takes up the whole string. */
6460 xassert (it
->sp
> 0);
6462 if (it
->method
== GET_FROM_STRING
)
6463 goto consider_string_end
;
6467 /* There are no other methods defined, so this should be a bug. */
6471 xassert (it
->method
!= GET_FROM_STRING
6472 || (STRINGP (it
->string
)
6473 && IT_STRING_CHARPOS (*it
) >= 0));
6476 /* Load IT's display element fields with information about the next
6477 display element which comes from a display table entry or from the
6478 result of translating a control character to one of the forms `^C'
6481 IT->dpvec holds the glyphs to return as characters.
6482 IT->saved_face_id holds the face id before the display vector--it
6483 is restored into IT->face_id in set_iterator_to_next. */
6486 next_element_from_display_vector (struct it
*it
)
6491 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6493 it
->face_id
= it
->saved_face_id
;
6495 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6496 That seemed totally bogus - so I changed it... */
6497 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6499 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6501 it
->c
= GLYPH_CODE_CHAR (gc
);
6502 it
->len
= CHAR_BYTES (it
->c
);
6504 /* The entry may contain a face id to use. Such a face id is
6505 the id of a Lisp face, not a realized face. A face id of
6506 zero means no face is specified. */
6507 if (it
->dpvec_face_id
>= 0)
6508 it
->face_id
= it
->dpvec_face_id
;
6511 int lface_id
= GLYPH_CODE_FACE (gc
);
6513 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6518 /* Display table entry is invalid. Return a space. */
6519 it
->c
= ' ', it
->len
= 1;
6521 /* Don't change position and object of the iterator here. They are
6522 still the values of the character that had this display table
6523 entry or was translated, and that's what we want. */
6524 it
->what
= IT_CHARACTER
;
6529 /* Load IT with the next display element from Lisp string IT->string.
6530 IT->current.string_pos is the current position within the string.
6531 If IT->current.overlay_string_index >= 0, the Lisp string is an
6535 next_element_from_string (struct it
*it
)
6537 struct text_pos position
;
6539 xassert (STRINGP (it
->string
));
6540 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6541 position
= it
->current
.string_pos
;
6543 /* Time to check for invisible text? */
6544 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6545 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6549 /* Since a handler may have changed IT->method, we must
6551 return GET_NEXT_DISPLAY_ELEMENT (it
);
6554 if (it
->current
.overlay_string_index
>= 0)
6556 /* Get the next character from an overlay string. In overlay
6557 strings, There is no field width or padding with spaces to
6559 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6564 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6565 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6566 && next_element_from_composition (it
))
6570 else if (STRING_MULTIBYTE (it
->string
))
6572 const unsigned char *s
= (SDATA (it
->string
)
6573 + IT_STRING_BYTEPOS (*it
));
6574 it
->c
= string_char_and_length (s
, &it
->len
);
6578 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6584 /* Get the next character from a Lisp string that is not an
6585 overlay string. Such strings come from the mode line, for
6586 example. We may have to pad with spaces, or truncate the
6587 string. See also next_element_from_c_string. */
6588 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6593 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6595 /* Pad with spaces. */
6596 it
->c
= ' ', it
->len
= 1;
6597 CHARPOS (position
) = BYTEPOS (position
) = -1;
6599 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6600 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6601 && next_element_from_composition (it
))
6605 else if (STRING_MULTIBYTE (it
->string
))
6607 const unsigned char *s
= (SDATA (it
->string
)
6608 + IT_STRING_BYTEPOS (*it
));
6609 it
->c
= string_char_and_length (s
, &it
->len
);
6613 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6618 /* Record what we have and where it came from. */
6619 it
->what
= IT_CHARACTER
;
6620 it
->object
= it
->string
;
6621 it
->position
= position
;
6626 /* Load IT with next display element from C string IT->s.
6627 IT->string_nchars is the maximum number of characters to return
6628 from the string. IT->end_charpos may be greater than
6629 IT->string_nchars when this function is called, in which case we
6630 may have to return padding spaces. Value is zero if end of string
6631 reached, including padding spaces. */
6634 next_element_from_c_string (struct it
*it
)
6639 it
->what
= IT_CHARACTER
;
6640 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6643 /* IT's position can be greater IT->string_nchars in case a field
6644 width or precision has been specified when the iterator was
6646 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6648 /* End of the game. */
6652 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6654 /* Pad with spaces. */
6655 it
->c
= ' ', it
->len
= 1;
6656 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6658 else if (it
->multibyte_p
)
6659 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6661 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6667 /* Set up IT to return characters from an ellipsis, if appropriate.
6668 The definition of the ellipsis glyphs may come from a display table
6669 entry. This function fills IT with the first glyph from the
6670 ellipsis if an ellipsis is to be displayed. */
6673 next_element_from_ellipsis (struct it
*it
)
6675 if (it
->selective_display_ellipsis_p
)
6676 setup_for_ellipsis (it
, it
->len
);
6679 /* The face at the current position may be different from the
6680 face we find after the invisible text. Remember what it
6681 was in IT->saved_face_id, and signal that it's there by
6682 setting face_before_selective_p. */
6683 it
->saved_face_id
= it
->face_id
;
6684 it
->method
= GET_FROM_BUFFER
;
6685 it
->object
= it
->w
->buffer
;
6686 reseat_at_next_visible_line_start (it
, 1);
6687 it
->face_before_selective_p
= 1;
6690 return GET_NEXT_DISPLAY_ELEMENT (it
);
6694 /* Deliver an image display element. The iterator IT is already
6695 filled with image information (done in handle_display_prop). Value
6700 next_element_from_image (struct it
*it
)
6702 it
->what
= IT_IMAGE
;
6703 it
->ignore_overlay_strings_at_pos_p
= 0;
6708 /* Fill iterator IT with next display element from a stretch glyph
6709 property. IT->object is the value of the text property. Value is
6713 next_element_from_stretch (struct it
*it
)
6715 it
->what
= IT_STRETCH
;
6719 /* Scan forward from CHARPOS in the current buffer, until we find a
6720 stop position > current IT's position. Then handle the stop
6721 position before that. This is called when we bump into a stop
6722 position while reordering bidirectional text. CHARPOS should be
6723 the last previously processed stop_pos (or BEGV, if none were
6724 processed yet) whose position is less that IT's current
6728 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
6730 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6731 struct display_pos save_current
= it
->current
;
6732 struct text_pos save_position
= it
->position
;
6733 struct text_pos pos1
;
6734 EMACS_INT next_stop
;
6736 /* Scan in strict logical order. */
6740 it
->prev_stop
= charpos
;
6741 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6742 reseat_1 (it
, pos1
, 0);
6743 compute_stop_pos (it
);
6744 /* We must advance forward, right? */
6745 if (it
->stop_charpos
<= it
->prev_stop
)
6747 charpos
= it
->stop_charpos
;
6749 while (charpos
<= where_we_are
);
6751 next_stop
= it
->stop_charpos
;
6752 it
->stop_charpos
= it
->prev_stop
;
6754 it
->current
= save_current
;
6755 it
->position
= save_position
;
6757 it
->stop_charpos
= next_stop
;
6760 /* Load IT with the next display element from current_buffer. Value
6761 is zero if end of buffer reached. IT->stop_charpos is the next
6762 position at which to stop and check for text properties or buffer
6766 next_element_from_buffer (struct it
*it
)
6770 xassert (IT_CHARPOS (*it
) >= BEGV
);
6772 /* With bidi reordering, the character to display might not be the
6773 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6774 we were reseat()ed to a new buffer position, which is potentially
6775 a different paragraph. */
6776 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6778 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6779 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6780 if (it
->bidi_it
.bytepos
== ZV_BYTE
)
6782 /* Nothing to do, but reset the FIRST_ELT flag, like
6783 bidi_paragraph_init does, because we are not going to
6785 it
->bidi_it
.first_elt
= 0;
6787 else if (it
->bidi_it
.bytepos
== BEGV_BYTE
6788 /* FIXME: Should support all Unicode line separators. */
6789 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6790 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6792 /* If we are at the beginning of a line, we can produce the
6793 next element right away. */
6794 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6795 bidi_move_to_visually_next (&it
->bidi_it
);
6799 EMACS_INT orig_bytepos
= IT_BYTEPOS (*it
);
6801 /* We need to prime the bidi iterator starting at the line's
6802 beginning, before we will be able to produce the next
6804 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6805 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6806 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6807 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6808 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6811 /* Now return to buffer position where we were asked to
6812 get the next display element, and produce that. */
6813 bidi_move_to_visually_next (&it
->bidi_it
);
6815 while (it
->bidi_it
.bytepos
!= orig_bytepos
6816 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6819 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6820 /* Adjust IT's position information to where we ended up. */
6821 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6822 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6823 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6825 EMACS_INT stop
= it
->end_charpos
;
6826 if (it
->bidi_it
.scan_dir
< 0)
6828 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6829 IT_BYTEPOS (*it
), stop
, Qnil
);
6833 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6835 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6837 int overlay_strings_follow_p
;
6839 /* End of the game, except when overlay strings follow that
6840 haven't been returned yet. */
6841 if (it
->overlay_strings_at_end_processed_p
)
6842 overlay_strings_follow_p
= 0;
6845 it
->overlay_strings_at_end_processed_p
= 1;
6846 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6849 if (overlay_strings_follow_p
)
6850 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6854 it
->position
= it
->current
.pos
;
6858 else if (!(!it
->bidi_p
6859 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6860 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6862 /* With bidi non-linear iteration, we could find ourselves
6863 far beyond the last computed stop_charpos, with several
6864 other stop positions in between that we missed. Scan
6865 them all now, in buffer's logical order, until we find
6866 and handle the last stop_charpos that precedes our
6867 current position. */
6868 handle_stop_backwards (it
, it
->stop_charpos
);
6869 return GET_NEXT_DISPLAY_ELEMENT (it
);
6875 /* Take note of the stop position we just moved across,
6876 for when we will move back across it. */
6877 it
->prev_stop
= it
->stop_charpos
;
6878 /* If we are at base paragraph embedding level, take
6879 note of the last stop position seen at this
6881 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6882 it
->base_level_stop
= it
->stop_charpos
;
6885 return GET_NEXT_DISPLAY_ELEMENT (it
);
6889 /* We can sometimes back up for reasons that have nothing
6890 to do with bidi reordering. E.g., compositions. The
6891 code below is only needed when we are above the base
6892 embedding level, so test for that explicitly. */
6893 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6894 && IT_CHARPOS (*it
) < it
->prev_stop
)
6896 if (it
->base_level_stop
<= 0)
6897 it
->base_level_stop
= BEGV
;
6898 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6900 handle_stop_backwards (it
, it
->base_level_stop
);
6901 return GET_NEXT_DISPLAY_ELEMENT (it
);
6905 /* No face changes, overlays etc. in sight, so just return a
6906 character from current_buffer. */
6910 /* Maybe run the redisplay end trigger hook. Performance note:
6911 This doesn't seem to cost measurable time. */
6912 if (it
->redisplay_end_trigger_charpos
6914 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6915 run_redisplay_end_trigger_hook (it
);
6917 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
6918 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6920 && next_element_from_composition (it
))
6925 /* Get the next character, maybe multibyte. */
6926 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6927 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6928 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6930 it
->c
= *p
, it
->len
= 1;
6932 /* Record what we have and where it came from. */
6933 it
->what
= IT_CHARACTER
;
6934 it
->object
= it
->w
->buffer
;
6935 it
->position
= it
->current
.pos
;
6937 /* Normally we return the character found above, except when we
6938 really want to return an ellipsis for selective display. */
6943 /* A value of selective > 0 means hide lines indented more
6944 than that number of columns. */
6945 if (it
->selective
> 0
6946 && IT_CHARPOS (*it
) + 1 < ZV
6947 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6948 IT_BYTEPOS (*it
) + 1,
6949 (double) it
->selective
)) /* iftc */
6951 success_p
= next_element_from_ellipsis (it
);
6952 it
->dpvec_char_len
= -1;
6955 else if (it
->c
== '\r' && it
->selective
== -1)
6957 /* A value of selective == -1 means that everything from the
6958 CR to the end of the line is invisible, with maybe an
6959 ellipsis displayed for it. */
6960 success_p
= next_element_from_ellipsis (it
);
6961 it
->dpvec_char_len
= -1;
6966 /* Value is zero if end of buffer reached. */
6967 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6972 /* Run the redisplay end trigger hook for IT. */
6975 run_redisplay_end_trigger_hook (struct it
*it
)
6977 Lisp_Object args
[3];
6979 /* IT->glyph_row should be non-null, i.e. we should be actually
6980 displaying something, or otherwise we should not run the hook. */
6981 xassert (it
->glyph_row
);
6983 /* Set up hook arguments. */
6984 args
[0] = Qredisplay_end_trigger_functions
;
6985 args
[1] = it
->window
;
6986 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6987 it
->redisplay_end_trigger_charpos
= 0;
6989 /* Since we are *trying* to run these functions, don't try to run
6990 them again, even if they get an error. */
6991 it
->w
->redisplay_end_trigger
= Qnil
;
6992 Frun_hook_with_args (3, args
);
6994 /* Notice if it changed the face of the character we are on. */
6995 handle_face_prop (it
);
6999 /* Deliver a composition display element. Unlike the other
7000 next_element_from_XXX, this function is not registered in the array
7001 get_next_element[]. It is called from next_element_from_buffer and
7002 next_element_from_string when necessary. */
7005 next_element_from_composition (struct it
*it
)
7007 it
->what
= IT_COMPOSITION
;
7008 it
->len
= it
->cmp_it
.nbytes
;
7009 if (STRINGP (it
->string
))
7013 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7014 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7017 it
->position
= it
->current
.string_pos
;
7018 it
->object
= it
->string
;
7019 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7020 IT_STRING_BYTEPOS (*it
), it
->string
);
7026 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7027 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7030 if (it
->bidi_it
.new_paragraph
)
7031 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7032 /* Resync the bidi iterator with IT's new position.
7033 FIXME: this doesn't support bidirectional text. */
7034 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7035 bidi_move_to_visually_next (&it
->bidi_it
);
7039 it
->position
= it
->current
.pos
;
7040 it
->object
= it
->w
->buffer
;
7041 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7042 IT_BYTEPOS (*it
), Qnil
);
7049 /***********************************************************************
7050 Moving an iterator without producing glyphs
7051 ***********************************************************************/
7053 /* Check if iterator is at a position corresponding to a valid buffer
7054 position after some move_it_ call. */
7056 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7057 ((it)->method == GET_FROM_STRING \
7058 ? IT_STRING_CHARPOS (*it) == 0 \
7062 /* Move iterator IT to a specified buffer or X position within one
7063 line on the display without producing glyphs.
7065 OP should be a bit mask including some or all of these bits:
7066 MOVE_TO_X: Stop upon reaching x-position TO_X.
7067 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7068 Regardless of OP's value, stop upon reaching the end of the display line.
7070 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7071 This means, in particular, that TO_X includes window's horizontal
7074 The return value has several possible values that
7075 say what condition caused the scan to stop:
7077 MOVE_POS_MATCH_OR_ZV
7078 - when TO_POS or ZV was reached.
7081 -when TO_X was reached before TO_POS or ZV were reached.
7084 - when we reached the end of the display area and the line must
7088 - when we reached the end of the display area and the line is
7092 - when we stopped at a line end, i.e. a newline or a CR and selective
7095 static enum move_it_result
7096 move_it_in_display_line_to (struct it
*it
,
7097 EMACS_INT to_charpos
, int to_x
,
7098 enum move_operation_enum op
)
7100 enum move_it_result result
= MOVE_UNDEFINED
;
7101 struct glyph_row
*saved_glyph_row
;
7102 struct it wrap_it
, atpos_it
, atx_it
;
7104 enum it_method prev_method
= it
->method
;
7105 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7107 /* Don't produce glyphs in produce_glyphs. */
7108 saved_glyph_row
= it
->glyph_row
;
7109 it
->glyph_row
= NULL
;
7111 /* Use wrap_it to save a copy of IT wherever a word wrap could
7112 occur. Use atpos_it to save a copy of IT at the desired buffer
7113 position, if found, so that we can scan ahead and check if the
7114 word later overshoots the window edge. Use atx_it similarly, for
7120 #define BUFFER_POS_REACHED_P() \
7121 ((op & MOVE_TO_POS) != 0 \
7122 && BUFFERP (it->object) \
7123 && (IT_CHARPOS (*it) == to_charpos \
7124 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
7125 && (it->method == GET_FROM_BUFFER \
7126 || (it->method == GET_FROM_DISPLAY_VECTOR \
7127 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7129 /* If there's a line-/wrap-prefix, handle it. */
7130 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7131 && it
->current_y
< it
->last_visible_y
)
7132 handle_line_prefix (it
);
7136 int x
, i
, ascent
= 0, descent
= 0;
7138 /* Utility macro to reset an iterator with x, ascent, and descent. */
7139 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7140 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7141 (IT)->max_descent = descent)
7143 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7145 if ((op
& MOVE_TO_POS
) != 0
7146 && BUFFERP (it
->object
)
7147 && it
->method
== GET_FROM_BUFFER
7148 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7150 && (prev_method
== GET_FROM_IMAGE
7151 || prev_method
== GET_FROM_STRETCH
)
7152 /* Passed TO_CHARPOS from left to right. */
7153 && ((prev_pos
< to_charpos
7154 && IT_CHARPOS (*it
) > to_charpos
)
7155 /* Passed TO_CHARPOS from right to left. */
7156 || (prev_pos
> to_charpos
7157 && IT_CHARPOS (*it
) < to_charpos
)))))
7159 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7161 result
= MOVE_POS_MATCH_OR_ZV
;
7164 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7165 /* If wrap_it is valid, the current position might be in a
7166 word that is wrapped. So, save the iterator in
7167 atpos_it and continue to see if wrapping happens. */
7171 prev_method
= it
->method
;
7172 if (it
->method
== GET_FROM_BUFFER
)
7173 prev_pos
= IT_CHARPOS (*it
);
7174 /* Stop when ZV reached.
7175 We used to stop here when TO_CHARPOS reached as well, but that is
7176 too soon if this glyph does not fit on this line. So we handle it
7177 explicitly below. */
7178 if (!get_next_display_element (it
))
7180 result
= MOVE_POS_MATCH_OR_ZV
;
7184 if (it
->line_wrap
== TRUNCATE
)
7186 if (BUFFER_POS_REACHED_P ())
7188 result
= MOVE_POS_MATCH_OR_ZV
;
7194 if (it
->line_wrap
== WORD_WRAP
)
7196 if (IT_DISPLAYING_WHITESPACE (it
))
7200 /* We have reached a glyph that follows one or more
7201 whitespace characters. If the position is
7202 already found, we are done. */
7203 if (atpos_it
.sp
>= 0)
7206 result
= MOVE_POS_MATCH_OR_ZV
;
7212 result
= MOVE_X_REACHED
;
7215 /* Otherwise, we can wrap here. */
7222 /* Remember the line height for the current line, in case
7223 the next element doesn't fit on the line. */
7224 ascent
= it
->max_ascent
;
7225 descent
= it
->max_descent
;
7227 /* The call to produce_glyphs will get the metrics of the
7228 display element IT is loaded with. Record the x-position
7229 before this display element, in case it doesn't fit on the
7233 PRODUCE_GLYPHS (it
);
7235 if (it
->area
!= TEXT_AREA
)
7237 set_iterator_to_next (it
, 1);
7241 /* The number of glyphs we get back in IT->nglyphs will normally
7242 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7243 character on a terminal frame, or (iii) a line end. For the
7244 second case, IT->nglyphs - 1 padding glyphs will be present.
7245 (On X frames, there is only one glyph produced for a
7246 composite character.)
7248 The behavior implemented below means, for continuation lines,
7249 that as many spaces of a TAB as fit on the current line are
7250 displayed there. For terminal frames, as many glyphs of a
7251 multi-glyph character are displayed in the current line, too.
7252 This is what the old redisplay code did, and we keep it that
7253 way. Under X, the whole shape of a complex character must
7254 fit on the line or it will be completely displayed in the
7257 Note that both for tabs and padding glyphs, all glyphs have
7261 /* More than one glyph or glyph doesn't fit on line. All
7262 glyphs have the same width. */
7263 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7265 int x_before_this_char
= x
;
7266 int hpos_before_this_char
= it
->hpos
;
7268 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7270 new_x
= x
+ single_glyph_width
;
7272 /* We want to leave anything reaching TO_X to the caller. */
7273 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7275 if (BUFFER_POS_REACHED_P ())
7277 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7278 goto buffer_pos_reached
;
7279 if (atpos_it
.sp
< 0)
7282 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7287 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7290 result
= MOVE_X_REACHED
;
7296 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7301 if (/* Lines are continued. */
7302 it
->line_wrap
!= TRUNCATE
7303 && (/* And glyph doesn't fit on the line. */
7304 new_x
> it
->last_visible_x
7305 /* Or it fits exactly and we're on a window
7307 || (new_x
== it
->last_visible_x
7308 && FRAME_WINDOW_P (it
->f
))))
7310 if (/* IT->hpos == 0 means the very first glyph
7311 doesn't fit on the line, e.g. a wide image. */
7313 || (new_x
== it
->last_visible_x
7314 && FRAME_WINDOW_P (it
->f
)))
7317 it
->current_x
= new_x
;
7319 /* The character's last glyph just barely fits
7321 if (i
== it
->nglyphs
- 1)
7323 /* If this is the destination position,
7324 return a position *before* it in this row,
7325 now that we know it fits in this row. */
7326 if (BUFFER_POS_REACHED_P ())
7328 if (it
->line_wrap
!= WORD_WRAP
7331 it
->hpos
= hpos_before_this_char
;
7332 it
->current_x
= x_before_this_char
;
7333 result
= MOVE_POS_MATCH_OR_ZV
;
7336 if (it
->line_wrap
== WORD_WRAP
7340 atpos_it
.current_x
= x_before_this_char
;
7341 atpos_it
.hpos
= hpos_before_this_char
;
7345 set_iterator_to_next (it
, 1);
7346 /* On graphical terminals, newlines may
7347 "overflow" into the fringe if
7348 overflow-newline-into-fringe is non-nil.
7349 On text-only terminals, newlines may
7350 overflow into the last glyph on the
7352 if (!FRAME_WINDOW_P (it
->f
)
7353 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7355 if (!get_next_display_element (it
))
7357 result
= MOVE_POS_MATCH_OR_ZV
;
7360 if (BUFFER_POS_REACHED_P ())
7362 if (ITERATOR_AT_END_OF_LINE_P (it
))
7363 result
= MOVE_POS_MATCH_OR_ZV
;
7365 result
= MOVE_LINE_CONTINUED
;
7368 if (ITERATOR_AT_END_OF_LINE_P (it
))
7370 result
= MOVE_NEWLINE_OR_CR
;
7377 IT_RESET_X_ASCENT_DESCENT (it
);
7379 if (wrap_it
.sp
>= 0)
7386 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7388 result
= MOVE_LINE_CONTINUED
;
7392 if (BUFFER_POS_REACHED_P ())
7394 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7395 goto buffer_pos_reached
;
7396 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7399 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7403 if (new_x
> it
->first_visible_x
)
7405 /* Glyph is visible. Increment number of glyphs that
7406 would be displayed. */
7411 if (result
!= MOVE_UNDEFINED
)
7414 else if (BUFFER_POS_REACHED_P ())
7417 IT_RESET_X_ASCENT_DESCENT (it
);
7418 result
= MOVE_POS_MATCH_OR_ZV
;
7421 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7423 /* Stop when TO_X specified and reached. This check is
7424 necessary here because of lines consisting of a line end,
7425 only. The line end will not produce any glyphs and we
7426 would never get MOVE_X_REACHED. */
7427 xassert (it
->nglyphs
== 0);
7428 result
= MOVE_X_REACHED
;
7432 /* Is this a line end? If yes, we're done. */
7433 if (ITERATOR_AT_END_OF_LINE_P (it
))
7435 result
= MOVE_NEWLINE_OR_CR
;
7439 if (it
->method
== GET_FROM_BUFFER
)
7440 prev_pos
= IT_CHARPOS (*it
);
7441 /* The current display element has been consumed. Advance
7443 set_iterator_to_next (it
, 1);
7445 /* Stop if lines are truncated and IT's current x-position is
7446 past the right edge of the window now. */
7447 if (it
->line_wrap
== TRUNCATE
7448 && it
->current_x
>= it
->last_visible_x
)
7450 if (!FRAME_WINDOW_P (it
->f
)
7451 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7453 if (!get_next_display_element (it
)
7454 || BUFFER_POS_REACHED_P ())
7456 result
= MOVE_POS_MATCH_OR_ZV
;
7459 if (ITERATOR_AT_END_OF_LINE_P (it
))
7461 result
= MOVE_NEWLINE_OR_CR
;
7465 result
= MOVE_LINE_TRUNCATED
;
7468 #undef IT_RESET_X_ASCENT_DESCENT
7471 #undef BUFFER_POS_REACHED_P
7473 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7474 restore the saved iterator. */
7475 if (atpos_it
.sp
>= 0)
7477 else if (atx_it
.sp
>= 0)
7482 /* Restore the iterator settings altered at the beginning of this
7484 it
->glyph_row
= saved_glyph_row
;
7488 /* For external use. */
7490 move_it_in_display_line (struct it
*it
,
7491 EMACS_INT to_charpos
, int to_x
,
7492 enum move_operation_enum op
)
7494 if (it
->line_wrap
== WORD_WRAP
7495 && (op
& MOVE_TO_X
))
7497 struct it save_it
= *it
;
7498 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7499 /* When word-wrap is on, TO_X may lie past the end
7500 of a wrapped line. Then it->current is the
7501 character on the next line, so backtrack to the
7502 space before the wrap point. */
7503 if (skip
== MOVE_LINE_CONTINUED
)
7505 int prev_x
= max (it
->current_x
- 1, 0);
7507 move_it_in_display_line_to
7508 (it
, -1, prev_x
, MOVE_TO_X
);
7512 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7516 /* Move IT forward until it satisfies one or more of the criteria in
7517 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7519 OP is a bit-mask that specifies where to stop, and in particular,
7520 which of those four position arguments makes a difference. See the
7521 description of enum move_operation_enum.
7523 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7524 screen line, this function will set IT to the next position >
7528 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7530 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7531 int line_height
, line_start_x
= 0, reached
= 0;
7535 if (op
& MOVE_TO_VPOS
)
7537 /* If no TO_CHARPOS and no TO_X specified, stop at the
7538 start of the line TO_VPOS. */
7539 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7541 if (it
->vpos
== to_vpos
)
7547 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7551 /* TO_VPOS >= 0 means stop at TO_X in the line at
7552 TO_VPOS, or at TO_POS, whichever comes first. */
7553 if (it
->vpos
== to_vpos
)
7559 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7561 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7566 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7568 /* We have reached TO_X but not in the line we want. */
7569 skip
= move_it_in_display_line_to (it
, to_charpos
,
7571 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7579 else if (op
& MOVE_TO_Y
)
7581 struct it it_backup
;
7583 if (it
->line_wrap
== WORD_WRAP
)
7586 /* TO_Y specified means stop at TO_X in the line containing
7587 TO_Y---or at TO_CHARPOS if this is reached first. The
7588 problem is that we can't really tell whether the line
7589 contains TO_Y before we have completely scanned it, and
7590 this may skip past TO_X. What we do is to first scan to
7593 If TO_X is not specified, use a TO_X of zero. The reason
7594 is to make the outcome of this function more predictable.
7595 If we didn't use TO_X == 0, we would stop at the end of
7596 the line which is probably not what a caller would expect
7598 skip
= move_it_in_display_line_to
7599 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7600 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7602 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7603 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7605 else if (skip
== MOVE_X_REACHED
)
7607 /* If TO_X was reached, we want to know whether TO_Y is
7608 in the line. We know this is the case if the already
7609 scanned glyphs make the line tall enough. Otherwise,
7610 we must check by scanning the rest of the line. */
7611 line_height
= it
->max_ascent
+ it
->max_descent
;
7612 if (to_y
>= it
->current_y
7613 && to_y
< it
->current_y
+ line_height
)
7619 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7620 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7622 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7623 line_height
= it
->max_ascent
+ it
->max_descent
;
7624 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7626 if (to_y
>= it
->current_y
7627 && to_y
< it
->current_y
+ line_height
)
7629 /* If TO_Y is in this line and TO_X was reached
7630 above, we scanned too far. We have to restore
7631 IT's settings to the ones before skipping. */
7638 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7644 /* Check whether TO_Y is in this line. */
7645 line_height
= it
->max_ascent
+ it
->max_descent
;
7646 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7648 if (to_y
>= it
->current_y
7649 && to_y
< it
->current_y
+ line_height
)
7651 /* When word-wrap is on, TO_X may lie past the end
7652 of a wrapped line. Then it->current is the
7653 character on the next line, so backtrack to the
7654 space before the wrap point. */
7655 if (skip
== MOVE_LINE_CONTINUED
7656 && it
->line_wrap
== WORD_WRAP
)
7658 int prev_x
= max (it
->current_x
- 1, 0);
7660 skip
= move_it_in_display_line_to
7661 (it
, -1, prev_x
, MOVE_TO_X
);
7670 else if (BUFFERP (it
->object
)
7671 && (it
->method
== GET_FROM_BUFFER
7672 || it
->method
== GET_FROM_STRETCH
)
7673 && IT_CHARPOS (*it
) >= to_charpos
)
7674 skip
= MOVE_POS_MATCH_OR_ZV
;
7676 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7680 case MOVE_POS_MATCH_OR_ZV
:
7684 case MOVE_NEWLINE_OR_CR
:
7685 set_iterator_to_next (it
, 1);
7686 it
->continuation_lines_width
= 0;
7689 case MOVE_LINE_TRUNCATED
:
7690 it
->continuation_lines_width
= 0;
7691 reseat_at_next_visible_line_start (it
, 0);
7692 if ((op
& MOVE_TO_POS
) != 0
7693 && IT_CHARPOS (*it
) > to_charpos
)
7700 case MOVE_LINE_CONTINUED
:
7701 /* For continued lines ending in a tab, some of the glyphs
7702 associated with the tab are displayed on the current
7703 line. Since it->current_x does not include these glyphs,
7704 we use it->last_visible_x instead. */
7707 it
->continuation_lines_width
+= it
->last_visible_x
;
7708 /* When moving by vpos, ensure that the iterator really
7709 advances to the next line (bug#847, bug#969). Fixme:
7710 do we need to do this in other circumstances? */
7711 if (it
->current_x
!= it
->last_visible_x
7712 && (op
& MOVE_TO_VPOS
)
7713 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7715 line_start_x
= it
->current_x
+ it
->pixel_width
7716 - it
->last_visible_x
;
7717 set_iterator_to_next (it
, 0);
7721 it
->continuation_lines_width
+= it
->current_x
;
7728 /* Reset/increment for the next run. */
7729 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7730 it
->current_x
= line_start_x
;
7733 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7735 last_height
= it
->max_ascent
+ it
->max_descent
;
7736 last_max_ascent
= it
->max_ascent
;
7737 it
->max_ascent
= it
->max_descent
= 0;
7742 /* On text terminals, we may stop at the end of a line in the middle
7743 of a multi-character glyph. If the glyph itself is continued,
7744 i.e. it is actually displayed on the next line, don't treat this
7745 stopping point as valid; move to the next line instead (unless
7746 that brings us offscreen). */
7747 if (!FRAME_WINDOW_P (it
->f
)
7749 && IT_CHARPOS (*it
) == to_charpos
7750 && it
->what
== IT_CHARACTER
7752 && it
->line_wrap
== WINDOW_WRAP
7753 && it
->current_x
== it
->last_visible_x
- 1
7756 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7758 it
->continuation_lines_width
+= it
->current_x
;
7759 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7760 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7762 last_height
= it
->max_ascent
+ it
->max_descent
;
7763 last_max_ascent
= it
->max_ascent
;
7766 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7770 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7772 If DY > 0, move IT backward at least that many pixels. DY = 0
7773 means move IT backward to the preceding line start or BEGV. This
7774 function may move over more than DY pixels if IT->current_y - DY
7775 ends up in the middle of a line; in this case IT->current_y will be
7776 set to the top of the line moved to. */
7779 move_it_vertically_backward (struct it
*it
, int dy
)
7783 EMACS_INT start_pos
;
7788 start_pos
= IT_CHARPOS (*it
);
7790 /* Estimate how many newlines we must move back. */
7791 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7793 /* Set the iterator's position that many lines back. */
7794 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7795 back_to_previous_visible_line_start (it
);
7797 /* Reseat the iterator here. When moving backward, we don't want
7798 reseat to skip forward over invisible text, set up the iterator
7799 to deliver from overlay strings at the new position etc. So,
7800 use reseat_1 here. */
7801 reseat_1 (it
, it
->current
.pos
, 1);
7803 /* We are now surely at a line start. */
7804 it
->current_x
= it
->hpos
= 0;
7805 it
->continuation_lines_width
= 0;
7807 /* Move forward and see what y-distance we moved. First move to the
7808 start of the next line so that we get its height. We need this
7809 height to be able to tell whether we reached the specified
7812 it2
.max_ascent
= it2
.max_descent
= 0;
7815 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7816 MOVE_TO_POS
| MOVE_TO_VPOS
);
7818 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7819 xassert (IT_CHARPOS (*it
) >= BEGV
);
7822 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7823 xassert (IT_CHARPOS (*it
) >= BEGV
);
7824 /* H is the actual vertical distance from the position in *IT
7825 and the starting position. */
7826 h
= it2
.current_y
- it
->current_y
;
7827 /* NLINES is the distance in number of lines. */
7828 nlines
= it2
.vpos
- it
->vpos
;
7830 /* Correct IT's y and vpos position
7831 so that they are relative to the starting point. */
7837 /* DY == 0 means move to the start of the screen line. The
7838 value of nlines is > 0 if continuation lines were involved. */
7840 move_it_by_lines (it
, nlines
, 1);
7844 /* The y-position we try to reach, relative to *IT.
7845 Note that H has been subtracted in front of the if-statement. */
7846 int target_y
= it
->current_y
+ h
- dy
;
7847 int y0
= it3
.current_y
;
7848 int y1
= line_bottom_y (&it3
);
7849 int line_height
= y1
- y0
;
7851 /* If we did not reach target_y, try to move further backward if
7852 we can. If we moved too far backward, try to move forward. */
7853 if (target_y
< it
->current_y
7854 /* This is heuristic. In a window that's 3 lines high, with
7855 a line height of 13 pixels each, recentering with point
7856 on the bottom line will try to move -39/2 = 19 pixels
7857 backward. Try to avoid moving into the first line. */
7858 && (it
->current_y
- target_y
7859 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7860 && IT_CHARPOS (*it
) > BEGV
)
7862 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7863 target_y
- it
->current_y
));
7864 dy
= it
->current_y
- target_y
;
7865 goto move_further_back
;
7867 else if (target_y
>= it
->current_y
+ line_height
7868 && IT_CHARPOS (*it
) < ZV
)
7870 /* Should move forward by at least one line, maybe more.
7872 Note: Calling move_it_by_lines can be expensive on
7873 terminal frames, where compute_motion is used (via
7874 vmotion) to do the job, when there are very long lines
7875 and truncate-lines is nil. That's the reason for
7876 treating terminal frames specially here. */
7878 if (!FRAME_WINDOW_P (it
->f
))
7879 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7884 move_it_by_lines (it
, 1, 1);
7886 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7893 /* Move IT by a specified amount of pixel lines DY. DY negative means
7894 move backwards. DY = 0 means move to start of screen line. At the
7895 end, IT will be on the start of a screen line. */
7898 move_it_vertically (struct it
*it
, int dy
)
7901 move_it_vertically_backward (it
, -dy
);
7904 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7905 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7906 MOVE_TO_POS
| MOVE_TO_Y
);
7907 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7909 /* If buffer ends in ZV without a newline, move to the start of
7910 the line to satisfy the post-condition. */
7911 if (IT_CHARPOS (*it
) == ZV
7913 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7914 move_it_by_lines (it
, 0, 0);
7919 /* Move iterator IT past the end of the text line it is in. */
7922 move_it_past_eol (struct it
*it
)
7924 enum move_it_result rc
;
7926 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7927 if (rc
== MOVE_NEWLINE_OR_CR
)
7928 set_iterator_to_next (it
, 0);
7932 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7933 negative means move up. DVPOS == 0 means move to the start of the
7934 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7935 NEED_Y_P is zero, IT->current_y will be left unchanged.
7937 Further optimization ideas: If we would know that IT->f doesn't use
7938 a face with proportional font, we could be faster for
7939 truncate-lines nil. */
7942 move_it_by_lines (struct it
*it
, int dvpos
, int need_y_p
)
7945 /* The commented-out optimization uses vmotion on terminals. This
7946 gives bad results, because elements like it->what, on which
7947 callers such as pos_visible_p rely, aren't updated. */
7948 /* struct position pos;
7949 if (!FRAME_WINDOW_P (it->f))
7951 struct text_pos textpos;
7953 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7954 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7955 reseat (it, textpos, 1);
7956 it->vpos += pos.vpos;
7957 it->current_y += pos.vpos;
7963 /* DVPOS == 0 means move to the start of the screen line. */
7964 move_it_vertically_backward (it
, 0);
7965 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7966 /* Let next call to line_bottom_y calculate real line height */
7971 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7972 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7973 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7978 EMACS_INT start_charpos
, i
;
7980 /* Start at the beginning of the screen line containing IT's
7981 position. This may actually move vertically backwards,
7982 in case of overlays, so adjust dvpos accordingly. */
7984 move_it_vertically_backward (it
, 0);
7987 /* Go back -DVPOS visible lines and reseat the iterator there. */
7988 start_charpos
= IT_CHARPOS (*it
);
7989 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7990 back_to_previous_visible_line_start (it
);
7991 reseat (it
, it
->current
.pos
, 1);
7993 /* Move further back if we end up in a string or an image. */
7994 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7996 /* First try to move to start of display line. */
7998 move_it_vertically_backward (it
, 0);
8000 if (IT_POS_VALID_AFTER_MOVE_P (it
))
8002 /* If start of line is still in string or image,
8003 move further back. */
8004 back_to_previous_visible_line_start (it
);
8005 reseat (it
, it
->current
.pos
, 1);
8009 it
->current_x
= it
->hpos
= 0;
8011 /* Above call may have moved too far if continuation lines
8012 are involved. Scan forward and see if it did. */
8014 it2
.vpos
= it2
.current_y
= 0;
8015 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
8016 it
->vpos
-= it2
.vpos
;
8017 it
->current_y
-= it2
.current_y
;
8018 it
->current_x
= it
->hpos
= 0;
8020 /* If we moved too far back, move IT some lines forward. */
8021 if (it2
.vpos
> -dvpos
)
8023 int delta
= it2
.vpos
+ dvpos
;
8025 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
8026 /* Move back again if we got too far ahead. */
8027 if (IT_CHARPOS (*it
) >= start_charpos
)
8033 /* Return 1 if IT points into the middle of a display vector. */
8036 in_display_vector_p (struct it
*it
)
8038 return (it
->method
== GET_FROM_DISPLAY_VECTOR
8039 && it
->current
.dpvec_index
> 0
8040 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
8044 /***********************************************************************
8046 ***********************************************************************/
8049 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
8053 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
8055 Lisp_Object args
[3];
8056 Lisp_Object msg
, fmt
;
8059 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8062 /* Do nothing if called asynchronously. Inserting text into
8063 a buffer may call after-change-functions and alike and
8064 that would means running Lisp asynchronously. */
8065 if (handling_signal
)
8069 GCPRO4 (fmt
, msg
, arg1
, arg2
);
8071 args
[0] = fmt
= build_string (format
);
8074 msg
= Fformat (3, args
);
8076 len
= SBYTES (msg
) + 1;
8077 SAFE_ALLOCA (buffer
, char *, len
);
8078 memcpy (buffer
, SDATA (msg
), len
);
8080 message_dolog (buffer
, len
- 1, 1, 0);
8087 /* Output a newline in the *Messages* buffer if "needs" one. */
8090 message_log_maybe_newline (void)
8092 if (message_log_need_newline
)
8093 message_dolog ("", 0, 1, 0);
8097 /* Add a string M of length NBYTES to the message log, optionally
8098 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8099 nonzero, means interpret the contents of M as multibyte. This
8100 function calls low-level routines in order to bypass text property
8101 hooks, etc. which might not be safe to run.
8103 This may GC (insert may run before/after change hooks),
8104 so the buffer M must NOT point to a Lisp string. */
8107 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
8109 if (!NILP (Vmemory_full
))
8112 if (!NILP (Vmessage_log_max
))
8114 struct buffer
*oldbuf
;
8115 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8116 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8117 EMACS_INT point_at_end
= 0;
8118 EMACS_INT zv_at_end
= 0;
8119 Lisp_Object old_deactivate_mark
, tem
;
8120 struct gcpro gcpro1
;
8122 old_deactivate_mark
= Vdeactivate_mark
;
8123 oldbuf
= current_buffer
;
8124 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8125 current_buffer
->undo_list
= Qt
;
8127 oldpoint
= message_dolog_marker1
;
8128 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8129 oldbegv
= message_dolog_marker2
;
8130 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8131 oldzv
= message_dolog_marker3
;
8132 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8133 GCPRO1 (old_deactivate_mark
);
8141 BEGV_BYTE
= BEG_BYTE
;
8144 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8146 /* Insert the string--maybe converting multibyte to single byte
8147 or vice versa, so that all the text fits the buffer. */
8149 && NILP (current_buffer
->enable_multibyte_characters
))
8153 unsigned char work
[1];
8155 /* Convert a multibyte string to single-byte
8156 for the *Message* buffer. */
8157 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8159 c
= string_char_and_length (m
+ i
, &char_bytes
);
8160 work
[0] = (ASCII_CHAR_P (c
)
8162 : multibyte_char_to_unibyte (c
, Qnil
));
8163 insert_1_both (work
, 1, 1, 1, 0, 0);
8166 else if (! multibyte
8167 && ! NILP (current_buffer
->enable_multibyte_characters
))
8171 unsigned char *msg
= (unsigned char *) m
;
8172 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8173 /* Convert a single-byte string to multibyte
8174 for the *Message* buffer. */
8175 for (i
= 0; i
< nbytes
; i
++)
8178 MAKE_CHAR_MULTIBYTE (c
);
8179 char_bytes
= CHAR_STRING (c
, str
);
8180 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
8184 insert_1 (m
, nbytes
, 1, 0, 0);
8188 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8190 insert_1 ("\n", 1, 1, 0, 0);
8192 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8194 this_bol_byte
= PT_BYTE
;
8196 /* See if this line duplicates the previous one.
8197 If so, combine duplicates. */
8200 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8202 prev_bol_byte
= PT_BYTE
;
8204 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
8205 this_bol
, this_bol_byte
);
8208 del_range_both (prev_bol
, prev_bol_byte
,
8209 this_bol
, this_bol_byte
, 0);
8215 /* If you change this format, don't forget to also
8216 change message_log_check_duplicate. */
8217 sprintf (dupstr
, " [%d times]", dup
);
8218 duplen
= strlen (dupstr
);
8219 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8220 insert_1 (dupstr
, duplen
, 1, 0, 1);
8225 /* If we have more than the desired maximum number of lines
8226 in the *Messages* buffer now, delete the oldest ones.
8227 This is safe because we don't have undo in this buffer. */
8229 if (NATNUMP (Vmessage_log_max
))
8231 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8232 -XFASTINT (Vmessage_log_max
) - 1, 0);
8233 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8236 BEGV
= XMARKER (oldbegv
)->charpos
;
8237 BEGV_BYTE
= marker_byte_position (oldbegv
);
8246 ZV
= XMARKER (oldzv
)->charpos
;
8247 ZV_BYTE
= marker_byte_position (oldzv
);
8251 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8253 /* We can't do Fgoto_char (oldpoint) because it will run some
8255 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8256 XMARKER (oldpoint
)->bytepos
);
8259 unchain_marker (XMARKER (oldpoint
));
8260 unchain_marker (XMARKER (oldbegv
));
8261 unchain_marker (XMARKER (oldzv
));
8263 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8264 set_buffer_internal (oldbuf
);
8266 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8267 message_log_need_newline
= !nlflag
;
8268 Vdeactivate_mark
= old_deactivate_mark
;
8273 /* We are at the end of the buffer after just having inserted a newline.
8274 (Note: We depend on the fact we won't be crossing the gap.)
8275 Check to see if the most recent message looks a lot like the previous one.
8276 Return 0 if different, 1 if the new one should just replace it, or a
8277 value N > 1 if we should also append " [N times]". */
8280 message_log_check_duplicate (EMACS_INT prev_bol
, EMACS_INT prev_bol_byte
,
8281 EMACS_INT this_bol
, EMACS_INT this_bol_byte
)
8284 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8286 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8287 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8289 for (i
= 0; i
< len
; i
++)
8291 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8299 if (*p1
++ == ' ' && *p1
++ == '[')
8302 while (*p1
>= '0' && *p1
<= '9')
8303 n
= n
* 10 + *p1
++ - '0';
8304 if (strncmp (p1
, " times]\n", 8) == 0)
8311 /* Display an echo area message M with a specified length of NBYTES
8312 bytes. The string may include null characters. If M is 0, clear
8313 out any existing message, and let the mini-buffer text show
8316 This may GC, so the buffer M must NOT point to a Lisp string. */
8319 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8321 /* First flush out any partial line written with print. */
8322 message_log_maybe_newline ();
8324 message_dolog (m
, nbytes
, 1, multibyte
);
8325 message2_nolog (m
, nbytes
, multibyte
);
8329 /* The non-logging counterpart of message2. */
8332 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8334 struct frame
*sf
= SELECTED_FRAME ();
8335 message_enable_multibyte
= multibyte
;
8337 if (FRAME_INITIAL_P (sf
))
8339 if (noninteractive_need_newline
)
8340 putc ('\n', stderr
);
8341 noninteractive_need_newline
= 0;
8343 fwrite (m
, nbytes
, 1, stderr
);
8344 if (cursor_in_echo_area
== 0)
8345 fprintf (stderr
, "\n");
8348 /* A null message buffer means that the frame hasn't really been
8349 initialized yet. Error messages get reported properly by
8350 cmd_error, so this must be just an informative message; toss it. */
8351 else if (INTERACTIVE
8352 && sf
->glyphs_initialized_p
8353 && FRAME_MESSAGE_BUF (sf
))
8355 Lisp_Object mini_window
;
8358 /* Get the frame containing the mini-buffer
8359 that the selected frame is using. */
8360 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8361 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8363 FRAME_SAMPLE_VISIBILITY (f
);
8364 if (FRAME_VISIBLE_P (sf
)
8365 && ! FRAME_VISIBLE_P (f
))
8366 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8370 set_message (m
, Qnil
, nbytes
, multibyte
);
8371 if (minibuffer_auto_raise
)
8372 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8375 clear_message (1, 1);
8377 do_pending_window_change (0);
8378 echo_area_display (1);
8379 do_pending_window_change (0);
8380 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8381 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8386 /* Display an echo area message M with a specified length of NBYTES
8387 bytes. The string may include null characters. If M is not a
8388 string, clear out any existing message, and let the mini-buffer
8391 This function cancels echoing. */
8394 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8396 struct gcpro gcpro1
;
8399 clear_message (1,1);
8402 /* First flush out any partial line written with print. */
8403 message_log_maybe_newline ();
8409 SAFE_ALLOCA (buffer
, char *, nbytes
);
8410 memcpy (buffer
, SDATA (m
), nbytes
);
8411 message_dolog (buffer
, nbytes
, 1, multibyte
);
8414 message3_nolog (m
, nbytes
, multibyte
);
8420 /* The non-logging version of message3.
8421 This does not cancel echoing, because it is used for echoing.
8422 Perhaps we need to make a separate function for echoing
8423 and make this cancel echoing. */
8426 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8428 struct frame
*sf
= SELECTED_FRAME ();
8429 message_enable_multibyte
= multibyte
;
8431 if (FRAME_INITIAL_P (sf
))
8433 if (noninteractive_need_newline
)
8434 putc ('\n', stderr
);
8435 noninteractive_need_newline
= 0;
8437 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8438 if (cursor_in_echo_area
== 0)
8439 fprintf (stderr
, "\n");
8442 /* A null message buffer means that the frame hasn't really been
8443 initialized yet. Error messages get reported properly by
8444 cmd_error, so this must be just an informative message; toss it. */
8445 else if (INTERACTIVE
8446 && sf
->glyphs_initialized_p
8447 && FRAME_MESSAGE_BUF (sf
))
8449 Lisp_Object mini_window
;
8453 /* Get the frame containing the mini-buffer
8454 that the selected frame is using. */
8455 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8456 frame
= XWINDOW (mini_window
)->frame
;
8459 FRAME_SAMPLE_VISIBILITY (f
);
8460 if (FRAME_VISIBLE_P (sf
)
8461 && !FRAME_VISIBLE_P (f
))
8462 Fmake_frame_visible (frame
);
8464 if (STRINGP (m
) && SCHARS (m
) > 0)
8466 set_message (NULL
, m
, nbytes
, multibyte
);
8467 if (minibuffer_auto_raise
)
8468 Fraise_frame (frame
);
8469 /* Assume we are not echoing.
8470 (If we are, echo_now will override this.) */
8471 echo_message_buffer
= Qnil
;
8474 clear_message (1, 1);
8476 do_pending_window_change (0);
8477 echo_area_display (1);
8478 do_pending_window_change (0);
8479 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8480 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8485 /* Display a null-terminated echo area message M. If M is 0, clear
8486 out any existing message, and let the mini-buffer text show through.
8488 The buffer M must continue to exist until after the echo area gets
8489 cleared or some other message gets displayed there. Do not pass
8490 text that is stored in a Lisp string. Do not pass text in a buffer
8491 that was alloca'd. */
8494 message1 (const char *m
)
8496 message2 (m
, (m
? strlen (m
) : 0), 0);
8500 /* The non-logging counterpart of message1. */
8503 message1_nolog (const char *m
)
8505 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8508 /* Display a message M which contains a single %s
8509 which gets replaced with STRING. */
8512 message_with_string (const char *m
, Lisp_Object string
, int log
)
8514 CHECK_STRING (string
);
8520 if (noninteractive_need_newline
)
8521 putc ('\n', stderr
);
8522 noninteractive_need_newline
= 0;
8523 fprintf (stderr
, m
, SDATA (string
));
8524 if (!cursor_in_echo_area
)
8525 fprintf (stderr
, "\n");
8529 else if (INTERACTIVE
)
8531 /* The frame whose minibuffer we're going to display the message on.
8532 It may be larger than the selected frame, so we need
8533 to use its buffer, not the selected frame's buffer. */
8534 Lisp_Object mini_window
;
8535 struct frame
*f
, *sf
= SELECTED_FRAME ();
8537 /* Get the frame containing the minibuffer
8538 that the selected frame is using. */
8539 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8540 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8542 /* A null message buffer means that the frame hasn't really been
8543 initialized yet. Error messages get reported properly by
8544 cmd_error, so this must be just an informative message; toss it. */
8545 if (FRAME_MESSAGE_BUF (f
))
8547 Lisp_Object args
[2], message
;
8548 struct gcpro gcpro1
, gcpro2
;
8550 args
[0] = build_string (m
);
8551 args
[1] = message
= string
;
8552 GCPRO2 (args
[0], message
);
8555 message
= Fformat (2, args
);
8558 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8560 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8564 /* Print should start at the beginning of the message
8565 buffer next time. */
8566 message_buf_print
= 0;
8572 /* Dump an informative message to the minibuf. If M is 0, clear out
8573 any existing message, and let the mini-buffer text show through. */
8576 vmessage (const char *m
, va_list ap
)
8582 if (noninteractive_need_newline
)
8583 putc ('\n', stderr
);
8584 noninteractive_need_newline
= 0;
8585 vfprintf (stderr
, m
, ap
);
8586 if (cursor_in_echo_area
== 0)
8587 fprintf (stderr
, "\n");
8591 else if (INTERACTIVE
)
8593 /* The frame whose mini-buffer we're going to display the message
8594 on. It may be larger than the selected frame, so we need to
8595 use its buffer, not the selected frame's buffer. */
8596 Lisp_Object mini_window
;
8597 struct frame
*f
, *sf
= SELECTED_FRAME ();
8599 /* Get the frame containing the mini-buffer
8600 that the selected frame is using. */
8601 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8602 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8604 /* A null message buffer means that the frame hasn't really been
8605 initialized yet. Error messages get reported properly by
8606 cmd_error, so this must be just an informative message; toss
8608 if (FRAME_MESSAGE_BUF (f
))
8614 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8615 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
8617 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8622 /* Print should start at the beginning of the message
8623 buffer next time. */
8624 message_buf_print
= 0;
8630 message (const char *m
, ...)
8639 /* The non-logging version of message. */
8642 message_nolog (const char *m
, ...)
8644 Lisp_Object old_log_max
;
8647 old_log_max
= Vmessage_log_max
;
8648 Vmessage_log_max
= Qnil
;
8650 Vmessage_log_max
= old_log_max
;
8655 /* Display the current message in the current mini-buffer. This is
8656 only called from error handlers in process.c, and is not time
8660 update_echo_area (void)
8662 if (!NILP (echo_area_buffer
[0]))
8665 string
= Fcurrent_message ();
8666 message3 (string
, SBYTES (string
),
8667 !NILP (current_buffer
->enable_multibyte_characters
));
8672 /* Make sure echo area buffers in `echo_buffers' are live.
8673 If they aren't, make new ones. */
8676 ensure_echo_area_buffers (void)
8680 for (i
= 0; i
< 2; ++i
)
8681 if (!BUFFERP (echo_buffer
[i
])
8682 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8685 Lisp_Object old_buffer
;
8688 old_buffer
= echo_buffer
[i
];
8689 sprintf (name
, " *Echo Area %d*", i
);
8690 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8691 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8692 /* to force word wrap in echo area -
8693 it was decided to postpone this*/
8694 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8696 for (j
= 0; j
< 2; ++j
)
8697 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8698 echo_area_buffer
[j
] = echo_buffer
[i
];
8703 /* Call FN with args A1..A4 with either the current or last displayed
8704 echo_area_buffer as current buffer.
8706 WHICH zero means use the current message buffer
8707 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8708 from echo_buffer[] and clear it.
8710 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8711 suitable buffer from echo_buffer[] and clear it.
8713 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8714 that the current message becomes the last displayed one, make
8715 choose a suitable buffer for echo_area_buffer[0], and clear it.
8717 Value is what FN returns. */
8720 with_echo_area_buffer (struct window
*w
, int which
,
8721 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
8722 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8725 int this_one
, the_other
, clear_buffer_p
, rc
;
8726 int count
= SPECPDL_INDEX ();
8728 /* If buffers aren't live, make new ones. */
8729 ensure_echo_area_buffers ();
8734 this_one
= 0, the_other
= 1;
8736 this_one
= 1, the_other
= 0;
8739 this_one
= 0, the_other
= 1;
8742 /* We need a fresh one in case the current echo buffer equals
8743 the one containing the last displayed echo area message. */
8744 if (!NILP (echo_area_buffer
[this_one
])
8745 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8746 echo_area_buffer
[this_one
] = Qnil
;
8749 /* Choose a suitable buffer from echo_buffer[] is we don't
8751 if (NILP (echo_area_buffer
[this_one
]))
8753 echo_area_buffer
[this_one
]
8754 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8755 ? echo_buffer
[the_other
]
8756 : echo_buffer
[this_one
]);
8760 buffer
= echo_area_buffer
[this_one
];
8762 /* Don't get confused by reusing the buffer used for echoing
8763 for a different purpose. */
8764 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8767 record_unwind_protect (unwind_with_echo_area_buffer
,
8768 with_echo_area_buffer_unwind_data (w
));
8770 /* Make the echo area buffer current. Note that for display
8771 purposes, it is not necessary that the displayed window's buffer
8772 == current_buffer, except for text property lookup. So, let's
8773 only set that buffer temporarily here without doing a full
8774 Fset_window_buffer. We must also change w->pointm, though,
8775 because otherwise an assertions in unshow_buffer fails, and Emacs
8777 set_buffer_internal_1 (XBUFFER (buffer
));
8781 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8784 current_buffer
->undo_list
= Qt
;
8785 current_buffer
->read_only
= Qnil
;
8786 specbind (Qinhibit_read_only
, Qt
);
8787 specbind (Qinhibit_modification_hooks
, Qt
);
8789 if (clear_buffer_p
&& Z
> BEG
)
8792 xassert (BEGV
>= BEG
);
8793 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8795 rc
= fn (a1
, a2
, a3
, a4
);
8797 xassert (BEGV
>= BEG
);
8798 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8800 unbind_to (count
, Qnil
);
8805 /* Save state that should be preserved around the call to the function
8806 FN called in with_echo_area_buffer. */
8809 with_echo_area_buffer_unwind_data (struct window
*w
)
8812 Lisp_Object vector
, tmp
;
8814 /* Reduce consing by keeping one vector in
8815 Vwith_echo_area_save_vector. */
8816 vector
= Vwith_echo_area_save_vector
;
8817 Vwith_echo_area_save_vector
= Qnil
;
8820 vector
= Fmake_vector (make_number (7), Qnil
);
8822 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8823 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8824 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8828 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8829 ASET (vector
, i
, w
->buffer
); ++i
;
8830 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8831 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8836 for (; i
< end
; ++i
)
8837 ASET (vector
, i
, Qnil
);
8840 xassert (i
== ASIZE (vector
));
8845 /* Restore global state from VECTOR which was created by
8846 with_echo_area_buffer_unwind_data. */
8849 unwind_with_echo_area_buffer (Lisp_Object vector
)
8851 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8852 Vdeactivate_mark
= AREF (vector
, 1);
8853 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8855 if (WINDOWP (AREF (vector
, 3)))
8858 Lisp_Object buffer
, charpos
, bytepos
;
8860 w
= XWINDOW (AREF (vector
, 3));
8861 buffer
= AREF (vector
, 4);
8862 charpos
= AREF (vector
, 5);
8863 bytepos
= AREF (vector
, 6);
8866 set_marker_both (w
->pointm
, buffer
,
8867 XFASTINT (charpos
), XFASTINT (bytepos
));
8870 Vwith_echo_area_save_vector
= vector
;
8875 /* Set up the echo area for use by print functions. MULTIBYTE_P
8876 non-zero means we will print multibyte. */
8879 setup_echo_area_for_printing (int multibyte_p
)
8881 /* If we can't find an echo area any more, exit. */
8882 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8885 ensure_echo_area_buffers ();
8887 if (!message_buf_print
)
8889 /* A message has been output since the last time we printed.
8890 Choose a fresh echo area buffer. */
8891 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8892 echo_area_buffer
[0] = echo_buffer
[1];
8894 echo_area_buffer
[0] = echo_buffer
[0];
8896 /* Switch to that buffer and clear it. */
8897 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8898 current_buffer
->truncate_lines
= Qnil
;
8902 int count
= SPECPDL_INDEX ();
8903 specbind (Qinhibit_read_only
, Qt
);
8904 /* Note that undo recording is always disabled. */
8906 unbind_to (count
, Qnil
);
8908 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8910 /* Set up the buffer for the multibyteness we need. */
8912 != !NILP (current_buffer
->enable_multibyte_characters
))
8913 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8915 /* Raise the frame containing the echo area. */
8916 if (minibuffer_auto_raise
)
8918 struct frame
*sf
= SELECTED_FRAME ();
8919 Lisp_Object mini_window
;
8920 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8921 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8924 message_log_maybe_newline ();
8925 message_buf_print
= 1;
8929 if (NILP (echo_area_buffer
[0]))
8931 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8932 echo_area_buffer
[0] = echo_buffer
[1];
8934 echo_area_buffer
[0] = echo_buffer
[0];
8937 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8939 /* Someone switched buffers between print requests. */
8940 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8941 current_buffer
->truncate_lines
= Qnil
;
8947 /* Display an echo area message in window W. Value is non-zero if W's
8948 height is changed. If display_last_displayed_message_p is
8949 non-zero, display the message that was last displayed, otherwise
8950 display the current message. */
8953 display_echo_area (struct window
*w
)
8955 int i
, no_message_p
, window_height_changed_p
, count
;
8957 /* Temporarily disable garbage collections while displaying the echo
8958 area. This is done because a GC can print a message itself.
8959 That message would modify the echo area buffer's contents while a
8960 redisplay of the buffer is going on, and seriously confuse
8962 count
= inhibit_garbage_collection ();
8964 /* If there is no message, we must call display_echo_area_1
8965 nevertheless because it resizes the window. But we will have to
8966 reset the echo_area_buffer in question to nil at the end because
8967 with_echo_area_buffer will sets it to an empty buffer. */
8968 i
= display_last_displayed_message_p
? 1 : 0;
8969 no_message_p
= NILP (echo_area_buffer
[i
]);
8971 window_height_changed_p
8972 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8973 display_echo_area_1
,
8974 (EMACS_INT
) w
, Qnil
, 0, 0);
8977 echo_area_buffer
[i
] = Qnil
;
8979 unbind_to (count
, Qnil
);
8980 return window_height_changed_p
;
8984 /* Helper for display_echo_area. Display the current buffer which
8985 contains the current echo area message in window W, a mini-window,
8986 a pointer to which is passed in A1. A2..A4 are currently not used.
8987 Change the height of W so that all of the message is displayed.
8988 Value is non-zero if height of W was changed. */
8991 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8993 struct window
*w
= (struct window
*) a1
;
8995 struct text_pos start
;
8996 int window_height_changed_p
= 0;
8998 /* Do this before displaying, so that we have a large enough glyph
8999 matrix for the display. If we can't get enough space for the
9000 whole text, display the last N lines. That works by setting w->start. */
9001 window_height_changed_p
= resize_mini_window (w
, 0);
9003 /* Use the starting position chosen by resize_mini_window. */
9004 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9007 clear_glyph_matrix (w
->desired_matrix
);
9008 XSETWINDOW (window
, w
);
9009 try_window (window
, start
, 0);
9011 return window_height_changed_p
;
9015 /* Resize the echo area window to exactly the size needed for the
9016 currently displayed message, if there is one. If a mini-buffer
9017 is active, don't shrink it. */
9020 resize_echo_area_exactly (void)
9022 if (BUFFERP (echo_area_buffer
[0])
9023 && WINDOWP (echo_area_window
))
9025 struct window
*w
= XWINDOW (echo_area_window
);
9027 Lisp_Object resize_exactly
;
9029 if (minibuf_level
== 0)
9030 resize_exactly
= Qt
;
9032 resize_exactly
= Qnil
;
9034 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
9035 (EMACS_INT
) w
, resize_exactly
, 0, 0);
9038 ++windows_or_buffers_changed
;
9039 ++update_mode_lines
;
9040 redisplay_internal (0);
9046 /* Callback function for with_echo_area_buffer, when used from
9047 resize_echo_area_exactly. A1 contains a pointer to the window to
9048 resize, EXACTLY non-nil means resize the mini-window exactly to the
9049 size of the text displayed. A3 and A4 are not used. Value is what
9050 resize_mini_window returns. */
9053 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
9055 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
9059 /* Resize mini-window W to fit the size of its contents. EXACT_P
9060 means size the window exactly to the size needed. Otherwise, it's
9061 only enlarged until W's buffer is empty.
9063 Set W->start to the right place to begin display. If the whole
9064 contents fit, start at the beginning. Otherwise, start so as
9065 to make the end of the contents appear. This is particularly
9066 important for y-or-n-p, but seems desirable generally.
9068 Value is non-zero if the window height has been changed. */
9071 resize_mini_window (struct window
*w
, int exact_p
)
9073 struct frame
*f
= XFRAME (w
->frame
);
9074 int window_height_changed_p
= 0;
9076 xassert (MINI_WINDOW_P (w
));
9078 /* By default, start display at the beginning. */
9079 set_marker_both (w
->start
, w
->buffer
,
9080 BUF_BEGV (XBUFFER (w
->buffer
)),
9081 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9083 /* Don't resize windows while redisplaying a window; it would
9084 confuse redisplay functions when the size of the window they are
9085 displaying changes from under them. Such a resizing can happen,
9086 for instance, when which-func prints a long message while
9087 we are running fontification-functions. We're running these
9088 functions with safe_call which binds inhibit-redisplay to t. */
9089 if (!NILP (Vinhibit_redisplay
))
9092 /* Nil means don't try to resize. */
9093 if (NILP (Vresize_mini_windows
)
9094 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9097 if (!FRAME_MINIBUF_ONLY_P (f
))
9100 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9101 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9102 int height
, max_height
;
9103 int unit
= FRAME_LINE_HEIGHT (f
);
9104 struct text_pos start
;
9105 struct buffer
*old_current_buffer
= NULL
;
9107 if (current_buffer
!= XBUFFER (w
->buffer
))
9109 old_current_buffer
= current_buffer
;
9110 set_buffer_internal (XBUFFER (w
->buffer
));
9113 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9115 /* Compute the max. number of lines specified by the user. */
9116 if (FLOATP (Vmax_mini_window_height
))
9117 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9118 else if (INTEGERP (Vmax_mini_window_height
))
9119 max_height
= XINT (Vmax_mini_window_height
);
9121 max_height
= total_height
/ 4;
9123 /* Correct that max. height if it's bogus. */
9124 max_height
= max (1, max_height
);
9125 max_height
= min (total_height
, max_height
);
9127 /* Find out the height of the text in the window. */
9128 if (it
.line_wrap
== TRUNCATE
)
9133 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9134 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9135 height
= it
.current_y
+ last_height
;
9137 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9138 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9139 height
= (height
+ unit
- 1) / unit
;
9142 /* Compute a suitable window start. */
9143 if (height
> max_height
)
9145 height
= max_height
;
9146 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9147 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9148 start
= it
.current
.pos
;
9151 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9152 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9154 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9156 /* Let it grow only, until we display an empty message, in which
9157 case the window shrinks again. */
9158 if (height
> WINDOW_TOTAL_LINES (w
))
9160 int old_height
= WINDOW_TOTAL_LINES (w
);
9161 freeze_window_starts (f
, 1);
9162 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9163 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9165 else if (height
< WINDOW_TOTAL_LINES (w
)
9166 && (exact_p
|| BEGV
== ZV
))
9168 int old_height
= WINDOW_TOTAL_LINES (w
);
9169 freeze_window_starts (f
, 0);
9170 shrink_mini_window (w
);
9171 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9176 /* Always resize to exact size needed. */
9177 if (height
> WINDOW_TOTAL_LINES (w
))
9179 int old_height
= WINDOW_TOTAL_LINES (w
);
9180 freeze_window_starts (f
, 1);
9181 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9182 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9184 else if (height
< WINDOW_TOTAL_LINES (w
))
9186 int old_height
= WINDOW_TOTAL_LINES (w
);
9187 freeze_window_starts (f
, 0);
9188 shrink_mini_window (w
);
9192 freeze_window_starts (f
, 1);
9193 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9196 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9200 if (old_current_buffer
)
9201 set_buffer_internal (old_current_buffer
);
9204 return window_height_changed_p
;
9208 /* Value is the current message, a string, or nil if there is no
9212 current_message (void)
9216 if (!BUFFERP (echo_area_buffer
[0]))
9220 with_echo_area_buffer (0, 0, current_message_1
,
9221 (EMACS_INT
) &msg
, Qnil
, 0, 0);
9223 echo_area_buffer
[0] = Qnil
;
9231 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9233 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
9236 *msg
= make_buffer_string (BEG
, Z
, 1);
9243 /* Push the current message on Vmessage_stack for later restauration
9244 by restore_message. Value is non-zero if the current message isn't
9245 empty. This is a relatively infrequent operation, so it's not
9246 worth optimizing. */
9252 msg
= current_message ();
9253 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9254 return STRINGP (msg
);
9258 /* Restore message display from the top of Vmessage_stack. */
9261 restore_message (void)
9265 xassert (CONSP (Vmessage_stack
));
9266 msg
= XCAR (Vmessage_stack
);
9268 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9270 message3_nolog (msg
, 0, 0);
9274 /* Handler for record_unwind_protect calling pop_message. */
9277 pop_message_unwind (Lisp_Object dummy
)
9283 /* Pop the top-most entry off Vmessage_stack. */
9288 xassert (CONSP (Vmessage_stack
));
9289 Vmessage_stack
= XCDR (Vmessage_stack
);
9293 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9294 exits. If the stack is not empty, we have a missing pop_message
9298 check_message_stack (void)
9300 if (!NILP (Vmessage_stack
))
9305 /* Truncate to NCHARS what will be displayed in the echo area the next
9306 time we display it---but don't redisplay it now. */
9309 truncate_echo_area (EMACS_INT nchars
)
9312 echo_area_buffer
[0] = Qnil
;
9313 /* A null message buffer means that the frame hasn't really been
9314 initialized yet. Error messages get reported properly by
9315 cmd_error, so this must be just an informative message; toss it. */
9316 else if (!noninteractive
9318 && !NILP (echo_area_buffer
[0]))
9320 struct frame
*sf
= SELECTED_FRAME ();
9321 if (FRAME_MESSAGE_BUF (sf
))
9322 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9327 /* Helper function for truncate_echo_area. Truncate the current
9328 message to at most NCHARS characters. */
9331 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9333 if (BEG
+ nchars
< Z
)
9334 del_range (BEG
+ nchars
, Z
);
9336 echo_area_buffer
[0] = Qnil
;
9341 /* Set the current message to a substring of S or STRING.
9343 If STRING is a Lisp string, set the message to the first NBYTES
9344 bytes from STRING. NBYTES zero means use the whole string. If
9345 STRING is multibyte, the message will be displayed multibyte.
9347 If S is not null, set the message to the first LEN bytes of S. LEN
9348 zero means use the whole string. MULTIBYTE_P non-zero means S is
9349 multibyte. Display the message multibyte in that case.
9351 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9352 to t before calling set_message_1 (which calls insert).
9356 set_message (const char *s
, Lisp_Object string
,
9357 EMACS_INT nbytes
, int multibyte_p
)
9359 message_enable_multibyte
9360 = ((s
&& multibyte_p
)
9361 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9363 with_echo_area_buffer (0, -1, set_message_1
,
9364 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9365 message_buf_print
= 0;
9366 help_echo_showing_p
= 0;
9370 /* Helper function for set_message. Arguments have the same meaning
9371 as there, with A1 corresponding to S and A2 corresponding to STRING
9372 This function is called with the echo area buffer being
9376 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9378 const char *s
= (const char *) a1
;
9379 Lisp_Object string
= a2
;
9381 /* Change multibyteness of the echo buffer appropriately. */
9382 if (message_enable_multibyte
9383 != !NILP (current_buffer
->enable_multibyte_characters
))
9384 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9386 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9388 /* Insert new message at BEG. */
9389 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9391 if (STRINGP (string
))
9396 nbytes
= SBYTES (string
);
9397 nchars
= string_byte_to_char (string
, nbytes
);
9399 /* This function takes care of single/multibyte conversion. We
9400 just have to ensure that the echo area buffer has the right
9401 setting of enable_multibyte_characters. */
9402 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9407 nbytes
= strlen (s
);
9409 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9411 /* Convert from multi-byte to single-byte. */
9414 unsigned char work
[1];
9416 /* Convert a multibyte string to single-byte. */
9417 for (i
= 0; i
< nbytes
; i
+= n
)
9419 c
= string_char_and_length (s
+ i
, &n
);
9420 work
[0] = (ASCII_CHAR_P (c
)
9422 : multibyte_char_to_unibyte (c
, Qnil
));
9423 insert_1_both (work
, 1, 1, 1, 0, 0);
9426 else if (!multibyte_p
9427 && !NILP (current_buffer
->enable_multibyte_characters
))
9429 /* Convert from single-byte to multi-byte. */
9432 const unsigned char *msg
= (const unsigned char *) s
;
9433 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9435 /* Convert a single-byte string to multibyte. */
9436 for (i
= 0; i
< nbytes
; i
++)
9439 MAKE_CHAR_MULTIBYTE (c
);
9440 n
= CHAR_STRING (c
, str
);
9441 insert_1_both (str
, 1, n
, 1, 0, 0);
9445 insert_1 (s
, nbytes
, 1, 0, 0);
9452 /* Clear messages. CURRENT_P non-zero means clear the current
9453 message. LAST_DISPLAYED_P non-zero means clear the message
9457 clear_message (int current_p
, int last_displayed_p
)
9461 echo_area_buffer
[0] = Qnil
;
9462 message_cleared_p
= 1;
9465 if (last_displayed_p
)
9466 echo_area_buffer
[1] = Qnil
;
9468 message_buf_print
= 0;
9471 /* Clear garbaged frames.
9473 This function is used where the old redisplay called
9474 redraw_garbaged_frames which in turn called redraw_frame which in
9475 turn called clear_frame. The call to clear_frame was a source of
9476 flickering. I believe a clear_frame is not necessary. It should
9477 suffice in the new redisplay to invalidate all current matrices,
9478 and ensure a complete redisplay of all windows. */
9481 clear_garbaged_frames (void)
9485 Lisp_Object tail
, frame
;
9486 int changed_count
= 0;
9488 FOR_EACH_FRAME (tail
, frame
)
9490 struct frame
*f
= XFRAME (frame
);
9492 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9496 Fredraw_frame (frame
);
9497 f
->force_flush_display_p
= 1;
9499 clear_current_matrices (f
);
9508 ++windows_or_buffers_changed
;
9513 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9514 is non-zero update selected_frame. Value is non-zero if the
9515 mini-windows height has been changed. */
9518 echo_area_display (int update_frame_p
)
9520 Lisp_Object mini_window
;
9523 int window_height_changed_p
= 0;
9524 struct frame
*sf
= SELECTED_FRAME ();
9526 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9527 w
= XWINDOW (mini_window
);
9528 f
= XFRAME (WINDOW_FRAME (w
));
9530 /* Don't display if frame is invisible or not yet initialized. */
9531 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9534 #ifdef HAVE_WINDOW_SYSTEM
9535 /* When Emacs starts, selected_frame may be the initial terminal
9536 frame. If we let this through, a message would be displayed on
9538 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9540 #endif /* HAVE_WINDOW_SYSTEM */
9542 /* Redraw garbaged frames. */
9544 clear_garbaged_frames ();
9546 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9548 echo_area_window
= mini_window
;
9549 window_height_changed_p
= display_echo_area (w
);
9550 w
->must_be_updated_p
= 1;
9552 /* Update the display, unless called from redisplay_internal.
9553 Also don't update the screen during redisplay itself. The
9554 update will happen at the end of redisplay, and an update
9555 here could cause confusion. */
9556 if (update_frame_p
&& !redisplaying_p
)
9560 /* If the display update has been interrupted by pending
9561 input, update mode lines in the frame. Due to the
9562 pending input, it might have been that redisplay hasn't
9563 been called, so that mode lines above the echo area are
9564 garbaged. This looks odd, so we prevent it here. */
9565 if (!display_completed
)
9566 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9568 if (window_height_changed_p
9569 /* Don't do this if Emacs is shutting down. Redisplay
9570 needs to run hooks. */
9571 && !NILP (Vrun_hooks
))
9573 /* Must update other windows. Likewise as in other
9574 cases, don't let this update be interrupted by
9576 int count
= SPECPDL_INDEX ();
9577 specbind (Qredisplay_dont_pause
, Qt
);
9578 windows_or_buffers_changed
= 1;
9579 redisplay_internal (0);
9580 unbind_to (count
, Qnil
);
9582 else if (FRAME_WINDOW_P (f
) && n
== 0)
9584 /* Window configuration is the same as before.
9585 Can do with a display update of the echo area,
9586 unless we displayed some mode lines. */
9587 update_single_window (w
, 1);
9588 FRAME_RIF (f
)->flush_display (f
);
9591 update_frame (f
, 1, 1);
9593 /* If cursor is in the echo area, make sure that the next
9594 redisplay displays the minibuffer, so that the cursor will
9595 be replaced with what the minibuffer wants. */
9596 if (cursor_in_echo_area
)
9597 ++windows_or_buffers_changed
;
9600 else if (!EQ (mini_window
, selected_window
))
9601 windows_or_buffers_changed
++;
9603 /* Last displayed message is now the current message. */
9604 echo_area_buffer
[1] = echo_area_buffer
[0];
9605 /* Inform read_char that we're not echoing. */
9606 echo_message_buffer
= Qnil
;
9608 /* Prevent redisplay optimization in redisplay_internal by resetting
9609 this_line_start_pos. This is done because the mini-buffer now
9610 displays the message instead of its buffer text. */
9611 if (EQ (mini_window
, selected_window
))
9612 CHARPOS (this_line_start_pos
) = 0;
9614 return window_height_changed_p
;
9619 /***********************************************************************
9620 Mode Lines and Frame Titles
9621 ***********************************************************************/
9623 /* A buffer for constructing non-propertized mode-line strings and
9624 frame titles in it; allocated from the heap in init_xdisp and
9625 resized as needed in store_mode_line_noprop_char. */
9627 static char *mode_line_noprop_buf
;
9629 /* The buffer's end, and a current output position in it. */
9631 static char *mode_line_noprop_buf_end
;
9632 static char *mode_line_noprop_ptr
;
9634 #define MODE_LINE_NOPROP_LEN(start) \
9635 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9638 MODE_LINE_DISPLAY
= 0,
9644 /* Alist that caches the results of :propertize.
9645 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9646 static Lisp_Object mode_line_proptrans_alist
;
9648 /* List of strings making up the mode-line. */
9649 static Lisp_Object mode_line_string_list
;
9651 /* Base face property when building propertized mode line string. */
9652 static Lisp_Object mode_line_string_face
;
9653 static Lisp_Object mode_line_string_face_prop
;
9656 /* Unwind data for mode line strings */
9658 static Lisp_Object Vmode_line_unwind_vector
;
9661 format_mode_line_unwind_data (struct buffer
*obuf
,
9665 Lisp_Object vector
, tmp
;
9667 /* Reduce consing by keeping one vector in
9668 Vwith_echo_area_save_vector. */
9669 vector
= Vmode_line_unwind_vector
;
9670 Vmode_line_unwind_vector
= Qnil
;
9673 vector
= Fmake_vector (make_number (8), Qnil
);
9675 ASET (vector
, 0, make_number (mode_line_target
));
9676 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9677 ASET (vector
, 2, mode_line_string_list
);
9678 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9679 ASET (vector
, 4, mode_line_string_face
);
9680 ASET (vector
, 5, mode_line_string_face_prop
);
9683 XSETBUFFER (tmp
, obuf
);
9686 ASET (vector
, 6, tmp
);
9687 ASET (vector
, 7, owin
);
9693 unwind_format_mode_line (Lisp_Object vector
)
9695 mode_line_target
= XINT (AREF (vector
, 0));
9696 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9697 mode_line_string_list
= AREF (vector
, 2);
9698 if (! EQ (AREF (vector
, 3), Qt
))
9699 mode_line_proptrans_alist
= AREF (vector
, 3);
9700 mode_line_string_face
= AREF (vector
, 4);
9701 mode_line_string_face_prop
= AREF (vector
, 5);
9703 if (!NILP (AREF (vector
, 7)))
9704 /* Select window before buffer, since it may change the buffer. */
9705 Fselect_window (AREF (vector
, 7), Qt
);
9707 if (!NILP (AREF (vector
, 6)))
9709 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9710 ASET (vector
, 6, Qnil
);
9713 Vmode_line_unwind_vector
= vector
;
9718 /* Store a single character C for the frame title in mode_line_noprop_buf.
9719 Re-allocate mode_line_noprop_buf if necessary. */
9722 store_mode_line_noprop_char (char c
)
9724 /* If output position has reached the end of the allocated buffer,
9725 double the buffer's size. */
9726 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9728 int len
= MODE_LINE_NOPROP_LEN (0);
9729 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9730 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9731 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9732 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9735 *mode_line_noprop_ptr
++ = c
;
9739 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9740 mode_line_noprop_ptr. STR is the string to store. Do not copy
9741 characters that yield more columns than PRECISION; PRECISION <= 0
9742 means copy the whole string. Pad with spaces until FIELD_WIDTH
9743 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9744 pad. Called from display_mode_element when it is used to build a
9748 store_mode_line_noprop (const unsigned char *str
, int field_width
, int precision
)
9751 EMACS_INT dummy
, nbytes
;
9753 /* Copy at most PRECISION chars from STR. */
9754 nbytes
= strlen (str
);
9755 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9757 store_mode_line_noprop_char (*str
++);
9759 /* Fill up with spaces until FIELD_WIDTH reached. */
9760 while (field_width
> 0
9763 store_mode_line_noprop_char (' ');
9770 /***********************************************************************
9772 ***********************************************************************/
9774 #ifdef HAVE_WINDOW_SYSTEM
9776 /* Set the title of FRAME, if it has changed. The title format is
9777 Vicon_title_format if FRAME is iconified, otherwise it is
9778 frame_title_format. */
9781 x_consider_frame_title (Lisp_Object frame
)
9783 struct frame
*f
= XFRAME (frame
);
9785 if (FRAME_WINDOW_P (f
)
9786 || FRAME_MINIBUF_ONLY_P (f
)
9787 || f
->explicit_name
)
9789 /* Do we have more than one visible frame on this X display? */
9796 int count
= SPECPDL_INDEX ();
9798 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9800 Lisp_Object other_frame
= XCAR (tail
);
9801 struct frame
*tf
= XFRAME (other_frame
);
9804 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9805 && !FRAME_MINIBUF_ONLY_P (tf
)
9806 && !EQ (other_frame
, tip_frame
)
9807 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9811 /* Set global variable indicating that multiple frames exist. */
9812 multiple_frames
= CONSP (tail
);
9814 /* Switch to the buffer of selected window of the frame. Set up
9815 mode_line_target so that display_mode_element will output into
9816 mode_line_noprop_buf; then display the title. */
9817 record_unwind_protect (unwind_format_mode_line
,
9818 format_mode_line_unwind_data
9819 (current_buffer
, selected_window
, 0));
9821 Fselect_window (f
->selected_window
, Qt
);
9822 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9823 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9825 mode_line_target
= MODE_LINE_TITLE
;
9826 title_start
= MODE_LINE_NOPROP_LEN (0);
9827 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9828 NULL
, DEFAULT_FACE_ID
);
9829 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9830 len
= MODE_LINE_NOPROP_LEN (title_start
);
9831 title
= mode_line_noprop_buf
+ title_start
;
9832 unbind_to (count
, Qnil
);
9834 /* Set the title only if it's changed. This avoids consing in
9835 the common case where it hasn't. (If it turns out that we've
9836 already wasted too much time by walking through the list with
9837 display_mode_element, then we might need to optimize at a
9838 higher level than this.) */
9839 if (! STRINGP (f
->name
)
9840 || SBYTES (f
->name
) != len
9841 || memcmp (title
, SDATA (f
->name
), len
) != 0)
9842 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9846 #endif /* not HAVE_WINDOW_SYSTEM */
9851 /***********************************************************************
9853 ***********************************************************************/
9856 /* Prepare for redisplay by updating menu-bar item lists when
9857 appropriate. This can call eval. */
9860 prepare_menu_bars (void)
9863 struct gcpro gcpro1
, gcpro2
;
9865 Lisp_Object tooltip_frame
;
9867 #ifdef HAVE_WINDOW_SYSTEM
9868 tooltip_frame
= tip_frame
;
9870 tooltip_frame
= Qnil
;
9873 /* Update all frame titles based on their buffer names, etc. We do
9874 this before the menu bars so that the buffer-menu will show the
9875 up-to-date frame titles. */
9876 #ifdef HAVE_WINDOW_SYSTEM
9877 if (windows_or_buffers_changed
|| update_mode_lines
)
9879 Lisp_Object tail
, frame
;
9881 FOR_EACH_FRAME (tail
, frame
)
9884 if (!EQ (frame
, tooltip_frame
)
9885 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9886 x_consider_frame_title (frame
);
9889 #endif /* HAVE_WINDOW_SYSTEM */
9891 /* Update the menu bar item lists, if appropriate. This has to be
9892 done before any actual redisplay or generation of display lines. */
9893 all_windows
= (update_mode_lines
9894 || buffer_shared
> 1
9895 || windows_or_buffers_changed
);
9898 Lisp_Object tail
, frame
;
9899 int count
= SPECPDL_INDEX ();
9900 /* 1 means that update_menu_bar has run its hooks
9901 so any further calls to update_menu_bar shouldn't do so again. */
9902 int menu_bar_hooks_run
= 0;
9904 record_unwind_save_match_data ();
9906 FOR_EACH_FRAME (tail
, frame
)
9910 /* Ignore tooltip frame. */
9911 if (EQ (frame
, tooltip_frame
))
9914 /* If a window on this frame changed size, report that to
9915 the user and clear the size-change flag. */
9916 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9918 Lisp_Object functions
;
9920 /* Clear flag first in case we get an error below. */
9921 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9922 functions
= Vwindow_size_change_functions
;
9923 GCPRO2 (tail
, functions
);
9925 while (CONSP (functions
))
9927 if (!EQ (XCAR (functions
), Qt
))
9928 call1 (XCAR (functions
), frame
);
9929 functions
= XCDR (functions
);
9935 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9936 #ifdef HAVE_WINDOW_SYSTEM
9937 update_tool_bar (f
, 0);
9940 if (windows_or_buffers_changed
9942 ns_set_doc_edited (f
, Fbuffer_modified_p
9943 (XWINDOW (f
->selected_window
)->buffer
));
9948 unbind_to (count
, Qnil
);
9952 struct frame
*sf
= SELECTED_FRAME ();
9953 update_menu_bar (sf
, 1, 0);
9954 #ifdef HAVE_WINDOW_SYSTEM
9955 update_tool_bar (sf
, 1);
9961 /* Update the menu bar item list for frame F. This has to be done
9962 before we start to fill in any display lines, because it can call
9965 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9967 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9968 already ran the menu bar hooks for this redisplay, so there
9969 is no need to run them again. The return value is the
9970 updated value of this flag, to pass to the next call. */
9973 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
9976 register struct window
*w
;
9978 /* If called recursively during a menu update, do nothing. This can
9979 happen when, for instance, an activate-menubar-hook causes a
9981 if (inhibit_menubar_update
)
9984 window
= FRAME_SELECTED_WINDOW (f
);
9985 w
= XWINDOW (window
);
9987 if (FRAME_WINDOW_P (f
)
9989 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9990 || defined (HAVE_NS) || defined (USE_GTK)
9991 FRAME_EXTERNAL_MENU_BAR (f
)
9993 FRAME_MENU_BAR_LINES (f
) > 0
9995 : FRAME_MENU_BAR_LINES (f
) > 0)
9997 /* If the user has switched buffers or windows, we need to
9998 recompute to reflect the new bindings. But we'll
9999 recompute when update_mode_lines is set too; that means
10000 that people can use force-mode-line-update to request
10001 that the menu bar be recomputed. The adverse effect on
10002 the rest of the redisplay algorithm is about the same as
10003 windows_or_buffers_changed anyway. */
10004 if (windows_or_buffers_changed
10005 /* This used to test w->update_mode_line, but we believe
10006 there is no need to recompute the menu in that case. */
10007 || update_mode_lines
10008 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10009 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10010 != !NILP (w
->last_had_star
))
10011 || ((!NILP (Vtransient_mark_mode
)
10012 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10013 != !NILP (w
->region_showing
)))
10015 struct buffer
*prev
= current_buffer
;
10016 int count
= SPECPDL_INDEX ();
10018 specbind (Qinhibit_menubar_update
, Qt
);
10020 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10021 if (save_match_data
)
10022 record_unwind_save_match_data ();
10023 if (NILP (Voverriding_local_map_menu_flag
))
10025 specbind (Qoverriding_terminal_local_map
, Qnil
);
10026 specbind (Qoverriding_local_map
, Qnil
);
10031 /* Run the Lucid hook. */
10032 safe_run_hooks (Qactivate_menubar_hook
);
10034 /* If it has changed current-menubar from previous value,
10035 really recompute the menu-bar from the value. */
10036 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10037 call0 (Qrecompute_lucid_menubar
);
10039 safe_run_hooks (Qmenu_bar_update_hook
);
10044 XSETFRAME (Vmenu_updating_frame
, f
);
10045 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10047 /* Redisplay the menu bar in case we changed it. */
10048 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10049 || defined (HAVE_NS) || defined (USE_GTK)
10050 if (FRAME_WINDOW_P (f
))
10052 #if defined (HAVE_NS)
10053 /* All frames on Mac OS share the same menubar. So only
10054 the selected frame should be allowed to set it. */
10055 if (f
== SELECTED_FRAME ())
10057 set_frame_menubar (f
, 0, 0);
10060 /* On a terminal screen, the menu bar is an ordinary screen
10061 line, and this makes it get updated. */
10062 w
->update_mode_line
= Qt
;
10063 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10064 /* In the non-toolkit version, the menu bar is an ordinary screen
10065 line, and this makes it get updated. */
10066 w
->update_mode_line
= Qt
;
10067 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10069 unbind_to (count
, Qnil
);
10070 set_buffer_internal_1 (prev
);
10079 /***********************************************************************
10081 ***********************************************************************/
10083 #ifdef HAVE_WINDOW_SYSTEM
10086 Nominal cursor position -- where to draw output.
10087 HPOS and VPOS are window relative glyph matrix coordinates.
10088 X and Y are window relative pixel coordinates. */
10090 struct cursor_pos output_cursor
;
10094 Set the global variable output_cursor to CURSOR. All cursor
10095 positions are relative to updated_window. */
10098 set_output_cursor (struct cursor_pos
*cursor
)
10100 output_cursor
.hpos
= cursor
->hpos
;
10101 output_cursor
.vpos
= cursor
->vpos
;
10102 output_cursor
.x
= cursor
->x
;
10103 output_cursor
.y
= cursor
->y
;
10108 Set a nominal cursor position.
10110 HPOS and VPOS are column/row positions in a window glyph matrix. X
10111 and Y are window text area relative pixel positions.
10113 If this is done during an update, updated_window will contain the
10114 window that is being updated and the position is the future output
10115 cursor position for that window. If updated_window is null, use
10116 selected_window and display the cursor at the given position. */
10119 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10123 /* If updated_window is not set, work on selected_window. */
10124 if (updated_window
)
10125 w
= updated_window
;
10127 w
= XWINDOW (selected_window
);
10129 /* Set the output cursor. */
10130 output_cursor
.hpos
= hpos
;
10131 output_cursor
.vpos
= vpos
;
10132 output_cursor
.x
= x
;
10133 output_cursor
.y
= y
;
10135 /* If not called as part of an update, really display the cursor.
10136 This will also set the cursor position of W. */
10137 if (updated_window
== NULL
)
10140 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10141 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10142 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10147 #endif /* HAVE_WINDOW_SYSTEM */
10150 /***********************************************************************
10152 ***********************************************************************/
10154 #ifdef HAVE_WINDOW_SYSTEM
10156 /* Where the mouse was last time we reported a mouse event. */
10158 FRAME_PTR last_mouse_frame
;
10160 /* Tool-bar item index of the item on which a mouse button was pressed
10163 int last_tool_bar_item
;
10167 update_tool_bar_unwind (Lisp_Object frame
)
10169 selected_frame
= frame
;
10173 /* Update the tool-bar item list for frame F. This has to be done
10174 before we start to fill in any display lines. Called from
10175 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10176 and restore it here. */
10179 update_tool_bar (struct frame
*f
, int save_match_data
)
10181 #if defined (USE_GTK) || defined (HAVE_NS)
10182 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10184 int do_update
= WINDOWP (f
->tool_bar_window
)
10185 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10190 Lisp_Object window
;
10193 window
= FRAME_SELECTED_WINDOW (f
);
10194 w
= XWINDOW (window
);
10196 /* If the user has switched buffers or windows, we need to
10197 recompute to reflect the new bindings. But we'll
10198 recompute when update_mode_lines is set too; that means
10199 that people can use force-mode-line-update to request
10200 that the menu bar be recomputed. The adverse effect on
10201 the rest of the redisplay algorithm is about the same as
10202 windows_or_buffers_changed anyway. */
10203 if (windows_or_buffers_changed
10204 || !NILP (w
->update_mode_line
)
10205 || update_mode_lines
10206 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10207 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10208 != !NILP (w
->last_had_star
))
10209 || ((!NILP (Vtransient_mark_mode
)
10210 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10211 != !NILP (w
->region_showing
)))
10213 struct buffer
*prev
= current_buffer
;
10214 int count
= SPECPDL_INDEX ();
10215 Lisp_Object frame
, new_tool_bar
;
10216 int new_n_tool_bar
;
10217 struct gcpro gcpro1
;
10219 /* Set current_buffer to the buffer of the selected
10220 window of the frame, so that we get the right local
10222 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10224 /* Save match data, if we must. */
10225 if (save_match_data
)
10226 record_unwind_save_match_data ();
10228 /* Make sure that we don't accidentally use bogus keymaps. */
10229 if (NILP (Voverriding_local_map_menu_flag
))
10231 specbind (Qoverriding_terminal_local_map
, Qnil
);
10232 specbind (Qoverriding_local_map
, Qnil
);
10235 GCPRO1 (new_tool_bar
);
10237 /* We must temporarily set the selected frame to this frame
10238 before calling tool_bar_items, because the calculation of
10239 the tool-bar keymap uses the selected frame (see
10240 `tool-bar-make-keymap' in tool-bar.el). */
10241 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10242 XSETFRAME (frame
, f
);
10243 selected_frame
= frame
;
10245 /* Build desired tool-bar items from keymaps. */
10246 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10249 /* Redisplay the tool-bar if we changed it. */
10250 if (new_n_tool_bar
!= f
->n_tool_bar_items
10251 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10253 /* Redisplay that happens asynchronously due to an expose event
10254 may access f->tool_bar_items. Make sure we update both
10255 variables within BLOCK_INPUT so no such event interrupts. */
10257 f
->tool_bar_items
= new_tool_bar
;
10258 f
->n_tool_bar_items
= new_n_tool_bar
;
10259 w
->update_mode_line
= Qt
;
10265 unbind_to (count
, Qnil
);
10266 set_buffer_internal_1 (prev
);
10272 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10273 F's desired tool-bar contents. F->tool_bar_items must have
10274 been set up previously by calling prepare_menu_bars. */
10277 build_desired_tool_bar_string (struct frame
*f
)
10279 int i
, size
, size_needed
;
10280 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10281 Lisp_Object image
, plist
, props
;
10283 image
= plist
= props
= Qnil
;
10284 GCPRO3 (image
, plist
, props
);
10286 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10287 Otherwise, make a new string. */
10289 /* The size of the string we might be able to reuse. */
10290 size
= (STRINGP (f
->desired_tool_bar_string
)
10291 ? SCHARS (f
->desired_tool_bar_string
)
10294 /* We need one space in the string for each image. */
10295 size_needed
= f
->n_tool_bar_items
;
10297 /* Reuse f->desired_tool_bar_string, if possible. */
10298 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10299 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10300 make_number (' '));
10303 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10304 Fremove_text_properties (make_number (0), make_number (size
),
10305 props
, f
->desired_tool_bar_string
);
10308 /* Put a `display' property on the string for the images to display,
10309 put a `menu_item' property on tool-bar items with a value that
10310 is the index of the item in F's tool-bar item vector. */
10311 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10313 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10315 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10316 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10317 int hmargin
, vmargin
, relief
, idx
, end
;
10319 /* If image is a vector, choose the image according to the
10321 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10322 if (VECTORP (image
))
10326 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10327 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10330 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10331 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10333 xassert (ASIZE (image
) >= idx
);
10334 image
= AREF (image
, idx
);
10339 /* Ignore invalid image specifications. */
10340 if (!valid_image_p (image
))
10343 /* Display the tool-bar button pressed, or depressed. */
10344 plist
= Fcopy_sequence (XCDR (image
));
10346 /* Compute margin and relief to draw. */
10347 relief
= (tool_bar_button_relief
>= 0
10348 ? tool_bar_button_relief
10349 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10350 hmargin
= vmargin
= relief
;
10352 if (INTEGERP (Vtool_bar_button_margin
)
10353 && XINT (Vtool_bar_button_margin
) > 0)
10355 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10356 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10358 else if (CONSP (Vtool_bar_button_margin
))
10360 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10361 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10362 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10364 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10365 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10366 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10369 if (auto_raise_tool_bar_buttons_p
)
10371 /* Add a `:relief' property to the image spec if the item is
10375 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10382 /* If image is selected, display it pressed, i.e. with a
10383 negative relief. If it's not selected, display it with a
10385 plist
= Fplist_put (plist
, QCrelief
,
10387 ? make_number (-relief
)
10388 : make_number (relief
)));
10393 /* Put a margin around the image. */
10394 if (hmargin
|| vmargin
)
10396 if (hmargin
== vmargin
)
10397 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10399 plist
= Fplist_put (plist
, QCmargin
,
10400 Fcons (make_number (hmargin
),
10401 make_number (vmargin
)));
10404 /* If button is not enabled, and we don't have special images
10405 for the disabled state, make the image appear disabled by
10406 applying an appropriate algorithm to it. */
10407 if (!enabled_p
&& idx
< 0)
10408 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10410 /* Put a `display' text property on the string for the image to
10411 display. Put a `menu-item' property on the string that gives
10412 the start of this item's properties in the tool-bar items
10414 image
= Fcons (Qimage
, plist
);
10415 props
= list4 (Qdisplay
, image
,
10416 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10418 /* Let the last image hide all remaining spaces in the tool bar
10419 string. The string can be longer than needed when we reuse a
10420 previous string. */
10421 if (i
+ 1 == f
->n_tool_bar_items
)
10422 end
= SCHARS (f
->desired_tool_bar_string
);
10425 Fadd_text_properties (make_number (i
), make_number (end
),
10426 props
, f
->desired_tool_bar_string
);
10434 /* Display one line of the tool-bar of frame IT->f.
10436 HEIGHT specifies the desired height of the tool-bar line.
10437 If the actual height of the glyph row is less than HEIGHT, the
10438 row's height is increased to HEIGHT, and the icons are centered
10439 vertically in the new height.
10441 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10442 count a final empty row in case the tool-bar width exactly matches
10447 display_tool_bar_line (struct it
*it
, int height
)
10449 struct glyph_row
*row
= it
->glyph_row
;
10450 int max_x
= it
->last_visible_x
;
10451 struct glyph
*last
;
10453 prepare_desired_row (row
);
10454 row
->y
= it
->current_y
;
10456 /* Note that this isn't made use of if the face hasn't a box,
10457 so there's no need to check the face here. */
10458 it
->start_of_box_run_p
= 1;
10460 while (it
->current_x
< max_x
)
10462 int x
, n_glyphs_before
, i
, nglyphs
;
10463 struct it it_before
;
10465 /* Get the next display element. */
10466 if (!get_next_display_element (it
))
10468 /* Don't count empty row if we are counting needed tool-bar lines. */
10469 if (height
< 0 && !it
->hpos
)
10474 /* Produce glyphs. */
10475 n_glyphs_before
= row
->used
[TEXT_AREA
];
10478 PRODUCE_GLYPHS (it
);
10480 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10482 x
= it_before
.current_x
;
10483 while (i
< nglyphs
)
10485 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10487 if (x
+ glyph
->pixel_width
> max_x
)
10489 /* Glyph doesn't fit on line. Backtrack. */
10490 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10492 /* If this is the only glyph on this line, it will never fit on the
10493 toolbar, so skip it. But ensure there is at least one glyph,
10494 so we don't accidentally disable the tool-bar. */
10495 if (n_glyphs_before
== 0
10496 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10502 x
+= glyph
->pixel_width
;
10506 /* Stop at line ends. */
10507 if (ITERATOR_AT_END_OF_LINE_P (it
))
10510 set_iterator_to_next (it
, 1);
10515 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10517 /* Use default face for the border below the tool bar.
10519 FIXME: When auto-resize-tool-bars is grow-only, there is
10520 no additional border below the possibly empty tool-bar lines.
10521 So to make the extra empty lines look "normal", we have to
10522 use the tool-bar face for the border too. */
10523 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10524 it
->face_id
= DEFAULT_FACE_ID
;
10526 extend_face_to_end_of_line (it
);
10527 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10528 last
->right_box_line_p
= 1;
10529 if (last
== row
->glyphs
[TEXT_AREA
])
10530 last
->left_box_line_p
= 1;
10532 /* Make line the desired height and center it vertically. */
10533 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10535 /* Don't add more than one line height. */
10536 height
%= FRAME_LINE_HEIGHT (it
->f
);
10537 it
->max_ascent
+= height
/ 2;
10538 it
->max_descent
+= (height
+ 1) / 2;
10541 compute_line_metrics (it
);
10543 /* If line is empty, make it occupy the rest of the tool-bar. */
10544 if (!row
->displays_text_p
)
10546 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10547 row
->visible_height
= row
->height
;
10548 row
->ascent
= row
->phys_ascent
= 0;
10549 row
->extra_line_spacing
= 0;
10552 row
->full_width_p
= 1;
10553 row
->continued_p
= 0;
10554 row
->truncated_on_left_p
= 0;
10555 row
->truncated_on_right_p
= 0;
10557 it
->current_x
= it
->hpos
= 0;
10558 it
->current_y
+= row
->height
;
10564 /* Max tool-bar height. */
10566 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10567 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10569 /* Value is the number of screen lines needed to make all tool-bar
10570 items of frame F visible. The number of actual rows needed is
10571 returned in *N_ROWS if non-NULL. */
10574 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10576 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10578 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10579 the desired matrix, so use (unused) mode-line row as temporary row to
10580 avoid destroying the first tool-bar row. */
10581 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10583 /* Initialize an iterator for iteration over
10584 F->desired_tool_bar_string in the tool-bar window of frame F. */
10585 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10586 it
.first_visible_x
= 0;
10587 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10588 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10590 while (!ITERATOR_AT_END_P (&it
))
10592 clear_glyph_row (temp_row
);
10593 it
.glyph_row
= temp_row
;
10594 display_tool_bar_line (&it
, -1);
10596 clear_glyph_row (temp_row
);
10598 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10600 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10602 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10606 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10608 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10609 (Lisp_Object frame
)
10616 frame
= selected_frame
;
10618 CHECK_FRAME (frame
);
10619 f
= XFRAME (frame
);
10621 if (WINDOWP (f
->tool_bar_window
)
10622 || (w
= XWINDOW (f
->tool_bar_window
),
10623 WINDOW_TOTAL_LINES (w
) > 0))
10625 update_tool_bar (f
, 1);
10626 if (f
->n_tool_bar_items
)
10628 build_desired_tool_bar_string (f
);
10629 nlines
= tool_bar_lines_needed (f
, NULL
);
10633 return make_number (nlines
);
10637 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10638 height should be changed. */
10641 redisplay_tool_bar (struct frame
*f
)
10645 struct glyph_row
*row
;
10647 #if defined (USE_GTK) || defined (HAVE_NS)
10648 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10649 update_frame_tool_bar (f
);
10653 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10654 do anything. This means you must start with tool-bar-lines
10655 non-zero to get the auto-sizing effect. Or in other words, you
10656 can turn off tool-bars by specifying tool-bar-lines zero. */
10657 if (!WINDOWP (f
->tool_bar_window
)
10658 || (w
= XWINDOW (f
->tool_bar_window
),
10659 WINDOW_TOTAL_LINES (w
) == 0))
10662 /* Set up an iterator for the tool-bar window. */
10663 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10664 it
.first_visible_x
= 0;
10665 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10666 row
= it
.glyph_row
;
10668 /* Build a string that represents the contents of the tool-bar. */
10669 build_desired_tool_bar_string (f
);
10670 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10672 if (f
->n_tool_bar_rows
== 0)
10676 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10677 nlines
!= WINDOW_TOTAL_LINES (w
)))
10680 int old_height
= WINDOW_TOTAL_LINES (w
);
10682 XSETFRAME (frame
, f
);
10683 Fmodify_frame_parameters (frame
,
10684 Fcons (Fcons (Qtool_bar_lines
,
10685 make_number (nlines
)),
10687 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10689 clear_glyph_matrix (w
->desired_matrix
);
10690 fonts_changed_p
= 1;
10696 /* Display as many lines as needed to display all tool-bar items. */
10698 if (f
->n_tool_bar_rows
> 0)
10700 int border
, rows
, height
, extra
;
10702 if (INTEGERP (Vtool_bar_border
))
10703 border
= XINT (Vtool_bar_border
);
10704 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10705 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10706 else if (EQ (Vtool_bar_border
, Qborder_width
))
10707 border
= f
->border_width
;
10713 rows
= f
->n_tool_bar_rows
;
10714 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10715 extra
= it
.last_visible_y
- border
- height
* rows
;
10717 while (it
.current_y
< it
.last_visible_y
)
10720 if (extra
> 0 && rows
-- > 0)
10722 h
= (extra
+ rows
- 1) / rows
;
10725 display_tool_bar_line (&it
, height
+ h
);
10730 while (it
.current_y
< it
.last_visible_y
)
10731 display_tool_bar_line (&it
, 0);
10734 /* It doesn't make much sense to try scrolling in the tool-bar
10735 window, so don't do it. */
10736 w
->desired_matrix
->no_scrolling_p
= 1;
10737 w
->must_be_updated_p
= 1;
10739 if (!NILP (Vauto_resize_tool_bars
))
10741 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10742 int change_height_p
= 0;
10744 /* If we couldn't display everything, change the tool-bar's
10745 height if there is room for more. */
10746 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10747 && it
.current_y
< max_tool_bar_height
)
10748 change_height_p
= 1;
10750 row
= it
.glyph_row
- 1;
10752 /* If there are blank lines at the end, except for a partially
10753 visible blank line at the end that is smaller than
10754 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10755 if (!row
->displays_text_p
10756 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10757 change_height_p
= 1;
10759 /* If row displays tool-bar items, but is partially visible,
10760 change the tool-bar's height. */
10761 if (row
->displays_text_p
10762 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10763 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10764 change_height_p
= 1;
10766 /* Resize windows as needed by changing the `tool-bar-lines'
10767 frame parameter. */
10768 if (change_height_p
)
10771 int old_height
= WINDOW_TOTAL_LINES (w
);
10773 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10775 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10776 && !f
->minimize_tool_bar_window_p
)
10777 ? (nlines
> old_height
)
10778 : (nlines
!= old_height
));
10779 f
->minimize_tool_bar_window_p
= 0;
10781 if (change_height_p
)
10783 XSETFRAME (frame
, f
);
10784 Fmodify_frame_parameters (frame
,
10785 Fcons (Fcons (Qtool_bar_lines
,
10786 make_number (nlines
)),
10788 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10790 clear_glyph_matrix (w
->desired_matrix
);
10791 f
->n_tool_bar_rows
= nrows
;
10792 fonts_changed_p
= 1;
10799 f
->minimize_tool_bar_window_p
= 0;
10804 /* Get information about the tool-bar item which is displayed in GLYPH
10805 on frame F. Return in *PROP_IDX the index where tool-bar item
10806 properties start in F->tool_bar_items. Value is zero if
10807 GLYPH doesn't display a tool-bar item. */
10810 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
10816 /* This function can be called asynchronously, which means we must
10817 exclude any possibility that Fget_text_property signals an
10819 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10820 charpos
= max (0, charpos
);
10822 /* Get the text property `menu-item' at pos. The value of that
10823 property is the start index of this item's properties in
10824 F->tool_bar_items. */
10825 prop
= Fget_text_property (make_number (charpos
),
10826 Qmenu_item
, f
->current_tool_bar_string
);
10827 if (INTEGERP (prop
))
10829 *prop_idx
= XINT (prop
);
10839 /* Get information about the tool-bar item at position X/Y on frame F.
10840 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10841 the current matrix of the tool-bar window of F, or NULL if not
10842 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10843 item in F->tool_bar_items. Value is
10845 -1 if X/Y is not on a tool-bar item
10846 0 if X/Y is on the same item that was highlighted before.
10850 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
10851 int *hpos
, int *vpos
, int *prop_idx
)
10853 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10854 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10857 /* Find the glyph under X/Y. */
10858 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10859 if (*glyph
== NULL
)
10862 /* Get the start of this tool-bar item's properties in
10863 f->tool_bar_items. */
10864 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10867 /* Is mouse on the highlighted item? */
10868 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
10869 && *vpos
>= hlinfo
->mouse_face_beg_row
10870 && *vpos
<= hlinfo
->mouse_face_end_row
10871 && (*vpos
> hlinfo
->mouse_face_beg_row
10872 || *hpos
>= hlinfo
->mouse_face_beg_col
)
10873 && (*vpos
< hlinfo
->mouse_face_end_row
10874 || *hpos
< hlinfo
->mouse_face_end_col
10875 || hlinfo
->mouse_face_past_end
))
10883 Handle mouse button event on the tool-bar of frame F, at
10884 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10885 0 for button release. MODIFIERS is event modifiers for button
10889 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
10890 unsigned int modifiers
)
10892 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10893 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10894 int hpos
, vpos
, prop_idx
;
10895 struct glyph
*glyph
;
10896 Lisp_Object enabled_p
;
10898 /* If not on the highlighted tool-bar item, return. */
10899 frame_to_window_pixel_xy (w
, &x
, &y
);
10900 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10903 /* If item is disabled, do nothing. */
10904 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10905 if (NILP (enabled_p
))
10910 /* Show item in pressed state. */
10911 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
10912 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10913 last_tool_bar_item
= prop_idx
;
10917 Lisp_Object key
, frame
;
10918 struct input_event event
;
10919 EVENT_INIT (event
);
10921 /* Show item in released state. */
10922 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
10923 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10925 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10927 XSETFRAME (frame
, f
);
10928 event
.kind
= TOOL_BAR_EVENT
;
10929 event
.frame_or_window
= frame
;
10931 kbd_buffer_store_event (&event
);
10933 event
.kind
= TOOL_BAR_EVENT
;
10934 event
.frame_or_window
= frame
;
10936 event
.modifiers
= modifiers
;
10937 kbd_buffer_store_event (&event
);
10938 last_tool_bar_item
= -1;
10943 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10944 tool-bar window-relative coordinates X/Y. Called from
10945 note_mouse_highlight. */
10948 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
10950 Lisp_Object window
= f
->tool_bar_window
;
10951 struct window
*w
= XWINDOW (window
);
10952 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10953 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10955 struct glyph
*glyph
;
10956 struct glyph_row
*row
;
10958 Lisp_Object enabled_p
;
10960 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10961 int mouse_down_p
, rc
;
10963 /* Function note_mouse_highlight is called with negative X/Y
10964 values when mouse moves outside of the frame. */
10965 if (x
<= 0 || y
<= 0)
10967 clear_mouse_face (hlinfo
);
10971 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10974 /* Not on tool-bar item. */
10975 clear_mouse_face (hlinfo
);
10979 /* On same tool-bar item as before. */
10980 goto set_help_echo
;
10982 clear_mouse_face (hlinfo
);
10984 /* Mouse is down, but on different tool-bar item? */
10985 mouse_down_p
= (dpyinfo
->grabbed
10986 && f
== last_mouse_frame
10987 && FRAME_LIVE_P (f
));
10989 && last_tool_bar_item
!= prop_idx
)
10992 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10993 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10995 /* If tool-bar item is not enabled, don't highlight it. */
10996 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10997 if (!NILP (enabled_p
))
10999 /* Compute the x-position of the glyph. In front and past the
11000 image is a space. We include this in the highlighted area. */
11001 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
11002 for (i
= x
= 0; i
< hpos
; ++i
)
11003 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11005 /* Record this as the current active region. */
11006 hlinfo
->mouse_face_beg_col
= hpos
;
11007 hlinfo
->mouse_face_beg_row
= vpos
;
11008 hlinfo
->mouse_face_beg_x
= x
;
11009 hlinfo
->mouse_face_beg_y
= row
->y
;
11010 hlinfo
->mouse_face_past_end
= 0;
11012 hlinfo
->mouse_face_end_col
= hpos
+ 1;
11013 hlinfo
->mouse_face_end_row
= vpos
;
11014 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11015 hlinfo
->mouse_face_end_y
= row
->y
;
11016 hlinfo
->mouse_face_window
= window
;
11017 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11019 /* Display it as active. */
11020 show_mouse_face (hlinfo
, draw
);
11021 hlinfo
->mouse_face_image_state
= draw
;
11026 /* Set help_echo_string to a help string to display for this tool-bar item.
11027 XTread_socket does the rest. */
11028 help_echo_object
= help_echo_window
= Qnil
;
11029 help_echo_pos
= -1;
11030 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11031 if (NILP (help_echo_string
))
11032 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11035 #endif /* HAVE_WINDOW_SYSTEM */
11039 /************************************************************************
11040 Horizontal scrolling
11041 ************************************************************************/
11043 static int hscroll_window_tree (Lisp_Object
);
11044 static int hscroll_windows (Lisp_Object
);
11046 /* For all leaf windows in the window tree rooted at WINDOW, set their
11047 hscroll value so that PT is (i) visible in the window, and (ii) so
11048 that it is not within a certain margin at the window's left and
11049 right border. Value is non-zero if any window's hscroll has been
11053 hscroll_window_tree (Lisp_Object window
)
11055 int hscrolled_p
= 0;
11056 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11057 int hscroll_step_abs
= 0;
11058 double hscroll_step_rel
= 0;
11060 if (hscroll_relative_p
)
11062 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11063 if (hscroll_step_rel
< 0)
11065 hscroll_relative_p
= 0;
11066 hscroll_step_abs
= 0;
11069 else if (INTEGERP (Vhscroll_step
))
11071 hscroll_step_abs
= XINT (Vhscroll_step
);
11072 if (hscroll_step_abs
< 0)
11073 hscroll_step_abs
= 0;
11076 hscroll_step_abs
= 0;
11078 while (WINDOWP (window
))
11080 struct window
*w
= XWINDOW (window
);
11082 if (WINDOWP (w
->hchild
))
11083 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11084 else if (WINDOWP (w
->vchild
))
11085 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11086 else if (w
->cursor
.vpos
>= 0)
11089 int text_area_width
;
11090 struct glyph_row
*current_cursor_row
11091 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11092 struct glyph_row
*desired_cursor_row
11093 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11094 struct glyph_row
*cursor_row
11095 = (desired_cursor_row
->enabled_p
11096 ? desired_cursor_row
11097 : current_cursor_row
);
11099 text_area_width
= window_box_width (w
, TEXT_AREA
);
11101 /* Scroll when cursor is inside this scroll margin. */
11102 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11104 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11105 && ((XFASTINT (w
->hscroll
)
11106 && w
->cursor
.x
<= h_margin
)
11107 || (cursor_row
->enabled_p
11108 && cursor_row
->truncated_on_right_p
11109 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11113 struct buffer
*saved_current_buffer
;
11117 /* Find point in a display of infinite width. */
11118 saved_current_buffer
= current_buffer
;
11119 current_buffer
= XBUFFER (w
->buffer
);
11121 if (w
== XWINDOW (selected_window
))
11122 pt
= BUF_PT (current_buffer
);
11125 pt
= marker_position (w
->pointm
);
11126 pt
= max (BEGV
, pt
);
11130 /* Move iterator to pt starting at cursor_row->start in
11131 a line with infinite width. */
11132 init_to_row_start (&it
, w
, cursor_row
);
11133 it
.last_visible_x
= INFINITY
;
11134 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11135 current_buffer
= saved_current_buffer
;
11137 /* Position cursor in window. */
11138 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11139 hscroll
= max (0, (it
.current_x
11140 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11141 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11142 : (text_area_width
/ 2))))
11143 / FRAME_COLUMN_WIDTH (it
.f
);
11144 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11146 if (hscroll_relative_p
)
11147 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11150 wanted_x
= text_area_width
11151 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11154 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11158 if (hscroll_relative_p
)
11159 wanted_x
= text_area_width
* hscroll_step_rel
11162 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11165 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11167 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11169 /* Don't call Fset_window_hscroll if value hasn't
11170 changed because it will prevent redisplay
11172 if (XFASTINT (w
->hscroll
) != hscroll
)
11174 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11175 w
->hscroll
= make_number (hscroll
);
11184 /* Value is non-zero if hscroll of any leaf window has been changed. */
11185 return hscrolled_p
;
11189 /* Set hscroll so that cursor is visible and not inside horizontal
11190 scroll margins for all windows in the tree rooted at WINDOW. See
11191 also hscroll_window_tree above. Value is non-zero if any window's
11192 hscroll has been changed. If it has, desired matrices on the frame
11193 of WINDOW are cleared. */
11196 hscroll_windows (Lisp_Object window
)
11198 int hscrolled_p
= hscroll_window_tree (window
);
11200 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11201 return hscrolled_p
;
11206 /************************************************************************
11208 ************************************************************************/
11210 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11211 to a non-zero value. This is sometimes handy to have in a debugger
11216 /* First and last unchanged row for try_window_id. */
11218 int debug_first_unchanged_at_end_vpos
;
11219 int debug_last_unchanged_at_beg_vpos
;
11221 /* Delta vpos and y. */
11223 int debug_dvpos
, debug_dy
;
11225 /* Delta in characters and bytes for try_window_id. */
11227 EMACS_INT debug_delta
, debug_delta_bytes
;
11229 /* Values of window_end_pos and window_end_vpos at the end of
11232 EMACS_INT debug_end_pos
, debug_end_vpos
;
11234 /* Append a string to W->desired_matrix->method. FMT is a printf
11235 format string. A1...A9 are a supplement for a variable-length
11236 argument list. If trace_redisplay_p is non-zero also printf the
11237 resulting string to stderr. */
11240 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11243 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11246 char *method
= w
->desired_matrix
->method
;
11247 int len
= strlen (method
);
11248 int size
= sizeof w
->desired_matrix
->method
;
11249 int remaining
= size
- len
- 1;
11251 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11252 if (len
&& remaining
)
11255 --remaining
, ++len
;
11258 strncpy (method
+ len
, buffer
, remaining
);
11260 if (trace_redisplay_p
)
11261 fprintf (stderr
, "%p (%s): %s\n",
11263 ((BUFFERP (w
->buffer
)
11264 && STRINGP (XBUFFER (w
->buffer
)->name
))
11265 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
11270 #endif /* GLYPH_DEBUG */
11273 /* Value is non-zero if all changes in window W, which displays
11274 current_buffer, are in the text between START and END. START is a
11275 buffer position, END is given as a distance from Z. Used in
11276 redisplay_internal for display optimization. */
11279 text_outside_line_unchanged_p (struct window
*w
,
11280 EMACS_INT start
, EMACS_INT end
)
11282 int unchanged_p
= 1;
11284 /* If text or overlays have changed, see where. */
11285 if (XFASTINT (w
->last_modified
) < MODIFF
11286 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11288 /* Gap in the line? */
11289 if (GPT
< start
|| Z
- GPT
< end
)
11292 /* Changes start in front of the line, or end after it? */
11294 && (BEG_UNCHANGED
< start
- 1
11295 || END_UNCHANGED
< end
))
11298 /* If selective display, can't optimize if changes start at the
11299 beginning of the line. */
11301 && INTEGERP (current_buffer
->selective_display
)
11302 && XINT (current_buffer
->selective_display
) > 0
11303 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11306 /* If there are overlays at the start or end of the line, these
11307 may have overlay strings with newlines in them. A change at
11308 START, for instance, may actually concern the display of such
11309 overlay strings as well, and they are displayed on different
11310 lines. So, quickly rule out this case. (For the future, it
11311 might be desirable to implement something more telling than
11312 just BEG/END_UNCHANGED.) */
11315 if (BEG
+ BEG_UNCHANGED
== start
11316 && overlay_touches_p (start
))
11318 if (END_UNCHANGED
== end
11319 && overlay_touches_p (Z
- end
))
11323 /* Under bidi reordering, adding or deleting a character in the
11324 beginning of a paragraph, before the first strong directional
11325 character, can change the base direction of the paragraph (unless
11326 the buffer specifies a fixed paragraph direction), which will
11327 require to redisplay the whole paragraph. It might be worthwhile
11328 to find the paragraph limits and widen the range of redisplayed
11329 lines to that, but for now just give up this optimization. */
11330 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
11331 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
11335 return unchanged_p
;
11339 /* Do a frame update, taking possible shortcuts into account. This is
11340 the main external entry point for redisplay.
11342 If the last redisplay displayed an echo area message and that message
11343 is no longer requested, we clear the echo area or bring back the
11344 mini-buffer if that is in use. */
11349 redisplay_internal (0);
11354 overlay_arrow_string_or_property (Lisp_Object var
)
11358 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11361 return Voverlay_arrow_string
;
11364 /* Return 1 if there are any overlay-arrows in current_buffer. */
11366 overlay_arrow_in_current_buffer_p (void)
11370 for (vlist
= Voverlay_arrow_variable_list
;
11372 vlist
= XCDR (vlist
))
11374 Lisp_Object var
= XCAR (vlist
);
11377 if (!SYMBOLP (var
))
11379 val
= find_symbol_value (var
);
11381 && current_buffer
== XMARKER (val
)->buffer
)
11388 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11392 overlay_arrows_changed_p (void)
11396 for (vlist
= Voverlay_arrow_variable_list
;
11398 vlist
= XCDR (vlist
))
11400 Lisp_Object var
= XCAR (vlist
);
11401 Lisp_Object val
, pstr
;
11403 if (!SYMBOLP (var
))
11405 val
= find_symbol_value (var
);
11406 if (!MARKERP (val
))
11408 if (! EQ (COERCE_MARKER (val
),
11409 Fget (var
, Qlast_arrow_position
))
11410 || ! (pstr
= overlay_arrow_string_or_property (var
),
11411 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11417 /* Mark overlay arrows to be updated on next redisplay. */
11420 update_overlay_arrows (int up_to_date
)
11424 for (vlist
= Voverlay_arrow_variable_list
;
11426 vlist
= XCDR (vlist
))
11428 Lisp_Object var
= XCAR (vlist
);
11430 if (!SYMBOLP (var
))
11433 if (up_to_date
> 0)
11435 Lisp_Object val
= find_symbol_value (var
);
11436 Fput (var
, Qlast_arrow_position
,
11437 COERCE_MARKER (val
));
11438 Fput (var
, Qlast_arrow_string
,
11439 overlay_arrow_string_or_property (var
));
11441 else if (up_to_date
< 0
11442 || !NILP (Fget (var
, Qlast_arrow_position
)))
11444 Fput (var
, Qlast_arrow_position
, Qt
);
11445 Fput (var
, Qlast_arrow_string
, Qt
);
11451 /* Return overlay arrow string to display at row.
11452 Return integer (bitmap number) for arrow bitmap in left fringe.
11453 Return nil if no overlay arrow. */
11456 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11460 for (vlist
= Voverlay_arrow_variable_list
;
11462 vlist
= XCDR (vlist
))
11464 Lisp_Object var
= XCAR (vlist
);
11467 if (!SYMBOLP (var
))
11470 val
= find_symbol_value (var
);
11473 && current_buffer
== XMARKER (val
)->buffer
11474 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11476 if (FRAME_WINDOW_P (it
->f
)
11477 /* FIXME: if ROW->reversed_p is set, this should test
11478 the right fringe, not the left one. */
11479 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11481 #ifdef HAVE_WINDOW_SYSTEM
11482 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11485 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11486 return make_number (fringe_bitmap
);
11489 return make_number (-1); /* Use default arrow bitmap */
11491 return overlay_arrow_string_or_property (var
);
11498 /* Return 1 if point moved out of or into a composition. Otherwise
11499 return 0. PREV_BUF and PREV_PT are the last point buffer and
11500 position. BUF and PT are the current point buffer and position. */
11503 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11504 struct buffer
*buf
, EMACS_INT pt
)
11506 EMACS_INT start
, end
;
11508 Lisp_Object buffer
;
11510 XSETBUFFER (buffer
, buf
);
11511 /* Check a composition at the last point if point moved within the
11513 if (prev_buf
== buf
)
11516 /* Point didn't move. */
11519 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11520 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11521 && COMPOSITION_VALID_P (start
, end
, prop
)
11522 && start
< prev_pt
&& end
> prev_pt
)
11523 /* The last point was within the composition. Return 1 iff
11524 point moved out of the composition. */
11525 return (pt
<= start
|| pt
>= end
);
11528 /* Check a composition at the current point. */
11529 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11530 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11531 && COMPOSITION_VALID_P (start
, end
, prop
)
11532 && start
< pt
&& end
> pt
);
11536 /* Reconsider the setting of B->clip_changed which is displayed
11540 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11542 if (b
->clip_changed
11543 && !NILP (w
->window_end_valid
)
11544 && w
->current_matrix
->buffer
== b
11545 && w
->current_matrix
->zv
== BUF_ZV (b
)
11546 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11547 b
->clip_changed
= 0;
11549 /* If display wasn't paused, and W is not a tool bar window, see if
11550 point has been moved into or out of a composition. In that case,
11551 we set b->clip_changed to 1 to force updating the screen. If
11552 b->clip_changed has already been set to 1, we can skip this
11554 if (!b
->clip_changed
11555 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11559 if (w
== XWINDOW (selected_window
))
11560 pt
= BUF_PT (current_buffer
);
11562 pt
= marker_position (w
->pointm
);
11564 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11565 || pt
!= XINT (w
->last_point
))
11566 && check_point_in_composition (w
->current_matrix
->buffer
,
11567 XINT (w
->last_point
),
11568 XBUFFER (w
->buffer
), pt
))
11569 b
->clip_changed
= 1;
11574 /* Select FRAME to forward the values of frame-local variables into C
11575 variables so that the redisplay routines can access those values
11579 select_frame_for_redisplay (Lisp_Object frame
)
11581 Lisp_Object tail
, tem
;
11582 Lisp_Object old
= selected_frame
;
11583 struct Lisp_Symbol
*sym
;
11585 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11587 selected_frame
= frame
;
11590 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11591 if (CONSP (XCAR (tail
))
11592 && (tem
= XCAR (XCAR (tail
)),
11594 && (sym
= indirect_variable (XSYMBOL (tem
)),
11595 sym
->redirect
== SYMBOL_LOCALIZED
)
11596 && sym
->val
.blv
->frame_local
)
11597 /* Use find_symbol_value rather than Fsymbol_value
11598 to avoid an error if it is void. */
11599 find_symbol_value (tem
);
11600 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11604 #define STOP_POLLING \
11605 do { if (! polling_stopped_here) stop_polling (); \
11606 polling_stopped_here = 1; } while (0)
11608 #define RESUME_POLLING \
11609 do { if (polling_stopped_here) start_polling (); \
11610 polling_stopped_here = 0; } while (0)
11613 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11614 response to any user action; therefore, we should preserve the echo
11615 area. (Actually, our caller does that job.) Perhaps in the future
11616 avoid recentering windows if it is not necessary; currently that
11617 causes some problems. */
11620 redisplay_internal (int preserve_echo_area
)
11622 struct window
*w
= XWINDOW (selected_window
);
11625 int must_finish
= 0;
11626 struct text_pos tlbufpos
, tlendpos
;
11627 int number_of_visible_frames
;
11630 int polling_stopped_here
= 0;
11631 Lisp_Object old_frame
= selected_frame
;
11633 /* Non-zero means redisplay has to consider all windows on all
11634 frames. Zero means, only selected_window is considered. */
11635 int consider_all_windows_p
;
11637 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11639 /* No redisplay if running in batch mode or frame is not yet fully
11640 initialized, or redisplay is explicitly turned off by setting
11641 Vinhibit_redisplay. */
11642 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11643 || !NILP (Vinhibit_redisplay
))
11646 /* Don't examine these until after testing Vinhibit_redisplay.
11647 When Emacs is shutting down, perhaps because its connection to
11648 X has dropped, we should not look at them at all. */
11649 f
= XFRAME (w
->frame
);
11650 sf
= SELECTED_FRAME ();
11652 if (!f
->glyphs_initialized_p
)
11655 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11656 if (popup_activated ())
11660 /* I don't think this happens but let's be paranoid. */
11661 if (redisplaying_p
)
11664 /* Record a function that resets redisplaying_p to its old value
11665 when we leave this function. */
11666 count
= SPECPDL_INDEX ();
11667 record_unwind_protect (unwind_redisplay
,
11668 Fcons (make_number (redisplaying_p
), selected_frame
));
11670 specbind (Qinhibit_free_realized_faces
, Qnil
);
11673 Lisp_Object tail
, frame
;
11675 FOR_EACH_FRAME (tail
, frame
)
11677 struct frame
*f
= XFRAME (frame
);
11678 f
->already_hscrolled_p
= 0;
11683 if (!EQ (old_frame
, selected_frame
)
11684 && FRAME_LIVE_P (XFRAME (old_frame
)))
11685 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11686 selected_frame and selected_window to be temporarily out-of-sync so
11687 when we come back here via `goto retry', we need to resync because we
11688 may need to run Elisp code (via prepare_menu_bars). */
11689 select_frame_for_redisplay (old_frame
);
11692 reconsider_clip_changes (w
, current_buffer
);
11693 last_escape_glyph_frame
= NULL
;
11694 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11695 last_glyphless_glyph_frame
= NULL
;
11696 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
11698 /* If new fonts have been loaded that make a glyph matrix adjustment
11699 necessary, do it. */
11700 if (fonts_changed_p
)
11702 adjust_glyphs (NULL
);
11703 ++windows_or_buffers_changed
;
11704 fonts_changed_p
= 0;
11707 /* If face_change_count is non-zero, init_iterator will free all
11708 realized faces, which includes the faces referenced from current
11709 matrices. So, we can't reuse current matrices in this case. */
11710 if (face_change_count
)
11711 ++windows_or_buffers_changed
;
11713 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11714 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11716 /* Since frames on a single ASCII terminal share the same
11717 display area, displaying a different frame means redisplay
11718 the whole thing. */
11719 windows_or_buffers_changed
++;
11720 SET_FRAME_GARBAGED (sf
);
11722 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11724 FRAME_TTY (sf
)->previous_frame
= sf
;
11727 /* Set the visible flags for all frames. Do this before checking
11728 for resized or garbaged frames; they want to know if their frames
11729 are visible. See the comment in frame.h for
11730 FRAME_SAMPLE_VISIBILITY. */
11732 Lisp_Object tail
, frame
;
11734 number_of_visible_frames
= 0;
11736 FOR_EACH_FRAME (tail
, frame
)
11738 struct frame
*f
= XFRAME (frame
);
11740 FRAME_SAMPLE_VISIBILITY (f
);
11741 if (FRAME_VISIBLE_P (f
))
11742 ++number_of_visible_frames
;
11743 clear_desired_matrices (f
);
11747 /* Notice any pending interrupt request to change frame size. */
11748 do_pending_window_change (1);
11750 /* Clear frames marked as garbaged. */
11751 if (frame_garbaged
)
11752 clear_garbaged_frames ();
11754 /* Build menubar and tool-bar items. */
11755 if (NILP (Vmemory_full
))
11756 prepare_menu_bars ();
11758 if (windows_or_buffers_changed
)
11759 update_mode_lines
++;
11761 /* Detect case that we need to write or remove a star in the mode line. */
11762 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11764 w
->update_mode_line
= Qt
;
11765 if (buffer_shared
> 1)
11766 update_mode_lines
++;
11769 /* Avoid invocation of point motion hooks by `current_column' below. */
11770 count1
= SPECPDL_INDEX ();
11771 specbind (Qinhibit_point_motion_hooks
, Qt
);
11773 /* If %c is in the mode line, update it if needed. */
11774 if (!NILP (w
->column_number_displayed
)
11775 /* This alternative quickly identifies a common case
11776 where no change is needed. */
11777 && !(PT
== XFASTINT (w
->last_point
)
11778 && XFASTINT (w
->last_modified
) >= MODIFF
11779 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11780 && (XFASTINT (w
->column_number_displayed
)
11781 != (int) current_column ())) /* iftc */
11782 w
->update_mode_line
= Qt
;
11784 unbind_to (count1
, Qnil
);
11786 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11788 /* The variable buffer_shared is set in redisplay_window and
11789 indicates that we redisplay a buffer in different windows. See
11791 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11792 || cursor_type_changed
);
11794 /* If specs for an arrow have changed, do thorough redisplay
11795 to ensure we remove any arrow that should no longer exist. */
11796 if (overlay_arrows_changed_p ())
11797 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11799 /* Normally the message* functions will have already displayed and
11800 updated the echo area, but the frame may have been trashed, or
11801 the update may have been preempted, so display the echo area
11802 again here. Checking message_cleared_p captures the case that
11803 the echo area should be cleared. */
11804 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11805 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11806 || (message_cleared_p
11807 && minibuf_level
== 0
11808 /* If the mini-window is currently selected, this means the
11809 echo-area doesn't show through. */
11810 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11812 int window_height_changed_p
= echo_area_display (0);
11815 /* If we don't display the current message, don't clear the
11816 message_cleared_p flag, because, if we did, we wouldn't clear
11817 the echo area in the next redisplay which doesn't preserve
11819 if (!display_last_displayed_message_p
)
11820 message_cleared_p
= 0;
11822 if (fonts_changed_p
)
11824 else if (window_height_changed_p
)
11826 consider_all_windows_p
= 1;
11827 ++update_mode_lines
;
11828 ++windows_or_buffers_changed
;
11830 /* If window configuration was changed, frames may have been
11831 marked garbaged. Clear them or we will experience
11832 surprises wrt scrolling. */
11833 if (frame_garbaged
)
11834 clear_garbaged_frames ();
11837 else if (EQ (selected_window
, minibuf_window
)
11838 && (current_buffer
->clip_changed
11839 || XFASTINT (w
->last_modified
) < MODIFF
11840 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11841 && resize_mini_window (w
, 0))
11843 /* Resized active mini-window to fit the size of what it is
11844 showing if its contents might have changed. */
11846 /* FIXME: this causes all frames to be updated, which seems unnecessary
11847 since only the current frame needs to be considered. This function needs
11848 to be rewritten with two variables, consider_all_windows and
11849 consider_all_frames. */
11850 consider_all_windows_p
= 1;
11851 ++windows_or_buffers_changed
;
11852 ++update_mode_lines
;
11854 /* If window configuration was changed, frames may have been
11855 marked garbaged. Clear them or we will experience
11856 surprises wrt scrolling. */
11857 if (frame_garbaged
)
11858 clear_garbaged_frames ();
11862 /* If showing the region, and mark has changed, we must redisplay
11863 the whole window. The assignment to this_line_start_pos prevents
11864 the optimization directly below this if-statement. */
11865 if (((!NILP (Vtransient_mark_mode
)
11866 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11867 != !NILP (w
->region_showing
))
11868 || (!NILP (w
->region_showing
)
11869 && !EQ (w
->region_showing
,
11870 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11871 CHARPOS (this_line_start_pos
) = 0;
11873 /* Optimize the case that only the line containing the cursor in the
11874 selected window has changed. Variables starting with this_ are
11875 set in display_line and record information about the line
11876 containing the cursor. */
11877 tlbufpos
= this_line_start_pos
;
11878 tlendpos
= this_line_end_pos
;
11879 if (!consider_all_windows_p
11880 && CHARPOS (tlbufpos
) > 0
11881 && NILP (w
->update_mode_line
)
11882 && !current_buffer
->clip_changed
11883 && !current_buffer
->prevent_redisplay_optimizations_p
11884 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11885 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11886 /* Make sure recorded data applies to current buffer, etc. */
11887 && this_line_buffer
== current_buffer
11888 && current_buffer
== XBUFFER (w
->buffer
)
11889 && NILP (w
->force_start
)
11890 && NILP (w
->optional_new_start
)
11891 /* Point must be on the line that we have info recorded about. */
11892 && PT
>= CHARPOS (tlbufpos
)
11893 && PT
<= Z
- CHARPOS (tlendpos
)
11894 /* All text outside that line, including its final newline,
11895 must be unchanged. */
11896 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11897 CHARPOS (tlendpos
)))
11899 if (CHARPOS (tlbufpos
) > BEGV
11900 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11901 && (CHARPOS (tlbufpos
) == ZV
11902 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11903 /* Former continuation line has disappeared by becoming empty. */
11905 else if (XFASTINT (w
->last_modified
) < MODIFF
11906 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11907 || MINI_WINDOW_P (w
))
11909 /* We have to handle the case of continuation around a
11910 wide-column character (see the comment in indent.c around
11913 For instance, in the following case:
11915 -------- Insert --------
11916 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11917 J_I_ ==> J_I_ `^^' are cursors.
11921 As we have to redraw the line above, we cannot use this
11925 int line_height_before
= this_line_pixel_height
;
11927 /* Note that start_display will handle the case that the
11928 line starting at tlbufpos is a continuation line. */
11929 start_display (&it
, w
, tlbufpos
);
11931 /* Implementation note: It this still necessary? */
11932 if (it
.current_x
!= this_line_start_x
)
11935 TRACE ((stderr
, "trying display optimization 1\n"));
11936 w
->cursor
.vpos
= -1;
11937 overlay_arrow_seen
= 0;
11938 it
.vpos
= this_line_vpos
;
11939 it
.current_y
= this_line_y
;
11940 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11941 display_line (&it
);
11943 /* If line contains point, is not continued,
11944 and ends at same distance from eob as before, we win. */
11945 if (w
->cursor
.vpos
>= 0
11946 /* Line is not continued, otherwise this_line_start_pos
11947 would have been set to 0 in display_line. */
11948 && CHARPOS (this_line_start_pos
)
11949 /* Line ends as before. */
11950 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11951 /* Line has same height as before. Otherwise other lines
11952 would have to be shifted up or down. */
11953 && this_line_pixel_height
== line_height_before
)
11955 /* If this is not the window's last line, we must adjust
11956 the charstarts of the lines below. */
11957 if (it
.current_y
< it
.last_visible_y
)
11959 struct glyph_row
*row
11960 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11961 EMACS_INT delta
, delta_bytes
;
11963 /* We used to distinguish between two cases here,
11964 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11965 when the line ends in a newline or the end of the
11966 buffer's accessible portion. But both cases did
11967 the same, so they were collapsed. */
11969 - CHARPOS (tlendpos
)
11970 - MATRIX_ROW_START_CHARPOS (row
));
11971 delta_bytes
= (Z_BYTE
11972 - BYTEPOS (tlendpos
)
11973 - MATRIX_ROW_START_BYTEPOS (row
));
11975 increment_matrix_positions (w
->current_matrix
,
11976 this_line_vpos
+ 1,
11977 w
->current_matrix
->nrows
,
11978 delta
, delta_bytes
);
11981 /* If this row displays text now but previously didn't,
11982 or vice versa, w->window_end_vpos may have to be
11984 if ((it
.glyph_row
- 1)->displays_text_p
)
11986 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11987 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11989 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11990 && this_line_vpos
> 0)
11991 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11992 w
->window_end_valid
= Qnil
;
11994 /* Update hint: No need to try to scroll in update_window. */
11995 w
->desired_matrix
->no_scrolling_p
= 1;
11998 *w
->desired_matrix
->method
= 0;
11999 debug_method_add (w
, "optimization 1");
12001 #ifdef HAVE_WINDOW_SYSTEM
12002 update_window_fringes (w
, 0);
12009 else if (/* Cursor position hasn't changed. */
12010 PT
== XFASTINT (w
->last_point
)
12011 /* Make sure the cursor was last displayed
12012 in this window. Otherwise we have to reposition it. */
12013 && 0 <= w
->cursor
.vpos
12014 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12018 do_pending_window_change (1);
12020 /* We used to always goto end_of_redisplay here, but this
12021 isn't enough if we have a blinking cursor. */
12022 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12023 goto end_of_redisplay
;
12027 /* If highlighting the region, or if the cursor is in the echo area,
12028 then we can't just move the cursor. */
12029 else if (! (!NILP (Vtransient_mark_mode
)
12030 && !NILP (current_buffer
->mark_active
))
12031 && (EQ (selected_window
, current_buffer
->last_selected_window
)
12032 || highlight_nonselected_windows
)
12033 && NILP (w
->region_showing
)
12034 && NILP (Vshow_trailing_whitespace
)
12035 && !cursor_in_echo_area
)
12038 struct glyph_row
*row
;
12040 /* Skip from tlbufpos to PT and see where it is. Note that
12041 PT may be in invisible text. If so, we will end at the
12042 next visible position. */
12043 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12044 NULL
, DEFAULT_FACE_ID
);
12045 it
.current_x
= this_line_start_x
;
12046 it
.current_y
= this_line_y
;
12047 it
.vpos
= this_line_vpos
;
12049 /* The call to move_it_to stops in front of PT, but
12050 moves over before-strings. */
12051 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12053 if (it
.vpos
== this_line_vpos
12054 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12057 xassert (this_line_vpos
== it
.vpos
);
12058 xassert (this_line_y
== it
.current_y
);
12059 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12061 *w
->desired_matrix
->method
= 0;
12062 debug_method_add (w
, "optimization 3");
12071 /* Text changed drastically or point moved off of line. */
12072 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12075 CHARPOS (this_line_start_pos
) = 0;
12076 consider_all_windows_p
|= buffer_shared
> 1;
12077 ++clear_face_cache_count
;
12078 #ifdef HAVE_WINDOW_SYSTEM
12079 ++clear_image_cache_count
;
12082 /* Build desired matrices, and update the display. If
12083 consider_all_windows_p is non-zero, do it for all windows on all
12084 frames. Otherwise do it for selected_window, only. */
12086 if (consider_all_windows_p
)
12088 Lisp_Object tail
, frame
;
12090 FOR_EACH_FRAME (tail
, frame
)
12091 XFRAME (frame
)->updated_p
= 0;
12093 /* Recompute # windows showing selected buffer. This will be
12094 incremented each time such a window is displayed. */
12097 FOR_EACH_FRAME (tail
, frame
)
12099 struct frame
*f
= XFRAME (frame
);
12101 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12103 if (! EQ (frame
, selected_frame
))
12104 /* Select the frame, for the sake of frame-local
12106 select_frame_for_redisplay (frame
);
12108 /* Mark all the scroll bars to be removed; we'll redeem
12109 the ones we want when we redisplay their windows. */
12110 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12111 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12113 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12114 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12116 /* The X error handler may have deleted that frame. */
12117 if (!FRAME_LIVE_P (f
))
12120 /* Any scroll bars which redisplay_windows should have
12121 nuked should now go away. */
12122 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12123 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12125 /* If fonts changed, display again. */
12126 /* ??? rms: I suspect it is a mistake to jump all the way
12127 back to retry here. It should just retry this frame. */
12128 if (fonts_changed_p
)
12131 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12133 /* See if we have to hscroll. */
12134 if (!f
->already_hscrolled_p
)
12136 f
->already_hscrolled_p
= 1;
12137 if (hscroll_windows (f
->root_window
))
12141 /* Prevent various kinds of signals during display
12142 update. stdio is not robust about handling
12143 signals, which can cause an apparent I/O
12145 if (interrupt_input
)
12146 unrequest_sigio ();
12149 /* Update the display. */
12150 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12151 pause
|= update_frame (f
, 0, 0);
12157 if (!EQ (old_frame
, selected_frame
)
12158 && FRAME_LIVE_P (XFRAME (old_frame
)))
12159 /* We played a bit fast-and-loose above and allowed selected_frame
12160 and selected_window to be temporarily out-of-sync but let's make
12161 sure this stays contained. */
12162 select_frame_for_redisplay (old_frame
);
12163 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12167 /* Do the mark_window_display_accurate after all windows have
12168 been redisplayed because this call resets flags in buffers
12169 which are needed for proper redisplay. */
12170 FOR_EACH_FRAME (tail
, frame
)
12172 struct frame
*f
= XFRAME (frame
);
12175 mark_window_display_accurate (f
->root_window
, 1);
12176 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12177 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12182 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12184 Lisp_Object mini_window
;
12185 struct frame
*mini_frame
;
12187 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12188 /* Use list_of_error, not Qerror, so that
12189 we catch only errors and don't run the debugger. */
12190 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12192 redisplay_window_error
);
12194 /* Compare desired and current matrices, perform output. */
12197 /* If fonts changed, display again. */
12198 if (fonts_changed_p
)
12201 /* Prevent various kinds of signals during display update.
12202 stdio is not robust about handling signals,
12203 which can cause an apparent I/O error. */
12204 if (interrupt_input
)
12205 unrequest_sigio ();
12208 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12210 if (hscroll_windows (selected_window
))
12213 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12214 pause
= update_frame (sf
, 0, 0);
12217 /* We may have called echo_area_display at the top of this
12218 function. If the echo area is on another frame, that may
12219 have put text on a frame other than the selected one, so the
12220 above call to update_frame would not have caught it. Catch
12222 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12223 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12225 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12227 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12228 pause
|= update_frame (mini_frame
, 0, 0);
12229 if (!pause
&& hscroll_windows (mini_window
))
12234 /* If display was paused because of pending input, make sure we do a
12235 thorough update the next time. */
12238 /* Prevent the optimization at the beginning of
12239 redisplay_internal that tries a single-line update of the
12240 line containing the cursor in the selected window. */
12241 CHARPOS (this_line_start_pos
) = 0;
12243 /* Let the overlay arrow be updated the next time. */
12244 update_overlay_arrows (0);
12246 /* If we pause after scrolling, some rows in the current
12247 matrices of some windows are not valid. */
12248 if (!WINDOW_FULL_WIDTH_P (w
)
12249 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12250 update_mode_lines
= 1;
12254 if (!consider_all_windows_p
)
12256 /* This has already been done above if
12257 consider_all_windows_p is set. */
12258 mark_window_display_accurate_1 (w
, 1);
12260 /* Say overlay arrows are up to date. */
12261 update_overlay_arrows (1);
12263 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12264 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12267 update_mode_lines
= 0;
12268 windows_or_buffers_changed
= 0;
12269 cursor_type_changed
= 0;
12272 /* Start SIGIO interrupts coming again. Having them off during the
12273 code above makes it less likely one will discard output, but not
12274 impossible, since there might be stuff in the system buffer here.
12275 But it is much hairier to try to do anything about that. */
12276 if (interrupt_input
)
12280 /* If a frame has become visible which was not before, redisplay
12281 again, so that we display it. Expose events for such a frame
12282 (which it gets when becoming visible) don't call the parts of
12283 redisplay constructing glyphs, so simply exposing a frame won't
12284 display anything in this case. So, we have to display these
12285 frames here explicitly. */
12288 Lisp_Object tail
, frame
;
12291 FOR_EACH_FRAME (tail
, frame
)
12293 int this_is_visible
= 0;
12295 if (XFRAME (frame
)->visible
)
12296 this_is_visible
= 1;
12297 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12298 if (XFRAME (frame
)->visible
)
12299 this_is_visible
= 1;
12301 if (this_is_visible
)
12305 if (new_count
!= number_of_visible_frames
)
12306 windows_or_buffers_changed
++;
12309 /* Change frame size now if a change is pending. */
12310 do_pending_window_change (1);
12312 /* If we just did a pending size change, or have additional
12313 visible frames, redisplay again. */
12314 if (windows_or_buffers_changed
&& !pause
)
12317 /* Clear the face and image caches.
12319 We used to do this only if consider_all_windows_p. But the cache
12320 needs to be cleared if a timer creates images in the current
12321 buffer (e.g. the test case in Bug#6230). */
12323 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12325 clear_face_cache (0);
12326 clear_face_cache_count
= 0;
12329 #ifdef HAVE_WINDOW_SYSTEM
12330 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12332 clear_image_caches (Qnil
);
12333 clear_image_cache_count
= 0;
12335 #endif /* HAVE_WINDOW_SYSTEM */
12338 unbind_to (count
, Qnil
);
12343 /* Redisplay, but leave alone any recent echo area message unless
12344 another message has been requested in its place.
12346 This is useful in situations where you need to redisplay but no
12347 user action has occurred, making it inappropriate for the message
12348 area to be cleared. See tracking_off and
12349 wait_reading_process_output for examples of these situations.
12351 FROM_WHERE is an integer saying from where this function was
12352 called. This is useful for debugging. */
12355 redisplay_preserve_echo_area (int from_where
)
12357 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12359 if (!NILP (echo_area_buffer
[1]))
12361 /* We have a previously displayed message, but no current
12362 message. Redisplay the previous message. */
12363 display_last_displayed_message_p
= 1;
12364 redisplay_internal (1);
12365 display_last_displayed_message_p
= 0;
12368 redisplay_internal (1);
12370 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12371 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12372 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12376 /* Function registered with record_unwind_protect in
12377 redisplay_internal. Reset redisplaying_p to the value it had
12378 before redisplay_internal was called, and clear
12379 prevent_freeing_realized_faces_p. It also selects the previously
12380 selected frame, unless it has been deleted (by an X connection
12381 failure during redisplay, for example). */
12384 unwind_redisplay (Lisp_Object val
)
12386 Lisp_Object old_redisplaying_p
, old_frame
;
12388 old_redisplaying_p
= XCAR (val
);
12389 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12390 old_frame
= XCDR (val
);
12391 if (! EQ (old_frame
, selected_frame
)
12392 && FRAME_LIVE_P (XFRAME (old_frame
)))
12393 select_frame_for_redisplay (old_frame
);
12398 /* Mark the display of window W as accurate or inaccurate. If
12399 ACCURATE_P is non-zero mark display of W as accurate. If
12400 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12401 redisplay_internal is called. */
12404 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12406 if (BUFFERP (w
->buffer
))
12408 struct buffer
*b
= XBUFFER (w
->buffer
);
12411 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12412 w
->last_overlay_modified
12413 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12415 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12419 b
->clip_changed
= 0;
12420 b
->prevent_redisplay_optimizations_p
= 0;
12422 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12423 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12424 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12425 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12427 w
->current_matrix
->buffer
= b
;
12428 w
->current_matrix
->begv
= BUF_BEGV (b
);
12429 w
->current_matrix
->zv
= BUF_ZV (b
);
12431 w
->last_cursor
= w
->cursor
;
12432 w
->last_cursor_off_p
= w
->cursor_off_p
;
12434 if (w
== XWINDOW (selected_window
))
12435 w
->last_point
= make_number (BUF_PT (b
));
12437 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12443 w
->window_end_valid
= w
->buffer
;
12444 w
->update_mode_line
= Qnil
;
12449 /* Mark the display of windows in the window tree rooted at WINDOW as
12450 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12451 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12452 be redisplayed the next time redisplay_internal is called. */
12455 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12459 for (; !NILP (window
); window
= w
->next
)
12461 w
= XWINDOW (window
);
12462 mark_window_display_accurate_1 (w
, accurate_p
);
12464 if (!NILP (w
->vchild
))
12465 mark_window_display_accurate (w
->vchild
, accurate_p
);
12466 if (!NILP (w
->hchild
))
12467 mark_window_display_accurate (w
->hchild
, accurate_p
);
12472 update_overlay_arrows (1);
12476 /* Force a thorough redisplay the next time by setting
12477 last_arrow_position and last_arrow_string to t, which is
12478 unequal to any useful value of Voverlay_arrow_... */
12479 update_overlay_arrows (-1);
12484 /* Return value in display table DP (Lisp_Char_Table *) for character
12485 C. Since a display table doesn't have any parent, we don't have to
12486 follow parent. Do not call this function directly but use the
12487 macro DISP_CHAR_VECTOR. */
12490 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12494 if (ASCII_CHAR_P (c
))
12497 if (SUB_CHAR_TABLE_P (val
))
12498 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12504 XSETCHAR_TABLE (table
, dp
);
12505 val
= char_table_ref (table
, c
);
12514 /***********************************************************************
12516 ***********************************************************************/
12518 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12521 redisplay_windows (Lisp_Object window
)
12523 while (!NILP (window
))
12525 struct window
*w
= XWINDOW (window
);
12527 if (!NILP (w
->hchild
))
12528 redisplay_windows (w
->hchild
);
12529 else if (!NILP (w
->vchild
))
12530 redisplay_windows (w
->vchild
);
12531 else if (!NILP (w
->buffer
))
12533 displayed_buffer
= XBUFFER (w
->buffer
);
12534 /* Use list_of_error, not Qerror, so that
12535 we catch only errors and don't run the debugger. */
12536 internal_condition_case_1 (redisplay_window_0
, window
,
12538 redisplay_window_error
);
12546 redisplay_window_error (Lisp_Object ignore
)
12548 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12553 redisplay_window_0 (Lisp_Object window
)
12555 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12556 redisplay_window (window
, 0);
12561 redisplay_window_1 (Lisp_Object window
)
12563 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12564 redisplay_window (window
, 1);
12569 /* Increment GLYPH until it reaches END or CONDITION fails while
12570 adding (GLYPH)->pixel_width to X. */
12572 #define SKIP_GLYPHS(glyph, end, x, condition) \
12575 (x) += (glyph)->pixel_width; \
12578 while ((glyph) < (end) && (condition))
12581 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12582 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12583 which positions recorded in ROW differ from current buffer
12586 Return 0 if cursor is not on this row, 1 otherwise. */
12589 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
12590 struct glyph_matrix
*matrix
,
12591 EMACS_INT delta
, EMACS_INT delta_bytes
,
12594 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12595 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12596 struct glyph
*cursor
= NULL
;
12597 /* The last known character position in row. */
12598 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12600 EMACS_INT pt_old
= PT
- delta
;
12601 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12602 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12603 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12604 /* A glyph beyond the edge of TEXT_AREA which we should never
12606 struct glyph
*glyphs_end
= end
;
12607 /* Non-zero means we've found a match for cursor position, but that
12608 glyph has the avoid_cursor_p flag set. */
12609 int match_with_avoid_cursor
= 0;
12610 /* Non-zero means we've seen at least one glyph that came from a
12612 int string_seen
= 0;
12613 /* Largest and smalles buffer positions seen so far during scan of
12615 EMACS_INT bpos_max
= pos_before
;
12616 EMACS_INT bpos_min
= pos_after
;
12617 /* Last buffer position covered by an overlay string with an integer
12618 `cursor' property. */
12619 EMACS_INT bpos_covered
= 0;
12621 /* Skip over glyphs not having an object at the start and the end of
12622 the row. These are special glyphs like truncation marks on
12623 terminal frames. */
12624 if (row
->displays_text_p
)
12626 if (!row
->reversed_p
)
12629 && INTEGERP (glyph
->object
)
12630 && glyph
->charpos
< 0)
12632 x
+= glyph
->pixel_width
;
12636 && INTEGERP ((end
- 1)->object
)
12637 /* CHARPOS is zero for blanks and stretch glyphs
12638 inserted by extend_face_to_end_of_line. */
12639 && (end
- 1)->charpos
<= 0)
12641 glyph_before
= glyph
- 1;
12648 /* If the glyph row is reversed, we need to process it from back
12649 to front, so swap the edge pointers. */
12650 glyphs_end
= end
= glyph
- 1;
12651 glyph
+= row
->used
[TEXT_AREA
] - 1;
12653 while (glyph
> end
+ 1
12654 && INTEGERP (glyph
->object
)
12655 && glyph
->charpos
< 0)
12658 x
-= glyph
->pixel_width
;
12660 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12662 /* By default, in reversed rows we put the cursor on the
12663 rightmost (first in the reading order) glyph. */
12664 for (g
= end
+ 1; g
< glyph
; g
++)
12665 x
+= g
->pixel_width
;
12667 && INTEGERP ((end
+ 1)->object
)
12668 && (end
+ 1)->charpos
<= 0)
12670 glyph_before
= glyph
+ 1;
12674 else if (row
->reversed_p
)
12676 /* In R2L rows that don't display text, put the cursor on the
12677 rightmost glyph. Case in point: an empty last line that is
12678 part of an R2L paragraph. */
12680 /* Avoid placing the cursor on the last glyph of the row, where
12681 on terminal frames we hold the vertical border between
12682 adjacent windows. */
12683 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
12684 && !WINDOW_RIGHTMOST_P (w
)
12685 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
12687 x
= -1; /* will be computed below, at label compute_x */
12690 /* Step 1: Try to find the glyph whose character position
12691 corresponds to point. If that's not possible, find 2 glyphs
12692 whose character positions are the closest to point, one before
12693 point, the other after it. */
12694 if (!row
->reversed_p
)
12695 while (/* not marched to end of glyph row */
12697 /* glyph was not inserted by redisplay for internal purposes */
12698 && !INTEGERP (glyph
->object
))
12700 if (BUFFERP (glyph
->object
))
12702 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12704 if (glyph
->charpos
> bpos_max
)
12705 bpos_max
= glyph
->charpos
;
12706 if (glyph
->charpos
< bpos_min
)
12707 bpos_min
= glyph
->charpos
;
12708 if (!glyph
->avoid_cursor_p
)
12710 /* If we hit point, we've found the glyph on which to
12711 display the cursor. */
12714 match_with_avoid_cursor
= 0;
12717 /* See if we've found a better approximation to
12718 POS_BEFORE or to POS_AFTER. Note that we want the
12719 first (leftmost) glyph of all those that are the
12720 closest from below, and the last (rightmost) of all
12721 those from above. */
12722 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12724 pos_before
= glyph
->charpos
;
12725 glyph_before
= glyph
;
12727 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12729 pos_after
= glyph
->charpos
;
12730 glyph_after
= glyph
;
12733 else if (dpos
== 0)
12734 match_with_avoid_cursor
= 1;
12736 else if (STRINGP (glyph
->object
))
12738 Lisp_Object chprop
;
12739 EMACS_INT glyph_pos
= glyph
->charpos
;
12741 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12743 if (INTEGERP (chprop
))
12745 bpos_covered
= bpos_max
+ XINT (chprop
);
12746 /* If the `cursor' property covers buffer positions up
12747 to and including point, we should display cursor on
12748 this glyph. Note that overlays and text properties
12749 with string values stop bidi reordering, so every
12750 buffer position to the left of the string is always
12751 smaller than any position to the right of the
12752 string. Therefore, if a `cursor' property on one
12753 of the string's characters has an integer value, we
12754 will break out of the loop below _before_ we get to
12755 the position match above. IOW, integer values of
12756 the `cursor' property override the "exact match for
12757 point" strategy of positioning the cursor. */
12758 /* Implementation note: bpos_max == pt_old when, e.g.,
12759 we are in an empty line, where bpos_max is set to
12760 MATRIX_ROW_START_CHARPOS, see above. */
12761 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12770 x
+= glyph
->pixel_width
;
12773 else if (glyph
> end
) /* row is reversed */
12774 while (!INTEGERP (glyph
->object
))
12776 if (BUFFERP (glyph
->object
))
12778 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12780 if (glyph
->charpos
> bpos_max
)
12781 bpos_max
= glyph
->charpos
;
12782 if (glyph
->charpos
< bpos_min
)
12783 bpos_min
= glyph
->charpos
;
12784 if (!glyph
->avoid_cursor_p
)
12788 match_with_avoid_cursor
= 0;
12791 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12793 pos_before
= glyph
->charpos
;
12794 glyph_before
= glyph
;
12796 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12798 pos_after
= glyph
->charpos
;
12799 glyph_after
= glyph
;
12802 else if (dpos
== 0)
12803 match_with_avoid_cursor
= 1;
12805 else if (STRINGP (glyph
->object
))
12807 Lisp_Object chprop
;
12808 EMACS_INT glyph_pos
= glyph
->charpos
;
12810 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12812 if (INTEGERP (chprop
))
12814 bpos_covered
= bpos_max
+ XINT (chprop
);
12815 /* If the `cursor' property covers buffer positions up
12816 to and including point, we should display cursor on
12818 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12827 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
12829 x
--; /* can't use any pixel_width */
12832 x
-= glyph
->pixel_width
;
12835 /* Step 2: If we didn't find an exact match for point, we need to
12836 look for a proper place to put the cursor among glyphs between
12837 GLYPH_BEFORE and GLYPH_AFTER. */
12838 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12839 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12840 && bpos_covered
< pt_old
)
12842 /* An empty line has a single glyph whose OBJECT is zero and
12843 whose CHARPOS is the position of a newline on that line.
12844 Note that on a TTY, there are more glyphs after that, which
12845 were produced by extend_face_to_end_of_line, but their
12846 CHARPOS is zero or negative. */
12848 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12849 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
12851 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12853 EMACS_INT ellipsis_pos
;
12855 /* Scan back over the ellipsis glyphs. */
12856 if (!row
->reversed_p
)
12858 ellipsis_pos
= (glyph
- 1)->charpos
;
12859 while (glyph
> row
->glyphs
[TEXT_AREA
]
12860 && (glyph
- 1)->charpos
== ellipsis_pos
)
12861 glyph
--, x
-= glyph
->pixel_width
;
12862 /* That loop always goes one position too far, including
12863 the glyph before the ellipsis. So scan forward over
12865 x
+= glyph
->pixel_width
;
12868 else /* row is reversed */
12870 ellipsis_pos
= (glyph
+ 1)->charpos
;
12871 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12872 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12873 glyph
++, x
+= glyph
->pixel_width
;
12874 x
-= glyph
->pixel_width
;
12878 else if (match_with_avoid_cursor
12879 /* A truncated row may not include PT among its
12880 character positions. Setting the cursor inside the
12881 scroll margin will trigger recalculation of hscroll
12882 in hscroll_window_tree. */
12883 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
12884 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
12885 /* Zero-width characters produce no glyphs. */
12888 && (row
->reversed_p
12889 ? glyph_after
> glyphs_end
12890 : glyph_after
< glyphs_end
)))
12892 cursor
= glyph_after
;
12895 else if (string_seen
)
12897 int incr
= row
->reversed_p
? -1 : +1;
12899 /* Need to find the glyph that came out of a string which is
12900 present at point. That glyph is somewhere between
12901 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12902 positioned between POS_BEFORE and POS_AFTER in the
12904 struct glyph
*stop
= glyph_after
;
12905 EMACS_INT pos
= pos_before
;
12908 for (glyph
= glyph_before
+ incr
;
12909 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12912 /* Any glyphs that come from the buffer are here because
12913 of bidi reordering. Skip them, and only pay
12914 attention to glyphs that came from some string. */
12915 if (STRINGP (glyph
->object
))
12920 str
= glyph
->object
;
12921 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12922 if (tem
== 0 /* from overlay */
12925 /* If the string from which this glyph came is
12926 found in the buffer at point, then we've
12927 found the glyph we've been looking for. If
12928 it comes from an overlay (tem == 0), and it
12929 has the `cursor' property on one of its
12930 glyphs, record that glyph as a candidate for
12931 displaying the cursor. (As in the
12932 unidirectional version, we will display the
12933 cursor on the last candidate we find.) */
12934 if (tem
== 0 || tem
== pt_old
)
12936 /* The glyphs from this string could have
12937 been reordered. Find the one with the
12938 smallest string position. Or there could
12939 be a character in the string with the
12940 `cursor' property, which means display
12941 cursor on that character's glyph. */
12942 EMACS_INT strpos
= glyph
->charpos
;
12946 for (glyph
+= incr
;
12947 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12948 && EQ (glyph
->object
, str
);
12952 EMACS_INT gpos
= glyph
->charpos
;
12954 cprop
= Fget_char_property (make_number (gpos
),
12962 if (tem
&& glyph
->charpos
< strpos
)
12964 strpos
= glyph
->charpos
;
12973 pos
= tem
+ 1; /* don't find previous instances */
12975 /* This string is not what we want; skip all of the
12976 glyphs that came from it. */
12977 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12978 && EQ (glyph
->object
, str
))
12985 /* If we reached the end of the line, and END was from a string,
12986 the cursor is not on this line. */
12988 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
12989 && STRINGP (end
->object
)
12990 && row
->continued_p
)
12996 if (cursor
!= NULL
)
13002 /* Need to compute x that corresponds to GLYPH. */
13003 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
13005 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
13007 x
+= g
->pixel_width
;
13011 /* ROW could be part of a continued line, which, under bidi
13012 reordering, might have other rows whose start and end charpos
13013 occlude point. Only set w->cursor if we found a better
13014 approximation to the cursor position than we have from previously
13015 examined candidate rows belonging to the same continued line. */
13016 if (/* we already have a candidate row */
13017 w
->cursor
.vpos
>= 0
13018 /* that candidate is not the row we are processing */
13019 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
13020 /* the row we are processing is part of a continued line */
13021 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
13022 /* Make sure cursor.vpos specifies a row whose start and end
13023 charpos occlude point. This is because some callers of this
13024 function leave cursor.vpos at the row where the cursor was
13025 displayed during the last redisplay cycle. */
13026 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13027 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13030 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13032 /* Don't consider glyphs that are outside TEXT_AREA. */
13033 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13035 /* Keep the candidate whose buffer position is the closest to
13037 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13038 w
->cursor
.hpos
>= 0
13039 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13040 && BUFFERP (g1
->object
)
13041 && (g1
->charpos
== pt_old
/* an exact match always wins */
13042 || (BUFFERP (glyph
->object
)
13043 && eabs (g1
->charpos
- pt_old
)
13044 < eabs (glyph
->charpos
- pt_old
))))
13046 /* If this candidate gives an exact match, use that. */
13047 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13048 /* Otherwise, keep the candidate that comes from a row
13049 spanning less buffer positions. This may win when one or
13050 both candidate positions are on glyphs that came from
13051 display strings, for which we cannot compare buffer
13053 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13054 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13055 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13058 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13060 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13061 w
->cursor
.y
= row
->y
+ dy
;
13063 if (w
== XWINDOW (selected_window
))
13065 if (!row
->continued_p
13066 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13069 this_line_buffer
= XBUFFER (w
->buffer
);
13071 CHARPOS (this_line_start_pos
)
13072 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13073 BYTEPOS (this_line_start_pos
)
13074 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13076 CHARPOS (this_line_end_pos
)
13077 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13078 BYTEPOS (this_line_end_pos
)
13079 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13081 this_line_y
= w
->cursor
.y
;
13082 this_line_pixel_height
= row
->height
;
13083 this_line_vpos
= w
->cursor
.vpos
;
13084 this_line_start_x
= row
->x
;
13087 CHARPOS (this_line_start_pos
) = 0;
13094 /* Run window scroll functions, if any, for WINDOW with new window
13095 start STARTP. Sets the window start of WINDOW to that position.
13097 We assume that the window's buffer is really current. */
13099 static INLINE
struct text_pos
13100 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13102 struct window
*w
= XWINDOW (window
);
13103 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13105 if (current_buffer
!= XBUFFER (w
->buffer
))
13108 if (!NILP (Vwindow_scroll_functions
))
13110 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13111 make_number (CHARPOS (startp
)));
13112 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13113 /* In case the hook functions switch buffers. */
13114 if (current_buffer
!= XBUFFER (w
->buffer
))
13115 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13122 /* Make sure the line containing the cursor is fully visible.
13123 A value of 1 means there is nothing to be done.
13124 (Either the line is fully visible, or it cannot be made so,
13125 or we cannot tell.)
13127 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13128 is higher than window.
13130 A value of 0 means the caller should do scrolling
13131 as if point had gone off the screen. */
13134 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13136 struct glyph_matrix
*matrix
;
13137 struct glyph_row
*row
;
13140 if (!make_cursor_line_fully_visible_p
)
13143 /* It's not always possible to find the cursor, e.g, when a window
13144 is full of overlay strings. Don't do anything in that case. */
13145 if (w
->cursor
.vpos
< 0)
13148 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13149 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13151 /* If the cursor row is not partially visible, there's nothing to do. */
13152 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13155 /* If the row the cursor is in is taller than the window's height,
13156 it's not clear what to do, so do nothing. */
13157 window_height
= window_box_height (w
);
13158 if (row
->height
>= window_height
)
13160 if (!force_p
|| MINI_WINDOW_P (w
)
13161 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13168 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13169 non-zero means only WINDOW is redisplayed in redisplay_internal.
13170 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13171 in redisplay_window to bring a partially visible line into view in
13172 the case that only the cursor has moved.
13174 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13175 last screen line's vertical height extends past the end of the screen.
13179 1 if scrolling succeeded
13181 0 if scrolling didn't find point.
13183 -1 if new fonts have been loaded so that we must interrupt
13184 redisplay, adjust glyph matrices, and try again. */
13190 SCROLLING_NEED_LARGER_MATRICES
13194 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13195 EMACS_INT scroll_conservatively
, EMACS_INT scroll_step
,
13196 int temp_scroll_step
, int last_line_misfit
)
13198 struct window
*w
= XWINDOW (window
);
13199 struct frame
*f
= XFRAME (w
->frame
);
13200 struct text_pos pos
, startp
;
13202 int this_scroll_margin
, scroll_max
, rc
, height
;
13203 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13204 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13205 Lisp_Object aggressive
;
13206 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13209 debug_method_add (w
, "try_scrolling");
13212 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13214 /* Compute scroll margin height in pixels. We scroll when point is
13215 within this distance from the top or bottom of the window. */
13216 if (scroll_margin
> 0)
13217 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13218 * FRAME_LINE_HEIGHT (f
);
13220 this_scroll_margin
= 0;
13222 /* Force scroll_conservatively to have a reasonable value, to avoid
13223 overflow while computing how much to scroll. Note that the user
13224 can supply scroll-conservatively equal to `most-positive-fixnum',
13225 which can be larger than INT_MAX. */
13226 if (scroll_conservatively
> scroll_limit
)
13228 scroll_conservatively
= scroll_limit
;
13229 scroll_max
= INT_MAX
;
13231 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13232 /* Compute how much we should try to scroll maximally to bring
13233 point into view. */
13234 scroll_max
= (max (scroll_step
,
13235 max (scroll_conservatively
, temp_scroll_step
))
13236 * FRAME_LINE_HEIGHT (f
));
13237 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13238 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13239 /* We're trying to scroll because of aggressive scrolling but no
13240 scroll_step is set. Choose an arbitrary one. */
13241 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13247 /* Decide whether to scroll down. */
13248 if (PT
> CHARPOS (startp
))
13250 int scroll_margin_y
;
13252 /* Compute the pixel ypos of the scroll margin, then move it to
13253 either that ypos or PT, whichever comes first. */
13254 start_display (&it
, w
, startp
);
13255 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13256 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13257 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13258 (MOVE_TO_POS
| MOVE_TO_Y
));
13260 if (PT
> CHARPOS (it
.current
.pos
))
13262 int y0
= line_bottom_y (&it
);
13263 /* Compute how many pixels below window bottom to stop searching
13264 for PT. This avoids costly search for PT that is far away if
13265 the user limited scrolling by a small number of lines, but
13266 always finds PT if scroll_conservatively is set to a large
13267 number, such as most-positive-fixnum. */
13268 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13270 slack
>= INT_MAX
- it
.last_visible_y
13272 : it
.last_visible_y
+ slack
;
13274 /* Compute the distance from the scroll margin to PT or to
13275 the scroll limit, whichever comes first. This should
13276 include the height of the cursor line, to make that line
13278 move_it_to (&it
, PT
, -1, y_to_move
,
13279 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13280 dy
= line_bottom_y (&it
) - y0
;
13282 if (dy
> scroll_max
)
13283 return SCROLLING_FAILED
;
13291 /* Point is in or below the bottom scroll margin, so move the
13292 window start down. If scrolling conservatively, move it just
13293 enough down to make point visible. If scroll_step is set,
13294 move it down by scroll_step. */
13295 if (scroll_conservatively
)
13297 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13298 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13299 else if (scroll_step
|| temp_scroll_step
)
13300 amount_to_scroll
= scroll_max
;
13303 aggressive
= current_buffer
->scroll_up_aggressively
;
13304 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13305 if (NUMBERP (aggressive
))
13307 double float_amount
= XFLOATINT (aggressive
) * height
;
13308 amount_to_scroll
= float_amount
;
13309 if (amount_to_scroll
== 0 && float_amount
> 0)
13310 amount_to_scroll
= 1;
13314 if (amount_to_scroll
<= 0)
13315 return SCROLLING_FAILED
;
13317 start_display (&it
, w
, startp
);
13318 if (scroll_max
< INT_MAX
)
13319 move_it_vertically (&it
, amount_to_scroll
);
13322 /* Extra precision for users who set scroll-conservatively
13323 to most-positive-fixnum: make sure the amount we scroll
13324 the window start is never less than amount_to_scroll,
13325 which was computed as distance from window bottom to
13326 point. This matters when lines at window top and lines
13327 below window bottom have different height. */
13328 struct it it1
= it
;
13329 /* We use a temporary it1 because line_bottom_y can modify
13330 its argument, if it moves one line down; see there. */
13331 int start_y
= line_bottom_y (&it1
);
13334 move_it_by_lines (&it
, 1, 1);
13336 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13339 /* If STARTP is unchanged, move it down another screen line. */
13340 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13341 move_it_by_lines (&it
, 1, 1);
13342 startp
= it
.current
.pos
;
13346 struct text_pos scroll_margin_pos
= startp
;
13348 /* See if point is inside the scroll margin at the top of the
13350 if (this_scroll_margin
)
13352 start_display (&it
, w
, startp
);
13353 move_it_vertically (&it
, this_scroll_margin
);
13354 scroll_margin_pos
= it
.current
.pos
;
13357 if (PT
< CHARPOS (scroll_margin_pos
))
13359 /* Point is in the scroll margin at the top of the window or
13360 above what is displayed in the window. */
13363 /* Compute the vertical distance from PT to the scroll
13364 margin position. Give up if distance is greater than
13366 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13367 start_display (&it
, w
, pos
);
13369 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13370 it
.last_visible_y
, -1,
13371 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13372 dy
= it
.current_y
- y0
;
13373 if (dy
> scroll_max
)
13374 return SCROLLING_FAILED
;
13376 /* Compute new window start. */
13377 start_display (&it
, w
, startp
);
13379 if (scroll_conservatively
)
13381 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13382 else if (scroll_step
|| temp_scroll_step
)
13383 amount_to_scroll
= scroll_max
;
13386 aggressive
= current_buffer
->scroll_down_aggressively
;
13387 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13388 if (NUMBERP (aggressive
))
13390 double float_amount
= XFLOATINT (aggressive
) * height
;
13391 amount_to_scroll
= float_amount
;
13392 if (amount_to_scroll
== 0 && float_amount
> 0)
13393 amount_to_scroll
= 1;
13397 if (amount_to_scroll
<= 0)
13398 return SCROLLING_FAILED
;
13400 move_it_vertically_backward (&it
, amount_to_scroll
);
13401 startp
= it
.current
.pos
;
13405 /* Run window scroll functions. */
13406 startp
= run_window_scroll_functions (window
, startp
);
13408 /* Display the window. Give up if new fonts are loaded, or if point
13410 if (!try_window (window
, startp
, 0))
13411 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13412 else if (w
->cursor
.vpos
< 0)
13414 clear_glyph_matrix (w
->desired_matrix
);
13415 rc
= SCROLLING_FAILED
;
13419 /* Maybe forget recorded base line for line number display. */
13420 if (!just_this_one_p
13421 || current_buffer
->clip_changed
13422 || BEG_UNCHANGED
< CHARPOS (startp
))
13423 w
->base_line_number
= Qnil
;
13425 /* If cursor ends up on a partially visible line,
13426 treat that as being off the bottom of the screen. */
13427 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13429 clear_glyph_matrix (w
->desired_matrix
);
13430 ++extra_scroll_margin_lines
;
13433 rc
= SCROLLING_SUCCESS
;
13440 /* Compute a suitable window start for window W if display of W starts
13441 on a continuation line. Value is non-zero if a new window start
13444 The new window start will be computed, based on W's width, starting
13445 from the start of the continued line. It is the start of the
13446 screen line with the minimum distance from the old start W->start. */
13449 compute_window_start_on_continuation_line (struct window
*w
)
13451 struct text_pos pos
, start_pos
;
13452 int window_start_changed_p
= 0;
13454 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13456 /* If window start is on a continuation line... Window start may be
13457 < BEGV in case there's invisible text at the start of the
13458 buffer (M-x rmail, for example). */
13459 if (CHARPOS (start_pos
) > BEGV
13460 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13463 struct glyph_row
*row
;
13465 /* Handle the case that the window start is out of range. */
13466 if (CHARPOS (start_pos
) < BEGV
)
13467 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13468 else if (CHARPOS (start_pos
) > ZV
)
13469 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13471 /* Find the start of the continued line. This should be fast
13472 because scan_buffer is fast (newline cache). */
13473 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13474 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13475 row
, DEFAULT_FACE_ID
);
13476 reseat_at_previous_visible_line_start (&it
);
13478 /* If the line start is "too far" away from the window start,
13479 say it takes too much time to compute a new window start. */
13480 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13481 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13483 int min_distance
, distance
;
13485 /* Move forward by display lines to find the new window
13486 start. If window width was enlarged, the new start can
13487 be expected to be > the old start. If window width was
13488 decreased, the new window start will be < the old start.
13489 So, we're looking for the display line start with the
13490 minimum distance from the old window start. */
13491 pos
= it
.current
.pos
;
13492 min_distance
= INFINITY
;
13493 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13494 distance
< min_distance
)
13496 min_distance
= distance
;
13497 pos
= it
.current
.pos
;
13498 move_it_by_lines (&it
, 1, 0);
13501 /* Set the window start there. */
13502 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13503 window_start_changed_p
= 1;
13507 return window_start_changed_p
;
13511 /* Try cursor movement in case text has not changed in window WINDOW,
13512 with window start STARTP. Value is
13514 CURSOR_MOVEMENT_SUCCESS if successful
13516 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13518 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13519 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13520 we want to scroll as if scroll-step were set to 1. See the code.
13522 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13523 which case we have to abort this redisplay, and adjust matrices
13528 CURSOR_MOVEMENT_SUCCESS
,
13529 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13530 CURSOR_MOVEMENT_MUST_SCROLL
,
13531 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13535 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13537 struct window
*w
= XWINDOW (window
);
13538 struct frame
*f
= XFRAME (w
->frame
);
13539 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13542 if (inhibit_try_cursor_movement
)
13546 /* Handle case where text has not changed, only point, and it has
13547 not moved off the frame. */
13548 if (/* Point may be in this window. */
13549 PT
>= CHARPOS (startp
)
13550 /* Selective display hasn't changed. */
13551 && !current_buffer
->clip_changed
13552 /* Function force-mode-line-update is used to force a thorough
13553 redisplay. It sets either windows_or_buffers_changed or
13554 update_mode_lines. So don't take a shortcut here for these
13556 && !update_mode_lines
13557 && !windows_or_buffers_changed
13558 && !cursor_type_changed
13559 /* Can't use this case if highlighting a region. When a
13560 region exists, cursor movement has to do more than just
13562 && !(!NILP (Vtransient_mark_mode
)
13563 && !NILP (current_buffer
->mark_active
))
13564 && NILP (w
->region_showing
)
13565 && NILP (Vshow_trailing_whitespace
)
13566 /* Right after splitting windows, last_point may be nil. */
13567 && INTEGERP (w
->last_point
)
13568 /* This code is not used for mini-buffer for the sake of the case
13569 of redisplaying to replace an echo area message; since in
13570 that case the mini-buffer contents per se are usually
13571 unchanged. This code is of no real use in the mini-buffer
13572 since the handling of this_line_start_pos, etc., in redisplay
13573 handles the same cases. */
13574 && !EQ (window
, minibuf_window
)
13575 /* When splitting windows or for new windows, it happens that
13576 redisplay is called with a nil window_end_vpos or one being
13577 larger than the window. This should really be fixed in
13578 window.c. I don't have this on my list, now, so we do
13579 approximately the same as the old redisplay code. --gerd. */
13580 && INTEGERP (w
->window_end_vpos
)
13581 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13582 && (FRAME_WINDOW_P (f
)
13583 || !overlay_arrow_in_current_buffer_p ()))
13585 int this_scroll_margin
, top_scroll_margin
;
13586 struct glyph_row
*row
= NULL
;
13589 debug_method_add (w
, "cursor movement");
13592 /* Scroll if point within this distance from the top or bottom
13593 of the window. This is a pixel value. */
13594 if (scroll_margin
> 0)
13596 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13597 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13600 this_scroll_margin
= 0;
13602 top_scroll_margin
= this_scroll_margin
;
13603 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13604 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13606 /* Start with the row the cursor was displayed during the last
13607 not paused redisplay. Give up if that row is not valid. */
13608 if (w
->last_cursor
.vpos
< 0
13609 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13610 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13613 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13614 if (row
->mode_line_p
)
13616 if (!row
->enabled_p
)
13617 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13620 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13622 int scroll_p
= 0, must_scroll
= 0;
13623 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13625 if (PT
> XFASTINT (w
->last_point
))
13627 /* Point has moved forward. */
13628 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13629 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13631 xassert (row
->enabled_p
);
13635 /* If the end position of a row equals the start
13636 position of the next row, and PT is at that position,
13637 we would rather display cursor in the next line. */
13638 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13639 && MATRIX_ROW_END_CHARPOS (row
) == PT
13640 && row
< w
->current_matrix
->rows
13641 + w
->current_matrix
->nrows
- 1
13642 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
13643 && !cursor_row_p (w
, row
))
13646 /* If within the scroll margin, scroll. Note that
13647 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13648 the next line would be drawn, and that
13649 this_scroll_margin can be zero. */
13650 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13651 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13652 /* Line is completely visible last line in window
13653 and PT is to be set in the next line. */
13654 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13655 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13656 && !row
->ends_at_zv_p
13657 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13660 else if (PT
< XFASTINT (w
->last_point
))
13662 /* Cursor has to be moved backward. Note that PT >=
13663 CHARPOS (startp) because of the outer if-statement. */
13664 while (!row
->mode_line_p
13665 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13666 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13667 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13668 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13669 row
> w
->current_matrix
->rows
13670 && (row
-1)->ends_in_newline_from_string_p
))))
13671 && (row
->y
> top_scroll_margin
13672 || CHARPOS (startp
) == BEGV
))
13674 xassert (row
->enabled_p
);
13678 /* Consider the following case: Window starts at BEGV,
13679 there is invisible, intangible text at BEGV, so that
13680 display starts at some point START > BEGV. It can
13681 happen that we are called with PT somewhere between
13682 BEGV and START. Try to handle that case. */
13683 if (row
< w
->current_matrix
->rows
13684 || row
->mode_line_p
)
13686 row
= w
->current_matrix
->rows
;
13687 if (row
->mode_line_p
)
13691 /* Due to newlines in overlay strings, we may have to
13692 skip forward over overlay strings. */
13693 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13694 && MATRIX_ROW_END_CHARPOS (row
) == PT
13695 && !cursor_row_p (w
, row
))
13698 /* If within the scroll margin, scroll. */
13699 if (row
->y
< top_scroll_margin
13700 && CHARPOS (startp
) != BEGV
)
13705 /* Cursor did not move. So don't scroll even if cursor line
13706 is partially visible, as it was so before. */
13707 rc
= CURSOR_MOVEMENT_SUCCESS
;
13710 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13711 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13713 /* if PT is not in the glyph row, give up. */
13714 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13717 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13718 && !NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13720 /* If rows are bidi-reordered and point moved, back up
13721 until we find a row that does not belong to a
13722 continuation line. This is because we must consider
13723 all rows of a continued line as candidates for the
13724 new cursor positioning, since row start and end
13725 positions change non-linearly with vertical position
13727 /* FIXME: Revisit this when glyph ``spilling'' in
13728 continuation lines' rows is implemented for
13729 bidi-reordered rows. */
13730 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13732 xassert (row
->enabled_p
);
13734 /* If we hit the beginning of the displayed portion
13735 without finding the first row of a continued
13737 if (row
<= w
->current_matrix
->rows
)
13739 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13747 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13748 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13749 && make_cursor_line_fully_visible_p
)
13751 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13752 && !row
->ends_at_zv_p
13753 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13754 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13755 else if (row
->height
> window_box_height (w
))
13757 /* If we end up in a partially visible line, let's
13758 make it fully visible, except when it's taller
13759 than the window, in which case we can't do much
13762 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13766 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13767 if (!cursor_row_fully_visible_p (w
, 0, 1))
13768 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13770 rc
= CURSOR_MOVEMENT_SUCCESS
;
13774 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13775 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13776 && !NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13778 /* With bidi-reordered rows, there could be more than
13779 one candidate row whose start and end positions
13780 occlude point. We need to let set_cursor_from_row
13781 find the best candidate. */
13782 /* FIXME: Revisit this when glyph ``spilling'' in
13783 continuation lines' rows is implemented for
13784 bidi-reordered rows. */
13789 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
13790 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13791 && cursor_row_p (w
, row
))
13792 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13794 /* As soon as we've found the first suitable row
13795 whose ends_at_zv_p flag is set, we are done. */
13797 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13799 rc
= CURSOR_MOVEMENT_SUCCESS
;
13804 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
13805 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
13806 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13807 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
13808 /* If we didn't find any candidate rows, or exited the
13809 loop before all the candidates were examined, signal
13810 to the caller that this method failed. */
13811 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13812 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
13813 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13815 rc
= CURSOR_MOVEMENT_SUCCESS
;
13821 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13823 rc
= CURSOR_MOVEMENT_SUCCESS
;
13828 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13829 && MATRIX_ROW_START_CHARPOS (row
) == PT
13830 && cursor_row_p (w
, row
));
13839 set_vertical_scroll_bar (struct window
*w
)
13841 EMACS_INT start
, end
, whole
;
13843 /* Calculate the start and end positions for the current window.
13844 At some point, it would be nice to choose between scrollbars
13845 which reflect the whole buffer size, with special markers
13846 indicating narrowing, and scrollbars which reflect only the
13849 Note that mini-buffers sometimes aren't displaying any text. */
13850 if (!MINI_WINDOW_P (w
)
13851 || (w
== XWINDOW (minibuf_window
)
13852 && NILP (echo_area_buffer
[0])))
13854 struct buffer
*buf
= XBUFFER (w
->buffer
);
13855 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13856 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13857 /* I don't think this is guaranteed to be right. For the
13858 moment, we'll pretend it is. */
13859 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13863 if (whole
< (end
- start
))
13864 whole
= end
- start
;
13867 start
= end
= whole
= 0;
13869 /* Indicate what this scroll bar ought to be displaying now. */
13870 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13871 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13872 (w
, end
- start
, whole
, start
);
13876 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13877 selected_window is redisplayed.
13879 We can return without actually redisplaying the window if
13880 fonts_changed_p is nonzero. In that case, redisplay_internal will
13884 redisplay_window (Lisp_Object window
, int just_this_one_p
)
13886 struct window
*w
= XWINDOW (window
);
13887 struct frame
*f
= XFRAME (w
->frame
);
13888 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13889 struct buffer
*old
= current_buffer
;
13890 struct text_pos lpoint
, opoint
, startp
;
13891 int update_mode_line
;
13894 /* Record it now because it's overwritten. */
13895 int current_matrix_up_to_date_p
= 0;
13896 int used_current_matrix_p
= 0;
13897 /* This is less strict than current_matrix_up_to_date_p.
13898 It indictes that the buffer contents and narrowing are unchanged. */
13899 int buffer_unchanged_p
= 0;
13900 int temp_scroll_step
= 0;
13901 int count
= SPECPDL_INDEX ();
13903 int centering_position
= -1;
13904 int last_line_misfit
= 0;
13905 EMACS_INT beg_unchanged
, end_unchanged
;
13907 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13910 /* W must be a leaf window here. */
13911 xassert (!NILP (w
->buffer
));
13913 *w
->desired_matrix
->method
= 0;
13917 reconsider_clip_changes (w
, buffer
);
13919 /* Has the mode line to be updated? */
13920 update_mode_line
= (!NILP (w
->update_mode_line
)
13921 || update_mode_lines
13922 || buffer
->clip_changed
13923 || buffer
->prevent_redisplay_optimizations_p
);
13925 if (MINI_WINDOW_P (w
))
13927 if (w
== XWINDOW (echo_area_window
)
13928 && !NILP (echo_area_buffer
[0]))
13930 if (update_mode_line
)
13931 /* We may have to update a tty frame's menu bar or a
13932 tool-bar. Example `M-x C-h C-h C-g'. */
13933 goto finish_menu_bars
;
13935 /* We've already displayed the echo area glyphs in this window. */
13936 goto finish_scroll_bars
;
13938 else if ((w
!= XWINDOW (minibuf_window
)
13939 || minibuf_level
== 0)
13940 /* When buffer is nonempty, redisplay window normally. */
13941 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13942 /* Quail displays non-mini buffers in minibuffer window.
13943 In that case, redisplay the window normally. */
13944 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13946 /* W is a mini-buffer window, but it's not active, so clear
13948 int yb
= window_text_bottom_y (w
);
13949 struct glyph_row
*row
;
13952 for (y
= 0, row
= w
->desired_matrix
->rows
;
13954 y
+= row
->height
, ++row
)
13955 blank_row (w
, row
, y
);
13956 goto finish_scroll_bars
;
13959 clear_glyph_matrix (w
->desired_matrix
);
13962 /* Otherwise set up data on this window; select its buffer and point
13964 /* Really select the buffer, for the sake of buffer-local
13966 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13968 current_matrix_up_to_date_p
13969 = (!NILP (w
->window_end_valid
)
13970 && !current_buffer
->clip_changed
13971 && !current_buffer
->prevent_redisplay_optimizations_p
13972 && XFASTINT (w
->last_modified
) >= MODIFF
13973 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13975 /* Run the window-bottom-change-functions
13976 if it is possible that the text on the screen has changed
13977 (either due to modification of the text, or any other reason). */
13978 if (!current_matrix_up_to_date_p
13979 && !NILP (Vwindow_text_change_functions
))
13981 safe_run_hooks (Qwindow_text_change_functions
);
13985 beg_unchanged
= BEG_UNCHANGED
;
13986 end_unchanged
= END_UNCHANGED
;
13988 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13990 specbind (Qinhibit_point_motion_hooks
, Qt
);
13993 = (!NILP (w
->window_end_valid
)
13994 && !current_buffer
->clip_changed
13995 && XFASTINT (w
->last_modified
) >= MODIFF
13996 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13998 /* When windows_or_buffers_changed is non-zero, we can't rely on
13999 the window end being valid, so set it to nil there. */
14000 if (windows_or_buffers_changed
)
14002 /* If window starts on a continuation line, maybe adjust the
14003 window start in case the window's width changed. */
14004 if (XMARKER (w
->start
)->buffer
== current_buffer
)
14005 compute_window_start_on_continuation_line (w
);
14007 w
->window_end_valid
= Qnil
;
14010 /* Some sanity checks. */
14011 CHECK_WINDOW_END (w
);
14012 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14014 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14017 /* If %c is in mode line, update it if needed. */
14018 if (!NILP (w
->column_number_displayed
)
14019 /* This alternative quickly identifies a common case
14020 where no change is needed. */
14021 && !(PT
== XFASTINT (w
->last_point
)
14022 && XFASTINT (w
->last_modified
) >= MODIFF
14023 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14024 && (XFASTINT (w
->column_number_displayed
)
14025 != (int) current_column ())) /* iftc */
14026 update_mode_line
= 1;
14028 /* Count number of windows showing the selected buffer. An indirect
14029 buffer counts as its base buffer. */
14030 if (!just_this_one_p
)
14032 struct buffer
*current_base
, *window_base
;
14033 current_base
= current_buffer
;
14034 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14035 if (current_base
->base_buffer
)
14036 current_base
= current_base
->base_buffer
;
14037 if (window_base
->base_buffer
)
14038 window_base
= window_base
->base_buffer
;
14039 if (current_base
== window_base
)
14043 /* Point refers normally to the selected window. For any other
14044 window, set up appropriate value. */
14045 if (!EQ (window
, selected_window
))
14047 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14048 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14052 new_pt_byte
= BEGV_BYTE
;
14053 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14055 else if (new_pt
> (ZV
- 1))
14058 new_pt_byte
= ZV_BYTE
;
14059 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14062 /* We don't use SET_PT so that the point-motion hooks don't run. */
14063 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14066 /* If any of the character widths specified in the display table
14067 have changed, invalidate the width run cache. It's true that
14068 this may be a bit late to catch such changes, but the rest of
14069 redisplay goes (non-fatally) haywire when the display table is
14070 changed, so why should we worry about doing any better? */
14071 if (current_buffer
->width_run_cache
)
14073 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14075 if (! disptab_matches_widthtab (disptab
,
14076 XVECTOR (current_buffer
->width_table
)))
14078 invalidate_region_cache (current_buffer
,
14079 current_buffer
->width_run_cache
,
14081 recompute_width_table (current_buffer
, disptab
);
14085 /* If window-start is screwed up, choose a new one. */
14086 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14089 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14091 /* If someone specified a new starting point but did not insist,
14092 check whether it can be used. */
14093 if (!NILP (w
->optional_new_start
)
14094 && CHARPOS (startp
) >= BEGV
14095 && CHARPOS (startp
) <= ZV
)
14097 w
->optional_new_start
= Qnil
;
14098 start_display (&it
, w
, startp
);
14099 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14100 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14101 if (IT_CHARPOS (it
) == PT
)
14102 w
->force_start
= Qt
;
14103 /* IT may overshoot PT if text at PT is invisible. */
14104 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14105 w
->force_start
= Qt
;
14110 /* Handle case where place to start displaying has been specified,
14111 unless the specified location is outside the accessible range. */
14112 if (!NILP (w
->force_start
)
14113 || w
->frozen_window_start_p
)
14115 /* We set this later on if we have to adjust point. */
14118 w
->force_start
= Qnil
;
14120 w
->window_end_valid
= Qnil
;
14122 /* Forget any recorded base line for line number display. */
14123 if (!buffer_unchanged_p
)
14124 w
->base_line_number
= Qnil
;
14126 /* Redisplay the mode line. Select the buffer properly for that.
14127 Also, run the hook window-scroll-functions
14128 because we have scrolled. */
14129 /* Note, we do this after clearing force_start because
14130 if there's an error, it is better to forget about force_start
14131 than to get into an infinite loop calling the hook functions
14132 and having them get more errors. */
14133 if (!update_mode_line
14134 || ! NILP (Vwindow_scroll_functions
))
14136 update_mode_line
= 1;
14137 w
->update_mode_line
= Qt
;
14138 startp
= run_window_scroll_functions (window
, startp
);
14141 w
->last_modified
= make_number (0);
14142 w
->last_overlay_modified
= make_number (0);
14143 if (CHARPOS (startp
) < BEGV
)
14144 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14145 else if (CHARPOS (startp
) > ZV
)
14146 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14148 /* Redisplay, then check if cursor has been set during the
14149 redisplay. Give up if new fonts were loaded. */
14150 /* We used to issue a CHECK_MARGINS argument to try_window here,
14151 but this causes scrolling to fail when point begins inside
14152 the scroll margin (bug#148) -- cyd */
14153 if (!try_window (window
, startp
, 0))
14155 w
->force_start
= Qt
;
14156 clear_glyph_matrix (w
->desired_matrix
);
14157 goto need_larger_matrices
;
14160 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14162 /* If point does not appear, try to move point so it does
14163 appear. The desired matrix has been built above, so we
14164 can use it here. */
14165 new_vpos
= window_box_height (w
) / 2;
14168 if (!cursor_row_fully_visible_p (w
, 0, 0))
14170 /* Point does appear, but on a line partly visible at end of window.
14171 Move it back to a fully-visible line. */
14172 new_vpos
= window_box_height (w
);
14175 /* If we need to move point for either of the above reasons,
14176 now actually do it. */
14179 struct glyph_row
*row
;
14181 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14182 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14185 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14186 MATRIX_ROW_START_BYTEPOS (row
));
14188 if (w
!= XWINDOW (selected_window
))
14189 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14190 else if (current_buffer
== old
)
14191 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14193 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14195 /* If we are highlighting the region, then we just changed
14196 the region, so redisplay to show it. */
14197 if (!NILP (Vtransient_mark_mode
)
14198 && !NILP (current_buffer
->mark_active
))
14200 clear_glyph_matrix (w
->desired_matrix
);
14201 if (!try_window (window
, startp
, 0))
14202 goto need_larger_matrices
;
14207 debug_method_add (w
, "forced window start");
14212 /* Handle case where text has not changed, only point, and it has
14213 not moved off the frame, and we are not retrying after hscroll.
14214 (current_matrix_up_to_date_p is nonzero when retrying.) */
14215 if (current_matrix_up_to_date_p
14216 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14217 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14221 case CURSOR_MOVEMENT_SUCCESS
:
14222 used_current_matrix_p
= 1;
14225 case CURSOR_MOVEMENT_MUST_SCROLL
:
14226 goto try_to_scroll
;
14232 /* If current starting point was originally the beginning of a line
14233 but no longer is, find a new starting point. */
14234 else if (!NILP (w
->start_at_line_beg
)
14235 && !(CHARPOS (startp
) <= BEGV
14236 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14239 debug_method_add (w
, "recenter 1");
14244 /* Try scrolling with try_window_id. Value is > 0 if update has
14245 been done, it is -1 if we know that the same window start will
14246 not work. It is 0 if unsuccessful for some other reason. */
14247 else if ((tem
= try_window_id (w
)) != 0)
14250 debug_method_add (w
, "try_window_id %d", tem
);
14253 if (fonts_changed_p
)
14254 goto need_larger_matrices
;
14258 /* Otherwise try_window_id has returned -1 which means that we
14259 don't want the alternative below this comment to execute. */
14261 else if (CHARPOS (startp
) >= BEGV
14262 && CHARPOS (startp
) <= ZV
14263 && PT
>= CHARPOS (startp
)
14264 && (CHARPOS (startp
) < ZV
14265 /* Avoid starting at end of buffer. */
14266 || CHARPOS (startp
) == BEGV
14267 || (XFASTINT (w
->last_modified
) >= MODIFF
14268 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14271 /* If first window line is a continuation line, and window start
14272 is inside the modified region, but the first change is before
14273 current window start, we must select a new window start.
14275 However, if this is the result of a down-mouse event (e.g. by
14276 extending the mouse-drag-overlay), we don't want to select a
14277 new window start, since that would change the position under
14278 the mouse, resulting in an unwanted mouse-movement rather
14279 than a simple mouse-click. */
14280 if (NILP (w
->start_at_line_beg
)
14281 && NILP (do_mouse_tracking
)
14282 && CHARPOS (startp
) > BEGV
14283 && CHARPOS (startp
) > BEG
+ beg_unchanged
14284 && CHARPOS (startp
) <= Z
- end_unchanged
14285 /* Even if w->start_at_line_beg is nil, a new window may
14286 start at a line_beg, since that's how set_buffer_window
14287 sets it. So, we need to check the return value of
14288 compute_window_start_on_continuation_line. (See also
14290 && XMARKER (w
->start
)->buffer
== current_buffer
14291 && compute_window_start_on_continuation_line (w
))
14293 w
->force_start
= Qt
;
14294 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14299 debug_method_add (w
, "same window start");
14302 /* Try to redisplay starting at same place as before.
14303 If point has not moved off frame, accept the results. */
14304 if (!current_matrix_up_to_date_p
14305 /* Don't use try_window_reusing_current_matrix in this case
14306 because a window scroll function can have changed the
14308 || !NILP (Vwindow_scroll_functions
)
14309 || MINI_WINDOW_P (w
)
14310 || !(used_current_matrix_p
14311 = try_window_reusing_current_matrix (w
)))
14313 IF_DEBUG (debug_method_add (w
, "1"));
14314 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14315 /* -1 means we need to scroll.
14316 0 means we need new matrices, but fonts_changed_p
14317 is set in that case, so we will detect it below. */
14318 goto try_to_scroll
;
14321 if (fonts_changed_p
)
14322 goto need_larger_matrices
;
14324 if (w
->cursor
.vpos
>= 0)
14326 if (!just_this_one_p
14327 || current_buffer
->clip_changed
14328 || BEG_UNCHANGED
< CHARPOS (startp
))
14329 /* Forget any recorded base line for line number display. */
14330 w
->base_line_number
= Qnil
;
14332 if (!cursor_row_fully_visible_p (w
, 1, 0))
14334 clear_glyph_matrix (w
->desired_matrix
);
14335 last_line_misfit
= 1;
14337 /* Drop through and scroll. */
14342 clear_glyph_matrix (w
->desired_matrix
);
14347 w
->last_modified
= make_number (0);
14348 w
->last_overlay_modified
= make_number (0);
14350 /* Redisplay the mode line. Select the buffer properly for that. */
14351 if (!update_mode_line
)
14353 update_mode_line
= 1;
14354 w
->update_mode_line
= Qt
;
14357 /* Try to scroll by specified few lines. */
14358 if ((scroll_conservatively
14360 || temp_scroll_step
14361 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14362 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14363 && !current_buffer
->clip_changed
14364 && CHARPOS (startp
) >= BEGV
14365 && CHARPOS (startp
) <= ZV
)
14367 /* The function returns -1 if new fonts were loaded, 1 if
14368 successful, 0 if not successful. */
14369 int rc
= try_scrolling (window
, just_this_one_p
,
14370 scroll_conservatively
,
14372 temp_scroll_step
, last_line_misfit
);
14375 case SCROLLING_SUCCESS
:
14378 case SCROLLING_NEED_LARGER_MATRICES
:
14379 goto need_larger_matrices
;
14381 case SCROLLING_FAILED
:
14389 /* Finally, just choose place to start which centers point */
14392 if (centering_position
< 0)
14393 centering_position
= window_box_height (w
) / 2;
14396 debug_method_add (w
, "recenter");
14399 /* w->vscroll = 0; */
14401 /* Forget any previously recorded base line for line number display. */
14402 if (!buffer_unchanged_p
)
14403 w
->base_line_number
= Qnil
;
14405 /* Move backward half the height of the window. */
14406 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14407 it
.current_y
= it
.last_visible_y
;
14408 move_it_vertically_backward (&it
, centering_position
);
14409 xassert (IT_CHARPOS (it
) >= BEGV
);
14411 /* The function move_it_vertically_backward may move over more
14412 than the specified y-distance. If it->w is small, e.g. a
14413 mini-buffer window, we may end up in front of the window's
14414 display area. Start displaying at the start of the line
14415 containing PT in this case. */
14416 if (it
.current_y
<= 0)
14418 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14419 move_it_vertically_backward (&it
, 0);
14423 it
.current_x
= it
.hpos
= 0;
14425 /* Set startp here explicitly in case that helps avoid an infinite loop
14426 in case the window-scroll-functions functions get errors. */
14427 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14429 /* Run scroll hooks. */
14430 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14432 /* Redisplay the window. */
14433 if (!current_matrix_up_to_date_p
14434 || windows_or_buffers_changed
14435 || cursor_type_changed
14436 /* Don't use try_window_reusing_current_matrix in this case
14437 because it can have changed the buffer. */
14438 || !NILP (Vwindow_scroll_functions
)
14439 || !just_this_one_p
14440 || MINI_WINDOW_P (w
)
14441 || !(used_current_matrix_p
14442 = try_window_reusing_current_matrix (w
)))
14443 try_window (window
, startp
, 0);
14445 /* If new fonts have been loaded (due to fontsets), give up. We
14446 have to start a new redisplay since we need to re-adjust glyph
14448 if (fonts_changed_p
)
14449 goto need_larger_matrices
;
14451 /* If cursor did not appear assume that the middle of the window is
14452 in the first line of the window. Do it again with the next line.
14453 (Imagine a window of height 100, displaying two lines of height
14454 60. Moving back 50 from it->last_visible_y will end in the first
14456 if (w
->cursor
.vpos
< 0)
14458 if (!NILP (w
->window_end_valid
)
14459 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14461 clear_glyph_matrix (w
->desired_matrix
);
14462 move_it_by_lines (&it
, 1, 0);
14463 try_window (window
, it
.current
.pos
, 0);
14465 else if (PT
< IT_CHARPOS (it
))
14467 clear_glyph_matrix (w
->desired_matrix
);
14468 move_it_by_lines (&it
, -1, 0);
14469 try_window (window
, it
.current
.pos
, 0);
14473 /* Not much we can do about it. */
14477 /* Consider the following case: Window starts at BEGV, there is
14478 invisible, intangible text at BEGV, so that display starts at
14479 some point START > BEGV. It can happen that we are called with
14480 PT somewhere between BEGV and START. Try to handle that case. */
14481 if (w
->cursor
.vpos
< 0)
14483 struct glyph_row
*row
= w
->current_matrix
->rows
;
14484 if (row
->mode_line_p
)
14486 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14489 if (!cursor_row_fully_visible_p (w
, 0, 0))
14491 /* If vscroll is enabled, disable it and try again. */
14495 clear_glyph_matrix (w
->desired_matrix
);
14499 /* If centering point failed to make the whole line visible,
14500 put point at the top instead. That has to make the whole line
14501 visible, if it can be done. */
14502 if (centering_position
== 0)
14505 clear_glyph_matrix (w
->desired_matrix
);
14506 centering_position
= 0;
14512 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14513 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14514 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14517 /* Display the mode line, if we must. */
14518 if ((update_mode_line
14519 /* If window not full width, must redo its mode line
14520 if (a) the window to its side is being redone and
14521 (b) we do a frame-based redisplay. This is a consequence
14522 of how inverted lines are drawn in frame-based redisplay. */
14523 || (!just_this_one_p
14524 && !FRAME_WINDOW_P (f
)
14525 && !WINDOW_FULL_WIDTH_P (w
))
14526 /* Line number to display. */
14527 || INTEGERP (w
->base_line_pos
)
14528 /* Column number is displayed and different from the one displayed. */
14529 || (!NILP (w
->column_number_displayed
)
14530 && (XFASTINT (w
->column_number_displayed
)
14531 != (int) current_column ()))) /* iftc */
14532 /* This means that the window has a mode line. */
14533 && (WINDOW_WANTS_MODELINE_P (w
)
14534 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14536 display_mode_lines (w
);
14538 /* If mode line height has changed, arrange for a thorough
14539 immediate redisplay using the correct mode line height. */
14540 if (WINDOW_WANTS_MODELINE_P (w
)
14541 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14543 fonts_changed_p
= 1;
14544 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14545 = DESIRED_MODE_LINE_HEIGHT (w
);
14548 /* If header line height has changed, arrange for a thorough
14549 immediate redisplay using the correct header line height. */
14550 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14551 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14553 fonts_changed_p
= 1;
14554 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14555 = DESIRED_HEADER_LINE_HEIGHT (w
);
14558 if (fonts_changed_p
)
14559 goto need_larger_matrices
;
14562 if (!line_number_displayed
14563 && !BUFFERP (w
->base_line_pos
))
14565 w
->base_line_pos
= Qnil
;
14566 w
->base_line_number
= Qnil
;
14571 /* When we reach a frame's selected window, redo the frame's menu bar. */
14572 if (update_mode_line
14573 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14575 int redisplay_menu_p
= 0;
14576 int redisplay_tool_bar_p
= 0;
14578 if (FRAME_WINDOW_P (f
))
14580 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14581 || defined (HAVE_NS) || defined (USE_GTK)
14582 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14584 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14588 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14590 if (redisplay_menu_p
)
14591 display_menu_bar (w
);
14593 #ifdef HAVE_WINDOW_SYSTEM
14594 if (FRAME_WINDOW_P (f
))
14596 #if defined (USE_GTK) || defined (HAVE_NS)
14597 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14599 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14600 && (FRAME_TOOL_BAR_LINES (f
) > 0
14601 || !NILP (Vauto_resize_tool_bars
));
14604 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14606 ignore_mouse_drag_p
= 1;
14612 #ifdef HAVE_WINDOW_SYSTEM
14613 if (FRAME_WINDOW_P (f
)
14614 && update_window_fringes (w
, (just_this_one_p
14615 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14616 || w
->pseudo_window_p
)))
14620 if (draw_window_fringes (w
, 1))
14621 x_draw_vertical_border (w
);
14625 #endif /* HAVE_WINDOW_SYSTEM */
14627 /* We go to this label, with fonts_changed_p nonzero,
14628 if it is necessary to try again using larger glyph matrices.
14629 We have to redeem the scroll bar even in this case,
14630 because the loop in redisplay_internal expects that. */
14631 need_larger_matrices
:
14633 finish_scroll_bars
:
14635 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14637 /* Set the thumb's position and size. */
14638 set_vertical_scroll_bar (w
);
14640 /* Note that we actually used the scroll bar attached to this
14641 window, so it shouldn't be deleted at the end of redisplay. */
14642 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14643 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14646 /* Restore current_buffer and value of point in it. The window
14647 update may have changed the buffer, so first make sure `opoint'
14648 is still valid (Bug#6177). */
14649 if (CHARPOS (opoint
) < BEGV
)
14650 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14651 else if (CHARPOS (opoint
) > ZV
)
14652 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
14654 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14656 set_buffer_internal_1 (old
);
14657 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14658 shorter. This can be caused by log truncation in *Messages*. */
14659 if (CHARPOS (lpoint
) <= ZV
)
14660 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14662 unbind_to (count
, Qnil
);
14666 /* Build the complete desired matrix of WINDOW with a window start
14667 buffer position POS.
14669 Value is 1 if successful. It is zero if fonts were loaded during
14670 redisplay which makes re-adjusting glyph matrices necessary, and -1
14671 if point would appear in the scroll margins.
14672 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
14673 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
14677 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
14679 struct window
*w
= XWINDOW (window
);
14681 struct glyph_row
*last_text_row
= NULL
;
14682 struct frame
*f
= XFRAME (w
->frame
);
14684 /* Make POS the new window start. */
14685 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14687 /* Mark cursor position as unknown. No overlay arrow seen. */
14688 w
->cursor
.vpos
= -1;
14689 overlay_arrow_seen
= 0;
14691 /* Initialize iterator and info to start at POS. */
14692 start_display (&it
, w
, pos
);
14694 /* Display all lines of W. */
14695 while (it
.current_y
< it
.last_visible_y
)
14697 if (display_line (&it
))
14698 last_text_row
= it
.glyph_row
- 1;
14699 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
14703 /* Don't let the cursor end in the scroll margins. */
14704 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
14705 && !MINI_WINDOW_P (w
))
14707 int this_scroll_margin
;
14709 if (scroll_margin
> 0)
14711 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14712 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14715 this_scroll_margin
= 0;
14717 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14718 && w
->cursor
.y
< this_scroll_margin
14719 && CHARPOS (pos
) > BEGV
14720 && IT_CHARPOS (it
) < ZV
)
14721 /* rms: considering make_cursor_line_fully_visible_p here
14722 seems to give wrong results. We don't want to recenter
14723 when the last line is partly visible, we want to allow
14724 that case to be handled in the usual way. */
14725 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14727 w
->cursor
.vpos
= -1;
14728 clear_glyph_matrix (w
->desired_matrix
);
14733 /* If bottom moved off end of frame, change mode line percentage. */
14734 if (XFASTINT (w
->window_end_pos
) <= 0
14735 && Z
!= IT_CHARPOS (it
))
14736 w
->update_mode_line
= Qt
;
14738 /* Set window_end_pos to the offset of the last character displayed
14739 on the window from the end of current_buffer. Set
14740 window_end_vpos to its row number. */
14743 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14744 w
->window_end_bytepos
14745 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14747 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14749 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14750 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14751 ->displays_text_p
);
14755 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14756 w
->window_end_pos
= make_number (Z
- ZV
);
14757 w
->window_end_vpos
= make_number (0);
14760 /* But that is not valid info until redisplay finishes. */
14761 w
->window_end_valid
= Qnil
;
14767 /************************************************************************
14768 Window redisplay reusing current matrix when buffer has not changed
14769 ************************************************************************/
14771 /* Try redisplay of window W showing an unchanged buffer with a
14772 different window start than the last time it was displayed by
14773 reusing its current matrix. Value is non-zero if successful.
14774 W->start is the new window start. */
14777 try_window_reusing_current_matrix (struct window
*w
)
14779 struct frame
*f
= XFRAME (w
->frame
);
14780 struct glyph_row
*row
, *bottom_row
;
14783 struct text_pos start
, new_start
;
14784 int nrows_scrolled
, i
;
14785 struct glyph_row
*last_text_row
;
14786 struct glyph_row
*last_reused_text_row
;
14787 struct glyph_row
*start_row
;
14788 int start_vpos
, min_y
, max_y
;
14791 if (inhibit_try_window_reusing
)
14795 if (/* This function doesn't handle terminal frames. */
14796 !FRAME_WINDOW_P (f
)
14797 /* Don't try to reuse the display if windows have been split
14799 || windows_or_buffers_changed
14800 || cursor_type_changed
)
14803 /* Can't do this if region may have changed. */
14804 if ((!NILP (Vtransient_mark_mode
)
14805 && !NILP (current_buffer
->mark_active
))
14806 || !NILP (w
->region_showing
)
14807 || !NILP (Vshow_trailing_whitespace
))
14810 /* If top-line visibility has changed, give up. */
14811 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14812 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14815 /* Give up if old or new display is scrolled vertically. We could
14816 make this function handle this, but right now it doesn't. */
14817 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14818 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14821 /* The variable new_start now holds the new window start. The old
14822 start `start' can be determined from the current matrix. */
14823 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14824 start
= start_row
->minpos
;
14825 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14827 /* Clear the desired matrix for the display below. */
14828 clear_glyph_matrix (w
->desired_matrix
);
14830 if (CHARPOS (new_start
) <= CHARPOS (start
))
14834 /* Don't use this method if the display starts with an ellipsis
14835 displayed for invisible text. It's not easy to handle that case
14836 below, and it's certainly not worth the effort since this is
14837 not a frequent case. */
14838 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14841 IF_DEBUG (debug_method_add (w
, "twu1"));
14843 /* Display up to a row that can be reused. The variable
14844 last_text_row is set to the last row displayed that displays
14845 text. Note that it.vpos == 0 if or if not there is a
14846 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14847 start_display (&it
, w
, new_start
);
14848 first_row_y
= it
.current_y
;
14849 w
->cursor
.vpos
= -1;
14850 last_text_row
= last_reused_text_row
= NULL
;
14852 while (it
.current_y
< it
.last_visible_y
14853 && !fonts_changed_p
)
14855 /* If we have reached into the characters in the START row,
14856 that means the line boundaries have changed. So we
14857 can't start copying with the row START. Maybe it will
14858 work to start copying with the following row. */
14859 while (IT_CHARPOS (it
) > CHARPOS (start
))
14861 /* Advance to the next row as the "start". */
14863 start
= start_row
->minpos
;
14864 /* If there are no more rows to try, or just one, give up. */
14865 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14866 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14867 || CHARPOS (start
) == ZV
)
14869 clear_glyph_matrix (w
->desired_matrix
);
14873 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14875 /* If we have reached alignment,
14876 we can copy the rest of the rows. */
14877 if (IT_CHARPOS (it
) == CHARPOS (start
))
14880 if (display_line (&it
))
14881 last_text_row
= it
.glyph_row
- 1;
14884 /* A value of current_y < last_visible_y means that we stopped
14885 at the previous window start, which in turn means that we
14886 have at least one reusable row. */
14887 if (it
.current_y
< it
.last_visible_y
)
14889 /* IT.vpos always starts from 0; it counts text lines. */
14890 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14892 /* Find PT if not already found in the lines displayed. */
14893 if (w
->cursor
.vpos
< 0)
14895 int dy
= it
.current_y
- start_row
->y
;
14897 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14898 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14900 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14901 dy
, nrows_scrolled
);
14904 clear_glyph_matrix (w
->desired_matrix
);
14909 /* Scroll the display. Do it before the current matrix is
14910 changed. The problem here is that update has not yet
14911 run, i.e. part of the current matrix is not up to date.
14912 scroll_run_hook will clear the cursor, and use the
14913 current matrix to get the height of the row the cursor is
14915 run
.current_y
= start_row
->y
;
14916 run
.desired_y
= it
.current_y
;
14917 run
.height
= it
.last_visible_y
- it
.current_y
;
14919 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14922 FRAME_RIF (f
)->update_window_begin_hook (w
);
14923 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14924 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14925 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14929 /* Shift current matrix down by nrows_scrolled lines. */
14930 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14931 rotate_matrix (w
->current_matrix
,
14933 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14936 /* Disable lines that must be updated. */
14937 for (i
= 0; i
< nrows_scrolled
; ++i
)
14938 (start_row
+ i
)->enabled_p
= 0;
14940 /* Re-compute Y positions. */
14941 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14942 max_y
= it
.last_visible_y
;
14943 for (row
= start_row
+ nrows_scrolled
;
14947 row
->y
= it
.current_y
;
14948 row
->visible_height
= row
->height
;
14950 if (row
->y
< min_y
)
14951 row
->visible_height
-= min_y
- row
->y
;
14952 if (row
->y
+ row
->height
> max_y
)
14953 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14954 row
->redraw_fringe_bitmaps_p
= 1;
14956 it
.current_y
+= row
->height
;
14958 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14959 last_reused_text_row
= row
;
14960 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14964 /* Disable lines in the current matrix which are now
14965 below the window. */
14966 for (++row
; row
< bottom_row
; ++row
)
14967 row
->enabled_p
= row
->mode_line_p
= 0;
14970 /* Update window_end_pos etc.; last_reused_text_row is the last
14971 reused row from the current matrix containing text, if any.
14972 The value of last_text_row is the last displayed line
14973 containing text. */
14974 if (last_reused_text_row
)
14976 w
->window_end_bytepos
14977 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14979 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14981 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14982 w
->current_matrix
));
14984 else if (last_text_row
)
14986 w
->window_end_bytepos
14987 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14989 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14991 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14995 /* This window must be completely empty. */
14996 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14997 w
->window_end_pos
= make_number (Z
- ZV
);
14998 w
->window_end_vpos
= make_number (0);
15000 w
->window_end_valid
= Qnil
;
15002 /* Update hint: don't try scrolling again in update_window. */
15003 w
->desired_matrix
->no_scrolling_p
= 1;
15006 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15010 else if (CHARPOS (new_start
) > CHARPOS (start
))
15012 struct glyph_row
*pt_row
, *row
;
15013 struct glyph_row
*first_reusable_row
;
15014 struct glyph_row
*first_row_to_display
;
15016 int yb
= window_text_bottom_y (w
);
15018 /* Find the row starting at new_start, if there is one. Don't
15019 reuse a partially visible line at the end. */
15020 first_reusable_row
= start_row
;
15021 while (first_reusable_row
->enabled_p
15022 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15023 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15024 < CHARPOS (new_start
)))
15025 ++first_reusable_row
;
15027 /* Give up if there is no row to reuse. */
15028 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15029 || !first_reusable_row
->enabled_p
15030 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15031 != CHARPOS (new_start
)))
15034 /* We can reuse fully visible rows beginning with
15035 first_reusable_row to the end of the window. Set
15036 first_row_to_display to the first row that cannot be reused.
15037 Set pt_row to the row containing point, if there is any. */
15039 for (first_row_to_display
= first_reusable_row
;
15040 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15041 ++first_row_to_display
)
15043 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15044 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15045 pt_row
= first_row_to_display
;
15048 /* Start displaying at the start of first_row_to_display. */
15049 xassert (first_row_to_display
->y
< yb
);
15050 init_to_row_start (&it
, w
, first_row_to_display
);
15052 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15054 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15056 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15057 + WINDOW_HEADER_LINE_HEIGHT (w
));
15059 /* Display lines beginning with first_row_to_display in the
15060 desired matrix. Set last_text_row to the last row displayed
15061 that displays text. */
15062 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15063 if (pt_row
== NULL
)
15064 w
->cursor
.vpos
= -1;
15065 last_text_row
= NULL
;
15066 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15067 if (display_line (&it
))
15068 last_text_row
= it
.glyph_row
- 1;
15070 /* If point is in a reused row, adjust y and vpos of the cursor
15074 w
->cursor
.vpos
-= nrows_scrolled
;
15075 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15078 /* Give up if point isn't in a row displayed or reused. (This
15079 also handles the case where w->cursor.vpos < nrows_scrolled
15080 after the calls to display_line, which can happen with scroll
15081 margins. See bug#1295.) */
15082 if (w
->cursor
.vpos
< 0)
15084 clear_glyph_matrix (w
->desired_matrix
);
15088 /* Scroll the display. */
15089 run
.current_y
= first_reusable_row
->y
;
15090 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15091 run
.height
= it
.last_visible_y
- run
.current_y
;
15092 dy
= run
.current_y
- run
.desired_y
;
15097 FRAME_RIF (f
)->update_window_begin_hook (w
);
15098 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15099 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15100 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15104 /* Adjust Y positions of reused rows. */
15105 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15106 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15107 max_y
= it
.last_visible_y
;
15108 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15111 row
->visible_height
= row
->height
;
15112 if (row
->y
< min_y
)
15113 row
->visible_height
-= min_y
- row
->y
;
15114 if (row
->y
+ row
->height
> max_y
)
15115 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15116 row
->redraw_fringe_bitmaps_p
= 1;
15119 /* Scroll the current matrix. */
15120 xassert (nrows_scrolled
> 0);
15121 rotate_matrix (w
->current_matrix
,
15123 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15126 /* Disable rows not reused. */
15127 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15128 row
->enabled_p
= 0;
15130 /* Point may have moved to a different line, so we cannot assume that
15131 the previous cursor position is valid; locate the correct row. */
15134 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15135 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15139 w
->cursor
.y
= row
->y
;
15141 if (row
< bottom_row
)
15143 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15144 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15146 /* Can't use this optimization with bidi-reordered glyph
15147 rows, unless cursor is already at point. */
15148 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
15150 if (!(w
->cursor
.hpos
>= 0
15151 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15152 && BUFFERP (glyph
->object
)
15153 && glyph
->charpos
== PT
))
15158 && (!BUFFERP (glyph
->object
)
15159 || glyph
->charpos
< PT
);
15163 w
->cursor
.x
+= glyph
->pixel_width
;
15168 /* Adjust window end. A null value of last_text_row means that
15169 the window end is in reused rows which in turn means that
15170 only its vpos can have changed. */
15173 w
->window_end_bytepos
15174 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15176 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15178 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15183 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15186 w
->window_end_valid
= Qnil
;
15187 w
->desired_matrix
->no_scrolling_p
= 1;
15190 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15200 /************************************************************************
15201 Window redisplay reusing current matrix when buffer has changed
15202 ************************************************************************/
15204 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15205 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15206 EMACS_INT
*, EMACS_INT
*);
15207 static struct glyph_row
*
15208 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15209 struct glyph_row
*);
15212 /* Return the last row in MATRIX displaying text. If row START is
15213 non-null, start searching with that row. IT gives the dimensions
15214 of the display. Value is null if matrix is empty; otherwise it is
15215 a pointer to the row found. */
15217 static struct glyph_row
*
15218 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15219 struct glyph_row
*start
)
15221 struct glyph_row
*row
, *row_found
;
15223 /* Set row_found to the last row in IT->w's current matrix
15224 displaying text. The loop looks funny but think of partially
15227 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15228 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15230 xassert (row
->enabled_p
);
15232 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15241 /* Return the last row in the current matrix of W that is not affected
15242 by changes at the start of current_buffer that occurred since W's
15243 current matrix was built. Value is null if no such row exists.
15245 BEG_UNCHANGED us the number of characters unchanged at the start of
15246 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15247 first changed character in current_buffer. Characters at positions <
15248 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15249 when the current matrix was built. */
15251 static struct glyph_row
*
15252 find_last_unchanged_at_beg_row (struct window
*w
)
15254 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15255 struct glyph_row
*row
;
15256 struct glyph_row
*row_found
= NULL
;
15257 int yb
= window_text_bottom_y (w
);
15259 /* Find the last row displaying unchanged text. */
15260 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15261 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15262 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15265 if (/* If row ends before first_changed_pos, it is unchanged,
15266 except in some case. */
15267 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15268 /* When row ends in ZV and we write at ZV it is not
15270 && !row
->ends_at_zv_p
15271 /* When first_changed_pos is the end of a continued line,
15272 row is not unchanged because it may be no longer
15274 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15275 && (row
->continued_p
15276 || row
->exact_window_width_line_p
)))
15279 /* Stop if last visible row. */
15280 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15288 /* Find the first glyph row in the current matrix of W that is not
15289 affected by changes at the end of current_buffer since the
15290 time W's current matrix was built.
15292 Return in *DELTA the number of chars by which buffer positions in
15293 unchanged text at the end of current_buffer must be adjusted.
15295 Return in *DELTA_BYTES the corresponding number of bytes.
15297 Value is null if no such row exists, i.e. all rows are affected by
15300 static struct glyph_row
*
15301 find_first_unchanged_at_end_row (struct window
*w
,
15302 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15304 struct glyph_row
*row
;
15305 struct glyph_row
*row_found
= NULL
;
15307 *delta
= *delta_bytes
= 0;
15309 /* Display must not have been paused, otherwise the current matrix
15310 is not up to date. */
15311 eassert (!NILP (w
->window_end_valid
));
15313 /* A value of window_end_pos >= END_UNCHANGED means that the window
15314 end is in the range of changed text. If so, there is no
15315 unchanged row at the end of W's current matrix. */
15316 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15319 /* Set row to the last row in W's current matrix displaying text. */
15320 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15322 /* If matrix is entirely empty, no unchanged row exists. */
15323 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15325 /* The value of row is the last glyph row in the matrix having a
15326 meaningful buffer position in it. The end position of row
15327 corresponds to window_end_pos. This allows us to translate
15328 buffer positions in the current matrix to current buffer
15329 positions for characters not in changed text. */
15331 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15332 EMACS_INT Z_BYTE_old
=
15333 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15334 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15335 struct glyph_row
*first_text_row
15336 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15338 *delta
= Z
- Z_old
;
15339 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15341 /* Set last_unchanged_pos to the buffer position of the last
15342 character in the buffer that has not been changed. Z is the
15343 index + 1 of the last character in current_buffer, i.e. by
15344 subtracting END_UNCHANGED we get the index of the last
15345 unchanged character, and we have to add BEG to get its buffer
15347 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15348 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15350 /* Search backward from ROW for a row displaying a line that
15351 starts at a minimum position >= last_unchanged_pos_old. */
15352 for (; row
> first_text_row
; --row
)
15354 /* This used to abort, but it can happen.
15355 It is ok to just stop the search instead here. KFS. */
15356 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15359 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15364 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15370 /* Make sure that glyph rows in the current matrix of window W
15371 reference the same glyph memory as corresponding rows in the
15372 frame's frame matrix. This function is called after scrolling W's
15373 current matrix on a terminal frame in try_window_id and
15374 try_window_reusing_current_matrix. */
15377 sync_frame_with_window_matrix_rows (struct window
*w
)
15379 struct frame
*f
= XFRAME (w
->frame
);
15380 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15382 /* Preconditions: W must be a leaf window and full-width. Its frame
15383 must have a frame matrix. */
15384 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15385 xassert (WINDOW_FULL_WIDTH_P (w
));
15386 xassert (!FRAME_WINDOW_P (f
));
15388 /* If W is a full-width window, glyph pointers in W's current matrix
15389 have, by definition, to be the same as glyph pointers in the
15390 corresponding frame matrix. Note that frame matrices have no
15391 marginal areas (see build_frame_matrix). */
15392 window_row
= w
->current_matrix
->rows
;
15393 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15394 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15395 while (window_row
< window_row_end
)
15397 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15398 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15400 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15401 frame_row
->glyphs
[TEXT_AREA
] = start
;
15402 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15403 frame_row
->glyphs
[LAST_AREA
] = end
;
15405 /* Disable frame rows whose corresponding window rows have
15406 been disabled in try_window_id. */
15407 if (!window_row
->enabled_p
)
15408 frame_row
->enabled_p
= 0;
15410 ++window_row
, ++frame_row
;
15415 /* Find the glyph row in window W containing CHARPOS. Consider all
15416 rows between START and END (not inclusive). END null means search
15417 all rows to the end of the display area of W. Value is the row
15418 containing CHARPOS or null. */
15421 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15422 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15424 struct glyph_row
*row
= start
;
15425 struct glyph_row
*best_row
= NULL
;
15426 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15429 /* If we happen to start on a header-line, skip that. */
15430 if (row
->mode_line_p
)
15433 if ((end
&& row
>= end
) || !row
->enabled_p
)
15436 last_y
= window_text_bottom_y (w
) - dy
;
15440 /* Give up if we have gone too far. */
15441 if (end
&& row
>= end
)
15443 /* This formerly returned if they were equal.
15444 I think that both quantities are of a "last plus one" type;
15445 if so, when they are equal, the row is within the screen. -- rms. */
15446 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15449 /* If it is in this row, return this row. */
15450 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15451 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15452 /* The end position of a row equals the start
15453 position of the next row. If CHARPOS is there, we
15454 would rather display it in the next line, except
15455 when this line ends in ZV. */
15456 && !row
->ends_at_zv_p
15457 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15458 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15462 if (NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15463 || (!best_row
&& !row
->continued_p
))
15465 /* In bidi-reordered rows, there could be several rows
15466 occluding point, all of them belonging to the same
15467 continued line. We need to find the row which fits
15468 CHARPOS the best. */
15469 for (g
= row
->glyphs
[TEXT_AREA
];
15470 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15473 if (!STRINGP (g
->object
))
15475 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15477 mindif
= eabs (g
->charpos
- charpos
);
15479 /* Exact match always wins. */
15486 else if (best_row
&& !row
->continued_p
)
15493 /* Try to redisplay window W by reusing its existing display. W's
15494 current matrix must be up to date when this function is called,
15495 i.e. window_end_valid must not be nil.
15499 1 if display has been updated
15500 0 if otherwise unsuccessful
15501 -1 if redisplay with same window start is known not to succeed
15503 The following steps are performed:
15505 1. Find the last row in the current matrix of W that is not
15506 affected by changes at the start of current_buffer. If no such row
15509 2. Find the first row in W's current matrix that is not affected by
15510 changes at the end of current_buffer. Maybe there is no such row.
15512 3. Display lines beginning with the row + 1 found in step 1 to the
15513 row found in step 2 or, if step 2 didn't find a row, to the end of
15516 4. If cursor is not known to appear on the window, give up.
15518 5. If display stopped at the row found in step 2, scroll the
15519 display and current matrix as needed.
15521 6. Maybe display some lines at the end of W, if we must. This can
15522 happen under various circumstances, like a partially visible line
15523 becoming fully visible, or because newly displayed lines are displayed
15524 in smaller font sizes.
15526 7. Update W's window end information. */
15529 try_window_id (struct window
*w
)
15531 struct frame
*f
= XFRAME (w
->frame
);
15532 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15533 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15534 struct glyph_row
*last_unchanged_at_beg_row
;
15535 struct glyph_row
*first_unchanged_at_end_row
;
15536 struct glyph_row
*row
;
15537 struct glyph_row
*bottom_row
;
15540 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
15542 struct text_pos start_pos
;
15544 int first_unchanged_at_end_vpos
= 0;
15545 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15546 struct text_pos start
;
15547 EMACS_INT first_changed_charpos
, last_changed_charpos
;
15550 if (inhibit_try_window_id
)
15554 /* This is handy for debugging. */
15556 #define GIVE_UP(X) \
15558 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15562 #define GIVE_UP(X) return 0
15565 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15567 /* Don't use this for mini-windows because these can show
15568 messages and mini-buffers, and we don't handle that here. */
15569 if (MINI_WINDOW_P (w
))
15572 /* This flag is used to prevent redisplay optimizations. */
15573 if (windows_or_buffers_changed
|| cursor_type_changed
)
15576 /* Verify that narrowing has not changed.
15577 Also verify that we were not told to prevent redisplay optimizations.
15578 It would be nice to further
15579 reduce the number of cases where this prevents try_window_id. */
15580 if (current_buffer
->clip_changed
15581 || current_buffer
->prevent_redisplay_optimizations_p
)
15584 /* Window must either use window-based redisplay or be full width. */
15585 if (!FRAME_WINDOW_P (f
)
15586 && (!FRAME_LINE_INS_DEL_OK (f
)
15587 || !WINDOW_FULL_WIDTH_P (w
)))
15590 /* Give up if point is known NOT to appear in W. */
15591 if (PT
< CHARPOS (start
))
15594 /* Another way to prevent redisplay optimizations. */
15595 if (XFASTINT (w
->last_modified
) == 0)
15598 /* Verify that window is not hscrolled. */
15599 if (XFASTINT (w
->hscroll
) != 0)
15602 /* Verify that display wasn't paused. */
15603 if (NILP (w
->window_end_valid
))
15606 /* Can't use this if highlighting a region because a cursor movement
15607 will do more than just set the cursor. */
15608 if (!NILP (Vtransient_mark_mode
)
15609 && !NILP (current_buffer
->mark_active
))
15612 /* Likewise if highlighting trailing whitespace. */
15613 if (!NILP (Vshow_trailing_whitespace
))
15616 /* Likewise if showing a region. */
15617 if (!NILP (w
->region_showing
))
15620 /* Can't use this if overlay arrow position and/or string have
15622 if (overlay_arrows_changed_p ())
15625 /* When word-wrap is on, adding a space to the first word of a
15626 wrapped line can change the wrap position, altering the line
15627 above it. It might be worthwhile to handle this more
15628 intelligently, but for now just redisplay from scratch. */
15629 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15632 /* Under bidi reordering, adding or deleting a character in the
15633 beginning of a paragraph, before the first strong directional
15634 character, can change the base direction of the paragraph (unless
15635 the buffer specifies a fixed paragraph direction), which will
15636 require to redisplay the whole paragraph. It might be worthwhile
15637 to find the paragraph limits and widen the range of redisplayed
15638 lines to that, but for now just give up this optimization and
15639 redisplay from scratch. */
15640 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15641 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15644 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15645 only if buffer has really changed. The reason is that the gap is
15646 initially at Z for freshly visited files. The code below would
15647 set end_unchanged to 0 in that case. */
15648 if (MODIFF
> SAVE_MODIFF
15649 /* This seems to happen sometimes after saving a buffer. */
15650 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15652 if (GPT
- BEG
< BEG_UNCHANGED
)
15653 BEG_UNCHANGED
= GPT
- BEG
;
15654 if (Z
- GPT
< END_UNCHANGED
)
15655 END_UNCHANGED
= Z
- GPT
;
15658 /* The position of the first and last character that has been changed. */
15659 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15660 last_changed_charpos
= Z
- END_UNCHANGED
;
15662 /* If window starts after a line end, and the last change is in
15663 front of that newline, then changes don't affect the display.
15664 This case happens with stealth-fontification. Note that although
15665 the display is unchanged, glyph positions in the matrix have to
15666 be adjusted, of course. */
15667 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15668 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15669 && ((last_changed_charpos
< CHARPOS (start
)
15670 && CHARPOS (start
) == BEGV
)
15671 || (last_changed_charpos
< CHARPOS (start
) - 1
15672 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15674 EMACS_INT Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15675 struct glyph_row
*r0
;
15677 /* Compute how many chars/bytes have been added to or removed
15678 from the buffer. */
15679 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15680 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15682 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15684 /* Give up if PT is not in the window. Note that it already has
15685 been checked at the start of try_window_id that PT is not in
15686 front of the window start. */
15687 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15690 /* If window start is unchanged, we can reuse the whole matrix
15691 as is, after adjusting glyph positions. No need to compute
15692 the window end again, since its offset from Z hasn't changed. */
15693 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15694 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15695 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15696 /* PT must not be in a partially visible line. */
15697 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15698 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15700 /* Adjust positions in the glyph matrix. */
15701 if (delta
|| delta_bytes
)
15703 struct glyph_row
*r1
15704 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15705 increment_matrix_positions (w
->current_matrix
,
15706 MATRIX_ROW_VPOS (r0
, current_matrix
),
15707 MATRIX_ROW_VPOS (r1
, current_matrix
),
15708 delta
, delta_bytes
);
15711 /* Set the cursor. */
15712 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15714 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15721 /* Handle the case that changes are all below what is displayed in
15722 the window, and that PT is in the window. This shortcut cannot
15723 be taken if ZV is visible in the window, and text has been added
15724 there that is visible in the window. */
15725 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15726 /* ZV is not visible in the window, or there are no
15727 changes at ZV, actually. */
15728 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15729 || first_changed_charpos
== last_changed_charpos
))
15731 struct glyph_row
*r0
;
15733 /* Give up if PT is not in the window. Note that it already has
15734 been checked at the start of try_window_id that PT is not in
15735 front of the window start. */
15736 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15739 /* If window start is unchanged, we can reuse the whole matrix
15740 as is, without changing glyph positions since no text has
15741 been added/removed in front of the window end. */
15742 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15743 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
15744 /* PT must not be in a partially visible line. */
15745 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15746 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15748 /* We have to compute the window end anew since text
15749 could have been added/removed after it. */
15751 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15752 w
->window_end_bytepos
15753 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15755 /* Set the cursor. */
15756 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15758 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15765 /* Give up if window start is in the changed area.
15767 The condition used to read
15769 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15771 but why that was tested escapes me at the moment. */
15772 if (CHARPOS (start
) >= first_changed_charpos
15773 && CHARPOS (start
) <= last_changed_charpos
)
15776 /* Check that window start agrees with the start of the first glyph
15777 row in its current matrix. Check this after we know the window
15778 start is not in changed text, otherwise positions would not be
15780 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15781 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
15784 /* Give up if the window ends in strings. Overlay strings
15785 at the end are difficult to handle, so don't try. */
15786 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15787 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15790 /* Compute the position at which we have to start displaying new
15791 lines. Some of the lines at the top of the window might be
15792 reusable because they are not displaying changed text. Find the
15793 last row in W's current matrix not affected by changes at the
15794 start of current_buffer. Value is null if changes start in the
15795 first line of window. */
15796 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15797 if (last_unchanged_at_beg_row
)
15799 /* Avoid starting to display in the moddle of a character, a TAB
15800 for instance. This is easier than to set up the iterator
15801 exactly, and it's not a frequent case, so the additional
15802 effort wouldn't really pay off. */
15803 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15804 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15805 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15806 --last_unchanged_at_beg_row
;
15808 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15811 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15813 start_pos
= it
.current
.pos
;
15815 /* Start displaying new lines in the desired matrix at the same
15816 vpos we would use in the current matrix, i.e. below
15817 last_unchanged_at_beg_row. */
15818 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15820 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15821 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15823 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15827 /* There are no reusable lines at the start of the window.
15828 Start displaying in the first text line. */
15829 start_display (&it
, w
, start
);
15830 it
.vpos
= it
.first_vpos
;
15831 start_pos
= it
.current
.pos
;
15834 /* Find the first row that is not affected by changes at the end of
15835 the buffer. Value will be null if there is no unchanged row, in
15836 which case we must redisplay to the end of the window. delta
15837 will be set to the value by which buffer positions beginning with
15838 first_unchanged_at_end_row have to be adjusted due to text
15840 first_unchanged_at_end_row
15841 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15842 IF_DEBUG (debug_delta
= delta
);
15843 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15845 /* Set stop_pos to the buffer position up to which we will have to
15846 display new lines. If first_unchanged_at_end_row != NULL, this
15847 is the buffer position of the start of the line displayed in that
15848 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15849 that we don't stop at a buffer position. */
15851 if (first_unchanged_at_end_row
)
15853 xassert (last_unchanged_at_beg_row
== NULL
15854 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15856 /* If this is a continuation line, move forward to the next one
15857 that isn't. Changes in lines above affect this line.
15858 Caution: this may move first_unchanged_at_end_row to a row
15859 not displaying text. */
15860 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15861 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15862 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15863 < it
.last_visible_y
))
15864 ++first_unchanged_at_end_row
;
15866 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15867 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15868 >= it
.last_visible_y
))
15869 first_unchanged_at_end_row
= NULL
;
15872 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15874 first_unchanged_at_end_vpos
15875 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15876 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15879 else if (last_unchanged_at_beg_row
== NULL
)
15885 /* Either there is no unchanged row at the end, or the one we have
15886 now displays text. This is a necessary condition for the window
15887 end pos calculation at the end of this function. */
15888 xassert (first_unchanged_at_end_row
== NULL
15889 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15891 debug_last_unchanged_at_beg_vpos
15892 = (last_unchanged_at_beg_row
15893 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15895 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15897 #endif /* GLYPH_DEBUG != 0 */
15900 /* Display new lines. Set last_text_row to the last new line
15901 displayed which has text on it, i.e. might end up as being the
15902 line where the window_end_vpos is. */
15903 w
->cursor
.vpos
= -1;
15904 last_text_row
= NULL
;
15905 overlay_arrow_seen
= 0;
15906 while (it
.current_y
< it
.last_visible_y
15907 && !fonts_changed_p
15908 && (first_unchanged_at_end_row
== NULL
15909 || IT_CHARPOS (it
) < stop_pos
))
15911 if (display_line (&it
))
15912 last_text_row
= it
.glyph_row
- 1;
15915 if (fonts_changed_p
)
15919 /* Compute differences in buffer positions, y-positions etc. for
15920 lines reused at the bottom of the window. Compute what we can
15922 if (first_unchanged_at_end_row
15923 /* No lines reused because we displayed everything up to the
15924 bottom of the window. */
15925 && it
.current_y
< it
.last_visible_y
)
15928 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15930 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15931 run
.current_y
= first_unchanged_at_end_row
->y
;
15932 run
.desired_y
= run
.current_y
+ dy
;
15933 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15937 delta
= delta_bytes
= dvpos
= dy
15938 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15939 first_unchanged_at_end_row
= NULL
;
15941 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15944 /* Find the cursor if not already found. We have to decide whether
15945 PT will appear on this window (it sometimes doesn't, but this is
15946 not a very frequent case.) This decision has to be made before
15947 the current matrix is altered. A value of cursor.vpos < 0 means
15948 that PT is either in one of the lines beginning at
15949 first_unchanged_at_end_row or below the window. Don't care for
15950 lines that might be displayed later at the window end; as
15951 mentioned, this is not a frequent case. */
15952 if (w
->cursor
.vpos
< 0)
15954 /* Cursor in unchanged rows at the top? */
15955 if (PT
< CHARPOS (start_pos
)
15956 && last_unchanged_at_beg_row
)
15958 row
= row_containing_pos (w
, PT
,
15959 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15960 last_unchanged_at_beg_row
+ 1, 0);
15962 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15965 /* Start from first_unchanged_at_end_row looking for PT. */
15966 else if (first_unchanged_at_end_row
)
15968 row
= row_containing_pos (w
, PT
- delta
,
15969 first_unchanged_at_end_row
, NULL
, 0);
15971 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15972 delta_bytes
, dy
, dvpos
);
15975 /* Give up if cursor was not found. */
15976 if (w
->cursor
.vpos
< 0)
15978 clear_glyph_matrix (w
->desired_matrix
);
15983 /* Don't let the cursor end in the scroll margins. */
15985 int this_scroll_margin
, cursor_height
;
15987 this_scroll_margin
= max (0, scroll_margin
);
15988 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15989 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15990 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15992 if ((w
->cursor
.y
< this_scroll_margin
15993 && CHARPOS (start
) > BEGV
)
15994 /* Old redisplay didn't take scroll margin into account at the bottom,
15995 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15996 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15997 ? cursor_height
+ this_scroll_margin
15998 : 1)) > it
.last_visible_y
)
16000 w
->cursor
.vpos
= -1;
16001 clear_glyph_matrix (w
->desired_matrix
);
16006 /* Scroll the display. Do it before changing the current matrix so
16007 that xterm.c doesn't get confused about where the cursor glyph is
16009 if (dy
&& run
.height
)
16013 if (FRAME_WINDOW_P (f
))
16015 FRAME_RIF (f
)->update_window_begin_hook (w
);
16016 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16017 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16018 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16022 /* Terminal frame. In this case, dvpos gives the number of
16023 lines to scroll by; dvpos < 0 means scroll up. */
16024 int first_unchanged_at_end_vpos
16025 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16026 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
16027 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16028 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16029 + window_internal_height (w
));
16031 #if defined (HAVE_GPM) || defined (MSDOS)
16032 x_clear_window_mouse_face (w
);
16034 /* Perform the operation on the screen. */
16037 /* Scroll last_unchanged_at_beg_row to the end of the
16038 window down dvpos lines. */
16039 set_terminal_window (f
, end
);
16041 /* On dumb terminals delete dvpos lines at the end
16042 before inserting dvpos empty lines. */
16043 if (!FRAME_SCROLL_REGION_OK (f
))
16044 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16046 /* Insert dvpos empty lines in front of
16047 last_unchanged_at_beg_row. */
16048 ins_del_lines (f
, from
, dvpos
);
16050 else if (dvpos
< 0)
16052 /* Scroll up last_unchanged_at_beg_vpos to the end of
16053 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16054 set_terminal_window (f
, end
);
16056 /* Delete dvpos lines in front of
16057 last_unchanged_at_beg_vpos. ins_del_lines will set
16058 the cursor to the given vpos and emit |dvpos| delete
16060 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16062 /* On a dumb terminal insert dvpos empty lines at the
16064 if (!FRAME_SCROLL_REGION_OK (f
))
16065 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16068 set_terminal_window (f
, 0);
16074 /* Shift reused rows of the current matrix to the right position.
16075 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16077 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16078 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16081 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16082 bottom_vpos
, dvpos
);
16083 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16086 else if (dvpos
> 0)
16088 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16089 bottom_vpos
, dvpos
);
16090 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16091 first_unchanged_at_end_vpos
+ dvpos
, 0);
16094 /* For frame-based redisplay, make sure that current frame and window
16095 matrix are in sync with respect to glyph memory. */
16096 if (!FRAME_WINDOW_P (f
))
16097 sync_frame_with_window_matrix_rows (w
);
16099 /* Adjust buffer positions in reused rows. */
16100 if (delta
|| delta_bytes
)
16101 increment_matrix_positions (current_matrix
,
16102 first_unchanged_at_end_vpos
+ dvpos
,
16103 bottom_vpos
, delta
, delta_bytes
);
16105 /* Adjust Y positions. */
16107 shift_glyph_matrix (w
, current_matrix
,
16108 first_unchanged_at_end_vpos
+ dvpos
,
16111 if (first_unchanged_at_end_row
)
16113 first_unchanged_at_end_row
+= dvpos
;
16114 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16115 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16116 first_unchanged_at_end_row
= NULL
;
16119 /* If scrolling up, there may be some lines to display at the end of
16121 last_text_row_at_end
= NULL
;
16124 /* Scrolling up can leave for example a partially visible line
16125 at the end of the window to be redisplayed. */
16126 /* Set last_row to the glyph row in the current matrix where the
16127 window end line is found. It has been moved up or down in
16128 the matrix by dvpos. */
16129 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16130 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16132 /* If last_row is the window end line, it should display text. */
16133 xassert (last_row
->displays_text_p
);
16135 /* If window end line was partially visible before, begin
16136 displaying at that line. Otherwise begin displaying with the
16137 line following it. */
16138 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16140 init_to_row_start (&it
, w
, last_row
);
16141 it
.vpos
= last_vpos
;
16142 it
.current_y
= last_row
->y
;
16146 init_to_row_end (&it
, w
, last_row
);
16147 it
.vpos
= 1 + last_vpos
;
16148 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16152 /* We may start in a continuation line. If so, we have to
16153 get the right continuation_lines_width and current_x. */
16154 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16155 it
.hpos
= it
.current_x
= 0;
16157 /* Display the rest of the lines at the window end. */
16158 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16159 while (it
.current_y
< it
.last_visible_y
16160 && !fonts_changed_p
)
16162 /* Is it always sure that the display agrees with lines in
16163 the current matrix? I don't think so, so we mark rows
16164 displayed invalid in the current matrix by setting their
16165 enabled_p flag to zero. */
16166 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16167 if (display_line (&it
))
16168 last_text_row_at_end
= it
.glyph_row
- 1;
16172 /* Update window_end_pos and window_end_vpos. */
16173 if (first_unchanged_at_end_row
16174 && !last_text_row_at_end
)
16176 /* Window end line if one of the preserved rows from the current
16177 matrix. Set row to the last row displaying text in current
16178 matrix starting at first_unchanged_at_end_row, after
16180 xassert (first_unchanged_at_end_row
->displays_text_p
);
16181 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16182 first_unchanged_at_end_row
);
16183 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16185 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16186 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16188 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16189 xassert (w
->window_end_bytepos
>= 0);
16190 IF_DEBUG (debug_method_add (w
, "A"));
16192 else if (last_text_row_at_end
)
16195 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16196 w
->window_end_bytepos
16197 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16199 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16200 xassert (w
->window_end_bytepos
>= 0);
16201 IF_DEBUG (debug_method_add (w
, "B"));
16203 else if (last_text_row
)
16205 /* We have displayed either to the end of the window or at the
16206 end of the window, i.e. the last row with text is to be found
16207 in the desired matrix. */
16209 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16210 w
->window_end_bytepos
16211 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16213 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16214 xassert (w
->window_end_bytepos
>= 0);
16216 else if (first_unchanged_at_end_row
== NULL
16217 && last_text_row
== NULL
16218 && last_text_row_at_end
== NULL
)
16220 /* Displayed to end of window, but no line containing text was
16221 displayed. Lines were deleted at the end of the window. */
16222 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16223 int vpos
= XFASTINT (w
->window_end_vpos
);
16224 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16225 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16228 row
== NULL
&& vpos
>= first_vpos
;
16229 --vpos
, --current_row
, --desired_row
)
16231 if (desired_row
->enabled_p
)
16233 if (desired_row
->displays_text_p
)
16236 else if (current_row
->displays_text_p
)
16240 xassert (row
!= NULL
);
16241 w
->window_end_vpos
= make_number (vpos
+ 1);
16242 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16243 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16244 xassert (w
->window_end_bytepos
>= 0);
16245 IF_DEBUG (debug_method_add (w
, "C"));
16250 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16251 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16253 /* Record that display has not been completed. */
16254 w
->window_end_valid
= Qnil
;
16255 w
->desired_matrix
->no_scrolling_p
= 1;
16263 /***********************************************************************
16264 More debugging support
16265 ***********************************************************************/
16269 void dump_glyph_row (struct glyph_row
*, int, int);
16270 void dump_glyph_matrix (struct glyph_matrix
*, int);
16271 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16274 /* Dump the contents of glyph matrix MATRIX on stderr.
16276 GLYPHS 0 means don't show glyph contents.
16277 GLYPHS 1 means show glyphs in short form
16278 GLYPHS > 1 means show glyphs in long form. */
16281 dump_glyph_matrix (matrix
, glyphs
)
16282 struct glyph_matrix
*matrix
;
16286 for (i
= 0; i
< matrix
->nrows
; ++i
)
16287 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16291 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16292 the glyph row and area where the glyph comes from. */
16295 dump_glyph (row
, glyph
, area
)
16296 struct glyph_row
*row
;
16297 struct glyph
*glyph
;
16300 if (glyph
->type
== CHAR_GLYPH
)
16303 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16304 glyph
- row
->glyphs
[TEXT_AREA
],
16307 (BUFFERP (glyph
->object
)
16309 : (STRINGP (glyph
->object
)
16312 glyph
->pixel_width
,
16314 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16318 glyph
->left_box_line_p
,
16319 glyph
->right_box_line_p
);
16321 else if (glyph
->type
== STRETCH_GLYPH
)
16324 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16325 glyph
- row
->glyphs
[TEXT_AREA
],
16328 (BUFFERP (glyph
->object
)
16330 : (STRINGP (glyph
->object
)
16333 glyph
->pixel_width
,
16337 glyph
->left_box_line_p
,
16338 glyph
->right_box_line_p
);
16340 else if (glyph
->type
== IMAGE_GLYPH
)
16343 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16344 glyph
- row
->glyphs
[TEXT_AREA
],
16347 (BUFFERP (glyph
->object
)
16349 : (STRINGP (glyph
->object
)
16352 glyph
->pixel_width
,
16356 glyph
->left_box_line_p
,
16357 glyph
->right_box_line_p
);
16359 else if (glyph
->type
== COMPOSITE_GLYPH
)
16362 " %5d %4c %6d %c %3d 0x%05x",
16363 glyph
- row
->glyphs
[TEXT_AREA
],
16366 (BUFFERP (glyph
->object
)
16368 : (STRINGP (glyph
->object
)
16371 glyph
->pixel_width
,
16373 if (glyph
->u
.cmp
.automatic
)
16376 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16377 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16379 glyph
->left_box_line_p
,
16380 glyph
->right_box_line_p
);
16385 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16386 GLYPHS 0 means don't show glyph contents.
16387 GLYPHS 1 means show glyphs in short form
16388 GLYPHS > 1 means show glyphs in long form. */
16391 dump_glyph_row (row
, vpos
, glyphs
)
16392 struct glyph_row
*row
;
16397 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16398 fprintf (stderr
, "======================================================================\n");
16400 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16401 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16403 MATRIX_ROW_START_CHARPOS (row
),
16404 MATRIX_ROW_END_CHARPOS (row
),
16405 row
->used
[TEXT_AREA
],
16406 row
->contains_overlapping_glyphs_p
,
16408 row
->truncated_on_left_p
,
16409 row
->truncated_on_right_p
,
16411 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16412 row
->displays_text_p
,
16415 row
->ends_in_middle_of_char_p
,
16416 row
->starts_in_middle_of_char_p
,
16422 row
->visible_height
,
16425 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16426 row
->end
.overlay_string_index
,
16427 row
->continuation_lines_width
);
16428 fprintf (stderr
, "%9d %5d\n",
16429 CHARPOS (row
->start
.string_pos
),
16430 CHARPOS (row
->end
.string_pos
));
16431 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16432 row
->end
.dpvec_index
);
16439 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16441 struct glyph
*glyph
= row
->glyphs
[area
];
16442 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16444 /* Glyph for a line end in text. */
16445 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16448 if (glyph
< glyph_end
)
16449 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16451 for (; glyph
< glyph_end
; ++glyph
)
16452 dump_glyph (row
, glyph
, area
);
16455 else if (glyphs
== 1)
16459 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16461 char *s
= (char *) alloca (row
->used
[area
] + 1);
16464 for (i
= 0; i
< row
->used
[area
]; ++i
)
16466 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16467 if (glyph
->type
== CHAR_GLYPH
16468 && glyph
->u
.ch
< 0x80
16469 && glyph
->u
.ch
>= ' ')
16470 s
[i
] = glyph
->u
.ch
;
16476 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16482 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16483 Sdump_glyph_matrix
, 0, 1, "p",
16484 doc
: /* Dump the current matrix of the selected window to stderr.
16485 Shows contents of glyph row structures. With non-nil
16486 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16487 glyphs in short form, otherwise show glyphs in long form. */)
16488 (Lisp_Object glyphs
)
16490 struct window
*w
= XWINDOW (selected_window
);
16491 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16493 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16494 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16495 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16496 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16497 fprintf (stderr
, "=============================================\n");
16498 dump_glyph_matrix (w
->current_matrix
,
16499 NILP (glyphs
) ? 0 : XINT (glyphs
));
16504 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16505 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16508 struct frame
*f
= XFRAME (selected_frame
);
16509 dump_glyph_matrix (f
->current_matrix
, 1);
16514 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16515 doc
: /* Dump glyph row ROW to stderr.
16516 GLYPH 0 means don't dump glyphs.
16517 GLYPH 1 means dump glyphs in short form.
16518 GLYPH > 1 or omitted means dump glyphs in long form. */)
16519 (Lisp_Object row
, Lisp_Object glyphs
)
16521 struct glyph_matrix
*matrix
;
16524 CHECK_NUMBER (row
);
16525 matrix
= XWINDOW (selected_window
)->current_matrix
;
16527 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16528 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16530 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16535 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16536 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16537 GLYPH 0 means don't dump glyphs.
16538 GLYPH 1 means dump glyphs in short form.
16539 GLYPH > 1 or omitted means dump glyphs in long form. */)
16540 (Lisp_Object row
, Lisp_Object glyphs
)
16542 struct frame
*sf
= SELECTED_FRAME ();
16543 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16546 CHECK_NUMBER (row
);
16548 if (vpos
>= 0 && vpos
< m
->nrows
)
16549 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16550 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16555 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16556 doc
: /* Toggle tracing of redisplay.
16557 With ARG, turn tracing on if and only if ARG is positive. */)
16561 trace_redisplay_p
= !trace_redisplay_p
;
16564 arg
= Fprefix_numeric_value (arg
);
16565 trace_redisplay_p
= XINT (arg
) > 0;
16572 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16573 doc
: /* Like `format', but print result to stderr.
16574 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16575 (int nargs
, Lisp_Object
*args
)
16577 Lisp_Object s
= Fformat (nargs
, args
);
16578 fprintf (stderr
, "%s", SDATA (s
));
16582 #endif /* GLYPH_DEBUG */
16586 /***********************************************************************
16587 Building Desired Matrix Rows
16588 ***********************************************************************/
16590 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16591 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16593 static struct glyph_row
*
16594 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
16596 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16597 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16598 struct buffer
*old
= current_buffer
;
16599 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16600 int arrow_len
= SCHARS (overlay_arrow_string
);
16601 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16602 const unsigned char *p
;
16605 int n_glyphs_before
;
16607 set_buffer_temp (buffer
);
16608 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16609 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16610 SET_TEXT_POS (it
.position
, 0, 0);
16612 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16614 while (p
< arrow_end
)
16616 Lisp_Object face
, ilisp
;
16618 /* Get the next character. */
16620 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
16623 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
16624 if (! ASCII_CHAR_P (it
.c
))
16625 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
16629 /* Get its face. */
16630 ilisp
= make_number (p
- arrow_string
);
16631 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16632 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
16634 /* Compute its width, get its glyphs. */
16635 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16636 SET_TEXT_POS (it
.position
, -1, -1);
16637 PRODUCE_GLYPHS (&it
);
16639 /* If this character doesn't fit any more in the line, we have
16640 to remove some glyphs. */
16641 if (it
.current_x
> it
.last_visible_x
)
16643 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16648 set_buffer_temp (old
);
16649 return it
.glyph_row
;
16653 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16654 glyphs are only inserted for terminal frames since we can't really
16655 win with truncation glyphs when partially visible glyphs are
16656 involved. Which glyphs to insert is determined by
16657 produce_special_glyphs. */
16660 insert_left_trunc_glyphs (struct it
*it
)
16662 struct it truncate_it
;
16663 struct glyph
*from
, *end
, *to
, *toend
;
16665 xassert (!FRAME_WINDOW_P (it
->f
));
16667 /* Get the truncation glyphs. */
16669 truncate_it
.current_x
= 0;
16670 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16671 truncate_it
.glyph_row
= &scratch_glyph_row
;
16672 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16673 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16674 truncate_it
.object
= make_number (0);
16675 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16677 /* Overwrite glyphs from IT with truncation glyphs. */
16678 if (!it
->glyph_row
->reversed_p
)
16680 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16681 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16682 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16683 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16688 /* There may be padding glyphs left over. Overwrite them too. */
16689 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16691 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16697 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16701 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
16702 that back to front. */
16703 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16704 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16705 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16706 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16708 while (from
>= end
&& to
>= toend
)
16710 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
16713 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
16714 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16715 while (from
>= end
&& to
>= toend
)
16720 /* Need to free some room before prepending additional
16722 int move_by
= from
- end
+ 1;
16723 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16724 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16726 for ( ; g
>= g0
; g
--)
16728 while (from
>= end
)
16730 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
16736 /* Compute the pixel height and width of IT->glyph_row.
16738 Most of the time, ascent and height of a display line will be equal
16739 to the max_ascent and max_height values of the display iterator
16740 structure. This is not the case if
16742 1. We hit ZV without displaying anything. In this case, max_ascent
16743 and max_height will be zero.
16745 2. We have some glyphs that don't contribute to the line height.
16746 (The glyph row flag contributes_to_line_height_p is for future
16747 pixmap extensions).
16749 The first case is easily covered by using default values because in
16750 these cases, the line height does not really matter, except that it
16751 must not be zero. */
16754 compute_line_metrics (struct it
*it
)
16756 struct glyph_row
*row
= it
->glyph_row
;
16759 if (FRAME_WINDOW_P (it
->f
))
16761 int i
, min_y
, max_y
;
16763 /* The line may consist of one space only, that was added to
16764 place the cursor on it. If so, the row's height hasn't been
16766 if (row
->height
== 0)
16768 if (it
->max_ascent
+ it
->max_descent
== 0)
16769 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16770 row
->ascent
= it
->max_ascent
;
16771 row
->height
= it
->max_ascent
+ it
->max_descent
;
16772 row
->phys_ascent
= it
->max_phys_ascent
;
16773 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16774 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16777 /* Compute the width of this line. */
16778 row
->pixel_width
= row
->x
;
16779 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16780 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16782 xassert (row
->pixel_width
>= 0);
16783 xassert (row
->ascent
>= 0 && row
->height
> 0);
16785 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16786 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16788 /* If first line's physical ascent is larger than its logical
16789 ascent, use the physical ascent, and make the row taller.
16790 This makes accented characters fully visible. */
16791 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16792 && row
->phys_ascent
> row
->ascent
)
16794 row
->height
+= row
->phys_ascent
- row
->ascent
;
16795 row
->ascent
= row
->phys_ascent
;
16798 /* Compute how much of the line is visible. */
16799 row
->visible_height
= row
->height
;
16801 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16802 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16804 if (row
->y
< min_y
)
16805 row
->visible_height
-= min_y
- row
->y
;
16806 if (row
->y
+ row
->height
> max_y
)
16807 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16811 row
->pixel_width
= row
->used
[TEXT_AREA
];
16812 if (row
->continued_p
)
16813 row
->pixel_width
-= it
->continuation_pixel_width
;
16814 else if (row
->truncated_on_right_p
)
16815 row
->pixel_width
-= it
->truncation_pixel_width
;
16816 row
->ascent
= row
->phys_ascent
= 0;
16817 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16818 row
->extra_line_spacing
= 0;
16821 /* Compute a hash code for this row. */
16823 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16824 for (i
= 0; i
< row
->used
[area
]; ++i
)
16825 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16826 + row
->glyphs
[area
][i
].u
.val
16827 + row
->glyphs
[area
][i
].face_id
16828 + row
->glyphs
[area
][i
].padding_p
16829 + (row
->glyphs
[area
][i
].type
<< 2));
16831 it
->max_ascent
= it
->max_descent
= 0;
16832 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16836 /* Append one space to the glyph row of iterator IT if doing a
16837 window-based redisplay. The space has the same face as
16838 IT->face_id. Value is non-zero if a space was added.
16840 This function is called to make sure that there is always one glyph
16841 at the end of a glyph row that the cursor can be set on under
16842 window-systems. (If there weren't such a glyph we would not know
16843 how wide and tall a box cursor should be displayed).
16845 At the same time this space let's a nicely handle clearing to the
16846 end of the line if the row ends in italic text. */
16849 append_space_for_newline (struct it
*it
, int default_face_p
)
16851 if (FRAME_WINDOW_P (it
->f
))
16853 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16855 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16856 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16858 /* Save some values that must not be changed.
16859 Must save IT->c and IT->len because otherwise
16860 ITERATOR_AT_END_P wouldn't work anymore after
16861 append_space_for_newline has been called. */
16862 enum display_element_type saved_what
= it
->what
;
16863 int saved_c
= it
->c
, saved_len
= it
->len
;
16864 int saved_char_to_display
= it
->char_to_display
;
16865 int saved_x
= it
->current_x
;
16866 int saved_face_id
= it
->face_id
;
16867 struct text_pos saved_pos
;
16868 Lisp_Object saved_object
;
16871 saved_object
= it
->object
;
16872 saved_pos
= it
->position
;
16874 it
->what
= IT_CHARACTER
;
16875 memset (&it
->position
, 0, sizeof it
->position
);
16876 it
->object
= make_number (0);
16877 it
->c
= it
->char_to_display
= ' ';
16880 if (default_face_p
)
16881 it
->face_id
= DEFAULT_FACE_ID
;
16882 else if (it
->face_before_selective_p
)
16883 it
->face_id
= it
->saved_face_id
;
16884 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16885 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16887 PRODUCE_GLYPHS (it
);
16889 it
->override_ascent
= -1;
16890 it
->constrain_row_ascent_descent_p
= 0;
16891 it
->current_x
= saved_x
;
16892 it
->object
= saved_object
;
16893 it
->position
= saved_pos
;
16894 it
->what
= saved_what
;
16895 it
->face_id
= saved_face_id
;
16896 it
->len
= saved_len
;
16898 it
->char_to_display
= saved_char_to_display
;
16907 /* Extend the face of the last glyph in the text area of IT->glyph_row
16908 to the end of the display line. Called from display_line. If the
16909 glyph row is empty, add a space glyph to it so that we know the
16910 face to draw. Set the glyph row flag fill_line_p. If the glyph
16911 row is R2L, prepend a stretch glyph to cover the empty space to the
16912 left of the leftmost glyph. */
16915 extend_face_to_end_of_line (struct it
*it
)
16918 struct frame
*f
= it
->f
;
16920 /* If line is already filled, do nothing. Non window-system frames
16921 get a grace of one more ``pixel'' because their characters are
16922 1-``pixel'' wide, so they hit the equality too early. This grace
16923 is needed only for R2L rows that are not continued, to produce
16924 one extra blank where we could display the cursor. */
16925 if (it
->current_x
>= it
->last_visible_x
16926 + (!FRAME_WINDOW_P (f
)
16927 && it
->glyph_row
->reversed_p
16928 && !it
->glyph_row
->continued_p
))
16931 /* Face extension extends the background and box of IT->face_id
16932 to the end of the line. If the background equals the background
16933 of the frame, we don't have to do anything. */
16934 if (it
->face_before_selective_p
)
16935 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
16937 face
= FACE_FROM_ID (f
, it
->face_id
);
16939 if (FRAME_WINDOW_P (f
)
16940 && it
->glyph_row
->displays_text_p
16941 && face
->box
== FACE_NO_BOX
16942 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16944 && !it
->glyph_row
->reversed_p
)
16947 /* Set the glyph row flag indicating that the face of the last glyph
16948 in the text area has to be drawn to the end of the text area. */
16949 it
->glyph_row
->fill_line_p
= 1;
16951 /* If current character of IT is not ASCII, make sure we have the
16952 ASCII face. This will be automatically undone the next time
16953 get_next_display_element returns a multibyte character. Note
16954 that the character will always be single byte in unibyte
16956 if (!ASCII_CHAR_P (it
->c
))
16958 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16961 if (FRAME_WINDOW_P (f
))
16963 /* If the row is empty, add a space with the current face of IT,
16964 so that we know which face to draw. */
16965 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16967 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16968 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16969 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16971 #ifdef HAVE_WINDOW_SYSTEM
16972 if (it
->glyph_row
->reversed_p
)
16974 /* Prepend a stretch glyph to the row, such that the
16975 rightmost glyph will be drawn flushed all the way to the
16976 right margin of the window. The stretch glyph that will
16977 occupy the empty space, if any, to the left of the
16979 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
16980 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16981 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
16983 int row_width
, stretch_ascent
, stretch_width
;
16984 struct text_pos saved_pos
;
16985 int saved_face_id
, saved_avoid_cursor
;
16987 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
16988 row_width
+= g
->pixel_width
;
16989 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
16990 if (stretch_width
> 0)
16993 (((it
->ascent
+ it
->descent
)
16994 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
16995 saved_pos
= it
->position
;
16996 memset (&it
->position
, 0, sizeof it
->position
);
16997 saved_avoid_cursor
= it
->avoid_cursor_p
;
16998 it
->avoid_cursor_p
= 1;
16999 saved_face_id
= it
->face_id
;
17000 /* The last row's stretch glyph should get the default
17001 face, to avoid painting the rest of the window with
17002 the region face, if the region ends at ZV. */
17003 if (it
->glyph_row
->ends_at_zv_p
)
17004 it
->face_id
= DEFAULT_FACE_ID
;
17006 it
->face_id
= face
->id
;
17007 append_stretch_glyph (it
, make_number (0), stretch_width
,
17008 it
->ascent
+ it
->descent
, stretch_ascent
);
17009 it
->position
= saved_pos
;
17010 it
->avoid_cursor_p
= saved_avoid_cursor
;
17011 it
->face_id
= saved_face_id
;
17014 #endif /* HAVE_WINDOW_SYSTEM */
17018 /* Save some values that must not be changed. */
17019 int saved_x
= it
->current_x
;
17020 struct text_pos saved_pos
;
17021 Lisp_Object saved_object
;
17022 enum display_element_type saved_what
= it
->what
;
17023 int saved_face_id
= it
->face_id
;
17025 saved_object
= it
->object
;
17026 saved_pos
= it
->position
;
17028 it
->what
= IT_CHARACTER
;
17029 memset (&it
->position
, 0, sizeof it
->position
);
17030 it
->object
= make_number (0);
17031 it
->c
= it
->char_to_display
= ' ';
17033 /* The last row's blank glyphs should get the default face, to
17034 avoid painting the rest of the window with the region face,
17035 if the region ends at ZV. */
17036 if (it
->glyph_row
->ends_at_zv_p
)
17037 it
->face_id
= DEFAULT_FACE_ID
;
17039 it
->face_id
= face
->id
;
17041 PRODUCE_GLYPHS (it
);
17043 while (it
->current_x
<= it
->last_visible_x
)
17044 PRODUCE_GLYPHS (it
);
17046 /* Don't count these blanks really. It would let us insert a left
17047 truncation glyph below and make us set the cursor on them, maybe. */
17048 it
->current_x
= saved_x
;
17049 it
->object
= saved_object
;
17050 it
->position
= saved_pos
;
17051 it
->what
= saved_what
;
17052 it
->face_id
= saved_face_id
;
17057 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17058 trailing whitespace. */
17061 trailing_whitespace_p (EMACS_INT charpos
)
17063 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17066 while (bytepos
< ZV_BYTE
17067 && (c
= FETCH_CHAR (bytepos
),
17068 c
== ' ' || c
== '\t'))
17071 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17073 if (bytepos
!= PT_BYTE
)
17080 /* Highlight trailing whitespace, if any, in ROW. */
17083 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17085 int used
= row
->used
[TEXT_AREA
];
17089 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17090 struct glyph
*glyph
= start
+ used
- 1;
17092 if (row
->reversed_p
)
17094 /* Right-to-left rows need to be processed in the opposite
17095 direction, so swap the edge pointers. */
17097 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17100 /* Skip over glyphs inserted to display the cursor at the
17101 end of a line, for extending the face of the last glyph
17102 to the end of the line on terminals, and for truncation
17103 and continuation glyphs. */
17104 if (!row
->reversed_p
)
17106 while (glyph
>= start
17107 && glyph
->type
== CHAR_GLYPH
17108 && INTEGERP (glyph
->object
))
17113 while (glyph
<= start
17114 && glyph
->type
== CHAR_GLYPH
17115 && INTEGERP (glyph
->object
))
17119 /* If last glyph is a space or stretch, and it's trailing
17120 whitespace, set the face of all trailing whitespace glyphs in
17121 IT->glyph_row to `trailing-whitespace'. */
17122 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17123 && BUFFERP (glyph
->object
)
17124 && (glyph
->type
== STRETCH_GLYPH
17125 || (glyph
->type
== CHAR_GLYPH
17126 && glyph
->u
.ch
== ' '))
17127 && trailing_whitespace_p (glyph
->charpos
))
17129 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17133 if (!row
->reversed_p
)
17135 while (glyph
>= start
17136 && BUFFERP (glyph
->object
)
17137 && (glyph
->type
== STRETCH_GLYPH
17138 || (glyph
->type
== CHAR_GLYPH
17139 && glyph
->u
.ch
== ' ')))
17140 (glyph
--)->face_id
= face_id
;
17144 while (glyph
<= start
17145 && BUFFERP (glyph
->object
)
17146 && (glyph
->type
== STRETCH_GLYPH
17147 || (glyph
->type
== CHAR_GLYPH
17148 && glyph
->u
.ch
== ' ')))
17149 (glyph
++)->face_id
= face_id
;
17156 /* Value is non-zero if glyph row ROW in window W should be
17157 used to hold the cursor. */
17160 cursor_row_p (struct window
*w
, struct glyph_row
*row
)
17162 int cursor_row_p
= 1;
17164 if (PT
== CHARPOS (row
->end
.pos
))
17166 /* Suppose the row ends on a string.
17167 Unless the row is continued, that means it ends on a newline
17168 in the string. If it's anything other than a display string
17169 (e.g. a before-string from an overlay), we don't want the
17170 cursor there. (This heuristic seems to give the optimal
17171 behavior for the various types of multi-line strings.) */
17172 if (CHARPOS (row
->end
.string_pos
) >= 0)
17174 if (row
->continued_p
)
17178 /* Check for `display' property. */
17179 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17180 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17181 struct glyph
*glyph
;
17184 for (glyph
= end
; glyph
>= beg
; --glyph
)
17185 if (STRINGP (glyph
->object
))
17188 = Fget_char_property (make_number (PT
),
17192 && display_prop_string_p (prop
, glyph
->object
));
17197 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17199 /* If the row ends in middle of a real character,
17200 and the line is continued, we want the cursor here.
17201 That's because CHARPOS (ROW->end.pos) would equal
17202 PT if PT is before the character. */
17203 if (!row
->ends_in_ellipsis_p
)
17204 cursor_row_p
= row
->continued_p
;
17206 /* If the row ends in an ellipsis, then
17207 CHARPOS (ROW->end.pos) will equal point after the
17208 invisible text. We want that position to be displayed
17209 after the ellipsis. */
17212 /* If the row ends at ZV, display the cursor at the end of that
17213 row instead of at the start of the row below. */
17214 else if (row
->ends_at_zv_p
)
17220 return cursor_row_p
;
17225 /* Push the display property PROP so that it will be rendered at the
17226 current position in IT. Return 1 if PROP was successfully pushed,
17230 push_display_prop (struct it
*it
, Lisp_Object prop
)
17234 if (STRINGP (prop
))
17236 if (SCHARS (prop
) == 0)
17243 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17244 it
->current
.overlay_string_index
= -1;
17245 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17246 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17247 it
->method
= GET_FROM_STRING
;
17248 it
->stop_charpos
= 0;
17250 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17252 it
->method
= GET_FROM_STRETCH
;
17255 #ifdef HAVE_WINDOW_SYSTEM
17256 else if (IMAGEP (prop
))
17258 it
->what
= IT_IMAGE
;
17259 it
->image_id
= lookup_image (it
->f
, prop
);
17260 it
->method
= GET_FROM_IMAGE
;
17262 #endif /* HAVE_WINDOW_SYSTEM */
17265 pop_it (it
); /* bogus display property, give up */
17272 /* Return the character-property PROP at the current position in IT. */
17275 get_it_property (struct it
*it
, Lisp_Object prop
)
17277 Lisp_Object position
;
17279 if (STRINGP (it
->object
))
17280 position
= make_number (IT_STRING_CHARPOS (*it
));
17281 else if (BUFFERP (it
->object
))
17282 position
= make_number (IT_CHARPOS (*it
));
17286 return Fget_char_property (position
, prop
, it
->object
);
17289 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17292 handle_line_prefix (struct it
*it
)
17294 Lisp_Object prefix
;
17295 if (it
->continuation_lines_width
> 0)
17297 prefix
= get_it_property (it
, Qwrap_prefix
);
17299 prefix
= Vwrap_prefix
;
17303 prefix
= get_it_property (it
, Qline_prefix
);
17305 prefix
= Vline_prefix
;
17307 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17309 /* If the prefix is wider than the window, and we try to wrap
17310 it, it would acquire its own wrap prefix, and so on till the
17311 iterator stack overflows. So, don't wrap the prefix. */
17312 it
->line_wrap
= TRUNCATE
;
17313 it
->avoid_cursor_p
= 1;
17319 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17320 only for R2L lines from display_line, when it decides that too many
17321 glyphs were produced by PRODUCE_GLYPHS, and the line needs to be
17324 unproduce_glyphs (struct it
*it
, int n
)
17326 struct glyph
*glyph
, *end
;
17328 xassert (it
->glyph_row
);
17329 xassert (it
->glyph_row
->reversed_p
);
17330 xassert (it
->area
== TEXT_AREA
);
17331 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17333 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17334 n
= it
->glyph_row
->used
[TEXT_AREA
];
17335 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17336 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17337 for ( ; glyph
< end
; glyph
++)
17338 glyph
[-n
] = *glyph
;
17341 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17342 and ROW->maxpos. */
17344 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17345 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17346 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17348 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17349 lines' rows is implemented for bidi-reordered rows. */
17351 /* ROW->minpos is the value of min_pos, the minimal buffer position
17354 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17357 /* We didn't find _any_ valid buffer positions in any of the
17358 glyphs, so we must trust the iterator's computed
17360 row
->minpos
= row
->start
.pos
;
17361 max_pos
= CHARPOS (it
->current
.pos
);
17362 max_bpos
= BYTEPOS (it
->current
.pos
);
17368 /* Here are the various use-cases for ending the row, and the
17369 corresponding values for ROW->maxpos:
17371 Line ends in a newline from buffer eol_pos + 1
17372 Line is continued from buffer max_pos + 1
17373 Line is truncated on right it->current.pos
17374 Line ends in a newline from string max_pos
17375 Line is continued from string max_pos
17376 Line is continued from display vector max_pos
17377 Line is entirely from a string min_pos == max_pos
17378 Line is entirely from a display vector min_pos == max_pos
17379 Line that ends at ZV ZV
17381 If you discover other use-cases, please add them here as
17383 if (row
->ends_at_zv_p
)
17384 row
->maxpos
= it
->current
.pos
;
17385 else if (row
->used
[TEXT_AREA
])
17387 if (row
->ends_in_newline_from_string_p
)
17388 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17389 else if (CHARPOS (it
->eol_pos
) > 0)
17390 SET_TEXT_POS (row
->maxpos
,
17391 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17392 else if (row
->continued_p
)
17394 /* If max_pos is different from IT's current position, it
17395 means IT->method does not belong to the display element
17396 at max_pos. However, it also means that the display
17397 element at max_pos was displayed in its entirety on this
17398 line, which is equivalent to saying that the next line
17399 starts at the next buffer position. */
17400 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17401 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17404 INC_BOTH (max_pos
, max_bpos
);
17405 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17408 else if (row
->truncated_on_right_p
)
17409 /* display_line already called reseat_at_next_visible_line_start,
17410 which puts the iterator at the beginning of the next line, in
17411 the logical order. */
17412 row
->maxpos
= it
->current
.pos
;
17413 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17414 /* A line that is entirely from a string/image/stretch... */
17415 row
->maxpos
= row
->minpos
;
17420 row
->maxpos
= it
->current
.pos
;
17423 /* Construct the glyph row IT->glyph_row in the desired matrix of
17424 IT->w from text at the current position of IT. See dispextern.h
17425 for an overview of struct it. Value is non-zero if
17426 IT->glyph_row displays text, as opposed to a line displaying ZV
17430 display_line (struct it
*it
)
17432 struct glyph_row
*row
= it
->glyph_row
;
17433 Lisp_Object overlay_arrow_string
;
17435 int may_wrap
= 0, wrap_x
;
17436 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
17437 int wrap_row_phys_ascent
, wrap_row_phys_height
;
17438 int wrap_row_extra_line_spacing
;
17439 EMACS_INT wrap_row_min_pos
, wrap_row_min_bpos
;
17440 EMACS_INT wrap_row_max_pos
, wrap_row_max_bpos
;
17442 EMACS_INT min_pos
= ZV
+ 1, min_bpos
, max_pos
= 0, max_bpos
;
17444 /* We always start displaying at hpos zero even if hscrolled. */
17445 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17447 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17448 >= it
->w
->desired_matrix
->nrows
)
17450 it
->w
->nrows_scale_factor
++;
17451 fonts_changed_p
= 1;
17455 /* Is IT->w showing the region? */
17456 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17458 /* Clear the result glyph row and enable it. */
17459 prepare_desired_row (row
);
17461 row
->y
= it
->current_y
;
17462 row
->start
= it
->start
;
17463 row
->continuation_lines_width
= it
->continuation_lines_width
;
17464 row
->displays_text_p
= 1;
17465 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17466 it
->starts_in_middle_of_char_p
= 0;
17468 /* Arrange the overlays nicely for our purposes. Usually, we call
17469 display_line on only one line at a time, in which case this
17470 can't really hurt too much, or we call it on lines which appear
17471 one after another in the buffer, in which case all calls to
17472 recenter_overlay_lists but the first will be pretty cheap. */
17473 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17475 /* Move over display elements that are not visible because we are
17476 hscrolled. This may stop at an x-position < IT->first_visible_x
17477 if the first glyph is partially visible or if we hit a line end. */
17478 if (it
->current_x
< it
->first_visible_x
)
17480 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17481 MOVE_TO_POS
| MOVE_TO_X
);
17485 /* We only do this when not calling `move_it_in_display_line_to'
17486 above, because move_it_in_display_line_to calls
17487 handle_line_prefix itself. */
17488 handle_line_prefix (it
);
17491 /* Get the initial row height. This is either the height of the
17492 text hscrolled, if there is any, or zero. */
17493 row
->ascent
= it
->max_ascent
;
17494 row
->height
= it
->max_ascent
+ it
->max_descent
;
17495 row
->phys_ascent
= it
->max_phys_ascent
;
17496 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17497 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17499 /* Utility macro to record max and min buffer positions seen until now. */
17500 #define RECORD_MAX_MIN_POS(IT) \
17503 if (IT_CHARPOS (*(IT)) < min_pos) \
17505 min_pos = IT_CHARPOS (*(IT)); \
17506 min_bpos = IT_BYTEPOS (*(IT)); \
17508 if (IT_CHARPOS (*(IT)) > max_pos) \
17510 max_pos = IT_CHARPOS (*(IT)); \
17511 max_bpos = IT_BYTEPOS (*(IT)); \
17516 /* Loop generating characters. The loop is left with IT on the next
17517 character to display. */
17520 int n_glyphs_before
, hpos_before
, x_before
;
17522 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17524 /* Retrieve the next thing to display. Value is zero if end of
17526 if (!get_next_display_element (it
))
17528 /* Maybe add a space at the end of this line that is used to
17529 display the cursor there under X. Set the charpos of the
17530 first glyph of blank lines not corresponding to any text
17532 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17533 row
->exact_window_width_line_p
= 1;
17534 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17535 || row
->used
[TEXT_AREA
] == 0)
17537 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17538 row
->displays_text_p
= 0;
17540 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17541 && (!MINI_WINDOW_P (it
->w
)
17542 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17543 row
->indicate_empty_line_p
= 1;
17546 it
->continuation_lines_width
= 0;
17547 row
->ends_at_zv_p
= 1;
17548 /* A row that displays right-to-left text must always have
17549 its last face extended all the way to the end of line,
17550 even if this row ends in ZV, because we still write to
17551 the screen left to right. */
17552 if (row
->reversed_p
)
17553 extend_face_to_end_of_line (it
);
17557 /* Now, get the metrics of what we want to display. This also
17558 generates glyphs in `row' (which is IT->glyph_row). */
17559 n_glyphs_before
= row
->used
[TEXT_AREA
];
17562 /* Remember the line height so far in case the next element doesn't
17563 fit on the line. */
17564 if (it
->line_wrap
!= TRUNCATE
)
17566 ascent
= it
->max_ascent
;
17567 descent
= it
->max_descent
;
17568 phys_ascent
= it
->max_phys_ascent
;
17569 phys_descent
= it
->max_phys_descent
;
17571 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17573 if (IT_DISPLAYING_WHITESPACE (it
))
17579 wrap_row_used
= row
->used
[TEXT_AREA
];
17580 wrap_row_ascent
= row
->ascent
;
17581 wrap_row_height
= row
->height
;
17582 wrap_row_phys_ascent
= row
->phys_ascent
;
17583 wrap_row_phys_height
= row
->phys_height
;
17584 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17585 wrap_row_min_pos
= min_pos
;
17586 wrap_row_min_bpos
= min_bpos
;
17587 wrap_row_max_pos
= max_pos
;
17588 wrap_row_max_bpos
= max_bpos
;
17594 PRODUCE_GLYPHS (it
);
17596 /* If this display element was in marginal areas, continue with
17598 if (it
->area
!= TEXT_AREA
)
17600 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17601 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17602 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17603 row
->phys_height
= max (row
->phys_height
,
17604 it
->max_phys_ascent
+ it
->max_phys_descent
);
17605 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17606 it
->max_extra_line_spacing
);
17607 set_iterator_to_next (it
, 1);
17611 /* Does the display element fit on the line? If we truncate
17612 lines, we should draw past the right edge of the window. If
17613 we don't truncate, we want to stop so that we can display the
17614 continuation glyph before the right margin. If lines are
17615 continued, there are two possible strategies for characters
17616 resulting in more than 1 glyph (e.g. tabs): Display as many
17617 glyphs as possible in this line and leave the rest for the
17618 continuation line, or display the whole element in the next
17619 line. Original redisplay did the former, so we do it also. */
17620 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17621 hpos_before
= it
->hpos
;
17624 if (/* Not a newline. */
17626 /* Glyphs produced fit entirely in the line. */
17627 && it
->current_x
< it
->last_visible_x
)
17629 it
->hpos
+= nglyphs
;
17630 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17631 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17632 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17633 row
->phys_height
= max (row
->phys_height
,
17634 it
->max_phys_ascent
+ it
->max_phys_descent
);
17635 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17636 it
->max_extra_line_spacing
);
17637 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17638 row
->x
= x
- it
->first_visible_x
;
17639 /* Record the maximum and minimum buffer positions seen so
17640 far in glyphs that will be displayed by this row. */
17642 RECORD_MAX_MIN_POS (it
);
17647 struct glyph
*glyph
;
17649 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17651 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17652 new_x
= x
+ glyph
->pixel_width
;
17654 if (/* Lines are continued. */
17655 it
->line_wrap
!= TRUNCATE
17656 && (/* Glyph doesn't fit on the line. */
17657 new_x
> it
->last_visible_x
17658 /* Or it fits exactly on a window system frame. */
17659 || (new_x
== it
->last_visible_x
17660 && FRAME_WINDOW_P (it
->f
))))
17662 /* End of a continued line. */
17665 || (new_x
== it
->last_visible_x
17666 && FRAME_WINDOW_P (it
->f
)))
17668 /* Current glyph is the only one on the line or
17669 fits exactly on the line. We must continue
17670 the line because we can't draw the cursor
17671 after the glyph. */
17672 row
->continued_p
= 1;
17673 it
->current_x
= new_x
;
17674 it
->continuation_lines_width
+= new_x
;
17676 /* Record the maximum and minimum buffer
17677 positions seen so far in glyphs that will be
17678 displayed by this row. */
17680 RECORD_MAX_MIN_POS (it
);
17681 if (i
== nglyphs
- 1)
17683 /* If line-wrap is on, check if a previous
17684 wrap point was found. */
17685 if (wrap_row_used
> 0
17686 /* Even if there is a previous wrap
17687 point, continue the line here as
17688 usual, if (i) the previous character
17689 was a space or tab AND (ii) the
17690 current character is not. */
17692 || IT_DISPLAYING_WHITESPACE (it
)))
17695 set_iterator_to_next (it
, 1);
17696 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17698 if (!get_next_display_element (it
))
17700 row
->exact_window_width_line_p
= 1;
17701 it
->continuation_lines_width
= 0;
17702 row
->continued_p
= 0;
17703 row
->ends_at_zv_p
= 1;
17705 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17707 row
->continued_p
= 0;
17708 row
->exact_window_width_line_p
= 1;
17713 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17714 && !FRAME_WINDOW_P (it
->f
))
17716 /* A padding glyph that doesn't fit on this line.
17717 This means the whole character doesn't fit
17719 if (row
->reversed_p
)
17720 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17721 - n_glyphs_before
);
17722 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17724 /* Fill the rest of the row with continuation
17725 glyphs like in 20.x. */
17726 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17727 < row
->glyphs
[1 + TEXT_AREA
])
17728 produce_special_glyphs (it
, IT_CONTINUATION
);
17730 row
->continued_p
= 1;
17731 it
->current_x
= x_before
;
17732 it
->continuation_lines_width
+= x_before
;
17734 /* Restore the height to what it was before the
17735 element not fitting on the line. */
17736 it
->max_ascent
= ascent
;
17737 it
->max_descent
= descent
;
17738 it
->max_phys_ascent
= phys_ascent
;
17739 it
->max_phys_descent
= phys_descent
;
17741 else if (wrap_row_used
> 0)
17744 if (row
->reversed_p
)
17745 unproduce_glyphs (it
,
17746 row
->used
[TEXT_AREA
] - wrap_row_used
);
17748 it
->continuation_lines_width
+= wrap_x
;
17749 row
->used
[TEXT_AREA
] = wrap_row_used
;
17750 row
->ascent
= wrap_row_ascent
;
17751 row
->height
= wrap_row_height
;
17752 row
->phys_ascent
= wrap_row_phys_ascent
;
17753 row
->phys_height
= wrap_row_phys_height
;
17754 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17755 min_pos
= wrap_row_min_pos
;
17756 min_bpos
= wrap_row_min_bpos
;
17757 max_pos
= wrap_row_max_pos
;
17758 max_bpos
= wrap_row_max_bpos
;
17759 row
->continued_p
= 1;
17760 row
->ends_at_zv_p
= 0;
17761 row
->exact_window_width_line_p
= 0;
17762 it
->continuation_lines_width
+= x
;
17764 /* Make sure that a non-default face is extended
17765 up to the right margin of the window. */
17766 extend_face_to_end_of_line (it
);
17768 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17770 /* A TAB that extends past the right edge of the
17771 window. This produces a single glyph on
17772 window system frames. We leave the glyph in
17773 this row and let it fill the row, but don't
17774 consume the TAB. */
17775 it
->continuation_lines_width
+= it
->last_visible_x
;
17776 row
->ends_in_middle_of_char_p
= 1;
17777 row
->continued_p
= 1;
17778 glyph
->pixel_width
= it
->last_visible_x
- x
;
17779 it
->starts_in_middle_of_char_p
= 1;
17783 /* Something other than a TAB that draws past
17784 the right edge of the window. Restore
17785 positions to values before the element. */
17786 if (row
->reversed_p
)
17787 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17788 - (n_glyphs_before
+ i
));
17789 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17791 /* Display continuation glyphs. */
17792 if (!FRAME_WINDOW_P (it
->f
))
17793 produce_special_glyphs (it
, IT_CONTINUATION
);
17794 row
->continued_p
= 1;
17796 it
->current_x
= x_before
;
17797 it
->continuation_lines_width
+= x
;
17798 extend_face_to_end_of_line (it
);
17800 if (nglyphs
> 1 && i
> 0)
17802 row
->ends_in_middle_of_char_p
= 1;
17803 it
->starts_in_middle_of_char_p
= 1;
17806 /* Restore the height to what it was before the
17807 element not fitting on the line. */
17808 it
->max_ascent
= ascent
;
17809 it
->max_descent
= descent
;
17810 it
->max_phys_ascent
= phys_ascent
;
17811 it
->max_phys_descent
= phys_descent
;
17816 else if (new_x
> it
->first_visible_x
)
17818 /* Increment number of glyphs actually displayed. */
17821 /* Record the maximum and minimum buffer positions
17822 seen so far in glyphs that will be displayed by
17825 RECORD_MAX_MIN_POS (it
);
17827 if (x
< it
->first_visible_x
)
17828 /* Glyph is partially visible, i.e. row starts at
17829 negative X position. */
17830 row
->x
= x
- it
->first_visible_x
;
17834 /* Glyph is completely off the left margin of the
17835 window. This should not happen because of the
17836 move_it_in_display_line at the start of this
17837 function, unless the text display area of the
17838 window is empty. */
17839 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17843 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17844 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17845 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17846 row
->phys_height
= max (row
->phys_height
,
17847 it
->max_phys_ascent
+ it
->max_phys_descent
);
17848 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17849 it
->max_extra_line_spacing
);
17851 /* End of this display line if row is continued. */
17852 if (row
->continued_p
|| row
->ends_at_zv_p
)
17857 /* Is this a line end? If yes, we're also done, after making
17858 sure that a non-default face is extended up to the right
17859 margin of the window. */
17860 if (ITERATOR_AT_END_OF_LINE_P (it
))
17862 int used_before
= row
->used
[TEXT_AREA
];
17864 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17866 /* Add a space at the end of the line that is used to
17867 display the cursor there. */
17868 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17869 append_space_for_newline (it
, 0);
17871 /* Extend the face to the end of the line. */
17872 extend_face_to_end_of_line (it
);
17874 /* Make sure we have the position. */
17875 if (used_before
== 0)
17876 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17878 /* Record the position of the newline, for use in
17880 it
->eol_pos
= it
->current
.pos
;
17882 /* Consume the line end. This skips over invisible lines. */
17883 set_iterator_to_next (it
, 1);
17884 it
->continuation_lines_width
= 0;
17888 /* Proceed with next display element. Note that this skips
17889 over lines invisible because of selective display. */
17890 set_iterator_to_next (it
, 1);
17892 /* If we truncate lines, we are done when the last displayed
17893 glyphs reach past the right margin of the window. */
17894 if (it
->line_wrap
== TRUNCATE
17895 && (FRAME_WINDOW_P (it
->f
)
17896 ? (it
->current_x
>= it
->last_visible_x
)
17897 : (it
->current_x
> it
->last_visible_x
)))
17899 /* Maybe add truncation glyphs. */
17900 if (!FRAME_WINDOW_P (it
->f
))
17904 if (!row
->reversed_p
)
17906 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17907 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17912 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
17913 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17915 /* Remove any padding glyphs at the front of ROW, to
17916 make room for the truncation glyphs we will be
17917 adding below. The loop below always inserts at
17918 least one truncation glyph, so also remove the
17919 last glyph added to ROW. */
17920 unproduce_glyphs (it
, i
+ 1);
17921 /* Adjust i for the loop below. */
17922 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
17925 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17927 row
->used
[TEXT_AREA
] = i
;
17928 produce_special_glyphs (it
, IT_TRUNCATION
);
17931 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17933 /* Don't truncate if we can overflow newline into fringe. */
17934 if (!get_next_display_element (it
))
17936 it
->continuation_lines_width
= 0;
17937 row
->ends_at_zv_p
= 1;
17938 row
->exact_window_width_line_p
= 1;
17941 if (ITERATOR_AT_END_OF_LINE_P (it
))
17943 row
->exact_window_width_line_p
= 1;
17944 goto at_end_of_line
;
17948 row
->truncated_on_right_p
= 1;
17949 it
->continuation_lines_width
= 0;
17950 reseat_at_next_visible_line_start (it
, 0);
17951 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17952 it
->hpos
= hpos_before
;
17953 it
->current_x
= x_before
;
17958 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17959 at the left window margin. */
17960 if (it
->first_visible_x
17961 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
17963 if (!FRAME_WINDOW_P (it
->f
))
17964 insert_left_trunc_glyphs (it
);
17965 row
->truncated_on_left_p
= 1;
17968 /* Remember the position at which this line ends.
17970 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
17971 cannot be before the call to find_row_edges below, since that is
17972 where these positions are determined. */
17973 row
->end
= it
->current
;
17976 row
->minpos
= row
->start
.pos
;
17977 row
->maxpos
= row
->end
.pos
;
17981 /* ROW->minpos and ROW->maxpos must be the smallest and
17982 `1 + the largest' buffer positions in ROW. But if ROW was
17983 bidi-reordered, these two positions can be anywhere in the
17984 row, so we must determine them now. */
17985 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
17988 /* If the start of this line is the overlay arrow-position, then
17989 mark this glyph row as the one containing the overlay arrow.
17990 This is clearly a mess with variable size fonts. It would be
17991 better to let it be displayed like cursors under X. */
17992 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17993 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17994 !NILP (overlay_arrow_string
)))
17996 /* Overlay arrow in window redisplay is a fringe bitmap. */
17997 if (STRINGP (overlay_arrow_string
))
17999 struct glyph_row
*arrow_row
18000 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18001 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18002 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18003 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18004 struct glyph
*p2
, *end
;
18006 /* Copy the arrow glyphs. */
18007 while (glyph
< arrow_end
)
18010 /* Throw away padding glyphs. */
18012 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18013 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18019 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18024 xassert (INTEGERP (overlay_arrow_string
));
18025 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18027 overlay_arrow_seen
= 1;
18030 /* Compute pixel dimensions of this line. */
18031 compute_line_metrics (it
);
18033 /* Record whether this row ends inside an ellipsis. */
18034 row
->ends_in_ellipsis_p
18035 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18036 && it
->ellipsis_p
);
18038 /* Save fringe bitmaps in this row. */
18039 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18040 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18041 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18042 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18044 it
->left_user_fringe_bitmap
= 0;
18045 it
->left_user_fringe_face_id
= 0;
18046 it
->right_user_fringe_bitmap
= 0;
18047 it
->right_user_fringe_face_id
= 0;
18049 /* Maybe set the cursor. */
18050 cvpos
= it
->w
->cursor
.vpos
;
18052 /* In bidi-reordered rows, keep checking for proper cursor
18053 position even if one has been found already, because buffer
18054 positions in such rows change non-linearly with ROW->VPOS,
18055 when a line is continued. One exception: when we are at ZV,
18056 display cursor on the first suitable glyph row, since all
18057 the empty rows after that also have their position set to ZV. */
18058 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18059 lines' rows is implemented for bidi-reordered rows. */
18061 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18062 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18063 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18064 && cursor_row_p (it
->w
, row
))
18065 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18067 /* Highlight trailing whitespace. */
18068 if (!NILP (Vshow_trailing_whitespace
))
18069 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18071 /* Prepare for the next line. This line starts horizontally at (X
18072 HPOS) = (0 0). Vertical positions are incremented. As a
18073 convenience for the caller, IT->glyph_row is set to the next
18075 it
->current_x
= it
->hpos
= 0;
18076 it
->current_y
+= row
->height
;
18077 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18080 /* The next row should by default use the same value of the
18081 reversed_p flag as this one. set_iterator_to_next decides when
18082 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18083 the flag accordingly. */
18084 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18085 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18086 it
->start
= row
->end
;
18087 return row
->displays_text_p
;
18089 #undef RECORD_MAX_MIN_POS
18092 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18093 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18094 doc
: /* Return paragraph direction at point in BUFFER.
18095 Value is either `left-to-right' or `right-to-left'.
18096 If BUFFER is omitted or nil, it defaults to the current buffer.
18098 Paragraph direction determines how the text in the paragraph is displayed.
18099 In left-to-right paragraphs, text begins at the left margin of the window
18100 and the reading direction is generally left to right. In right-to-left
18101 paragraphs, text begins at the right margin and is read from right to left.
18103 See also `bidi-paragraph-direction'. */)
18104 (Lisp_Object buffer
)
18106 struct buffer
*buf
;
18107 struct buffer
*old
;
18110 buf
= current_buffer
;
18113 CHECK_BUFFER (buffer
);
18114 buf
= XBUFFER (buffer
);
18115 old
= current_buffer
;
18118 if (NILP (buf
->bidi_display_reordering
))
18119 return Qleft_to_right
;
18120 else if (!NILP (buf
->bidi_paragraph_direction
))
18121 return buf
->bidi_paragraph_direction
;
18124 /* Determine the direction from buffer text. We could try to
18125 use current_matrix if it is up to date, but this seems fast
18126 enough as it is. */
18127 struct bidi_it itb
;
18128 EMACS_INT pos
= BUF_PT (buf
);
18129 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18132 if (buf
!= current_buffer
)
18133 set_buffer_temp (buf
);
18134 /* bidi_paragraph_init finds the base direction of the paragraph
18135 by searching forward from paragraph start. We need the base
18136 direction of the current or _previous_ paragraph, so we need
18137 to make sure we are within that paragraph. To that end, find
18138 the previous non-empty line. */
18139 if (pos
>= ZV
&& pos
> BEGV
)
18142 bytepos
= CHAR_TO_BYTE (pos
);
18144 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18145 || c
== ' ' || c
== '\t' || c
== '\f')
18147 if (bytepos
<= BEGV_BYTE
)
18152 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18155 itb
.bytepos
= bytepos
;
18157 itb
.separator_limit
= -1;
18158 itb
.paragraph_dir
= NEUTRAL_DIR
;
18160 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18161 if (buf
!= current_buffer
)
18162 set_buffer_temp (old
);
18163 switch (itb
.paragraph_dir
)
18166 return Qleft_to_right
;
18169 return Qright_to_left
;
18179 /***********************************************************************
18181 ***********************************************************************/
18183 /* Redisplay the menu bar in the frame for window W.
18185 The menu bar of X frames that don't have X toolkit support is
18186 displayed in a special window W->frame->menu_bar_window.
18188 The menu bar of terminal frames is treated specially as far as
18189 glyph matrices are concerned. Menu bar lines are not part of
18190 windows, so the update is done directly on the frame matrix rows
18191 for the menu bar. */
18194 display_menu_bar (struct window
*w
)
18196 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18201 /* Don't do all this for graphical frames. */
18203 if (FRAME_W32_P (f
))
18206 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18212 if (FRAME_NS_P (f
))
18214 #endif /* HAVE_NS */
18216 #ifdef USE_X_TOOLKIT
18217 xassert (!FRAME_WINDOW_P (f
));
18218 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18219 it
.first_visible_x
= 0;
18220 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18221 #else /* not USE_X_TOOLKIT */
18222 if (FRAME_WINDOW_P (f
))
18224 /* Menu bar lines are displayed in the desired matrix of the
18225 dummy window menu_bar_window. */
18226 struct window
*menu_w
;
18227 xassert (WINDOWP (f
->menu_bar_window
));
18228 menu_w
= XWINDOW (f
->menu_bar_window
);
18229 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18231 it
.first_visible_x
= 0;
18232 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18236 /* This is a TTY frame, i.e. character hpos/vpos are used as
18238 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18240 it
.first_visible_x
= 0;
18241 it
.last_visible_x
= FRAME_COLS (f
);
18243 #endif /* not USE_X_TOOLKIT */
18245 if (! mode_line_inverse_video
)
18246 /* Force the menu-bar to be displayed in the default face. */
18247 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18249 /* Clear all rows of the menu bar. */
18250 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18252 struct glyph_row
*row
= it
.glyph_row
+ i
;
18253 clear_glyph_row (row
);
18254 row
->enabled_p
= 1;
18255 row
->full_width_p
= 1;
18258 /* Display all items of the menu bar. */
18259 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18260 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
18262 Lisp_Object string
;
18264 /* Stop at nil string. */
18265 string
= AREF (items
, i
+ 1);
18269 /* Remember where item was displayed. */
18270 ASET (items
, i
+ 3, make_number (it
.hpos
));
18272 /* Display the item, pad with one space. */
18273 if (it
.current_x
< it
.last_visible_x
)
18274 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18275 SCHARS (string
) + 1, 0, 0, -1);
18278 /* Fill out the line with spaces. */
18279 if (it
.current_x
< it
.last_visible_x
)
18280 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18282 /* Compute the total height of the lines. */
18283 compute_line_metrics (&it
);
18288 /***********************************************************************
18290 ***********************************************************************/
18292 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18293 FORCE is non-zero, redisplay mode lines unconditionally.
18294 Otherwise, redisplay only mode lines that are garbaged. Value is
18295 the number of windows whose mode lines were redisplayed. */
18298 redisplay_mode_lines (Lisp_Object window
, int force
)
18302 while (!NILP (window
))
18304 struct window
*w
= XWINDOW (window
);
18306 if (WINDOWP (w
->hchild
))
18307 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18308 else if (WINDOWP (w
->vchild
))
18309 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18311 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18312 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18314 struct text_pos lpoint
;
18315 struct buffer
*old
= current_buffer
;
18317 /* Set the window's buffer for the mode line display. */
18318 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18319 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18321 /* Point refers normally to the selected window. For any
18322 other window, set up appropriate value. */
18323 if (!EQ (window
, selected_window
))
18325 struct text_pos pt
;
18327 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18328 if (CHARPOS (pt
) < BEGV
)
18329 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18330 else if (CHARPOS (pt
) > (ZV
- 1))
18331 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18333 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18336 /* Display mode lines. */
18337 clear_glyph_matrix (w
->desired_matrix
);
18338 if (display_mode_lines (w
))
18341 w
->must_be_updated_p
= 1;
18344 /* Restore old settings. */
18345 set_buffer_internal_1 (old
);
18346 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18356 /* Display the mode and/or header line of window W. Value is the
18357 sum number of mode lines and header lines displayed. */
18360 display_mode_lines (struct window
*w
)
18362 Lisp_Object old_selected_window
, old_selected_frame
;
18365 old_selected_frame
= selected_frame
;
18366 selected_frame
= w
->frame
;
18367 old_selected_window
= selected_window
;
18368 XSETWINDOW (selected_window
, w
);
18370 /* These will be set while the mode line specs are processed. */
18371 line_number_displayed
= 0;
18372 w
->column_number_displayed
= Qnil
;
18374 if (WINDOW_WANTS_MODELINE_P (w
))
18376 struct window
*sel_w
= XWINDOW (old_selected_window
);
18378 /* Select mode line face based on the real selected window. */
18379 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18380 current_buffer
->mode_line_format
);
18384 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18386 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18387 current_buffer
->header_line_format
);
18391 selected_frame
= old_selected_frame
;
18392 selected_window
= old_selected_window
;
18397 /* Display mode or header line of window W. FACE_ID specifies which
18398 line to display; it is either MODE_LINE_FACE_ID or
18399 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18400 display. Value is the pixel height of the mode/header line
18404 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18408 int count
= SPECPDL_INDEX ();
18410 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18411 /* Don't extend on a previously drawn mode-line.
18412 This may happen if called from pos_visible_p. */
18413 it
.glyph_row
->enabled_p
= 0;
18414 prepare_desired_row (it
.glyph_row
);
18416 it
.glyph_row
->mode_line_p
= 1;
18418 if (! mode_line_inverse_video
)
18419 /* Force the mode-line to be displayed in the default face. */
18420 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18422 record_unwind_protect (unwind_format_mode_line
,
18423 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18425 mode_line_target
= MODE_LINE_DISPLAY
;
18427 /* Temporarily make frame's keyboard the current kboard so that
18428 kboard-local variables in the mode_line_format will get the right
18430 push_kboard (FRAME_KBOARD (it
.f
));
18431 record_unwind_save_match_data ();
18432 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18435 unbind_to (count
, Qnil
);
18437 /* Fill up with spaces. */
18438 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18440 compute_line_metrics (&it
);
18441 it
.glyph_row
->full_width_p
= 1;
18442 it
.glyph_row
->continued_p
= 0;
18443 it
.glyph_row
->truncated_on_left_p
= 0;
18444 it
.glyph_row
->truncated_on_right_p
= 0;
18446 /* Make a 3D mode-line have a shadow at its right end. */
18447 face
= FACE_FROM_ID (it
.f
, face_id
);
18448 extend_face_to_end_of_line (&it
);
18449 if (face
->box
!= FACE_NO_BOX
)
18451 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18452 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18453 last
->right_box_line_p
= 1;
18456 return it
.glyph_row
->height
;
18459 /* Move element ELT in LIST to the front of LIST.
18460 Return the updated list. */
18463 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
18465 register Lisp_Object tail
, prev
;
18466 register Lisp_Object tem
;
18470 while (CONSP (tail
))
18476 /* Splice out the link TAIL. */
18478 list
= XCDR (tail
);
18480 Fsetcdr (prev
, XCDR (tail
));
18482 /* Now make it the first. */
18483 Fsetcdr (tail
, list
);
18488 tail
= XCDR (tail
);
18492 /* Not found--return unchanged LIST. */
18496 /* Contribute ELT to the mode line for window IT->w. How it
18497 translates into text depends on its data type.
18499 IT describes the display environment in which we display, as usual.
18501 DEPTH is the depth in recursion. It is used to prevent
18502 infinite recursion here.
18504 FIELD_WIDTH is the number of characters the display of ELT should
18505 occupy in the mode line, and PRECISION is the maximum number of
18506 characters to display from ELT's representation. See
18507 display_string for details.
18509 Returns the hpos of the end of the text generated by ELT.
18511 PROPS is a property list to add to any string we encounter.
18513 If RISKY is nonzero, remove (disregard) any properties in any string
18514 we encounter, and ignore :eval and :propertize.
18516 The global variable `mode_line_target' determines whether the
18517 output is passed to `store_mode_line_noprop',
18518 `store_mode_line_string', or `display_string'. */
18521 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
18522 Lisp_Object elt
, Lisp_Object props
, int risky
)
18524 int n
= 0, field
, prec
;
18529 elt
= build_string ("*too-deep*");
18533 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18537 /* A string: output it and check for %-constructs within it. */
18539 EMACS_INT offset
= 0;
18541 if (SCHARS (elt
) > 0
18542 && (!NILP (props
) || risky
))
18544 Lisp_Object oprops
, aelt
;
18545 oprops
= Ftext_properties_at (make_number (0), elt
);
18547 /* If the starting string's properties are not what
18548 we want, translate the string. Also, if the string
18549 is risky, do that anyway. */
18551 if (NILP (Fequal (props
, oprops
)) || risky
)
18553 /* If the starting string has properties,
18554 merge the specified ones onto the existing ones. */
18555 if (! NILP (oprops
) && !risky
)
18559 oprops
= Fcopy_sequence (oprops
);
18561 while (CONSP (tem
))
18563 oprops
= Fplist_put (oprops
, XCAR (tem
),
18564 XCAR (XCDR (tem
)));
18565 tem
= XCDR (XCDR (tem
));
18570 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18571 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18573 /* AELT is what we want. Move it to the front
18574 without consing. */
18576 mode_line_proptrans_alist
18577 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18583 /* If AELT has the wrong props, it is useless.
18584 so get rid of it. */
18586 mode_line_proptrans_alist
18587 = Fdelq (aelt
, mode_line_proptrans_alist
);
18589 elt
= Fcopy_sequence (elt
);
18590 Fset_text_properties (make_number (0), Flength (elt
),
18592 /* Add this item to mode_line_proptrans_alist. */
18593 mode_line_proptrans_alist
18594 = Fcons (Fcons (elt
, props
),
18595 mode_line_proptrans_alist
);
18596 /* Truncate mode_line_proptrans_alist
18597 to at most 50 elements. */
18598 tem
= Fnthcdr (make_number (50),
18599 mode_line_proptrans_alist
);
18601 XSETCDR (tem
, Qnil
);
18610 prec
= precision
- n
;
18611 switch (mode_line_target
)
18613 case MODE_LINE_NOPROP
:
18614 case MODE_LINE_TITLE
:
18615 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
18617 case MODE_LINE_STRING
:
18618 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18620 case MODE_LINE_DISPLAY
:
18621 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18622 0, prec
, 0, STRING_MULTIBYTE (elt
));
18629 /* Handle the non-literal case. */
18631 while ((precision
<= 0 || n
< precision
)
18632 && SREF (elt
, offset
) != 0
18633 && (mode_line_target
!= MODE_LINE_DISPLAY
18634 || it
->current_x
< it
->last_visible_x
))
18636 EMACS_INT last_offset
= offset
;
18638 /* Advance to end of string or next format specifier. */
18639 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18642 if (offset
- 1 != last_offset
)
18644 EMACS_INT nchars
, nbytes
;
18646 /* Output to end of string or up to '%'. Field width
18647 is length of string. Don't output more than
18648 PRECISION allows us. */
18651 prec
= c_string_width (SDATA (elt
) + last_offset
,
18652 offset
- last_offset
, precision
- n
,
18655 switch (mode_line_target
)
18657 case MODE_LINE_NOPROP
:
18658 case MODE_LINE_TITLE
:
18659 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18661 case MODE_LINE_STRING
:
18663 EMACS_INT bytepos
= last_offset
;
18664 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18665 EMACS_INT endpos
= (precision
<= 0
18666 ? string_byte_to_char (elt
, offset
)
18667 : charpos
+ nchars
);
18669 n
+= store_mode_line_string (NULL
,
18670 Fsubstring (elt
, make_number (charpos
),
18671 make_number (endpos
)),
18675 case MODE_LINE_DISPLAY
:
18677 EMACS_INT bytepos
= last_offset
;
18678 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18680 if (precision
<= 0)
18681 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18682 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18684 STRING_MULTIBYTE (elt
));
18689 else /* c == '%' */
18691 EMACS_INT percent_position
= offset
;
18693 /* Get the specified minimum width. Zero means
18696 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18697 field
= field
* 10 + c
- '0';
18699 /* Don't pad beyond the total padding allowed. */
18700 if (field_width
- n
> 0 && field
> field_width
- n
)
18701 field
= field_width
- n
;
18703 /* Note that either PRECISION <= 0 or N < PRECISION. */
18704 prec
= precision
- n
;
18707 n
+= display_mode_element (it
, depth
, field
, prec
,
18708 Vglobal_mode_string
, props
,
18713 EMACS_INT bytepos
, charpos
;
18714 const unsigned char *spec
;
18715 Lisp_Object string
;
18717 bytepos
= percent_position
;
18718 charpos
= (STRING_MULTIBYTE (elt
)
18719 ? string_byte_to_char (elt
, bytepos
)
18721 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
18722 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18724 switch (mode_line_target
)
18726 case MODE_LINE_NOPROP
:
18727 case MODE_LINE_TITLE
:
18728 n
+= store_mode_line_noprop (spec
, field
, prec
);
18730 case MODE_LINE_STRING
:
18732 int len
= strlen (spec
);
18733 Lisp_Object tem
= make_string (spec
, len
);
18734 props
= Ftext_properties_at (make_number (charpos
), elt
);
18735 /* Should only keep face property in props */
18736 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18739 case MODE_LINE_DISPLAY
:
18741 int nglyphs_before
, nwritten
;
18743 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18744 nwritten
= display_string (spec
, string
, elt
,
18749 /* Assign to the glyphs written above the
18750 string where the `%x' came from, position
18754 struct glyph
*glyph
18755 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18759 for (i
= 0; i
< nwritten
; ++i
)
18761 glyph
[i
].object
= elt
;
18762 glyph
[i
].charpos
= charpos
;
18779 /* A symbol: process the value of the symbol recursively
18780 as if it appeared here directly. Avoid error if symbol void.
18781 Special case: if value of symbol is a string, output the string
18784 register Lisp_Object tem
;
18786 /* If the variable is not marked as risky to set
18787 then its contents are risky to use. */
18788 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18791 tem
= Fboundp (elt
);
18794 tem
= Fsymbol_value (elt
);
18795 /* If value is a string, output that string literally:
18796 don't check for % within it. */
18800 if (!EQ (tem
, elt
))
18802 /* Give up right away for nil or t. */
18812 register Lisp_Object car
, tem
;
18814 /* A cons cell: five distinct cases.
18815 If first element is :eval or :propertize, do something special.
18816 If first element is a string or a cons, process all the elements
18817 and effectively concatenate them.
18818 If first element is a negative number, truncate displaying cdr to
18819 at most that many characters. If positive, pad (with spaces)
18820 to at least that many characters.
18821 If first element is a symbol, process the cadr or caddr recursively
18822 according to whether the symbol's value is non-nil or nil. */
18824 if (EQ (car
, QCeval
))
18826 /* An element of the form (:eval FORM) means evaluate FORM
18827 and use the result as mode line elements. */
18832 if (CONSP (XCDR (elt
)))
18835 spec
= safe_eval (XCAR (XCDR (elt
)));
18836 n
+= display_mode_element (it
, depth
, field_width
- n
,
18837 precision
- n
, spec
, props
,
18841 else if (EQ (car
, QCpropertize
))
18843 /* An element of the form (:propertize ELT PROPS...)
18844 means display ELT but applying properties PROPS. */
18849 if (CONSP (XCDR (elt
)))
18850 n
+= display_mode_element (it
, depth
, field_width
- n
,
18851 precision
- n
, XCAR (XCDR (elt
)),
18852 XCDR (XCDR (elt
)), risky
);
18854 else if (SYMBOLP (car
))
18856 tem
= Fboundp (car
);
18860 /* elt is now the cdr, and we know it is a cons cell.
18861 Use its car if CAR has a non-nil value. */
18864 tem
= Fsymbol_value (car
);
18871 /* Symbol's value is nil (or symbol is unbound)
18872 Get the cddr of the original list
18873 and if possible find the caddr and use that. */
18877 else if (!CONSP (elt
))
18882 else if (INTEGERP (car
))
18884 register int lim
= XINT (car
);
18888 /* Negative int means reduce maximum width. */
18889 if (precision
<= 0)
18892 precision
= min (precision
, -lim
);
18896 /* Padding specified. Don't let it be more than
18897 current maximum. */
18899 lim
= min (precision
, lim
);
18901 /* If that's more padding than already wanted, queue it.
18902 But don't reduce padding already specified even if
18903 that is beyond the current truncation point. */
18904 field_width
= max (lim
, field_width
);
18908 else if (STRINGP (car
) || CONSP (car
))
18910 Lisp_Object halftail
= elt
;
18914 && (precision
<= 0 || n
< precision
))
18916 n
+= display_mode_element (it
, depth
,
18917 /* Do padding only after the last
18918 element in the list. */
18919 (! CONSP (XCDR (elt
))
18922 precision
- n
, XCAR (elt
),
18926 if ((len
& 1) == 0)
18927 halftail
= XCDR (halftail
);
18928 /* Check for cycle. */
18929 if (EQ (halftail
, elt
))
18938 elt
= build_string ("*invalid*");
18942 /* Pad to FIELD_WIDTH. */
18943 if (field_width
> 0 && n
< field_width
)
18945 switch (mode_line_target
)
18947 case MODE_LINE_NOPROP
:
18948 case MODE_LINE_TITLE
:
18949 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18951 case MODE_LINE_STRING
:
18952 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18954 case MODE_LINE_DISPLAY
:
18955 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18964 /* Store a mode-line string element in mode_line_string_list.
18966 If STRING is non-null, display that C string. Otherwise, the Lisp
18967 string LISP_STRING is displayed.
18969 FIELD_WIDTH is the minimum number of output glyphs to produce.
18970 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18971 with spaces. FIELD_WIDTH <= 0 means don't pad.
18973 PRECISION is the maximum number of characters to output from
18974 STRING. PRECISION <= 0 means don't truncate the string.
18976 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18977 properties to the string.
18979 PROPS are the properties to add to the string.
18980 The mode_line_string_face face property is always added to the string.
18984 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
18985 int field_width
, int precision
, Lisp_Object props
)
18990 if (string
!= NULL
)
18992 len
= strlen (string
);
18993 if (precision
> 0 && len
> precision
)
18995 lisp_string
= make_string (string
, len
);
18997 props
= mode_line_string_face_prop
;
18998 else if (!NILP (mode_line_string_face
))
19000 Lisp_Object face
= Fplist_get (props
, Qface
);
19001 props
= Fcopy_sequence (props
);
19003 face
= mode_line_string_face
;
19005 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19006 props
= Fplist_put (props
, Qface
, face
);
19008 Fadd_text_properties (make_number (0), make_number (len
),
19009 props
, lisp_string
);
19013 len
= XFASTINT (Flength (lisp_string
));
19014 if (precision
> 0 && len
> precision
)
19017 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19020 if (!NILP (mode_line_string_face
))
19024 props
= Ftext_properties_at (make_number (0), lisp_string
);
19025 face
= Fplist_get (props
, Qface
);
19027 face
= mode_line_string_face
;
19029 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19030 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19032 lisp_string
= Fcopy_sequence (lisp_string
);
19035 Fadd_text_properties (make_number (0), make_number (len
),
19036 props
, lisp_string
);
19041 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19045 if (field_width
> len
)
19047 field_width
-= len
;
19048 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19050 Fadd_text_properties (make_number (0), make_number (field_width
),
19051 props
, lisp_string
);
19052 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19060 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19062 doc
: /* Format a string out of a mode line format specification.
19063 First arg FORMAT specifies the mode line format (see `mode-line-format'
19064 for details) to use.
19066 Optional second arg FACE specifies the face property to put
19067 on all characters for which no face is specified.
19068 The value t means whatever face the window's mode line currently uses
19069 \(either `mode-line' or `mode-line-inactive', depending).
19070 A value of nil means the default is no face property.
19071 If FACE is an integer, the value string has no text properties.
19073 Optional third and fourth args WINDOW and BUFFER specify the window
19074 and buffer to use as the context for the formatting (defaults
19075 are the selected window and the window's buffer). */)
19076 (Lisp_Object format
, Lisp_Object face
, Lisp_Object window
, Lisp_Object buffer
)
19081 struct buffer
*old_buffer
= NULL
;
19083 int no_props
= INTEGERP (face
);
19084 int count
= SPECPDL_INDEX ();
19086 int string_start
= 0;
19089 window
= selected_window
;
19090 CHECK_WINDOW (window
);
19091 w
= XWINDOW (window
);
19094 buffer
= w
->buffer
;
19095 CHECK_BUFFER (buffer
);
19097 /* Make formatting the modeline a non-op when noninteractive, otherwise
19098 there will be problems later caused by a partially initialized frame. */
19099 if (NILP (format
) || noninteractive
)
19100 return empty_unibyte_string
;
19108 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
19109 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
19113 face_id
= DEFAULT_FACE_ID
;
19115 if (XBUFFER (buffer
) != current_buffer
)
19116 old_buffer
= current_buffer
;
19118 /* Save things including mode_line_proptrans_alist,
19119 and set that to nil so that we don't alter the outer value. */
19120 record_unwind_protect (unwind_format_mode_line
,
19121 format_mode_line_unwind_data
19122 (old_buffer
, selected_window
, 1));
19123 mode_line_proptrans_alist
= Qnil
;
19125 Fselect_window (window
, Qt
);
19127 set_buffer_internal_1 (XBUFFER (buffer
));
19129 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19133 mode_line_target
= MODE_LINE_NOPROP
;
19134 mode_line_string_face_prop
= Qnil
;
19135 mode_line_string_list
= Qnil
;
19136 string_start
= MODE_LINE_NOPROP_LEN (0);
19140 mode_line_target
= MODE_LINE_STRING
;
19141 mode_line_string_list
= Qnil
;
19142 mode_line_string_face
= face
;
19143 mode_line_string_face_prop
19144 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19147 push_kboard (FRAME_KBOARD (it
.f
));
19148 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19153 len
= MODE_LINE_NOPROP_LEN (string_start
);
19154 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19158 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19159 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19160 empty_unibyte_string
);
19163 unbind_to (count
, Qnil
);
19167 /* Write a null-terminated, right justified decimal representation of
19168 the positive integer D to BUF using a minimal field width WIDTH. */
19171 pint2str (register char *buf
, register int width
, register int d
)
19173 register char *p
= buf
;
19181 *p
++ = d
% 10 + '0';
19186 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19197 /* Write a null-terminated, right justified decimal and "human
19198 readable" representation of the nonnegative integer D to BUF using
19199 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19201 static const char power_letter
[] =
19215 pint2hrstr (char *buf
, int width
, int d
)
19217 /* We aim to represent the nonnegative integer D as
19218 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19221 /* -1 means: do not use TENTHS. */
19225 /* Length of QUOTIENT.TENTHS as a string. */
19231 if (1000 <= quotient
)
19233 /* Scale to the appropriate EXPONENT. */
19236 remainder
= quotient
% 1000;
19240 while (1000 <= quotient
);
19242 /* Round to nearest and decide whether to use TENTHS or not. */
19245 tenths
= remainder
/ 100;
19246 if (50 <= remainder
% 100)
19253 if (quotient
== 10)
19261 if (500 <= remainder
)
19263 if (quotient
< 999)
19274 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19275 if (tenths
== -1 && quotient
<= 99)
19282 p
= psuffix
= buf
+ max (width
, length
);
19284 /* Print EXPONENT. */
19286 *psuffix
++ = power_letter
[exponent
];
19289 /* Print TENTHS. */
19292 *--p
= '0' + tenths
;
19296 /* Print QUOTIENT. */
19299 int digit
= quotient
% 10;
19300 *--p
= '0' + digit
;
19302 while ((quotient
/= 10) != 0);
19304 /* Print leading spaces. */
19309 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19310 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19311 type of CODING_SYSTEM. Return updated pointer into BUF. */
19313 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19316 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19319 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
19320 const unsigned char *eol_str
;
19322 /* The EOL conversion we are using. */
19323 Lisp_Object eoltype
;
19325 val
= CODING_SYSTEM_SPEC (coding_system
);
19328 if (!VECTORP (val
)) /* Not yet decided. */
19333 eoltype
= eol_mnemonic_undecided
;
19334 /* Don't mention EOL conversion if it isn't decided. */
19339 Lisp_Object eolvalue
;
19341 attrs
= AREF (val
, 0);
19342 eolvalue
= AREF (val
, 2);
19345 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19349 /* The EOL conversion that is normal on this system. */
19351 if (NILP (eolvalue
)) /* Not yet decided. */
19352 eoltype
= eol_mnemonic_undecided
;
19353 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19354 eoltype
= eol_mnemonic_undecided
;
19355 else /* eolvalue is Qunix, Qdos, or Qmac. */
19356 eoltype
= (EQ (eolvalue
, Qunix
)
19357 ? eol_mnemonic_unix
19358 : (EQ (eolvalue
, Qdos
) == 1
19359 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19365 /* Mention the EOL conversion if it is not the usual one. */
19366 if (STRINGP (eoltype
))
19368 eol_str
= SDATA (eoltype
);
19369 eol_str_len
= SBYTES (eoltype
);
19371 else if (CHARACTERP (eoltype
))
19373 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19374 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19379 eol_str
= invalid_eol_type
;
19380 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19382 memcpy (buf
, eol_str
, eol_str_len
);
19383 buf
+= eol_str_len
;
19389 /* Return a string for the output of a mode line %-spec for window W,
19390 generated by character C. PRECISION >= 0 means don't return a
19391 string longer than that value. FIELD_WIDTH > 0 means pad the
19392 string returned with spaces to that value. Return a Lisp string in
19393 *STRING if the resulting string is taken from that Lisp string.
19395 Note we operate on the current buffer for most purposes,
19396 the exception being w->base_line_pos. */
19398 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19400 static const char *
19401 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19402 int precision
, Lisp_Object
*string
)
19405 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19406 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19407 struct buffer
*b
= current_buffer
;
19415 if (!NILP (b
->read_only
))
19417 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19422 /* This differs from %* only for a modified read-only buffer. */
19423 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19425 if (!NILP (b
->read_only
))
19430 /* This differs from %* in ignoring read-only-ness. */
19431 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19443 if (command_loop_level
> 5)
19445 p
= decode_mode_spec_buf
;
19446 for (i
= 0; i
< command_loop_level
; i
++)
19449 return decode_mode_spec_buf
;
19457 if (command_loop_level
> 5)
19459 p
= decode_mode_spec_buf
;
19460 for (i
= 0; i
< command_loop_level
; i
++)
19463 return decode_mode_spec_buf
;
19470 /* Let lots_of_dashes be a string of infinite length. */
19471 if (mode_line_target
== MODE_LINE_NOPROP
||
19472 mode_line_target
== MODE_LINE_STRING
)
19474 if (field_width
<= 0
19475 || field_width
> sizeof (lots_of_dashes
))
19477 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19478 decode_mode_spec_buf
[i
] = '-';
19479 decode_mode_spec_buf
[i
] = '\0';
19480 return decode_mode_spec_buf
;
19483 return lots_of_dashes
;
19491 /* %c and %l are ignored in `frame-title-format'.
19492 (In redisplay_internal, the frame title is drawn _before_ the
19493 windows are updated, so the stuff which depends on actual
19494 window contents (such as %l) may fail to render properly, or
19495 even crash emacs.) */
19496 if (mode_line_target
== MODE_LINE_TITLE
)
19500 int col
= (int) current_column (); /* iftc */
19501 w
->column_number_displayed
= make_number (col
);
19502 pint2str (decode_mode_spec_buf
, field_width
, col
);
19503 return decode_mode_spec_buf
;
19507 #ifndef SYSTEM_MALLOC
19509 if (NILP (Vmemory_full
))
19512 return "!MEM FULL! ";
19519 /* %F displays the frame name. */
19520 if (!NILP (f
->title
))
19521 return (char *) SDATA (f
->title
);
19522 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19523 return (char *) SDATA (f
->name
);
19532 EMACS_INT size
= ZV
- BEGV
;
19533 pint2str (decode_mode_spec_buf
, field_width
, size
);
19534 return decode_mode_spec_buf
;
19539 EMACS_INT size
= ZV
- BEGV
;
19540 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19541 return decode_mode_spec_buf
;
19546 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19547 int topline
, nlines
, height
;
19550 /* %c and %l are ignored in `frame-title-format'. */
19551 if (mode_line_target
== MODE_LINE_TITLE
)
19554 startpos
= XMARKER (w
->start
)->charpos
;
19555 startpos_byte
= marker_byte_position (w
->start
);
19556 height
= WINDOW_TOTAL_LINES (w
);
19558 /* If we decided that this buffer isn't suitable for line numbers,
19559 don't forget that too fast. */
19560 if (EQ (w
->base_line_pos
, w
->buffer
))
19562 /* But do forget it, if the window shows a different buffer now. */
19563 else if (BUFFERP (w
->base_line_pos
))
19564 w
->base_line_pos
= Qnil
;
19566 /* If the buffer is very big, don't waste time. */
19567 if (INTEGERP (Vline_number_display_limit
)
19568 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19570 w
->base_line_pos
= Qnil
;
19571 w
->base_line_number
= Qnil
;
19575 if (INTEGERP (w
->base_line_number
)
19576 && INTEGERP (w
->base_line_pos
)
19577 && XFASTINT (w
->base_line_pos
) <= startpos
)
19579 line
= XFASTINT (w
->base_line_number
);
19580 linepos
= XFASTINT (w
->base_line_pos
);
19581 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19586 linepos
= BUF_BEGV (b
);
19587 linepos_byte
= BUF_BEGV_BYTE (b
);
19590 /* Count lines from base line to window start position. */
19591 nlines
= display_count_lines (linepos
, linepos_byte
,
19595 topline
= nlines
+ line
;
19597 /* Determine a new base line, if the old one is too close
19598 or too far away, or if we did not have one.
19599 "Too close" means it's plausible a scroll-down would
19600 go back past it. */
19601 if (startpos
== BUF_BEGV (b
))
19603 w
->base_line_number
= make_number (topline
);
19604 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19606 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19607 || linepos
== BUF_BEGV (b
))
19609 EMACS_INT limit
= BUF_BEGV (b
);
19610 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
19611 EMACS_INT position
;
19612 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
19614 if (startpos
- distance
> limit
)
19616 limit
= startpos
- distance
;
19617 limit_byte
= CHAR_TO_BYTE (limit
);
19620 nlines
= display_count_lines (startpos
, startpos_byte
,
19622 - (height
* 2 + 30),
19624 /* If we couldn't find the lines we wanted within
19625 line_number_display_limit_width chars per line,
19626 give up on line numbers for this window. */
19627 if (position
== limit_byte
&& limit
== startpos
- distance
)
19629 w
->base_line_pos
= w
->buffer
;
19630 w
->base_line_number
= Qnil
;
19634 w
->base_line_number
= make_number (topline
- nlines
);
19635 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19638 /* Now count lines from the start pos to point. */
19639 nlines
= display_count_lines (startpos
, startpos_byte
,
19640 PT_BYTE
, PT
, &junk
);
19642 /* Record that we did display the line number. */
19643 line_number_displayed
= 1;
19645 /* Make the string to show. */
19646 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19647 return decode_mode_spec_buf
;
19650 char* p
= decode_mode_spec_buf
;
19651 int pad
= field_width
- 2;
19657 return decode_mode_spec_buf
;
19663 obj
= b
->mode_name
;
19667 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19673 EMACS_INT pos
= marker_position (w
->start
);
19674 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19676 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19678 if (pos
<= BUF_BEGV (b
))
19683 else if (pos
<= BUF_BEGV (b
))
19687 if (total
> 1000000)
19688 /* Do it differently for a large value, to avoid overflow. */
19689 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19691 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19692 /* We can't normally display a 3-digit number,
19693 so get us a 2-digit number that is close. */
19696 sprintf (decode_mode_spec_buf
, "%2ld%%", (long)total
);
19697 return decode_mode_spec_buf
;
19701 /* Display percentage of size above the bottom of the screen. */
19704 EMACS_INT toppos
= marker_position (w
->start
);
19705 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19706 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19708 if (botpos
>= BUF_ZV (b
))
19710 if (toppos
<= BUF_BEGV (b
))
19717 if (total
> 1000000)
19718 /* Do it differently for a large value, to avoid overflow. */
19719 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19721 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19722 /* We can't normally display a 3-digit number,
19723 so get us a 2-digit number that is close. */
19726 if (toppos
<= BUF_BEGV (b
))
19727 sprintf (decode_mode_spec_buf
, "Top%2ld%%", (long)total
);
19729 sprintf (decode_mode_spec_buf
, "%2ld%%", (long)total
);
19730 return decode_mode_spec_buf
;
19735 /* status of process */
19736 obj
= Fget_buffer_process (Fcurrent_buffer ());
19738 return "no process";
19740 obj
= Fsymbol_name (Fprocess_status (obj
));
19746 int count
= inhibit_garbage_collection ();
19747 Lisp_Object val
= call1 (intern ("file-remote-p"),
19748 current_buffer
->directory
);
19749 unbind_to (count
, Qnil
);
19757 case 't': /* indicate TEXT or BINARY */
19758 #ifdef MODE_LINE_BINARY_TEXT
19759 return MODE_LINE_BINARY_TEXT (b
);
19765 /* coding-system (not including end-of-line format) */
19767 /* coding-system (including end-of-line type) */
19769 int eol_flag
= (c
== 'Z');
19770 char *p
= decode_mode_spec_buf
;
19772 if (! FRAME_WINDOW_P (f
))
19774 /* No need to mention EOL here--the terminal never needs
19775 to do EOL conversion. */
19776 p
= decode_mode_spec_coding (CODING_ID_NAME
19777 (FRAME_KEYBOARD_CODING (f
)->id
),
19779 p
= decode_mode_spec_coding (CODING_ID_NAME
19780 (FRAME_TERMINAL_CODING (f
)->id
),
19783 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19786 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19787 #ifdef subprocesses
19788 obj
= Fget_buffer_process (Fcurrent_buffer ());
19789 if (PROCESSP (obj
))
19791 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19793 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19796 #endif /* subprocesses */
19799 return decode_mode_spec_buf
;
19806 return (char *) SDATA (obj
);
19813 /* Count up to COUNT lines starting from START / START_BYTE.
19814 But don't go beyond LIMIT_BYTE.
19815 Return the number of lines thus found (always nonnegative).
19817 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19820 display_count_lines (EMACS_INT start
, EMACS_INT start_byte
,
19821 EMACS_INT limit_byte
, int count
,
19822 EMACS_INT
*byte_pos_ptr
)
19824 register unsigned char *cursor
;
19825 unsigned char *base
;
19827 register int ceiling
;
19828 register unsigned char *ceiling_addr
;
19829 int orig_count
= count
;
19831 /* If we are not in selective display mode,
19832 check only for newlines. */
19833 int selective_display
= (!NILP (current_buffer
->selective_display
)
19834 && !INTEGERP (current_buffer
->selective_display
));
19838 while (start_byte
< limit_byte
)
19840 ceiling
= BUFFER_CEILING_OF (start_byte
);
19841 ceiling
= min (limit_byte
- 1, ceiling
);
19842 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19843 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19846 if (selective_display
)
19847 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19850 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19853 if (cursor
!= ceiling_addr
)
19857 start_byte
+= cursor
- base
+ 1;
19858 *byte_pos_ptr
= start_byte
;
19862 if (++cursor
== ceiling_addr
)
19868 start_byte
+= cursor
- base
;
19873 while (start_byte
> limit_byte
)
19875 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19876 ceiling
= max (limit_byte
, ceiling
);
19877 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19878 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19881 if (selective_display
)
19882 while (--cursor
!= ceiling_addr
19883 && *cursor
!= '\n' && *cursor
!= 015)
19886 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19889 if (cursor
!= ceiling_addr
)
19893 start_byte
+= cursor
- base
+ 1;
19894 *byte_pos_ptr
= start_byte
;
19895 /* When scanning backwards, we should
19896 not count the newline posterior to which we stop. */
19897 return - orig_count
- 1;
19903 /* Here we add 1 to compensate for the last decrement
19904 of CURSOR, which took it past the valid range. */
19905 start_byte
+= cursor
- base
+ 1;
19909 *byte_pos_ptr
= limit_byte
;
19912 return - orig_count
+ count
;
19913 return orig_count
- count
;
19919 /***********************************************************************
19921 ***********************************************************************/
19923 /* Display a NUL-terminated string, starting with index START.
19925 If STRING is non-null, display that C string. Otherwise, the Lisp
19926 string LISP_STRING is displayed. There's a case that STRING is
19927 non-null and LISP_STRING is not nil. It means STRING is a string
19928 data of LISP_STRING. In that case, we display LISP_STRING while
19929 ignoring its text properties.
19931 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19932 FACE_STRING. Display STRING or LISP_STRING with the face at
19933 FACE_STRING_POS in FACE_STRING:
19935 Display the string in the environment given by IT, but use the
19936 standard display table, temporarily.
19938 FIELD_WIDTH is the minimum number of output glyphs to produce.
19939 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19940 with spaces. If STRING has more characters, more than FIELD_WIDTH
19941 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19943 PRECISION is the maximum number of characters to output from
19944 STRING. PRECISION < 0 means don't truncate the string.
19946 This is roughly equivalent to printf format specifiers:
19948 FIELD_WIDTH PRECISION PRINTF
19949 ----------------------------------------
19955 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19956 display them, and < 0 means obey the current buffer's value of
19957 enable_multibyte_characters.
19959 Value is the number of columns displayed. */
19962 display_string (const unsigned char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
19963 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
19964 int field_width
, int precision
, int max_x
, int multibyte
)
19966 int hpos_at_start
= it
->hpos
;
19967 int saved_face_id
= it
->face_id
;
19968 struct glyph_row
*row
= it
->glyph_row
;
19970 /* Initialize the iterator IT for iteration over STRING beginning
19971 with index START. */
19972 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19973 precision
, field_width
, multibyte
);
19974 if (string
&& STRINGP (lisp_string
))
19975 /* LISP_STRING is the one returned by decode_mode_spec. We should
19976 ignore its text properties. */
19977 it
->stop_charpos
= -1;
19979 /* If displaying STRING, set up the face of the iterator
19980 from LISP_STRING, if that's given. */
19981 if (STRINGP (face_string
))
19987 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19988 0, it
->region_beg_charpos
,
19989 it
->region_end_charpos
,
19990 &endptr
, it
->base_face_id
, 0);
19991 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19992 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19995 /* Set max_x to the maximum allowed X position. Don't let it go
19996 beyond the right edge of the window. */
19998 max_x
= it
->last_visible_x
;
20000 max_x
= min (max_x
, it
->last_visible_x
);
20002 /* Skip over display elements that are not visible. because IT->w is
20004 if (it
->current_x
< it
->first_visible_x
)
20005 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20006 MOVE_TO_POS
| MOVE_TO_X
);
20008 row
->ascent
= it
->max_ascent
;
20009 row
->height
= it
->max_ascent
+ it
->max_descent
;
20010 row
->phys_ascent
= it
->max_phys_ascent
;
20011 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20012 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20014 /* This condition is for the case that we are called with current_x
20015 past last_visible_x. */
20016 while (it
->current_x
< max_x
)
20018 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20020 /* Get the next display element. */
20021 if (!get_next_display_element (it
))
20024 /* Produce glyphs. */
20025 x_before
= it
->current_x
;
20026 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20027 PRODUCE_GLYPHS (it
);
20029 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
20032 while (i
< nglyphs
)
20034 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20036 if (it
->line_wrap
!= TRUNCATE
20037 && x
+ glyph
->pixel_width
> max_x
)
20039 /* End of continued line or max_x reached. */
20040 if (CHAR_GLYPH_PADDING_P (*glyph
))
20042 /* A wide character is unbreakable. */
20043 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
20044 it
->current_x
= x_before
;
20048 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20053 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20055 /* Glyph is at least partially visible. */
20057 if (x
< it
->first_visible_x
)
20058 it
->glyph_row
->x
= x
- it
->first_visible_x
;
20062 /* Glyph is off the left margin of the display area.
20063 Should not happen. */
20067 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20068 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20069 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20070 row
->phys_height
= max (row
->phys_height
,
20071 it
->max_phys_ascent
+ it
->max_phys_descent
);
20072 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20073 it
->max_extra_line_spacing
);
20074 x
+= glyph
->pixel_width
;
20078 /* Stop if max_x reached. */
20082 /* Stop at line ends. */
20083 if (ITERATOR_AT_END_OF_LINE_P (it
))
20085 it
->continuation_lines_width
= 0;
20089 set_iterator_to_next (it
, 1);
20091 /* Stop if truncating at the right edge. */
20092 if (it
->line_wrap
== TRUNCATE
20093 && it
->current_x
>= it
->last_visible_x
)
20095 /* Add truncation mark, but don't do it if the line is
20096 truncated at a padding space. */
20097 if (IT_CHARPOS (*it
) < it
->string_nchars
)
20099 if (!FRAME_WINDOW_P (it
->f
))
20103 if (it
->current_x
> it
->last_visible_x
)
20105 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20106 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20108 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20110 row
->used
[TEXT_AREA
] = i
;
20111 produce_special_glyphs (it
, IT_TRUNCATION
);
20114 produce_special_glyphs (it
, IT_TRUNCATION
);
20116 it
->glyph_row
->truncated_on_right_p
= 1;
20122 /* Maybe insert a truncation at the left. */
20123 if (it
->first_visible_x
20124 && IT_CHARPOS (*it
) > 0)
20126 if (!FRAME_WINDOW_P (it
->f
))
20127 insert_left_trunc_glyphs (it
);
20128 it
->glyph_row
->truncated_on_left_p
= 1;
20131 it
->face_id
= saved_face_id
;
20133 /* Value is number of columns displayed. */
20134 return it
->hpos
- hpos_at_start
;
20139 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20140 appears as an element of LIST or as the car of an element of LIST.
20141 If PROPVAL is a list, compare each element against LIST in that
20142 way, and return 1/2 if any element of PROPVAL is found in LIST.
20143 Otherwise return 0. This function cannot quit.
20144 The return value is 2 if the text is invisible but with an ellipsis
20145 and 1 if it's invisible and without an ellipsis. */
20148 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20150 register Lisp_Object tail
, proptail
;
20152 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20154 register Lisp_Object tem
;
20156 if (EQ (propval
, tem
))
20158 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20159 return NILP (XCDR (tem
)) ? 1 : 2;
20162 if (CONSP (propval
))
20164 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20166 Lisp_Object propelt
;
20167 propelt
= XCAR (proptail
);
20168 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20170 register Lisp_Object tem
;
20172 if (EQ (propelt
, tem
))
20174 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20175 return NILP (XCDR (tem
)) ? 1 : 2;
20183 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20184 doc
: /* Non-nil if the property makes the text invisible.
20185 POS-OR-PROP can be a marker or number, in which case it is taken to be
20186 a position in the current buffer and the value of the `invisible' property
20187 is checked; or it can be some other value, which is then presumed to be the
20188 value of the `invisible' property of the text of interest.
20189 The non-nil value returned can be t for truly invisible text or something
20190 else if the text is replaced by an ellipsis. */)
20191 (Lisp_Object pos_or_prop
)
20194 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20195 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20197 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20198 return (invis
== 0 ? Qnil
20200 : make_number (invis
));
20203 /* Calculate a width or height in pixels from a specification using
20204 the following elements:
20207 NUM - a (fractional) multiple of the default font width/height
20208 (NUM) - specifies exactly NUM pixels
20209 UNIT - a fixed number of pixels, see below.
20210 ELEMENT - size of a display element in pixels, see below.
20211 (NUM . SPEC) - equals NUM * SPEC
20212 (+ SPEC SPEC ...) - add pixel values
20213 (- SPEC SPEC ...) - subtract pixel values
20214 (- SPEC) - negate pixel value
20217 INT or FLOAT - a number constant
20218 SYMBOL - use symbol's (buffer local) variable binding.
20221 in - pixels per inch *)
20222 mm - pixels per 1/1000 meter *)
20223 cm - pixels per 1/100 meter *)
20224 width - width of current font in pixels.
20225 height - height of current font in pixels.
20227 *) using the ratio(s) defined in display-pixels-per-inch.
20231 left-fringe - left fringe width in pixels
20232 right-fringe - right fringe width in pixels
20234 left-margin - left margin width in pixels
20235 right-margin - right margin width in pixels
20237 scroll-bar - scroll-bar area width in pixels
20241 Pixels corresponding to 5 inches:
20244 Total width of non-text areas on left side of window (if scroll-bar is on left):
20245 '(space :width (+ left-fringe left-margin scroll-bar))
20247 Align to first text column (in header line):
20248 '(space :align-to 0)
20250 Align to middle of text area minus half the width of variable `my-image'
20251 containing a loaded image:
20252 '(space :align-to (0.5 . (- text my-image)))
20254 Width of left margin minus width of 1 character in the default font:
20255 '(space :width (- left-margin 1))
20257 Width of left margin minus width of 2 characters in the current font:
20258 '(space :width (- left-margin (2 . width)))
20260 Center 1 character over left-margin (in header line):
20261 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20263 Different ways to express width of left fringe plus left margin minus one pixel:
20264 '(space :width (- (+ left-fringe left-margin) (1)))
20265 '(space :width (+ left-fringe left-margin (- (1))))
20266 '(space :width (+ left-fringe left-margin (-1)))
20270 #define NUMVAL(X) \
20271 ((INTEGERP (X) || FLOATP (X)) \
20276 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20277 struct font
*font
, int width_p
, int *align_to
)
20281 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20282 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20285 return OK_PIXELS (0);
20287 xassert (FRAME_LIVE_P (it
->f
));
20289 if (SYMBOLP (prop
))
20291 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20293 char *unit
= SDATA (SYMBOL_NAME (prop
));
20295 if (unit
[0] == 'i' && unit
[1] == 'n')
20297 else if (unit
[0] == 'm' && unit
[1] == 'm')
20299 else if (unit
[0] == 'c' && unit
[1] == 'm')
20306 #ifdef HAVE_WINDOW_SYSTEM
20307 if (FRAME_WINDOW_P (it
->f
)
20309 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20310 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20312 return OK_PIXELS (ppi
/ pixels
);
20315 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20316 || (CONSP (Vdisplay_pixels_per_inch
)
20318 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20319 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20321 return OK_PIXELS (ppi
/ pixels
);
20327 #ifdef HAVE_WINDOW_SYSTEM
20328 if (EQ (prop
, Qheight
))
20329 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20330 if (EQ (prop
, Qwidth
))
20331 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20333 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20334 return OK_PIXELS (1);
20337 if (EQ (prop
, Qtext
))
20338 return OK_PIXELS (width_p
20339 ? window_box_width (it
->w
, TEXT_AREA
)
20340 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20342 if (align_to
&& *align_to
< 0)
20345 if (EQ (prop
, Qleft
))
20346 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20347 if (EQ (prop
, Qright
))
20348 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20349 if (EQ (prop
, Qcenter
))
20350 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20351 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20352 if (EQ (prop
, Qleft_fringe
))
20353 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20354 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20355 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20356 if (EQ (prop
, Qright_fringe
))
20357 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20358 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20359 : window_box_right_offset (it
->w
, TEXT_AREA
));
20360 if (EQ (prop
, Qleft_margin
))
20361 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20362 if (EQ (prop
, Qright_margin
))
20363 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20364 if (EQ (prop
, Qscroll_bar
))
20365 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20367 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20368 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20369 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20374 if (EQ (prop
, Qleft_fringe
))
20375 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20376 if (EQ (prop
, Qright_fringe
))
20377 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20378 if (EQ (prop
, Qleft_margin
))
20379 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20380 if (EQ (prop
, Qright_margin
))
20381 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20382 if (EQ (prop
, Qscroll_bar
))
20383 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20386 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20389 if (INTEGERP (prop
) || FLOATP (prop
))
20391 int base_unit
= (width_p
20392 ? FRAME_COLUMN_WIDTH (it
->f
)
20393 : FRAME_LINE_HEIGHT (it
->f
));
20394 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20399 Lisp_Object car
= XCAR (prop
);
20400 Lisp_Object cdr
= XCDR (prop
);
20404 #ifdef HAVE_WINDOW_SYSTEM
20405 if (FRAME_WINDOW_P (it
->f
)
20406 && valid_image_p (prop
))
20408 int id
= lookup_image (it
->f
, prop
);
20409 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20411 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20414 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20420 while (CONSP (cdr
))
20422 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20423 font
, width_p
, align_to
))
20426 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20431 if (EQ (car
, Qminus
))
20433 return OK_PIXELS (pixels
);
20436 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20439 if (INTEGERP (car
) || FLOATP (car
))
20442 pixels
= XFLOATINT (car
);
20444 return OK_PIXELS (pixels
);
20445 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20446 font
, width_p
, align_to
))
20447 return OK_PIXELS (pixels
* fact
);
20458 /***********************************************************************
20460 ***********************************************************************/
20462 #ifdef HAVE_WINDOW_SYSTEM
20467 dump_glyph_string (s
)
20468 struct glyph_string
*s
;
20470 fprintf (stderr
, "glyph string\n");
20471 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20472 s
->x
, s
->y
, s
->width
, s
->height
);
20473 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20474 fprintf (stderr
, " hl = %d\n", s
->hl
);
20475 fprintf (stderr
, " left overhang = %d, right = %d\n",
20476 s
->left_overhang
, s
->right_overhang
);
20477 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20478 fprintf (stderr
, " extends to end of line = %d\n",
20479 s
->extends_to_end_of_line_p
);
20480 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20481 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20484 #endif /* GLYPH_DEBUG */
20486 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20487 of XChar2b structures for S; it can't be allocated in
20488 init_glyph_string because it must be allocated via `alloca'. W
20489 is the window on which S is drawn. ROW and AREA are the glyph row
20490 and area within the row from which S is constructed. START is the
20491 index of the first glyph structure covered by S. HL is a
20492 face-override for drawing S. */
20495 #define OPTIONAL_HDC(hdc) HDC hdc,
20496 #define DECLARE_HDC(hdc) HDC hdc;
20497 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20498 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20501 #ifndef OPTIONAL_HDC
20502 #define OPTIONAL_HDC(hdc)
20503 #define DECLARE_HDC(hdc)
20504 #define ALLOCATE_HDC(hdc, f)
20505 #define RELEASE_HDC(hdc, f)
20509 init_glyph_string (struct glyph_string
*s
,
20511 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
20512 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
20514 memset (s
, 0, sizeof *s
);
20516 s
->f
= XFRAME (w
->frame
);
20520 s
->display
= FRAME_X_DISPLAY (s
->f
);
20521 s
->window
= FRAME_X_WINDOW (s
->f
);
20522 s
->char2b
= char2b
;
20526 s
->first_glyph
= row
->glyphs
[area
] + start
;
20527 s
->height
= row
->height
;
20528 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20529 s
->ybase
= s
->y
+ row
->ascent
;
20533 /* Append the list of glyph strings with head H and tail T to the list
20534 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20537 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20538 struct glyph_string
*h
, struct glyph_string
*t
)
20552 /* Prepend the list of glyph strings with head H and tail T to the
20553 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20557 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20558 struct glyph_string
*h
, struct glyph_string
*t
)
20572 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20573 Set *HEAD and *TAIL to the resulting list. */
20576 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
20577 struct glyph_string
*s
)
20579 s
->next
= s
->prev
= NULL
;
20580 append_glyph_string_lists (head
, tail
, s
, s
);
20584 /* Get face and two-byte form of character C in face FACE_ID on frame
20585 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
20586 means we want to display multibyte text. DISPLAY_P non-zero means
20587 make sure that X resources for the face returned are allocated.
20588 Value is a pointer to a realized face that is ready for display if
20589 DISPLAY_P is non-zero. */
20591 static INLINE
struct face
*
20592 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
20593 XChar2b
*char2b
, int multibyte_p
, int display_p
)
20595 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20599 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20601 if (code
!= FONT_INVALID_CODE
)
20602 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20604 STORE_XCHAR2B (char2b
, 0, 0);
20607 /* Make sure X resources of the face are allocated. */
20608 #ifdef HAVE_X_WINDOWS
20612 xassert (face
!= NULL
);
20613 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20620 /* Get face and two-byte form of character glyph GLYPH on frame F.
20621 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20622 a pointer to a realized face that is ready for display. */
20624 static INLINE
struct face
*
20625 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
20626 XChar2b
*char2b
, int *two_byte_p
)
20630 xassert (glyph
->type
== CHAR_GLYPH
);
20631 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20640 if (CHAR_BYTE8_P (glyph
->u
.ch
))
20641 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
20643 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20645 if (code
!= FONT_INVALID_CODE
)
20646 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20648 STORE_XCHAR2B (char2b
, 0, 0);
20651 /* Make sure X resources of the face are allocated. */
20652 xassert (face
!= NULL
);
20653 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20658 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
20659 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
20662 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
20666 if (CHAR_BYTE8_P (c
))
20667 code
= CHAR_TO_BYTE8 (c
);
20669 code
= font
->driver
->encode_char (font
, c
);
20671 if (code
== FONT_INVALID_CODE
)
20673 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20678 /* Fill glyph string S with composition components specified by S->cmp.
20680 BASE_FACE is the base face of the composition.
20681 S->cmp_from is the index of the first component for S.
20683 OVERLAPS non-zero means S should draw the foreground only, and use
20684 its physical height for clipping. See also draw_glyphs.
20686 Value is the index of a component not in S. */
20689 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
20693 /* For all glyphs of this composition, starting at the offset
20694 S->cmp_from, until we reach the end of the definition or encounter a
20695 glyph that requires the different face, add it to S. */
20700 s
->for_overlaps
= overlaps
;
20703 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20705 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20709 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20712 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20713 s
->char2b
+ i
, 1, 1);
20719 s
->font
= s
->face
->font
;
20721 else if (s
->face
!= face
)
20729 /* All glyph strings for the same composition has the same width,
20730 i.e. the width set for the first component of the composition. */
20731 s
->width
= s
->first_glyph
->pixel_width
;
20733 /* If the specified font could not be loaded, use the frame's
20734 default font, but record the fact that we couldn't load it in
20735 the glyph string so that we can draw rectangles for the
20736 characters of the glyph string. */
20737 if (s
->font
== NULL
)
20739 s
->font_not_found_p
= 1;
20740 s
->font
= FRAME_FONT (s
->f
);
20743 /* Adjust base line for subscript/superscript text. */
20744 s
->ybase
+= s
->first_glyph
->voffset
;
20746 /* This glyph string must always be drawn with 16-bit functions. */
20753 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
20754 int start
, int end
, int overlaps
)
20756 struct glyph
*glyph
, *last
;
20757 Lisp_Object lgstring
;
20760 s
->for_overlaps
= overlaps
;
20761 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20762 last
= s
->row
->glyphs
[s
->area
] + end
;
20763 s
->cmp_id
= glyph
->u
.cmp
.id
;
20764 s
->cmp_from
= glyph
->slice
.cmp
.from
;
20765 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
20766 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20767 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20768 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20770 while (glyph
< last
20771 && glyph
->u
.cmp
.automatic
20772 && glyph
->u
.cmp
.id
== s
->cmp_id
20773 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
20774 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
20776 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20778 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20779 unsigned code
= LGLYPH_CODE (lglyph
);
20781 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20783 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20784 return glyph
- s
->row
->glyphs
[s
->area
];
20788 /* Fill glyph string S from a sequence glyphs for glyphless characters.
20789 See the comment of fill_glyph_string for arguments.
20790 Value is the index of the first glyph not in S. */
20794 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
20795 int start
, int end
, int overlaps
)
20797 struct glyph
*glyph
, *last
;
20800 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
20801 s
->for_overlaps
= overlaps
;
20802 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20803 last
= s
->row
->glyphs
[s
->area
] + end
;
20804 voffset
= glyph
->voffset
;
20805 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20806 s
->font
= s
->face
->font
;
20808 s
->width
= glyph
->pixel_width
;
20810 while (glyph
< last
20811 && glyph
->type
== GLYPHLESS_GLYPH
20812 && glyph
->voffset
== voffset
20813 && glyph
->face_id
== face_id
)
20816 s
->width
+= glyph
->pixel_width
;
20819 s
->ybase
+= voffset
;
20820 return glyph
- s
->row
->glyphs
[s
->area
];
20824 /* Fill glyph string S from a sequence of character glyphs.
20826 FACE_ID is the face id of the string. START is the index of the
20827 first glyph to consider, END is the index of the last + 1.
20828 OVERLAPS non-zero means S should draw the foreground only, and use
20829 its physical height for clipping. See also draw_glyphs.
20831 Value is the index of the first glyph not in S. */
20834 fill_glyph_string (struct glyph_string
*s
, int face_id
,
20835 int start
, int end
, int overlaps
)
20837 struct glyph
*glyph
, *last
;
20839 int glyph_not_available_p
;
20841 xassert (s
->f
== XFRAME (s
->w
->frame
));
20842 xassert (s
->nchars
== 0);
20843 xassert (start
>= 0 && end
> start
);
20845 s
->for_overlaps
= overlaps
;
20846 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20847 last
= s
->row
->glyphs
[s
->area
] + end
;
20848 voffset
= glyph
->voffset
;
20849 s
->padding_p
= glyph
->padding_p
;
20850 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20852 while (glyph
< last
20853 && glyph
->type
== CHAR_GLYPH
20854 && glyph
->voffset
== voffset
20855 /* Same face id implies same font, nowadays. */
20856 && glyph
->face_id
== face_id
20857 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20861 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20862 s
->char2b
+ s
->nchars
,
20864 s
->two_byte_p
= two_byte_p
;
20866 xassert (s
->nchars
<= end
- start
);
20867 s
->width
+= glyph
->pixel_width
;
20868 if (glyph
++->padding_p
!= s
->padding_p
)
20872 s
->font
= s
->face
->font
;
20874 /* If the specified font could not be loaded, use the frame's font,
20875 but record the fact that we couldn't load it in
20876 S->font_not_found_p so that we can draw rectangles for the
20877 characters of the glyph string. */
20878 if (s
->font
== NULL
|| glyph_not_available_p
)
20880 s
->font_not_found_p
= 1;
20881 s
->font
= FRAME_FONT (s
->f
);
20884 /* Adjust base line for subscript/superscript text. */
20885 s
->ybase
+= voffset
;
20887 xassert (s
->face
&& s
->face
->gc
);
20888 return glyph
- s
->row
->glyphs
[s
->area
];
20892 /* Fill glyph string S from image glyph S->first_glyph. */
20895 fill_image_glyph_string (struct glyph_string
*s
)
20897 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20898 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20900 s
->slice
= s
->first_glyph
->slice
.img
;
20901 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20902 s
->font
= s
->face
->font
;
20903 s
->width
= s
->first_glyph
->pixel_width
;
20905 /* Adjust base line for subscript/superscript text. */
20906 s
->ybase
+= s
->first_glyph
->voffset
;
20910 /* Fill glyph string S from a sequence of stretch glyphs.
20912 ROW is the glyph row in which the glyphs are found, AREA is the
20913 area within the row. START is the index of the first glyph to
20914 consider, END is the index of the last + 1.
20916 Value is the index of the first glyph not in S. */
20919 fill_stretch_glyph_string (struct glyph_string
*s
, struct glyph_row
*row
,
20920 enum glyph_row_area area
, int start
, int end
)
20922 struct glyph
*glyph
, *last
;
20923 int voffset
, face_id
;
20925 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20927 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20928 last
= s
->row
->glyphs
[s
->area
] + end
;
20929 face_id
= glyph
->face_id
;
20930 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20931 s
->font
= s
->face
->font
;
20932 s
->width
= glyph
->pixel_width
;
20934 voffset
= glyph
->voffset
;
20938 && glyph
->type
== STRETCH_GLYPH
20939 && glyph
->voffset
== voffset
20940 && glyph
->face_id
== face_id
);
20942 s
->width
+= glyph
->pixel_width
;
20944 /* Adjust base line for subscript/superscript text. */
20945 s
->ybase
+= voffset
;
20947 /* The case that face->gc == 0 is handled when drawing the glyph
20948 string by calling PREPARE_FACE_FOR_DISPLAY. */
20950 return glyph
- s
->row
->glyphs
[s
->area
];
20953 static struct font_metrics
*
20954 get_per_char_metric (struct frame
*f
, struct font
*font
, XChar2b
*char2b
)
20956 static struct font_metrics metrics
;
20957 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20959 if (! font
|| code
== FONT_INVALID_CODE
)
20961 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20966 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20967 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20968 assumed to be zero. */
20971 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
20973 *left
= *right
= 0;
20975 if (glyph
->type
== CHAR_GLYPH
)
20979 struct font_metrics
*pcm
;
20981 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20982 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20984 if (pcm
->rbearing
> pcm
->width
)
20985 *right
= pcm
->rbearing
- pcm
->width
;
20986 if (pcm
->lbearing
< 0)
20987 *left
= -pcm
->lbearing
;
20990 else if (glyph
->type
== COMPOSITE_GLYPH
)
20992 if (! glyph
->u
.cmp
.automatic
)
20994 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20996 if (cmp
->rbearing
> cmp
->pixel_width
)
20997 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20998 if (cmp
->lbearing
< 0)
20999 *left
= - cmp
->lbearing
;
21003 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21004 struct font_metrics metrics
;
21006 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21007 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21008 if (metrics
.rbearing
> metrics
.width
)
21009 *right
= metrics
.rbearing
- metrics
.width
;
21010 if (metrics
.lbearing
< 0)
21011 *left
= - metrics
.lbearing
;
21017 /* Return the index of the first glyph preceding glyph string S that
21018 is overwritten by S because of S's left overhang. Value is -1
21019 if no glyphs are overwritten. */
21022 left_overwritten (struct glyph_string
*s
)
21026 if (s
->left_overhang
)
21029 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21030 int first
= s
->first_glyph
- glyphs
;
21032 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21033 x
-= glyphs
[i
].pixel_width
;
21044 /* Return the index of the first glyph preceding glyph string S that
21045 is overwriting S because of its right overhang. Value is -1 if no
21046 glyph in front of S overwrites S. */
21049 left_overwriting (struct glyph_string
*s
)
21052 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21053 int first
= s
->first_glyph
- glyphs
;
21057 for (i
= first
- 1; i
>= 0; --i
)
21060 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21063 x
-= glyphs
[i
].pixel_width
;
21070 /* Return the index of the last glyph following glyph string S that is
21071 overwritten by S because of S's right overhang. Value is -1 if
21072 no such glyph is found. */
21075 right_overwritten (struct glyph_string
*s
)
21079 if (s
->right_overhang
)
21082 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21083 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21084 int end
= s
->row
->used
[s
->area
];
21086 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21087 x
+= glyphs
[i
].pixel_width
;
21096 /* Return the index of the last glyph following glyph string S that
21097 overwrites S because of its left overhang. Value is negative
21098 if no such glyph is found. */
21101 right_overwriting (struct glyph_string
*s
)
21104 int end
= s
->row
->used
[s
->area
];
21105 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21106 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21110 for (i
= first
; i
< end
; ++i
)
21113 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21116 x
+= glyphs
[i
].pixel_width
;
21123 /* Set background width of glyph string S. START is the index of the
21124 first glyph following S. LAST_X is the right-most x-position + 1
21125 in the drawing area. */
21128 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21130 /* If the face of this glyph string has to be drawn to the end of
21131 the drawing area, set S->extends_to_end_of_line_p. */
21133 if (start
== s
->row
->used
[s
->area
]
21134 && s
->area
== TEXT_AREA
21135 && ((s
->row
->fill_line_p
21136 && (s
->hl
== DRAW_NORMAL_TEXT
21137 || s
->hl
== DRAW_IMAGE_RAISED
21138 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21139 || s
->hl
== DRAW_MOUSE_FACE
))
21140 s
->extends_to_end_of_line_p
= 1;
21142 /* If S extends its face to the end of the line, set its
21143 background_width to the distance to the right edge of the drawing
21145 if (s
->extends_to_end_of_line_p
)
21146 s
->background_width
= last_x
- s
->x
+ 1;
21148 s
->background_width
= s
->width
;
21152 /* Compute overhangs and x-positions for glyph string S and its
21153 predecessors, or successors. X is the starting x-position for S.
21154 BACKWARD_P non-zero means process predecessors. */
21157 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21163 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21164 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21174 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21175 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21185 /* The following macros are only called from draw_glyphs below.
21186 They reference the following parameters of that function directly:
21187 `w', `row', `area', and `overlap_p'
21188 as well as the following local variables:
21189 `s', `f', and `hdc' (in W32) */
21192 /* On W32, silently add local `hdc' variable to argument list of
21193 init_glyph_string. */
21194 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21195 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21197 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21198 init_glyph_string (s, char2b, w, row, area, start, hl)
21201 /* Add a glyph string for a stretch glyph to the list of strings
21202 between HEAD and TAIL. START is the index of the stretch glyph in
21203 row area AREA of glyph row ROW. END is the index of the last glyph
21204 in that glyph row area. X is the current output position assigned
21205 to the new glyph string constructed. HL overrides that face of the
21206 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21207 is the right-most x-position of the drawing area. */
21209 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21210 and below -- keep them on one line. */
21211 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21214 s = (struct glyph_string *) alloca (sizeof *s); \
21215 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21216 START = fill_stretch_glyph_string (s, row, area, START, END); \
21217 append_glyph_string (&HEAD, &TAIL, s); \
21223 /* Add a glyph string for an image glyph to the list of strings
21224 between HEAD and TAIL. START is the index of the image glyph in
21225 row area AREA of glyph row ROW. END is the index of the last glyph
21226 in that glyph row area. X is the current output position assigned
21227 to the new glyph string constructed. HL overrides that face of the
21228 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21229 is the right-most x-position of the drawing area. */
21231 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21234 s = (struct glyph_string *) alloca (sizeof *s); \
21235 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21236 fill_image_glyph_string (s); \
21237 append_glyph_string (&HEAD, &TAIL, s); \
21244 /* Add a glyph string for a sequence of character glyphs to the list
21245 of strings between HEAD and TAIL. START is the index of the first
21246 glyph in row area AREA of glyph row ROW that is part of the new
21247 glyph string. END is the index of the last glyph in that glyph row
21248 area. X is the current output position assigned to the new glyph
21249 string constructed. HL overrides that face of the glyph; e.g. it
21250 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21251 right-most x-position of the drawing area. */
21253 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21259 face_id = (row)->glyphs[area][START].face_id; \
21261 s = (struct glyph_string *) alloca (sizeof *s); \
21262 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21263 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21264 append_glyph_string (&HEAD, &TAIL, s); \
21266 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21271 /* Add a glyph string for a composite sequence to the list of strings
21272 between HEAD and TAIL. START is the index of the first glyph in
21273 row area AREA of glyph row ROW that is part of the new glyph
21274 string. END is the index of the last glyph in that glyph row area.
21275 X is the current output position assigned to the new glyph string
21276 constructed. HL overrides that face of the glyph; e.g. it is
21277 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21278 x-position of the drawing area. */
21280 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21282 int face_id = (row)->glyphs[area][START].face_id; \
21283 struct face *base_face = FACE_FROM_ID (f, face_id); \
21284 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21285 struct composition *cmp = composition_table[cmp_id]; \
21287 struct glyph_string *first_s; \
21290 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21292 /* Make glyph_strings for each glyph sequence that is drawable by \
21293 the same face, and append them to HEAD/TAIL. */ \
21294 for (n = 0; n < cmp->glyph_len;) \
21296 s = (struct glyph_string *) alloca (sizeof *s); \
21297 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21298 append_glyph_string (&(HEAD), &(TAIL), s); \
21304 n = fill_composite_glyph_string (s, base_face, overlaps); \
21312 /* Add a glyph string for a glyph-string sequence to the list of strings
21313 between HEAD and TAIL. */
21315 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21319 Lisp_Object gstring; \
21321 face_id = (row)->glyphs[area][START].face_id; \
21322 gstring = (composition_gstring_from_id \
21323 ((row)->glyphs[area][START].u.cmp.id)); \
21324 s = (struct glyph_string *) alloca (sizeof *s); \
21325 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21326 * LGSTRING_GLYPH_LEN (gstring)); \
21327 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21328 append_glyph_string (&(HEAD), &(TAIL), s); \
21330 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21334 /* Add a glyph string for a sequence of glyphless character's glyphs
21335 to the list of strings between HEAD and TAIL. The meanings of
21336 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21338 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21344 face_id = (row)->glyphs[area][START].face_id; \
21346 s = (struct glyph_string *) alloca (sizeof *s); \
21347 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21348 append_glyph_string (&HEAD, &TAIL, s); \
21350 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21356 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21357 of AREA of glyph row ROW on window W between indices START and END.
21358 HL overrides the face for drawing glyph strings, e.g. it is
21359 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21360 x-positions of the drawing area.
21362 This is an ugly monster macro construct because we must use alloca
21363 to allocate glyph strings (because draw_glyphs can be called
21364 asynchronously). */
21366 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21369 HEAD = TAIL = NULL; \
21370 while (START < END) \
21372 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21373 switch (first_glyph->type) \
21376 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21380 case COMPOSITE_GLYPH: \
21381 if (first_glyph->u.cmp.automatic) \
21382 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21385 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21389 case STRETCH_GLYPH: \
21390 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21394 case IMAGE_GLYPH: \
21395 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21399 case GLYPHLESS_GLYPH: \
21400 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
21410 set_glyph_string_background_width (s, START, LAST_X); \
21417 /* Draw glyphs between START and END in AREA of ROW on window W,
21418 starting at x-position X. X is relative to AREA in W. HL is a
21419 face-override with the following meaning:
21421 DRAW_NORMAL_TEXT draw normally
21422 DRAW_CURSOR draw in cursor face
21423 DRAW_MOUSE_FACE draw in mouse face.
21424 DRAW_INVERSE_VIDEO draw in mode line face
21425 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21426 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21428 If OVERLAPS is non-zero, draw only the foreground of characters and
21429 clip to the physical height of ROW. Non-zero value also defines
21430 the overlapping part to be drawn:
21432 OVERLAPS_PRED overlap with preceding rows
21433 OVERLAPS_SUCC overlap with succeeding rows
21434 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21435 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21437 Value is the x-position reached, relative to AREA of W. */
21440 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
21441 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
21442 enum draw_glyphs_face hl
, int overlaps
)
21444 struct glyph_string
*head
, *tail
;
21445 struct glyph_string
*s
;
21446 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21447 int i
, j
, x_reached
, last_x
, area_left
= 0;
21448 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21451 ALLOCATE_HDC (hdc
, f
);
21453 /* Let's rather be paranoid than getting a SEGV. */
21454 end
= min (end
, row
->used
[area
]);
21455 start
= max (0, start
);
21456 start
= min (end
, start
);
21458 /* Translate X to frame coordinates. Set last_x to the right
21459 end of the drawing area. */
21460 if (row
->full_width_p
)
21462 /* X is relative to the left edge of W, without scroll bars
21464 area_left
= WINDOW_LEFT_EDGE_X (w
);
21465 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21469 area_left
= window_box_left (w
, area
);
21470 last_x
= area_left
+ window_box_width (w
, area
);
21474 /* Build a doubly-linked list of glyph_string structures between
21475 head and tail from what we have to draw. Note that the macro
21476 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21477 the reason we use a separate variable `i'. */
21479 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21481 x_reached
= tail
->x
+ tail
->background_width
;
21485 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21486 the row, redraw some glyphs in front or following the glyph
21487 strings built above. */
21488 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21490 struct glyph_string
*h
, *t
;
21491 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
21492 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
21495 /* If mouse highlighting is on, we may need to draw adjacent
21496 glyphs using mouse-face highlighting. */
21497 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21499 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21501 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
21502 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
21504 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21506 check_mouse_face
= 1;
21507 mouse_beg_col
= (row
== mouse_beg_row
)
21508 ? hlinfo
->mouse_face_beg_col
: 0;
21509 mouse_end_col
= (row
== mouse_end_row
)
21510 ? hlinfo
->mouse_face_end_col
21511 : row
->used
[TEXT_AREA
];
21515 /* Compute overhangs for all glyph strings. */
21516 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21517 for (s
= head
; s
; s
= s
->next
)
21518 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21520 /* Prepend glyph strings for glyphs in front of the first glyph
21521 string that are overwritten because of the first glyph
21522 string's left overhang. The background of all strings
21523 prepended must be drawn because the first glyph string
21525 i
= left_overwritten (head
);
21528 enum draw_glyphs_face overlap_hl
;
21530 /* If this row contains mouse highlighting, attempt to draw
21531 the overlapped glyphs with the correct highlight. This
21532 code fails if the overlap encompasses more than one glyph
21533 and mouse-highlight spans only some of these glyphs.
21534 However, making it work perfectly involves a lot more
21535 code, and I don't know if the pathological case occurs in
21536 practice, so we'll stick to this for now. --- cyd */
21537 if (check_mouse_face
21538 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21539 overlap_hl
= DRAW_MOUSE_FACE
;
21541 overlap_hl
= DRAW_NORMAL_TEXT
;
21544 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21545 overlap_hl
, dummy_x
, last_x
);
21547 compute_overhangs_and_x (t
, head
->x
, 1);
21548 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21552 /* Prepend glyph strings for glyphs in front of the first glyph
21553 string that overwrite that glyph string because of their
21554 right overhang. For these strings, only the foreground must
21555 be drawn, because it draws over the glyph string at `head'.
21556 The background must not be drawn because this would overwrite
21557 right overhangs of preceding glyphs for which no glyph
21559 i
= left_overwriting (head
);
21562 enum draw_glyphs_face overlap_hl
;
21564 if (check_mouse_face
21565 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21566 overlap_hl
= DRAW_MOUSE_FACE
;
21568 overlap_hl
= DRAW_NORMAL_TEXT
;
21571 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21572 overlap_hl
, dummy_x
, last_x
);
21573 for (s
= h
; s
; s
= s
->next
)
21574 s
->background_filled_p
= 1;
21575 compute_overhangs_and_x (t
, head
->x
, 1);
21576 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21579 /* Append glyphs strings for glyphs following the last glyph
21580 string tail that are overwritten by tail. The background of
21581 these strings has to be drawn because tail's foreground draws
21583 i
= right_overwritten (tail
);
21586 enum draw_glyphs_face overlap_hl
;
21588 if (check_mouse_face
21589 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21590 overlap_hl
= DRAW_MOUSE_FACE
;
21592 overlap_hl
= DRAW_NORMAL_TEXT
;
21594 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21595 overlap_hl
, x
, last_x
);
21596 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21597 we don't have `end = i;' here. */
21598 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21599 append_glyph_string_lists (&head
, &tail
, h
, t
);
21603 /* Append glyph strings for glyphs following the last glyph
21604 string tail that overwrite tail. The foreground of such
21605 glyphs has to be drawn because it writes into the background
21606 of tail. The background must not be drawn because it could
21607 paint over the foreground of following glyphs. */
21608 i
= right_overwriting (tail
);
21611 enum draw_glyphs_face overlap_hl
;
21612 if (check_mouse_face
21613 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21614 overlap_hl
= DRAW_MOUSE_FACE
;
21616 overlap_hl
= DRAW_NORMAL_TEXT
;
21619 i
++; /* We must include the Ith glyph. */
21620 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21621 overlap_hl
, x
, last_x
);
21622 for (s
= h
; s
; s
= s
->next
)
21623 s
->background_filled_p
= 1;
21624 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21625 append_glyph_string_lists (&head
, &tail
, h
, t
);
21627 if (clip_head
|| clip_tail
)
21628 for (s
= head
; s
; s
= s
->next
)
21630 s
->clip_head
= clip_head
;
21631 s
->clip_tail
= clip_tail
;
21635 /* Draw all strings. */
21636 for (s
= head
; s
; s
= s
->next
)
21637 FRAME_RIF (f
)->draw_glyph_string (s
);
21640 /* When focus a sole frame and move horizontally, this sets on_p to 0
21641 causing a failure to erase prev cursor position. */
21642 if (area
== TEXT_AREA
21643 && !row
->full_width_p
21644 /* When drawing overlapping rows, only the glyph strings'
21645 foreground is drawn, which doesn't erase a cursor
21649 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21650 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21651 : (tail
? tail
->x
+ tail
->background_width
: x
));
21655 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21656 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21660 /* Value is the x-position up to which drawn, relative to AREA of W.
21661 This doesn't include parts drawn because of overhangs. */
21662 if (row
->full_width_p
)
21663 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21665 x_reached
-= area_left
;
21667 RELEASE_HDC (hdc
, f
);
21672 /* Expand row matrix if too narrow. Don't expand if area
21675 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21677 if (!fonts_changed_p \
21678 && (it->glyph_row->glyphs[area] \
21679 < it->glyph_row->glyphs[area + 1])) \
21681 it->w->ncols_scale_factor++; \
21682 fonts_changed_p = 1; \
21686 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21687 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21690 append_glyph (struct it
*it
)
21692 struct glyph
*glyph
;
21693 enum glyph_row_area area
= it
->area
;
21695 xassert (it
->glyph_row
);
21696 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21698 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21699 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21701 /* If the glyph row is reversed, we need to prepend the glyph
21702 rather than append it. */
21703 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21707 /* Make room for the additional glyph. */
21708 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21710 glyph
= it
->glyph_row
->glyphs
[area
];
21712 glyph
->charpos
= CHARPOS (it
->position
);
21713 glyph
->object
= it
->object
;
21714 if (it
->pixel_width
> 0)
21716 glyph
->pixel_width
= it
->pixel_width
;
21717 glyph
->padding_p
= 0;
21721 /* Assure at least 1-pixel width. Otherwise, cursor can't
21722 be displayed correctly. */
21723 glyph
->pixel_width
= 1;
21724 glyph
->padding_p
= 1;
21726 glyph
->ascent
= it
->ascent
;
21727 glyph
->descent
= it
->descent
;
21728 glyph
->voffset
= it
->voffset
;
21729 glyph
->type
= CHAR_GLYPH
;
21730 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21731 glyph
->multibyte_p
= it
->multibyte_p
;
21732 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21733 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21734 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21735 || it
->phys_descent
> it
->descent
);
21736 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21737 glyph
->face_id
= it
->face_id
;
21738 glyph
->u
.ch
= it
->char_to_display
;
21739 glyph
->slice
.img
= null_glyph_slice
;
21740 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21743 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21744 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21746 glyph
->bidi_type
= it
->bidi_it
.type
;
21750 glyph
->resolved_level
= 0;
21751 glyph
->bidi_type
= UNKNOWN_BT
;
21753 ++it
->glyph_row
->used
[area
];
21756 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21759 /* Store one glyph for the composition IT->cmp_it.id in
21760 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21764 append_composite_glyph (struct it
*it
)
21766 struct glyph
*glyph
;
21767 enum glyph_row_area area
= it
->area
;
21769 xassert (it
->glyph_row
);
21771 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21772 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21774 /* If the glyph row is reversed, we need to prepend the glyph
21775 rather than append it. */
21776 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
21780 /* Make room for the new glyph. */
21781 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
21783 glyph
= it
->glyph_row
->glyphs
[it
->area
];
21785 glyph
->charpos
= it
->cmp_it
.charpos
;
21786 glyph
->object
= it
->object
;
21787 glyph
->pixel_width
= it
->pixel_width
;
21788 glyph
->ascent
= it
->ascent
;
21789 glyph
->descent
= it
->descent
;
21790 glyph
->voffset
= it
->voffset
;
21791 glyph
->type
= COMPOSITE_GLYPH
;
21792 if (it
->cmp_it
.ch
< 0)
21794 glyph
->u
.cmp
.automatic
= 0;
21795 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21796 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
21800 glyph
->u
.cmp
.automatic
= 1;
21801 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21802 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
21803 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
21805 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21806 glyph
->multibyte_p
= it
->multibyte_p
;
21807 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21808 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21809 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21810 || it
->phys_descent
> it
->descent
);
21811 glyph
->padding_p
= 0;
21812 glyph
->glyph_not_available_p
= 0;
21813 glyph
->face_id
= it
->face_id
;
21814 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21817 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21818 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21820 glyph
->bidi_type
= it
->bidi_it
.type
;
21822 ++it
->glyph_row
->used
[area
];
21825 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21829 /* Change IT->ascent and IT->height according to the setting of
21833 take_vertical_position_into_account (struct it
*it
)
21837 if (it
->voffset
< 0)
21838 /* Increase the ascent so that we can display the text higher
21840 it
->ascent
-= it
->voffset
;
21842 /* Increase the descent so that we can display the text lower
21844 it
->descent
+= it
->voffset
;
21849 /* Produce glyphs/get display metrics for the image IT is loaded with.
21850 See the description of struct display_iterator in dispextern.h for
21851 an overview of struct display_iterator. */
21854 produce_image_glyph (struct it
*it
)
21858 int glyph_ascent
, crop
;
21859 struct glyph_slice slice
;
21861 xassert (it
->what
== IT_IMAGE
);
21863 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21865 /* Make sure X resources of the face is loaded. */
21866 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21868 if (it
->image_id
< 0)
21870 /* Fringe bitmap. */
21871 it
->ascent
= it
->phys_ascent
= 0;
21872 it
->descent
= it
->phys_descent
= 0;
21873 it
->pixel_width
= 0;
21878 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21880 /* Make sure X resources of the image is loaded. */
21881 prepare_image_for_display (it
->f
, img
);
21883 slice
.x
= slice
.y
= 0;
21884 slice
.width
= img
->width
;
21885 slice
.height
= img
->height
;
21887 if (INTEGERP (it
->slice
.x
))
21888 slice
.x
= XINT (it
->slice
.x
);
21889 else if (FLOATP (it
->slice
.x
))
21890 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21892 if (INTEGERP (it
->slice
.y
))
21893 slice
.y
= XINT (it
->slice
.y
);
21894 else if (FLOATP (it
->slice
.y
))
21895 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21897 if (INTEGERP (it
->slice
.width
))
21898 slice
.width
= XINT (it
->slice
.width
);
21899 else if (FLOATP (it
->slice
.width
))
21900 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21902 if (INTEGERP (it
->slice
.height
))
21903 slice
.height
= XINT (it
->slice
.height
);
21904 else if (FLOATP (it
->slice
.height
))
21905 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21907 if (slice
.x
>= img
->width
)
21908 slice
.x
= img
->width
;
21909 if (slice
.y
>= img
->height
)
21910 slice
.y
= img
->height
;
21911 if (slice
.x
+ slice
.width
>= img
->width
)
21912 slice
.width
= img
->width
- slice
.x
;
21913 if (slice
.y
+ slice
.height
> img
->height
)
21914 slice
.height
= img
->height
- slice
.y
;
21916 if (slice
.width
== 0 || slice
.height
== 0)
21919 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21921 it
->descent
= slice
.height
- glyph_ascent
;
21923 it
->descent
+= img
->vmargin
;
21924 if (slice
.y
+ slice
.height
== img
->height
)
21925 it
->descent
+= img
->vmargin
;
21926 it
->phys_descent
= it
->descent
;
21928 it
->pixel_width
= slice
.width
;
21930 it
->pixel_width
+= img
->hmargin
;
21931 if (slice
.x
+ slice
.width
== img
->width
)
21932 it
->pixel_width
+= img
->hmargin
;
21934 /* It's quite possible for images to have an ascent greater than
21935 their height, so don't get confused in that case. */
21936 if (it
->descent
< 0)
21941 if (face
->box
!= FACE_NO_BOX
)
21943 if (face
->box_line_width
> 0)
21946 it
->ascent
+= face
->box_line_width
;
21947 if (slice
.y
+ slice
.height
== img
->height
)
21948 it
->descent
+= face
->box_line_width
;
21951 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21952 it
->pixel_width
+= eabs (face
->box_line_width
);
21953 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21954 it
->pixel_width
+= eabs (face
->box_line_width
);
21957 take_vertical_position_into_account (it
);
21959 /* Automatically crop wide image glyphs at right edge so we can
21960 draw the cursor on same display row. */
21961 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21962 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21964 it
->pixel_width
-= crop
;
21965 slice
.width
-= crop
;
21970 struct glyph
*glyph
;
21971 enum glyph_row_area area
= it
->area
;
21973 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21974 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21976 glyph
->charpos
= CHARPOS (it
->position
);
21977 glyph
->object
= it
->object
;
21978 glyph
->pixel_width
= it
->pixel_width
;
21979 glyph
->ascent
= glyph_ascent
;
21980 glyph
->descent
= it
->descent
;
21981 glyph
->voffset
= it
->voffset
;
21982 glyph
->type
= IMAGE_GLYPH
;
21983 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21984 glyph
->multibyte_p
= it
->multibyte_p
;
21985 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21986 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21987 glyph
->overlaps_vertically_p
= 0;
21988 glyph
->padding_p
= 0;
21989 glyph
->glyph_not_available_p
= 0;
21990 glyph
->face_id
= it
->face_id
;
21991 glyph
->u
.img_id
= img
->id
;
21992 glyph
->slice
.img
= slice
;
21993 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21996 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21997 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21999 glyph
->bidi_type
= it
->bidi_it
.type
;
22001 ++it
->glyph_row
->used
[area
];
22004 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22009 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22010 of the glyph, WIDTH and HEIGHT are the width and height of the
22011 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22014 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22015 int width
, int height
, int ascent
)
22017 struct glyph
*glyph
;
22018 enum glyph_row_area area
= it
->area
;
22020 xassert (ascent
>= 0 && ascent
<= height
);
22022 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22023 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22025 /* If the glyph row is reversed, we need to prepend the glyph
22026 rather than append it. */
22027 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22031 /* Make room for the additional glyph. */
22032 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22034 glyph
= it
->glyph_row
->glyphs
[area
];
22036 glyph
->charpos
= CHARPOS (it
->position
);
22037 glyph
->object
= object
;
22038 glyph
->pixel_width
= width
;
22039 glyph
->ascent
= ascent
;
22040 glyph
->descent
= height
- ascent
;
22041 glyph
->voffset
= it
->voffset
;
22042 glyph
->type
= STRETCH_GLYPH
;
22043 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22044 glyph
->multibyte_p
= it
->multibyte_p
;
22045 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22046 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22047 glyph
->overlaps_vertically_p
= 0;
22048 glyph
->padding_p
= 0;
22049 glyph
->glyph_not_available_p
= 0;
22050 glyph
->face_id
= it
->face_id
;
22051 glyph
->u
.stretch
.ascent
= ascent
;
22052 glyph
->u
.stretch
.height
= height
;
22053 glyph
->slice
.img
= null_glyph_slice
;
22054 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22057 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22058 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22060 glyph
->bidi_type
= it
->bidi_it
.type
;
22064 glyph
->resolved_level
= 0;
22065 glyph
->bidi_type
= UNKNOWN_BT
;
22067 ++it
->glyph_row
->used
[area
];
22070 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22074 /* Produce a stretch glyph for iterator IT. IT->object is the value
22075 of the glyph property displayed. The value must be a list
22076 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22079 1. `:width WIDTH' specifies that the space should be WIDTH *
22080 canonical char width wide. WIDTH may be an integer or floating
22083 2. `:relative-width FACTOR' specifies that the width of the stretch
22084 should be computed from the width of the first character having the
22085 `glyph' property, and should be FACTOR times that width.
22087 3. `:align-to HPOS' specifies that the space should be wide enough
22088 to reach HPOS, a value in canonical character units.
22090 Exactly one of the above pairs must be present.
22092 4. `:height HEIGHT' specifies that the height of the stretch produced
22093 should be HEIGHT, measured in canonical character units.
22095 5. `:relative-height FACTOR' specifies that the height of the
22096 stretch should be FACTOR times the height of the characters having
22097 the glyph property.
22099 Either none or exactly one of 4 or 5 must be present.
22101 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22102 of the stretch should be used for the ascent of the stretch.
22103 ASCENT must be in the range 0 <= ASCENT <= 100. */
22106 produce_stretch_glyph (struct it
*it
)
22108 /* (space :width WIDTH :height HEIGHT ...) */
22109 Lisp_Object prop
, plist
;
22110 int width
= 0, height
= 0, align_to
= -1;
22111 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22114 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22115 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22117 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22119 /* List should start with `space'. */
22120 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22121 plist
= XCDR (it
->object
);
22123 /* Compute the width of the stretch. */
22124 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22125 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22127 /* Absolute width `:width WIDTH' specified and valid. */
22128 zero_width_ok_p
= 1;
22131 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22134 /* Relative width `:relative-width FACTOR' specified and valid.
22135 Compute the width of the characters having the `glyph'
22138 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22141 if (it
->multibyte_p
)
22142 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22145 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22146 if (! ASCII_CHAR_P (it2
.c
))
22147 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22150 it2
.glyph_row
= NULL
;
22151 it2
.what
= IT_CHARACTER
;
22152 x_produce_glyphs (&it2
);
22153 width
= NUMVAL (prop
) * it2
.pixel_width
;
22155 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22156 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22158 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22159 align_to
= (align_to
< 0
22161 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22162 else if (align_to
< 0)
22163 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22164 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22165 zero_width_ok_p
= 1;
22168 /* Nothing specified -> width defaults to canonical char width. */
22169 width
= FRAME_COLUMN_WIDTH (it
->f
);
22171 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22174 /* Compute height. */
22175 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22176 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22179 zero_height_ok_p
= 1;
22181 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22183 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22185 height
= FONT_HEIGHT (font
);
22187 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22190 /* Compute percentage of height used for ascent. If
22191 `:ascent ASCENT' is present and valid, use that. Otherwise,
22192 derive the ascent from the font in use. */
22193 if (prop
= Fplist_get (plist
, QCascent
),
22194 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22195 ascent
= height
* NUMVAL (prop
) / 100.0;
22196 else if (!NILP (prop
)
22197 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22198 ascent
= min (max (0, (int)tem
), height
);
22200 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22202 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22203 && it
->current_x
+ width
> it
->last_visible_x
)
22204 width
= it
->last_visible_x
- it
->current_x
- 1;
22206 if (width
> 0 && height
> 0 && it
->glyph_row
)
22208 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22209 if (!STRINGP (object
))
22210 object
= it
->w
->buffer
;
22211 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22214 it
->pixel_width
= width
;
22215 it
->ascent
= it
->phys_ascent
= ascent
;
22216 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22217 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22219 take_vertical_position_into_account (it
);
22222 /* Calculate line-height and line-spacing properties.
22223 An integer value specifies explicit pixel value.
22224 A float value specifies relative value to current face height.
22225 A cons (float . face-name) specifies relative value to
22226 height of specified face font.
22228 Returns height in pixels, or nil. */
22232 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22233 int boff
, int override
)
22235 Lisp_Object face_name
= Qnil
;
22236 int ascent
, descent
, height
;
22238 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22243 face_name
= XCAR (val
);
22245 if (!NUMBERP (val
))
22246 val
= make_number (1);
22247 if (NILP (face_name
))
22249 height
= it
->ascent
+ it
->descent
;
22254 if (NILP (face_name
))
22256 font
= FRAME_FONT (it
->f
);
22257 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22259 else if (EQ (face_name
, Qt
))
22268 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22270 return make_number (-1);
22272 face
= FACE_FROM_ID (it
->f
, face_id
);
22275 return make_number (-1);
22276 boff
= font
->baseline_offset
;
22277 if (font
->vertical_centering
)
22278 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22281 ascent
= FONT_BASE (font
) + boff
;
22282 descent
= FONT_DESCENT (font
) - boff
;
22286 it
->override_ascent
= ascent
;
22287 it
->override_descent
= descent
;
22288 it
->override_boff
= boff
;
22291 height
= ascent
+ descent
;
22295 height
= (int)(XFLOAT_DATA (val
) * height
);
22296 else if (INTEGERP (val
))
22297 height
*= XINT (val
);
22299 return make_number (height
);
22303 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22304 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22305 and only if this is for a character for which no font was found.
22307 If the display method (it->glyphless_method) is
22308 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22309 length of the acronym or the hexadecimal string, UPPER_XOFF and
22310 UPPER_YOFF are pixel offsets for the upper part of the string,
22311 LOWER_XOFF and LOWER_YOFF are for the lower part.
22313 For the other display methods, LEN through LOWER_YOFF are zero. */
22316 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22317 short upper_xoff
, short upper_yoff
,
22318 short lower_xoff
, short lower_yoff
)
22320 struct glyph
*glyph
;
22321 enum glyph_row_area area
= it
->area
;
22323 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22324 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22326 /* If the glyph row is reversed, we need to prepend the glyph
22327 rather than append it. */
22328 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22332 /* Make room for the additional glyph. */
22333 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22335 glyph
= it
->glyph_row
->glyphs
[area
];
22337 glyph
->charpos
= CHARPOS (it
->position
);
22338 glyph
->object
= it
->object
;
22339 glyph
->pixel_width
= it
->pixel_width
;
22340 glyph
->ascent
= it
->ascent
;
22341 glyph
->descent
= it
->descent
;
22342 glyph
->voffset
= it
->voffset
;
22343 glyph
->type
= GLYPHLESS_GLYPH
;
22344 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22345 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22346 glyph
->u
.glyphless
.len
= len
;
22347 glyph
->u
.glyphless
.ch
= it
->c
;
22348 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22349 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22350 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22351 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22352 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22353 glyph
->multibyte_p
= it
->multibyte_p
;
22354 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22355 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22356 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22357 || it
->phys_descent
> it
->descent
);
22358 glyph
->padding_p
= 0;
22359 glyph
->glyph_not_available_p
= 0;
22360 glyph
->face_id
= face_id
;
22361 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22364 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22365 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22367 glyph
->bidi_type
= it
->bidi_it
.type
;
22369 ++it
->glyph_row
->used
[area
];
22372 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22376 /* Produce a glyph for a glyphless character for iterator IT.
22377 IT->glyphless_method specifies which method to use for displaying
22378 the character. See the description of enum
22379 glyphless_display_method in dispextern.h for the detail.
22381 FOR_NO_FONT is nonzero if and only if this is for a character for
22382 which no font was found. ACRONYM, if non-nil, is an acronym string
22383 for the character. */
22386 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22391 int base_width
, base_height
, width
, height
;
22392 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22395 /* Get the metrics of the base font. We always refer to the current
22397 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22398 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22399 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22400 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
22401 base_height
= it
->ascent
+ it
->descent
;
22402 base_width
= font
->average_width
;
22404 /* Get a face ID for the glyph by utilizing a cache (the same way as
22405 doen for `escape-glyph' in get_next_display_element). */
22406 if (it
->f
== last_glyphless_glyph_frame
22407 && it
->face_id
== last_glyphless_glyph_face_id
)
22409 face_id
= last_glyphless_glyph_merged_face_id
;
22413 /* Merge the `glyphless-char' face into the current face. */
22414 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
22415 last_glyphless_glyph_frame
= it
->f
;
22416 last_glyphless_glyph_face_id
= it
->face_id
;
22417 last_glyphless_glyph_merged_face_id
= face_id
;
22420 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
22422 it
->pixel_width
= THIN_SPACE_WIDTH
;
22424 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22426 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
22428 width
= CHAR_WIDTH (it
->c
);
22431 else if (width
> 4)
22433 it
->pixel_width
= base_width
* width
;
22435 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22440 unsigned int code
[6];
22442 int ascent
, descent
;
22443 struct font_metrics metrics_upper
, metrics_lower
;
22445 face
= FACE_FROM_ID (it
->f
, face_id
);
22446 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22447 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22449 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
22451 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
22452 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
22453 str
= STRINGP (acronym
) ? (char *) SDATA (acronym
) : "";
22457 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
22458 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
22461 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
22462 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
22463 upper_len
= (len
+ 1) / 2;
22464 font
->driver
->text_extents (font
, code
, upper_len
,
22466 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
22471 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
22472 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
22473 upper_xoff
= upper_yoff
= 2; /* the typical case */
22474 if (base_width
>= width
)
22476 /* Align the upper to the left, the lower to the right. */
22477 it
->pixel_width
= base_width
;
22478 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
22482 /* Center the shorter one. */
22483 it
->pixel_width
= width
;
22484 if (metrics_upper
.width
>= metrics_lower
.width
)
22485 lower_xoff
= (width
- metrics_lower
.width
) / 2;
22487 upper_xoff
= (width
- metrics_upper
.width
) / 2;
22490 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
22491 top, bottom, and between upper and lower strings. */
22492 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
22493 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
22494 /* Center vertically.
22495 H:base_height, D:base_descent
22496 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
22498 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
22499 descent = D - H/2 + h/2;
22500 lower_yoff = descent - 2 - ld;
22501 upper_yoff = lower_yoff - la - 1 - ud; */
22502 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
22503 descent
= it
->descent
- (base_height
- height
) / 2;
22504 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
22505 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
22506 - metrics_upper
.descent
);
22507 /* Don't make the height shorter than the base height. */
22508 if (height
> base_height
)
22510 it
->ascent
= ascent
;
22511 it
->descent
= descent
;
22515 it
->phys_ascent
= it
->ascent
;
22516 it
->phys_descent
= it
->descent
;
22518 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
22519 upper_xoff
, upper_yoff
,
22520 lower_xoff
, lower_yoff
);
22522 take_vertical_position_into_account (it
);
22527 Produce glyphs/get display metrics for the display element IT is
22528 loaded with. See the description of struct it in dispextern.h
22529 for an overview of struct it. */
22532 x_produce_glyphs (struct it
*it
)
22534 int extra_line_spacing
= it
->extra_line_spacing
;
22536 it
->glyph_not_available_p
= 0;
22538 if (it
->what
== IT_CHARACTER
)
22541 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22542 struct font
*font
= face
->font
;
22543 struct font_metrics
*pcm
= NULL
;
22544 int boff
; /* baseline offset */
22548 /* When no suitable font is found, display this character by
22549 the method specified in the first extra slot of
22550 Vglyphless_char_display. */
22551 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
22553 xassert (it
->what
== IT_GLYPHLESS
);
22554 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
22558 boff
= font
->baseline_offset
;
22559 if (font
->vertical_centering
)
22560 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22562 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
22568 if (it
->override_ascent
>= 0)
22570 it
->ascent
= it
->override_ascent
;
22571 it
->descent
= it
->override_descent
;
22572 boff
= it
->override_boff
;
22576 it
->ascent
= FONT_BASE (font
) + boff
;
22577 it
->descent
= FONT_DESCENT (font
) - boff
;
22580 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
22582 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22583 if (pcm
->width
== 0
22584 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
22590 it
->phys_ascent
= pcm
->ascent
+ boff
;
22591 it
->phys_descent
= pcm
->descent
- boff
;
22592 it
->pixel_width
= pcm
->width
;
22596 it
->glyph_not_available_p
= 1;
22597 it
->phys_ascent
= it
->ascent
;
22598 it
->phys_descent
= it
->descent
;
22599 it
->pixel_width
= font
->space_width
;
22602 if (it
->constrain_row_ascent_descent_p
)
22604 if (it
->descent
> it
->max_descent
)
22606 it
->ascent
+= it
->descent
- it
->max_descent
;
22607 it
->descent
= it
->max_descent
;
22609 if (it
->ascent
> it
->max_ascent
)
22611 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22612 it
->ascent
= it
->max_ascent
;
22614 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22615 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22616 extra_line_spacing
= 0;
22619 /* If this is a space inside a region of text with
22620 `space-width' property, change its width. */
22621 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22623 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22625 /* If face has a box, add the box thickness to the character
22626 height. If character has a box line to the left and/or
22627 right, add the box line width to the character's width. */
22628 if (face
->box
!= FACE_NO_BOX
)
22630 int thick
= face
->box_line_width
;
22634 it
->ascent
+= thick
;
22635 it
->descent
+= thick
;
22640 if (it
->start_of_box_run_p
)
22641 it
->pixel_width
+= thick
;
22642 if (it
->end_of_box_run_p
)
22643 it
->pixel_width
+= thick
;
22646 /* If face has an overline, add the height of the overline
22647 (1 pixel) and a 1 pixel margin to the character height. */
22648 if (face
->overline_p
)
22649 it
->ascent
+= overline_margin
;
22651 if (it
->constrain_row_ascent_descent_p
)
22653 if (it
->ascent
> it
->max_ascent
)
22654 it
->ascent
= it
->max_ascent
;
22655 if (it
->descent
> it
->max_descent
)
22656 it
->descent
= it
->max_descent
;
22659 take_vertical_position_into_account (it
);
22661 /* If we have to actually produce glyphs, do it. */
22666 /* Translate a space with a `space-width' property
22667 into a stretch glyph. */
22668 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22669 / FONT_HEIGHT (font
));
22670 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22671 it
->ascent
+ it
->descent
, ascent
);
22676 /* If characters with lbearing or rbearing are displayed
22677 in this line, record that fact in a flag of the
22678 glyph row. This is used to optimize X output code. */
22679 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22680 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22682 if (! stretched_p
&& it
->pixel_width
== 0)
22683 /* We assure that all visible glyphs have at least 1-pixel
22685 it
->pixel_width
= 1;
22687 else if (it
->char_to_display
== '\n')
22689 /* A newline has no width, but we need the height of the
22690 line. But if previous part of the line sets a height,
22691 don't increase that height */
22693 Lisp_Object height
;
22694 Lisp_Object total_height
= Qnil
;
22696 it
->override_ascent
= -1;
22697 it
->pixel_width
= 0;
22700 height
= get_it_property (it
, Qline_height
);
22701 /* Split (line-height total-height) list */
22703 && CONSP (XCDR (height
))
22704 && NILP (XCDR (XCDR (height
))))
22706 total_height
= XCAR (XCDR (height
));
22707 height
= XCAR (height
);
22709 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
22711 if (it
->override_ascent
>= 0)
22713 it
->ascent
= it
->override_ascent
;
22714 it
->descent
= it
->override_descent
;
22715 boff
= it
->override_boff
;
22719 it
->ascent
= FONT_BASE (font
) + boff
;
22720 it
->descent
= FONT_DESCENT (font
) - boff
;
22723 if (EQ (height
, Qt
))
22725 if (it
->descent
> it
->max_descent
)
22727 it
->ascent
+= it
->descent
- it
->max_descent
;
22728 it
->descent
= it
->max_descent
;
22730 if (it
->ascent
> it
->max_ascent
)
22732 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22733 it
->ascent
= it
->max_ascent
;
22735 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22736 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22737 it
->constrain_row_ascent_descent_p
= 1;
22738 extra_line_spacing
= 0;
22742 Lisp_Object spacing
;
22744 it
->phys_ascent
= it
->ascent
;
22745 it
->phys_descent
= it
->descent
;
22747 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22748 && face
->box
!= FACE_NO_BOX
22749 && face
->box_line_width
> 0)
22751 it
->ascent
+= face
->box_line_width
;
22752 it
->descent
+= face
->box_line_width
;
22755 && XINT (height
) > it
->ascent
+ it
->descent
)
22756 it
->ascent
= XINT (height
) - it
->descent
;
22758 if (!NILP (total_height
))
22759 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
22762 spacing
= get_it_property (it
, Qline_spacing
);
22763 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
22765 if (INTEGERP (spacing
))
22767 extra_line_spacing
= XINT (spacing
);
22768 if (!NILP (total_height
))
22769 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22773 else /* i.e. (it->char_to_display == '\t') */
22775 if (font
->space_width
> 0)
22777 int tab_width
= it
->tab_width
* font
->space_width
;
22778 int x
= it
->current_x
+ it
->continuation_lines_width
;
22779 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22781 /* If the distance from the current position to the next tab
22782 stop is less than a space character width, use the
22783 tab stop after that. */
22784 if (next_tab_x
- x
< font
->space_width
)
22785 next_tab_x
+= tab_width
;
22787 it
->pixel_width
= next_tab_x
- x
;
22789 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22790 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22794 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22795 it
->ascent
+ it
->descent
, it
->ascent
);
22800 it
->pixel_width
= 0;
22805 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22807 /* A static composition.
22809 Note: A composition is represented as one glyph in the
22810 glyph matrix. There are no padding glyphs.
22812 Important note: pixel_width, ascent, and descent are the
22813 values of what is drawn by draw_glyphs (i.e. the values of
22814 the overall glyphs composed). */
22815 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22816 int boff
; /* baseline offset */
22817 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22818 int glyph_len
= cmp
->glyph_len
;
22819 struct font
*font
= face
->font
;
22823 /* If we have not yet calculated pixel size data of glyphs of
22824 the composition for the current face font, calculate them
22825 now. Theoretically, we have to check all fonts for the
22826 glyphs, but that requires much time and memory space. So,
22827 here we check only the font of the first glyph. This may
22828 lead to incorrect display, but it's very rare, and C-l
22829 (recenter-top-bottom) can correct the display anyway. */
22830 if (! cmp
->font
|| cmp
->font
!= font
)
22832 /* Ascent and descent of the font of the first character
22833 of this composition (adjusted by baseline offset).
22834 Ascent and descent of overall glyphs should not be less
22835 than these, respectively. */
22836 int font_ascent
, font_descent
, font_height
;
22837 /* Bounding box of the overall glyphs. */
22838 int leftmost
, rightmost
, lowest
, highest
;
22839 int lbearing
, rbearing
;
22840 int i
, width
, ascent
, descent
;
22841 int left_padded
= 0, right_padded
= 0;
22844 struct font_metrics
*pcm
;
22845 int font_not_found_p
;
22848 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22849 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22851 if (glyph_len
< cmp
->glyph_len
)
22853 for (i
= 0; i
< glyph_len
; i
++)
22855 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22857 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22862 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22863 : IT_CHARPOS (*it
));
22864 /* If no suitable font is found, use the default font. */
22865 font_not_found_p
= font
== NULL
;
22866 if (font_not_found_p
)
22868 face
= face
->ascii_face
;
22871 boff
= font
->baseline_offset
;
22872 if (font
->vertical_centering
)
22873 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22874 font_ascent
= FONT_BASE (font
) + boff
;
22875 font_descent
= FONT_DESCENT (font
) - boff
;
22876 font_height
= FONT_HEIGHT (font
);
22878 cmp
->font
= (void *) font
;
22881 if (! font_not_found_p
)
22883 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22884 &char2b
, it
->multibyte_p
, 0);
22885 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22888 /* Initialize the bounding box. */
22891 width
= pcm
->width
;
22892 ascent
= pcm
->ascent
;
22893 descent
= pcm
->descent
;
22894 lbearing
= pcm
->lbearing
;
22895 rbearing
= pcm
->rbearing
;
22899 width
= font
->space_width
;
22900 ascent
= FONT_BASE (font
);
22901 descent
= FONT_DESCENT (font
);
22908 lowest
= - descent
+ boff
;
22909 highest
= ascent
+ boff
;
22911 if (! font_not_found_p
22912 && font
->default_ascent
22913 && CHAR_TABLE_P (Vuse_default_ascent
)
22914 && !NILP (Faref (Vuse_default_ascent
,
22915 make_number (it
->char_to_display
))))
22916 highest
= font
->default_ascent
+ boff
;
22918 /* Draw the first glyph at the normal position. It may be
22919 shifted to right later if some other glyphs are drawn
22921 cmp
->offsets
[i
* 2] = 0;
22922 cmp
->offsets
[i
* 2 + 1] = boff
;
22923 cmp
->lbearing
= lbearing
;
22924 cmp
->rbearing
= rbearing
;
22926 /* Set cmp->offsets for the remaining glyphs. */
22927 for (i
++; i
< glyph_len
; i
++)
22929 int left
, right
, btm
, top
;
22930 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22932 struct face
*this_face
;
22937 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22938 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22939 font
= this_face
->font
;
22945 this_boff
= font
->baseline_offset
;
22946 if (font
->vertical_centering
)
22947 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22948 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22949 &char2b
, it
->multibyte_p
, 0);
22950 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22953 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22956 width
= pcm
->width
;
22957 ascent
= pcm
->ascent
;
22958 descent
= pcm
->descent
;
22959 lbearing
= pcm
->lbearing
;
22960 rbearing
= pcm
->rbearing
;
22961 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22963 /* Relative composition with or without
22964 alternate chars. */
22965 left
= (leftmost
+ rightmost
- width
) / 2;
22966 btm
= - descent
+ boff
;
22967 if (font
->relative_compose
22968 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22969 || NILP (Faref (Vignore_relative_composition
,
22970 make_number (ch
)))))
22973 if (- descent
>= font
->relative_compose
)
22974 /* One extra pixel between two glyphs. */
22976 else if (ascent
<= 0)
22977 /* One extra pixel between two glyphs. */
22978 btm
= lowest
- 1 - ascent
- descent
;
22983 /* A composition rule is specified by an integer
22984 value that encodes global and new reference
22985 points (GREF and NREF). GREF and NREF are
22986 specified by numbers as below:
22988 0---1---2 -- ascent
22992 9--10--11 -- center
22994 ---3---4---5--- baseline
22996 6---7---8 -- descent
22998 int rule
= COMPOSITION_RULE (cmp
, i
);
22999 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23001 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23002 grefx
= gref
% 3, nrefx
= nref
% 3;
23003 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23005 xoff
= font_height
* (xoff
- 128) / 256;
23007 yoff
= font_height
* (yoff
- 128) / 256;
23010 + grefx
* (rightmost
- leftmost
) / 2
23011 - nrefx
* width
/ 2
23014 btm
= ((grefy
== 0 ? highest
23016 : grefy
== 2 ? lowest
23017 : (highest
+ lowest
) / 2)
23018 - (nrefy
== 0 ? ascent
+ descent
23019 : nrefy
== 1 ? descent
- boff
23021 : (ascent
+ descent
) / 2)
23025 cmp
->offsets
[i
* 2] = left
;
23026 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23028 /* Update the bounding box of the overall glyphs. */
23031 right
= left
+ width
;
23032 if (left
< leftmost
)
23034 if (right
> rightmost
)
23037 top
= btm
+ descent
+ ascent
;
23043 if (cmp
->lbearing
> left
+ lbearing
)
23044 cmp
->lbearing
= left
+ lbearing
;
23045 if (cmp
->rbearing
< left
+ rbearing
)
23046 cmp
->rbearing
= left
+ rbearing
;
23050 /* If there are glyphs whose x-offsets are negative,
23051 shift all glyphs to the right and make all x-offsets
23055 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23056 cmp
->offsets
[i
* 2] -= leftmost
;
23057 rightmost
-= leftmost
;
23058 cmp
->lbearing
-= leftmost
;
23059 cmp
->rbearing
-= leftmost
;
23062 if (left_padded
&& cmp
->lbearing
< 0)
23064 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23065 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23066 rightmost
-= cmp
->lbearing
;
23067 cmp
->rbearing
-= cmp
->lbearing
;
23070 if (right_padded
&& rightmost
< cmp
->rbearing
)
23072 rightmost
= cmp
->rbearing
;
23075 cmp
->pixel_width
= rightmost
;
23076 cmp
->ascent
= highest
;
23077 cmp
->descent
= - lowest
;
23078 if (cmp
->ascent
< font_ascent
)
23079 cmp
->ascent
= font_ascent
;
23080 if (cmp
->descent
< font_descent
)
23081 cmp
->descent
= font_descent
;
23085 && (cmp
->lbearing
< 0
23086 || cmp
->rbearing
> cmp
->pixel_width
))
23087 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23089 it
->pixel_width
= cmp
->pixel_width
;
23090 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23091 it
->descent
= it
->phys_descent
= cmp
->descent
;
23092 if (face
->box
!= FACE_NO_BOX
)
23094 int thick
= face
->box_line_width
;
23098 it
->ascent
+= thick
;
23099 it
->descent
+= thick
;
23104 if (it
->start_of_box_run_p
)
23105 it
->pixel_width
+= thick
;
23106 if (it
->end_of_box_run_p
)
23107 it
->pixel_width
+= thick
;
23110 /* If face has an overline, add the height of the overline
23111 (1 pixel) and a 1 pixel margin to the character height. */
23112 if (face
->overline_p
)
23113 it
->ascent
+= overline_margin
;
23115 take_vertical_position_into_account (it
);
23116 if (it
->ascent
< 0)
23118 if (it
->descent
< 0)
23122 append_composite_glyph (it
);
23124 else if (it
->what
== IT_COMPOSITION
)
23126 /* A dynamic (automatic) composition. */
23127 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23128 Lisp_Object gstring
;
23129 struct font_metrics metrics
;
23131 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23133 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23136 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23137 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23138 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23139 it
->descent
= it
->phys_descent
= metrics
.descent
;
23140 if (face
->box
!= FACE_NO_BOX
)
23142 int thick
= face
->box_line_width
;
23146 it
->ascent
+= thick
;
23147 it
->descent
+= thick
;
23152 if (it
->start_of_box_run_p
)
23153 it
->pixel_width
+= thick
;
23154 if (it
->end_of_box_run_p
)
23155 it
->pixel_width
+= thick
;
23157 /* If face has an overline, add the height of the overline
23158 (1 pixel) and a 1 pixel margin to the character height. */
23159 if (face
->overline_p
)
23160 it
->ascent
+= overline_margin
;
23161 take_vertical_position_into_account (it
);
23162 if (it
->ascent
< 0)
23164 if (it
->descent
< 0)
23168 append_composite_glyph (it
);
23170 else if (it
->what
== IT_GLYPHLESS
)
23171 produce_glyphless_glyph (it
, 0, Qnil
);
23172 else if (it
->what
== IT_IMAGE
)
23173 produce_image_glyph (it
);
23174 else if (it
->what
== IT_STRETCH
)
23175 produce_stretch_glyph (it
);
23178 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23179 because this isn't true for images with `:ascent 100'. */
23180 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23181 if (it
->area
== TEXT_AREA
)
23182 it
->current_x
+= it
->pixel_width
;
23184 if (extra_line_spacing
> 0)
23186 it
->descent
+= extra_line_spacing
;
23187 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23188 it
->max_extra_line_spacing
= extra_line_spacing
;
23191 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23192 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23193 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23194 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23198 Output LEN glyphs starting at START at the nominal cursor position.
23199 Advance the nominal cursor over the text. The global variable
23200 updated_window contains the window being updated, updated_row is
23201 the glyph row being updated, and updated_area is the area of that
23202 row being updated. */
23205 x_write_glyphs (struct glyph
*start
, int len
)
23209 xassert (updated_window
&& updated_row
);
23212 /* Write glyphs. */
23214 hpos
= start
- updated_row
->glyphs
[updated_area
];
23215 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23216 updated_row
, updated_area
,
23218 DRAW_NORMAL_TEXT
, 0);
23220 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23221 if (updated_area
== TEXT_AREA
23222 && updated_window
->phys_cursor_on_p
23223 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23224 && updated_window
->phys_cursor
.hpos
>= hpos
23225 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23226 updated_window
->phys_cursor_on_p
= 0;
23230 /* Advance the output cursor. */
23231 output_cursor
.hpos
+= len
;
23232 output_cursor
.x
= x
;
23237 Insert LEN glyphs from START at the nominal cursor position. */
23240 x_insert_glyphs (struct glyph
*start
, int len
)
23244 int line_height
, shift_by_width
, shifted_region_width
;
23245 struct glyph_row
*row
;
23246 struct glyph
*glyph
;
23247 int frame_x
, frame_y
;
23250 xassert (updated_window
&& updated_row
);
23252 w
= updated_window
;
23253 f
= XFRAME (WINDOW_FRAME (w
));
23255 /* Get the height of the line we are in. */
23257 line_height
= row
->height
;
23259 /* Get the width of the glyphs to insert. */
23260 shift_by_width
= 0;
23261 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23262 shift_by_width
+= glyph
->pixel_width
;
23264 /* Get the width of the region to shift right. */
23265 shifted_region_width
= (window_box_width (w
, updated_area
)
23270 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23271 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23273 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23274 line_height
, shift_by_width
);
23276 /* Write the glyphs. */
23277 hpos
= start
- row
->glyphs
[updated_area
];
23278 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23280 DRAW_NORMAL_TEXT
, 0);
23282 /* Advance the output cursor. */
23283 output_cursor
.hpos
+= len
;
23284 output_cursor
.x
+= shift_by_width
;
23290 Erase the current text line from the nominal cursor position
23291 (inclusive) to pixel column TO_X (exclusive). The idea is that
23292 everything from TO_X onward is already erased.
23294 TO_X is a pixel position relative to updated_area of
23295 updated_window. TO_X == -1 means clear to the end of this area. */
23298 x_clear_end_of_line (int to_x
)
23301 struct window
*w
= updated_window
;
23302 int max_x
, min_y
, max_y
;
23303 int from_x
, from_y
, to_y
;
23305 xassert (updated_window
&& updated_row
);
23306 f
= XFRAME (w
->frame
);
23308 if (updated_row
->full_width_p
)
23309 max_x
= WINDOW_TOTAL_WIDTH (w
);
23311 max_x
= window_box_width (w
, updated_area
);
23312 max_y
= window_text_bottom_y (w
);
23314 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23315 of window. For TO_X > 0, truncate to end of drawing area. */
23321 to_x
= min (to_x
, max_x
);
23323 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23325 /* Notice if the cursor will be cleared by this operation. */
23326 if (!updated_row
->full_width_p
)
23327 notice_overwritten_cursor (w
, updated_area
,
23328 output_cursor
.x
, -1,
23330 MATRIX_ROW_BOTTOM_Y (updated_row
));
23332 from_x
= output_cursor
.x
;
23334 /* Translate to frame coordinates. */
23335 if (updated_row
->full_width_p
)
23337 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23338 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23342 int area_left
= window_box_left (w
, updated_area
);
23343 from_x
+= area_left
;
23347 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23348 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23349 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23351 /* Prevent inadvertently clearing to end of the X window. */
23352 if (to_x
> from_x
&& to_y
> from_y
)
23355 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23356 to_x
- from_x
, to_y
- from_y
);
23361 #endif /* HAVE_WINDOW_SYSTEM */
23365 /***********************************************************************
23367 ***********************************************************************/
23369 /* Value is the internal representation of the specified cursor type
23370 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23371 of the bar cursor. */
23373 static enum text_cursor_kinds
23374 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23376 enum text_cursor_kinds type
;
23381 if (EQ (arg
, Qbox
))
23382 return FILLED_BOX_CURSOR
;
23384 if (EQ (arg
, Qhollow
))
23385 return HOLLOW_BOX_CURSOR
;
23387 if (EQ (arg
, Qbar
))
23394 && EQ (XCAR (arg
), Qbar
)
23395 && INTEGERP (XCDR (arg
))
23396 && XINT (XCDR (arg
)) >= 0)
23398 *width
= XINT (XCDR (arg
));
23402 if (EQ (arg
, Qhbar
))
23405 return HBAR_CURSOR
;
23409 && EQ (XCAR (arg
), Qhbar
)
23410 && INTEGERP (XCDR (arg
))
23411 && XINT (XCDR (arg
)) >= 0)
23413 *width
= XINT (XCDR (arg
));
23414 return HBAR_CURSOR
;
23417 /* Treat anything unknown as "hollow box cursor".
23418 It was bad to signal an error; people have trouble fixing
23419 .Xdefaults with Emacs, when it has something bad in it. */
23420 type
= HOLLOW_BOX_CURSOR
;
23425 /* Set the default cursor types for specified frame. */
23427 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
23432 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23433 FRAME_CURSOR_WIDTH (f
) = width
;
23435 /* By default, set up the blink-off state depending on the on-state. */
23437 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23440 FRAME_BLINK_OFF_CURSOR (f
)
23441 = get_specified_cursor_type (XCDR (tem
), &width
);
23442 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23445 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23449 #ifdef HAVE_WINDOW_SYSTEM
23451 /* Return the cursor we want to be displayed in window W. Return
23452 width of bar/hbar cursor through WIDTH arg. Return with
23453 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23454 (i.e. if the `system caret' should track this cursor).
23456 In a mini-buffer window, we want the cursor only to appear if we
23457 are reading input from this window. For the selected window, we
23458 want the cursor type given by the frame parameter or buffer local
23459 setting of cursor-type. If explicitly marked off, draw no cursor.
23460 In all other cases, we want a hollow box cursor. */
23462 static enum text_cursor_kinds
23463 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
23464 int *active_cursor
)
23466 struct frame
*f
= XFRAME (w
->frame
);
23467 struct buffer
*b
= XBUFFER (w
->buffer
);
23468 int cursor_type
= DEFAULT_CURSOR
;
23469 Lisp_Object alt_cursor
;
23470 int non_selected
= 0;
23472 *active_cursor
= 1;
23475 if (cursor_in_echo_area
23476 && FRAME_HAS_MINIBUF_P (f
)
23477 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23479 if (w
== XWINDOW (echo_area_window
))
23481 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
23483 *width
= FRAME_CURSOR_WIDTH (f
);
23484 return FRAME_DESIRED_CURSOR (f
);
23487 return get_specified_cursor_type (b
->cursor_type
, width
);
23490 *active_cursor
= 0;
23494 /* Detect a nonselected window or nonselected frame. */
23495 else if (w
!= XWINDOW (f
->selected_window
)
23496 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
23498 *active_cursor
= 0;
23500 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23506 /* Never display a cursor in a window in which cursor-type is nil. */
23507 if (NILP (b
->cursor_type
))
23510 /* Get the normal cursor type for this window. */
23511 if (EQ (b
->cursor_type
, Qt
))
23513 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23514 *width
= FRAME_CURSOR_WIDTH (f
);
23517 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
23519 /* Use cursor-in-non-selected-windows instead
23520 for non-selected window or frame. */
23523 alt_cursor
= b
->cursor_in_non_selected_windows
;
23524 if (!EQ (Qt
, alt_cursor
))
23525 return get_specified_cursor_type (alt_cursor
, width
);
23526 /* t means modify the normal cursor type. */
23527 if (cursor_type
== FILLED_BOX_CURSOR
)
23528 cursor_type
= HOLLOW_BOX_CURSOR
;
23529 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23531 return cursor_type
;
23534 /* Use normal cursor if not blinked off. */
23535 if (!w
->cursor_off_p
)
23537 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23539 if (cursor_type
== FILLED_BOX_CURSOR
)
23541 /* Using a block cursor on large images can be very annoying.
23542 So use a hollow cursor for "large" images.
23543 If image is not transparent (no mask), also use hollow cursor. */
23544 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23545 if (img
!= NULL
&& IMAGEP (img
->spec
))
23547 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23548 where N = size of default frame font size.
23549 This should cover most of the "tiny" icons people may use. */
23551 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23552 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23553 cursor_type
= HOLLOW_BOX_CURSOR
;
23556 else if (cursor_type
!= NO_CURSOR
)
23558 /* Display current only supports BOX and HOLLOW cursors for images.
23559 So for now, unconditionally use a HOLLOW cursor when cursor is
23560 not a solid box cursor. */
23561 cursor_type
= HOLLOW_BOX_CURSOR
;
23564 return cursor_type
;
23567 /* Cursor is blinked off, so determine how to "toggle" it. */
23569 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23570 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
23571 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23573 /* Then see if frame has specified a specific blink off cursor type. */
23574 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23576 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23577 return FRAME_BLINK_OFF_CURSOR (f
);
23581 /* Some people liked having a permanently visible blinking cursor,
23582 while others had very strong opinions against it. So it was
23583 decided to remove it. KFS 2003-09-03 */
23585 /* Finally perform built-in cursor blinking:
23586 filled box <-> hollow box
23587 wide [h]bar <-> narrow [h]bar
23588 narrow [h]bar <-> no cursor
23589 other type <-> no cursor */
23591 if (cursor_type
== FILLED_BOX_CURSOR
)
23592 return HOLLOW_BOX_CURSOR
;
23594 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23597 return cursor_type
;
23605 /* Notice when the text cursor of window W has been completely
23606 overwritten by a drawing operation that outputs glyphs in AREA
23607 starting at X0 and ending at X1 in the line starting at Y0 and
23608 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23609 the rest of the line after X0 has been written. Y coordinates
23610 are window-relative. */
23613 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
23614 int x0
, int x1
, int y0
, int y1
)
23616 int cx0
, cx1
, cy0
, cy1
;
23617 struct glyph_row
*row
;
23619 if (!w
->phys_cursor_on_p
)
23621 if (area
!= TEXT_AREA
)
23624 if (w
->phys_cursor
.vpos
< 0
23625 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23626 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23627 !(row
->enabled_p
&& row
->displays_text_p
)))
23630 if (row
->cursor_in_fringe_p
)
23632 row
->cursor_in_fringe_p
= 0;
23633 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
23634 w
->phys_cursor_on_p
= 0;
23638 cx0
= w
->phys_cursor
.x
;
23639 cx1
= cx0
+ w
->phys_cursor_width
;
23640 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23643 /* The cursor image will be completely removed from the
23644 screen if the output area intersects the cursor area in
23645 y-direction. When we draw in [y0 y1[, and some part of
23646 the cursor is at y < y0, that part must have been drawn
23647 before. When scrolling, the cursor is erased before
23648 actually scrolling, so we don't come here. When not
23649 scrolling, the rows above the old cursor row must have
23650 changed, and in this case these rows must have written
23651 over the cursor image.
23653 Likewise if part of the cursor is below y1, with the
23654 exception of the cursor being in the first blank row at
23655 the buffer and window end because update_text_area
23656 doesn't draw that row. (Except when it does, but
23657 that's handled in update_text_area.) */
23659 cy0
= w
->phys_cursor
.y
;
23660 cy1
= cy0
+ w
->phys_cursor_height
;
23661 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23664 w
->phys_cursor_on_p
= 0;
23667 #endif /* HAVE_WINDOW_SYSTEM */
23670 /************************************************************************
23672 ************************************************************************/
23674 #ifdef HAVE_WINDOW_SYSTEM
23677 Fix the display of area AREA of overlapping row ROW in window W
23678 with respect to the overlapping part OVERLAPS. */
23681 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
23682 enum glyph_row_area area
, int overlaps
)
23689 for (i
= 0; i
< row
->used
[area
];)
23691 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23693 int start
= i
, start_x
= x
;
23697 x
+= row
->glyphs
[area
][i
].pixel_width
;
23700 while (i
< row
->used
[area
]
23701 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23703 draw_glyphs (w
, start_x
, row
, area
,
23705 DRAW_NORMAL_TEXT
, overlaps
);
23709 x
+= row
->glyphs
[area
][i
].pixel_width
;
23719 Draw the cursor glyph of window W in glyph row ROW. See the
23720 comment of draw_glyphs for the meaning of HL. */
23723 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
23724 enum draw_glyphs_face hl
)
23726 /* If cursor hpos is out of bounds, don't draw garbage. This can
23727 happen in mini-buffer windows when switching between echo area
23728 glyphs and mini-buffer. */
23729 if ((row
->reversed_p
23730 ? (w
->phys_cursor
.hpos
>= 0)
23731 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
23733 int on_p
= w
->phys_cursor_on_p
;
23735 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23736 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23738 w
->phys_cursor_on_p
= on_p
;
23740 if (hl
== DRAW_CURSOR
)
23741 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23742 /* When we erase the cursor, and ROW is overlapped by other
23743 rows, make sure that these overlapping parts of other rows
23745 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23747 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23749 if (row
> w
->current_matrix
->rows
23750 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23751 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23752 OVERLAPS_ERASED_CURSOR
);
23754 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23755 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23756 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23757 OVERLAPS_ERASED_CURSOR
);
23764 Erase the image of a cursor of window W from the screen. */
23767 erase_phys_cursor (struct window
*w
)
23769 struct frame
*f
= XFRAME (w
->frame
);
23770 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23771 int hpos
= w
->phys_cursor
.hpos
;
23772 int vpos
= w
->phys_cursor
.vpos
;
23773 int mouse_face_here_p
= 0;
23774 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23775 struct glyph_row
*cursor_row
;
23776 struct glyph
*cursor_glyph
;
23777 enum draw_glyphs_face hl
;
23779 /* No cursor displayed or row invalidated => nothing to do on the
23781 if (w
->phys_cursor_type
== NO_CURSOR
)
23782 goto mark_cursor_off
;
23784 /* VPOS >= active_glyphs->nrows means that window has been resized.
23785 Don't bother to erase the cursor. */
23786 if (vpos
>= active_glyphs
->nrows
)
23787 goto mark_cursor_off
;
23789 /* If row containing cursor is marked invalid, there is nothing we
23791 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23792 if (!cursor_row
->enabled_p
)
23793 goto mark_cursor_off
;
23795 /* If line spacing is > 0, old cursor may only be partially visible in
23796 window after split-window. So adjust visible height. */
23797 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23798 window_text_bottom_y (w
) - cursor_row
->y
);
23800 /* If row is completely invisible, don't attempt to delete a cursor which
23801 isn't there. This can happen if cursor is at top of a window, and
23802 we switch to a buffer with a header line in that window. */
23803 if (cursor_row
->visible_height
<= 0)
23804 goto mark_cursor_off
;
23806 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23807 if (cursor_row
->cursor_in_fringe_p
)
23809 cursor_row
->cursor_in_fringe_p
= 0;
23810 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
23811 goto mark_cursor_off
;
23814 /* This can happen when the new row is shorter than the old one.
23815 In this case, either draw_glyphs or clear_end_of_line
23816 should have cleared the cursor. Note that we wouldn't be
23817 able to erase the cursor in this case because we don't have a
23818 cursor glyph at hand. */
23819 if ((cursor_row
->reversed_p
23820 ? (w
->phys_cursor
.hpos
< 0)
23821 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
23822 goto mark_cursor_off
;
23824 /* If the cursor is in the mouse face area, redisplay that when
23825 we clear the cursor. */
23826 if (! NILP (hlinfo
->mouse_face_window
)
23827 && coords_in_mouse_face_p (w
, hpos
, vpos
)
23828 /* Don't redraw the cursor's spot in mouse face if it is at the
23829 end of a line (on a newline). The cursor appears there, but
23830 mouse highlighting does not. */
23831 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
23832 mouse_face_here_p
= 1;
23834 /* Maybe clear the display under the cursor. */
23835 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23838 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23841 cursor_glyph
= get_phys_cursor_glyph (w
);
23842 if (cursor_glyph
== NULL
)
23843 goto mark_cursor_off
;
23845 width
= cursor_glyph
->pixel_width
;
23846 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23847 x
= w
->phys_cursor
.x
;
23849 width
-= left_x
- x
;
23850 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23851 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23852 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23855 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23858 /* Erase the cursor by redrawing the character underneath it. */
23859 if (mouse_face_here_p
)
23860 hl
= DRAW_MOUSE_FACE
;
23862 hl
= DRAW_NORMAL_TEXT
;
23863 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23866 w
->phys_cursor_on_p
= 0;
23867 w
->phys_cursor_type
= NO_CURSOR
;
23872 Display or clear cursor of window W. If ON is zero, clear the
23873 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23874 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23877 display_and_set_cursor (struct window
*w
, int on
,
23878 int hpos
, int vpos
, int x
, int y
)
23880 struct frame
*f
= XFRAME (w
->frame
);
23881 int new_cursor_type
;
23882 int new_cursor_width
;
23884 struct glyph_row
*glyph_row
;
23885 struct glyph
*glyph
;
23887 /* This is pointless on invisible frames, and dangerous on garbaged
23888 windows and frames; in the latter case, the frame or window may
23889 be in the midst of changing its size, and x and y may be off the
23891 if (! FRAME_VISIBLE_P (f
)
23892 || FRAME_GARBAGED_P (f
)
23893 || vpos
>= w
->current_matrix
->nrows
23894 || hpos
>= w
->current_matrix
->matrix_w
)
23897 /* If cursor is off and we want it off, return quickly. */
23898 if (!on
&& !w
->phys_cursor_on_p
)
23901 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23902 /* If cursor row is not enabled, we don't really know where to
23903 display the cursor. */
23904 if (!glyph_row
->enabled_p
)
23906 w
->phys_cursor_on_p
= 0;
23911 if (!glyph_row
->exact_window_width_line_p
23912 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
23913 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23915 xassert (interrupt_input_blocked
);
23917 /* Set new_cursor_type to the cursor we want to be displayed. */
23918 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23919 &new_cursor_width
, &active_cursor
);
23921 /* If cursor is currently being shown and we don't want it to be or
23922 it is in the wrong place, or the cursor type is not what we want,
23924 if (w
->phys_cursor_on_p
23926 || w
->phys_cursor
.x
!= x
23927 || w
->phys_cursor
.y
!= y
23928 || new_cursor_type
!= w
->phys_cursor_type
23929 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23930 && new_cursor_width
!= w
->phys_cursor_width
)))
23931 erase_phys_cursor (w
);
23933 /* Don't check phys_cursor_on_p here because that flag is only set
23934 to zero in some cases where we know that the cursor has been
23935 completely erased, to avoid the extra work of erasing the cursor
23936 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23937 still not be visible, or it has only been partly erased. */
23940 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23941 w
->phys_cursor_height
= glyph_row
->height
;
23943 /* Set phys_cursor_.* before x_draw_.* is called because some
23944 of them may need the information. */
23945 w
->phys_cursor
.x
= x
;
23946 w
->phys_cursor
.y
= glyph_row
->y
;
23947 w
->phys_cursor
.hpos
= hpos
;
23948 w
->phys_cursor
.vpos
= vpos
;
23951 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23952 new_cursor_type
, new_cursor_width
,
23953 on
, active_cursor
);
23957 /* Switch the display of W's cursor on or off, according to the value
23961 update_window_cursor (struct window
*w
, int on
)
23963 /* Don't update cursor in windows whose frame is in the process
23964 of being deleted. */
23965 if (w
->current_matrix
)
23968 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23969 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23975 /* Call update_window_cursor with parameter ON_P on all leaf windows
23976 in the window tree rooted at W. */
23979 update_cursor_in_window_tree (struct window
*w
, int on_p
)
23983 if (!NILP (w
->hchild
))
23984 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23985 else if (!NILP (w
->vchild
))
23986 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23988 update_window_cursor (w
, on_p
);
23990 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23996 Display the cursor on window W, or clear it, according to ON_P.
23997 Don't change the cursor's position. */
24000 x_update_cursor (struct frame
*f
, int on_p
)
24002 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24007 Clear the cursor of window W to background color, and mark the
24008 cursor as not shown. This is used when the text where the cursor
24009 is about to be rewritten. */
24012 x_clear_cursor (struct window
*w
)
24014 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24015 update_window_cursor (w
, 0);
24018 #endif /* HAVE_WINDOW_SYSTEM */
24020 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24023 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24024 int start_hpos
, int end_hpos
,
24025 enum draw_glyphs_face draw
)
24027 #ifdef HAVE_WINDOW_SYSTEM
24028 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24030 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24034 #if defined (HAVE_GPM) || defined (MSDOS)
24035 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24040 Display the active region described by mouse_face_* according to DRAW. */
24043 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24045 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24046 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24048 if (/* If window is in the process of being destroyed, don't bother
24050 w
->current_matrix
!= NULL
24051 /* Don't update mouse highlight if hidden */
24052 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24053 /* Recognize when we are called to operate on rows that don't exist
24054 anymore. This can happen when a window is split. */
24055 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24057 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24058 struct glyph_row
*row
, *first
, *last
;
24060 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24061 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24063 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24065 int start_hpos
, end_hpos
, start_x
;
24067 /* For all but the first row, the highlight starts at column 0. */
24070 /* R2L rows have BEG and END in reversed order, but the
24071 screen drawing geometry is always left to right. So
24072 we need to mirror the beginning and end of the
24073 highlighted area in R2L rows. */
24074 if (!row
->reversed_p
)
24076 start_hpos
= hlinfo
->mouse_face_beg_col
;
24077 start_x
= hlinfo
->mouse_face_beg_x
;
24079 else if (row
== last
)
24081 start_hpos
= hlinfo
->mouse_face_end_col
;
24082 start_x
= hlinfo
->mouse_face_end_x
;
24090 else if (row
->reversed_p
&& row
== last
)
24092 start_hpos
= hlinfo
->mouse_face_end_col
;
24093 start_x
= hlinfo
->mouse_face_end_x
;
24103 if (!row
->reversed_p
)
24104 end_hpos
= hlinfo
->mouse_face_end_col
;
24105 else if (row
== first
)
24106 end_hpos
= hlinfo
->mouse_face_beg_col
;
24109 end_hpos
= row
->used
[TEXT_AREA
];
24110 if (draw
== DRAW_NORMAL_TEXT
)
24111 row
->fill_line_p
= 1; /* Clear to end of line */
24114 else if (row
->reversed_p
&& row
== first
)
24115 end_hpos
= hlinfo
->mouse_face_beg_col
;
24118 end_hpos
= row
->used
[TEXT_AREA
];
24119 if (draw
== DRAW_NORMAL_TEXT
)
24120 row
->fill_line_p
= 1; /* Clear to end of line */
24123 if (end_hpos
> start_hpos
)
24125 draw_row_with_mouse_face (w
, start_x
, row
,
24126 start_hpos
, end_hpos
, draw
);
24129 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24133 #ifdef HAVE_WINDOW_SYSTEM
24134 /* When we've written over the cursor, arrange for it to
24135 be displayed again. */
24136 if (FRAME_WINDOW_P (f
)
24137 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24140 display_and_set_cursor (w
, 1,
24141 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24142 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24145 #endif /* HAVE_WINDOW_SYSTEM */
24148 #ifdef HAVE_WINDOW_SYSTEM
24149 /* Change the mouse cursor. */
24150 if (FRAME_WINDOW_P (f
))
24152 if (draw
== DRAW_NORMAL_TEXT
24153 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24154 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24155 else if (draw
== DRAW_MOUSE_FACE
)
24156 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24158 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24160 #endif /* HAVE_WINDOW_SYSTEM */
24164 Clear out the mouse-highlighted active region.
24165 Redraw it un-highlighted first. Value is non-zero if mouse
24166 face was actually drawn unhighlighted. */
24169 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24173 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24175 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24179 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24180 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24181 hlinfo
->mouse_face_window
= Qnil
;
24182 hlinfo
->mouse_face_overlay
= Qnil
;
24186 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24187 within the mouse face on that window. */
24189 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24191 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24193 /* Quickly resolve the easy cases. */
24194 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24195 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24197 if (vpos
< hlinfo
->mouse_face_beg_row
24198 || vpos
> hlinfo
->mouse_face_end_row
)
24200 if (vpos
> hlinfo
->mouse_face_beg_row
24201 && vpos
< hlinfo
->mouse_face_end_row
)
24204 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24206 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24208 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24211 else if ((vpos
== hlinfo
->mouse_face_beg_row
24212 && hpos
>= hlinfo
->mouse_face_beg_col
)
24213 || (vpos
== hlinfo
->mouse_face_end_row
24214 && hpos
< hlinfo
->mouse_face_end_col
))
24219 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24221 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24224 else if ((vpos
== hlinfo
->mouse_face_beg_row
24225 && hpos
<= hlinfo
->mouse_face_beg_col
)
24226 || (vpos
== hlinfo
->mouse_face_end_row
24227 && hpos
> hlinfo
->mouse_face_end_col
))
24235 Non-zero if physical cursor of window W is within mouse face. */
24238 cursor_in_mouse_face_p (struct window
*w
)
24240 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24245 /* Find the glyph rows START_ROW and END_ROW of window W that display
24246 characters between buffer positions START_CHARPOS and END_CHARPOS
24247 (excluding END_CHARPOS). This is similar to row_containing_pos,
24248 but is more accurate when bidi reordering makes buffer positions
24249 change non-linearly with glyph rows. */
24251 rows_from_pos_range (struct window
*w
,
24252 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24253 struct glyph_row
**start
, struct glyph_row
**end
)
24255 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24256 int last_y
= window_text_bottom_y (w
);
24257 struct glyph_row
*row
;
24262 while (!first
->enabled_p
24263 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24266 /* Find the START row. */
24268 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24271 /* A row can potentially be the START row if the range of the
24272 characters it displays intersects the range
24273 [START_CHARPOS..END_CHARPOS). */
24274 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24275 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24276 /* See the commentary in row_containing_pos, for the
24277 explanation of the complicated way to check whether
24278 some position is beyond the end of the characters
24279 displayed by a row. */
24280 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24281 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24282 && !row
->ends_at_zv_p
24283 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24284 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24285 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24286 && !row
->ends_at_zv_p
24287 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24289 /* Found a candidate row. Now make sure at least one of the
24290 glyphs it displays has a charpos from the range
24291 [START_CHARPOS..END_CHARPOS).
24293 This is not obvious because bidi reordering could make
24294 buffer positions of a row be 1,2,3,102,101,100, and if we
24295 want to highlight characters in [50..60), we don't want
24296 this row, even though [50..60) does intersect [1..103),
24297 the range of character positions given by the row's start
24298 and end positions. */
24299 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24300 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24304 if (BUFFERP (g
->object
)
24305 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24314 /* Find the END row. */
24316 /* If the last row is partially visible, start looking for END
24317 from that row, instead of starting from FIRST. */
24318 && !(row
->enabled_p
24319 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24321 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24323 struct glyph_row
*next
= row
+ 1;
24325 if (!next
->enabled_p
24326 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24327 /* The first row >= START whose range of displayed characters
24328 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24329 is the row END + 1. */
24330 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24331 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24332 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24333 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24334 && !next
->ends_at_zv_p
24335 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24336 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24337 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24338 && !next
->ends_at_zv_p
24339 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24346 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24347 but none of the characters it displays are in the range, it is
24349 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24350 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24354 if (BUFFERP (g
->object
)
24355 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24368 /* This function sets the mouse_face_* elements of HLINFO, assuming
24369 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24370 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24371 for the overlay or run of text properties specifying the mouse
24372 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24373 before-string and after-string that must also be highlighted.
24374 DISPLAY_STRING, if non-nil, is a display string that may cover some
24375 or all of the highlighted text. */
24378 mouse_face_from_buffer_pos (Lisp_Object window
,
24379 Mouse_HLInfo
*hlinfo
,
24380 EMACS_INT mouse_charpos
,
24381 EMACS_INT start_charpos
,
24382 EMACS_INT end_charpos
,
24383 Lisp_Object before_string
,
24384 Lisp_Object after_string
,
24385 Lisp_Object display_string
)
24387 struct window
*w
= XWINDOW (window
);
24388 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24389 struct glyph_row
*r1
, *r2
;
24390 struct glyph
*glyph
, *end
;
24391 EMACS_INT ignore
, pos
;
24394 xassert (NILP (display_string
) || STRINGP (display_string
));
24395 xassert (NILP (before_string
) || STRINGP (before_string
));
24396 xassert (NILP (after_string
) || STRINGP (after_string
));
24398 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
24399 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
24401 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24402 /* If the before-string or display-string contains newlines,
24403 rows_from_pos_range skips to its last row. Move back. */
24404 if (!NILP (before_string
) || !NILP (display_string
))
24406 struct glyph_row
*prev
;
24407 while ((prev
= r1
- 1, prev
>= first
)
24408 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
24409 && prev
->used
[TEXT_AREA
] > 0)
24411 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
24412 glyph
= beg
+ prev
->used
[TEXT_AREA
];
24413 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
24415 || !(EQ (glyph
->object
, before_string
)
24416 || EQ (glyph
->object
, display_string
)))
24423 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24424 hlinfo
->mouse_face_past_end
= 1;
24426 else if (!NILP (after_string
))
24428 /* If the after-string has newlines, advance to its last row. */
24429 struct glyph_row
*next
;
24430 struct glyph_row
*last
24431 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24433 for (next
= r2
+ 1;
24435 && next
->used
[TEXT_AREA
] > 0
24436 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
24440 /* The rest of the display engine assumes that mouse_face_beg_row is
24441 either above below mouse_face_end_row or identical to it. But
24442 with bidi-reordered continued lines, the row for START_CHARPOS
24443 could be below the row for END_CHARPOS. If so, swap the rows and
24444 store them in correct order. */
24447 struct glyph_row
*tem
= r2
;
24453 hlinfo
->mouse_face_beg_y
= r1
->y
;
24454 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
24455 hlinfo
->mouse_face_end_y
= r2
->y
;
24456 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
24458 /* For a bidi-reordered row, the positions of BEFORE_STRING,
24459 AFTER_STRING, DISPLAY_STRING, START_CHARPOS, and END_CHARPOS
24460 could be anywhere in the row and in any order. The strategy
24461 below is to find the leftmost and the rightmost glyph that
24462 belongs to either of these 3 strings, or whose position is
24463 between START_CHARPOS and END_CHARPOS, and highlight all the
24464 glyphs between those two. This may cover more than just the text
24465 between START_CHARPOS and END_CHARPOS if the range of characters
24466 strides the bidi level boundary, e.g. if the beginning is in R2L
24467 text while the end is in L2R text or vice versa. */
24468 if (!r1
->reversed_p
)
24470 /* This row is in a left to right paragraph. Scan it left to
24472 glyph
= r1
->glyphs
[TEXT_AREA
];
24473 end
= glyph
+ r1
->used
[TEXT_AREA
];
24476 /* Skip truncation glyphs at the start of the glyph row. */
24477 if (r1
->displays_text_p
)
24479 && INTEGERP (glyph
->object
)
24480 && glyph
->charpos
< 0;
24482 x
+= glyph
->pixel_width
;
24484 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24485 or DISPLAY_STRING, and the first glyph from buffer whose
24486 position is between START_CHARPOS and END_CHARPOS. */
24488 && !INTEGERP (glyph
->object
)
24489 && !EQ (glyph
->object
, display_string
)
24490 && !(BUFFERP (glyph
->object
)
24491 && (glyph
->charpos
>= start_charpos
24492 && glyph
->charpos
< end_charpos
));
24495 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24496 are present at buffer positions between START_CHARPOS and
24497 END_CHARPOS, or if they come from an overlay. */
24498 if (EQ (glyph
->object
, before_string
))
24500 pos
= string_buffer_position (w
, before_string
,
24502 /* If pos == 0, it means before_string came from an
24503 overlay, not from a buffer position. */
24504 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24507 else if (EQ (glyph
->object
, after_string
))
24509 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24510 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24513 x
+= glyph
->pixel_width
;
24515 hlinfo
->mouse_face_beg_x
= x
;
24516 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24520 /* This row is in a right to left paragraph. Scan it right to
24524 end
= r1
->glyphs
[TEXT_AREA
] - 1;
24525 glyph
= end
+ r1
->used
[TEXT_AREA
];
24527 /* Skip truncation glyphs at the start of the glyph row. */
24528 if (r1
->displays_text_p
)
24530 && INTEGERP (glyph
->object
)
24531 && glyph
->charpos
< 0;
24535 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24536 or DISPLAY_STRING, and the first glyph from buffer whose
24537 position is between START_CHARPOS and END_CHARPOS. */
24539 && !INTEGERP (glyph
->object
)
24540 && !EQ (glyph
->object
, display_string
)
24541 && !(BUFFERP (glyph
->object
)
24542 && (glyph
->charpos
>= start_charpos
24543 && glyph
->charpos
< end_charpos
));
24546 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24547 are present at buffer positions between START_CHARPOS and
24548 END_CHARPOS, or if they come from an overlay. */
24549 if (EQ (glyph
->object
, before_string
))
24551 pos
= string_buffer_position (w
, before_string
, start_charpos
);
24552 /* If pos == 0, it means before_string came from an
24553 overlay, not from a buffer position. */
24554 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24557 else if (EQ (glyph
->object
, after_string
))
24559 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24560 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24565 glyph
++; /* first glyph to the right of the highlighted area */
24566 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
24567 x
+= g
->pixel_width
;
24568 hlinfo
->mouse_face_beg_x
= x
;
24569 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24572 /* If the highlight ends in a different row, compute GLYPH and END
24573 for the end row. Otherwise, reuse the values computed above for
24574 the row where the highlight begins. */
24577 if (!r2
->reversed_p
)
24579 glyph
= r2
->glyphs
[TEXT_AREA
];
24580 end
= glyph
+ r2
->used
[TEXT_AREA
];
24585 end
= r2
->glyphs
[TEXT_AREA
] - 1;
24586 glyph
= end
+ r2
->used
[TEXT_AREA
];
24590 if (!r2
->reversed_p
)
24592 /* Skip truncation and continuation glyphs near the end of the
24593 row, and also blanks and stretch glyphs inserted by
24594 extend_face_to_end_of_line. */
24596 && INTEGERP ((end
- 1)->object
)
24597 && (end
- 1)->charpos
<= 0)
24599 /* Scan the rest of the glyph row from the end, looking for the
24600 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24601 DISPLAY_STRING, or whose position is between START_CHARPOS
24605 && !INTEGERP (end
->object
)
24606 && !EQ (end
->object
, display_string
)
24607 && !(BUFFERP (end
->object
)
24608 && (end
->charpos
>= start_charpos
24609 && end
->charpos
< end_charpos
));
24612 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24613 are present at buffer positions between START_CHARPOS and
24614 END_CHARPOS, or if they come from an overlay. */
24615 if (EQ (end
->object
, before_string
))
24617 pos
= string_buffer_position (w
, before_string
, start_charpos
);
24618 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24621 else if (EQ (end
->object
, after_string
))
24623 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24624 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24628 /* Find the X coordinate of the last glyph to be highlighted. */
24629 for (; glyph
<= end
; ++glyph
)
24630 x
+= glyph
->pixel_width
;
24632 hlinfo
->mouse_face_end_x
= x
;
24633 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
24637 /* Skip truncation and continuation glyphs near the end of the
24638 row, and also blanks and stretch glyphs inserted by
24639 extend_face_to_end_of_line. */
24643 && INTEGERP (end
->object
)
24644 && end
->charpos
<= 0)
24646 x
+= end
->pixel_width
;
24649 /* Scan the rest of the glyph row from the end, looking for the
24650 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24651 DISPLAY_STRING, or whose position is between START_CHARPOS
24655 && !INTEGERP (end
->object
)
24656 && !EQ (end
->object
, display_string
)
24657 && !(BUFFERP (end
->object
)
24658 && (end
->charpos
>= start_charpos
24659 && end
->charpos
< end_charpos
));
24662 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24663 are present at buffer positions between START_CHARPOS and
24664 END_CHARPOS, or if they come from an overlay. */
24665 if (EQ (end
->object
, before_string
))
24667 pos
= string_buffer_position (w
, before_string
, start_charpos
);
24668 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24671 else if (EQ (end
->object
, after_string
))
24673 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24674 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24677 x
+= end
->pixel_width
;
24679 hlinfo
->mouse_face_end_x
= x
;
24680 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
24683 hlinfo
->mouse_face_window
= window
;
24684 hlinfo
->mouse_face_face_id
24685 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
24687 !hlinfo
->mouse_face_hidden
, -1);
24688 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
24691 /* The following function is not used anymore (replaced with
24692 mouse_face_from_string_pos), but I leave it here for the time
24693 being, in case someone would. */
24695 #if 0 /* not used */
24697 /* Find the position of the glyph for position POS in OBJECT in
24698 window W's current matrix, and return in *X, *Y the pixel
24699 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
24701 RIGHT_P non-zero means return the position of the right edge of the
24702 glyph, RIGHT_P zero means return the left edge position.
24704 If no glyph for POS exists in the matrix, return the position of
24705 the glyph with the next smaller position that is in the matrix, if
24706 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
24707 exists in the matrix, return the position of the glyph with the
24708 next larger position in OBJECT.
24710 Value is non-zero if a glyph was found. */
24713 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
24714 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
24716 int yb
= window_text_bottom_y (w
);
24717 struct glyph_row
*r
;
24718 struct glyph
*best_glyph
= NULL
;
24719 struct glyph_row
*best_row
= NULL
;
24722 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24723 r
->enabled_p
&& r
->y
< yb
;
24726 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
24727 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
24730 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24731 if (EQ (g
->object
, object
))
24733 if (g
->charpos
== pos
)
24740 else if (best_glyph
== NULL
24741 || ((eabs (g
->charpos
- pos
)
24742 < eabs (best_glyph
->charpos
- pos
))
24745 : g
->charpos
> pos
)))
24759 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
24763 *x
+= best_glyph
->pixel_width
;
24768 *vpos
= best_row
- w
->current_matrix
->rows
;
24771 return best_glyph
!= NULL
;
24773 #endif /* not used */
24775 /* Find the positions of the first and the last glyphs in window W's
24776 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
24777 (assumed to be a string), and return in HLINFO's mouse_face_*
24778 members the pixel and column/row coordinates of those glyphs. */
24781 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
24782 Lisp_Object object
,
24783 EMACS_INT startpos
, EMACS_INT endpos
)
24785 int yb
= window_text_bottom_y (w
);
24786 struct glyph_row
*r
;
24787 struct glyph
*g
, *e
;
24791 /* Find the glyph row with at least one position in the range
24792 [STARTPOS..ENDPOS], and the first glyph in that row whose
24793 position belongs to that range. */
24794 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24795 r
->enabled_p
&& r
->y
< yb
;
24798 if (!r
->reversed_p
)
24800 g
= r
->glyphs
[TEXT_AREA
];
24801 e
= g
+ r
->used
[TEXT_AREA
];
24802 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24803 if (EQ (g
->object
, object
)
24804 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24806 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24807 hlinfo
->mouse_face_beg_y
= r
->y
;
24808 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24809 hlinfo
->mouse_face_beg_x
= gx
;
24818 e
= r
->glyphs
[TEXT_AREA
];
24819 g
= e
+ r
->used
[TEXT_AREA
];
24820 for ( ; g
> e
; --g
)
24821 if (EQ ((g
-1)->object
, object
)
24822 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
24824 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24825 hlinfo
->mouse_face_beg_y
= r
->y
;
24826 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24827 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
24828 gx
+= g1
->pixel_width
;
24829 hlinfo
->mouse_face_beg_x
= gx
;
24841 /* Starting with the next row, look for the first row which does NOT
24842 include any glyphs whose positions are in the range. */
24843 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
24845 g
= r
->glyphs
[TEXT_AREA
];
24846 e
= g
+ r
->used
[TEXT_AREA
];
24848 for ( ; g
< e
; ++g
)
24849 if (EQ (g
->object
, object
)
24850 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24859 /* The highlighted region ends on the previous row. */
24862 /* Set the end row and its vertical pixel coordinate. */
24863 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
24864 hlinfo
->mouse_face_end_y
= r
->y
;
24866 /* Compute and set the end column and the end column's horizontal
24867 pixel coordinate. */
24868 if (!r
->reversed_p
)
24870 g
= r
->glyphs
[TEXT_AREA
];
24871 e
= g
+ r
->used
[TEXT_AREA
];
24872 for ( ; e
> g
; --e
)
24873 if (EQ ((e
-1)->object
, object
)
24874 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
24876 hlinfo
->mouse_face_end_col
= e
- g
;
24878 for (gx
= r
->x
; g
< e
; ++g
)
24879 gx
+= g
->pixel_width
;
24880 hlinfo
->mouse_face_end_x
= gx
;
24884 e
= r
->glyphs
[TEXT_AREA
];
24885 g
= e
+ r
->used
[TEXT_AREA
];
24886 for (gx
= r
->x
; e
< g
; ++e
)
24888 if (EQ (e
->object
, object
)
24889 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
24891 gx
+= e
->pixel_width
;
24893 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
24894 hlinfo
->mouse_face_end_x
= gx
;
24898 #ifdef HAVE_WINDOW_SYSTEM
24900 /* See if position X, Y is within a hot-spot of an image. */
24903 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
24905 if (!CONSP (hot_spot
))
24908 if (EQ (XCAR (hot_spot
), Qrect
))
24910 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
24911 Lisp_Object rect
= XCDR (hot_spot
);
24915 if (!CONSP (XCAR (rect
)))
24917 if (!CONSP (XCDR (rect
)))
24919 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
24921 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
24923 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
24925 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
24929 else if (EQ (XCAR (hot_spot
), Qcircle
))
24931 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
24932 Lisp_Object circ
= XCDR (hot_spot
);
24933 Lisp_Object lr
, lx0
, ly0
;
24935 && CONSP (XCAR (circ
))
24936 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
24937 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
24938 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
24940 double r
= XFLOATINT (lr
);
24941 double dx
= XINT (lx0
) - x
;
24942 double dy
= XINT (ly0
) - y
;
24943 return (dx
* dx
+ dy
* dy
<= r
* r
);
24946 else if (EQ (XCAR (hot_spot
), Qpoly
))
24948 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
24949 if (VECTORP (XCDR (hot_spot
)))
24951 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
24952 Lisp_Object
*poly
= v
->contents
;
24956 Lisp_Object lx
, ly
;
24959 /* Need an even number of coordinates, and at least 3 edges. */
24960 if (n
< 6 || n
& 1)
24963 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
24964 If count is odd, we are inside polygon. Pixels on edges
24965 may or may not be included depending on actual geometry of the
24967 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
24968 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
24970 x0
= XINT (lx
), y0
= XINT (ly
);
24971 for (i
= 0; i
< n
; i
+= 2)
24973 int x1
= x0
, y1
= y0
;
24974 if ((lx
= poly
[i
], !INTEGERP (lx
))
24975 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
24977 x0
= XINT (lx
), y0
= XINT (ly
);
24979 /* Does this segment cross the X line? */
24987 if (y
> y0
&& y
> y1
)
24989 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
24999 find_hot_spot (Lisp_Object map
, int x
, int y
)
25001 while (CONSP (map
))
25003 if (CONSP (XCAR (map
))
25004 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25012 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25014 doc
: /* Lookup in image map MAP coordinates X and Y.
25015 An image map is an alist where each element has the format (AREA ID PLIST).
25016 An AREA is specified as either a rectangle, a circle, or a polygon:
25017 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25018 pixel coordinates of the upper left and bottom right corners.
25019 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25020 and the radius of the circle; r may be a float or integer.
25021 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25022 vector describes one corner in the polygon.
25023 Returns the alist element for the first matching AREA in MAP. */)
25024 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25032 return find_hot_spot (map
, XINT (x
), XINT (y
));
25036 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25038 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25040 /* Do not change cursor shape while dragging mouse. */
25041 if (!NILP (do_mouse_tracking
))
25044 if (!NILP (pointer
))
25046 if (EQ (pointer
, Qarrow
))
25047 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25048 else if (EQ (pointer
, Qhand
))
25049 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25050 else if (EQ (pointer
, Qtext
))
25051 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25052 else if (EQ (pointer
, intern ("hdrag")))
25053 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25054 #ifdef HAVE_X_WINDOWS
25055 else if (EQ (pointer
, intern ("vdrag")))
25056 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25058 else if (EQ (pointer
, intern ("hourglass")))
25059 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25060 else if (EQ (pointer
, Qmodeline
))
25061 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25063 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25066 if (cursor
!= No_Cursor
)
25067 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25070 #endif /* HAVE_WINDOW_SYSTEM */
25072 /* Take proper action when mouse has moved to the mode or header line
25073 or marginal area AREA of window W, x-position X and y-position Y.
25074 X is relative to the start of the text display area of W, so the
25075 width of bitmap areas and scroll bars must be subtracted to get a
25076 position relative to the start of the mode line. */
25079 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25080 enum window_part area
)
25082 struct window
*w
= XWINDOW (window
);
25083 struct frame
*f
= XFRAME (w
->frame
);
25084 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25085 #ifdef HAVE_WINDOW_SYSTEM
25086 Display_Info
*dpyinfo
;
25088 Cursor cursor
= No_Cursor
;
25089 Lisp_Object pointer
= Qnil
;
25090 int dx
, dy
, width
, height
;
25092 Lisp_Object string
, object
= Qnil
;
25093 Lisp_Object pos
, help
;
25095 Lisp_Object mouse_face
;
25096 int original_x_pixel
= x
;
25097 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25098 struct glyph_row
*row
;
25100 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25105 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25106 returns them in row/column units! */
25107 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25108 &object
, &dx
, &dy
, &width
, &height
);
25110 row
= (area
== ON_MODE_LINE
25111 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25112 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25114 /* Find the glyph under the mouse pointer. */
25115 if (row
->mode_line_p
&& row
->enabled_p
)
25117 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25118 end
= glyph
+ row
->used
[TEXT_AREA
];
25120 for (x0
= original_x_pixel
;
25121 glyph
< end
&& x0
>= glyph
->pixel_width
;
25123 x0
-= glyph
->pixel_width
;
25131 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25132 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25133 returns them in row/column units! */
25134 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25135 &object
, &dx
, &dy
, &width
, &height
);
25140 #ifdef HAVE_WINDOW_SYSTEM
25141 if (IMAGEP (object
))
25143 Lisp_Object image_map
, hotspot
;
25144 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25146 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25148 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25150 Lisp_Object area_id
, plist
;
25152 area_id
= XCAR (hotspot
);
25153 /* Could check AREA_ID to see if we enter/leave this hot-spot.
25154 If so, we could look for mouse-enter, mouse-leave
25155 properties in PLIST (and do something...). */
25156 hotspot
= XCDR (hotspot
);
25157 if (CONSP (hotspot
)
25158 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25160 pointer
= Fplist_get (plist
, Qpointer
);
25161 if (NILP (pointer
))
25163 help
= Fplist_get (plist
, Qhelp_echo
);
25166 help_echo_string
= help
;
25167 /* Is this correct? ++kfs */
25168 XSETWINDOW (help_echo_window
, w
);
25169 help_echo_object
= w
->buffer
;
25170 help_echo_pos
= charpos
;
25174 if (NILP (pointer
))
25175 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25177 #endif /* HAVE_WINDOW_SYSTEM */
25179 if (STRINGP (string
))
25181 pos
= make_number (charpos
);
25182 /* If we're on a string with `help-echo' text property, arrange
25183 for the help to be displayed. This is done by setting the
25184 global variable help_echo_string to the help string. */
25187 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25190 help_echo_string
= help
;
25191 XSETWINDOW (help_echo_window
, w
);
25192 help_echo_object
= string
;
25193 help_echo_pos
= charpos
;
25197 #ifdef HAVE_WINDOW_SYSTEM
25198 if (FRAME_WINDOW_P (f
))
25200 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25201 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25202 if (NILP (pointer
))
25203 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25205 /* Change the mouse pointer according to what is under X/Y. */
25207 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25210 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25211 if (!KEYMAPP (map
))
25212 map
= Fget_text_property (pos
, Qkeymap
, string
);
25213 if (!KEYMAPP (map
))
25214 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25219 /* Change the mouse face according to what is under X/Y. */
25220 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25221 if (!NILP (mouse_face
)
25222 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25227 struct glyph
* tmp_glyph
;
25231 int total_pixel_width
;
25232 EMACS_INT begpos
, endpos
, ignore
;
25236 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25237 Qmouse_face
, string
, Qnil
);
25243 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25245 endpos
= SCHARS (string
);
25249 /* Calculate the glyph position GPOS of GLYPH in the
25250 displayed string, relative to the beginning of the
25251 highlighted part of the string.
25253 Note: GPOS is different from CHARPOS. CHARPOS is the
25254 position of GLYPH in the internal string object. A mode
25255 line string format has structures which are converted to
25256 a flattened string by the Emacs Lisp interpreter. The
25257 internal string is an element of those structures. The
25258 displayed string is the flattened string. */
25259 tmp_glyph
= row_start_glyph
;
25260 while (tmp_glyph
< glyph
25261 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25262 && begpos
<= tmp_glyph
->charpos
25263 && tmp_glyph
->charpos
< endpos
)))
25265 gpos
= glyph
- tmp_glyph
;
25267 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25268 the highlighted part of the displayed string to which
25269 GLYPH belongs. Note: GSEQ_LENGTH is different from
25270 SCHARS (STRING), because the latter returns the length of
25271 the internal string. */
25272 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25274 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25275 && begpos
<= tmp_glyph
->charpos
25276 && tmp_glyph
->charpos
< endpos
));
25279 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25281 /* Calculate the total pixel width of all the glyphs between
25282 the beginning of the highlighted area and GLYPH. */
25283 total_pixel_width
= 0;
25284 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25285 total_pixel_width
+= tmp_glyph
->pixel_width
;
25287 /* Pre calculation of re-rendering position. Note: X is in
25288 column units here, after the call to mode_line_string or
25289 marginal_area_string. */
25291 vpos
= (area
== ON_MODE_LINE
25292 ? (w
->current_matrix
)->nrows
- 1
25295 /* If GLYPH's position is included in the region that is
25296 already drawn in mouse face, we have nothing to do. */
25297 if ( EQ (window
, hlinfo
->mouse_face_window
)
25298 && (!row
->reversed_p
25299 ? (hlinfo
->mouse_face_beg_col
<= hpos
25300 && hpos
< hlinfo
->mouse_face_end_col
)
25301 /* In R2L rows we swap BEG and END, see below. */
25302 : (hlinfo
->mouse_face_end_col
<= hpos
25303 && hpos
< hlinfo
->mouse_face_beg_col
))
25304 && hlinfo
->mouse_face_beg_row
== vpos
)
25307 if (clear_mouse_face (hlinfo
))
25308 cursor
= No_Cursor
;
25310 if (!row
->reversed_p
)
25312 hlinfo
->mouse_face_beg_col
= hpos
;
25313 hlinfo
->mouse_face_beg_x
= original_x_pixel
25314 - (total_pixel_width
+ dx
);
25315 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25316 hlinfo
->mouse_face_end_x
= 0;
25320 /* In R2L rows, show_mouse_face expects BEG and END
25321 coordinates to be swapped. */
25322 hlinfo
->mouse_face_end_col
= hpos
;
25323 hlinfo
->mouse_face_end_x
= original_x_pixel
25324 - (total_pixel_width
+ dx
);
25325 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25326 hlinfo
->mouse_face_beg_x
= 0;
25329 hlinfo
->mouse_face_beg_row
= vpos
;
25330 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25331 hlinfo
->mouse_face_beg_y
= 0;
25332 hlinfo
->mouse_face_end_y
= 0;
25333 hlinfo
->mouse_face_past_end
= 0;
25334 hlinfo
->mouse_face_window
= window
;
25336 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25342 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25344 if (NILP (pointer
))
25347 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25348 clear_mouse_face (hlinfo
);
25350 #ifdef HAVE_WINDOW_SYSTEM
25351 if (FRAME_WINDOW_P (f
))
25352 define_frame_cursor1 (f
, cursor
, pointer
);
25358 Take proper action when the mouse has moved to position X, Y on
25359 frame F as regards highlighting characters that have mouse-face
25360 properties. Also de-highlighting chars where the mouse was before.
25361 X and Y can be negative or out of range. */
25364 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25366 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25367 enum window_part part
;
25368 Lisp_Object window
;
25370 Cursor cursor
= No_Cursor
;
25371 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25374 /* When a menu is active, don't highlight because this looks odd. */
25375 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25376 if (popup_activated ())
25380 if (NILP (Vmouse_highlight
)
25381 || !f
->glyphs_initialized_p
25382 || f
->pointer_invisible
)
25385 hlinfo
->mouse_face_mouse_x
= x
;
25386 hlinfo
->mouse_face_mouse_y
= y
;
25387 hlinfo
->mouse_face_mouse_frame
= f
;
25389 if (hlinfo
->mouse_face_defer
)
25392 if (gc_in_progress
)
25394 hlinfo
->mouse_face_deferred_gc
= 1;
25398 /* Which window is that in? */
25399 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
25401 /* If we were displaying active text in another window, clear that.
25402 Also clear if we move out of text area in same window. */
25403 if (! EQ (window
, hlinfo
->mouse_face_window
)
25404 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
25405 && !NILP (hlinfo
->mouse_face_window
)))
25406 clear_mouse_face (hlinfo
);
25408 /* Not on a window -> return. */
25409 if (!WINDOWP (window
))
25412 /* Reset help_echo_string. It will get recomputed below. */
25413 help_echo_string
= Qnil
;
25415 /* Convert to window-relative pixel coordinates. */
25416 w
= XWINDOW (window
);
25417 frame_to_window_pixel_xy (w
, &x
, &y
);
25419 #ifdef HAVE_WINDOW_SYSTEM
25420 /* Handle tool-bar window differently since it doesn't display a
25422 if (EQ (window
, f
->tool_bar_window
))
25424 note_tool_bar_highlight (f
, x
, y
);
25429 /* Mouse is on the mode, header line or margin? */
25430 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
25431 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
25433 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
25437 #ifdef HAVE_WINDOW_SYSTEM
25438 if (part
== ON_VERTICAL_BORDER
)
25440 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25441 help_echo_string
= build_string ("drag-mouse-1: resize");
25443 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
25444 || part
== ON_SCROLL_BAR
)
25445 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25447 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25450 /* Are we in a window whose display is up to date?
25451 And verify the buffer's text has not changed. */
25452 b
= XBUFFER (w
->buffer
);
25453 if (part
== ON_TEXT
25454 && EQ (w
->window_end_valid
, w
->buffer
)
25455 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
25456 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
25458 int hpos
, vpos
, i
, dx
, dy
, area
;
25460 struct glyph
*glyph
;
25461 Lisp_Object object
;
25462 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
25463 Lisp_Object
*overlay_vec
= NULL
;
25465 struct buffer
*obuf
;
25466 EMACS_INT obegv
, ozv
;
25469 /* Find the glyph under X/Y. */
25470 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
25472 #ifdef HAVE_WINDOW_SYSTEM
25473 /* Look for :pointer property on image. */
25474 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25476 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25477 if (img
!= NULL
&& IMAGEP (img
->spec
))
25479 Lisp_Object image_map
, hotspot
;
25480 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
25482 && (hotspot
= find_hot_spot (image_map
,
25483 glyph
->slice
.img
.x
+ dx
,
25484 glyph
->slice
.img
.y
+ dy
),
25486 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25488 Lisp_Object area_id
, plist
;
25490 area_id
= XCAR (hotspot
);
25491 /* Could check AREA_ID to see if we enter/leave this hot-spot.
25492 If so, we could look for mouse-enter, mouse-leave
25493 properties in PLIST (and do something...). */
25494 hotspot
= XCDR (hotspot
);
25495 if (CONSP (hotspot
)
25496 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25498 pointer
= Fplist_get (plist
, Qpointer
);
25499 if (NILP (pointer
))
25501 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
25502 if (!NILP (help_echo_string
))
25504 help_echo_window
= window
;
25505 help_echo_object
= glyph
->object
;
25506 help_echo_pos
= glyph
->charpos
;
25510 if (NILP (pointer
))
25511 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
25514 #endif /* HAVE_WINDOW_SYSTEM */
25516 /* Clear mouse face if X/Y not over text. */
25518 || area
!= TEXT_AREA
25519 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
25520 /* Glyph's OBJECT is an integer for glyphs inserted by the
25521 display engine for its internal purposes, like truncation
25522 and continuation glyphs and blanks beyond the end of
25523 line's text on text terminals. If we are over such a
25524 glyph, we are not over any text. */
25525 || INTEGERP (glyph
->object
)
25526 /* R2L rows have a stretch glyph at their front, which
25527 stands for no text, whereas L2R rows have no glyphs at
25528 all beyond the end of text. Treat such stretch glyphs
25529 like we do with NULL glyphs in L2R rows. */
25530 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
25531 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
25532 && glyph
->type
== STRETCH_GLYPH
25533 && glyph
->avoid_cursor_p
))
25535 if (clear_mouse_face (hlinfo
))
25536 cursor
= No_Cursor
;
25537 #ifdef HAVE_WINDOW_SYSTEM
25538 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25540 if (area
!= TEXT_AREA
)
25541 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25543 pointer
= Vvoid_text_area_pointer
;
25549 pos
= glyph
->charpos
;
25550 object
= glyph
->object
;
25551 if (!STRINGP (object
) && !BUFFERP (object
))
25554 /* If we get an out-of-range value, return now; avoid an error. */
25555 if (BUFFERP (object
) && pos
> BUF_Z (b
))
25558 /* Make the window's buffer temporarily current for
25559 overlays_at and compute_char_face. */
25560 obuf
= current_buffer
;
25561 current_buffer
= b
;
25567 /* Is this char mouse-active or does it have help-echo? */
25568 position
= make_number (pos
);
25570 if (BUFFERP (object
))
25572 /* Put all the overlays we want in a vector in overlay_vec. */
25573 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
25574 /* Sort overlays into increasing priority order. */
25575 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
25580 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
25583 cursor
= No_Cursor
;
25585 /* Check mouse-face highlighting. */
25587 /* If there exists an overlay with mouse-face overlapping
25588 the one we are currently highlighting, we have to
25589 check if we enter the overlapping overlay, and then
25590 highlight only that. */
25591 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
25592 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
25594 /* Find the highest priority overlay with a mouse-face. */
25596 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
25598 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
25599 if (!NILP (mouse_face
))
25600 overlay
= overlay_vec
[i
];
25603 /* If we're highlighting the same overlay as before, there's
25604 no need to do that again. */
25605 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
25606 goto check_help_echo
;
25607 hlinfo
->mouse_face_overlay
= overlay
;
25609 /* Clear the display of the old active region, if any. */
25610 if (clear_mouse_face (hlinfo
))
25611 cursor
= No_Cursor
;
25613 /* If no overlay applies, get a text property. */
25614 if (NILP (overlay
))
25615 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
25617 /* Next, compute the bounds of the mouse highlighting and
25619 if (!NILP (mouse_face
) && STRINGP (object
))
25621 /* The mouse-highlighting comes from a display string
25622 with a mouse-face. */
25626 b
= Fprevious_single_property_change
25627 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
25628 e
= Fnext_single_property_change
25629 (position
, Qmouse_face
, object
, Qnil
);
25631 b
= make_number (0);
25633 e
= make_number (SCHARS (object
) - 1);
25634 mouse_face_from_string_pos (w
, hlinfo
, object
,
25635 XINT (b
), XINT (e
));
25636 hlinfo
->mouse_face_past_end
= 0;
25637 hlinfo
->mouse_face_window
= window
;
25638 hlinfo
->mouse_face_face_id
25639 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
25640 glyph
->face_id
, 1);
25641 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25642 cursor
= No_Cursor
;
25646 /* The mouse-highlighting, if any, comes from an overlay
25647 or text property in the buffer. */
25648 Lisp_Object buffer
, display_string
;
25650 if (STRINGP (object
))
25652 /* If we are on a display string with no mouse-face,
25653 check if the text under it has one. */
25654 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
25655 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25656 pos
= string_buffer_position (w
, object
, start
);
25659 mouse_face
= get_char_property_and_overlay
25660 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
25661 buffer
= w
->buffer
;
25662 display_string
= object
;
25668 display_string
= Qnil
;
25671 if (!NILP (mouse_face
))
25673 Lisp_Object before
, after
;
25674 Lisp_Object before_string
, after_string
;
25675 /* To correctly find the limits of mouse highlight
25676 in a bidi-reordered buffer, we must not use the
25677 optimization of limiting the search in
25678 previous-single-property-change and
25679 next-single-property-change, because
25680 rows_from_pos_range needs the real start and end
25681 positions to DTRT in this case. That's because
25682 the first row visible in a window does not
25683 necessarily display the character whose position
25684 is the smallest. */
25686 NILP (XBUFFER (buffer
)->bidi_display_reordering
)
25687 ? Fmarker_position (w
->start
)
25690 NILP (XBUFFER (buffer
)->bidi_display_reordering
)
25691 ? make_number (BUF_Z (XBUFFER (buffer
))
25692 - XFASTINT (w
->window_end_pos
))
25695 if (NILP (overlay
))
25697 /* Handle the text property case. */
25698 before
= Fprevious_single_property_change
25699 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
25700 after
= Fnext_single_property_change
25701 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
25702 before_string
= after_string
= Qnil
;
25706 /* Handle the overlay case. */
25707 before
= Foverlay_start (overlay
);
25708 after
= Foverlay_end (overlay
);
25709 before_string
= Foverlay_get (overlay
, Qbefore_string
);
25710 after_string
= Foverlay_get (overlay
, Qafter_string
);
25712 if (!STRINGP (before_string
)) before_string
= Qnil
;
25713 if (!STRINGP (after_string
)) after_string
= Qnil
;
25716 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
25719 before_string
, after_string
,
25721 cursor
= No_Cursor
;
25728 /* Look for a `help-echo' property. */
25729 if (NILP (help_echo_string
)) {
25730 Lisp_Object help
, overlay
;
25732 /* Check overlays first. */
25733 help
= overlay
= Qnil
;
25734 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
25736 overlay
= overlay_vec
[i
];
25737 help
= Foverlay_get (overlay
, Qhelp_echo
);
25742 help_echo_string
= help
;
25743 help_echo_window
= window
;
25744 help_echo_object
= overlay
;
25745 help_echo_pos
= pos
;
25749 Lisp_Object object
= glyph
->object
;
25750 EMACS_INT charpos
= glyph
->charpos
;
25752 /* Try text properties. */
25753 if (STRINGP (object
)
25755 && charpos
< SCHARS (object
))
25757 help
= Fget_text_property (make_number (charpos
),
25758 Qhelp_echo
, object
);
25761 /* If the string itself doesn't specify a help-echo,
25762 see if the buffer text ``under'' it does. */
25763 struct glyph_row
*r
25764 = MATRIX_ROW (w
->current_matrix
, vpos
);
25765 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25766 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
25769 help
= Fget_char_property (make_number (pos
),
25770 Qhelp_echo
, w
->buffer
);
25774 object
= w
->buffer
;
25779 else if (BUFFERP (object
)
25782 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
25787 help_echo_string
= help
;
25788 help_echo_window
= window
;
25789 help_echo_object
= object
;
25790 help_echo_pos
= charpos
;
25795 #ifdef HAVE_WINDOW_SYSTEM
25796 /* Look for a `pointer' property. */
25797 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25799 /* Check overlays first. */
25800 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
25801 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
25803 if (NILP (pointer
))
25805 Lisp_Object object
= glyph
->object
;
25806 EMACS_INT charpos
= glyph
->charpos
;
25808 /* Try text properties. */
25809 if (STRINGP (object
)
25811 && charpos
< SCHARS (object
))
25813 pointer
= Fget_text_property (make_number (charpos
),
25815 if (NILP (pointer
))
25817 /* If the string itself doesn't specify a pointer,
25818 see if the buffer text ``under'' it does. */
25819 struct glyph_row
*r
25820 = MATRIX_ROW (w
->current_matrix
, vpos
);
25821 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25822 EMACS_INT pos
= string_buffer_position (w
, object
,
25825 pointer
= Fget_char_property (make_number (pos
),
25826 Qpointer
, w
->buffer
);
25829 else if (BUFFERP (object
)
25832 pointer
= Fget_text_property (make_number (charpos
),
25836 #endif /* HAVE_WINDOW_SYSTEM */
25840 current_buffer
= obuf
;
25845 #ifdef HAVE_WINDOW_SYSTEM
25846 if (FRAME_WINDOW_P (f
))
25847 define_frame_cursor1 (f
, cursor
, pointer
);
25849 /* This is here to prevent a compiler error, about "label at end of
25850 compound statement". */
25857 Clear any mouse-face on window W. This function is part of the
25858 redisplay interface, and is called from try_window_id and similar
25859 functions to ensure the mouse-highlight is off. */
25862 x_clear_window_mouse_face (struct window
*w
)
25864 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25865 Lisp_Object window
;
25868 XSETWINDOW (window
, w
);
25869 if (EQ (window
, hlinfo
->mouse_face_window
))
25870 clear_mouse_face (hlinfo
);
25876 Just discard the mouse face information for frame F, if any.
25877 This is used when the size of F is changed. */
25880 cancel_mouse_face (struct frame
*f
)
25882 Lisp_Object window
;
25883 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25885 window
= hlinfo
->mouse_face_window
;
25886 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
25888 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25889 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25890 hlinfo
->mouse_face_window
= Qnil
;
25896 /***********************************************************************
25898 ***********************************************************************/
25900 #ifdef HAVE_WINDOW_SYSTEM
25902 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
25903 which intersects rectangle R. R is in window-relative coordinates. */
25906 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
25907 enum glyph_row_area area
)
25909 struct glyph
*first
= row
->glyphs
[area
];
25910 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
25911 struct glyph
*last
;
25912 int first_x
, start_x
, x
;
25914 if (area
== TEXT_AREA
&& row
->fill_line_p
)
25915 /* If row extends face to end of line write the whole line. */
25916 draw_glyphs (w
, 0, row
, area
,
25917 0, row
->used
[area
],
25918 DRAW_NORMAL_TEXT
, 0);
25921 /* Set START_X to the window-relative start position for drawing glyphs of
25922 AREA. The first glyph of the text area can be partially visible.
25923 The first glyphs of other areas cannot. */
25924 start_x
= window_box_left_offset (w
, area
);
25926 if (area
== TEXT_AREA
)
25929 /* Find the first glyph that must be redrawn. */
25931 && x
+ first
->pixel_width
< r
->x
)
25933 x
+= first
->pixel_width
;
25937 /* Find the last one. */
25941 && x
< r
->x
+ r
->width
)
25943 x
+= last
->pixel_width
;
25949 draw_glyphs (w
, first_x
- start_x
, row
, area
,
25950 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
25951 DRAW_NORMAL_TEXT
, 0);
25956 /* Redraw the parts of the glyph row ROW on window W intersecting
25957 rectangle R. R is in window-relative coordinates. Value is
25958 non-zero if mouse-face was overwritten. */
25961 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
25963 xassert (row
->enabled_p
);
25965 if (row
->mode_line_p
|| w
->pseudo_window_p
)
25966 draw_glyphs (w
, 0, row
, TEXT_AREA
,
25967 0, row
->used
[TEXT_AREA
],
25968 DRAW_NORMAL_TEXT
, 0);
25971 if (row
->used
[LEFT_MARGIN_AREA
])
25972 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
25973 if (row
->used
[TEXT_AREA
])
25974 expose_area (w
, row
, r
, TEXT_AREA
);
25975 if (row
->used
[RIGHT_MARGIN_AREA
])
25976 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
25977 draw_row_fringe_bitmaps (w
, row
);
25980 return row
->mouse_face_p
;
25984 /* Redraw those parts of glyphs rows during expose event handling that
25985 overlap other rows. Redrawing of an exposed line writes over parts
25986 of lines overlapping that exposed line; this function fixes that.
25988 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
25989 row in W's current matrix that is exposed and overlaps other rows.
25990 LAST_OVERLAPPING_ROW is the last such row. */
25993 expose_overlaps (struct window
*w
,
25994 struct glyph_row
*first_overlapping_row
,
25995 struct glyph_row
*last_overlapping_row
,
25998 struct glyph_row
*row
;
26000 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26001 if (row
->overlapping_p
)
26003 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26006 if (row
->used
[LEFT_MARGIN_AREA
])
26007 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26009 if (row
->used
[TEXT_AREA
])
26010 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26012 if (row
->used
[RIGHT_MARGIN_AREA
])
26013 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26019 /* Return non-zero if W's cursor intersects rectangle R. */
26022 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26024 XRectangle cr
, result
;
26025 struct glyph
*cursor_glyph
;
26026 struct glyph_row
*row
;
26028 if (w
->phys_cursor
.vpos
>= 0
26029 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26030 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26032 && row
->cursor_in_fringe_p
)
26034 /* Cursor is in the fringe. */
26035 cr
.x
= window_box_right_offset (w
,
26036 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26037 ? RIGHT_MARGIN_AREA
26040 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26041 cr
.height
= row
->height
;
26042 return x_intersect_rectangles (&cr
, r
, &result
);
26045 cursor_glyph
= get_phys_cursor_glyph (w
);
26048 /* r is relative to W's box, but w->phys_cursor.x is relative
26049 to left edge of W's TEXT area. Adjust it. */
26050 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26051 cr
.y
= w
->phys_cursor
.y
;
26052 cr
.width
= cursor_glyph
->pixel_width
;
26053 cr
.height
= w
->phys_cursor_height
;
26054 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26055 I assume the effect is the same -- and this is portable. */
26056 return x_intersect_rectangles (&cr
, r
, &result
);
26058 /* If we don't understand the format, pretend we're not in the hot-spot. */
26064 Draw a vertical window border to the right of window W if W doesn't
26065 have vertical scroll bars. */
26068 x_draw_vertical_border (struct window
*w
)
26070 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26072 /* We could do better, if we knew what type of scroll-bar the adjacent
26073 windows (on either side) have... But we don't :-(
26074 However, I think this works ok. ++KFS 2003-04-25 */
26076 /* Redraw borders between horizontally adjacent windows. Don't
26077 do it for frames with vertical scroll bars because either the
26078 right scroll bar of a window, or the left scroll bar of its
26079 neighbor will suffice as a border. */
26080 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26083 if (!WINDOW_RIGHTMOST_P (w
)
26084 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26086 int x0
, x1
, y0
, y1
;
26088 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26091 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26094 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26096 else if (!WINDOW_LEFTMOST_P (w
)
26097 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26099 int x0
, x1
, y0
, y1
;
26101 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26104 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26107 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26112 /* Redraw the part of window W intersection rectangle FR. Pixel
26113 coordinates in FR are frame-relative. Call this function with
26114 input blocked. Value is non-zero if the exposure overwrites
26118 expose_window (struct window
*w
, XRectangle
*fr
)
26120 struct frame
*f
= XFRAME (w
->frame
);
26122 int mouse_face_overwritten_p
= 0;
26124 /* If window is not yet fully initialized, do nothing. This can
26125 happen when toolkit scroll bars are used and a window is split.
26126 Reconfiguring the scroll bar will generate an expose for a newly
26128 if (w
->current_matrix
== NULL
)
26131 /* When we're currently updating the window, display and current
26132 matrix usually don't agree. Arrange for a thorough display
26134 if (w
== updated_window
)
26136 SET_FRAME_GARBAGED (f
);
26140 /* Frame-relative pixel rectangle of W. */
26141 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26142 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26143 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26144 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26146 if (x_intersect_rectangles (fr
, &wr
, &r
))
26148 int yb
= window_text_bottom_y (w
);
26149 struct glyph_row
*row
;
26150 int cursor_cleared_p
;
26151 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26153 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26154 r
.x
, r
.y
, r
.width
, r
.height
));
26156 /* Convert to window coordinates. */
26157 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26158 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26160 /* Turn off the cursor. */
26161 if (!w
->pseudo_window_p
26162 && phys_cursor_in_rect_p (w
, &r
))
26164 x_clear_cursor (w
);
26165 cursor_cleared_p
= 1;
26168 cursor_cleared_p
= 0;
26170 /* Update lines intersecting rectangle R. */
26171 first_overlapping_row
= last_overlapping_row
= NULL
;
26172 for (row
= w
->current_matrix
->rows
;
26177 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26179 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26180 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26181 || (r
.y
>= y0
&& r
.y
< y1
)
26182 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26184 /* A header line may be overlapping, but there is no need
26185 to fix overlapping areas for them. KFS 2005-02-12 */
26186 if (row
->overlapping_p
&& !row
->mode_line_p
)
26188 if (first_overlapping_row
== NULL
)
26189 first_overlapping_row
= row
;
26190 last_overlapping_row
= row
;
26194 if (expose_line (w
, row
, &r
))
26195 mouse_face_overwritten_p
= 1;
26198 else if (row
->overlapping_p
)
26200 /* We must redraw a row overlapping the exposed area. */
26202 ? y0
+ row
->phys_height
> r
.y
26203 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26205 if (first_overlapping_row
== NULL
)
26206 first_overlapping_row
= row
;
26207 last_overlapping_row
= row
;
26215 /* Display the mode line if there is one. */
26216 if (WINDOW_WANTS_MODELINE_P (w
)
26217 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26219 && row
->y
< r
.y
+ r
.height
)
26221 if (expose_line (w
, row
, &r
))
26222 mouse_face_overwritten_p
= 1;
26225 if (!w
->pseudo_window_p
)
26227 /* Fix the display of overlapping rows. */
26228 if (first_overlapping_row
)
26229 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26232 /* Draw border between windows. */
26233 x_draw_vertical_border (w
);
26235 /* Turn the cursor on again. */
26236 if (cursor_cleared_p
)
26237 update_window_cursor (w
, 1);
26241 return mouse_face_overwritten_p
;
26246 /* Redraw (parts) of all windows in the window tree rooted at W that
26247 intersect R. R contains frame pixel coordinates. Value is
26248 non-zero if the exposure overwrites mouse-face. */
26251 expose_window_tree (struct window
*w
, XRectangle
*r
)
26253 struct frame
*f
= XFRAME (w
->frame
);
26254 int mouse_face_overwritten_p
= 0;
26256 while (w
&& !FRAME_GARBAGED_P (f
))
26258 if (!NILP (w
->hchild
))
26259 mouse_face_overwritten_p
26260 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26261 else if (!NILP (w
->vchild
))
26262 mouse_face_overwritten_p
26263 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26265 mouse_face_overwritten_p
|= expose_window (w
, r
);
26267 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26270 return mouse_face_overwritten_p
;
26275 Redisplay an exposed area of frame F. X and Y are the upper-left
26276 corner of the exposed rectangle. W and H are width and height of
26277 the exposed area. All are pixel values. W or H zero means redraw
26278 the entire frame. */
26281 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26284 int mouse_face_overwritten_p
= 0;
26286 TRACE ((stderr
, "expose_frame "));
26288 /* No need to redraw if frame will be redrawn soon. */
26289 if (FRAME_GARBAGED_P (f
))
26291 TRACE ((stderr
, " garbaged\n"));
26295 /* If basic faces haven't been realized yet, there is no point in
26296 trying to redraw anything. This can happen when we get an expose
26297 event while Emacs is starting, e.g. by moving another window. */
26298 if (FRAME_FACE_CACHE (f
) == NULL
26299 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26301 TRACE ((stderr
, " no faces\n"));
26305 if (w
== 0 || h
== 0)
26308 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26309 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26319 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26320 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26322 if (WINDOWP (f
->tool_bar_window
))
26323 mouse_face_overwritten_p
26324 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26326 #ifdef HAVE_X_WINDOWS
26328 #ifndef USE_X_TOOLKIT
26329 if (WINDOWP (f
->menu_bar_window
))
26330 mouse_face_overwritten_p
26331 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26332 #endif /* not USE_X_TOOLKIT */
26336 /* Some window managers support a focus-follows-mouse style with
26337 delayed raising of frames. Imagine a partially obscured frame,
26338 and moving the mouse into partially obscured mouse-face on that
26339 frame. The visible part of the mouse-face will be highlighted,
26340 then the WM raises the obscured frame. With at least one WM, KDE
26341 2.1, Emacs is not getting any event for the raising of the frame
26342 (even tried with SubstructureRedirectMask), only Expose events.
26343 These expose events will draw text normally, i.e. not
26344 highlighted. Which means we must redo the highlight here.
26345 Subsume it under ``we love X''. --gerd 2001-08-15 */
26346 /* Included in Windows version because Windows most likely does not
26347 do the right thing if any third party tool offers
26348 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26349 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26351 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26352 if (f
== hlinfo
->mouse_face_mouse_frame
)
26354 int x
= hlinfo
->mouse_face_mouse_x
;
26355 int y
= hlinfo
->mouse_face_mouse_y
;
26356 clear_mouse_face (hlinfo
);
26357 note_mouse_highlight (f
, x
, y
);
26364 Determine the intersection of two rectangles R1 and R2. Return
26365 the intersection in *RESULT. Value is non-zero if RESULT is not
26369 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26371 XRectangle
*left
, *right
;
26372 XRectangle
*upper
, *lower
;
26373 int intersection_p
= 0;
26375 /* Rearrange so that R1 is the left-most rectangle. */
26377 left
= r1
, right
= r2
;
26379 left
= r2
, right
= r1
;
26381 /* X0 of the intersection is right.x0, if this is inside R1,
26382 otherwise there is no intersection. */
26383 if (right
->x
<= left
->x
+ left
->width
)
26385 result
->x
= right
->x
;
26387 /* The right end of the intersection is the minimum of the
26388 the right ends of left and right. */
26389 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26392 /* Same game for Y. */
26394 upper
= r1
, lower
= r2
;
26396 upper
= r2
, lower
= r1
;
26398 /* The upper end of the intersection is lower.y0, if this is inside
26399 of upper. Otherwise, there is no intersection. */
26400 if (lower
->y
<= upper
->y
+ upper
->height
)
26402 result
->y
= lower
->y
;
26404 /* The lower end of the intersection is the minimum of the lower
26405 ends of upper and lower. */
26406 result
->height
= (min (lower
->y
+ lower
->height
,
26407 upper
->y
+ upper
->height
)
26409 intersection_p
= 1;
26413 return intersection_p
;
26416 #endif /* HAVE_WINDOW_SYSTEM */
26419 /***********************************************************************
26421 ***********************************************************************/
26424 syms_of_xdisp (void)
26426 Vwith_echo_area_save_vector
= Qnil
;
26427 staticpro (&Vwith_echo_area_save_vector
);
26429 Vmessage_stack
= Qnil
;
26430 staticpro (&Vmessage_stack
);
26432 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
26433 staticpro (&Qinhibit_redisplay
);
26435 message_dolog_marker1
= Fmake_marker ();
26436 staticpro (&message_dolog_marker1
);
26437 message_dolog_marker2
= Fmake_marker ();
26438 staticpro (&message_dolog_marker2
);
26439 message_dolog_marker3
= Fmake_marker ();
26440 staticpro (&message_dolog_marker3
);
26443 defsubr (&Sdump_frame_glyph_matrix
);
26444 defsubr (&Sdump_glyph_matrix
);
26445 defsubr (&Sdump_glyph_row
);
26446 defsubr (&Sdump_tool_bar_row
);
26447 defsubr (&Strace_redisplay
);
26448 defsubr (&Strace_to_stderr
);
26450 #ifdef HAVE_WINDOW_SYSTEM
26451 defsubr (&Stool_bar_lines_needed
);
26452 defsubr (&Slookup_image_map
);
26454 defsubr (&Sformat_mode_line
);
26455 defsubr (&Sinvisible_p
);
26456 defsubr (&Scurrent_bidi_paragraph_direction
);
26458 staticpro (&Qmenu_bar_update_hook
);
26459 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
26461 staticpro (&Qoverriding_terminal_local_map
);
26462 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
26464 staticpro (&Qoverriding_local_map
);
26465 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
26467 staticpro (&Qwindow_scroll_functions
);
26468 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
26470 staticpro (&Qwindow_text_change_functions
);
26471 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
26473 staticpro (&Qredisplay_end_trigger_functions
);
26474 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
26476 staticpro (&Qinhibit_point_motion_hooks
);
26477 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
26479 Qeval
= intern_c_string ("eval");
26480 staticpro (&Qeval
);
26482 QCdata
= intern_c_string (":data");
26483 staticpro (&QCdata
);
26484 Qdisplay
= intern_c_string ("display");
26485 staticpro (&Qdisplay
);
26486 Qspace_width
= intern_c_string ("space-width");
26487 staticpro (&Qspace_width
);
26488 Qraise
= intern_c_string ("raise");
26489 staticpro (&Qraise
);
26490 Qslice
= intern_c_string ("slice");
26491 staticpro (&Qslice
);
26492 Qspace
= intern_c_string ("space");
26493 staticpro (&Qspace
);
26494 Qmargin
= intern_c_string ("margin");
26495 staticpro (&Qmargin
);
26496 Qpointer
= intern_c_string ("pointer");
26497 staticpro (&Qpointer
);
26498 Qleft_margin
= intern_c_string ("left-margin");
26499 staticpro (&Qleft_margin
);
26500 Qright_margin
= intern_c_string ("right-margin");
26501 staticpro (&Qright_margin
);
26502 Qcenter
= intern_c_string ("center");
26503 staticpro (&Qcenter
);
26504 Qline_height
= intern_c_string ("line-height");
26505 staticpro (&Qline_height
);
26506 QCalign_to
= intern_c_string (":align-to");
26507 staticpro (&QCalign_to
);
26508 QCrelative_width
= intern_c_string (":relative-width");
26509 staticpro (&QCrelative_width
);
26510 QCrelative_height
= intern_c_string (":relative-height");
26511 staticpro (&QCrelative_height
);
26512 QCeval
= intern_c_string (":eval");
26513 staticpro (&QCeval
);
26514 QCpropertize
= intern_c_string (":propertize");
26515 staticpro (&QCpropertize
);
26516 QCfile
= intern_c_string (":file");
26517 staticpro (&QCfile
);
26518 Qfontified
= intern_c_string ("fontified");
26519 staticpro (&Qfontified
);
26520 Qfontification_functions
= intern_c_string ("fontification-functions");
26521 staticpro (&Qfontification_functions
);
26522 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
26523 staticpro (&Qtrailing_whitespace
);
26524 Qescape_glyph
= intern_c_string ("escape-glyph");
26525 staticpro (&Qescape_glyph
);
26526 Qnobreak_space
= intern_c_string ("nobreak-space");
26527 staticpro (&Qnobreak_space
);
26528 Qimage
= intern_c_string ("image");
26529 staticpro (&Qimage
);
26530 Qtext
= intern_c_string ("text");
26531 staticpro (&Qtext
);
26532 Qboth
= intern_c_string ("both");
26533 staticpro (&Qboth
);
26534 Qboth_horiz
= intern_c_string ("both-horiz");
26535 staticpro (&Qboth_horiz
);
26536 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
26537 staticpro (&Qtext_image_horiz
);
26538 QCmap
= intern_c_string (":map");
26539 staticpro (&QCmap
);
26540 QCpointer
= intern_c_string (":pointer");
26541 staticpro (&QCpointer
);
26542 Qrect
= intern_c_string ("rect");
26543 staticpro (&Qrect
);
26544 Qcircle
= intern_c_string ("circle");
26545 staticpro (&Qcircle
);
26546 Qpoly
= intern_c_string ("poly");
26547 staticpro (&Qpoly
);
26548 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
26549 staticpro (&Qmessage_truncate_lines
);
26550 Qgrow_only
= intern_c_string ("grow-only");
26551 staticpro (&Qgrow_only
);
26552 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
26553 staticpro (&Qinhibit_menubar_update
);
26554 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
26555 staticpro (&Qinhibit_eval_during_redisplay
);
26556 Qposition
= intern_c_string ("position");
26557 staticpro (&Qposition
);
26558 Qbuffer_position
= intern_c_string ("buffer-position");
26559 staticpro (&Qbuffer_position
);
26560 Qobject
= intern_c_string ("object");
26561 staticpro (&Qobject
);
26562 Qbar
= intern_c_string ("bar");
26564 Qhbar
= intern_c_string ("hbar");
26565 staticpro (&Qhbar
);
26566 Qbox
= intern_c_string ("box");
26568 Qhollow
= intern_c_string ("hollow");
26569 staticpro (&Qhollow
);
26570 Qhand
= intern_c_string ("hand");
26571 staticpro (&Qhand
);
26572 Qarrow
= intern_c_string ("arrow");
26573 staticpro (&Qarrow
);
26574 Qtext
= intern_c_string ("text");
26575 staticpro (&Qtext
);
26576 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
26577 staticpro (&Qrisky_local_variable
);
26578 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
26579 staticpro (&Qinhibit_free_realized_faces
);
26581 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
26582 Fcons (intern_c_string ("void-variable"), Qnil
)),
26584 staticpro (&list_of_error
);
26586 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
26587 staticpro (&Qlast_arrow_position
);
26588 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
26589 staticpro (&Qlast_arrow_string
);
26591 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
26592 staticpro (&Qoverlay_arrow_string
);
26593 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
26594 staticpro (&Qoverlay_arrow_bitmap
);
26596 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
26597 staticpro (&echo_buffer
[0]);
26598 staticpro (&echo_buffer
[1]);
26600 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
26601 staticpro (&echo_area_buffer
[0]);
26602 staticpro (&echo_area_buffer
[1]);
26604 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
26605 staticpro (&Vmessages_buffer_name
);
26607 mode_line_proptrans_alist
= Qnil
;
26608 staticpro (&mode_line_proptrans_alist
);
26609 mode_line_string_list
= Qnil
;
26610 staticpro (&mode_line_string_list
);
26611 mode_line_string_face
= Qnil
;
26612 staticpro (&mode_line_string_face
);
26613 mode_line_string_face_prop
= Qnil
;
26614 staticpro (&mode_line_string_face_prop
);
26615 Vmode_line_unwind_vector
= Qnil
;
26616 staticpro (&Vmode_line_unwind_vector
);
26618 help_echo_string
= Qnil
;
26619 staticpro (&help_echo_string
);
26620 help_echo_object
= Qnil
;
26621 staticpro (&help_echo_object
);
26622 help_echo_window
= Qnil
;
26623 staticpro (&help_echo_window
);
26624 previous_help_echo_string
= Qnil
;
26625 staticpro (&previous_help_echo_string
);
26626 help_echo_pos
= -1;
26628 Qright_to_left
= intern_c_string ("right-to-left");
26629 staticpro (&Qright_to_left
);
26630 Qleft_to_right
= intern_c_string ("left-to-right");
26631 staticpro (&Qleft_to_right
);
26633 #ifdef HAVE_WINDOW_SYSTEM
26634 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
26635 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
26636 For example, if a block cursor is over a tab, it will be drawn as
26637 wide as that tab on the display. */);
26638 x_stretch_cursor_p
= 0;
26641 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
26642 doc
: /* *Non-nil means highlight trailing whitespace.
26643 The face used for trailing whitespace is `trailing-whitespace'. */);
26644 Vshow_trailing_whitespace
= Qnil
;
26646 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
26647 doc
: /* *Control highlighting of nobreak space and soft hyphen.
26648 A value of t means highlight the character itself (for nobreak space,
26649 use face `nobreak-space').
26650 A value of nil means no highlighting.
26651 Other values mean display the escape glyph followed by an ordinary
26652 space or ordinary hyphen. */);
26653 Vnobreak_char_display
= Qt
;
26655 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
26656 doc
: /* *The pointer shape to show in void text areas.
26657 A value of nil means to show the text pointer. Other options are `arrow',
26658 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
26659 Vvoid_text_area_pointer
= Qarrow
;
26661 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
26662 doc
: /* Non-nil means don't actually do any redisplay.
26663 This is used for internal purposes. */);
26664 Vinhibit_redisplay
= Qnil
;
26666 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
26667 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
26668 Vglobal_mode_string
= Qnil
;
26670 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
26671 doc
: /* Marker for where to display an arrow on top of the buffer text.
26672 This must be the beginning of a line in order to work.
26673 See also `overlay-arrow-string'. */);
26674 Voverlay_arrow_position
= Qnil
;
26676 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
26677 doc
: /* String to display as an arrow in non-window frames.
26678 See also `overlay-arrow-position'. */);
26679 Voverlay_arrow_string
= make_pure_c_string ("=>");
26681 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
26682 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
26683 The symbols on this list are examined during redisplay to determine
26684 where to display overlay arrows. */);
26685 Voverlay_arrow_variable_list
26686 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
26688 DEFVAR_INT ("scroll-step", &scroll_step
,
26689 doc
: /* *The number of lines to try scrolling a window by when point moves out.
26690 If that fails to bring point back on frame, point is centered instead.
26691 If this is zero, point is always centered after it moves off frame.
26692 If you want scrolling to always be a line at a time, you should set
26693 `scroll-conservatively' to a large value rather than set this to 1. */);
26695 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
26696 doc
: /* *Scroll up to this many lines, to bring point back on screen.
26697 If point moves off-screen, redisplay will scroll by up to
26698 `scroll-conservatively' lines in order to bring point just barely
26699 onto the screen again. If that cannot be done, then redisplay
26700 recenters point as usual.
26702 A value of zero means always recenter point if it moves off screen. */);
26703 scroll_conservatively
= 0;
26705 DEFVAR_INT ("scroll-margin", &scroll_margin
,
26706 doc
: /* *Number of lines of margin at the top and bottom of a window.
26707 Recenter the window whenever point gets within this many lines
26708 of the top or bottom of the window. */);
26711 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
26712 doc
: /* Pixels per inch value for non-window system displays.
26713 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
26714 Vdisplay_pixels_per_inch
= make_float (72.0);
26717 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
26720 DEFVAR_LISP ("truncate-partial-width-windows",
26721 &Vtruncate_partial_width_windows
,
26722 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
26723 For an integer value, truncate lines in each window narrower than the
26724 full frame width, provided the window width is less than that integer;
26725 otherwise, respect the value of `truncate-lines'.
26727 For any other non-nil value, truncate lines in all windows that do
26728 not span the full frame width.
26730 A value of nil means to respect the value of `truncate-lines'.
26732 If `word-wrap' is enabled, you might want to reduce this. */);
26733 Vtruncate_partial_width_windows
= make_number (50);
26735 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
26736 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
26737 Any other value means to use the appropriate face, `mode-line',
26738 `header-line', or `menu' respectively. */);
26739 mode_line_inverse_video
= 1;
26741 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
26742 doc
: /* *Maximum buffer size for which line number should be displayed.
26743 If the buffer is bigger than this, the line number does not appear
26744 in the mode line. A value of nil means no limit. */);
26745 Vline_number_display_limit
= Qnil
;
26747 DEFVAR_INT ("line-number-display-limit-width",
26748 &line_number_display_limit_width
,
26749 doc
: /* *Maximum line width (in characters) for line number display.
26750 If the average length of the lines near point is bigger than this, then the
26751 line number may be omitted from the mode line. */);
26752 line_number_display_limit_width
= 200;
26754 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
26755 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
26756 highlight_nonselected_windows
= 0;
26758 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
26759 doc
: /* Non-nil if more than one frame is visible on this display.
26760 Minibuffer-only frames don't count, but iconified frames do.
26761 This variable is not guaranteed to be accurate except while processing
26762 `frame-title-format' and `icon-title-format'. */);
26764 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
26765 doc
: /* Template for displaying the title bar of visible frames.
26766 \(Assuming the window manager supports this feature.)
26768 This variable has the same structure as `mode-line-format', except that
26769 the %c and %l constructs are ignored. It is used only on frames for
26770 which no explicit name has been set \(see `modify-frame-parameters'). */);
26772 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
26773 doc
: /* Template for displaying the title bar of an iconified frame.
26774 \(Assuming the window manager supports this feature.)
26775 This variable has the same structure as `mode-line-format' (which see),
26776 and is used only on frames for which no explicit name has been set
26777 \(see `modify-frame-parameters'). */);
26779 = Vframe_title_format
26780 = pure_cons (intern_c_string ("multiple-frames"),
26781 pure_cons (make_pure_c_string ("%b"),
26782 pure_cons (pure_cons (empty_unibyte_string
,
26783 pure_cons (intern_c_string ("invocation-name"),
26784 pure_cons (make_pure_c_string ("@"),
26785 pure_cons (intern_c_string ("system-name"),
26789 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
26790 doc
: /* Maximum number of lines to keep in the message log buffer.
26791 If nil, disable message logging. If t, log messages but don't truncate
26792 the buffer when it becomes large. */);
26793 Vmessage_log_max
= make_number (100);
26795 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
26796 doc
: /* Functions called before redisplay, if window sizes have changed.
26797 The value should be a list of functions that take one argument.
26798 Just before redisplay, for each frame, if any of its windows have changed
26799 size since the last redisplay, or have been split or deleted,
26800 all the functions in the list are called, with the frame as argument. */);
26801 Vwindow_size_change_functions
= Qnil
;
26803 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
26804 doc
: /* List of functions to call before redisplaying a window with scrolling.
26805 Each function is called with two arguments, the window and its new
26806 display-start position. Note that these functions are also called by
26807 `set-window-buffer'. Also note that the value of `window-end' is not
26808 valid when these functions are called. */);
26809 Vwindow_scroll_functions
= Qnil
;
26811 DEFVAR_LISP ("window-text-change-functions",
26812 &Vwindow_text_change_functions
,
26813 doc
: /* Functions to call in redisplay when text in the window might change. */);
26814 Vwindow_text_change_functions
= Qnil
;
26816 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
26817 doc
: /* Functions called when redisplay of a window reaches the end trigger.
26818 Each function is called with two arguments, the window and the end trigger value.
26819 See `set-window-redisplay-end-trigger'. */);
26820 Vredisplay_end_trigger_functions
= Qnil
;
26822 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
26823 doc
: /* *Non-nil means autoselect window with mouse pointer.
26824 If nil, do not autoselect windows.
26825 A positive number means delay autoselection by that many seconds: a
26826 window is autoselected only after the mouse has remained in that
26827 window for the duration of the delay.
26828 A negative number has a similar effect, but causes windows to be
26829 autoselected only after the mouse has stopped moving. \(Because of
26830 the way Emacs compares mouse events, you will occasionally wait twice
26831 that time before the window gets selected.\)
26832 Any other value means to autoselect window instantaneously when the
26833 mouse pointer enters it.
26835 Autoselection selects the minibuffer only if it is active, and never
26836 unselects the minibuffer if it is active.
26838 When customizing this variable make sure that the actual value of
26839 `focus-follows-mouse' matches the behavior of your window manager. */);
26840 Vmouse_autoselect_window
= Qnil
;
26842 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
26843 doc
: /* *Non-nil means automatically resize tool-bars.
26844 This dynamically changes the tool-bar's height to the minimum height
26845 that is needed to make all tool-bar items visible.
26846 If value is `grow-only', the tool-bar's height is only increased
26847 automatically; to decrease the tool-bar height, use \\[recenter]. */);
26848 Vauto_resize_tool_bars
= Qt
;
26850 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
26851 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
26852 auto_raise_tool_bar_buttons_p
= 1;
26854 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
26855 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
26856 make_cursor_line_fully_visible_p
= 1;
26858 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
26859 doc
: /* *Border below tool-bar in pixels.
26860 If an integer, use it as the height of the border.
26861 If it is one of `internal-border-width' or `border-width', use the
26862 value of the corresponding frame parameter.
26863 Otherwise, no border is added below the tool-bar. */);
26864 Vtool_bar_border
= Qinternal_border_width
;
26866 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
26867 doc
: /* *Margin around tool-bar buttons in pixels.
26868 If an integer, use that for both horizontal and vertical margins.
26869 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
26870 HORZ specifying the horizontal margin, and VERT specifying the
26871 vertical margin. */);
26872 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
26874 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
26875 doc
: /* *Relief thickness of tool-bar buttons. */);
26876 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
26878 DEFVAR_LISP ("tool-bar-style", &Vtool_bar_style
,
26879 doc
: /* *Tool bar style to use.
26881 image - show images only
26882 text - show text only
26883 both - show both, text below image
26884 both-horiz - show text to the right of the image
26885 text-image-horiz - show text to the left of the image
26886 any other - use system default or image if no system default. */);
26887 Vtool_bar_style
= Qnil
;
26889 DEFVAR_INT ("tool-bar-max-label-size", &tool_bar_max_label_size
,
26890 doc
: /* *Maximum number of characters a label can have to be shown.
26891 The tool bar style must also show labels for this to have any effect, see
26892 `tool-bar-style'. */);
26893 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
26895 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
26896 doc
: /* List of functions to call to fontify regions of text.
26897 Each function is called with one argument POS. Functions must
26898 fontify a region starting at POS in the current buffer, and give
26899 fontified regions the property `fontified'. */);
26900 Vfontification_functions
= Qnil
;
26901 Fmake_variable_buffer_local (Qfontification_functions
);
26903 DEFVAR_BOOL ("unibyte-display-via-language-environment",
26904 &unibyte_display_via_language_environment
,
26905 doc
: /* *Non-nil means display unibyte text according to language environment.
26906 Specifically, this means that raw bytes in the range 160-255 decimal
26907 are displayed by converting them to the equivalent multibyte characters
26908 according to the current language environment. As a result, they are
26909 displayed according to the current fontset.
26911 Note that this variable affects only how these bytes are displayed,
26912 but does not change the fact they are interpreted as raw bytes. */);
26913 unibyte_display_via_language_environment
= 0;
26915 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
26916 doc
: /* *Maximum height for resizing mini-windows.
26917 If a float, it specifies a fraction of the mini-window frame's height.
26918 If an integer, it specifies a number of lines. */);
26919 Vmax_mini_window_height
= make_float (0.25);
26921 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
26922 doc
: /* *How to resize mini-windows.
26923 A value of nil means don't automatically resize mini-windows.
26924 A value of t means resize them to fit the text displayed in them.
26925 A value of `grow-only', the default, means let mini-windows grow
26926 only, until their display becomes empty, at which point the windows
26927 go back to their normal size. */);
26928 Vresize_mini_windows
= Qgrow_only
;
26930 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
26931 doc
: /* Alist specifying how to blink the cursor off.
26932 Each element has the form (ON-STATE . OFF-STATE). Whenever the
26933 `cursor-type' frame-parameter or variable equals ON-STATE,
26934 comparing using `equal', Emacs uses OFF-STATE to specify
26935 how to blink it off. ON-STATE and OFF-STATE are values for
26936 the `cursor-type' frame parameter.
26938 If a frame's ON-STATE has no entry in this list,
26939 the frame's other specifications determine how to blink the cursor off. */);
26940 Vblink_cursor_alist
= Qnil
;
26942 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
26943 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
26944 If non-nil, windows are automatically scrolled horizontally to make
26945 point visible. */);
26946 automatic_hscrolling_p
= 1;
26947 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
26948 staticpro (&Qauto_hscroll_mode
);
26950 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
26951 doc
: /* *How many columns away from the window edge point is allowed to get
26952 before automatic hscrolling will horizontally scroll the window. */);
26953 hscroll_margin
= 5;
26955 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
26956 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
26957 When point is less than `hscroll-margin' columns from the window
26958 edge, automatic hscrolling will scroll the window by the amount of columns
26959 determined by this variable. If its value is a positive integer, scroll that
26960 many columns. If it's a positive floating-point number, it specifies the
26961 fraction of the window's width to scroll. If it's nil or zero, point will be
26962 centered horizontally after the scroll. Any other value, including negative
26963 numbers, are treated as if the value were zero.
26965 Automatic hscrolling always moves point outside the scroll margin, so if
26966 point was more than scroll step columns inside the margin, the window will
26967 scroll more than the value given by the scroll step.
26969 Note that the lower bound for automatic hscrolling specified by `scroll-left'
26970 and `scroll-right' overrides this variable's effect. */);
26971 Vhscroll_step
= make_number (0);
26973 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
26974 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
26975 Bind this around calls to `message' to let it take effect. */);
26976 message_truncate_lines
= 0;
26978 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
26979 doc
: /* Normal hook run to update the menu bar definitions.
26980 Redisplay runs this hook before it redisplays the menu bar.
26981 This is used to update submenus such as Buffers,
26982 whose contents depend on various data. */);
26983 Vmenu_bar_update_hook
= Qnil
;
26985 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
26986 doc
: /* Frame for which we are updating a menu.
26987 The enable predicate for a menu binding should check this variable. */);
26988 Vmenu_updating_frame
= Qnil
;
26990 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
26991 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
26992 inhibit_menubar_update
= 0;
26994 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
26995 doc
: /* Prefix prepended to all continuation lines at display time.
26996 The value may be a string, an image, or a stretch-glyph; it is
26997 interpreted in the same way as the value of a `display' text property.
26999 This variable is overridden by any `wrap-prefix' text or overlay
27002 To add a prefix to non-continuation lines, use `line-prefix'. */);
27003 Vwrap_prefix
= Qnil
;
27004 staticpro (&Qwrap_prefix
);
27005 Qwrap_prefix
= intern_c_string ("wrap-prefix");
27006 Fmake_variable_buffer_local (Qwrap_prefix
);
27008 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
27009 doc
: /* Prefix prepended to all non-continuation lines at display time.
27010 The value may be a string, an image, or a stretch-glyph; it is
27011 interpreted in the same way as the value of a `display' text property.
27013 This variable is overridden by any `line-prefix' text or overlay
27016 To add a prefix to continuation lines, use `wrap-prefix'. */);
27017 Vline_prefix
= Qnil
;
27018 staticpro (&Qline_prefix
);
27019 Qline_prefix
= intern_c_string ("line-prefix");
27020 Fmake_variable_buffer_local (Qline_prefix
);
27022 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
27023 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27024 inhibit_eval_during_redisplay
= 0;
27026 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
27027 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27028 inhibit_free_realized_faces
= 0;
27031 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
27032 doc
: /* Inhibit try_window_id display optimization. */);
27033 inhibit_try_window_id
= 0;
27035 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
27036 doc
: /* Inhibit try_window_reusing display optimization. */);
27037 inhibit_try_window_reusing
= 0;
27039 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
27040 doc
: /* Inhibit try_cursor_movement display optimization. */);
27041 inhibit_try_cursor_movement
= 0;
27042 #endif /* GLYPH_DEBUG */
27044 DEFVAR_INT ("overline-margin", &overline_margin
,
27045 doc
: /* *Space between overline and text, in pixels.
27046 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27047 margin to the caracter height. */);
27048 overline_margin
= 2;
27050 DEFVAR_INT ("underline-minimum-offset",
27051 &underline_minimum_offset
,
27052 doc
: /* Minimum distance between baseline and underline.
27053 This can improve legibility of underlined text at small font sizes,
27054 particularly when using variable `x-use-underline-position-properties'
27055 with fonts that specify an UNDERLINE_POSITION relatively close to the
27056 baseline. The default value is 1. */);
27057 underline_minimum_offset
= 1;
27059 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
27060 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27061 This feature only works when on a window system that can change
27062 cursor shapes. */);
27063 display_hourglass_p
= 1;
27065 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
27066 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27067 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27069 hourglass_atimer
= NULL
;
27070 hourglass_shown_p
= 0;
27072 DEFSYM (Qglyphless_char
, "glyphless-char");
27073 DEFSYM (Qhex_code
, "hex-code");
27074 DEFSYM (Qempty_box
, "empty-box");
27075 DEFSYM (Qthin_space
, "thin-space");
27076 DEFSYM (Qzero_width
, "zero-width");
27078 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27079 /* Intern this now in case it isn't already done.
27080 Setting this variable twice is harmless.
27081 But don't staticpro it here--that is done in alloc.c. */
27082 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27083 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27085 DEFVAR_LISP ("glyphless-char-display", &Vglyphless_char_display
,
27086 doc
: /* Char-table to control displaying of glyphless characters.
27087 Each element, if non-nil, is an ASCII acronym string (displayed in a box)
27088 or one of these symbols:
27089 hex-code: display the hexadecimal code of a character in a box
27090 empty-box: display as an empty box
27091 thin-space: display as 1-pixel width space
27092 zero-width: don't display
27094 It has one extra slot to control the display of a character for which
27095 no font is found. The value of the slot is `hex-code' or `empty-box'.
27096 The default is `empty-box'. */);
27097 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27098 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27103 /* Initialize this module when Emacs starts. */
27108 Lisp_Object root_window
;
27109 struct window
*mini_w
;
27111 current_header_line_height
= current_mode_line_height
= -1;
27113 CHARPOS (this_line_start_pos
) = 0;
27115 mini_w
= XWINDOW (minibuf_window
);
27116 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27118 if (!noninteractive
)
27120 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27123 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27124 set_window_height (root_window
,
27125 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27127 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27128 set_window_height (minibuf_window
, 1, 0);
27130 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27131 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27133 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27134 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27135 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27137 /* The default ellipsis glyphs `...'. */
27138 for (i
= 0; i
< 3; ++i
)
27139 default_invis_vector
[i
] = make_number ('.');
27143 /* Allocate the buffer for frame titles.
27144 Also used for `format-mode-line'. */
27146 mode_line_noprop_buf
= (char *) xmalloc (size
);
27147 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27148 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27149 mode_line_target
= MODE_LINE_DISPLAY
;
27152 help_echo_showing_p
= 0;
27155 /* Since w32 does not support atimers, it defines its own implementation of
27156 the following three functions in w32fns.c. */
27159 /* Platform-independent portion of hourglass implementation. */
27161 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27163 hourglass_started (void)
27165 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27168 /* Cancel a currently active hourglass timer, and start a new one. */
27170 start_hourglass (void)
27172 #if defined (HAVE_WINDOW_SYSTEM)
27174 int secs
, usecs
= 0;
27176 cancel_hourglass ();
27178 if (INTEGERP (Vhourglass_delay
)
27179 && XINT (Vhourglass_delay
) > 0)
27180 secs
= XFASTINT (Vhourglass_delay
);
27181 else if (FLOATP (Vhourglass_delay
)
27182 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27185 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27186 secs
= XFASTINT (tem
);
27187 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27190 secs
= DEFAULT_HOURGLASS_DELAY
;
27192 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27193 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27194 show_hourglass
, NULL
);
27199 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27202 cancel_hourglass (void)
27204 #if defined (HAVE_WINDOW_SYSTEM)
27205 if (hourglass_atimer
)
27207 cancel_atimer (hourglass_atimer
);
27208 hourglass_atimer
= NULL
;
27211 if (hourglass_shown_p
)
27215 #endif /* ! WINDOWSNT */