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
;
9387 if (!NILP (current_buffer
->bidi_display_reordering
))
9388 current_buffer
->bidi_paragraph_direction
= Qleft_to_right
;
9390 /* Insert new message at BEG. */
9391 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9393 if (STRINGP (string
))
9398 nbytes
= SBYTES (string
);
9399 nchars
= string_byte_to_char (string
, nbytes
);
9401 /* This function takes care of single/multibyte conversion. We
9402 just have to ensure that the echo area buffer has the right
9403 setting of enable_multibyte_characters. */
9404 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9409 nbytes
= strlen (s
);
9411 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9413 /* Convert from multi-byte to single-byte. */
9416 unsigned char work
[1];
9418 /* Convert a multibyte string to single-byte. */
9419 for (i
= 0; i
< nbytes
; i
+= n
)
9421 c
= string_char_and_length (s
+ i
, &n
);
9422 work
[0] = (ASCII_CHAR_P (c
)
9424 : multibyte_char_to_unibyte (c
, Qnil
));
9425 insert_1_both (work
, 1, 1, 1, 0, 0);
9428 else if (!multibyte_p
9429 && !NILP (current_buffer
->enable_multibyte_characters
))
9431 /* Convert from single-byte to multi-byte. */
9434 const unsigned char *msg
= (const unsigned char *) s
;
9435 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9437 /* Convert a single-byte string to multibyte. */
9438 for (i
= 0; i
< nbytes
; i
++)
9441 MAKE_CHAR_MULTIBYTE (c
);
9442 n
= CHAR_STRING (c
, str
);
9443 insert_1_both (str
, 1, n
, 1, 0, 0);
9447 insert_1 (s
, nbytes
, 1, 0, 0);
9454 /* Clear messages. CURRENT_P non-zero means clear the current
9455 message. LAST_DISPLAYED_P non-zero means clear the message
9459 clear_message (int current_p
, int last_displayed_p
)
9463 echo_area_buffer
[0] = Qnil
;
9464 message_cleared_p
= 1;
9467 if (last_displayed_p
)
9468 echo_area_buffer
[1] = Qnil
;
9470 message_buf_print
= 0;
9473 /* Clear garbaged frames.
9475 This function is used where the old redisplay called
9476 redraw_garbaged_frames which in turn called redraw_frame which in
9477 turn called clear_frame. The call to clear_frame was a source of
9478 flickering. I believe a clear_frame is not necessary. It should
9479 suffice in the new redisplay to invalidate all current matrices,
9480 and ensure a complete redisplay of all windows. */
9483 clear_garbaged_frames (void)
9487 Lisp_Object tail
, frame
;
9488 int changed_count
= 0;
9490 FOR_EACH_FRAME (tail
, frame
)
9492 struct frame
*f
= XFRAME (frame
);
9494 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9498 Fredraw_frame (frame
);
9499 f
->force_flush_display_p
= 1;
9501 clear_current_matrices (f
);
9510 ++windows_or_buffers_changed
;
9515 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9516 is non-zero update selected_frame. Value is non-zero if the
9517 mini-windows height has been changed. */
9520 echo_area_display (int update_frame_p
)
9522 Lisp_Object mini_window
;
9525 int window_height_changed_p
= 0;
9526 struct frame
*sf
= SELECTED_FRAME ();
9528 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9529 w
= XWINDOW (mini_window
);
9530 f
= XFRAME (WINDOW_FRAME (w
));
9532 /* Don't display if frame is invisible or not yet initialized. */
9533 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9536 #ifdef HAVE_WINDOW_SYSTEM
9537 /* When Emacs starts, selected_frame may be the initial terminal
9538 frame. If we let this through, a message would be displayed on
9540 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9542 #endif /* HAVE_WINDOW_SYSTEM */
9544 /* Redraw garbaged frames. */
9546 clear_garbaged_frames ();
9548 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9550 echo_area_window
= mini_window
;
9551 window_height_changed_p
= display_echo_area (w
);
9552 w
->must_be_updated_p
= 1;
9554 /* Update the display, unless called from redisplay_internal.
9555 Also don't update the screen during redisplay itself. The
9556 update will happen at the end of redisplay, and an update
9557 here could cause confusion. */
9558 if (update_frame_p
&& !redisplaying_p
)
9562 /* If the display update has been interrupted by pending
9563 input, update mode lines in the frame. Due to the
9564 pending input, it might have been that redisplay hasn't
9565 been called, so that mode lines above the echo area are
9566 garbaged. This looks odd, so we prevent it here. */
9567 if (!display_completed
)
9568 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9570 if (window_height_changed_p
9571 /* Don't do this if Emacs is shutting down. Redisplay
9572 needs to run hooks. */
9573 && !NILP (Vrun_hooks
))
9575 /* Must update other windows. Likewise as in other
9576 cases, don't let this update be interrupted by
9578 int count
= SPECPDL_INDEX ();
9579 specbind (Qredisplay_dont_pause
, Qt
);
9580 windows_or_buffers_changed
= 1;
9581 redisplay_internal (0);
9582 unbind_to (count
, Qnil
);
9584 else if (FRAME_WINDOW_P (f
) && n
== 0)
9586 /* Window configuration is the same as before.
9587 Can do with a display update of the echo area,
9588 unless we displayed some mode lines. */
9589 update_single_window (w
, 1);
9590 FRAME_RIF (f
)->flush_display (f
);
9593 update_frame (f
, 1, 1);
9595 /* If cursor is in the echo area, make sure that the next
9596 redisplay displays the minibuffer, so that the cursor will
9597 be replaced with what the minibuffer wants. */
9598 if (cursor_in_echo_area
)
9599 ++windows_or_buffers_changed
;
9602 else if (!EQ (mini_window
, selected_window
))
9603 windows_or_buffers_changed
++;
9605 /* Last displayed message is now the current message. */
9606 echo_area_buffer
[1] = echo_area_buffer
[0];
9607 /* Inform read_char that we're not echoing. */
9608 echo_message_buffer
= Qnil
;
9610 /* Prevent redisplay optimization in redisplay_internal by resetting
9611 this_line_start_pos. This is done because the mini-buffer now
9612 displays the message instead of its buffer text. */
9613 if (EQ (mini_window
, selected_window
))
9614 CHARPOS (this_line_start_pos
) = 0;
9616 return window_height_changed_p
;
9621 /***********************************************************************
9622 Mode Lines and Frame Titles
9623 ***********************************************************************/
9625 /* A buffer for constructing non-propertized mode-line strings and
9626 frame titles in it; allocated from the heap in init_xdisp and
9627 resized as needed in store_mode_line_noprop_char. */
9629 static char *mode_line_noprop_buf
;
9631 /* The buffer's end, and a current output position in it. */
9633 static char *mode_line_noprop_buf_end
;
9634 static char *mode_line_noprop_ptr
;
9636 #define MODE_LINE_NOPROP_LEN(start) \
9637 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9640 MODE_LINE_DISPLAY
= 0,
9646 /* Alist that caches the results of :propertize.
9647 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9648 static Lisp_Object mode_line_proptrans_alist
;
9650 /* List of strings making up the mode-line. */
9651 static Lisp_Object mode_line_string_list
;
9653 /* Base face property when building propertized mode line string. */
9654 static Lisp_Object mode_line_string_face
;
9655 static Lisp_Object mode_line_string_face_prop
;
9658 /* Unwind data for mode line strings */
9660 static Lisp_Object Vmode_line_unwind_vector
;
9663 format_mode_line_unwind_data (struct buffer
*obuf
,
9667 Lisp_Object vector
, tmp
;
9669 /* Reduce consing by keeping one vector in
9670 Vwith_echo_area_save_vector. */
9671 vector
= Vmode_line_unwind_vector
;
9672 Vmode_line_unwind_vector
= Qnil
;
9675 vector
= Fmake_vector (make_number (8), Qnil
);
9677 ASET (vector
, 0, make_number (mode_line_target
));
9678 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9679 ASET (vector
, 2, mode_line_string_list
);
9680 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9681 ASET (vector
, 4, mode_line_string_face
);
9682 ASET (vector
, 5, mode_line_string_face_prop
);
9685 XSETBUFFER (tmp
, obuf
);
9688 ASET (vector
, 6, tmp
);
9689 ASET (vector
, 7, owin
);
9695 unwind_format_mode_line (Lisp_Object vector
)
9697 mode_line_target
= XINT (AREF (vector
, 0));
9698 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9699 mode_line_string_list
= AREF (vector
, 2);
9700 if (! EQ (AREF (vector
, 3), Qt
))
9701 mode_line_proptrans_alist
= AREF (vector
, 3);
9702 mode_line_string_face
= AREF (vector
, 4);
9703 mode_line_string_face_prop
= AREF (vector
, 5);
9705 if (!NILP (AREF (vector
, 7)))
9706 /* Select window before buffer, since it may change the buffer. */
9707 Fselect_window (AREF (vector
, 7), Qt
);
9709 if (!NILP (AREF (vector
, 6)))
9711 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9712 ASET (vector
, 6, Qnil
);
9715 Vmode_line_unwind_vector
= vector
;
9720 /* Store a single character C for the frame title in mode_line_noprop_buf.
9721 Re-allocate mode_line_noprop_buf if necessary. */
9724 store_mode_line_noprop_char (char c
)
9726 /* If output position has reached the end of the allocated buffer,
9727 double the buffer's size. */
9728 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9730 int len
= MODE_LINE_NOPROP_LEN (0);
9731 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9732 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9733 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9734 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9737 *mode_line_noprop_ptr
++ = c
;
9741 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9742 mode_line_noprop_ptr. STR is the string to store. Do not copy
9743 characters that yield more columns than PRECISION; PRECISION <= 0
9744 means copy the whole string. Pad with spaces until FIELD_WIDTH
9745 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9746 pad. Called from display_mode_element when it is used to build a
9750 store_mode_line_noprop (const unsigned char *str
, int field_width
, int precision
)
9753 EMACS_INT dummy
, nbytes
;
9755 /* Copy at most PRECISION chars from STR. */
9756 nbytes
= strlen (str
);
9757 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9759 store_mode_line_noprop_char (*str
++);
9761 /* Fill up with spaces until FIELD_WIDTH reached. */
9762 while (field_width
> 0
9765 store_mode_line_noprop_char (' ');
9772 /***********************************************************************
9774 ***********************************************************************/
9776 #ifdef HAVE_WINDOW_SYSTEM
9778 /* Set the title of FRAME, if it has changed. The title format is
9779 Vicon_title_format if FRAME is iconified, otherwise it is
9780 frame_title_format. */
9783 x_consider_frame_title (Lisp_Object frame
)
9785 struct frame
*f
= XFRAME (frame
);
9787 if (FRAME_WINDOW_P (f
)
9788 || FRAME_MINIBUF_ONLY_P (f
)
9789 || f
->explicit_name
)
9791 /* Do we have more than one visible frame on this X display? */
9798 int count
= SPECPDL_INDEX ();
9800 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9802 Lisp_Object other_frame
= XCAR (tail
);
9803 struct frame
*tf
= XFRAME (other_frame
);
9806 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9807 && !FRAME_MINIBUF_ONLY_P (tf
)
9808 && !EQ (other_frame
, tip_frame
)
9809 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9813 /* Set global variable indicating that multiple frames exist. */
9814 multiple_frames
= CONSP (tail
);
9816 /* Switch to the buffer of selected window of the frame. Set up
9817 mode_line_target so that display_mode_element will output into
9818 mode_line_noprop_buf; then display the title. */
9819 record_unwind_protect (unwind_format_mode_line
,
9820 format_mode_line_unwind_data
9821 (current_buffer
, selected_window
, 0));
9823 Fselect_window (f
->selected_window
, Qt
);
9824 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9825 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9827 mode_line_target
= MODE_LINE_TITLE
;
9828 title_start
= MODE_LINE_NOPROP_LEN (0);
9829 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9830 NULL
, DEFAULT_FACE_ID
);
9831 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9832 len
= MODE_LINE_NOPROP_LEN (title_start
);
9833 title
= mode_line_noprop_buf
+ title_start
;
9834 unbind_to (count
, Qnil
);
9836 /* Set the title only if it's changed. This avoids consing in
9837 the common case where it hasn't. (If it turns out that we've
9838 already wasted too much time by walking through the list with
9839 display_mode_element, then we might need to optimize at a
9840 higher level than this.) */
9841 if (! STRINGP (f
->name
)
9842 || SBYTES (f
->name
) != len
9843 || memcmp (title
, SDATA (f
->name
), len
) != 0)
9844 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9848 #endif /* not HAVE_WINDOW_SYSTEM */
9853 /***********************************************************************
9855 ***********************************************************************/
9858 /* Prepare for redisplay by updating menu-bar item lists when
9859 appropriate. This can call eval. */
9862 prepare_menu_bars (void)
9865 struct gcpro gcpro1
, gcpro2
;
9867 Lisp_Object tooltip_frame
;
9869 #ifdef HAVE_WINDOW_SYSTEM
9870 tooltip_frame
= tip_frame
;
9872 tooltip_frame
= Qnil
;
9875 /* Update all frame titles based on their buffer names, etc. We do
9876 this before the menu bars so that the buffer-menu will show the
9877 up-to-date frame titles. */
9878 #ifdef HAVE_WINDOW_SYSTEM
9879 if (windows_or_buffers_changed
|| update_mode_lines
)
9881 Lisp_Object tail
, frame
;
9883 FOR_EACH_FRAME (tail
, frame
)
9886 if (!EQ (frame
, tooltip_frame
)
9887 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9888 x_consider_frame_title (frame
);
9891 #endif /* HAVE_WINDOW_SYSTEM */
9893 /* Update the menu bar item lists, if appropriate. This has to be
9894 done before any actual redisplay or generation of display lines. */
9895 all_windows
= (update_mode_lines
9896 || buffer_shared
> 1
9897 || windows_or_buffers_changed
);
9900 Lisp_Object tail
, frame
;
9901 int count
= SPECPDL_INDEX ();
9902 /* 1 means that update_menu_bar has run its hooks
9903 so any further calls to update_menu_bar shouldn't do so again. */
9904 int menu_bar_hooks_run
= 0;
9906 record_unwind_save_match_data ();
9908 FOR_EACH_FRAME (tail
, frame
)
9912 /* Ignore tooltip frame. */
9913 if (EQ (frame
, tooltip_frame
))
9916 /* If a window on this frame changed size, report that to
9917 the user and clear the size-change flag. */
9918 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9920 Lisp_Object functions
;
9922 /* Clear flag first in case we get an error below. */
9923 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9924 functions
= Vwindow_size_change_functions
;
9925 GCPRO2 (tail
, functions
);
9927 while (CONSP (functions
))
9929 if (!EQ (XCAR (functions
), Qt
))
9930 call1 (XCAR (functions
), frame
);
9931 functions
= XCDR (functions
);
9937 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9938 #ifdef HAVE_WINDOW_SYSTEM
9939 update_tool_bar (f
, 0);
9942 if (windows_or_buffers_changed
9944 ns_set_doc_edited (f
, Fbuffer_modified_p
9945 (XWINDOW (f
->selected_window
)->buffer
));
9950 unbind_to (count
, Qnil
);
9954 struct frame
*sf
= SELECTED_FRAME ();
9955 update_menu_bar (sf
, 1, 0);
9956 #ifdef HAVE_WINDOW_SYSTEM
9957 update_tool_bar (sf
, 1);
9963 /* Update the menu bar item list for frame F. This has to be done
9964 before we start to fill in any display lines, because it can call
9967 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9969 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9970 already ran the menu bar hooks for this redisplay, so there
9971 is no need to run them again. The return value is the
9972 updated value of this flag, to pass to the next call. */
9975 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
9978 register struct window
*w
;
9980 /* If called recursively during a menu update, do nothing. This can
9981 happen when, for instance, an activate-menubar-hook causes a
9983 if (inhibit_menubar_update
)
9986 window
= FRAME_SELECTED_WINDOW (f
);
9987 w
= XWINDOW (window
);
9989 if (FRAME_WINDOW_P (f
)
9991 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9992 || defined (HAVE_NS) || defined (USE_GTK)
9993 FRAME_EXTERNAL_MENU_BAR (f
)
9995 FRAME_MENU_BAR_LINES (f
) > 0
9997 : FRAME_MENU_BAR_LINES (f
) > 0)
9999 /* If the user has switched buffers or windows, we need to
10000 recompute to reflect the new bindings. But we'll
10001 recompute when update_mode_lines is set too; that means
10002 that people can use force-mode-line-update to request
10003 that the menu bar be recomputed. The adverse effect on
10004 the rest of the redisplay algorithm is about the same as
10005 windows_or_buffers_changed anyway. */
10006 if (windows_or_buffers_changed
10007 /* This used to test w->update_mode_line, but we believe
10008 there is no need to recompute the menu in that case. */
10009 || update_mode_lines
10010 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10011 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10012 != !NILP (w
->last_had_star
))
10013 || ((!NILP (Vtransient_mark_mode
)
10014 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10015 != !NILP (w
->region_showing
)))
10017 struct buffer
*prev
= current_buffer
;
10018 int count
= SPECPDL_INDEX ();
10020 specbind (Qinhibit_menubar_update
, Qt
);
10022 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10023 if (save_match_data
)
10024 record_unwind_save_match_data ();
10025 if (NILP (Voverriding_local_map_menu_flag
))
10027 specbind (Qoverriding_terminal_local_map
, Qnil
);
10028 specbind (Qoverriding_local_map
, Qnil
);
10033 /* Run the Lucid hook. */
10034 safe_run_hooks (Qactivate_menubar_hook
);
10036 /* If it has changed current-menubar from previous value,
10037 really recompute the menu-bar from the value. */
10038 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10039 call0 (Qrecompute_lucid_menubar
);
10041 safe_run_hooks (Qmenu_bar_update_hook
);
10046 XSETFRAME (Vmenu_updating_frame
, f
);
10047 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10049 /* Redisplay the menu bar in case we changed it. */
10050 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10051 || defined (HAVE_NS) || defined (USE_GTK)
10052 if (FRAME_WINDOW_P (f
))
10054 #if defined (HAVE_NS)
10055 /* All frames on Mac OS share the same menubar. So only
10056 the selected frame should be allowed to set it. */
10057 if (f
== SELECTED_FRAME ())
10059 set_frame_menubar (f
, 0, 0);
10062 /* On a terminal screen, the menu bar is an ordinary screen
10063 line, and this makes it get updated. */
10064 w
->update_mode_line
= Qt
;
10065 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10066 /* In the non-toolkit version, the menu bar is an ordinary screen
10067 line, and this makes it get updated. */
10068 w
->update_mode_line
= Qt
;
10069 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10071 unbind_to (count
, Qnil
);
10072 set_buffer_internal_1 (prev
);
10081 /***********************************************************************
10083 ***********************************************************************/
10085 #ifdef HAVE_WINDOW_SYSTEM
10088 Nominal cursor position -- where to draw output.
10089 HPOS and VPOS are window relative glyph matrix coordinates.
10090 X and Y are window relative pixel coordinates. */
10092 struct cursor_pos output_cursor
;
10096 Set the global variable output_cursor to CURSOR. All cursor
10097 positions are relative to updated_window. */
10100 set_output_cursor (struct cursor_pos
*cursor
)
10102 output_cursor
.hpos
= cursor
->hpos
;
10103 output_cursor
.vpos
= cursor
->vpos
;
10104 output_cursor
.x
= cursor
->x
;
10105 output_cursor
.y
= cursor
->y
;
10110 Set a nominal cursor position.
10112 HPOS and VPOS are column/row positions in a window glyph matrix. X
10113 and Y are window text area relative pixel positions.
10115 If this is done during an update, updated_window will contain the
10116 window that is being updated and the position is the future output
10117 cursor position for that window. If updated_window is null, use
10118 selected_window and display the cursor at the given position. */
10121 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10125 /* If updated_window is not set, work on selected_window. */
10126 if (updated_window
)
10127 w
= updated_window
;
10129 w
= XWINDOW (selected_window
);
10131 /* Set the output cursor. */
10132 output_cursor
.hpos
= hpos
;
10133 output_cursor
.vpos
= vpos
;
10134 output_cursor
.x
= x
;
10135 output_cursor
.y
= y
;
10137 /* If not called as part of an update, really display the cursor.
10138 This will also set the cursor position of W. */
10139 if (updated_window
== NULL
)
10142 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10143 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10144 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10149 #endif /* HAVE_WINDOW_SYSTEM */
10152 /***********************************************************************
10154 ***********************************************************************/
10156 #ifdef HAVE_WINDOW_SYSTEM
10158 /* Where the mouse was last time we reported a mouse event. */
10160 FRAME_PTR last_mouse_frame
;
10162 /* Tool-bar item index of the item on which a mouse button was pressed
10165 int last_tool_bar_item
;
10169 update_tool_bar_unwind (Lisp_Object frame
)
10171 selected_frame
= frame
;
10175 /* Update the tool-bar item list for frame F. This has to be done
10176 before we start to fill in any display lines. Called from
10177 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10178 and restore it here. */
10181 update_tool_bar (struct frame
*f
, int save_match_data
)
10183 #if defined (USE_GTK) || defined (HAVE_NS)
10184 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10186 int do_update
= WINDOWP (f
->tool_bar_window
)
10187 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10192 Lisp_Object window
;
10195 window
= FRAME_SELECTED_WINDOW (f
);
10196 w
= XWINDOW (window
);
10198 /* If the user has switched buffers or windows, we need to
10199 recompute to reflect the new bindings. But we'll
10200 recompute when update_mode_lines is set too; that means
10201 that people can use force-mode-line-update to request
10202 that the menu bar be recomputed. The adverse effect on
10203 the rest of the redisplay algorithm is about the same as
10204 windows_or_buffers_changed anyway. */
10205 if (windows_or_buffers_changed
10206 || !NILP (w
->update_mode_line
)
10207 || update_mode_lines
10208 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10209 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10210 != !NILP (w
->last_had_star
))
10211 || ((!NILP (Vtransient_mark_mode
)
10212 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10213 != !NILP (w
->region_showing
)))
10215 struct buffer
*prev
= current_buffer
;
10216 int count
= SPECPDL_INDEX ();
10217 Lisp_Object frame
, new_tool_bar
;
10218 int new_n_tool_bar
;
10219 struct gcpro gcpro1
;
10221 /* Set current_buffer to the buffer of the selected
10222 window of the frame, so that we get the right local
10224 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10226 /* Save match data, if we must. */
10227 if (save_match_data
)
10228 record_unwind_save_match_data ();
10230 /* Make sure that we don't accidentally use bogus keymaps. */
10231 if (NILP (Voverriding_local_map_menu_flag
))
10233 specbind (Qoverriding_terminal_local_map
, Qnil
);
10234 specbind (Qoverriding_local_map
, Qnil
);
10237 GCPRO1 (new_tool_bar
);
10239 /* We must temporarily set the selected frame to this frame
10240 before calling tool_bar_items, because the calculation of
10241 the tool-bar keymap uses the selected frame (see
10242 `tool-bar-make-keymap' in tool-bar.el). */
10243 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10244 XSETFRAME (frame
, f
);
10245 selected_frame
= frame
;
10247 /* Build desired tool-bar items from keymaps. */
10248 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10251 /* Redisplay the tool-bar if we changed it. */
10252 if (new_n_tool_bar
!= f
->n_tool_bar_items
10253 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10255 /* Redisplay that happens asynchronously due to an expose event
10256 may access f->tool_bar_items. Make sure we update both
10257 variables within BLOCK_INPUT so no such event interrupts. */
10259 f
->tool_bar_items
= new_tool_bar
;
10260 f
->n_tool_bar_items
= new_n_tool_bar
;
10261 w
->update_mode_line
= Qt
;
10267 unbind_to (count
, Qnil
);
10268 set_buffer_internal_1 (prev
);
10274 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10275 F's desired tool-bar contents. F->tool_bar_items must have
10276 been set up previously by calling prepare_menu_bars. */
10279 build_desired_tool_bar_string (struct frame
*f
)
10281 int i
, size
, size_needed
;
10282 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10283 Lisp_Object image
, plist
, props
;
10285 image
= plist
= props
= Qnil
;
10286 GCPRO3 (image
, plist
, props
);
10288 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10289 Otherwise, make a new string. */
10291 /* The size of the string we might be able to reuse. */
10292 size
= (STRINGP (f
->desired_tool_bar_string
)
10293 ? SCHARS (f
->desired_tool_bar_string
)
10296 /* We need one space in the string for each image. */
10297 size_needed
= f
->n_tool_bar_items
;
10299 /* Reuse f->desired_tool_bar_string, if possible. */
10300 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10301 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10302 make_number (' '));
10305 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10306 Fremove_text_properties (make_number (0), make_number (size
),
10307 props
, f
->desired_tool_bar_string
);
10310 /* Put a `display' property on the string for the images to display,
10311 put a `menu_item' property on tool-bar items with a value that
10312 is the index of the item in F's tool-bar item vector. */
10313 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10315 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10317 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10318 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10319 int hmargin
, vmargin
, relief
, idx
, end
;
10321 /* If image is a vector, choose the image according to the
10323 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10324 if (VECTORP (image
))
10328 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10329 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10332 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10333 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10335 xassert (ASIZE (image
) >= idx
);
10336 image
= AREF (image
, idx
);
10341 /* Ignore invalid image specifications. */
10342 if (!valid_image_p (image
))
10345 /* Display the tool-bar button pressed, or depressed. */
10346 plist
= Fcopy_sequence (XCDR (image
));
10348 /* Compute margin and relief to draw. */
10349 relief
= (tool_bar_button_relief
>= 0
10350 ? tool_bar_button_relief
10351 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10352 hmargin
= vmargin
= relief
;
10354 if (INTEGERP (Vtool_bar_button_margin
)
10355 && XINT (Vtool_bar_button_margin
) > 0)
10357 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10358 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10360 else if (CONSP (Vtool_bar_button_margin
))
10362 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10363 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10364 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10366 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10367 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10368 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10371 if (auto_raise_tool_bar_buttons_p
)
10373 /* Add a `:relief' property to the image spec if the item is
10377 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10384 /* If image is selected, display it pressed, i.e. with a
10385 negative relief. If it's not selected, display it with a
10387 plist
= Fplist_put (plist
, QCrelief
,
10389 ? make_number (-relief
)
10390 : make_number (relief
)));
10395 /* Put a margin around the image. */
10396 if (hmargin
|| vmargin
)
10398 if (hmargin
== vmargin
)
10399 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10401 plist
= Fplist_put (plist
, QCmargin
,
10402 Fcons (make_number (hmargin
),
10403 make_number (vmargin
)));
10406 /* If button is not enabled, and we don't have special images
10407 for the disabled state, make the image appear disabled by
10408 applying an appropriate algorithm to it. */
10409 if (!enabled_p
&& idx
< 0)
10410 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10412 /* Put a `display' text property on the string for the image to
10413 display. Put a `menu-item' property on the string that gives
10414 the start of this item's properties in the tool-bar items
10416 image
= Fcons (Qimage
, plist
);
10417 props
= list4 (Qdisplay
, image
,
10418 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10420 /* Let the last image hide all remaining spaces in the tool bar
10421 string. The string can be longer than needed when we reuse a
10422 previous string. */
10423 if (i
+ 1 == f
->n_tool_bar_items
)
10424 end
= SCHARS (f
->desired_tool_bar_string
);
10427 Fadd_text_properties (make_number (i
), make_number (end
),
10428 props
, f
->desired_tool_bar_string
);
10436 /* Display one line of the tool-bar of frame IT->f.
10438 HEIGHT specifies the desired height of the tool-bar line.
10439 If the actual height of the glyph row is less than HEIGHT, the
10440 row's height is increased to HEIGHT, and the icons are centered
10441 vertically in the new height.
10443 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10444 count a final empty row in case the tool-bar width exactly matches
10449 display_tool_bar_line (struct it
*it
, int height
)
10451 struct glyph_row
*row
= it
->glyph_row
;
10452 int max_x
= it
->last_visible_x
;
10453 struct glyph
*last
;
10455 prepare_desired_row (row
);
10456 row
->y
= it
->current_y
;
10458 /* Note that this isn't made use of if the face hasn't a box,
10459 so there's no need to check the face here. */
10460 it
->start_of_box_run_p
= 1;
10462 while (it
->current_x
< max_x
)
10464 int x
, n_glyphs_before
, i
, nglyphs
;
10465 struct it it_before
;
10467 /* Get the next display element. */
10468 if (!get_next_display_element (it
))
10470 /* Don't count empty row if we are counting needed tool-bar lines. */
10471 if (height
< 0 && !it
->hpos
)
10476 /* Produce glyphs. */
10477 n_glyphs_before
= row
->used
[TEXT_AREA
];
10480 PRODUCE_GLYPHS (it
);
10482 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10484 x
= it_before
.current_x
;
10485 while (i
< nglyphs
)
10487 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10489 if (x
+ glyph
->pixel_width
> max_x
)
10491 /* Glyph doesn't fit on line. Backtrack. */
10492 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10494 /* If this is the only glyph on this line, it will never fit on the
10495 toolbar, so skip it. But ensure there is at least one glyph,
10496 so we don't accidentally disable the tool-bar. */
10497 if (n_glyphs_before
== 0
10498 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10504 x
+= glyph
->pixel_width
;
10508 /* Stop at line ends. */
10509 if (ITERATOR_AT_END_OF_LINE_P (it
))
10512 set_iterator_to_next (it
, 1);
10517 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10519 /* Use default face for the border below the tool bar.
10521 FIXME: When auto-resize-tool-bars is grow-only, there is
10522 no additional border below the possibly empty tool-bar lines.
10523 So to make the extra empty lines look "normal", we have to
10524 use the tool-bar face for the border too. */
10525 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10526 it
->face_id
= DEFAULT_FACE_ID
;
10528 extend_face_to_end_of_line (it
);
10529 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10530 last
->right_box_line_p
= 1;
10531 if (last
== row
->glyphs
[TEXT_AREA
])
10532 last
->left_box_line_p
= 1;
10534 /* Make line the desired height and center it vertically. */
10535 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10537 /* Don't add more than one line height. */
10538 height
%= FRAME_LINE_HEIGHT (it
->f
);
10539 it
->max_ascent
+= height
/ 2;
10540 it
->max_descent
+= (height
+ 1) / 2;
10543 compute_line_metrics (it
);
10545 /* If line is empty, make it occupy the rest of the tool-bar. */
10546 if (!row
->displays_text_p
)
10548 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10549 row
->visible_height
= row
->height
;
10550 row
->ascent
= row
->phys_ascent
= 0;
10551 row
->extra_line_spacing
= 0;
10554 row
->full_width_p
= 1;
10555 row
->continued_p
= 0;
10556 row
->truncated_on_left_p
= 0;
10557 row
->truncated_on_right_p
= 0;
10559 it
->current_x
= it
->hpos
= 0;
10560 it
->current_y
+= row
->height
;
10566 /* Max tool-bar height. */
10568 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10569 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10571 /* Value is the number of screen lines needed to make all tool-bar
10572 items of frame F visible. The number of actual rows needed is
10573 returned in *N_ROWS if non-NULL. */
10576 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10578 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10580 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10581 the desired matrix, so use (unused) mode-line row as temporary row to
10582 avoid destroying the first tool-bar row. */
10583 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10585 /* Initialize an iterator for iteration over
10586 F->desired_tool_bar_string in the tool-bar window of frame F. */
10587 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10588 it
.first_visible_x
= 0;
10589 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10590 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10592 while (!ITERATOR_AT_END_P (&it
))
10594 clear_glyph_row (temp_row
);
10595 it
.glyph_row
= temp_row
;
10596 display_tool_bar_line (&it
, -1);
10598 clear_glyph_row (temp_row
);
10600 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10602 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10604 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10608 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10610 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10611 (Lisp_Object frame
)
10618 frame
= selected_frame
;
10620 CHECK_FRAME (frame
);
10621 f
= XFRAME (frame
);
10623 if (WINDOWP (f
->tool_bar_window
)
10624 || (w
= XWINDOW (f
->tool_bar_window
),
10625 WINDOW_TOTAL_LINES (w
) > 0))
10627 update_tool_bar (f
, 1);
10628 if (f
->n_tool_bar_items
)
10630 build_desired_tool_bar_string (f
);
10631 nlines
= tool_bar_lines_needed (f
, NULL
);
10635 return make_number (nlines
);
10639 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10640 height should be changed. */
10643 redisplay_tool_bar (struct frame
*f
)
10647 struct glyph_row
*row
;
10649 #if defined (USE_GTK) || defined (HAVE_NS)
10650 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10651 update_frame_tool_bar (f
);
10655 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10656 do anything. This means you must start with tool-bar-lines
10657 non-zero to get the auto-sizing effect. Or in other words, you
10658 can turn off tool-bars by specifying tool-bar-lines zero. */
10659 if (!WINDOWP (f
->tool_bar_window
)
10660 || (w
= XWINDOW (f
->tool_bar_window
),
10661 WINDOW_TOTAL_LINES (w
) == 0))
10664 /* Set up an iterator for the tool-bar window. */
10665 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10666 it
.first_visible_x
= 0;
10667 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10668 row
= it
.glyph_row
;
10670 /* Build a string that represents the contents of the tool-bar. */
10671 build_desired_tool_bar_string (f
);
10672 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10674 if (f
->n_tool_bar_rows
== 0)
10678 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10679 nlines
!= WINDOW_TOTAL_LINES (w
)))
10682 int old_height
= WINDOW_TOTAL_LINES (w
);
10684 XSETFRAME (frame
, f
);
10685 Fmodify_frame_parameters (frame
,
10686 Fcons (Fcons (Qtool_bar_lines
,
10687 make_number (nlines
)),
10689 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10691 clear_glyph_matrix (w
->desired_matrix
);
10692 fonts_changed_p
= 1;
10698 /* Display as many lines as needed to display all tool-bar items. */
10700 if (f
->n_tool_bar_rows
> 0)
10702 int border
, rows
, height
, extra
;
10704 if (INTEGERP (Vtool_bar_border
))
10705 border
= XINT (Vtool_bar_border
);
10706 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10707 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10708 else if (EQ (Vtool_bar_border
, Qborder_width
))
10709 border
= f
->border_width
;
10715 rows
= f
->n_tool_bar_rows
;
10716 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10717 extra
= it
.last_visible_y
- border
- height
* rows
;
10719 while (it
.current_y
< it
.last_visible_y
)
10722 if (extra
> 0 && rows
-- > 0)
10724 h
= (extra
+ rows
- 1) / rows
;
10727 display_tool_bar_line (&it
, height
+ h
);
10732 while (it
.current_y
< it
.last_visible_y
)
10733 display_tool_bar_line (&it
, 0);
10736 /* It doesn't make much sense to try scrolling in the tool-bar
10737 window, so don't do it. */
10738 w
->desired_matrix
->no_scrolling_p
= 1;
10739 w
->must_be_updated_p
= 1;
10741 if (!NILP (Vauto_resize_tool_bars
))
10743 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10744 int change_height_p
= 0;
10746 /* If we couldn't display everything, change the tool-bar's
10747 height if there is room for more. */
10748 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10749 && it
.current_y
< max_tool_bar_height
)
10750 change_height_p
= 1;
10752 row
= it
.glyph_row
- 1;
10754 /* If there are blank lines at the end, except for a partially
10755 visible blank line at the end that is smaller than
10756 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10757 if (!row
->displays_text_p
10758 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10759 change_height_p
= 1;
10761 /* If row displays tool-bar items, but is partially visible,
10762 change the tool-bar's height. */
10763 if (row
->displays_text_p
10764 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10765 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10766 change_height_p
= 1;
10768 /* Resize windows as needed by changing the `tool-bar-lines'
10769 frame parameter. */
10770 if (change_height_p
)
10773 int old_height
= WINDOW_TOTAL_LINES (w
);
10775 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10777 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10778 && !f
->minimize_tool_bar_window_p
)
10779 ? (nlines
> old_height
)
10780 : (nlines
!= old_height
));
10781 f
->minimize_tool_bar_window_p
= 0;
10783 if (change_height_p
)
10785 XSETFRAME (frame
, f
);
10786 Fmodify_frame_parameters (frame
,
10787 Fcons (Fcons (Qtool_bar_lines
,
10788 make_number (nlines
)),
10790 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10792 clear_glyph_matrix (w
->desired_matrix
);
10793 f
->n_tool_bar_rows
= nrows
;
10794 fonts_changed_p
= 1;
10801 f
->minimize_tool_bar_window_p
= 0;
10806 /* Get information about the tool-bar item which is displayed in GLYPH
10807 on frame F. Return in *PROP_IDX the index where tool-bar item
10808 properties start in F->tool_bar_items. Value is zero if
10809 GLYPH doesn't display a tool-bar item. */
10812 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
10818 /* This function can be called asynchronously, which means we must
10819 exclude any possibility that Fget_text_property signals an
10821 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10822 charpos
= max (0, charpos
);
10824 /* Get the text property `menu-item' at pos. The value of that
10825 property is the start index of this item's properties in
10826 F->tool_bar_items. */
10827 prop
= Fget_text_property (make_number (charpos
),
10828 Qmenu_item
, f
->current_tool_bar_string
);
10829 if (INTEGERP (prop
))
10831 *prop_idx
= XINT (prop
);
10841 /* Get information about the tool-bar item at position X/Y on frame F.
10842 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10843 the current matrix of the tool-bar window of F, or NULL if not
10844 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10845 item in F->tool_bar_items. Value is
10847 -1 if X/Y is not on a tool-bar item
10848 0 if X/Y is on the same item that was highlighted before.
10852 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
10853 int *hpos
, int *vpos
, int *prop_idx
)
10855 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10856 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10859 /* Find the glyph under X/Y. */
10860 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10861 if (*glyph
== NULL
)
10864 /* Get the start of this tool-bar item's properties in
10865 f->tool_bar_items. */
10866 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10869 /* Is mouse on the highlighted item? */
10870 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
10871 && *vpos
>= hlinfo
->mouse_face_beg_row
10872 && *vpos
<= hlinfo
->mouse_face_end_row
10873 && (*vpos
> hlinfo
->mouse_face_beg_row
10874 || *hpos
>= hlinfo
->mouse_face_beg_col
)
10875 && (*vpos
< hlinfo
->mouse_face_end_row
10876 || *hpos
< hlinfo
->mouse_face_end_col
10877 || hlinfo
->mouse_face_past_end
))
10885 Handle mouse button event on the tool-bar of frame F, at
10886 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10887 0 for button release. MODIFIERS is event modifiers for button
10891 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
10892 unsigned int modifiers
)
10894 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10895 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10896 int hpos
, vpos
, prop_idx
;
10897 struct glyph
*glyph
;
10898 Lisp_Object enabled_p
;
10900 /* If not on the highlighted tool-bar item, return. */
10901 frame_to_window_pixel_xy (w
, &x
, &y
);
10902 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10905 /* If item is disabled, do nothing. */
10906 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10907 if (NILP (enabled_p
))
10912 /* Show item in pressed state. */
10913 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
10914 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10915 last_tool_bar_item
= prop_idx
;
10919 Lisp_Object key
, frame
;
10920 struct input_event event
;
10921 EVENT_INIT (event
);
10923 /* Show item in released state. */
10924 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
10925 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10927 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10929 XSETFRAME (frame
, f
);
10930 event
.kind
= TOOL_BAR_EVENT
;
10931 event
.frame_or_window
= frame
;
10933 kbd_buffer_store_event (&event
);
10935 event
.kind
= TOOL_BAR_EVENT
;
10936 event
.frame_or_window
= frame
;
10938 event
.modifiers
= modifiers
;
10939 kbd_buffer_store_event (&event
);
10940 last_tool_bar_item
= -1;
10945 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10946 tool-bar window-relative coordinates X/Y. Called from
10947 note_mouse_highlight. */
10950 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
10952 Lisp_Object window
= f
->tool_bar_window
;
10953 struct window
*w
= XWINDOW (window
);
10954 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10955 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10957 struct glyph
*glyph
;
10958 struct glyph_row
*row
;
10960 Lisp_Object enabled_p
;
10962 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10963 int mouse_down_p
, rc
;
10965 /* Function note_mouse_highlight is called with negative X/Y
10966 values when mouse moves outside of the frame. */
10967 if (x
<= 0 || y
<= 0)
10969 clear_mouse_face (hlinfo
);
10973 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10976 /* Not on tool-bar item. */
10977 clear_mouse_face (hlinfo
);
10981 /* On same tool-bar item as before. */
10982 goto set_help_echo
;
10984 clear_mouse_face (hlinfo
);
10986 /* Mouse is down, but on different tool-bar item? */
10987 mouse_down_p
= (dpyinfo
->grabbed
10988 && f
== last_mouse_frame
10989 && FRAME_LIVE_P (f
));
10991 && last_tool_bar_item
!= prop_idx
)
10994 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10995 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10997 /* If tool-bar item is not enabled, don't highlight it. */
10998 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10999 if (!NILP (enabled_p
))
11001 /* Compute the x-position of the glyph. In front and past the
11002 image is a space. We include this in the highlighted area. */
11003 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
11004 for (i
= x
= 0; i
< hpos
; ++i
)
11005 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11007 /* Record this as the current active region. */
11008 hlinfo
->mouse_face_beg_col
= hpos
;
11009 hlinfo
->mouse_face_beg_row
= vpos
;
11010 hlinfo
->mouse_face_beg_x
= x
;
11011 hlinfo
->mouse_face_beg_y
= row
->y
;
11012 hlinfo
->mouse_face_past_end
= 0;
11014 hlinfo
->mouse_face_end_col
= hpos
+ 1;
11015 hlinfo
->mouse_face_end_row
= vpos
;
11016 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11017 hlinfo
->mouse_face_end_y
= row
->y
;
11018 hlinfo
->mouse_face_window
= window
;
11019 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11021 /* Display it as active. */
11022 show_mouse_face (hlinfo
, draw
);
11023 hlinfo
->mouse_face_image_state
= draw
;
11028 /* Set help_echo_string to a help string to display for this tool-bar item.
11029 XTread_socket does the rest. */
11030 help_echo_object
= help_echo_window
= Qnil
;
11031 help_echo_pos
= -1;
11032 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11033 if (NILP (help_echo_string
))
11034 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11037 #endif /* HAVE_WINDOW_SYSTEM */
11041 /************************************************************************
11042 Horizontal scrolling
11043 ************************************************************************/
11045 static int hscroll_window_tree (Lisp_Object
);
11046 static int hscroll_windows (Lisp_Object
);
11048 /* For all leaf windows in the window tree rooted at WINDOW, set their
11049 hscroll value so that PT is (i) visible in the window, and (ii) so
11050 that it is not within a certain margin at the window's left and
11051 right border. Value is non-zero if any window's hscroll has been
11055 hscroll_window_tree (Lisp_Object window
)
11057 int hscrolled_p
= 0;
11058 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11059 int hscroll_step_abs
= 0;
11060 double hscroll_step_rel
= 0;
11062 if (hscroll_relative_p
)
11064 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11065 if (hscroll_step_rel
< 0)
11067 hscroll_relative_p
= 0;
11068 hscroll_step_abs
= 0;
11071 else if (INTEGERP (Vhscroll_step
))
11073 hscroll_step_abs
= XINT (Vhscroll_step
);
11074 if (hscroll_step_abs
< 0)
11075 hscroll_step_abs
= 0;
11078 hscroll_step_abs
= 0;
11080 while (WINDOWP (window
))
11082 struct window
*w
= XWINDOW (window
);
11084 if (WINDOWP (w
->hchild
))
11085 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11086 else if (WINDOWP (w
->vchild
))
11087 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11088 else if (w
->cursor
.vpos
>= 0)
11091 int text_area_width
;
11092 struct glyph_row
*current_cursor_row
11093 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11094 struct glyph_row
*desired_cursor_row
11095 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11096 struct glyph_row
*cursor_row
11097 = (desired_cursor_row
->enabled_p
11098 ? desired_cursor_row
11099 : current_cursor_row
);
11101 text_area_width
= window_box_width (w
, TEXT_AREA
);
11103 /* Scroll when cursor is inside this scroll margin. */
11104 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11106 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11107 && ((XFASTINT (w
->hscroll
)
11108 && w
->cursor
.x
<= h_margin
)
11109 || (cursor_row
->enabled_p
11110 && cursor_row
->truncated_on_right_p
11111 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11115 struct buffer
*saved_current_buffer
;
11119 /* Find point in a display of infinite width. */
11120 saved_current_buffer
= current_buffer
;
11121 current_buffer
= XBUFFER (w
->buffer
);
11123 if (w
== XWINDOW (selected_window
))
11124 pt
= BUF_PT (current_buffer
);
11127 pt
= marker_position (w
->pointm
);
11128 pt
= max (BEGV
, pt
);
11132 /* Move iterator to pt starting at cursor_row->start in
11133 a line with infinite width. */
11134 init_to_row_start (&it
, w
, cursor_row
);
11135 it
.last_visible_x
= INFINITY
;
11136 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11137 current_buffer
= saved_current_buffer
;
11139 /* Position cursor in window. */
11140 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11141 hscroll
= max (0, (it
.current_x
11142 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11143 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11144 : (text_area_width
/ 2))))
11145 / FRAME_COLUMN_WIDTH (it
.f
);
11146 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11148 if (hscroll_relative_p
)
11149 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11152 wanted_x
= text_area_width
11153 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11156 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11160 if (hscroll_relative_p
)
11161 wanted_x
= text_area_width
* hscroll_step_rel
11164 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11167 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11169 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11171 /* Don't call Fset_window_hscroll if value hasn't
11172 changed because it will prevent redisplay
11174 if (XFASTINT (w
->hscroll
) != hscroll
)
11176 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11177 w
->hscroll
= make_number (hscroll
);
11186 /* Value is non-zero if hscroll of any leaf window has been changed. */
11187 return hscrolled_p
;
11191 /* Set hscroll so that cursor is visible and not inside horizontal
11192 scroll margins for all windows in the tree rooted at WINDOW. See
11193 also hscroll_window_tree above. Value is non-zero if any window's
11194 hscroll has been changed. If it has, desired matrices on the frame
11195 of WINDOW are cleared. */
11198 hscroll_windows (Lisp_Object window
)
11200 int hscrolled_p
= hscroll_window_tree (window
);
11202 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11203 return hscrolled_p
;
11208 /************************************************************************
11210 ************************************************************************/
11212 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11213 to a non-zero value. This is sometimes handy to have in a debugger
11218 /* First and last unchanged row for try_window_id. */
11220 int debug_first_unchanged_at_end_vpos
;
11221 int debug_last_unchanged_at_beg_vpos
;
11223 /* Delta vpos and y. */
11225 int debug_dvpos
, debug_dy
;
11227 /* Delta in characters and bytes for try_window_id. */
11229 EMACS_INT debug_delta
, debug_delta_bytes
;
11231 /* Values of window_end_pos and window_end_vpos at the end of
11234 EMACS_INT debug_end_pos
, debug_end_vpos
;
11236 /* Append a string to W->desired_matrix->method. FMT is a printf
11237 format string. A1...A9 are a supplement for a variable-length
11238 argument list. If trace_redisplay_p is non-zero also printf the
11239 resulting string to stderr. */
11242 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11245 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11248 char *method
= w
->desired_matrix
->method
;
11249 int len
= strlen (method
);
11250 int size
= sizeof w
->desired_matrix
->method
;
11251 int remaining
= size
- len
- 1;
11253 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11254 if (len
&& remaining
)
11257 --remaining
, ++len
;
11260 strncpy (method
+ len
, buffer
, remaining
);
11262 if (trace_redisplay_p
)
11263 fprintf (stderr
, "%p (%s): %s\n",
11265 ((BUFFERP (w
->buffer
)
11266 && STRINGP (XBUFFER (w
->buffer
)->name
))
11267 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
11272 #endif /* GLYPH_DEBUG */
11275 /* Value is non-zero if all changes in window W, which displays
11276 current_buffer, are in the text between START and END. START is a
11277 buffer position, END is given as a distance from Z. Used in
11278 redisplay_internal for display optimization. */
11281 text_outside_line_unchanged_p (struct window
*w
,
11282 EMACS_INT start
, EMACS_INT end
)
11284 int unchanged_p
= 1;
11286 /* If text or overlays have changed, see where. */
11287 if (XFASTINT (w
->last_modified
) < MODIFF
11288 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11290 /* Gap in the line? */
11291 if (GPT
< start
|| Z
- GPT
< end
)
11294 /* Changes start in front of the line, or end after it? */
11296 && (BEG_UNCHANGED
< start
- 1
11297 || END_UNCHANGED
< end
))
11300 /* If selective display, can't optimize if changes start at the
11301 beginning of the line. */
11303 && INTEGERP (current_buffer
->selective_display
)
11304 && XINT (current_buffer
->selective_display
) > 0
11305 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11308 /* If there are overlays at the start or end of the line, these
11309 may have overlay strings with newlines in them. A change at
11310 START, for instance, may actually concern the display of such
11311 overlay strings as well, and they are displayed on different
11312 lines. So, quickly rule out this case. (For the future, it
11313 might be desirable to implement something more telling than
11314 just BEG/END_UNCHANGED.) */
11317 if (BEG
+ BEG_UNCHANGED
== start
11318 && overlay_touches_p (start
))
11320 if (END_UNCHANGED
== end
11321 && overlay_touches_p (Z
- end
))
11325 /* Under bidi reordering, adding or deleting a character in the
11326 beginning of a paragraph, before the first strong directional
11327 character, can change the base direction of the paragraph (unless
11328 the buffer specifies a fixed paragraph direction), which will
11329 require to redisplay the whole paragraph. It might be worthwhile
11330 to find the paragraph limits and widen the range of redisplayed
11331 lines to that, but for now just give up this optimization. */
11332 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
11333 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
11337 return unchanged_p
;
11341 /* Do a frame update, taking possible shortcuts into account. This is
11342 the main external entry point for redisplay.
11344 If the last redisplay displayed an echo area message and that message
11345 is no longer requested, we clear the echo area or bring back the
11346 mini-buffer if that is in use. */
11351 redisplay_internal (0);
11356 overlay_arrow_string_or_property (Lisp_Object var
)
11360 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11363 return Voverlay_arrow_string
;
11366 /* Return 1 if there are any overlay-arrows in current_buffer. */
11368 overlay_arrow_in_current_buffer_p (void)
11372 for (vlist
= Voverlay_arrow_variable_list
;
11374 vlist
= XCDR (vlist
))
11376 Lisp_Object var
= XCAR (vlist
);
11379 if (!SYMBOLP (var
))
11381 val
= find_symbol_value (var
);
11383 && current_buffer
== XMARKER (val
)->buffer
)
11390 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11394 overlay_arrows_changed_p (void)
11398 for (vlist
= Voverlay_arrow_variable_list
;
11400 vlist
= XCDR (vlist
))
11402 Lisp_Object var
= XCAR (vlist
);
11403 Lisp_Object val
, pstr
;
11405 if (!SYMBOLP (var
))
11407 val
= find_symbol_value (var
);
11408 if (!MARKERP (val
))
11410 if (! EQ (COERCE_MARKER (val
),
11411 Fget (var
, Qlast_arrow_position
))
11412 || ! (pstr
= overlay_arrow_string_or_property (var
),
11413 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11419 /* Mark overlay arrows to be updated on next redisplay. */
11422 update_overlay_arrows (int up_to_date
)
11426 for (vlist
= Voverlay_arrow_variable_list
;
11428 vlist
= XCDR (vlist
))
11430 Lisp_Object var
= XCAR (vlist
);
11432 if (!SYMBOLP (var
))
11435 if (up_to_date
> 0)
11437 Lisp_Object val
= find_symbol_value (var
);
11438 Fput (var
, Qlast_arrow_position
,
11439 COERCE_MARKER (val
));
11440 Fput (var
, Qlast_arrow_string
,
11441 overlay_arrow_string_or_property (var
));
11443 else if (up_to_date
< 0
11444 || !NILP (Fget (var
, Qlast_arrow_position
)))
11446 Fput (var
, Qlast_arrow_position
, Qt
);
11447 Fput (var
, Qlast_arrow_string
, Qt
);
11453 /* Return overlay arrow string to display at row.
11454 Return integer (bitmap number) for arrow bitmap in left fringe.
11455 Return nil if no overlay arrow. */
11458 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11462 for (vlist
= Voverlay_arrow_variable_list
;
11464 vlist
= XCDR (vlist
))
11466 Lisp_Object var
= XCAR (vlist
);
11469 if (!SYMBOLP (var
))
11472 val
= find_symbol_value (var
);
11475 && current_buffer
== XMARKER (val
)->buffer
11476 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11478 if (FRAME_WINDOW_P (it
->f
)
11479 /* FIXME: if ROW->reversed_p is set, this should test
11480 the right fringe, not the left one. */
11481 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11483 #ifdef HAVE_WINDOW_SYSTEM
11484 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11487 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11488 return make_number (fringe_bitmap
);
11491 return make_number (-1); /* Use default arrow bitmap */
11493 return overlay_arrow_string_or_property (var
);
11500 /* Return 1 if point moved out of or into a composition. Otherwise
11501 return 0. PREV_BUF and PREV_PT are the last point buffer and
11502 position. BUF and PT are the current point buffer and position. */
11505 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11506 struct buffer
*buf
, EMACS_INT pt
)
11508 EMACS_INT start
, end
;
11510 Lisp_Object buffer
;
11512 XSETBUFFER (buffer
, buf
);
11513 /* Check a composition at the last point if point moved within the
11515 if (prev_buf
== buf
)
11518 /* Point didn't move. */
11521 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11522 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11523 && COMPOSITION_VALID_P (start
, end
, prop
)
11524 && start
< prev_pt
&& end
> prev_pt
)
11525 /* The last point was within the composition. Return 1 iff
11526 point moved out of the composition. */
11527 return (pt
<= start
|| pt
>= end
);
11530 /* Check a composition at the current point. */
11531 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11532 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11533 && COMPOSITION_VALID_P (start
, end
, prop
)
11534 && start
< pt
&& end
> pt
);
11538 /* Reconsider the setting of B->clip_changed which is displayed
11542 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11544 if (b
->clip_changed
11545 && !NILP (w
->window_end_valid
)
11546 && w
->current_matrix
->buffer
== b
11547 && w
->current_matrix
->zv
== BUF_ZV (b
)
11548 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11549 b
->clip_changed
= 0;
11551 /* If display wasn't paused, and W is not a tool bar window, see if
11552 point has been moved into or out of a composition. In that case,
11553 we set b->clip_changed to 1 to force updating the screen. If
11554 b->clip_changed has already been set to 1, we can skip this
11556 if (!b
->clip_changed
11557 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11561 if (w
== XWINDOW (selected_window
))
11562 pt
= BUF_PT (current_buffer
);
11564 pt
= marker_position (w
->pointm
);
11566 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11567 || pt
!= XINT (w
->last_point
))
11568 && check_point_in_composition (w
->current_matrix
->buffer
,
11569 XINT (w
->last_point
),
11570 XBUFFER (w
->buffer
), pt
))
11571 b
->clip_changed
= 1;
11576 /* Select FRAME to forward the values of frame-local variables into C
11577 variables so that the redisplay routines can access those values
11581 select_frame_for_redisplay (Lisp_Object frame
)
11583 Lisp_Object tail
, tem
;
11584 Lisp_Object old
= selected_frame
;
11585 struct Lisp_Symbol
*sym
;
11587 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11589 selected_frame
= frame
;
11592 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11593 if (CONSP (XCAR (tail
))
11594 && (tem
= XCAR (XCAR (tail
)),
11596 && (sym
= indirect_variable (XSYMBOL (tem
)),
11597 sym
->redirect
== SYMBOL_LOCALIZED
)
11598 && sym
->val
.blv
->frame_local
)
11599 /* Use find_symbol_value rather than Fsymbol_value
11600 to avoid an error if it is void. */
11601 find_symbol_value (tem
);
11602 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11606 #define STOP_POLLING \
11607 do { if (! polling_stopped_here) stop_polling (); \
11608 polling_stopped_here = 1; } while (0)
11610 #define RESUME_POLLING \
11611 do { if (polling_stopped_here) start_polling (); \
11612 polling_stopped_here = 0; } while (0)
11615 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11616 response to any user action; therefore, we should preserve the echo
11617 area. (Actually, our caller does that job.) Perhaps in the future
11618 avoid recentering windows if it is not necessary; currently that
11619 causes some problems. */
11622 redisplay_internal (int preserve_echo_area
)
11624 struct window
*w
= XWINDOW (selected_window
);
11627 int must_finish
= 0;
11628 struct text_pos tlbufpos
, tlendpos
;
11629 int number_of_visible_frames
;
11632 int polling_stopped_here
= 0;
11633 Lisp_Object old_frame
= selected_frame
;
11635 /* Non-zero means redisplay has to consider all windows on all
11636 frames. Zero means, only selected_window is considered. */
11637 int consider_all_windows_p
;
11639 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11641 /* No redisplay if running in batch mode or frame is not yet fully
11642 initialized, or redisplay is explicitly turned off by setting
11643 Vinhibit_redisplay. */
11644 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11645 || !NILP (Vinhibit_redisplay
))
11648 /* Don't examine these until after testing Vinhibit_redisplay.
11649 When Emacs is shutting down, perhaps because its connection to
11650 X has dropped, we should not look at them at all. */
11651 f
= XFRAME (w
->frame
);
11652 sf
= SELECTED_FRAME ();
11654 if (!f
->glyphs_initialized_p
)
11657 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11658 if (popup_activated ())
11662 /* I don't think this happens but let's be paranoid. */
11663 if (redisplaying_p
)
11666 /* Record a function that resets redisplaying_p to its old value
11667 when we leave this function. */
11668 count
= SPECPDL_INDEX ();
11669 record_unwind_protect (unwind_redisplay
,
11670 Fcons (make_number (redisplaying_p
), selected_frame
));
11672 specbind (Qinhibit_free_realized_faces
, Qnil
);
11675 Lisp_Object tail
, frame
;
11677 FOR_EACH_FRAME (tail
, frame
)
11679 struct frame
*f
= XFRAME (frame
);
11680 f
->already_hscrolled_p
= 0;
11685 if (!EQ (old_frame
, selected_frame
)
11686 && FRAME_LIVE_P (XFRAME (old_frame
)))
11687 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11688 selected_frame and selected_window to be temporarily out-of-sync so
11689 when we come back here via `goto retry', we need to resync because we
11690 may need to run Elisp code (via prepare_menu_bars). */
11691 select_frame_for_redisplay (old_frame
);
11694 reconsider_clip_changes (w
, current_buffer
);
11695 last_escape_glyph_frame
= NULL
;
11696 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11697 last_glyphless_glyph_frame
= NULL
;
11698 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
11700 /* If new fonts have been loaded that make a glyph matrix adjustment
11701 necessary, do it. */
11702 if (fonts_changed_p
)
11704 adjust_glyphs (NULL
);
11705 ++windows_or_buffers_changed
;
11706 fonts_changed_p
= 0;
11709 /* If face_change_count is non-zero, init_iterator will free all
11710 realized faces, which includes the faces referenced from current
11711 matrices. So, we can't reuse current matrices in this case. */
11712 if (face_change_count
)
11713 ++windows_or_buffers_changed
;
11715 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11716 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11718 /* Since frames on a single ASCII terminal share the same
11719 display area, displaying a different frame means redisplay
11720 the whole thing. */
11721 windows_or_buffers_changed
++;
11722 SET_FRAME_GARBAGED (sf
);
11724 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11726 FRAME_TTY (sf
)->previous_frame
= sf
;
11729 /* Set the visible flags for all frames. Do this before checking
11730 for resized or garbaged frames; they want to know if their frames
11731 are visible. See the comment in frame.h for
11732 FRAME_SAMPLE_VISIBILITY. */
11734 Lisp_Object tail
, frame
;
11736 number_of_visible_frames
= 0;
11738 FOR_EACH_FRAME (tail
, frame
)
11740 struct frame
*f
= XFRAME (frame
);
11742 FRAME_SAMPLE_VISIBILITY (f
);
11743 if (FRAME_VISIBLE_P (f
))
11744 ++number_of_visible_frames
;
11745 clear_desired_matrices (f
);
11749 /* Notice any pending interrupt request to change frame size. */
11750 do_pending_window_change (1);
11752 /* Clear frames marked as garbaged. */
11753 if (frame_garbaged
)
11754 clear_garbaged_frames ();
11756 /* Build menubar and tool-bar items. */
11757 if (NILP (Vmemory_full
))
11758 prepare_menu_bars ();
11760 if (windows_or_buffers_changed
)
11761 update_mode_lines
++;
11763 /* Detect case that we need to write or remove a star in the mode line. */
11764 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11766 w
->update_mode_line
= Qt
;
11767 if (buffer_shared
> 1)
11768 update_mode_lines
++;
11771 /* Avoid invocation of point motion hooks by `current_column' below. */
11772 count1
= SPECPDL_INDEX ();
11773 specbind (Qinhibit_point_motion_hooks
, Qt
);
11775 /* If %c is in the mode line, update it if needed. */
11776 if (!NILP (w
->column_number_displayed
)
11777 /* This alternative quickly identifies a common case
11778 where no change is needed. */
11779 && !(PT
== XFASTINT (w
->last_point
)
11780 && XFASTINT (w
->last_modified
) >= MODIFF
11781 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11782 && (XFASTINT (w
->column_number_displayed
)
11783 != (int) current_column ())) /* iftc */
11784 w
->update_mode_line
= Qt
;
11786 unbind_to (count1
, Qnil
);
11788 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11790 /* The variable buffer_shared is set in redisplay_window and
11791 indicates that we redisplay a buffer in different windows. See
11793 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11794 || cursor_type_changed
);
11796 /* If specs for an arrow have changed, do thorough redisplay
11797 to ensure we remove any arrow that should no longer exist. */
11798 if (overlay_arrows_changed_p ())
11799 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11801 /* Normally the message* functions will have already displayed and
11802 updated the echo area, but the frame may have been trashed, or
11803 the update may have been preempted, so display the echo area
11804 again here. Checking message_cleared_p captures the case that
11805 the echo area should be cleared. */
11806 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11807 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11808 || (message_cleared_p
11809 && minibuf_level
== 0
11810 /* If the mini-window is currently selected, this means the
11811 echo-area doesn't show through. */
11812 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11814 int window_height_changed_p
= echo_area_display (0);
11817 /* If we don't display the current message, don't clear the
11818 message_cleared_p flag, because, if we did, we wouldn't clear
11819 the echo area in the next redisplay which doesn't preserve
11821 if (!display_last_displayed_message_p
)
11822 message_cleared_p
= 0;
11824 if (fonts_changed_p
)
11826 else if (window_height_changed_p
)
11828 consider_all_windows_p
= 1;
11829 ++update_mode_lines
;
11830 ++windows_or_buffers_changed
;
11832 /* If window configuration was changed, frames may have been
11833 marked garbaged. Clear them or we will experience
11834 surprises wrt scrolling. */
11835 if (frame_garbaged
)
11836 clear_garbaged_frames ();
11839 else if (EQ (selected_window
, minibuf_window
)
11840 && (current_buffer
->clip_changed
11841 || XFASTINT (w
->last_modified
) < MODIFF
11842 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11843 && resize_mini_window (w
, 0))
11845 /* Resized active mini-window to fit the size of what it is
11846 showing if its contents might have changed. */
11848 /* FIXME: this causes all frames to be updated, which seems unnecessary
11849 since only the current frame needs to be considered. This function needs
11850 to be rewritten with two variables, consider_all_windows and
11851 consider_all_frames. */
11852 consider_all_windows_p
= 1;
11853 ++windows_or_buffers_changed
;
11854 ++update_mode_lines
;
11856 /* If window configuration was changed, frames may have been
11857 marked garbaged. Clear them or we will experience
11858 surprises wrt scrolling. */
11859 if (frame_garbaged
)
11860 clear_garbaged_frames ();
11864 /* If showing the region, and mark has changed, we must redisplay
11865 the whole window. The assignment to this_line_start_pos prevents
11866 the optimization directly below this if-statement. */
11867 if (((!NILP (Vtransient_mark_mode
)
11868 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11869 != !NILP (w
->region_showing
))
11870 || (!NILP (w
->region_showing
)
11871 && !EQ (w
->region_showing
,
11872 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11873 CHARPOS (this_line_start_pos
) = 0;
11875 /* Optimize the case that only the line containing the cursor in the
11876 selected window has changed. Variables starting with this_ are
11877 set in display_line and record information about the line
11878 containing the cursor. */
11879 tlbufpos
= this_line_start_pos
;
11880 tlendpos
= this_line_end_pos
;
11881 if (!consider_all_windows_p
11882 && CHARPOS (tlbufpos
) > 0
11883 && NILP (w
->update_mode_line
)
11884 && !current_buffer
->clip_changed
11885 && !current_buffer
->prevent_redisplay_optimizations_p
11886 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11887 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11888 /* Make sure recorded data applies to current buffer, etc. */
11889 && this_line_buffer
== current_buffer
11890 && current_buffer
== XBUFFER (w
->buffer
)
11891 && NILP (w
->force_start
)
11892 && NILP (w
->optional_new_start
)
11893 /* Point must be on the line that we have info recorded about. */
11894 && PT
>= CHARPOS (tlbufpos
)
11895 && PT
<= Z
- CHARPOS (tlendpos
)
11896 /* All text outside that line, including its final newline,
11897 must be unchanged. */
11898 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11899 CHARPOS (tlendpos
)))
11901 if (CHARPOS (tlbufpos
) > BEGV
11902 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11903 && (CHARPOS (tlbufpos
) == ZV
11904 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11905 /* Former continuation line has disappeared by becoming empty. */
11907 else if (XFASTINT (w
->last_modified
) < MODIFF
11908 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11909 || MINI_WINDOW_P (w
))
11911 /* We have to handle the case of continuation around a
11912 wide-column character (see the comment in indent.c around
11915 For instance, in the following case:
11917 -------- Insert --------
11918 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11919 J_I_ ==> J_I_ `^^' are cursors.
11923 As we have to redraw the line above, we cannot use this
11927 int line_height_before
= this_line_pixel_height
;
11929 /* Note that start_display will handle the case that the
11930 line starting at tlbufpos is a continuation line. */
11931 start_display (&it
, w
, tlbufpos
);
11933 /* Implementation note: It this still necessary? */
11934 if (it
.current_x
!= this_line_start_x
)
11937 TRACE ((stderr
, "trying display optimization 1\n"));
11938 w
->cursor
.vpos
= -1;
11939 overlay_arrow_seen
= 0;
11940 it
.vpos
= this_line_vpos
;
11941 it
.current_y
= this_line_y
;
11942 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11943 display_line (&it
);
11945 /* If line contains point, is not continued,
11946 and ends at same distance from eob as before, we win. */
11947 if (w
->cursor
.vpos
>= 0
11948 /* Line is not continued, otherwise this_line_start_pos
11949 would have been set to 0 in display_line. */
11950 && CHARPOS (this_line_start_pos
)
11951 /* Line ends as before. */
11952 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11953 /* Line has same height as before. Otherwise other lines
11954 would have to be shifted up or down. */
11955 && this_line_pixel_height
== line_height_before
)
11957 /* If this is not the window's last line, we must adjust
11958 the charstarts of the lines below. */
11959 if (it
.current_y
< it
.last_visible_y
)
11961 struct glyph_row
*row
11962 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11963 EMACS_INT delta
, delta_bytes
;
11965 /* We used to distinguish between two cases here,
11966 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11967 when the line ends in a newline or the end of the
11968 buffer's accessible portion. But both cases did
11969 the same, so they were collapsed. */
11971 - CHARPOS (tlendpos
)
11972 - MATRIX_ROW_START_CHARPOS (row
));
11973 delta_bytes
= (Z_BYTE
11974 - BYTEPOS (tlendpos
)
11975 - MATRIX_ROW_START_BYTEPOS (row
));
11977 increment_matrix_positions (w
->current_matrix
,
11978 this_line_vpos
+ 1,
11979 w
->current_matrix
->nrows
,
11980 delta
, delta_bytes
);
11983 /* If this row displays text now but previously didn't,
11984 or vice versa, w->window_end_vpos may have to be
11986 if ((it
.glyph_row
- 1)->displays_text_p
)
11988 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11989 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11991 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11992 && this_line_vpos
> 0)
11993 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11994 w
->window_end_valid
= Qnil
;
11996 /* Update hint: No need to try to scroll in update_window. */
11997 w
->desired_matrix
->no_scrolling_p
= 1;
12000 *w
->desired_matrix
->method
= 0;
12001 debug_method_add (w
, "optimization 1");
12003 #ifdef HAVE_WINDOW_SYSTEM
12004 update_window_fringes (w
, 0);
12011 else if (/* Cursor position hasn't changed. */
12012 PT
== XFASTINT (w
->last_point
)
12013 /* Make sure the cursor was last displayed
12014 in this window. Otherwise we have to reposition it. */
12015 && 0 <= w
->cursor
.vpos
12016 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12020 do_pending_window_change (1);
12022 /* We used to always goto end_of_redisplay here, but this
12023 isn't enough if we have a blinking cursor. */
12024 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12025 goto end_of_redisplay
;
12029 /* If highlighting the region, or if the cursor is in the echo area,
12030 then we can't just move the cursor. */
12031 else if (! (!NILP (Vtransient_mark_mode
)
12032 && !NILP (current_buffer
->mark_active
))
12033 && (EQ (selected_window
, current_buffer
->last_selected_window
)
12034 || highlight_nonselected_windows
)
12035 && NILP (w
->region_showing
)
12036 && NILP (Vshow_trailing_whitespace
)
12037 && !cursor_in_echo_area
)
12040 struct glyph_row
*row
;
12042 /* Skip from tlbufpos to PT and see where it is. Note that
12043 PT may be in invisible text. If so, we will end at the
12044 next visible position. */
12045 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12046 NULL
, DEFAULT_FACE_ID
);
12047 it
.current_x
= this_line_start_x
;
12048 it
.current_y
= this_line_y
;
12049 it
.vpos
= this_line_vpos
;
12051 /* The call to move_it_to stops in front of PT, but
12052 moves over before-strings. */
12053 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12055 if (it
.vpos
== this_line_vpos
12056 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12059 xassert (this_line_vpos
== it
.vpos
);
12060 xassert (this_line_y
== it
.current_y
);
12061 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12063 *w
->desired_matrix
->method
= 0;
12064 debug_method_add (w
, "optimization 3");
12073 /* Text changed drastically or point moved off of line. */
12074 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12077 CHARPOS (this_line_start_pos
) = 0;
12078 consider_all_windows_p
|= buffer_shared
> 1;
12079 ++clear_face_cache_count
;
12080 #ifdef HAVE_WINDOW_SYSTEM
12081 ++clear_image_cache_count
;
12084 /* Build desired matrices, and update the display. If
12085 consider_all_windows_p is non-zero, do it for all windows on all
12086 frames. Otherwise do it for selected_window, only. */
12088 if (consider_all_windows_p
)
12090 Lisp_Object tail
, frame
;
12092 FOR_EACH_FRAME (tail
, frame
)
12093 XFRAME (frame
)->updated_p
= 0;
12095 /* Recompute # windows showing selected buffer. This will be
12096 incremented each time such a window is displayed. */
12099 FOR_EACH_FRAME (tail
, frame
)
12101 struct frame
*f
= XFRAME (frame
);
12103 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12105 if (! EQ (frame
, selected_frame
))
12106 /* Select the frame, for the sake of frame-local
12108 select_frame_for_redisplay (frame
);
12110 /* Mark all the scroll bars to be removed; we'll redeem
12111 the ones we want when we redisplay their windows. */
12112 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12113 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12115 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12116 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12118 /* The X error handler may have deleted that frame. */
12119 if (!FRAME_LIVE_P (f
))
12122 /* Any scroll bars which redisplay_windows should have
12123 nuked should now go away. */
12124 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12125 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12127 /* If fonts changed, display again. */
12128 /* ??? rms: I suspect it is a mistake to jump all the way
12129 back to retry here. It should just retry this frame. */
12130 if (fonts_changed_p
)
12133 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12135 /* See if we have to hscroll. */
12136 if (!f
->already_hscrolled_p
)
12138 f
->already_hscrolled_p
= 1;
12139 if (hscroll_windows (f
->root_window
))
12143 /* Prevent various kinds of signals during display
12144 update. stdio is not robust about handling
12145 signals, which can cause an apparent I/O
12147 if (interrupt_input
)
12148 unrequest_sigio ();
12151 /* Update the display. */
12152 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12153 pause
|= update_frame (f
, 0, 0);
12159 if (!EQ (old_frame
, selected_frame
)
12160 && FRAME_LIVE_P (XFRAME (old_frame
)))
12161 /* We played a bit fast-and-loose above and allowed selected_frame
12162 and selected_window to be temporarily out-of-sync but let's make
12163 sure this stays contained. */
12164 select_frame_for_redisplay (old_frame
);
12165 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12169 /* Do the mark_window_display_accurate after all windows have
12170 been redisplayed because this call resets flags in buffers
12171 which are needed for proper redisplay. */
12172 FOR_EACH_FRAME (tail
, frame
)
12174 struct frame
*f
= XFRAME (frame
);
12177 mark_window_display_accurate (f
->root_window
, 1);
12178 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12179 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12184 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12186 Lisp_Object mini_window
;
12187 struct frame
*mini_frame
;
12189 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12190 /* Use list_of_error, not Qerror, so that
12191 we catch only errors and don't run the debugger. */
12192 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12194 redisplay_window_error
);
12196 /* Compare desired and current matrices, perform output. */
12199 /* If fonts changed, display again. */
12200 if (fonts_changed_p
)
12203 /* Prevent various kinds of signals during display update.
12204 stdio is not robust about handling signals,
12205 which can cause an apparent I/O error. */
12206 if (interrupt_input
)
12207 unrequest_sigio ();
12210 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12212 if (hscroll_windows (selected_window
))
12215 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12216 pause
= update_frame (sf
, 0, 0);
12219 /* We may have called echo_area_display at the top of this
12220 function. If the echo area is on another frame, that may
12221 have put text on a frame other than the selected one, so the
12222 above call to update_frame would not have caught it. Catch
12224 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12225 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12227 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12229 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12230 pause
|= update_frame (mini_frame
, 0, 0);
12231 if (!pause
&& hscroll_windows (mini_window
))
12236 /* If display was paused because of pending input, make sure we do a
12237 thorough update the next time. */
12240 /* Prevent the optimization at the beginning of
12241 redisplay_internal that tries a single-line update of the
12242 line containing the cursor in the selected window. */
12243 CHARPOS (this_line_start_pos
) = 0;
12245 /* Let the overlay arrow be updated the next time. */
12246 update_overlay_arrows (0);
12248 /* If we pause after scrolling, some rows in the current
12249 matrices of some windows are not valid. */
12250 if (!WINDOW_FULL_WIDTH_P (w
)
12251 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12252 update_mode_lines
= 1;
12256 if (!consider_all_windows_p
)
12258 /* This has already been done above if
12259 consider_all_windows_p is set. */
12260 mark_window_display_accurate_1 (w
, 1);
12262 /* Say overlay arrows are up to date. */
12263 update_overlay_arrows (1);
12265 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12266 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12269 update_mode_lines
= 0;
12270 windows_or_buffers_changed
= 0;
12271 cursor_type_changed
= 0;
12274 /* Start SIGIO interrupts coming again. Having them off during the
12275 code above makes it less likely one will discard output, but not
12276 impossible, since there might be stuff in the system buffer here.
12277 But it is much hairier to try to do anything about that. */
12278 if (interrupt_input
)
12282 /* If a frame has become visible which was not before, redisplay
12283 again, so that we display it. Expose events for such a frame
12284 (which it gets when becoming visible) don't call the parts of
12285 redisplay constructing glyphs, so simply exposing a frame won't
12286 display anything in this case. So, we have to display these
12287 frames here explicitly. */
12290 Lisp_Object tail
, frame
;
12293 FOR_EACH_FRAME (tail
, frame
)
12295 int this_is_visible
= 0;
12297 if (XFRAME (frame
)->visible
)
12298 this_is_visible
= 1;
12299 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12300 if (XFRAME (frame
)->visible
)
12301 this_is_visible
= 1;
12303 if (this_is_visible
)
12307 if (new_count
!= number_of_visible_frames
)
12308 windows_or_buffers_changed
++;
12311 /* Change frame size now if a change is pending. */
12312 do_pending_window_change (1);
12314 /* If we just did a pending size change, or have additional
12315 visible frames, redisplay again. */
12316 if (windows_or_buffers_changed
&& !pause
)
12319 /* Clear the face and image caches.
12321 We used to do this only if consider_all_windows_p. But the cache
12322 needs to be cleared if a timer creates images in the current
12323 buffer (e.g. the test case in Bug#6230). */
12325 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12327 clear_face_cache (0);
12328 clear_face_cache_count
= 0;
12331 #ifdef HAVE_WINDOW_SYSTEM
12332 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12334 clear_image_caches (Qnil
);
12335 clear_image_cache_count
= 0;
12337 #endif /* HAVE_WINDOW_SYSTEM */
12340 unbind_to (count
, Qnil
);
12345 /* Redisplay, but leave alone any recent echo area message unless
12346 another message has been requested in its place.
12348 This is useful in situations where you need to redisplay but no
12349 user action has occurred, making it inappropriate for the message
12350 area to be cleared. See tracking_off and
12351 wait_reading_process_output for examples of these situations.
12353 FROM_WHERE is an integer saying from where this function was
12354 called. This is useful for debugging. */
12357 redisplay_preserve_echo_area (int from_where
)
12359 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12361 if (!NILP (echo_area_buffer
[1]))
12363 /* We have a previously displayed message, but no current
12364 message. Redisplay the previous message. */
12365 display_last_displayed_message_p
= 1;
12366 redisplay_internal (1);
12367 display_last_displayed_message_p
= 0;
12370 redisplay_internal (1);
12372 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12373 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12374 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12378 /* Function registered with record_unwind_protect in
12379 redisplay_internal. Reset redisplaying_p to the value it had
12380 before redisplay_internal was called, and clear
12381 prevent_freeing_realized_faces_p. It also selects the previously
12382 selected frame, unless it has been deleted (by an X connection
12383 failure during redisplay, for example). */
12386 unwind_redisplay (Lisp_Object val
)
12388 Lisp_Object old_redisplaying_p
, old_frame
;
12390 old_redisplaying_p
= XCAR (val
);
12391 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12392 old_frame
= XCDR (val
);
12393 if (! EQ (old_frame
, selected_frame
)
12394 && FRAME_LIVE_P (XFRAME (old_frame
)))
12395 select_frame_for_redisplay (old_frame
);
12400 /* Mark the display of window W as accurate or inaccurate. If
12401 ACCURATE_P is non-zero mark display of W as accurate. If
12402 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12403 redisplay_internal is called. */
12406 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12408 if (BUFFERP (w
->buffer
))
12410 struct buffer
*b
= XBUFFER (w
->buffer
);
12413 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12414 w
->last_overlay_modified
12415 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12417 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12421 b
->clip_changed
= 0;
12422 b
->prevent_redisplay_optimizations_p
= 0;
12424 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12425 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12426 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12427 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12429 w
->current_matrix
->buffer
= b
;
12430 w
->current_matrix
->begv
= BUF_BEGV (b
);
12431 w
->current_matrix
->zv
= BUF_ZV (b
);
12433 w
->last_cursor
= w
->cursor
;
12434 w
->last_cursor_off_p
= w
->cursor_off_p
;
12436 if (w
== XWINDOW (selected_window
))
12437 w
->last_point
= make_number (BUF_PT (b
));
12439 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12445 w
->window_end_valid
= w
->buffer
;
12446 w
->update_mode_line
= Qnil
;
12451 /* Mark the display of windows in the window tree rooted at WINDOW as
12452 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12453 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12454 be redisplayed the next time redisplay_internal is called. */
12457 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12461 for (; !NILP (window
); window
= w
->next
)
12463 w
= XWINDOW (window
);
12464 mark_window_display_accurate_1 (w
, accurate_p
);
12466 if (!NILP (w
->vchild
))
12467 mark_window_display_accurate (w
->vchild
, accurate_p
);
12468 if (!NILP (w
->hchild
))
12469 mark_window_display_accurate (w
->hchild
, accurate_p
);
12474 update_overlay_arrows (1);
12478 /* Force a thorough redisplay the next time by setting
12479 last_arrow_position and last_arrow_string to t, which is
12480 unequal to any useful value of Voverlay_arrow_... */
12481 update_overlay_arrows (-1);
12486 /* Return value in display table DP (Lisp_Char_Table *) for character
12487 C. Since a display table doesn't have any parent, we don't have to
12488 follow parent. Do not call this function directly but use the
12489 macro DISP_CHAR_VECTOR. */
12492 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12496 if (ASCII_CHAR_P (c
))
12499 if (SUB_CHAR_TABLE_P (val
))
12500 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12506 XSETCHAR_TABLE (table
, dp
);
12507 val
= char_table_ref (table
, c
);
12516 /***********************************************************************
12518 ***********************************************************************/
12520 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12523 redisplay_windows (Lisp_Object window
)
12525 while (!NILP (window
))
12527 struct window
*w
= XWINDOW (window
);
12529 if (!NILP (w
->hchild
))
12530 redisplay_windows (w
->hchild
);
12531 else if (!NILP (w
->vchild
))
12532 redisplay_windows (w
->vchild
);
12533 else if (!NILP (w
->buffer
))
12535 displayed_buffer
= XBUFFER (w
->buffer
);
12536 /* Use list_of_error, not Qerror, so that
12537 we catch only errors and don't run the debugger. */
12538 internal_condition_case_1 (redisplay_window_0
, window
,
12540 redisplay_window_error
);
12548 redisplay_window_error (Lisp_Object ignore
)
12550 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12555 redisplay_window_0 (Lisp_Object window
)
12557 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12558 redisplay_window (window
, 0);
12563 redisplay_window_1 (Lisp_Object window
)
12565 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12566 redisplay_window (window
, 1);
12571 /* Increment GLYPH until it reaches END or CONDITION fails while
12572 adding (GLYPH)->pixel_width to X. */
12574 #define SKIP_GLYPHS(glyph, end, x, condition) \
12577 (x) += (glyph)->pixel_width; \
12580 while ((glyph) < (end) && (condition))
12583 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12584 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12585 which positions recorded in ROW differ from current buffer
12588 Return 0 if cursor is not on this row, 1 otherwise. */
12591 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
12592 struct glyph_matrix
*matrix
,
12593 EMACS_INT delta
, EMACS_INT delta_bytes
,
12596 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12597 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12598 struct glyph
*cursor
= NULL
;
12599 /* The last known character position in row. */
12600 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12602 EMACS_INT pt_old
= PT
- delta
;
12603 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12604 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12605 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12606 /* A glyph beyond the edge of TEXT_AREA which we should never
12608 struct glyph
*glyphs_end
= end
;
12609 /* Non-zero means we've found a match for cursor position, but that
12610 glyph has the avoid_cursor_p flag set. */
12611 int match_with_avoid_cursor
= 0;
12612 /* Non-zero means we've seen at least one glyph that came from a
12614 int string_seen
= 0;
12615 /* Largest and smalles buffer positions seen so far during scan of
12617 EMACS_INT bpos_max
= pos_before
;
12618 EMACS_INT bpos_min
= pos_after
;
12619 /* Last buffer position covered by an overlay string with an integer
12620 `cursor' property. */
12621 EMACS_INT bpos_covered
= 0;
12623 /* Skip over glyphs not having an object at the start and the end of
12624 the row. These are special glyphs like truncation marks on
12625 terminal frames. */
12626 if (row
->displays_text_p
)
12628 if (!row
->reversed_p
)
12631 && INTEGERP (glyph
->object
)
12632 && glyph
->charpos
< 0)
12634 x
+= glyph
->pixel_width
;
12638 && INTEGERP ((end
- 1)->object
)
12639 /* CHARPOS is zero for blanks and stretch glyphs
12640 inserted by extend_face_to_end_of_line. */
12641 && (end
- 1)->charpos
<= 0)
12643 glyph_before
= glyph
- 1;
12650 /* If the glyph row is reversed, we need to process it from back
12651 to front, so swap the edge pointers. */
12652 glyphs_end
= end
= glyph
- 1;
12653 glyph
+= row
->used
[TEXT_AREA
] - 1;
12655 while (glyph
> end
+ 1
12656 && INTEGERP (glyph
->object
)
12657 && glyph
->charpos
< 0)
12660 x
-= glyph
->pixel_width
;
12662 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12664 /* By default, in reversed rows we put the cursor on the
12665 rightmost (first in the reading order) glyph. */
12666 for (g
= end
+ 1; g
< glyph
; g
++)
12667 x
+= g
->pixel_width
;
12669 && INTEGERP ((end
+ 1)->object
)
12670 && (end
+ 1)->charpos
<= 0)
12672 glyph_before
= glyph
+ 1;
12676 else if (row
->reversed_p
)
12678 /* In R2L rows that don't display text, put the cursor on the
12679 rightmost glyph. Case in point: an empty last line that is
12680 part of an R2L paragraph. */
12682 /* Avoid placing the cursor on the last glyph of the row, where
12683 on terminal frames we hold the vertical border between
12684 adjacent windows. */
12685 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
12686 && !WINDOW_RIGHTMOST_P (w
)
12687 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
12689 x
= -1; /* will be computed below, at label compute_x */
12692 /* Step 1: Try to find the glyph whose character position
12693 corresponds to point. If that's not possible, find 2 glyphs
12694 whose character positions are the closest to point, one before
12695 point, the other after it. */
12696 if (!row
->reversed_p
)
12697 while (/* not marched to end of glyph row */
12699 /* glyph was not inserted by redisplay for internal purposes */
12700 && !INTEGERP (glyph
->object
))
12702 if (BUFFERP (glyph
->object
))
12704 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12706 if (glyph
->charpos
> bpos_max
)
12707 bpos_max
= glyph
->charpos
;
12708 if (glyph
->charpos
< bpos_min
)
12709 bpos_min
= glyph
->charpos
;
12710 if (!glyph
->avoid_cursor_p
)
12712 /* If we hit point, we've found the glyph on which to
12713 display the cursor. */
12716 match_with_avoid_cursor
= 0;
12719 /* See if we've found a better approximation to
12720 POS_BEFORE or to POS_AFTER. Note that we want the
12721 first (leftmost) glyph of all those that are the
12722 closest from below, and the last (rightmost) of all
12723 those from above. */
12724 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12726 pos_before
= glyph
->charpos
;
12727 glyph_before
= glyph
;
12729 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12731 pos_after
= glyph
->charpos
;
12732 glyph_after
= glyph
;
12735 else if (dpos
== 0)
12736 match_with_avoid_cursor
= 1;
12738 else if (STRINGP (glyph
->object
))
12740 Lisp_Object chprop
;
12741 EMACS_INT glyph_pos
= glyph
->charpos
;
12743 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12745 if (INTEGERP (chprop
))
12747 bpos_covered
= bpos_max
+ XINT (chprop
);
12748 /* If the `cursor' property covers buffer positions up
12749 to and including point, we should display cursor on
12750 this glyph. Note that overlays and text properties
12751 with string values stop bidi reordering, so every
12752 buffer position to the left of the string is always
12753 smaller than any position to the right of the
12754 string. Therefore, if a `cursor' property on one
12755 of the string's characters has an integer value, we
12756 will break out of the loop below _before_ we get to
12757 the position match above. IOW, integer values of
12758 the `cursor' property override the "exact match for
12759 point" strategy of positioning the cursor. */
12760 /* Implementation note: bpos_max == pt_old when, e.g.,
12761 we are in an empty line, where bpos_max is set to
12762 MATRIX_ROW_START_CHARPOS, see above. */
12763 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12772 x
+= glyph
->pixel_width
;
12775 else if (glyph
> end
) /* row is reversed */
12776 while (!INTEGERP (glyph
->object
))
12778 if (BUFFERP (glyph
->object
))
12780 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12782 if (glyph
->charpos
> bpos_max
)
12783 bpos_max
= glyph
->charpos
;
12784 if (glyph
->charpos
< bpos_min
)
12785 bpos_min
= glyph
->charpos
;
12786 if (!glyph
->avoid_cursor_p
)
12790 match_with_avoid_cursor
= 0;
12793 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12795 pos_before
= glyph
->charpos
;
12796 glyph_before
= glyph
;
12798 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12800 pos_after
= glyph
->charpos
;
12801 glyph_after
= glyph
;
12804 else if (dpos
== 0)
12805 match_with_avoid_cursor
= 1;
12807 else if (STRINGP (glyph
->object
))
12809 Lisp_Object chprop
;
12810 EMACS_INT glyph_pos
= glyph
->charpos
;
12812 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12814 if (INTEGERP (chprop
))
12816 bpos_covered
= bpos_max
+ XINT (chprop
);
12817 /* If the `cursor' property covers buffer positions up
12818 to and including point, we should display cursor on
12820 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12829 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
12831 x
--; /* can't use any pixel_width */
12834 x
-= glyph
->pixel_width
;
12837 /* Step 2: If we didn't find an exact match for point, we need to
12838 look for a proper place to put the cursor among glyphs between
12839 GLYPH_BEFORE and GLYPH_AFTER. */
12840 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12841 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12842 && bpos_covered
< pt_old
)
12844 /* An empty line has a single glyph whose OBJECT is zero and
12845 whose CHARPOS is the position of a newline on that line.
12846 Note that on a TTY, there are more glyphs after that, which
12847 were produced by extend_face_to_end_of_line, but their
12848 CHARPOS is zero or negative. */
12850 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12851 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
12853 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12855 EMACS_INT ellipsis_pos
;
12857 /* Scan back over the ellipsis glyphs. */
12858 if (!row
->reversed_p
)
12860 ellipsis_pos
= (glyph
- 1)->charpos
;
12861 while (glyph
> row
->glyphs
[TEXT_AREA
]
12862 && (glyph
- 1)->charpos
== ellipsis_pos
)
12863 glyph
--, x
-= glyph
->pixel_width
;
12864 /* That loop always goes one position too far, including
12865 the glyph before the ellipsis. So scan forward over
12867 x
+= glyph
->pixel_width
;
12870 else /* row is reversed */
12872 ellipsis_pos
= (glyph
+ 1)->charpos
;
12873 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12874 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12875 glyph
++, x
+= glyph
->pixel_width
;
12876 x
-= glyph
->pixel_width
;
12880 else if (match_with_avoid_cursor
12881 /* A truncated row may not include PT among its
12882 character positions. Setting the cursor inside the
12883 scroll margin will trigger recalculation of hscroll
12884 in hscroll_window_tree. */
12885 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
12886 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
12887 /* Zero-width characters produce no glyphs. */
12890 && (row
->reversed_p
12891 ? glyph_after
> glyphs_end
12892 : glyph_after
< glyphs_end
)))
12894 cursor
= glyph_after
;
12897 else if (string_seen
)
12899 int incr
= row
->reversed_p
? -1 : +1;
12901 /* Need to find the glyph that came out of a string which is
12902 present at point. That glyph is somewhere between
12903 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12904 positioned between POS_BEFORE and POS_AFTER in the
12906 struct glyph
*stop
= glyph_after
;
12907 EMACS_INT pos
= pos_before
;
12910 for (glyph
= glyph_before
+ incr
;
12911 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12914 /* Any glyphs that come from the buffer are here because
12915 of bidi reordering. Skip them, and only pay
12916 attention to glyphs that came from some string. */
12917 if (STRINGP (glyph
->object
))
12922 str
= glyph
->object
;
12923 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12924 if (tem
== 0 /* from overlay */
12927 /* If the string from which this glyph came is
12928 found in the buffer at point, then we've
12929 found the glyph we've been looking for. If
12930 it comes from an overlay (tem == 0), and it
12931 has the `cursor' property on one of its
12932 glyphs, record that glyph as a candidate for
12933 displaying the cursor. (As in the
12934 unidirectional version, we will display the
12935 cursor on the last candidate we find.) */
12936 if (tem
== 0 || tem
== pt_old
)
12938 /* The glyphs from this string could have
12939 been reordered. Find the one with the
12940 smallest string position. Or there could
12941 be a character in the string with the
12942 `cursor' property, which means display
12943 cursor on that character's glyph. */
12944 EMACS_INT strpos
= glyph
->charpos
;
12949 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12950 && EQ (glyph
->object
, str
);
12954 EMACS_INT gpos
= glyph
->charpos
;
12956 cprop
= Fget_char_property (make_number (gpos
),
12964 if (tem
&& glyph
->charpos
< strpos
)
12966 strpos
= glyph
->charpos
;
12975 pos
= tem
+ 1; /* don't find previous instances */
12977 /* This string is not what we want; skip all of the
12978 glyphs that came from it. */
12979 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12980 && EQ (glyph
->object
, str
))
12987 /* If we reached the end of the line, and END was from a string,
12988 the cursor is not on this line. */
12990 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
12991 && STRINGP (end
->object
)
12992 && row
->continued_p
)
12998 if (cursor
!= NULL
)
13004 /* Need to compute x that corresponds to GLYPH. */
13005 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
13007 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
13009 x
+= g
->pixel_width
;
13013 /* ROW could be part of a continued line, which, under bidi
13014 reordering, might have other rows whose start and end charpos
13015 occlude point. Only set w->cursor if we found a better
13016 approximation to the cursor position than we have from previously
13017 examined candidate rows belonging to the same continued line. */
13018 if (/* we already have a candidate row */
13019 w
->cursor
.vpos
>= 0
13020 /* that candidate is not the row we are processing */
13021 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
13022 /* the row we are processing is part of a continued line */
13023 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
13024 /* Make sure cursor.vpos specifies a row whose start and end
13025 charpos occlude point. This is because some callers of this
13026 function leave cursor.vpos at the row where the cursor was
13027 displayed during the last redisplay cycle. */
13028 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13029 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13032 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13034 /* Don't consider glyphs that are outside TEXT_AREA. */
13035 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13037 /* Keep the candidate whose buffer position is the closest to
13039 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13040 w
->cursor
.hpos
>= 0
13041 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13042 && BUFFERP (g1
->object
)
13043 && (g1
->charpos
== pt_old
/* an exact match always wins */
13044 || (BUFFERP (glyph
->object
)
13045 && eabs (g1
->charpos
- pt_old
)
13046 < eabs (glyph
->charpos
- pt_old
))))
13048 /* If this candidate gives an exact match, use that. */
13049 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13050 /* Otherwise, keep the candidate that comes from a row
13051 spanning less buffer positions. This may win when one or
13052 both candidate positions are on glyphs that came from
13053 display strings, for which we cannot compare buffer
13055 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13056 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13057 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13060 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13062 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13063 w
->cursor
.y
= row
->y
+ dy
;
13065 if (w
== XWINDOW (selected_window
))
13067 if (!row
->continued_p
13068 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13071 this_line_buffer
= XBUFFER (w
->buffer
);
13073 CHARPOS (this_line_start_pos
)
13074 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13075 BYTEPOS (this_line_start_pos
)
13076 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13078 CHARPOS (this_line_end_pos
)
13079 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13080 BYTEPOS (this_line_end_pos
)
13081 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13083 this_line_y
= w
->cursor
.y
;
13084 this_line_pixel_height
= row
->height
;
13085 this_line_vpos
= w
->cursor
.vpos
;
13086 this_line_start_x
= row
->x
;
13089 CHARPOS (this_line_start_pos
) = 0;
13096 /* Run window scroll functions, if any, for WINDOW with new window
13097 start STARTP. Sets the window start of WINDOW to that position.
13099 We assume that the window's buffer is really current. */
13101 static INLINE
struct text_pos
13102 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13104 struct window
*w
= XWINDOW (window
);
13105 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13107 if (current_buffer
!= XBUFFER (w
->buffer
))
13110 if (!NILP (Vwindow_scroll_functions
))
13112 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13113 make_number (CHARPOS (startp
)));
13114 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13115 /* In case the hook functions switch buffers. */
13116 if (current_buffer
!= XBUFFER (w
->buffer
))
13117 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13124 /* Make sure the line containing the cursor is fully visible.
13125 A value of 1 means there is nothing to be done.
13126 (Either the line is fully visible, or it cannot be made so,
13127 or we cannot tell.)
13129 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13130 is higher than window.
13132 A value of 0 means the caller should do scrolling
13133 as if point had gone off the screen. */
13136 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13138 struct glyph_matrix
*matrix
;
13139 struct glyph_row
*row
;
13142 if (!make_cursor_line_fully_visible_p
)
13145 /* It's not always possible to find the cursor, e.g, when a window
13146 is full of overlay strings. Don't do anything in that case. */
13147 if (w
->cursor
.vpos
< 0)
13150 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13151 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13153 /* If the cursor row is not partially visible, there's nothing to do. */
13154 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13157 /* If the row the cursor is in is taller than the window's height,
13158 it's not clear what to do, so do nothing. */
13159 window_height
= window_box_height (w
);
13160 if (row
->height
>= window_height
)
13162 if (!force_p
|| MINI_WINDOW_P (w
)
13163 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13170 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13171 non-zero means only WINDOW is redisplayed in redisplay_internal.
13172 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13173 in redisplay_window to bring a partially visible line into view in
13174 the case that only the cursor has moved.
13176 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13177 last screen line's vertical height extends past the end of the screen.
13181 1 if scrolling succeeded
13183 0 if scrolling didn't find point.
13185 -1 if new fonts have been loaded so that we must interrupt
13186 redisplay, adjust glyph matrices, and try again. */
13192 SCROLLING_NEED_LARGER_MATRICES
13196 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13197 EMACS_INT scroll_conservatively
, EMACS_INT scroll_step
,
13198 int temp_scroll_step
, int last_line_misfit
)
13200 struct window
*w
= XWINDOW (window
);
13201 struct frame
*f
= XFRAME (w
->frame
);
13202 struct text_pos pos
, startp
;
13204 int this_scroll_margin
, scroll_max
, rc
, height
;
13205 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13206 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13207 Lisp_Object aggressive
;
13208 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13211 debug_method_add (w
, "try_scrolling");
13214 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13216 /* Compute scroll margin height in pixels. We scroll when point is
13217 within this distance from the top or bottom of the window. */
13218 if (scroll_margin
> 0)
13219 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13220 * FRAME_LINE_HEIGHT (f
);
13222 this_scroll_margin
= 0;
13224 /* Force scroll_conservatively to have a reasonable value, to avoid
13225 overflow while computing how much to scroll. Note that the user
13226 can supply scroll-conservatively equal to `most-positive-fixnum',
13227 which can be larger than INT_MAX. */
13228 if (scroll_conservatively
> scroll_limit
)
13230 scroll_conservatively
= scroll_limit
;
13231 scroll_max
= INT_MAX
;
13233 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13234 /* Compute how much we should try to scroll maximally to bring
13235 point into view. */
13236 scroll_max
= (max (scroll_step
,
13237 max (scroll_conservatively
, temp_scroll_step
))
13238 * FRAME_LINE_HEIGHT (f
));
13239 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13240 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13241 /* We're trying to scroll because of aggressive scrolling but no
13242 scroll_step is set. Choose an arbitrary one. */
13243 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13249 /* Decide whether to scroll down. */
13250 if (PT
> CHARPOS (startp
))
13252 int scroll_margin_y
;
13254 /* Compute the pixel ypos of the scroll margin, then move it to
13255 either that ypos or PT, whichever comes first. */
13256 start_display (&it
, w
, startp
);
13257 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13258 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13259 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13260 (MOVE_TO_POS
| MOVE_TO_Y
));
13262 if (PT
> CHARPOS (it
.current
.pos
))
13264 int y0
= line_bottom_y (&it
);
13265 /* Compute how many pixels below window bottom to stop searching
13266 for PT. This avoids costly search for PT that is far away if
13267 the user limited scrolling by a small number of lines, but
13268 always finds PT if scroll_conservatively is set to a large
13269 number, such as most-positive-fixnum. */
13270 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13272 slack
>= INT_MAX
- it
.last_visible_y
13274 : it
.last_visible_y
+ slack
;
13276 /* Compute the distance from the scroll margin to PT or to
13277 the scroll limit, whichever comes first. This should
13278 include the height of the cursor line, to make that line
13280 move_it_to (&it
, PT
, -1, y_to_move
,
13281 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13282 dy
= line_bottom_y (&it
) - y0
;
13284 if (dy
> scroll_max
)
13285 return SCROLLING_FAILED
;
13293 /* Point is in or below the bottom scroll margin, so move the
13294 window start down. If scrolling conservatively, move it just
13295 enough down to make point visible. If scroll_step is set,
13296 move it down by scroll_step. */
13297 if (scroll_conservatively
)
13299 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13300 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13301 else if (scroll_step
|| temp_scroll_step
)
13302 amount_to_scroll
= scroll_max
;
13305 aggressive
= current_buffer
->scroll_up_aggressively
;
13306 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13307 if (NUMBERP (aggressive
))
13309 double float_amount
= XFLOATINT (aggressive
) * height
;
13310 amount_to_scroll
= float_amount
;
13311 if (amount_to_scroll
== 0 && float_amount
> 0)
13312 amount_to_scroll
= 1;
13316 if (amount_to_scroll
<= 0)
13317 return SCROLLING_FAILED
;
13319 start_display (&it
, w
, startp
);
13320 if (scroll_max
< INT_MAX
)
13321 move_it_vertically (&it
, amount_to_scroll
);
13324 /* Extra precision for users who set scroll-conservatively
13325 to most-positive-fixnum: make sure the amount we scroll
13326 the window start is never less than amount_to_scroll,
13327 which was computed as distance from window bottom to
13328 point. This matters when lines at window top and lines
13329 below window bottom have different height. */
13330 struct it it1
= it
;
13331 /* We use a temporary it1 because line_bottom_y can modify
13332 its argument, if it moves one line down; see there. */
13333 int start_y
= line_bottom_y (&it1
);
13336 move_it_by_lines (&it
, 1, 1);
13338 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13341 /* If STARTP is unchanged, move it down another screen line. */
13342 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13343 move_it_by_lines (&it
, 1, 1);
13344 startp
= it
.current
.pos
;
13348 struct text_pos scroll_margin_pos
= startp
;
13350 /* See if point is inside the scroll margin at the top of the
13352 if (this_scroll_margin
)
13354 start_display (&it
, w
, startp
);
13355 move_it_vertically (&it
, this_scroll_margin
);
13356 scroll_margin_pos
= it
.current
.pos
;
13359 if (PT
< CHARPOS (scroll_margin_pos
))
13361 /* Point is in the scroll margin at the top of the window or
13362 above what is displayed in the window. */
13365 /* Compute the vertical distance from PT to the scroll
13366 margin position. Give up if distance is greater than
13368 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13369 start_display (&it
, w
, pos
);
13371 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13372 it
.last_visible_y
, -1,
13373 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13374 dy
= it
.current_y
- y0
;
13375 if (dy
> scroll_max
)
13376 return SCROLLING_FAILED
;
13378 /* Compute new window start. */
13379 start_display (&it
, w
, startp
);
13381 if (scroll_conservatively
)
13383 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13384 else if (scroll_step
|| temp_scroll_step
)
13385 amount_to_scroll
= scroll_max
;
13388 aggressive
= current_buffer
->scroll_down_aggressively
;
13389 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13390 if (NUMBERP (aggressive
))
13392 double float_amount
= XFLOATINT (aggressive
) * height
;
13393 amount_to_scroll
= float_amount
;
13394 if (amount_to_scroll
== 0 && float_amount
> 0)
13395 amount_to_scroll
= 1;
13399 if (amount_to_scroll
<= 0)
13400 return SCROLLING_FAILED
;
13402 move_it_vertically_backward (&it
, amount_to_scroll
);
13403 startp
= it
.current
.pos
;
13407 /* Run window scroll functions. */
13408 startp
= run_window_scroll_functions (window
, startp
);
13410 /* Display the window. Give up if new fonts are loaded, or if point
13412 if (!try_window (window
, startp
, 0))
13413 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13414 else if (w
->cursor
.vpos
< 0)
13416 clear_glyph_matrix (w
->desired_matrix
);
13417 rc
= SCROLLING_FAILED
;
13421 /* Maybe forget recorded base line for line number display. */
13422 if (!just_this_one_p
13423 || current_buffer
->clip_changed
13424 || BEG_UNCHANGED
< CHARPOS (startp
))
13425 w
->base_line_number
= Qnil
;
13427 /* If cursor ends up on a partially visible line,
13428 treat that as being off the bottom of the screen. */
13429 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13431 clear_glyph_matrix (w
->desired_matrix
);
13432 ++extra_scroll_margin_lines
;
13435 rc
= SCROLLING_SUCCESS
;
13442 /* Compute a suitable window start for window W if display of W starts
13443 on a continuation line. Value is non-zero if a new window start
13446 The new window start will be computed, based on W's width, starting
13447 from the start of the continued line. It is the start of the
13448 screen line with the minimum distance from the old start W->start. */
13451 compute_window_start_on_continuation_line (struct window
*w
)
13453 struct text_pos pos
, start_pos
;
13454 int window_start_changed_p
= 0;
13456 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13458 /* If window start is on a continuation line... Window start may be
13459 < BEGV in case there's invisible text at the start of the
13460 buffer (M-x rmail, for example). */
13461 if (CHARPOS (start_pos
) > BEGV
13462 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13465 struct glyph_row
*row
;
13467 /* Handle the case that the window start is out of range. */
13468 if (CHARPOS (start_pos
) < BEGV
)
13469 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13470 else if (CHARPOS (start_pos
) > ZV
)
13471 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13473 /* Find the start of the continued line. This should be fast
13474 because scan_buffer is fast (newline cache). */
13475 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13476 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13477 row
, DEFAULT_FACE_ID
);
13478 reseat_at_previous_visible_line_start (&it
);
13480 /* If the line start is "too far" away from the window start,
13481 say it takes too much time to compute a new window start. */
13482 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13483 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13485 int min_distance
, distance
;
13487 /* Move forward by display lines to find the new window
13488 start. If window width was enlarged, the new start can
13489 be expected to be > the old start. If window width was
13490 decreased, the new window start will be < the old start.
13491 So, we're looking for the display line start with the
13492 minimum distance from the old window start. */
13493 pos
= it
.current
.pos
;
13494 min_distance
= INFINITY
;
13495 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13496 distance
< min_distance
)
13498 min_distance
= distance
;
13499 pos
= it
.current
.pos
;
13500 move_it_by_lines (&it
, 1, 0);
13503 /* Set the window start there. */
13504 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13505 window_start_changed_p
= 1;
13509 return window_start_changed_p
;
13513 /* Try cursor movement in case text has not changed in window WINDOW,
13514 with window start STARTP. Value is
13516 CURSOR_MOVEMENT_SUCCESS if successful
13518 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13520 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13521 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13522 we want to scroll as if scroll-step were set to 1. See the code.
13524 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13525 which case we have to abort this redisplay, and adjust matrices
13530 CURSOR_MOVEMENT_SUCCESS
,
13531 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13532 CURSOR_MOVEMENT_MUST_SCROLL
,
13533 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13537 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13539 struct window
*w
= XWINDOW (window
);
13540 struct frame
*f
= XFRAME (w
->frame
);
13541 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13544 if (inhibit_try_cursor_movement
)
13548 /* Handle case where text has not changed, only point, and it has
13549 not moved off the frame. */
13550 if (/* Point may be in this window. */
13551 PT
>= CHARPOS (startp
)
13552 /* Selective display hasn't changed. */
13553 && !current_buffer
->clip_changed
13554 /* Function force-mode-line-update is used to force a thorough
13555 redisplay. It sets either windows_or_buffers_changed or
13556 update_mode_lines. So don't take a shortcut here for these
13558 && !update_mode_lines
13559 && !windows_or_buffers_changed
13560 && !cursor_type_changed
13561 /* Can't use this case if highlighting a region. When a
13562 region exists, cursor movement has to do more than just
13564 && !(!NILP (Vtransient_mark_mode
)
13565 && !NILP (current_buffer
->mark_active
))
13566 && NILP (w
->region_showing
)
13567 && NILP (Vshow_trailing_whitespace
)
13568 /* Right after splitting windows, last_point may be nil. */
13569 && INTEGERP (w
->last_point
)
13570 /* This code is not used for mini-buffer for the sake of the case
13571 of redisplaying to replace an echo area message; since in
13572 that case the mini-buffer contents per se are usually
13573 unchanged. This code is of no real use in the mini-buffer
13574 since the handling of this_line_start_pos, etc., in redisplay
13575 handles the same cases. */
13576 && !EQ (window
, minibuf_window
)
13577 /* When splitting windows or for new windows, it happens that
13578 redisplay is called with a nil window_end_vpos or one being
13579 larger than the window. This should really be fixed in
13580 window.c. I don't have this on my list, now, so we do
13581 approximately the same as the old redisplay code. --gerd. */
13582 && INTEGERP (w
->window_end_vpos
)
13583 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13584 && (FRAME_WINDOW_P (f
)
13585 || !overlay_arrow_in_current_buffer_p ()))
13587 int this_scroll_margin
, top_scroll_margin
;
13588 struct glyph_row
*row
= NULL
;
13591 debug_method_add (w
, "cursor movement");
13594 /* Scroll if point within this distance from the top or bottom
13595 of the window. This is a pixel value. */
13596 if (scroll_margin
> 0)
13598 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13599 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13602 this_scroll_margin
= 0;
13604 top_scroll_margin
= this_scroll_margin
;
13605 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13606 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13608 /* Start with the row the cursor was displayed during the last
13609 not paused redisplay. Give up if that row is not valid. */
13610 if (w
->last_cursor
.vpos
< 0
13611 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13612 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13615 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13616 if (row
->mode_line_p
)
13618 if (!row
->enabled_p
)
13619 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13622 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13624 int scroll_p
= 0, must_scroll
= 0;
13625 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13627 if (PT
> XFASTINT (w
->last_point
))
13629 /* Point has moved forward. */
13630 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13631 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13633 xassert (row
->enabled_p
);
13637 /* If the end position of a row equals the start
13638 position of the next row, and PT is at that position,
13639 we would rather display cursor in the next line. */
13640 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13641 && MATRIX_ROW_END_CHARPOS (row
) == PT
13642 && row
< w
->current_matrix
->rows
13643 + w
->current_matrix
->nrows
- 1
13644 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
13645 && !cursor_row_p (w
, row
))
13648 /* If within the scroll margin, scroll. Note that
13649 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13650 the next line would be drawn, and that
13651 this_scroll_margin can be zero. */
13652 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13653 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13654 /* Line is completely visible last line in window
13655 and PT is to be set in the next line. */
13656 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13657 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13658 && !row
->ends_at_zv_p
13659 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13662 else if (PT
< XFASTINT (w
->last_point
))
13664 /* Cursor has to be moved backward. Note that PT >=
13665 CHARPOS (startp) because of the outer if-statement. */
13666 while (!row
->mode_line_p
13667 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13668 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13669 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13670 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13671 row
> w
->current_matrix
->rows
13672 && (row
-1)->ends_in_newline_from_string_p
))))
13673 && (row
->y
> top_scroll_margin
13674 || CHARPOS (startp
) == BEGV
))
13676 xassert (row
->enabled_p
);
13680 /* Consider the following case: Window starts at BEGV,
13681 there is invisible, intangible text at BEGV, so that
13682 display starts at some point START > BEGV. It can
13683 happen that we are called with PT somewhere between
13684 BEGV and START. Try to handle that case. */
13685 if (row
< w
->current_matrix
->rows
13686 || row
->mode_line_p
)
13688 row
= w
->current_matrix
->rows
;
13689 if (row
->mode_line_p
)
13693 /* Due to newlines in overlay strings, we may have to
13694 skip forward over overlay strings. */
13695 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13696 && MATRIX_ROW_END_CHARPOS (row
) == PT
13697 && !cursor_row_p (w
, row
))
13700 /* If within the scroll margin, scroll. */
13701 if (row
->y
< top_scroll_margin
13702 && CHARPOS (startp
) != BEGV
)
13707 /* Cursor did not move. So don't scroll even if cursor line
13708 is partially visible, as it was so before. */
13709 rc
= CURSOR_MOVEMENT_SUCCESS
;
13712 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13713 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13715 /* if PT is not in the glyph row, give up. */
13716 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13719 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13720 && !NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13722 /* If rows are bidi-reordered and point moved, back up
13723 until we find a row that does not belong to a
13724 continuation line. This is because we must consider
13725 all rows of a continued line as candidates for the
13726 new cursor positioning, since row start and end
13727 positions change non-linearly with vertical position
13729 /* FIXME: Revisit this when glyph ``spilling'' in
13730 continuation lines' rows is implemented for
13731 bidi-reordered rows. */
13732 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13734 xassert (row
->enabled_p
);
13736 /* If we hit the beginning of the displayed portion
13737 without finding the first row of a continued
13739 if (row
<= w
->current_matrix
->rows
)
13741 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13749 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13750 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13751 && make_cursor_line_fully_visible_p
)
13753 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13754 && !row
->ends_at_zv_p
13755 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13756 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13757 else if (row
->height
> window_box_height (w
))
13759 /* If we end up in a partially visible line, let's
13760 make it fully visible, except when it's taller
13761 than the window, in which case we can't do much
13764 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13768 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13769 if (!cursor_row_fully_visible_p (w
, 0, 1))
13770 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13772 rc
= CURSOR_MOVEMENT_SUCCESS
;
13776 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13777 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13778 && !NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13780 /* With bidi-reordered rows, there could be more than
13781 one candidate row whose start and end positions
13782 occlude point. We need to let set_cursor_from_row
13783 find the best candidate. */
13784 /* FIXME: Revisit this when glyph ``spilling'' in
13785 continuation lines' rows is implemented for
13786 bidi-reordered rows. */
13791 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
13792 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13793 && cursor_row_p (w
, row
))
13794 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13796 /* As soon as we've found the first suitable row
13797 whose ends_at_zv_p flag is set, we are done. */
13799 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13801 rc
= CURSOR_MOVEMENT_SUCCESS
;
13806 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
13807 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
13808 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13809 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
13810 /* If we didn't find any candidate rows, or exited the
13811 loop before all the candidates were examined, signal
13812 to the caller that this method failed. */
13813 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13814 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
13815 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13817 rc
= CURSOR_MOVEMENT_SUCCESS
;
13823 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13825 rc
= CURSOR_MOVEMENT_SUCCESS
;
13830 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13831 && MATRIX_ROW_START_CHARPOS (row
) == PT
13832 && cursor_row_p (w
, row
));
13841 set_vertical_scroll_bar (struct window
*w
)
13843 EMACS_INT start
, end
, whole
;
13845 /* Calculate the start and end positions for the current window.
13846 At some point, it would be nice to choose between scrollbars
13847 which reflect the whole buffer size, with special markers
13848 indicating narrowing, and scrollbars which reflect only the
13851 Note that mini-buffers sometimes aren't displaying any text. */
13852 if (!MINI_WINDOW_P (w
)
13853 || (w
== XWINDOW (minibuf_window
)
13854 && NILP (echo_area_buffer
[0])))
13856 struct buffer
*buf
= XBUFFER (w
->buffer
);
13857 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13858 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13859 /* I don't think this is guaranteed to be right. For the
13860 moment, we'll pretend it is. */
13861 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13865 if (whole
< (end
- start
))
13866 whole
= end
- start
;
13869 start
= end
= whole
= 0;
13871 /* Indicate what this scroll bar ought to be displaying now. */
13872 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13873 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13874 (w
, end
- start
, whole
, start
);
13878 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13879 selected_window is redisplayed.
13881 We can return without actually redisplaying the window if
13882 fonts_changed_p is nonzero. In that case, redisplay_internal will
13886 redisplay_window (Lisp_Object window
, int just_this_one_p
)
13888 struct window
*w
= XWINDOW (window
);
13889 struct frame
*f
= XFRAME (w
->frame
);
13890 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13891 struct buffer
*old
= current_buffer
;
13892 struct text_pos lpoint
, opoint
, startp
;
13893 int update_mode_line
;
13896 /* Record it now because it's overwritten. */
13897 int current_matrix_up_to_date_p
= 0;
13898 int used_current_matrix_p
= 0;
13899 /* This is less strict than current_matrix_up_to_date_p.
13900 It indictes that the buffer contents and narrowing are unchanged. */
13901 int buffer_unchanged_p
= 0;
13902 int temp_scroll_step
= 0;
13903 int count
= SPECPDL_INDEX ();
13905 int centering_position
= -1;
13906 int last_line_misfit
= 0;
13907 EMACS_INT beg_unchanged
, end_unchanged
;
13909 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13912 /* W must be a leaf window here. */
13913 xassert (!NILP (w
->buffer
));
13915 *w
->desired_matrix
->method
= 0;
13919 reconsider_clip_changes (w
, buffer
);
13921 /* Has the mode line to be updated? */
13922 update_mode_line
= (!NILP (w
->update_mode_line
)
13923 || update_mode_lines
13924 || buffer
->clip_changed
13925 || buffer
->prevent_redisplay_optimizations_p
);
13927 if (MINI_WINDOW_P (w
))
13929 if (w
== XWINDOW (echo_area_window
)
13930 && !NILP (echo_area_buffer
[0]))
13932 if (update_mode_line
)
13933 /* We may have to update a tty frame's menu bar or a
13934 tool-bar. Example `M-x C-h C-h C-g'. */
13935 goto finish_menu_bars
;
13937 /* We've already displayed the echo area glyphs in this window. */
13938 goto finish_scroll_bars
;
13940 else if ((w
!= XWINDOW (minibuf_window
)
13941 || minibuf_level
== 0)
13942 /* When buffer is nonempty, redisplay window normally. */
13943 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13944 /* Quail displays non-mini buffers in minibuffer window.
13945 In that case, redisplay the window normally. */
13946 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13948 /* W is a mini-buffer window, but it's not active, so clear
13950 int yb
= window_text_bottom_y (w
);
13951 struct glyph_row
*row
;
13954 for (y
= 0, row
= w
->desired_matrix
->rows
;
13956 y
+= row
->height
, ++row
)
13957 blank_row (w
, row
, y
);
13958 goto finish_scroll_bars
;
13961 clear_glyph_matrix (w
->desired_matrix
);
13964 /* Otherwise set up data on this window; select its buffer and point
13966 /* Really select the buffer, for the sake of buffer-local
13968 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13970 current_matrix_up_to_date_p
13971 = (!NILP (w
->window_end_valid
)
13972 && !current_buffer
->clip_changed
13973 && !current_buffer
->prevent_redisplay_optimizations_p
13974 && XFASTINT (w
->last_modified
) >= MODIFF
13975 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13977 /* Run the window-bottom-change-functions
13978 if it is possible that the text on the screen has changed
13979 (either due to modification of the text, or any other reason). */
13980 if (!current_matrix_up_to_date_p
13981 && !NILP (Vwindow_text_change_functions
))
13983 safe_run_hooks (Qwindow_text_change_functions
);
13987 beg_unchanged
= BEG_UNCHANGED
;
13988 end_unchanged
= END_UNCHANGED
;
13990 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13992 specbind (Qinhibit_point_motion_hooks
, Qt
);
13995 = (!NILP (w
->window_end_valid
)
13996 && !current_buffer
->clip_changed
13997 && XFASTINT (w
->last_modified
) >= MODIFF
13998 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14000 /* When windows_or_buffers_changed is non-zero, we can't rely on
14001 the window end being valid, so set it to nil there. */
14002 if (windows_or_buffers_changed
)
14004 /* If window starts on a continuation line, maybe adjust the
14005 window start in case the window's width changed. */
14006 if (XMARKER (w
->start
)->buffer
== current_buffer
)
14007 compute_window_start_on_continuation_line (w
);
14009 w
->window_end_valid
= Qnil
;
14012 /* Some sanity checks. */
14013 CHECK_WINDOW_END (w
);
14014 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14016 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14019 /* If %c is in mode line, update it if needed. */
14020 if (!NILP (w
->column_number_displayed
)
14021 /* This alternative quickly identifies a common case
14022 where no change is needed. */
14023 && !(PT
== XFASTINT (w
->last_point
)
14024 && XFASTINT (w
->last_modified
) >= MODIFF
14025 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14026 && (XFASTINT (w
->column_number_displayed
)
14027 != (int) current_column ())) /* iftc */
14028 update_mode_line
= 1;
14030 /* Count number of windows showing the selected buffer. An indirect
14031 buffer counts as its base buffer. */
14032 if (!just_this_one_p
)
14034 struct buffer
*current_base
, *window_base
;
14035 current_base
= current_buffer
;
14036 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14037 if (current_base
->base_buffer
)
14038 current_base
= current_base
->base_buffer
;
14039 if (window_base
->base_buffer
)
14040 window_base
= window_base
->base_buffer
;
14041 if (current_base
== window_base
)
14045 /* Point refers normally to the selected window. For any other
14046 window, set up appropriate value. */
14047 if (!EQ (window
, selected_window
))
14049 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14050 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14054 new_pt_byte
= BEGV_BYTE
;
14055 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14057 else if (new_pt
> (ZV
- 1))
14060 new_pt_byte
= ZV_BYTE
;
14061 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14064 /* We don't use SET_PT so that the point-motion hooks don't run. */
14065 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14068 /* If any of the character widths specified in the display table
14069 have changed, invalidate the width run cache. It's true that
14070 this may be a bit late to catch such changes, but the rest of
14071 redisplay goes (non-fatally) haywire when the display table is
14072 changed, so why should we worry about doing any better? */
14073 if (current_buffer
->width_run_cache
)
14075 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14077 if (! disptab_matches_widthtab (disptab
,
14078 XVECTOR (current_buffer
->width_table
)))
14080 invalidate_region_cache (current_buffer
,
14081 current_buffer
->width_run_cache
,
14083 recompute_width_table (current_buffer
, disptab
);
14087 /* If window-start is screwed up, choose a new one. */
14088 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14091 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14093 /* If someone specified a new starting point but did not insist,
14094 check whether it can be used. */
14095 if (!NILP (w
->optional_new_start
)
14096 && CHARPOS (startp
) >= BEGV
14097 && CHARPOS (startp
) <= ZV
)
14099 w
->optional_new_start
= Qnil
;
14100 start_display (&it
, w
, startp
);
14101 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14102 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14103 if (IT_CHARPOS (it
) == PT
)
14104 w
->force_start
= Qt
;
14105 /* IT may overshoot PT if text at PT is invisible. */
14106 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14107 w
->force_start
= Qt
;
14112 /* Handle case where place to start displaying has been specified,
14113 unless the specified location is outside the accessible range. */
14114 if (!NILP (w
->force_start
)
14115 || w
->frozen_window_start_p
)
14117 /* We set this later on if we have to adjust point. */
14120 w
->force_start
= Qnil
;
14122 w
->window_end_valid
= Qnil
;
14124 /* Forget any recorded base line for line number display. */
14125 if (!buffer_unchanged_p
)
14126 w
->base_line_number
= Qnil
;
14128 /* Redisplay the mode line. Select the buffer properly for that.
14129 Also, run the hook window-scroll-functions
14130 because we have scrolled. */
14131 /* Note, we do this after clearing force_start because
14132 if there's an error, it is better to forget about force_start
14133 than to get into an infinite loop calling the hook functions
14134 and having them get more errors. */
14135 if (!update_mode_line
14136 || ! NILP (Vwindow_scroll_functions
))
14138 update_mode_line
= 1;
14139 w
->update_mode_line
= Qt
;
14140 startp
= run_window_scroll_functions (window
, startp
);
14143 w
->last_modified
= make_number (0);
14144 w
->last_overlay_modified
= make_number (0);
14145 if (CHARPOS (startp
) < BEGV
)
14146 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14147 else if (CHARPOS (startp
) > ZV
)
14148 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14150 /* Redisplay, then check if cursor has been set during the
14151 redisplay. Give up if new fonts were loaded. */
14152 /* We used to issue a CHECK_MARGINS argument to try_window here,
14153 but this causes scrolling to fail when point begins inside
14154 the scroll margin (bug#148) -- cyd */
14155 if (!try_window (window
, startp
, 0))
14157 w
->force_start
= Qt
;
14158 clear_glyph_matrix (w
->desired_matrix
);
14159 goto need_larger_matrices
;
14162 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14164 /* If point does not appear, try to move point so it does
14165 appear. The desired matrix has been built above, so we
14166 can use it here. */
14167 new_vpos
= window_box_height (w
) / 2;
14170 if (!cursor_row_fully_visible_p (w
, 0, 0))
14172 /* Point does appear, but on a line partly visible at end of window.
14173 Move it back to a fully-visible line. */
14174 new_vpos
= window_box_height (w
);
14177 /* If we need to move point for either of the above reasons,
14178 now actually do it. */
14181 struct glyph_row
*row
;
14183 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14184 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14187 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14188 MATRIX_ROW_START_BYTEPOS (row
));
14190 if (w
!= XWINDOW (selected_window
))
14191 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14192 else if (current_buffer
== old
)
14193 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14195 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14197 /* If we are highlighting the region, then we just changed
14198 the region, so redisplay to show it. */
14199 if (!NILP (Vtransient_mark_mode
)
14200 && !NILP (current_buffer
->mark_active
))
14202 clear_glyph_matrix (w
->desired_matrix
);
14203 if (!try_window (window
, startp
, 0))
14204 goto need_larger_matrices
;
14209 debug_method_add (w
, "forced window start");
14214 /* Handle case where text has not changed, only point, and it has
14215 not moved off the frame, and we are not retrying after hscroll.
14216 (current_matrix_up_to_date_p is nonzero when retrying.) */
14217 if (current_matrix_up_to_date_p
14218 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14219 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14223 case CURSOR_MOVEMENT_SUCCESS
:
14224 used_current_matrix_p
= 1;
14227 case CURSOR_MOVEMENT_MUST_SCROLL
:
14228 goto try_to_scroll
;
14234 /* If current starting point was originally the beginning of a line
14235 but no longer is, find a new starting point. */
14236 else if (!NILP (w
->start_at_line_beg
)
14237 && !(CHARPOS (startp
) <= BEGV
14238 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14241 debug_method_add (w
, "recenter 1");
14246 /* Try scrolling with try_window_id. Value is > 0 if update has
14247 been done, it is -1 if we know that the same window start will
14248 not work. It is 0 if unsuccessful for some other reason. */
14249 else if ((tem
= try_window_id (w
)) != 0)
14252 debug_method_add (w
, "try_window_id %d", tem
);
14255 if (fonts_changed_p
)
14256 goto need_larger_matrices
;
14260 /* Otherwise try_window_id has returned -1 which means that we
14261 don't want the alternative below this comment to execute. */
14263 else if (CHARPOS (startp
) >= BEGV
14264 && CHARPOS (startp
) <= ZV
14265 && PT
>= CHARPOS (startp
)
14266 && (CHARPOS (startp
) < ZV
14267 /* Avoid starting at end of buffer. */
14268 || CHARPOS (startp
) == BEGV
14269 || (XFASTINT (w
->last_modified
) >= MODIFF
14270 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14273 /* If first window line is a continuation line, and window start
14274 is inside the modified region, but the first change is before
14275 current window start, we must select a new window start.
14277 However, if this is the result of a down-mouse event (e.g. by
14278 extending the mouse-drag-overlay), we don't want to select a
14279 new window start, since that would change the position under
14280 the mouse, resulting in an unwanted mouse-movement rather
14281 than a simple mouse-click. */
14282 if (NILP (w
->start_at_line_beg
)
14283 && NILP (do_mouse_tracking
)
14284 && CHARPOS (startp
) > BEGV
14285 && CHARPOS (startp
) > BEG
+ beg_unchanged
14286 && CHARPOS (startp
) <= Z
- end_unchanged
14287 /* Even if w->start_at_line_beg is nil, a new window may
14288 start at a line_beg, since that's how set_buffer_window
14289 sets it. So, we need to check the return value of
14290 compute_window_start_on_continuation_line. (See also
14292 && XMARKER (w
->start
)->buffer
== current_buffer
14293 && compute_window_start_on_continuation_line (w
))
14295 w
->force_start
= Qt
;
14296 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14301 debug_method_add (w
, "same window start");
14304 /* Try to redisplay starting at same place as before.
14305 If point has not moved off frame, accept the results. */
14306 if (!current_matrix_up_to_date_p
14307 /* Don't use try_window_reusing_current_matrix in this case
14308 because a window scroll function can have changed the
14310 || !NILP (Vwindow_scroll_functions
)
14311 || MINI_WINDOW_P (w
)
14312 || !(used_current_matrix_p
14313 = try_window_reusing_current_matrix (w
)))
14315 IF_DEBUG (debug_method_add (w
, "1"));
14316 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14317 /* -1 means we need to scroll.
14318 0 means we need new matrices, but fonts_changed_p
14319 is set in that case, so we will detect it below. */
14320 goto try_to_scroll
;
14323 if (fonts_changed_p
)
14324 goto need_larger_matrices
;
14326 if (w
->cursor
.vpos
>= 0)
14328 if (!just_this_one_p
14329 || current_buffer
->clip_changed
14330 || BEG_UNCHANGED
< CHARPOS (startp
))
14331 /* Forget any recorded base line for line number display. */
14332 w
->base_line_number
= Qnil
;
14334 if (!cursor_row_fully_visible_p (w
, 1, 0))
14336 clear_glyph_matrix (w
->desired_matrix
);
14337 last_line_misfit
= 1;
14339 /* Drop through and scroll. */
14344 clear_glyph_matrix (w
->desired_matrix
);
14349 w
->last_modified
= make_number (0);
14350 w
->last_overlay_modified
= make_number (0);
14352 /* Redisplay the mode line. Select the buffer properly for that. */
14353 if (!update_mode_line
)
14355 update_mode_line
= 1;
14356 w
->update_mode_line
= Qt
;
14359 /* Try to scroll by specified few lines. */
14360 if ((scroll_conservatively
14362 || temp_scroll_step
14363 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14364 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14365 && !current_buffer
->clip_changed
14366 && CHARPOS (startp
) >= BEGV
14367 && CHARPOS (startp
) <= ZV
)
14369 /* The function returns -1 if new fonts were loaded, 1 if
14370 successful, 0 if not successful. */
14371 int rc
= try_scrolling (window
, just_this_one_p
,
14372 scroll_conservatively
,
14374 temp_scroll_step
, last_line_misfit
);
14377 case SCROLLING_SUCCESS
:
14380 case SCROLLING_NEED_LARGER_MATRICES
:
14381 goto need_larger_matrices
;
14383 case SCROLLING_FAILED
:
14391 /* Finally, just choose place to start which centers point */
14394 if (centering_position
< 0)
14395 centering_position
= window_box_height (w
) / 2;
14398 debug_method_add (w
, "recenter");
14401 /* w->vscroll = 0; */
14403 /* Forget any previously recorded base line for line number display. */
14404 if (!buffer_unchanged_p
)
14405 w
->base_line_number
= Qnil
;
14407 /* Move backward half the height of the window. */
14408 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14409 it
.current_y
= it
.last_visible_y
;
14410 move_it_vertically_backward (&it
, centering_position
);
14411 xassert (IT_CHARPOS (it
) >= BEGV
);
14413 /* The function move_it_vertically_backward may move over more
14414 than the specified y-distance. If it->w is small, e.g. a
14415 mini-buffer window, we may end up in front of the window's
14416 display area. Start displaying at the start of the line
14417 containing PT in this case. */
14418 if (it
.current_y
<= 0)
14420 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14421 move_it_vertically_backward (&it
, 0);
14425 it
.current_x
= it
.hpos
= 0;
14427 /* Set startp here explicitly in case that helps avoid an infinite loop
14428 in case the window-scroll-functions functions get errors. */
14429 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14431 /* Run scroll hooks. */
14432 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14434 /* Redisplay the window. */
14435 if (!current_matrix_up_to_date_p
14436 || windows_or_buffers_changed
14437 || cursor_type_changed
14438 /* Don't use try_window_reusing_current_matrix in this case
14439 because it can have changed the buffer. */
14440 || !NILP (Vwindow_scroll_functions
)
14441 || !just_this_one_p
14442 || MINI_WINDOW_P (w
)
14443 || !(used_current_matrix_p
14444 = try_window_reusing_current_matrix (w
)))
14445 try_window (window
, startp
, 0);
14447 /* If new fonts have been loaded (due to fontsets), give up. We
14448 have to start a new redisplay since we need to re-adjust glyph
14450 if (fonts_changed_p
)
14451 goto need_larger_matrices
;
14453 /* If cursor did not appear assume that the middle of the window is
14454 in the first line of the window. Do it again with the next line.
14455 (Imagine a window of height 100, displaying two lines of height
14456 60. Moving back 50 from it->last_visible_y will end in the first
14458 if (w
->cursor
.vpos
< 0)
14460 if (!NILP (w
->window_end_valid
)
14461 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14463 clear_glyph_matrix (w
->desired_matrix
);
14464 move_it_by_lines (&it
, 1, 0);
14465 try_window (window
, it
.current
.pos
, 0);
14467 else if (PT
< IT_CHARPOS (it
))
14469 clear_glyph_matrix (w
->desired_matrix
);
14470 move_it_by_lines (&it
, -1, 0);
14471 try_window (window
, it
.current
.pos
, 0);
14475 /* Not much we can do about it. */
14479 /* Consider the following case: Window starts at BEGV, there is
14480 invisible, intangible text at BEGV, so that display starts at
14481 some point START > BEGV. It can happen that we are called with
14482 PT somewhere between BEGV and START. Try to handle that case. */
14483 if (w
->cursor
.vpos
< 0)
14485 struct glyph_row
*row
= w
->current_matrix
->rows
;
14486 if (row
->mode_line_p
)
14488 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14491 if (!cursor_row_fully_visible_p (w
, 0, 0))
14493 /* If vscroll is enabled, disable it and try again. */
14497 clear_glyph_matrix (w
->desired_matrix
);
14501 /* If centering point failed to make the whole line visible,
14502 put point at the top instead. That has to make the whole line
14503 visible, if it can be done. */
14504 if (centering_position
== 0)
14507 clear_glyph_matrix (w
->desired_matrix
);
14508 centering_position
= 0;
14514 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14515 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14516 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14519 /* Display the mode line, if we must. */
14520 if ((update_mode_line
14521 /* If window not full width, must redo its mode line
14522 if (a) the window to its side is being redone and
14523 (b) we do a frame-based redisplay. This is a consequence
14524 of how inverted lines are drawn in frame-based redisplay. */
14525 || (!just_this_one_p
14526 && !FRAME_WINDOW_P (f
)
14527 && !WINDOW_FULL_WIDTH_P (w
))
14528 /* Line number to display. */
14529 || INTEGERP (w
->base_line_pos
)
14530 /* Column number is displayed and different from the one displayed. */
14531 || (!NILP (w
->column_number_displayed
)
14532 && (XFASTINT (w
->column_number_displayed
)
14533 != (int) current_column ()))) /* iftc */
14534 /* This means that the window has a mode line. */
14535 && (WINDOW_WANTS_MODELINE_P (w
)
14536 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14538 display_mode_lines (w
);
14540 /* If mode line height has changed, arrange for a thorough
14541 immediate redisplay using the correct mode line height. */
14542 if (WINDOW_WANTS_MODELINE_P (w
)
14543 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14545 fonts_changed_p
= 1;
14546 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14547 = DESIRED_MODE_LINE_HEIGHT (w
);
14550 /* If header line height has changed, arrange for a thorough
14551 immediate redisplay using the correct header line height. */
14552 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14553 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14555 fonts_changed_p
= 1;
14556 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14557 = DESIRED_HEADER_LINE_HEIGHT (w
);
14560 if (fonts_changed_p
)
14561 goto need_larger_matrices
;
14564 if (!line_number_displayed
14565 && !BUFFERP (w
->base_line_pos
))
14567 w
->base_line_pos
= Qnil
;
14568 w
->base_line_number
= Qnil
;
14573 /* When we reach a frame's selected window, redo the frame's menu bar. */
14574 if (update_mode_line
14575 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14577 int redisplay_menu_p
= 0;
14578 int redisplay_tool_bar_p
= 0;
14580 if (FRAME_WINDOW_P (f
))
14582 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14583 || defined (HAVE_NS) || defined (USE_GTK)
14584 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14586 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14590 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14592 if (redisplay_menu_p
)
14593 display_menu_bar (w
);
14595 #ifdef HAVE_WINDOW_SYSTEM
14596 if (FRAME_WINDOW_P (f
))
14598 #if defined (USE_GTK) || defined (HAVE_NS)
14599 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14601 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14602 && (FRAME_TOOL_BAR_LINES (f
) > 0
14603 || !NILP (Vauto_resize_tool_bars
));
14606 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14608 ignore_mouse_drag_p
= 1;
14614 #ifdef HAVE_WINDOW_SYSTEM
14615 if (FRAME_WINDOW_P (f
)
14616 && update_window_fringes (w
, (just_this_one_p
14617 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14618 || w
->pseudo_window_p
)))
14622 if (draw_window_fringes (w
, 1))
14623 x_draw_vertical_border (w
);
14627 #endif /* HAVE_WINDOW_SYSTEM */
14629 /* We go to this label, with fonts_changed_p nonzero,
14630 if it is necessary to try again using larger glyph matrices.
14631 We have to redeem the scroll bar even in this case,
14632 because the loop in redisplay_internal expects that. */
14633 need_larger_matrices
:
14635 finish_scroll_bars
:
14637 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14639 /* Set the thumb's position and size. */
14640 set_vertical_scroll_bar (w
);
14642 /* Note that we actually used the scroll bar attached to this
14643 window, so it shouldn't be deleted at the end of redisplay. */
14644 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14645 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14648 /* Restore current_buffer and value of point in it. The window
14649 update may have changed the buffer, so first make sure `opoint'
14650 is still valid (Bug#6177). */
14651 if (CHARPOS (opoint
) < BEGV
)
14652 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14653 else if (CHARPOS (opoint
) > ZV
)
14654 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
14656 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14658 set_buffer_internal_1 (old
);
14659 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14660 shorter. This can be caused by log truncation in *Messages*. */
14661 if (CHARPOS (lpoint
) <= ZV
)
14662 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14664 unbind_to (count
, Qnil
);
14668 /* Build the complete desired matrix of WINDOW with a window start
14669 buffer position POS.
14671 Value is 1 if successful. It is zero if fonts were loaded during
14672 redisplay which makes re-adjusting glyph matrices necessary, and -1
14673 if point would appear in the scroll margins.
14674 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
14675 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
14679 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
14681 struct window
*w
= XWINDOW (window
);
14683 struct glyph_row
*last_text_row
= NULL
;
14684 struct frame
*f
= XFRAME (w
->frame
);
14686 /* Make POS the new window start. */
14687 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14689 /* Mark cursor position as unknown. No overlay arrow seen. */
14690 w
->cursor
.vpos
= -1;
14691 overlay_arrow_seen
= 0;
14693 /* Initialize iterator and info to start at POS. */
14694 start_display (&it
, w
, pos
);
14696 /* Display all lines of W. */
14697 while (it
.current_y
< it
.last_visible_y
)
14699 if (display_line (&it
))
14700 last_text_row
= it
.glyph_row
- 1;
14701 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
14705 /* Don't let the cursor end in the scroll margins. */
14706 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
14707 && !MINI_WINDOW_P (w
))
14709 int this_scroll_margin
;
14711 if (scroll_margin
> 0)
14713 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14714 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14717 this_scroll_margin
= 0;
14719 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14720 && w
->cursor
.y
< this_scroll_margin
14721 && CHARPOS (pos
) > BEGV
14722 && IT_CHARPOS (it
) < ZV
)
14723 /* rms: considering make_cursor_line_fully_visible_p here
14724 seems to give wrong results. We don't want to recenter
14725 when the last line is partly visible, we want to allow
14726 that case to be handled in the usual way. */
14727 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14729 w
->cursor
.vpos
= -1;
14730 clear_glyph_matrix (w
->desired_matrix
);
14735 /* If bottom moved off end of frame, change mode line percentage. */
14736 if (XFASTINT (w
->window_end_pos
) <= 0
14737 && Z
!= IT_CHARPOS (it
))
14738 w
->update_mode_line
= Qt
;
14740 /* Set window_end_pos to the offset of the last character displayed
14741 on the window from the end of current_buffer. Set
14742 window_end_vpos to its row number. */
14745 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14746 w
->window_end_bytepos
14747 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14749 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14751 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14752 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14753 ->displays_text_p
);
14757 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14758 w
->window_end_pos
= make_number (Z
- ZV
);
14759 w
->window_end_vpos
= make_number (0);
14762 /* But that is not valid info until redisplay finishes. */
14763 w
->window_end_valid
= Qnil
;
14769 /************************************************************************
14770 Window redisplay reusing current matrix when buffer has not changed
14771 ************************************************************************/
14773 /* Try redisplay of window W showing an unchanged buffer with a
14774 different window start than the last time it was displayed by
14775 reusing its current matrix. Value is non-zero if successful.
14776 W->start is the new window start. */
14779 try_window_reusing_current_matrix (struct window
*w
)
14781 struct frame
*f
= XFRAME (w
->frame
);
14782 struct glyph_row
*row
, *bottom_row
;
14785 struct text_pos start
, new_start
;
14786 int nrows_scrolled
, i
;
14787 struct glyph_row
*last_text_row
;
14788 struct glyph_row
*last_reused_text_row
;
14789 struct glyph_row
*start_row
;
14790 int start_vpos
, min_y
, max_y
;
14793 if (inhibit_try_window_reusing
)
14797 if (/* This function doesn't handle terminal frames. */
14798 !FRAME_WINDOW_P (f
)
14799 /* Don't try to reuse the display if windows have been split
14801 || windows_or_buffers_changed
14802 || cursor_type_changed
)
14805 /* Can't do this if region may have changed. */
14806 if ((!NILP (Vtransient_mark_mode
)
14807 && !NILP (current_buffer
->mark_active
))
14808 || !NILP (w
->region_showing
)
14809 || !NILP (Vshow_trailing_whitespace
))
14812 /* If top-line visibility has changed, give up. */
14813 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14814 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14817 /* Give up if old or new display is scrolled vertically. We could
14818 make this function handle this, but right now it doesn't. */
14819 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14820 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14823 /* The variable new_start now holds the new window start. The old
14824 start `start' can be determined from the current matrix. */
14825 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14826 start
= start_row
->minpos
;
14827 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14829 /* Clear the desired matrix for the display below. */
14830 clear_glyph_matrix (w
->desired_matrix
);
14832 if (CHARPOS (new_start
) <= CHARPOS (start
))
14836 /* Don't use this method if the display starts with an ellipsis
14837 displayed for invisible text. It's not easy to handle that case
14838 below, and it's certainly not worth the effort since this is
14839 not a frequent case. */
14840 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14843 IF_DEBUG (debug_method_add (w
, "twu1"));
14845 /* Display up to a row that can be reused. The variable
14846 last_text_row is set to the last row displayed that displays
14847 text. Note that it.vpos == 0 if or if not there is a
14848 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14849 start_display (&it
, w
, new_start
);
14850 first_row_y
= it
.current_y
;
14851 w
->cursor
.vpos
= -1;
14852 last_text_row
= last_reused_text_row
= NULL
;
14854 while (it
.current_y
< it
.last_visible_y
14855 && !fonts_changed_p
)
14857 /* If we have reached into the characters in the START row,
14858 that means the line boundaries have changed. So we
14859 can't start copying with the row START. Maybe it will
14860 work to start copying with the following row. */
14861 while (IT_CHARPOS (it
) > CHARPOS (start
))
14863 /* Advance to the next row as the "start". */
14865 start
= start_row
->minpos
;
14866 /* If there are no more rows to try, or just one, give up. */
14867 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14868 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14869 || CHARPOS (start
) == ZV
)
14871 clear_glyph_matrix (w
->desired_matrix
);
14875 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14877 /* If we have reached alignment,
14878 we can copy the rest of the rows. */
14879 if (IT_CHARPOS (it
) == CHARPOS (start
))
14882 if (display_line (&it
))
14883 last_text_row
= it
.glyph_row
- 1;
14886 /* A value of current_y < last_visible_y means that we stopped
14887 at the previous window start, which in turn means that we
14888 have at least one reusable row. */
14889 if (it
.current_y
< it
.last_visible_y
)
14891 /* IT.vpos always starts from 0; it counts text lines. */
14892 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14894 /* Find PT if not already found in the lines displayed. */
14895 if (w
->cursor
.vpos
< 0)
14897 int dy
= it
.current_y
- start_row
->y
;
14899 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14900 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14902 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14903 dy
, nrows_scrolled
);
14906 clear_glyph_matrix (w
->desired_matrix
);
14911 /* Scroll the display. Do it before the current matrix is
14912 changed. The problem here is that update has not yet
14913 run, i.e. part of the current matrix is not up to date.
14914 scroll_run_hook will clear the cursor, and use the
14915 current matrix to get the height of the row the cursor is
14917 run
.current_y
= start_row
->y
;
14918 run
.desired_y
= it
.current_y
;
14919 run
.height
= it
.last_visible_y
- it
.current_y
;
14921 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14924 FRAME_RIF (f
)->update_window_begin_hook (w
);
14925 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14926 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14927 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14931 /* Shift current matrix down by nrows_scrolled lines. */
14932 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14933 rotate_matrix (w
->current_matrix
,
14935 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14938 /* Disable lines that must be updated. */
14939 for (i
= 0; i
< nrows_scrolled
; ++i
)
14940 (start_row
+ i
)->enabled_p
= 0;
14942 /* Re-compute Y positions. */
14943 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14944 max_y
= it
.last_visible_y
;
14945 for (row
= start_row
+ nrows_scrolled
;
14949 row
->y
= it
.current_y
;
14950 row
->visible_height
= row
->height
;
14952 if (row
->y
< min_y
)
14953 row
->visible_height
-= min_y
- row
->y
;
14954 if (row
->y
+ row
->height
> max_y
)
14955 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14956 row
->redraw_fringe_bitmaps_p
= 1;
14958 it
.current_y
+= row
->height
;
14960 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14961 last_reused_text_row
= row
;
14962 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14966 /* Disable lines in the current matrix which are now
14967 below the window. */
14968 for (++row
; row
< bottom_row
; ++row
)
14969 row
->enabled_p
= row
->mode_line_p
= 0;
14972 /* Update window_end_pos etc.; last_reused_text_row is the last
14973 reused row from the current matrix containing text, if any.
14974 The value of last_text_row is the last displayed line
14975 containing text. */
14976 if (last_reused_text_row
)
14978 w
->window_end_bytepos
14979 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14981 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14983 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14984 w
->current_matrix
));
14986 else if (last_text_row
)
14988 w
->window_end_bytepos
14989 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14991 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14993 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14997 /* This window must be completely empty. */
14998 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14999 w
->window_end_pos
= make_number (Z
- ZV
);
15000 w
->window_end_vpos
= make_number (0);
15002 w
->window_end_valid
= Qnil
;
15004 /* Update hint: don't try scrolling again in update_window. */
15005 w
->desired_matrix
->no_scrolling_p
= 1;
15008 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15012 else if (CHARPOS (new_start
) > CHARPOS (start
))
15014 struct glyph_row
*pt_row
, *row
;
15015 struct glyph_row
*first_reusable_row
;
15016 struct glyph_row
*first_row_to_display
;
15018 int yb
= window_text_bottom_y (w
);
15020 /* Find the row starting at new_start, if there is one. Don't
15021 reuse a partially visible line at the end. */
15022 first_reusable_row
= start_row
;
15023 while (first_reusable_row
->enabled_p
15024 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15025 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15026 < CHARPOS (new_start
)))
15027 ++first_reusable_row
;
15029 /* Give up if there is no row to reuse. */
15030 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15031 || !first_reusable_row
->enabled_p
15032 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15033 != CHARPOS (new_start
)))
15036 /* We can reuse fully visible rows beginning with
15037 first_reusable_row to the end of the window. Set
15038 first_row_to_display to the first row that cannot be reused.
15039 Set pt_row to the row containing point, if there is any. */
15041 for (first_row_to_display
= first_reusable_row
;
15042 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15043 ++first_row_to_display
)
15045 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15046 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15047 pt_row
= first_row_to_display
;
15050 /* Start displaying at the start of first_row_to_display. */
15051 xassert (first_row_to_display
->y
< yb
);
15052 init_to_row_start (&it
, w
, first_row_to_display
);
15054 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15056 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15058 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15059 + WINDOW_HEADER_LINE_HEIGHT (w
));
15061 /* Display lines beginning with first_row_to_display in the
15062 desired matrix. Set last_text_row to the last row displayed
15063 that displays text. */
15064 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15065 if (pt_row
== NULL
)
15066 w
->cursor
.vpos
= -1;
15067 last_text_row
= NULL
;
15068 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15069 if (display_line (&it
))
15070 last_text_row
= it
.glyph_row
- 1;
15072 /* If point is in a reused row, adjust y and vpos of the cursor
15076 w
->cursor
.vpos
-= nrows_scrolled
;
15077 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15080 /* Give up if point isn't in a row displayed or reused. (This
15081 also handles the case where w->cursor.vpos < nrows_scrolled
15082 after the calls to display_line, which can happen with scroll
15083 margins. See bug#1295.) */
15084 if (w
->cursor
.vpos
< 0)
15086 clear_glyph_matrix (w
->desired_matrix
);
15090 /* Scroll the display. */
15091 run
.current_y
= first_reusable_row
->y
;
15092 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15093 run
.height
= it
.last_visible_y
- run
.current_y
;
15094 dy
= run
.current_y
- run
.desired_y
;
15099 FRAME_RIF (f
)->update_window_begin_hook (w
);
15100 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15101 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15102 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15106 /* Adjust Y positions of reused rows. */
15107 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15108 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15109 max_y
= it
.last_visible_y
;
15110 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15113 row
->visible_height
= row
->height
;
15114 if (row
->y
< min_y
)
15115 row
->visible_height
-= min_y
- row
->y
;
15116 if (row
->y
+ row
->height
> max_y
)
15117 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15118 row
->redraw_fringe_bitmaps_p
= 1;
15121 /* Scroll the current matrix. */
15122 xassert (nrows_scrolled
> 0);
15123 rotate_matrix (w
->current_matrix
,
15125 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15128 /* Disable rows not reused. */
15129 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15130 row
->enabled_p
= 0;
15132 /* Point may have moved to a different line, so we cannot assume that
15133 the previous cursor position is valid; locate the correct row. */
15136 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15137 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15141 w
->cursor
.y
= row
->y
;
15143 if (row
< bottom_row
)
15145 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15146 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15148 /* Can't use this optimization with bidi-reordered glyph
15149 rows, unless cursor is already at point. */
15150 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
15152 if (!(w
->cursor
.hpos
>= 0
15153 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15154 && BUFFERP (glyph
->object
)
15155 && glyph
->charpos
== PT
))
15160 && (!BUFFERP (glyph
->object
)
15161 || glyph
->charpos
< PT
);
15165 w
->cursor
.x
+= glyph
->pixel_width
;
15170 /* Adjust window end. A null value of last_text_row means that
15171 the window end is in reused rows which in turn means that
15172 only its vpos can have changed. */
15175 w
->window_end_bytepos
15176 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15178 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15180 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15185 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15188 w
->window_end_valid
= Qnil
;
15189 w
->desired_matrix
->no_scrolling_p
= 1;
15192 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15202 /************************************************************************
15203 Window redisplay reusing current matrix when buffer has changed
15204 ************************************************************************/
15206 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15207 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15208 EMACS_INT
*, EMACS_INT
*);
15209 static struct glyph_row
*
15210 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15211 struct glyph_row
*);
15214 /* Return the last row in MATRIX displaying text. If row START is
15215 non-null, start searching with that row. IT gives the dimensions
15216 of the display. Value is null if matrix is empty; otherwise it is
15217 a pointer to the row found. */
15219 static struct glyph_row
*
15220 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15221 struct glyph_row
*start
)
15223 struct glyph_row
*row
, *row_found
;
15225 /* Set row_found to the last row in IT->w's current matrix
15226 displaying text. The loop looks funny but think of partially
15229 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15230 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15232 xassert (row
->enabled_p
);
15234 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15243 /* Return the last row in the current matrix of W that is not affected
15244 by changes at the start of current_buffer that occurred since W's
15245 current matrix was built. Value is null if no such row exists.
15247 BEG_UNCHANGED us the number of characters unchanged at the start of
15248 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15249 first changed character in current_buffer. Characters at positions <
15250 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15251 when the current matrix was built. */
15253 static struct glyph_row
*
15254 find_last_unchanged_at_beg_row (struct window
*w
)
15256 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15257 struct glyph_row
*row
;
15258 struct glyph_row
*row_found
= NULL
;
15259 int yb
= window_text_bottom_y (w
);
15261 /* Find the last row displaying unchanged text. */
15262 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15263 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15264 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15267 if (/* If row ends before first_changed_pos, it is unchanged,
15268 except in some case. */
15269 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15270 /* When row ends in ZV and we write at ZV it is not
15272 && !row
->ends_at_zv_p
15273 /* When first_changed_pos is the end of a continued line,
15274 row is not unchanged because it may be no longer
15276 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15277 && (row
->continued_p
15278 || row
->exact_window_width_line_p
)))
15281 /* Stop if last visible row. */
15282 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15290 /* Find the first glyph row in the current matrix of W that is not
15291 affected by changes at the end of current_buffer since the
15292 time W's current matrix was built.
15294 Return in *DELTA the number of chars by which buffer positions in
15295 unchanged text at the end of current_buffer must be adjusted.
15297 Return in *DELTA_BYTES the corresponding number of bytes.
15299 Value is null if no such row exists, i.e. all rows are affected by
15302 static struct glyph_row
*
15303 find_first_unchanged_at_end_row (struct window
*w
,
15304 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15306 struct glyph_row
*row
;
15307 struct glyph_row
*row_found
= NULL
;
15309 *delta
= *delta_bytes
= 0;
15311 /* Display must not have been paused, otherwise the current matrix
15312 is not up to date. */
15313 eassert (!NILP (w
->window_end_valid
));
15315 /* A value of window_end_pos >= END_UNCHANGED means that the window
15316 end is in the range of changed text. If so, there is no
15317 unchanged row at the end of W's current matrix. */
15318 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15321 /* Set row to the last row in W's current matrix displaying text. */
15322 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15324 /* If matrix is entirely empty, no unchanged row exists. */
15325 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15327 /* The value of row is the last glyph row in the matrix having a
15328 meaningful buffer position in it. The end position of row
15329 corresponds to window_end_pos. This allows us to translate
15330 buffer positions in the current matrix to current buffer
15331 positions for characters not in changed text. */
15333 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15334 EMACS_INT Z_BYTE_old
=
15335 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15336 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15337 struct glyph_row
*first_text_row
15338 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15340 *delta
= Z
- Z_old
;
15341 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15343 /* Set last_unchanged_pos to the buffer position of the last
15344 character in the buffer that has not been changed. Z is the
15345 index + 1 of the last character in current_buffer, i.e. by
15346 subtracting END_UNCHANGED we get the index of the last
15347 unchanged character, and we have to add BEG to get its buffer
15349 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15350 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15352 /* Search backward from ROW for a row displaying a line that
15353 starts at a minimum position >= last_unchanged_pos_old. */
15354 for (; row
> first_text_row
; --row
)
15356 /* This used to abort, but it can happen.
15357 It is ok to just stop the search instead here. KFS. */
15358 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15361 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15366 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15372 /* Make sure that glyph rows in the current matrix of window W
15373 reference the same glyph memory as corresponding rows in the
15374 frame's frame matrix. This function is called after scrolling W's
15375 current matrix on a terminal frame in try_window_id and
15376 try_window_reusing_current_matrix. */
15379 sync_frame_with_window_matrix_rows (struct window
*w
)
15381 struct frame
*f
= XFRAME (w
->frame
);
15382 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15384 /* Preconditions: W must be a leaf window and full-width. Its frame
15385 must have a frame matrix. */
15386 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15387 xassert (WINDOW_FULL_WIDTH_P (w
));
15388 xassert (!FRAME_WINDOW_P (f
));
15390 /* If W is a full-width window, glyph pointers in W's current matrix
15391 have, by definition, to be the same as glyph pointers in the
15392 corresponding frame matrix. Note that frame matrices have no
15393 marginal areas (see build_frame_matrix). */
15394 window_row
= w
->current_matrix
->rows
;
15395 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15396 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15397 while (window_row
< window_row_end
)
15399 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15400 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15402 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15403 frame_row
->glyphs
[TEXT_AREA
] = start
;
15404 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15405 frame_row
->glyphs
[LAST_AREA
] = end
;
15407 /* Disable frame rows whose corresponding window rows have
15408 been disabled in try_window_id. */
15409 if (!window_row
->enabled_p
)
15410 frame_row
->enabled_p
= 0;
15412 ++window_row
, ++frame_row
;
15417 /* Find the glyph row in window W containing CHARPOS. Consider all
15418 rows between START and END (not inclusive). END null means search
15419 all rows to the end of the display area of W. Value is the row
15420 containing CHARPOS or null. */
15423 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15424 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15426 struct glyph_row
*row
= start
;
15427 struct glyph_row
*best_row
= NULL
;
15428 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15431 /* If we happen to start on a header-line, skip that. */
15432 if (row
->mode_line_p
)
15435 if ((end
&& row
>= end
) || !row
->enabled_p
)
15438 last_y
= window_text_bottom_y (w
) - dy
;
15442 /* Give up if we have gone too far. */
15443 if (end
&& row
>= end
)
15445 /* This formerly returned if they were equal.
15446 I think that both quantities are of a "last plus one" type;
15447 if so, when they are equal, the row is within the screen. -- rms. */
15448 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15451 /* If it is in this row, return this row. */
15452 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15453 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15454 /* The end position of a row equals the start
15455 position of the next row. If CHARPOS is there, we
15456 would rather display it in the next line, except
15457 when this line ends in ZV. */
15458 && !row
->ends_at_zv_p
15459 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15460 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15464 if (NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15465 || (!best_row
&& !row
->continued_p
))
15467 /* In bidi-reordered rows, there could be several rows
15468 occluding point, all of them belonging to the same
15469 continued line. We need to find the row which fits
15470 CHARPOS the best. */
15471 for (g
= row
->glyphs
[TEXT_AREA
];
15472 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15475 if (!STRINGP (g
->object
))
15477 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15479 mindif
= eabs (g
->charpos
- charpos
);
15481 /* Exact match always wins. */
15488 else if (best_row
&& !row
->continued_p
)
15495 /* Try to redisplay window W by reusing its existing display. W's
15496 current matrix must be up to date when this function is called,
15497 i.e. window_end_valid must not be nil.
15501 1 if display has been updated
15502 0 if otherwise unsuccessful
15503 -1 if redisplay with same window start is known not to succeed
15505 The following steps are performed:
15507 1. Find the last row in the current matrix of W that is not
15508 affected by changes at the start of current_buffer. If no such row
15511 2. Find the first row in W's current matrix that is not affected by
15512 changes at the end of current_buffer. Maybe there is no such row.
15514 3. Display lines beginning with the row + 1 found in step 1 to the
15515 row found in step 2 or, if step 2 didn't find a row, to the end of
15518 4. If cursor is not known to appear on the window, give up.
15520 5. If display stopped at the row found in step 2, scroll the
15521 display and current matrix as needed.
15523 6. Maybe display some lines at the end of W, if we must. This can
15524 happen under various circumstances, like a partially visible line
15525 becoming fully visible, or because newly displayed lines are displayed
15526 in smaller font sizes.
15528 7. Update W's window end information. */
15531 try_window_id (struct window
*w
)
15533 struct frame
*f
= XFRAME (w
->frame
);
15534 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15535 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15536 struct glyph_row
*last_unchanged_at_beg_row
;
15537 struct glyph_row
*first_unchanged_at_end_row
;
15538 struct glyph_row
*row
;
15539 struct glyph_row
*bottom_row
;
15542 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
15544 struct text_pos start_pos
;
15546 int first_unchanged_at_end_vpos
= 0;
15547 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15548 struct text_pos start
;
15549 EMACS_INT first_changed_charpos
, last_changed_charpos
;
15552 if (inhibit_try_window_id
)
15556 /* This is handy for debugging. */
15558 #define GIVE_UP(X) \
15560 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15564 #define GIVE_UP(X) return 0
15567 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15569 /* Don't use this for mini-windows because these can show
15570 messages and mini-buffers, and we don't handle that here. */
15571 if (MINI_WINDOW_P (w
))
15574 /* This flag is used to prevent redisplay optimizations. */
15575 if (windows_or_buffers_changed
|| cursor_type_changed
)
15578 /* Verify that narrowing has not changed.
15579 Also verify that we were not told to prevent redisplay optimizations.
15580 It would be nice to further
15581 reduce the number of cases where this prevents try_window_id. */
15582 if (current_buffer
->clip_changed
15583 || current_buffer
->prevent_redisplay_optimizations_p
)
15586 /* Window must either use window-based redisplay or be full width. */
15587 if (!FRAME_WINDOW_P (f
)
15588 && (!FRAME_LINE_INS_DEL_OK (f
)
15589 || !WINDOW_FULL_WIDTH_P (w
)))
15592 /* Give up if point is known NOT to appear in W. */
15593 if (PT
< CHARPOS (start
))
15596 /* Another way to prevent redisplay optimizations. */
15597 if (XFASTINT (w
->last_modified
) == 0)
15600 /* Verify that window is not hscrolled. */
15601 if (XFASTINT (w
->hscroll
) != 0)
15604 /* Verify that display wasn't paused. */
15605 if (NILP (w
->window_end_valid
))
15608 /* Can't use this if highlighting a region because a cursor movement
15609 will do more than just set the cursor. */
15610 if (!NILP (Vtransient_mark_mode
)
15611 && !NILP (current_buffer
->mark_active
))
15614 /* Likewise if highlighting trailing whitespace. */
15615 if (!NILP (Vshow_trailing_whitespace
))
15618 /* Likewise if showing a region. */
15619 if (!NILP (w
->region_showing
))
15622 /* Can't use this if overlay arrow position and/or string have
15624 if (overlay_arrows_changed_p ())
15627 /* When word-wrap is on, adding a space to the first word of a
15628 wrapped line can change the wrap position, altering the line
15629 above it. It might be worthwhile to handle this more
15630 intelligently, but for now just redisplay from scratch. */
15631 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15634 /* Under bidi reordering, adding or deleting a character in the
15635 beginning of a paragraph, before the first strong directional
15636 character, can change the base direction of the paragraph (unless
15637 the buffer specifies a fixed paragraph direction), which will
15638 require to redisplay the whole paragraph. It might be worthwhile
15639 to find the paragraph limits and widen the range of redisplayed
15640 lines to that, but for now just give up this optimization and
15641 redisplay from scratch. */
15642 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15643 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15646 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15647 only if buffer has really changed. The reason is that the gap is
15648 initially at Z for freshly visited files. The code below would
15649 set end_unchanged to 0 in that case. */
15650 if (MODIFF
> SAVE_MODIFF
15651 /* This seems to happen sometimes after saving a buffer. */
15652 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15654 if (GPT
- BEG
< BEG_UNCHANGED
)
15655 BEG_UNCHANGED
= GPT
- BEG
;
15656 if (Z
- GPT
< END_UNCHANGED
)
15657 END_UNCHANGED
= Z
- GPT
;
15660 /* The position of the first and last character that has been changed. */
15661 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15662 last_changed_charpos
= Z
- END_UNCHANGED
;
15664 /* If window starts after a line end, and the last change is in
15665 front of that newline, then changes don't affect the display.
15666 This case happens with stealth-fontification. Note that although
15667 the display is unchanged, glyph positions in the matrix have to
15668 be adjusted, of course. */
15669 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15670 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15671 && ((last_changed_charpos
< CHARPOS (start
)
15672 && CHARPOS (start
) == BEGV
)
15673 || (last_changed_charpos
< CHARPOS (start
) - 1
15674 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15676 EMACS_INT Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15677 struct glyph_row
*r0
;
15679 /* Compute how many chars/bytes have been added to or removed
15680 from the buffer. */
15681 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15682 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15684 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15686 /* Give up if PT is not in the window. Note that it already has
15687 been checked at the start of try_window_id that PT is not in
15688 front of the window start. */
15689 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15692 /* If window start is unchanged, we can reuse the whole matrix
15693 as is, after adjusting glyph positions. No need to compute
15694 the window end again, since its offset from Z hasn't changed. */
15695 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15696 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15697 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15698 /* PT must not be in a partially visible line. */
15699 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15700 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15702 /* Adjust positions in the glyph matrix. */
15703 if (delta
|| delta_bytes
)
15705 struct glyph_row
*r1
15706 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15707 increment_matrix_positions (w
->current_matrix
,
15708 MATRIX_ROW_VPOS (r0
, current_matrix
),
15709 MATRIX_ROW_VPOS (r1
, current_matrix
),
15710 delta
, delta_bytes
);
15713 /* Set the cursor. */
15714 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15716 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15723 /* Handle the case that changes are all below what is displayed in
15724 the window, and that PT is in the window. This shortcut cannot
15725 be taken if ZV is visible in the window, and text has been added
15726 there that is visible in the window. */
15727 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15728 /* ZV is not visible in the window, or there are no
15729 changes at ZV, actually. */
15730 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15731 || first_changed_charpos
== last_changed_charpos
))
15733 struct glyph_row
*r0
;
15735 /* Give up if PT is not in the window. Note that it already has
15736 been checked at the start of try_window_id that PT is not in
15737 front of the window start. */
15738 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15741 /* If window start is unchanged, we can reuse the whole matrix
15742 as is, without changing glyph positions since no text has
15743 been added/removed in front of the window end. */
15744 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15745 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
15746 /* PT must not be in a partially visible line. */
15747 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15748 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15750 /* We have to compute the window end anew since text
15751 could have been added/removed after it. */
15753 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15754 w
->window_end_bytepos
15755 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15757 /* Set the cursor. */
15758 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15760 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15767 /* Give up if window start is in the changed area.
15769 The condition used to read
15771 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15773 but why that was tested escapes me at the moment. */
15774 if (CHARPOS (start
) >= first_changed_charpos
15775 && CHARPOS (start
) <= last_changed_charpos
)
15778 /* Check that window start agrees with the start of the first glyph
15779 row in its current matrix. Check this after we know the window
15780 start is not in changed text, otherwise positions would not be
15782 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15783 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
15786 /* Give up if the window ends in strings. Overlay strings
15787 at the end are difficult to handle, so don't try. */
15788 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15789 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15792 /* Compute the position at which we have to start displaying new
15793 lines. Some of the lines at the top of the window might be
15794 reusable because they are not displaying changed text. Find the
15795 last row in W's current matrix not affected by changes at the
15796 start of current_buffer. Value is null if changes start in the
15797 first line of window. */
15798 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15799 if (last_unchanged_at_beg_row
)
15801 /* Avoid starting to display in the moddle of a character, a TAB
15802 for instance. This is easier than to set up the iterator
15803 exactly, and it's not a frequent case, so the additional
15804 effort wouldn't really pay off. */
15805 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15806 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15807 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15808 --last_unchanged_at_beg_row
;
15810 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15813 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15815 start_pos
= it
.current
.pos
;
15817 /* Start displaying new lines in the desired matrix at the same
15818 vpos we would use in the current matrix, i.e. below
15819 last_unchanged_at_beg_row. */
15820 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15822 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15823 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15825 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15829 /* There are no reusable lines at the start of the window.
15830 Start displaying in the first text line. */
15831 start_display (&it
, w
, start
);
15832 it
.vpos
= it
.first_vpos
;
15833 start_pos
= it
.current
.pos
;
15836 /* Find the first row that is not affected by changes at the end of
15837 the buffer. Value will be null if there is no unchanged row, in
15838 which case we must redisplay to the end of the window. delta
15839 will be set to the value by which buffer positions beginning with
15840 first_unchanged_at_end_row have to be adjusted due to text
15842 first_unchanged_at_end_row
15843 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15844 IF_DEBUG (debug_delta
= delta
);
15845 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15847 /* Set stop_pos to the buffer position up to which we will have to
15848 display new lines. If first_unchanged_at_end_row != NULL, this
15849 is the buffer position of the start of the line displayed in that
15850 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15851 that we don't stop at a buffer position. */
15853 if (first_unchanged_at_end_row
)
15855 xassert (last_unchanged_at_beg_row
== NULL
15856 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15858 /* If this is a continuation line, move forward to the next one
15859 that isn't. Changes in lines above affect this line.
15860 Caution: this may move first_unchanged_at_end_row to a row
15861 not displaying text. */
15862 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15863 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15864 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15865 < it
.last_visible_y
))
15866 ++first_unchanged_at_end_row
;
15868 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15869 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15870 >= it
.last_visible_y
))
15871 first_unchanged_at_end_row
= NULL
;
15874 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15876 first_unchanged_at_end_vpos
15877 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15878 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15881 else if (last_unchanged_at_beg_row
== NULL
)
15887 /* Either there is no unchanged row at the end, or the one we have
15888 now displays text. This is a necessary condition for the window
15889 end pos calculation at the end of this function. */
15890 xassert (first_unchanged_at_end_row
== NULL
15891 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15893 debug_last_unchanged_at_beg_vpos
15894 = (last_unchanged_at_beg_row
15895 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15897 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15899 #endif /* GLYPH_DEBUG != 0 */
15902 /* Display new lines. Set last_text_row to the last new line
15903 displayed which has text on it, i.e. might end up as being the
15904 line where the window_end_vpos is. */
15905 w
->cursor
.vpos
= -1;
15906 last_text_row
= NULL
;
15907 overlay_arrow_seen
= 0;
15908 while (it
.current_y
< it
.last_visible_y
15909 && !fonts_changed_p
15910 && (first_unchanged_at_end_row
== NULL
15911 || IT_CHARPOS (it
) < stop_pos
))
15913 if (display_line (&it
))
15914 last_text_row
= it
.glyph_row
- 1;
15917 if (fonts_changed_p
)
15921 /* Compute differences in buffer positions, y-positions etc. for
15922 lines reused at the bottom of the window. Compute what we can
15924 if (first_unchanged_at_end_row
15925 /* No lines reused because we displayed everything up to the
15926 bottom of the window. */
15927 && it
.current_y
< it
.last_visible_y
)
15930 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15932 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15933 run
.current_y
= first_unchanged_at_end_row
->y
;
15934 run
.desired_y
= run
.current_y
+ dy
;
15935 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15939 delta
= delta_bytes
= dvpos
= dy
15940 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15941 first_unchanged_at_end_row
= NULL
;
15943 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15946 /* Find the cursor if not already found. We have to decide whether
15947 PT will appear on this window (it sometimes doesn't, but this is
15948 not a very frequent case.) This decision has to be made before
15949 the current matrix is altered. A value of cursor.vpos < 0 means
15950 that PT is either in one of the lines beginning at
15951 first_unchanged_at_end_row or below the window. Don't care for
15952 lines that might be displayed later at the window end; as
15953 mentioned, this is not a frequent case. */
15954 if (w
->cursor
.vpos
< 0)
15956 /* Cursor in unchanged rows at the top? */
15957 if (PT
< CHARPOS (start_pos
)
15958 && last_unchanged_at_beg_row
)
15960 row
= row_containing_pos (w
, PT
,
15961 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15962 last_unchanged_at_beg_row
+ 1, 0);
15964 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15967 /* Start from first_unchanged_at_end_row looking for PT. */
15968 else if (first_unchanged_at_end_row
)
15970 row
= row_containing_pos (w
, PT
- delta
,
15971 first_unchanged_at_end_row
, NULL
, 0);
15973 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15974 delta_bytes
, dy
, dvpos
);
15977 /* Give up if cursor was not found. */
15978 if (w
->cursor
.vpos
< 0)
15980 clear_glyph_matrix (w
->desired_matrix
);
15985 /* Don't let the cursor end in the scroll margins. */
15987 int this_scroll_margin
, cursor_height
;
15989 this_scroll_margin
= max (0, scroll_margin
);
15990 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15991 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15992 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15994 if ((w
->cursor
.y
< this_scroll_margin
15995 && CHARPOS (start
) > BEGV
)
15996 /* Old redisplay didn't take scroll margin into account at the bottom,
15997 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15998 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15999 ? cursor_height
+ this_scroll_margin
16000 : 1)) > it
.last_visible_y
)
16002 w
->cursor
.vpos
= -1;
16003 clear_glyph_matrix (w
->desired_matrix
);
16008 /* Scroll the display. Do it before changing the current matrix so
16009 that xterm.c doesn't get confused about where the cursor glyph is
16011 if (dy
&& run
.height
)
16015 if (FRAME_WINDOW_P (f
))
16017 FRAME_RIF (f
)->update_window_begin_hook (w
);
16018 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16019 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16020 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16024 /* Terminal frame. In this case, dvpos gives the number of
16025 lines to scroll by; dvpos < 0 means scroll up. */
16026 int first_unchanged_at_end_vpos
16027 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16028 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
16029 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16030 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16031 + window_internal_height (w
));
16033 #if defined (HAVE_GPM) || defined (MSDOS)
16034 x_clear_window_mouse_face (w
);
16036 /* Perform the operation on the screen. */
16039 /* Scroll last_unchanged_at_beg_row to the end of the
16040 window down dvpos lines. */
16041 set_terminal_window (f
, end
);
16043 /* On dumb terminals delete dvpos lines at the end
16044 before inserting dvpos empty lines. */
16045 if (!FRAME_SCROLL_REGION_OK (f
))
16046 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16048 /* Insert dvpos empty lines in front of
16049 last_unchanged_at_beg_row. */
16050 ins_del_lines (f
, from
, dvpos
);
16052 else if (dvpos
< 0)
16054 /* Scroll up last_unchanged_at_beg_vpos to the end of
16055 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16056 set_terminal_window (f
, end
);
16058 /* Delete dvpos lines in front of
16059 last_unchanged_at_beg_vpos. ins_del_lines will set
16060 the cursor to the given vpos and emit |dvpos| delete
16062 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16064 /* On a dumb terminal insert dvpos empty lines at the
16066 if (!FRAME_SCROLL_REGION_OK (f
))
16067 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16070 set_terminal_window (f
, 0);
16076 /* Shift reused rows of the current matrix to the right position.
16077 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16079 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16080 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16083 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16084 bottom_vpos
, dvpos
);
16085 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16088 else if (dvpos
> 0)
16090 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16091 bottom_vpos
, dvpos
);
16092 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16093 first_unchanged_at_end_vpos
+ dvpos
, 0);
16096 /* For frame-based redisplay, make sure that current frame and window
16097 matrix are in sync with respect to glyph memory. */
16098 if (!FRAME_WINDOW_P (f
))
16099 sync_frame_with_window_matrix_rows (w
);
16101 /* Adjust buffer positions in reused rows. */
16102 if (delta
|| delta_bytes
)
16103 increment_matrix_positions (current_matrix
,
16104 first_unchanged_at_end_vpos
+ dvpos
,
16105 bottom_vpos
, delta
, delta_bytes
);
16107 /* Adjust Y positions. */
16109 shift_glyph_matrix (w
, current_matrix
,
16110 first_unchanged_at_end_vpos
+ dvpos
,
16113 if (first_unchanged_at_end_row
)
16115 first_unchanged_at_end_row
+= dvpos
;
16116 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16117 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16118 first_unchanged_at_end_row
= NULL
;
16121 /* If scrolling up, there may be some lines to display at the end of
16123 last_text_row_at_end
= NULL
;
16126 /* Scrolling up can leave for example a partially visible line
16127 at the end of the window to be redisplayed. */
16128 /* Set last_row to the glyph row in the current matrix where the
16129 window end line is found. It has been moved up or down in
16130 the matrix by dvpos. */
16131 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16132 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16134 /* If last_row is the window end line, it should display text. */
16135 xassert (last_row
->displays_text_p
);
16137 /* If window end line was partially visible before, begin
16138 displaying at that line. Otherwise begin displaying with the
16139 line following it. */
16140 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16142 init_to_row_start (&it
, w
, last_row
);
16143 it
.vpos
= last_vpos
;
16144 it
.current_y
= last_row
->y
;
16148 init_to_row_end (&it
, w
, last_row
);
16149 it
.vpos
= 1 + last_vpos
;
16150 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16154 /* We may start in a continuation line. If so, we have to
16155 get the right continuation_lines_width and current_x. */
16156 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16157 it
.hpos
= it
.current_x
= 0;
16159 /* Display the rest of the lines at the window end. */
16160 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16161 while (it
.current_y
< it
.last_visible_y
16162 && !fonts_changed_p
)
16164 /* Is it always sure that the display agrees with lines in
16165 the current matrix? I don't think so, so we mark rows
16166 displayed invalid in the current matrix by setting their
16167 enabled_p flag to zero. */
16168 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16169 if (display_line (&it
))
16170 last_text_row_at_end
= it
.glyph_row
- 1;
16174 /* Update window_end_pos and window_end_vpos. */
16175 if (first_unchanged_at_end_row
16176 && !last_text_row_at_end
)
16178 /* Window end line if one of the preserved rows from the current
16179 matrix. Set row to the last row displaying text in current
16180 matrix starting at first_unchanged_at_end_row, after
16182 xassert (first_unchanged_at_end_row
->displays_text_p
);
16183 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16184 first_unchanged_at_end_row
);
16185 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16187 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16188 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16190 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16191 xassert (w
->window_end_bytepos
>= 0);
16192 IF_DEBUG (debug_method_add (w
, "A"));
16194 else if (last_text_row_at_end
)
16197 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16198 w
->window_end_bytepos
16199 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16201 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16202 xassert (w
->window_end_bytepos
>= 0);
16203 IF_DEBUG (debug_method_add (w
, "B"));
16205 else if (last_text_row
)
16207 /* We have displayed either to the end of the window or at the
16208 end of the window, i.e. the last row with text is to be found
16209 in the desired matrix. */
16211 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16212 w
->window_end_bytepos
16213 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16215 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16216 xassert (w
->window_end_bytepos
>= 0);
16218 else if (first_unchanged_at_end_row
== NULL
16219 && last_text_row
== NULL
16220 && last_text_row_at_end
== NULL
)
16222 /* Displayed to end of window, but no line containing text was
16223 displayed. Lines were deleted at the end of the window. */
16224 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16225 int vpos
= XFASTINT (w
->window_end_vpos
);
16226 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16227 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16230 row
== NULL
&& vpos
>= first_vpos
;
16231 --vpos
, --current_row
, --desired_row
)
16233 if (desired_row
->enabled_p
)
16235 if (desired_row
->displays_text_p
)
16238 else if (current_row
->displays_text_p
)
16242 xassert (row
!= NULL
);
16243 w
->window_end_vpos
= make_number (vpos
+ 1);
16244 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16245 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16246 xassert (w
->window_end_bytepos
>= 0);
16247 IF_DEBUG (debug_method_add (w
, "C"));
16252 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16253 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16255 /* Record that display has not been completed. */
16256 w
->window_end_valid
= Qnil
;
16257 w
->desired_matrix
->no_scrolling_p
= 1;
16265 /***********************************************************************
16266 More debugging support
16267 ***********************************************************************/
16271 void dump_glyph_row (struct glyph_row
*, int, int);
16272 void dump_glyph_matrix (struct glyph_matrix
*, int);
16273 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16276 /* Dump the contents of glyph matrix MATRIX on stderr.
16278 GLYPHS 0 means don't show glyph contents.
16279 GLYPHS 1 means show glyphs in short form
16280 GLYPHS > 1 means show glyphs in long form. */
16283 dump_glyph_matrix (matrix
, glyphs
)
16284 struct glyph_matrix
*matrix
;
16288 for (i
= 0; i
< matrix
->nrows
; ++i
)
16289 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16293 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16294 the glyph row and area where the glyph comes from. */
16297 dump_glyph (row
, glyph
, area
)
16298 struct glyph_row
*row
;
16299 struct glyph
*glyph
;
16302 if (glyph
->type
== CHAR_GLYPH
)
16305 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16306 glyph
- row
->glyphs
[TEXT_AREA
],
16309 (BUFFERP (glyph
->object
)
16311 : (STRINGP (glyph
->object
)
16314 glyph
->pixel_width
,
16316 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16320 glyph
->left_box_line_p
,
16321 glyph
->right_box_line_p
);
16323 else if (glyph
->type
== STRETCH_GLYPH
)
16326 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16327 glyph
- row
->glyphs
[TEXT_AREA
],
16330 (BUFFERP (glyph
->object
)
16332 : (STRINGP (glyph
->object
)
16335 glyph
->pixel_width
,
16339 glyph
->left_box_line_p
,
16340 glyph
->right_box_line_p
);
16342 else if (glyph
->type
== IMAGE_GLYPH
)
16345 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16346 glyph
- row
->glyphs
[TEXT_AREA
],
16349 (BUFFERP (glyph
->object
)
16351 : (STRINGP (glyph
->object
)
16354 glyph
->pixel_width
,
16358 glyph
->left_box_line_p
,
16359 glyph
->right_box_line_p
);
16361 else if (glyph
->type
== COMPOSITE_GLYPH
)
16364 " %5d %4c %6d %c %3d 0x%05x",
16365 glyph
- row
->glyphs
[TEXT_AREA
],
16368 (BUFFERP (glyph
->object
)
16370 : (STRINGP (glyph
->object
)
16373 glyph
->pixel_width
,
16375 if (glyph
->u
.cmp
.automatic
)
16378 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16379 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16381 glyph
->left_box_line_p
,
16382 glyph
->right_box_line_p
);
16387 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16388 GLYPHS 0 means don't show glyph contents.
16389 GLYPHS 1 means show glyphs in short form
16390 GLYPHS > 1 means show glyphs in long form. */
16393 dump_glyph_row (row
, vpos
, glyphs
)
16394 struct glyph_row
*row
;
16399 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16400 fprintf (stderr
, "======================================================================\n");
16402 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16403 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16405 MATRIX_ROW_START_CHARPOS (row
),
16406 MATRIX_ROW_END_CHARPOS (row
),
16407 row
->used
[TEXT_AREA
],
16408 row
->contains_overlapping_glyphs_p
,
16410 row
->truncated_on_left_p
,
16411 row
->truncated_on_right_p
,
16413 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16414 row
->displays_text_p
,
16417 row
->ends_in_middle_of_char_p
,
16418 row
->starts_in_middle_of_char_p
,
16424 row
->visible_height
,
16427 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16428 row
->end
.overlay_string_index
,
16429 row
->continuation_lines_width
);
16430 fprintf (stderr
, "%9d %5d\n",
16431 CHARPOS (row
->start
.string_pos
),
16432 CHARPOS (row
->end
.string_pos
));
16433 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16434 row
->end
.dpvec_index
);
16441 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16443 struct glyph
*glyph
= row
->glyphs
[area
];
16444 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16446 /* Glyph for a line end in text. */
16447 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16450 if (glyph
< glyph_end
)
16451 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16453 for (; glyph
< glyph_end
; ++glyph
)
16454 dump_glyph (row
, glyph
, area
);
16457 else if (glyphs
== 1)
16461 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16463 char *s
= (char *) alloca (row
->used
[area
] + 1);
16466 for (i
= 0; i
< row
->used
[area
]; ++i
)
16468 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16469 if (glyph
->type
== CHAR_GLYPH
16470 && glyph
->u
.ch
< 0x80
16471 && glyph
->u
.ch
>= ' ')
16472 s
[i
] = glyph
->u
.ch
;
16478 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16484 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16485 Sdump_glyph_matrix
, 0, 1, "p",
16486 doc
: /* Dump the current matrix of the selected window to stderr.
16487 Shows contents of glyph row structures. With non-nil
16488 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16489 glyphs in short form, otherwise show glyphs in long form. */)
16490 (Lisp_Object glyphs
)
16492 struct window
*w
= XWINDOW (selected_window
);
16493 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16495 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16496 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16497 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16498 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16499 fprintf (stderr
, "=============================================\n");
16500 dump_glyph_matrix (w
->current_matrix
,
16501 NILP (glyphs
) ? 0 : XINT (glyphs
));
16506 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16507 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16510 struct frame
*f
= XFRAME (selected_frame
);
16511 dump_glyph_matrix (f
->current_matrix
, 1);
16516 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16517 doc
: /* Dump glyph row ROW to stderr.
16518 GLYPH 0 means don't dump glyphs.
16519 GLYPH 1 means dump glyphs in short form.
16520 GLYPH > 1 or omitted means dump glyphs in long form. */)
16521 (Lisp_Object row
, Lisp_Object glyphs
)
16523 struct glyph_matrix
*matrix
;
16526 CHECK_NUMBER (row
);
16527 matrix
= XWINDOW (selected_window
)->current_matrix
;
16529 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16530 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16532 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16537 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16538 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16539 GLYPH 0 means don't dump glyphs.
16540 GLYPH 1 means dump glyphs in short form.
16541 GLYPH > 1 or omitted means dump glyphs in long form. */)
16542 (Lisp_Object row
, Lisp_Object glyphs
)
16544 struct frame
*sf
= SELECTED_FRAME ();
16545 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16548 CHECK_NUMBER (row
);
16550 if (vpos
>= 0 && vpos
< m
->nrows
)
16551 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16552 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16557 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16558 doc
: /* Toggle tracing of redisplay.
16559 With ARG, turn tracing on if and only if ARG is positive. */)
16563 trace_redisplay_p
= !trace_redisplay_p
;
16566 arg
= Fprefix_numeric_value (arg
);
16567 trace_redisplay_p
= XINT (arg
) > 0;
16574 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16575 doc
: /* Like `format', but print result to stderr.
16576 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16577 (int nargs
, Lisp_Object
*args
)
16579 Lisp_Object s
= Fformat (nargs
, args
);
16580 fprintf (stderr
, "%s", SDATA (s
));
16584 #endif /* GLYPH_DEBUG */
16588 /***********************************************************************
16589 Building Desired Matrix Rows
16590 ***********************************************************************/
16592 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16593 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16595 static struct glyph_row
*
16596 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
16598 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16599 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16600 struct buffer
*old
= current_buffer
;
16601 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16602 int arrow_len
= SCHARS (overlay_arrow_string
);
16603 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16604 const unsigned char *p
;
16607 int n_glyphs_before
;
16609 set_buffer_temp (buffer
);
16610 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16611 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16612 SET_TEXT_POS (it
.position
, 0, 0);
16614 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16616 while (p
< arrow_end
)
16618 Lisp_Object face
, ilisp
;
16620 /* Get the next character. */
16622 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
16625 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
16626 if (! ASCII_CHAR_P (it
.c
))
16627 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
16631 /* Get its face. */
16632 ilisp
= make_number (p
- arrow_string
);
16633 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16634 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
16636 /* Compute its width, get its glyphs. */
16637 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16638 SET_TEXT_POS (it
.position
, -1, -1);
16639 PRODUCE_GLYPHS (&it
);
16641 /* If this character doesn't fit any more in the line, we have
16642 to remove some glyphs. */
16643 if (it
.current_x
> it
.last_visible_x
)
16645 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16650 set_buffer_temp (old
);
16651 return it
.glyph_row
;
16655 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16656 glyphs are only inserted for terminal frames since we can't really
16657 win with truncation glyphs when partially visible glyphs are
16658 involved. Which glyphs to insert is determined by
16659 produce_special_glyphs. */
16662 insert_left_trunc_glyphs (struct it
*it
)
16664 struct it truncate_it
;
16665 struct glyph
*from
, *end
, *to
, *toend
;
16667 xassert (!FRAME_WINDOW_P (it
->f
));
16669 /* Get the truncation glyphs. */
16671 truncate_it
.current_x
= 0;
16672 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16673 truncate_it
.glyph_row
= &scratch_glyph_row
;
16674 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16675 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16676 truncate_it
.object
= make_number (0);
16677 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16679 /* Overwrite glyphs from IT with truncation glyphs. */
16680 if (!it
->glyph_row
->reversed_p
)
16682 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16683 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16684 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16685 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16690 /* There may be padding glyphs left over. Overwrite them too. */
16691 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16693 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16699 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16703 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
16704 that back to front. */
16705 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16706 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16707 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16708 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16710 while (from
>= end
&& to
>= toend
)
16712 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
16715 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
16716 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16717 while (from
>= end
&& to
>= toend
)
16722 /* Need to free some room before prepending additional
16724 int move_by
= from
- end
+ 1;
16725 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16726 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16728 for ( ; g
>= g0
; g
--)
16730 while (from
>= end
)
16732 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
16738 /* Compute the pixel height and width of IT->glyph_row.
16740 Most of the time, ascent and height of a display line will be equal
16741 to the max_ascent and max_height values of the display iterator
16742 structure. This is not the case if
16744 1. We hit ZV without displaying anything. In this case, max_ascent
16745 and max_height will be zero.
16747 2. We have some glyphs that don't contribute to the line height.
16748 (The glyph row flag contributes_to_line_height_p is for future
16749 pixmap extensions).
16751 The first case is easily covered by using default values because in
16752 these cases, the line height does not really matter, except that it
16753 must not be zero. */
16756 compute_line_metrics (struct it
*it
)
16758 struct glyph_row
*row
= it
->glyph_row
;
16761 if (FRAME_WINDOW_P (it
->f
))
16763 int i
, min_y
, max_y
;
16765 /* The line may consist of one space only, that was added to
16766 place the cursor on it. If so, the row's height hasn't been
16768 if (row
->height
== 0)
16770 if (it
->max_ascent
+ it
->max_descent
== 0)
16771 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16772 row
->ascent
= it
->max_ascent
;
16773 row
->height
= it
->max_ascent
+ it
->max_descent
;
16774 row
->phys_ascent
= it
->max_phys_ascent
;
16775 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16776 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16779 /* Compute the width of this line. */
16780 row
->pixel_width
= row
->x
;
16781 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16782 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16784 xassert (row
->pixel_width
>= 0);
16785 xassert (row
->ascent
>= 0 && row
->height
> 0);
16787 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16788 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16790 /* If first line's physical ascent is larger than its logical
16791 ascent, use the physical ascent, and make the row taller.
16792 This makes accented characters fully visible. */
16793 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16794 && row
->phys_ascent
> row
->ascent
)
16796 row
->height
+= row
->phys_ascent
- row
->ascent
;
16797 row
->ascent
= row
->phys_ascent
;
16800 /* Compute how much of the line is visible. */
16801 row
->visible_height
= row
->height
;
16803 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16804 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16806 if (row
->y
< min_y
)
16807 row
->visible_height
-= min_y
- row
->y
;
16808 if (row
->y
+ row
->height
> max_y
)
16809 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16813 row
->pixel_width
= row
->used
[TEXT_AREA
];
16814 if (row
->continued_p
)
16815 row
->pixel_width
-= it
->continuation_pixel_width
;
16816 else if (row
->truncated_on_right_p
)
16817 row
->pixel_width
-= it
->truncation_pixel_width
;
16818 row
->ascent
= row
->phys_ascent
= 0;
16819 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16820 row
->extra_line_spacing
= 0;
16823 /* Compute a hash code for this row. */
16825 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16826 for (i
= 0; i
< row
->used
[area
]; ++i
)
16827 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16828 + row
->glyphs
[area
][i
].u
.val
16829 + row
->glyphs
[area
][i
].face_id
16830 + row
->glyphs
[area
][i
].padding_p
16831 + (row
->glyphs
[area
][i
].type
<< 2));
16833 it
->max_ascent
= it
->max_descent
= 0;
16834 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16838 /* Append one space to the glyph row of iterator IT if doing a
16839 window-based redisplay. The space has the same face as
16840 IT->face_id. Value is non-zero if a space was added.
16842 This function is called to make sure that there is always one glyph
16843 at the end of a glyph row that the cursor can be set on under
16844 window-systems. (If there weren't such a glyph we would not know
16845 how wide and tall a box cursor should be displayed).
16847 At the same time this space let's a nicely handle clearing to the
16848 end of the line if the row ends in italic text. */
16851 append_space_for_newline (struct it
*it
, int default_face_p
)
16853 if (FRAME_WINDOW_P (it
->f
))
16855 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16857 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16858 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16860 /* Save some values that must not be changed.
16861 Must save IT->c and IT->len because otherwise
16862 ITERATOR_AT_END_P wouldn't work anymore after
16863 append_space_for_newline has been called. */
16864 enum display_element_type saved_what
= it
->what
;
16865 int saved_c
= it
->c
, saved_len
= it
->len
;
16866 int saved_char_to_display
= it
->char_to_display
;
16867 int saved_x
= it
->current_x
;
16868 int saved_face_id
= it
->face_id
;
16869 struct text_pos saved_pos
;
16870 Lisp_Object saved_object
;
16873 saved_object
= it
->object
;
16874 saved_pos
= it
->position
;
16876 it
->what
= IT_CHARACTER
;
16877 memset (&it
->position
, 0, sizeof it
->position
);
16878 it
->object
= make_number (0);
16879 it
->c
= it
->char_to_display
= ' ';
16882 if (default_face_p
)
16883 it
->face_id
= DEFAULT_FACE_ID
;
16884 else if (it
->face_before_selective_p
)
16885 it
->face_id
= it
->saved_face_id
;
16886 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16887 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16889 PRODUCE_GLYPHS (it
);
16891 it
->override_ascent
= -1;
16892 it
->constrain_row_ascent_descent_p
= 0;
16893 it
->current_x
= saved_x
;
16894 it
->object
= saved_object
;
16895 it
->position
= saved_pos
;
16896 it
->what
= saved_what
;
16897 it
->face_id
= saved_face_id
;
16898 it
->len
= saved_len
;
16900 it
->char_to_display
= saved_char_to_display
;
16909 /* Extend the face of the last glyph in the text area of IT->glyph_row
16910 to the end of the display line. Called from display_line. If the
16911 glyph row is empty, add a space glyph to it so that we know the
16912 face to draw. Set the glyph row flag fill_line_p. If the glyph
16913 row is R2L, prepend a stretch glyph to cover the empty space to the
16914 left of the leftmost glyph. */
16917 extend_face_to_end_of_line (struct it
*it
)
16920 struct frame
*f
= it
->f
;
16922 /* If line is already filled, do nothing. Non window-system frames
16923 get a grace of one more ``pixel'' because their characters are
16924 1-``pixel'' wide, so they hit the equality too early. This grace
16925 is needed only for R2L rows that are not continued, to produce
16926 one extra blank where we could display the cursor. */
16927 if (it
->current_x
>= it
->last_visible_x
16928 + (!FRAME_WINDOW_P (f
)
16929 && it
->glyph_row
->reversed_p
16930 && !it
->glyph_row
->continued_p
))
16933 /* Face extension extends the background and box of IT->face_id
16934 to the end of the line. If the background equals the background
16935 of the frame, we don't have to do anything. */
16936 if (it
->face_before_selective_p
)
16937 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
16939 face
= FACE_FROM_ID (f
, it
->face_id
);
16941 if (FRAME_WINDOW_P (f
)
16942 && it
->glyph_row
->displays_text_p
16943 && face
->box
== FACE_NO_BOX
16944 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16946 && !it
->glyph_row
->reversed_p
)
16949 /* Set the glyph row flag indicating that the face of the last glyph
16950 in the text area has to be drawn to the end of the text area. */
16951 it
->glyph_row
->fill_line_p
= 1;
16953 /* If current character of IT is not ASCII, make sure we have the
16954 ASCII face. This will be automatically undone the next time
16955 get_next_display_element returns a multibyte character. Note
16956 that the character will always be single byte in unibyte
16958 if (!ASCII_CHAR_P (it
->c
))
16960 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16963 if (FRAME_WINDOW_P (f
))
16965 /* If the row is empty, add a space with the current face of IT,
16966 so that we know which face to draw. */
16967 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16969 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16970 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16971 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16973 #ifdef HAVE_WINDOW_SYSTEM
16974 if (it
->glyph_row
->reversed_p
)
16976 /* Prepend a stretch glyph to the row, such that the
16977 rightmost glyph will be drawn flushed all the way to the
16978 right margin of the window. The stretch glyph that will
16979 occupy the empty space, if any, to the left of the
16981 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
16982 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16983 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
16985 int row_width
, stretch_ascent
, stretch_width
;
16986 struct text_pos saved_pos
;
16987 int saved_face_id
, saved_avoid_cursor
;
16989 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
16990 row_width
+= g
->pixel_width
;
16991 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
16992 if (stretch_width
> 0)
16995 (((it
->ascent
+ it
->descent
)
16996 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
16997 saved_pos
= it
->position
;
16998 memset (&it
->position
, 0, sizeof it
->position
);
16999 saved_avoid_cursor
= it
->avoid_cursor_p
;
17000 it
->avoid_cursor_p
= 1;
17001 saved_face_id
= it
->face_id
;
17002 /* The last row's stretch glyph should get the default
17003 face, to avoid painting the rest of the window with
17004 the region face, if the region ends at ZV. */
17005 if (it
->glyph_row
->ends_at_zv_p
)
17006 it
->face_id
= DEFAULT_FACE_ID
;
17008 it
->face_id
= face
->id
;
17009 append_stretch_glyph (it
, make_number (0), stretch_width
,
17010 it
->ascent
+ it
->descent
, stretch_ascent
);
17011 it
->position
= saved_pos
;
17012 it
->avoid_cursor_p
= saved_avoid_cursor
;
17013 it
->face_id
= saved_face_id
;
17016 #endif /* HAVE_WINDOW_SYSTEM */
17020 /* Save some values that must not be changed. */
17021 int saved_x
= it
->current_x
;
17022 struct text_pos saved_pos
;
17023 Lisp_Object saved_object
;
17024 enum display_element_type saved_what
= it
->what
;
17025 int saved_face_id
= it
->face_id
;
17027 saved_object
= it
->object
;
17028 saved_pos
= it
->position
;
17030 it
->what
= IT_CHARACTER
;
17031 memset (&it
->position
, 0, sizeof it
->position
);
17032 it
->object
= make_number (0);
17033 it
->c
= it
->char_to_display
= ' ';
17035 /* The last row's blank glyphs should get the default face, to
17036 avoid painting the rest of the window with the region face,
17037 if the region ends at ZV. */
17038 if (it
->glyph_row
->ends_at_zv_p
)
17039 it
->face_id
= DEFAULT_FACE_ID
;
17041 it
->face_id
= face
->id
;
17043 PRODUCE_GLYPHS (it
);
17045 while (it
->current_x
<= it
->last_visible_x
)
17046 PRODUCE_GLYPHS (it
);
17048 /* Don't count these blanks really. It would let us insert a left
17049 truncation glyph below and make us set the cursor on them, maybe. */
17050 it
->current_x
= saved_x
;
17051 it
->object
= saved_object
;
17052 it
->position
= saved_pos
;
17053 it
->what
= saved_what
;
17054 it
->face_id
= saved_face_id
;
17059 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17060 trailing whitespace. */
17063 trailing_whitespace_p (EMACS_INT charpos
)
17065 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17068 while (bytepos
< ZV_BYTE
17069 && (c
= FETCH_CHAR (bytepos
),
17070 c
== ' ' || c
== '\t'))
17073 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17075 if (bytepos
!= PT_BYTE
)
17082 /* Highlight trailing whitespace, if any, in ROW. */
17085 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17087 int used
= row
->used
[TEXT_AREA
];
17091 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17092 struct glyph
*glyph
= start
+ used
- 1;
17094 if (row
->reversed_p
)
17096 /* Right-to-left rows need to be processed in the opposite
17097 direction, so swap the edge pointers. */
17099 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17102 /* Skip over glyphs inserted to display the cursor at the
17103 end of a line, for extending the face of the last glyph
17104 to the end of the line on terminals, and for truncation
17105 and continuation glyphs. */
17106 if (!row
->reversed_p
)
17108 while (glyph
>= start
17109 && glyph
->type
== CHAR_GLYPH
17110 && INTEGERP (glyph
->object
))
17115 while (glyph
<= start
17116 && glyph
->type
== CHAR_GLYPH
17117 && INTEGERP (glyph
->object
))
17121 /* If last glyph is a space or stretch, and it's trailing
17122 whitespace, set the face of all trailing whitespace glyphs in
17123 IT->glyph_row to `trailing-whitespace'. */
17124 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17125 && BUFFERP (glyph
->object
)
17126 && (glyph
->type
== STRETCH_GLYPH
17127 || (glyph
->type
== CHAR_GLYPH
17128 && glyph
->u
.ch
== ' '))
17129 && trailing_whitespace_p (glyph
->charpos
))
17131 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17135 if (!row
->reversed_p
)
17137 while (glyph
>= start
17138 && BUFFERP (glyph
->object
)
17139 && (glyph
->type
== STRETCH_GLYPH
17140 || (glyph
->type
== CHAR_GLYPH
17141 && glyph
->u
.ch
== ' ')))
17142 (glyph
--)->face_id
= face_id
;
17146 while (glyph
<= start
17147 && BUFFERP (glyph
->object
)
17148 && (glyph
->type
== STRETCH_GLYPH
17149 || (glyph
->type
== CHAR_GLYPH
17150 && glyph
->u
.ch
== ' ')))
17151 (glyph
++)->face_id
= face_id
;
17158 /* Value is non-zero if glyph row ROW in window W should be
17159 used to hold the cursor. */
17162 cursor_row_p (struct window
*w
, struct glyph_row
*row
)
17164 int cursor_row_p
= 1;
17166 if (PT
== CHARPOS (row
->end
.pos
))
17168 /* Suppose the row ends on a string.
17169 Unless the row is continued, that means it ends on a newline
17170 in the string. If it's anything other than a display string
17171 (e.g. a before-string from an overlay), we don't want the
17172 cursor there. (This heuristic seems to give the optimal
17173 behavior for the various types of multi-line strings.) */
17174 if (CHARPOS (row
->end
.string_pos
) >= 0)
17176 if (row
->continued_p
)
17180 /* Check for `display' property. */
17181 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17182 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17183 struct glyph
*glyph
;
17186 for (glyph
= end
; glyph
>= beg
; --glyph
)
17187 if (STRINGP (glyph
->object
))
17190 = Fget_char_property (make_number (PT
),
17194 && display_prop_string_p (prop
, glyph
->object
));
17199 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17201 /* If the row ends in middle of a real character,
17202 and the line is continued, we want the cursor here.
17203 That's because CHARPOS (ROW->end.pos) would equal
17204 PT if PT is before the character. */
17205 if (!row
->ends_in_ellipsis_p
)
17206 cursor_row_p
= row
->continued_p
;
17208 /* If the row ends in an ellipsis, then
17209 CHARPOS (ROW->end.pos) will equal point after the
17210 invisible text. We want that position to be displayed
17211 after the ellipsis. */
17214 /* If the row ends at ZV, display the cursor at the end of that
17215 row instead of at the start of the row below. */
17216 else if (row
->ends_at_zv_p
)
17222 return cursor_row_p
;
17227 /* Push the display property PROP so that it will be rendered at the
17228 current position in IT. Return 1 if PROP was successfully pushed,
17232 push_display_prop (struct it
*it
, Lisp_Object prop
)
17236 if (STRINGP (prop
))
17238 if (SCHARS (prop
) == 0)
17245 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17246 it
->current
.overlay_string_index
= -1;
17247 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17248 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17249 it
->method
= GET_FROM_STRING
;
17250 it
->stop_charpos
= 0;
17252 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17254 it
->method
= GET_FROM_STRETCH
;
17257 #ifdef HAVE_WINDOW_SYSTEM
17258 else if (IMAGEP (prop
))
17260 it
->what
= IT_IMAGE
;
17261 it
->image_id
= lookup_image (it
->f
, prop
);
17262 it
->method
= GET_FROM_IMAGE
;
17264 #endif /* HAVE_WINDOW_SYSTEM */
17267 pop_it (it
); /* bogus display property, give up */
17274 /* Return the character-property PROP at the current position in IT. */
17277 get_it_property (struct it
*it
, Lisp_Object prop
)
17279 Lisp_Object position
;
17281 if (STRINGP (it
->object
))
17282 position
= make_number (IT_STRING_CHARPOS (*it
));
17283 else if (BUFFERP (it
->object
))
17284 position
= make_number (IT_CHARPOS (*it
));
17288 return Fget_char_property (position
, prop
, it
->object
);
17291 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17294 handle_line_prefix (struct it
*it
)
17296 Lisp_Object prefix
;
17297 if (it
->continuation_lines_width
> 0)
17299 prefix
= get_it_property (it
, Qwrap_prefix
);
17301 prefix
= Vwrap_prefix
;
17305 prefix
= get_it_property (it
, Qline_prefix
);
17307 prefix
= Vline_prefix
;
17309 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17311 /* If the prefix is wider than the window, and we try to wrap
17312 it, it would acquire its own wrap prefix, and so on till the
17313 iterator stack overflows. So, don't wrap the prefix. */
17314 it
->line_wrap
= TRUNCATE
;
17315 it
->avoid_cursor_p
= 1;
17321 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17322 only for R2L lines from display_line, when it decides that too many
17323 glyphs were produced by PRODUCE_GLYPHS, and the line needs to be
17326 unproduce_glyphs (struct it
*it
, int n
)
17328 struct glyph
*glyph
, *end
;
17330 xassert (it
->glyph_row
);
17331 xassert (it
->glyph_row
->reversed_p
);
17332 xassert (it
->area
== TEXT_AREA
);
17333 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17335 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17336 n
= it
->glyph_row
->used
[TEXT_AREA
];
17337 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17338 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17339 for ( ; glyph
< end
; glyph
++)
17340 glyph
[-n
] = *glyph
;
17343 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17344 and ROW->maxpos. */
17346 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17347 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17348 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17350 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17351 lines' rows is implemented for bidi-reordered rows. */
17353 /* ROW->minpos is the value of min_pos, the minimal buffer position
17356 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17359 /* We didn't find _any_ valid buffer positions in any of the
17360 glyphs, so we must trust the iterator's computed
17362 row
->minpos
= row
->start
.pos
;
17363 max_pos
= CHARPOS (it
->current
.pos
);
17364 max_bpos
= BYTEPOS (it
->current
.pos
);
17370 /* Here are the various use-cases for ending the row, and the
17371 corresponding values for ROW->maxpos:
17373 Line ends in a newline from buffer eol_pos + 1
17374 Line is continued from buffer max_pos + 1
17375 Line is truncated on right it->current.pos
17376 Line ends in a newline from string max_pos
17377 Line is continued from string max_pos
17378 Line is continued from display vector max_pos
17379 Line is entirely from a string min_pos == max_pos
17380 Line is entirely from a display vector min_pos == max_pos
17381 Line that ends at ZV ZV
17383 If you discover other use-cases, please add them here as
17385 if (row
->ends_at_zv_p
)
17386 row
->maxpos
= it
->current
.pos
;
17387 else if (row
->used
[TEXT_AREA
])
17389 if (row
->ends_in_newline_from_string_p
)
17390 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17391 else if (CHARPOS (it
->eol_pos
) > 0)
17392 SET_TEXT_POS (row
->maxpos
,
17393 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17394 else if (row
->continued_p
)
17396 /* If max_pos is different from IT's current position, it
17397 means IT->method does not belong to the display element
17398 at max_pos. However, it also means that the display
17399 element at max_pos was displayed in its entirety on this
17400 line, which is equivalent to saying that the next line
17401 starts at the next buffer position. */
17402 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17403 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17406 INC_BOTH (max_pos
, max_bpos
);
17407 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17410 else if (row
->truncated_on_right_p
)
17411 /* display_line already called reseat_at_next_visible_line_start,
17412 which puts the iterator at the beginning of the next line, in
17413 the logical order. */
17414 row
->maxpos
= it
->current
.pos
;
17415 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17416 /* A line that is entirely from a string/image/stretch... */
17417 row
->maxpos
= row
->minpos
;
17422 row
->maxpos
= it
->current
.pos
;
17425 /* Construct the glyph row IT->glyph_row in the desired matrix of
17426 IT->w from text at the current position of IT. See dispextern.h
17427 for an overview of struct it. Value is non-zero if
17428 IT->glyph_row displays text, as opposed to a line displaying ZV
17432 display_line (struct it
*it
)
17434 struct glyph_row
*row
= it
->glyph_row
;
17435 Lisp_Object overlay_arrow_string
;
17437 int may_wrap
= 0, wrap_x
;
17438 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
17439 int wrap_row_phys_ascent
, wrap_row_phys_height
;
17440 int wrap_row_extra_line_spacing
;
17441 EMACS_INT wrap_row_min_pos
, wrap_row_min_bpos
;
17442 EMACS_INT wrap_row_max_pos
, wrap_row_max_bpos
;
17444 EMACS_INT min_pos
= ZV
+ 1, min_bpos
, max_pos
= 0, max_bpos
;
17446 /* We always start displaying at hpos zero even if hscrolled. */
17447 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17449 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17450 >= it
->w
->desired_matrix
->nrows
)
17452 it
->w
->nrows_scale_factor
++;
17453 fonts_changed_p
= 1;
17457 /* Is IT->w showing the region? */
17458 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17460 /* Clear the result glyph row and enable it. */
17461 prepare_desired_row (row
);
17463 row
->y
= it
->current_y
;
17464 row
->start
= it
->start
;
17465 row
->continuation_lines_width
= it
->continuation_lines_width
;
17466 row
->displays_text_p
= 1;
17467 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17468 it
->starts_in_middle_of_char_p
= 0;
17470 /* Arrange the overlays nicely for our purposes. Usually, we call
17471 display_line on only one line at a time, in which case this
17472 can't really hurt too much, or we call it on lines which appear
17473 one after another in the buffer, in which case all calls to
17474 recenter_overlay_lists but the first will be pretty cheap. */
17475 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17477 /* Move over display elements that are not visible because we are
17478 hscrolled. This may stop at an x-position < IT->first_visible_x
17479 if the first glyph is partially visible or if we hit a line end. */
17480 if (it
->current_x
< it
->first_visible_x
)
17482 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17483 MOVE_TO_POS
| MOVE_TO_X
);
17487 /* We only do this when not calling `move_it_in_display_line_to'
17488 above, because move_it_in_display_line_to calls
17489 handle_line_prefix itself. */
17490 handle_line_prefix (it
);
17493 /* Get the initial row height. This is either the height of the
17494 text hscrolled, if there is any, or zero. */
17495 row
->ascent
= it
->max_ascent
;
17496 row
->height
= it
->max_ascent
+ it
->max_descent
;
17497 row
->phys_ascent
= it
->max_phys_ascent
;
17498 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17499 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17501 /* Utility macro to record max and min buffer positions seen until now. */
17502 #define RECORD_MAX_MIN_POS(IT) \
17505 if (IT_CHARPOS (*(IT)) < min_pos) \
17507 min_pos = IT_CHARPOS (*(IT)); \
17508 min_bpos = IT_BYTEPOS (*(IT)); \
17510 if (IT_CHARPOS (*(IT)) > max_pos) \
17512 max_pos = IT_CHARPOS (*(IT)); \
17513 max_bpos = IT_BYTEPOS (*(IT)); \
17518 /* Loop generating characters. The loop is left with IT on the next
17519 character to display. */
17522 int n_glyphs_before
, hpos_before
, x_before
;
17524 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17526 /* Retrieve the next thing to display. Value is zero if end of
17528 if (!get_next_display_element (it
))
17530 /* Maybe add a space at the end of this line that is used to
17531 display the cursor there under X. Set the charpos of the
17532 first glyph of blank lines not corresponding to any text
17534 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17535 row
->exact_window_width_line_p
= 1;
17536 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17537 || row
->used
[TEXT_AREA
] == 0)
17539 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17540 row
->displays_text_p
= 0;
17542 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17543 && (!MINI_WINDOW_P (it
->w
)
17544 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17545 row
->indicate_empty_line_p
= 1;
17548 it
->continuation_lines_width
= 0;
17549 row
->ends_at_zv_p
= 1;
17550 /* A row that displays right-to-left text must always have
17551 its last face extended all the way to the end of line,
17552 even if this row ends in ZV, because we still write to
17553 the screen left to right. */
17554 if (row
->reversed_p
)
17555 extend_face_to_end_of_line (it
);
17559 /* Now, get the metrics of what we want to display. This also
17560 generates glyphs in `row' (which is IT->glyph_row). */
17561 n_glyphs_before
= row
->used
[TEXT_AREA
];
17564 /* Remember the line height so far in case the next element doesn't
17565 fit on the line. */
17566 if (it
->line_wrap
!= TRUNCATE
)
17568 ascent
= it
->max_ascent
;
17569 descent
= it
->max_descent
;
17570 phys_ascent
= it
->max_phys_ascent
;
17571 phys_descent
= it
->max_phys_descent
;
17573 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17575 if (IT_DISPLAYING_WHITESPACE (it
))
17581 wrap_row_used
= row
->used
[TEXT_AREA
];
17582 wrap_row_ascent
= row
->ascent
;
17583 wrap_row_height
= row
->height
;
17584 wrap_row_phys_ascent
= row
->phys_ascent
;
17585 wrap_row_phys_height
= row
->phys_height
;
17586 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17587 wrap_row_min_pos
= min_pos
;
17588 wrap_row_min_bpos
= min_bpos
;
17589 wrap_row_max_pos
= max_pos
;
17590 wrap_row_max_bpos
= max_bpos
;
17596 PRODUCE_GLYPHS (it
);
17598 /* If this display element was in marginal areas, continue with
17600 if (it
->area
!= TEXT_AREA
)
17602 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17603 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17604 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17605 row
->phys_height
= max (row
->phys_height
,
17606 it
->max_phys_ascent
+ it
->max_phys_descent
);
17607 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17608 it
->max_extra_line_spacing
);
17609 set_iterator_to_next (it
, 1);
17613 /* Does the display element fit on the line? If we truncate
17614 lines, we should draw past the right edge of the window. If
17615 we don't truncate, we want to stop so that we can display the
17616 continuation glyph before the right margin. If lines are
17617 continued, there are two possible strategies for characters
17618 resulting in more than 1 glyph (e.g. tabs): Display as many
17619 glyphs as possible in this line and leave the rest for the
17620 continuation line, or display the whole element in the next
17621 line. Original redisplay did the former, so we do it also. */
17622 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17623 hpos_before
= it
->hpos
;
17626 if (/* Not a newline. */
17628 /* Glyphs produced fit entirely in the line. */
17629 && it
->current_x
< it
->last_visible_x
)
17631 it
->hpos
+= nglyphs
;
17632 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17633 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17634 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17635 row
->phys_height
= max (row
->phys_height
,
17636 it
->max_phys_ascent
+ it
->max_phys_descent
);
17637 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17638 it
->max_extra_line_spacing
);
17639 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17640 row
->x
= x
- it
->first_visible_x
;
17641 /* Record the maximum and minimum buffer positions seen so
17642 far in glyphs that will be displayed by this row. */
17644 RECORD_MAX_MIN_POS (it
);
17649 struct glyph
*glyph
;
17651 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17653 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17654 new_x
= x
+ glyph
->pixel_width
;
17656 if (/* Lines are continued. */
17657 it
->line_wrap
!= TRUNCATE
17658 && (/* Glyph doesn't fit on the line. */
17659 new_x
> it
->last_visible_x
17660 /* Or it fits exactly on a window system frame. */
17661 || (new_x
== it
->last_visible_x
17662 && FRAME_WINDOW_P (it
->f
))))
17664 /* End of a continued line. */
17667 || (new_x
== it
->last_visible_x
17668 && FRAME_WINDOW_P (it
->f
)))
17670 /* Current glyph is the only one on the line or
17671 fits exactly on the line. We must continue
17672 the line because we can't draw the cursor
17673 after the glyph. */
17674 row
->continued_p
= 1;
17675 it
->current_x
= new_x
;
17676 it
->continuation_lines_width
+= new_x
;
17678 /* Record the maximum and minimum buffer
17679 positions seen so far in glyphs that will be
17680 displayed by this row. */
17682 RECORD_MAX_MIN_POS (it
);
17683 if (i
== nglyphs
- 1)
17685 /* If line-wrap is on, check if a previous
17686 wrap point was found. */
17687 if (wrap_row_used
> 0
17688 /* Even if there is a previous wrap
17689 point, continue the line here as
17690 usual, if (i) the previous character
17691 was a space or tab AND (ii) the
17692 current character is not. */
17694 || IT_DISPLAYING_WHITESPACE (it
)))
17697 set_iterator_to_next (it
, 1);
17698 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17700 if (!get_next_display_element (it
))
17702 row
->exact_window_width_line_p
= 1;
17703 it
->continuation_lines_width
= 0;
17704 row
->continued_p
= 0;
17705 row
->ends_at_zv_p
= 1;
17707 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17709 row
->continued_p
= 0;
17710 row
->exact_window_width_line_p
= 1;
17715 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17716 && !FRAME_WINDOW_P (it
->f
))
17718 /* A padding glyph that doesn't fit on this line.
17719 This means the whole character doesn't fit
17721 if (row
->reversed_p
)
17722 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17723 - n_glyphs_before
);
17724 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17726 /* Fill the rest of the row with continuation
17727 glyphs like in 20.x. */
17728 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17729 < row
->glyphs
[1 + TEXT_AREA
])
17730 produce_special_glyphs (it
, IT_CONTINUATION
);
17732 row
->continued_p
= 1;
17733 it
->current_x
= x_before
;
17734 it
->continuation_lines_width
+= x_before
;
17736 /* Restore the height to what it was before the
17737 element not fitting on the line. */
17738 it
->max_ascent
= ascent
;
17739 it
->max_descent
= descent
;
17740 it
->max_phys_ascent
= phys_ascent
;
17741 it
->max_phys_descent
= phys_descent
;
17743 else if (wrap_row_used
> 0)
17746 if (row
->reversed_p
)
17747 unproduce_glyphs (it
,
17748 row
->used
[TEXT_AREA
] - wrap_row_used
);
17750 it
->continuation_lines_width
+= wrap_x
;
17751 row
->used
[TEXT_AREA
] = wrap_row_used
;
17752 row
->ascent
= wrap_row_ascent
;
17753 row
->height
= wrap_row_height
;
17754 row
->phys_ascent
= wrap_row_phys_ascent
;
17755 row
->phys_height
= wrap_row_phys_height
;
17756 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17757 min_pos
= wrap_row_min_pos
;
17758 min_bpos
= wrap_row_min_bpos
;
17759 max_pos
= wrap_row_max_pos
;
17760 max_bpos
= wrap_row_max_bpos
;
17761 row
->continued_p
= 1;
17762 row
->ends_at_zv_p
= 0;
17763 row
->exact_window_width_line_p
= 0;
17764 it
->continuation_lines_width
+= x
;
17766 /* Make sure that a non-default face is extended
17767 up to the right margin of the window. */
17768 extend_face_to_end_of_line (it
);
17770 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17772 /* A TAB that extends past the right edge of the
17773 window. This produces a single glyph on
17774 window system frames. We leave the glyph in
17775 this row and let it fill the row, but don't
17776 consume the TAB. */
17777 it
->continuation_lines_width
+= it
->last_visible_x
;
17778 row
->ends_in_middle_of_char_p
= 1;
17779 row
->continued_p
= 1;
17780 glyph
->pixel_width
= it
->last_visible_x
- x
;
17781 it
->starts_in_middle_of_char_p
= 1;
17785 /* Something other than a TAB that draws past
17786 the right edge of the window. Restore
17787 positions to values before the element. */
17788 if (row
->reversed_p
)
17789 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17790 - (n_glyphs_before
+ i
));
17791 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17793 /* Display continuation glyphs. */
17794 if (!FRAME_WINDOW_P (it
->f
))
17795 produce_special_glyphs (it
, IT_CONTINUATION
);
17796 row
->continued_p
= 1;
17798 it
->current_x
= x_before
;
17799 it
->continuation_lines_width
+= x
;
17800 extend_face_to_end_of_line (it
);
17802 if (nglyphs
> 1 && i
> 0)
17804 row
->ends_in_middle_of_char_p
= 1;
17805 it
->starts_in_middle_of_char_p
= 1;
17808 /* Restore the height to what it was before the
17809 element not fitting on the line. */
17810 it
->max_ascent
= ascent
;
17811 it
->max_descent
= descent
;
17812 it
->max_phys_ascent
= phys_ascent
;
17813 it
->max_phys_descent
= phys_descent
;
17818 else if (new_x
> it
->first_visible_x
)
17820 /* Increment number of glyphs actually displayed. */
17823 /* Record the maximum and minimum buffer positions
17824 seen so far in glyphs that will be displayed by
17827 RECORD_MAX_MIN_POS (it
);
17829 if (x
< it
->first_visible_x
)
17830 /* Glyph is partially visible, i.e. row starts at
17831 negative X position. */
17832 row
->x
= x
- it
->first_visible_x
;
17836 /* Glyph is completely off the left margin of the
17837 window. This should not happen because of the
17838 move_it_in_display_line at the start of this
17839 function, unless the text display area of the
17840 window is empty. */
17841 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17845 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17846 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17847 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17848 row
->phys_height
= max (row
->phys_height
,
17849 it
->max_phys_ascent
+ it
->max_phys_descent
);
17850 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17851 it
->max_extra_line_spacing
);
17853 /* End of this display line if row is continued. */
17854 if (row
->continued_p
|| row
->ends_at_zv_p
)
17859 /* Is this a line end? If yes, we're also done, after making
17860 sure that a non-default face is extended up to the right
17861 margin of the window. */
17862 if (ITERATOR_AT_END_OF_LINE_P (it
))
17864 int used_before
= row
->used
[TEXT_AREA
];
17866 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17868 /* Add a space at the end of the line that is used to
17869 display the cursor there. */
17870 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17871 append_space_for_newline (it
, 0);
17873 /* Extend the face to the end of the line. */
17874 extend_face_to_end_of_line (it
);
17876 /* Make sure we have the position. */
17877 if (used_before
== 0)
17878 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17880 /* Record the position of the newline, for use in
17882 it
->eol_pos
= it
->current
.pos
;
17884 /* Consume the line end. This skips over invisible lines. */
17885 set_iterator_to_next (it
, 1);
17886 it
->continuation_lines_width
= 0;
17890 /* Proceed with next display element. Note that this skips
17891 over lines invisible because of selective display. */
17892 set_iterator_to_next (it
, 1);
17894 /* If we truncate lines, we are done when the last displayed
17895 glyphs reach past the right margin of the window. */
17896 if (it
->line_wrap
== TRUNCATE
17897 && (FRAME_WINDOW_P (it
->f
)
17898 ? (it
->current_x
>= it
->last_visible_x
)
17899 : (it
->current_x
> it
->last_visible_x
)))
17901 /* Maybe add truncation glyphs. */
17902 if (!FRAME_WINDOW_P (it
->f
))
17906 if (!row
->reversed_p
)
17908 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17909 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17914 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
17915 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17917 /* Remove any padding glyphs at the front of ROW, to
17918 make room for the truncation glyphs we will be
17919 adding below. The loop below always inserts at
17920 least one truncation glyph, so also remove the
17921 last glyph added to ROW. */
17922 unproduce_glyphs (it
, i
+ 1);
17923 /* Adjust i for the loop below. */
17924 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
17927 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17929 row
->used
[TEXT_AREA
] = i
;
17930 produce_special_glyphs (it
, IT_TRUNCATION
);
17933 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17935 /* Don't truncate if we can overflow newline into fringe. */
17936 if (!get_next_display_element (it
))
17938 it
->continuation_lines_width
= 0;
17939 row
->ends_at_zv_p
= 1;
17940 row
->exact_window_width_line_p
= 1;
17943 if (ITERATOR_AT_END_OF_LINE_P (it
))
17945 row
->exact_window_width_line_p
= 1;
17946 goto at_end_of_line
;
17950 row
->truncated_on_right_p
= 1;
17951 it
->continuation_lines_width
= 0;
17952 reseat_at_next_visible_line_start (it
, 0);
17953 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17954 it
->hpos
= hpos_before
;
17955 it
->current_x
= x_before
;
17960 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17961 at the left window margin. */
17962 if (it
->first_visible_x
17963 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
17965 if (!FRAME_WINDOW_P (it
->f
))
17966 insert_left_trunc_glyphs (it
);
17967 row
->truncated_on_left_p
= 1;
17970 /* Remember the position at which this line ends.
17972 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
17973 cannot be before the call to find_row_edges below, since that is
17974 where these positions are determined. */
17975 row
->end
= it
->current
;
17978 row
->minpos
= row
->start
.pos
;
17979 row
->maxpos
= row
->end
.pos
;
17983 /* ROW->minpos and ROW->maxpos must be the smallest and
17984 `1 + the largest' buffer positions in ROW. But if ROW was
17985 bidi-reordered, these two positions can be anywhere in the
17986 row, so we must determine them now. */
17987 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
17990 /* If the start of this line is the overlay arrow-position, then
17991 mark this glyph row as the one containing the overlay arrow.
17992 This is clearly a mess with variable size fonts. It would be
17993 better to let it be displayed like cursors under X. */
17994 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17995 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17996 !NILP (overlay_arrow_string
)))
17998 /* Overlay arrow in window redisplay is a fringe bitmap. */
17999 if (STRINGP (overlay_arrow_string
))
18001 struct glyph_row
*arrow_row
18002 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18003 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18004 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18005 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18006 struct glyph
*p2
, *end
;
18008 /* Copy the arrow glyphs. */
18009 while (glyph
< arrow_end
)
18012 /* Throw away padding glyphs. */
18014 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18015 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18021 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18026 xassert (INTEGERP (overlay_arrow_string
));
18027 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18029 overlay_arrow_seen
= 1;
18032 /* Compute pixel dimensions of this line. */
18033 compute_line_metrics (it
);
18035 /* Record whether this row ends inside an ellipsis. */
18036 row
->ends_in_ellipsis_p
18037 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18038 && it
->ellipsis_p
);
18040 /* Save fringe bitmaps in this row. */
18041 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18042 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18043 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18044 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18046 it
->left_user_fringe_bitmap
= 0;
18047 it
->left_user_fringe_face_id
= 0;
18048 it
->right_user_fringe_bitmap
= 0;
18049 it
->right_user_fringe_face_id
= 0;
18051 /* Maybe set the cursor. */
18052 cvpos
= it
->w
->cursor
.vpos
;
18054 /* In bidi-reordered rows, keep checking for proper cursor
18055 position even if one has been found already, because buffer
18056 positions in such rows change non-linearly with ROW->VPOS,
18057 when a line is continued. One exception: when we are at ZV,
18058 display cursor on the first suitable glyph row, since all
18059 the empty rows after that also have their position set to ZV. */
18060 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18061 lines' rows is implemented for bidi-reordered rows. */
18063 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18064 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18065 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18066 && cursor_row_p (it
->w
, row
))
18067 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18069 /* Highlight trailing whitespace. */
18070 if (!NILP (Vshow_trailing_whitespace
))
18071 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18073 /* Prepare for the next line. This line starts horizontally at (X
18074 HPOS) = (0 0). Vertical positions are incremented. As a
18075 convenience for the caller, IT->glyph_row is set to the next
18077 it
->current_x
= it
->hpos
= 0;
18078 it
->current_y
+= row
->height
;
18079 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18082 /* The next row should by default use the same value of the
18083 reversed_p flag as this one. set_iterator_to_next decides when
18084 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18085 the flag accordingly. */
18086 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18087 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18088 it
->start
= row
->end
;
18089 return row
->displays_text_p
;
18091 #undef RECORD_MAX_MIN_POS
18094 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18095 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18096 doc
: /* Return paragraph direction at point in BUFFER.
18097 Value is either `left-to-right' or `right-to-left'.
18098 If BUFFER is omitted or nil, it defaults to the current buffer.
18100 Paragraph direction determines how the text in the paragraph is displayed.
18101 In left-to-right paragraphs, text begins at the left margin of the window
18102 and the reading direction is generally left to right. In right-to-left
18103 paragraphs, text begins at the right margin and is read from right to left.
18105 See also `bidi-paragraph-direction'. */)
18106 (Lisp_Object buffer
)
18108 struct buffer
*buf
;
18109 struct buffer
*old
;
18112 buf
= current_buffer
;
18115 CHECK_BUFFER (buffer
);
18116 buf
= XBUFFER (buffer
);
18117 old
= current_buffer
;
18120 if (NILP (buf
->bidi_display_reordering
))
18121 return Qleft_to_right
;
18122 else if (!NILP (buf
->bidi_paragraph_direction
))
18123 return buf
->bidi_paragraph_direction
;
18126 /* Determine the direction from buffer text. We could try to
18127 use current_matrix if it is up to date, but this seems fast
18128 enough as it is. */
18129 struct bidi_it itb
;
18130 EMACS_INT pos
= BUF_PT (buf
);
18131 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18134 if (buf
!= current_buffer
)
18135 set_buffer_temp (buf
);
18136 /* bidi_paragraph_init finds the base direction of the paragraph
18137 by searching forward from paragraph start. We need the base
18138 direction of the current or _previous_ paragraph, so we need
18139 to make sure we are within that paragraph. To that end, find
18140 the previous non-empty line. */
18141 if (pos
>= ZV
&& pos
> BEGV
)
18144 bytepos
= CHAR_TO_BYTE (pos
);
18146 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18147 || c
== ' ' || c
== '\t' || c
== '\f')
18149 if (bytepos
<= BEGV_BYTE
)
18154 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18157 itb
.bytepos
= bytepos
;
18159 itb
.separator_limit
= -1;
18160 itb
.paragraph_dir
= NEUTRAL_DIR
;
18162 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18163 if (buf
!= current_buffer
)
18164 set_buffer_temp (old
);
18165 switch (itb
.paragraph_dir
)
18168 return Qleft_to_right
;
18171 return Qright_to_left
;
18181 /***********************************************************************
18183 ***********************************************************************/
18185 /* Redisplay the menu bar in the frame for window W.
18187 The menu bar of X frames that don't have X toolkit support is
18188 displayed in a special window W->frame->menu_bar_window.
18190 The menu bar of terminal frames is treated specially as far as
18191 glyph matrices are concerned. Menu bar lines are not part of
18192 windows, so the update is done directly on the frame matrix rows
18193 for the menu bar. */
18196 display_menu_bar (struct window
*w
)
18198 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18203 /* Don't do all this for graphical frames. */
18205 if (FRAME_W32_P (f
))
18208 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18214 if (FRAME_NS_P (f
))
18216 #endif /* HAVE_NS */
18218 #ifdef USE_X_TOOLKIT
18219 xassert (!FRAME_WINDOW_P (f
));
18220 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18221 it
.first_visible_x
= 0;
18222 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18223 #else /* not USE_X_TOOLKIT */
18224 if (FRAME_WINDOW_P (f
))
18226 /* Menu bar lines are displayed in the desired matrix of the
18227 dummy window menu_bar_window. */
18228 struct window
*menu_w
;
18229 xassert (WINDOWP (f
->menu_bar_window
));
18230 menu_w
= XWINDOW (f
->menu_bar_window
);
18231 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18233 it
.first_visible_x
= 0;
18234 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18238 /* This is a TTY frame, i.e. character hpos/vpos are used as
18240 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18242 it
.first_visible_x
= 0;
18243 it
.last_visible_x
= FRAME_COLS (f
);
18245 #endif /* not USE_X_TOOLKIT */
18247 if (! mode_line_inverse_video
)
18248 /* Force the menu-bar to be displayed in the default face. */
18249 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18251 /* Clear all rows of the menu bar. */
18252 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18254 struct glyph_row
*row
= it
.glyph_row
+ i
;
18255 clear_glyph_row (row
);
18256 row
->enabled_p
= 1;
18257 row
->full_width_p
= 1;
18260 /* Display all items of the menu bar. */
18261 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18262 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
18264 Lisp_Object string
;
18266 /* Stop at nil string. */
18267 string
= AREF (items
, i
+ 1);
18271 /* Remember where item was displayed. */
18272 ASET (items
, i
+ 3, make_number (it
.hpos
));
18274 /* Display the item, pad with one space. */
18275 if (it
.current_x
< it
.last_visible_x
)
18276 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18277 SCHARS (string
) + 1, 0, 0, -1);
18280 /* Fill out the line with spaces. */
18281 if (it
.current_x
< it
.last_visible_x
)
18282 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18284 /* Compute the total height of the lines. */
18285 compute_line_metrics (&it
);
18290 /***********************************************************************
18292 ***********************************************************************/
18294 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18295 FORCE is non-zero, redisplay mode lines unconditionally.
18296 Otherwise, redisplay only mode lines that are garbaged. Value is
18297 the number of windows whose mode lines were redisplayed. */
18300 redisplay_mode_lines (Lisp_Object window
, int force
)
18304 while (!NILP (window
))
18306 struct window
*w
= XWINDOW (window
);
18308 if (WINDOWP (w
->hchild
))
18309 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18310 else if (WINDOWP (w
->vchild
))
18311 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18313 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18314 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18316 struct text_pos lpoint
;
18317 struct buffer
*old
= current_buffer
;
18319 /* Set the window's buffer for the mode line display. */
18320 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18321 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18323 /* Point refers normally to the selected window. For any
18324 other window, set up appropriate value. */
18325 if (!EQ (window
, selected_window
))
18327 struct text_pos pt
;
18329 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18330 if (CHARPOS (pt
) < BEGV
)
18331 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18332 else if (CHARPOS (pt
) > (ZV
- 1))
18333 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18335 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18338 /* Display mode lines. */
18339 clear_glyph_matrix (w
->desired_matrix
);
18340 if (display_mode_lines (w
))
18343 w
->must_be_updated_p
= 1;
18346 /* Restore old settings. */
18347 set_buffer_internal_1 (old
);
18348 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18358 /* Display the mode and/or header line of window W. Value is the
18359 sum number of mode lines and header lines displayed. */
18362 display_mode_lines (struct window
*w
)
18364 Lisp_Object old_selected_window
, old_selected_frame
;
18367 old_selected_frame
= selected_frame
;
18368 selected_frame
= w
->frame
;
18369 old_selected_window
= selected_window
;
18370 XSETWINDOW (selected_window
, w
);
18372 /* These will be set while the mode line specs are processed. */
18373 line_number_displayed
= 0;
18374 w
->column_number_displayed
= Qnil
;
18376 if (WINDOW_WANTS_MODELINE_P (w
))
18378 struct window
*sel_w
= XWINDOW (old_selected_window
);
18380 /* Select mode line face based on the real selected window. */
18381 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18382 current_buffer
->mode_line_format
);
18386 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18388 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18389 current_buffer
->header_line_format
);
18393 selected_frame
= old_selected_frame
;
18394 selected_window
= old_selected_window
;
18399 /* Display mode or header line of window W. FACE_ID specifies which
18400 line to display; it is either MODE_LINE_FACE_ID or
18401 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18402 display. Value is the pixel height of the mode/header line
18406 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18410 int count
= SPECPDL_INDEX ();
18412 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18413 /* Don't extend on a previously drawn mode-line.
18414 This may happen if called from pos_visible_p. */
18415 it
.glyph_row
->enabled_p
= 0;
18416 prepare_desired_row (it
.glyph_row
);
18418 it
.glyph_row
->mode_line_p
= 1;
18420 if (! mode_line_inverse_video
)
18421 /* Force the mode-line to be displayed in the default face. */
18422 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18424 record_unwind_protect (unwind_format_mode_line
,
18425 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18427 mode_line_target
= MODE_LINE_DISPLAY
;
18429 /* Temporarily make frame's keyboard the current kboard so that
18430 kboard-local variables in the mode_line_format will get the right
18432 push_kboard (FRAME_KBOARD (it
.f
));
18433 record_unwind_save_match_data ();
18434 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18437 unbind_to (count
, Qnil
);
18439 /* Fill up with spaces. */
18440 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18442 compute_line_metrics (&it
);
18443 it
.glyph_row
->full_width_p
= 1;
18444 it
.glyph_row
->continued_p
= 0;
18445 it
.glyph_row
->truncated_on_left_p
= 0;
18446 it
.glyph_row
->truncated_on_right_p
= 0;
18448 /* Make a 3D mode-line have a shadow at its right end. */
18449 face
= FACE_FROM_ID (it
.f
, face_id
);
18450 extend_face_to_end_of_line (&it
);
18451 if (face
->box
!= FACE_NO_BOX
)
18453 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18454 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18455 last
->right_box_line_p
= 1;
18458 return it
.glyph_row
->height
;
18461 /* Move element ELT in LIST to the front of LIST.
18462 Return the updated list. */
18465 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
18467 register Lisp_Object tail
, prev
;
18468 register Lisp_Object tem
;
18472 while (CONSP (tail
))
18478 /* Splice out the link TAIL. */
18480 list
= XCDR (tail
);
18482 Fsetcdr (prev
, XCDR (tail
));
18484 /* Now make it the first. */
18485 Fsetcdr (tail
, list
);
18490 tail
= XCDR (tail
);
18494 /* Not found--return unchanged LIST. */
18498 /* Contribute ELT to the mode line for window IT->w. How it
18499 translates into text depends on its data type.
18501 IT describes the display environment in which we display, as usual.
18503 DEPTH is the depth in recursion. It is used to prevent
18504 infinite recursion here.
18506 FIELD_WIDTH is the number of characters the display of ELT should
18507 occupy in the mode line, and PRECISION is the maximum number of
18508 characters to display from ELT's representation. See
18509 display_string for details.
18511 Returns the hpos of the end of the text generated by ELT.
18513 PROPS is a property list to add to any string we encounter.
18515 If RISKY is nonzero, remove (disregard) any properties in any string
18516 we encounter, and ignore :eval and :propertize.
18518 The global variable `mode_line_target' determines whether the
18519 output is passed to `store_mode_line_noprop',
18520 `store_mode_line_string', or `display_string'. */
18523 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
18524 Lisp_Object elt
, Lisp_Object props
, int risky
)
18526 int n
= 0, field
, prec
;
18531 elt
= build_string ("*too-deep*");
18535 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18539 /* A string: output it and check for %-constructs within it. */
18541 EMACS_INT offset
= 0;
18543 if (SCHARS (elt
) > 0
18544 && (!NILP (props
) || risky
))
18546 Lisp_Object oprops
, aelt
;
18547 oprops
= Ftext_properties_at (make_number (0), elt
);
18549 /* If the starting string's properties are not what
18550 we want, translate the string. Also, if the string
18551 is risky, do that anyway. */
18553 if (NILP (Fequal (props
, oprops
)) || risky
)
18555 /* If the starting string has properties,
18556 merge the specified ones onto the existing ones. */
18557 if (! NILP (oprops
) && !risky
)
18561 oprops
= Fcopy_sequence (oprops
);
18563 while (CONSP (tem
))
18565 oprops
= Fplist_put (oprops
, XCAR (tem
),
18566 XCAR (XCDR (tem
)));
18567 tem
= XCDR (XCDR (tem
));
18572 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18573 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18575 /* AELT is what we want. Move it to the front
18576 without consing. */
18578 mode_line_proptrans_alist
18579 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18585 /* If AELT has the wrong props, it is useless.
18586 so get rid of it. */
18588 mode_line_proptrans_alist
18589 = Fdelq (aelt
, mode_line_proptrans_alist
);
18591 elt
= Fcopy_sequence (elt
);
18592 Fset_text_properties (make_number (0), Flength (elt
),
18594 /* Add this item to mode_line_proptrans_alist. */
18595 mode_line_proptrans_alist
18596 = Fcons (Fcons (elt
, props
),
18597 mode_line_proptrans_alist
);
18598 /* Truncate mode_line_proptrans_alist
18599 to at most 50 elements. */
18600 tem
= Fnthcdr (make_number (50),
18601 mode_line_proptrans_alist
);
18603 XSETCDR (tem
, Qnil
);
18612 prec
= precision
- n
;
18613 switch (mode_line_target
)
18615 case MODE_LINE_NOPROP
:
18616 case MODE_LINE_TITLE
:
18617 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
18619 case MODE_LINE_STRING
:
18620 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18622 case MODE_LINE_DISPLAY
:
18623 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18624 0, prec
, 0, STRING_MULTIBYTE (elt
));
18631 /* Handle the non-literal case. */
18633 while ((precision
<= 0 || n
< precision
)
18634 && SREF (elt
, offset
) != 0
18635 && (mode_line_target
!= MODE_LINE_DISPLAY
18636 || it
->current_x
< it
->last_visible_x
))
18638 EMACS_INT last_offset
= offset
;
18640 /* Advance to end of string or next format specifier. */
18641 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18644 if (offset
- 1 != last_offset
)
18646 EMACS_INT nchars
, nbytes
;
18648 /* Output to end of string or up to '%'. Field width
18649 is length of string. Don't output more than
18650 PRECISION allows us. */
18653 prec
= c_string_width (SDATA (elt
) + last_offset
,
18654 offset
- last_offset
, precision
- n
,
18657 switch (mode_line_target
)
18659 case MODE_LINE_NOPROP
:
18660 case MODE_LINE_TITLE
:
18661 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18663 case MODE_LINE_STRING
:
18665 EMACS_INT bytepos
= last_offset
;
18666 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18667 EMACS_INT endpos
= (precision
<= 0
18668 ? string_byte_to_char (elt
, offset
)
18669 : charpos
+ nchars
);
18671 n
+= store_mode_line_string (NULL
,
18672 Fsubstring (elt
, make_number (charpos
),
18673 make_number (endpos
)),
18677 case MODE_LINE_DISPLAY
:
18679 EMACS_INT bytepos
= last_offset
;
18680 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18682 if (precision
<= 0)
18683 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18684 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18686 STRING_MULTIBYTE (elt
));
18691 else /* c == '%' */
18693 EMACS_INT percent_position
= offset
;
18695 /* Get the specified minimum width. Zero means
18698 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18699 field
= field
* 10 + c
- '0';
18701 /* Don't pad beyond the total padding allowed. */
18702 if (field_width
- n
> 0 && field
> field_width
- n
)
18703 field
= field_width
- n
;
18705 /* Note that either PRECISION <= 0 or N < PRECISION. */
18706 prec
= precision
- n
;
18709 n
+= display_mode_element (it
, depth
, field
, prec
,
18710 Vglobal_mode_string
, props
,
18715 EMACS_INT bytepos
, charpos
;
18716 const unsigned char *spec
;
18717 Lisp_Object string
;
18719 bytepos
= percent_position
;
18720 charpos
= (STRING_MULTIBYTE (elt
)
18721 ? string_byte_to_char (elt
, bytepos
)
18723 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
18724 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18726 switch (mode_line_target
)
18728 case MODE_LINE_NOPROP
:
18729 case MODE_LINE_TITLE
:
18730 n
+= store_mode_line_noprop (spec
, field
, prec
);
18732 case MODE_LINE_STRING
:
18734 int len
= strlen (spec
);
18735 Lisp_Object tem
= make_string (spec
, len
);
18736 props
= Ftext_properties_at (make_number (charpos
), elt
);
18737 /* Should only keep face property in props */
18738 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18741 case MODE_LINE_DISPLAY
:
18743 int nglyphs_before
, nwritten
;
18745 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18746 nwritten
= display_string (spec
, string
, elt
,
18751 /* Assign to the glyphs written above the
18752 string where the `%x' came from, position
18756 struct glyph
*glyph
18757 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18761 for (i
= 0; i
< nwritten
; ++i
)
18763 glyph
[i
].object
= elt
;
18764 glyph
[i
].charpos
= charpos
;
18781 /* A symbol: process the value of the symbol recursively
18782 as if it appeared here directly. Avoid error if symbol void.
18783 Special case: if value of symbol is a string, output the string
18786 register Lisp_Object tem
;
18788 /* If the variable is not marked as risky to set
18789 then its contents are risky to use. */
18790 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18793 tem
= Fboundp (elt
);
18796 tem
= Fsymbol_value (elt
);
18797 /* If value is a string, output that string literally:
18798 don't check for % within it. */
18802 if (!EQ (tem
, elt
))
18804 /* Give up right away for nil or t. */
18814 register Lisp_Object car
, tem
;
18816 /* A cons cell: five distinct cases.
18817 If first element is :eval or :propertize, do something special.
18818 If first element is a string or a cons, process all the elements
18819 and effectively concatenate them.
18820 If first element is a negative number, truncate displaying cdr to
18821 at most that many characters. If positive, pad (with spaces)
18822 to at least that many characters.
18823 If first element is a symbol, process the cadr or caddr recursively
18824 according to whether the symbol's value is non-nil or nil. */
18826 if (EQ (car
, QCeval
))
18828 /* An element of the form (:eval FORM) means evaluate FORM
18829 and use the result as mode line elements. */
18834 if (CONSP (XCDR (elt
)))
18837 spec
= safe_eval (XCAR (XCDR (elt
)));
18838 n
+= display_mode_element (it
, depth
, field_width
- n
,
18839 precision
- n
, spec
, props
,
18843 else if (EQ (car
, QCpropertize
))
18845 /* An element of the form (:propertize ELT PROPS...)
18846 means display ELT but applying properties PROPS. */
18851 if (CONSP (XCDR (elt
)))
18852 n
+= display_mode_element (it
, depth
, field_width
- n
,
18853 precision
- n
, XCAR (XCDR (elt
)),
18854 XCDR (XCDR (elt
)), risky
);
18856 else if (SYMBOLP (car
))
18858 tem
= Fboundp (car
);
18862 /* elt is now the cdr, and we know it is a cons cell.
18863 Use its car if CAR has a non-nil value. */
18866 tem
= Fsymbol_value (car
);
18873 /* Symbol's value is nil (or symbol is unbound)
18874 Get the cddr of the original list
18875 and if possible find the caddr and use that. */
18879 else if (!CONSP (elt
))
18884 else if (INTEGERP (car
))
18886 register int lim
= XINT (car
);
18890 /* Negative int means reduce maximum width. */
18891 if (precision
<= 0)
18894 precision
= min (precision
, -lim
);
18898 /* Padding specified. Don't let it be more than
18899 current maximum. */
18901 lim
= min (precision
, lim
);
18903 /* If that's more padding than already wanted, queue it.
18904 But don't reduce padding already specified even if
18905 that is beyond the current truncation point. */
18906 field_width
= max (lim
, field_width
);
18910 else if (STRINGP (car
) || CONSP (car
))
18912 Lisp_Object halftail
= elt
;
18916 && (precision
<= 0 || n
< precision
))
18918 n
+= display_mode_element (it
, depth
,
18919 /* Do padding only after the last
18920 element in the list. */
18921 (! CONSP (XCDR (elt
))
18924 precision
- n
, XCAR (elt
),
18928 if ((len
& 1) == 0)
18929 halftail
= XCDR (halftail
);
18930 /* Check for cycle. */
18931 if (EQ (halftail
, elt
))
18940 elt
= build_string ("*invalid*");
18944 /* Pad to FIELD_WIDTH. */
18945 if (field_width
> 0 && n
< field_width
)
18947 switch (mode_line_target
)
18949 case MODE_LINE_NOPROP
:
18950 case MODE_LINE_TITLE
:
18951 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18953 case MODE_LINE_STRING
:
18954 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18956 case MODE_LINE_DISPLAY
:
18957 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18966 /* Store a mode-line string element in mode_line_string_list.
18968 If STRING is non-null, display that C string. Otherwise, the Lisp
18969 string LISP_STRING is displayed.
18971 FIELD_WIDTH is the minimum number of output glyphs to produce.
18972 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18973 with spaces. FIELD_WIDTH <= 0 means don't pad.
18975 PRECISION is the maximum number of characters to output from
18976 STRING. PRECISION <= 0 means don't truncate the string.
18978 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18979 properties to the string.
18981 PROPS are the properties to add to the string.
18982 The mode_line_string_face face property is always added to the string.
18986 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
18987 int field_width
, int precision
, Lisp_Object props
)
18992 if (string
!= NULL
)
18994 len
= strlen (string
);
18995 if (precision
> 0 && len
> precision
)
18997 lisp_string
= make_string (string
, len
);
18999 props
= mode_line_string_face_prop
;
19000 else if (!NILP (mode_line_string_face
))
19002 Lisp_Object face
= Fplist_get (props
, Qface
);
19003 props
= Fcopy_sequence (props
);
19005 face
= mode_line_string_face
;
19007 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19008 props
= Fplist_put (props
, Qface
, face
);
19010 Fadd_text_properties (make_number (0), make_number (len
),
19011 props
, lisp_string
);
19015 len
= XFASTINT (Flength (lisp_string
));
19016 if (precision
> 0 && len
> precision
)
19019 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19022 if (!NILP (mode_line_string_face
))
19026 props
= Ftext_properties_at (make_number (0), lisp_string
);
19027 face
= Fplist_get (props
, Qface
);
19029 face
= mode_line_string_face
;
19031 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19032 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19034 lisp_string
= Fcopy_sequence (lisp_string
);
19037 Fadd_text_properties (make_number (0), make_number (len
),
19038 props
, lisp_string
);
19043 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19047 if (field_width
> len
)
19049 field_width
-= len
;
19050 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19052 Fadd_text_properties (make_number (0), make_number (field_width
),
19053 props
, lisp_string
);
19054 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19062 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19064 doc
: /* Format a string out of a mode line format specification.
19065 First arg FORMAT specifies the mode line format (see `mode-line-format'
19066 for details) to use.
19068 Optional second arg FACE specifies the face property to put
19069 on all characters for which no face is specified.
19070 The value t means whatever face the window's mode line currently uses
19071 \(either `mode-line' or `mode-line-inactive', depending).
19072 A value of nil means the default is no face property.
19073 If FACE is an integer, the value string has no text properties.
19075 Optional third and fourth args WINDOW and BUFFER specify the window
19076 and buffer to use as the context for the formatting (defaults
19077 are the selected window and the window's buffer). */)
19078 (Lisp_Object format
, Lisp_Object face
, Lisp_Object window
, Lisp_Object buffer
)
19083 struct buffer
*old_buffer
= NULL
;
19085 int no_props
= INTEGERP (face
);
19086 int count
= SPECPDL_INDEX ();
19088 int string_start
= 0;
19091 window
= selected_window
;
19092 CHECK_WINDOW (window
);
19093 w
= XWINDOW (window
);
19096 buffer
= w
->buffer
;
19097 CHECK_BUFFER (buffer
);
19099 /* Make formatting the modeline a non-op when noninteractive, otherwise
19100 there will be problems later caused by a partially initialized frame. */
19101 if (NILP (format
) || noninteractive
)
19102 return empty_unibyte_string
;
19110 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
19111 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
19115 face_id
= DEFAULT_FACE_ID
;
19117 if (XBUFFER (buffer
) != current_buffer
)
19118 old_buffer
= current_buffer
;
19120 /* Save things including mode_line_proptrans_alist,
19121 and set that to nil so that we don't alter the outer value. */
19122 record_unwind_protect (unwind_format_mode_line
,
19123 format_mode_line_unwind_data
19124 (old_buffer
, selected_window
, 1));
19125 mode_line_proptrans_alist
= Qnil
;
19127 Fselect_window (window
, Qt
);
19129 set_buffer_internal_1 (XBUFFER (buffer
));
19131 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19135 mode_line_target
= MODE_LINE_NOPROP
;
19136 mode_line_string_face_prop
= Qnil
;
19137 mode_line_string_list
= Qnil
;
19138 string_start
= MODE_LINE_NOPROP_LEN (0);
19142 mode_line_target
= MODE_LINE_STRING
;
19143 mode_line_string_list
= Qnil
;
19144 mode_line_string_face
= face
;
19145 mode_line_string_face_prop
19146 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19149 push_kboard (FRAME_KBOARD (it
.f
));
19150 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19155 len
= MODE_LINE_NOPROP_LEN (string_start
);
19156 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19160 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19161 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19162 empty_unibyte_string
);
19165 unbind_to (count
, Qnil
);
19169 /* Write a null-terminated, right justified decimal representation of
19170 the positive integer D to BUF using a minimal field width WIDTH. */
19173 pint2str (register char *buf
, register int width
, register int d
)
19175 register char *p
= buf
;
19183 *p
++ = d
% 10 + '0';
19188 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19199 /* Write a null-terminated, right justified decimal and "human
19200 readable" representation of the nonnegative integer D to BUF using
19201 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19203 static const char power_letter
[] =
19217 pint2hrstr (char *buf
, int width
, int d
)
19219 /* We aim to represent the nonnegative integer D as
19220 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19223 /* -1 means: do not use TENTHS. */
19227 /* Length of QUOTIENT.TENTHS as a string. */
19233 if (1000 <= quotient
)
19235 /* Scale to the appropriate EXPONENT. */
19238 remainder
= quotient
% 1000;
19242 while (1000 <= quotient
);
19244 /* Round to nearest and decide whether to use TENTHS or not. */
19247 tenths
= remainder
/ 100;
19248 if (50 <= remainder
% 100)
19255 if (quotient
== 10)
19263 if (500 <= remainder
)
19265 if (quotient
< 999)
19276 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19277 if (tenths
== -1 && quotient
<= 99)
19284 p
= psuffix
= buf
+ max (width
, length
);
19286 /* Print EXPONENT. */
19288 *psuffix
++ = power_letter
[exponent
];
19291 /* Print TENTHS. */
19294 *--p
= '0' + tenths
;
19298 /* Print QUOTIENT. */
19301 int digit
= quotient
% 10;
19302 *--p
= '0' + digit
;
19304 while ((quotient
/= 10) != 0);
19306 /* Print leading spaces. */
19311 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19312 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19313 type of CODING_SYSTEM. Return updated pointer into BUF. */
19315 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19318 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19321 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
19322 const unsigned char *eol_str
;
19324 /* The EOL conversion we are using. */
19325 Lisp_Object eoltype
;
19327 val
= CODING_SYSTEM_SPEC (coding_system
);
19330 if (!VECTORP (val
)) /* Not yet decided. */
19335 eoltype
= eol_mnemonic_undecided
;
19336 /* Don't mention EOL conversion if it isn't decided. */
19341 Lisp_Object eolvalue
;
19343 attrs
= AREF (val
, 0);
19344 eolvalue
= AREF (val
, 2);
19347 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19351 /* The EOL conversion that is normal on this system. */
19353 if (NILP (eolvalue
)) /* Not yet decided. */
19354 eoltype
= eol_mnemonic_undecided
;
19355 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19356 eoltype
= eol_mnemonic_undecided
;
19357 else /* eolvalue is Qunix, Qdos, or Qmac. */
19358 eoltype
= (EQ (eolvalue
, Qunix
)
19359 ? eol_mnemonic_unix
19360 : (EQ (eolvalue
, Qdos
) == 1
19361 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19367 /* Mention the EOL conversion if it is not the usual one. */
19368 if (STRINGP (eoltype
))
19370 eol_str
= SDATA (eoltype
);
19371 eol_str_len
= SBYTES (eoltype
);
19373 else if (CHARACTERP (eoltype
))
19375 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19376 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19381 eol_str
= invalid_eol_type
;
19382 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19384 memcpy (buf
, eol_str
, eol_str_len
);
19385 buf
+= eol_str_len
;
19391 /* Return a string for the output of a mode line %-spec for window W,
19392 generated by character C. PRECISION >= 0 means don't return a
19393 string longer than that value. FIELD_WIDTH > 0 means pad the
19394 string returned with spaces to that value. Return a Lisp string in
19395 *STRING if the resulting string is taken from that Lisp string.
19397 Note we operate on the current buffer for most purposes,
19398 the exception being w->base_line_pos. */
19400 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19402 static const char *
19403 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19404 int precision
, Lisp_Object
*string
)
19407 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19408 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19409 struct buffer
*b
= current_buffer
;
19417 if (!NILP (b
->read_only
))
19419 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19424 /* This differs from %* only for a modified read-only buffer. */
19425 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19427 if (!NILP (b
->read_only
))
19432 /* This differs from %* in ignoring read-only-ness. */
19433 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19445 if (command_loop_level
> 5)
19447 p
= decode_mode_spec_buf
;
19448 for (i
= 0; i
< command_loop_level
; i
++)
19451 return decode_mode_spec_buf
;
19459 if (command_loop_level
> 5)
19461 p
= decode_mode_spec_buf
;
19462 for (i
= 0; i
< command_loop_level
; i
++)
19465 return decode_mode_spec_buf
;
19472 /* Let lots_of_dashes be a string of infinite length. */
19473 if (mode_line_target
== MODE_LINE_NOPROP
||
19474 mode_line_target
== MODE_LINE_STRING
)
19476 if (field_width
<= 0
19477 || field_width
> sizeof (lots_of_dashes
))
19479 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19480 decode_mode_spec_buf
[i
] = '-';
19481 decode_mode_spec_buf
[i
] = '\0';
19482 return decode_mode_spec_buf
;
19485 return lots_of_dashes
;
19493 /* %c and %l are ignored in `frame-title-format'.
19494 (In redisplay_internal, the frame title is drawn _before_ the
19495 windows are updated, so the stuff which depends on actual
19496 window contents (such as %l) may fail to render properly, or
19497 even crash emacs.) */
19498 if (mode_line_target
== MODE_LINE_TITLE
)
19502 int col
= (int) current_column (); /* iftc */
19503 w
->column_number_displayed
= make_number (col
);
19504 pint2str (decode_mode_spec_buf
, field_width
, col
);
19505 return decode_mode_spec_buf
;
19509 #ifndef SYSTEM_MALLOC
19511 if (NILP (Vmemory_full
))
19514 return "!MEM FULL! ";
19521 /* %F displays the frame name. */
19522 if (!NILP (f
->title
))
19523 return (char *) SDATA (f
->title
);
19524 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19525 return (char *) SDATA (f
->name
);
19534 EMACS_INT size
= ZV
- BEGV
;
19535 pint2str (decode_mode_spec_buf
, field_width
, size
);
19536 return decode_mode_spec_buf
;
19541 EMACS_INT size
= ZV
- BEGV
;
19542 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19543 return decode_mode_spec_buf
;
19548 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19549 int topline
, nlines
, height
;
19552 /* %c and %l are ignored in `frame-title-format'. */
19553 if (mode_line_target
== MODE_LINE_TITLE
)
19556 startpos
= XMARKER (w
->start
)->charpos
;
19557 startpos_byte
= marker_byte_position (w
->start
);
19558 height
= WINDOW_TOTAL_LINES (w
);
19560 /* If we decided that this buffer isn't suitable for line numbers,
19561 don't forget that too fast. */
19562 if (EQ (w
->base_line_pos
, w
->buffer
))
19564 /* But do forget it, if the window shows a different buffer now. */
19565 else if (BUFFERP (w
->base_line_pos
))
19566 w
->base_line_pos
= Qnil
;
19568 /* If the buffer is very big, don't waste time. */
19569 if (INTEGERP (Vline_number_display_limit
)
19570 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19572 w
->base_line_pos
= Qnil
;
19573 w
->base_line_number
= Qnil
;
19577 if (INTEGERP (w
->base_line_number
)
19578 && INTEGERP (w
->base_line_pos
)
19579 && XFASTINT (w
->base_line_pos
) <= startpos
)
19581 line
= XFASTINT (w
->base_line_number
);
19582 linepos
= XFASTINT (w
->base_line_pos
);
19583 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19588 linepos
= BUF_BEGV (b
);
19589 linepos_byte
= BUF_BEGV_BYTE (b
);
19592 /* Count lines from base line to window start position. */
19593 nlines
= display_count_lines (linepos
, linepos_byte
,
19597 topline
= nlines
+ line
;
19599 /* Determine a new base line, if the old one is too close
19600 or too far away, or if we did not have one.
19601 "Too close" means it's plausible a scroll-down would
19602 go back past it. */
19603 if (startpos
== BUF_BEGV (b
))
19605 w
->base_line_number
= make_number (topline
);
19606 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19608 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19609 || linepos
== BUF_BEGV (b
))
19611 EMACS_INT limit
= BUF_BEGV (b
);
19612 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
19613 EMACS_INT position
;
19614 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
19616 if (startpos
- distance
> limit
)
19618 limit
= startpos
- distance
;
19619 limit_byte
= CHAR_TO_BYTE (limit
);
19622 nlines
= display_count_lines (startpos
, startpos_byte
,
19624 - (height
* 2 + 30),
19626 /* If we couldn't find the lines we wanted within
19627 line_number_display_limit_width chars per line,
19628 give up on line numbers for this window. */
19629 if (position
== limit_byte
&& limit
== startpos
- distance
)
19631 w
->base_line_pos
= w
->buffer
;
19632 w
->base_line_number
= Qnil
;
19636 w
->base_line_number
= make_number (topline
- nlines
);
19637 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19640 /* Now count lines from the start pos to point. */
19641 nlines
= display_count_lines (startpos
, startpos_byte
,
19642 PT_BYTE
, PT
, &junk
);
19644 /* Record that we did display the line number. */
19645 line_number_displayed
= 1;
19647 /* Make the string to show. */
19648 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19649 return decode_mode_spec_buf
;
19652 char* p
= decode_mode_spec_buf
;
19653 int pad
= field_width
- 2;
19659 return decode_mode_spec_buf
;
19665 obj
= b
->mode_name
;
19669 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19675 EMACS_INT pos
= marker_position (w
->start
);
19676 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19678 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19680 if (pos
<= BUF_BEGV (b
))
19685 else if (pos
<= BUF_BEGV (b
))
19689 if (total
> 1000000)
19690 /* Do it differently for a large value, to avoid overflow. */
19691 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19693 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19694 /* We can't normally display a 3-digit number,
19695 so get us a 2-digit number that is close. */
19698 sprintf (decode_mode_spec_buf
, "%2ld%%", (long)total
);
19699 return decode_mode_spec_buf
;
19703 /* Display percentage of size above the bottom of the screen. */
19706 EMACS_INT toppos
= marker_position (w
->start
);
19707 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19708 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19710 if (botpos
>= BUF_ZV (b
))
19712 if (toppos
<= BUF_BEGV (b
))
19719 if (total
> 1000000)
19720 /* Do it differently for a large value, to avoid overflow. */
19721 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19723 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19724 /* We can't normally display a 3-digit number,
19725 so get us a 2-digit number that is close. */
19728 if (toppos
<= BUF_BEGV (b
))
19729 sprintf (decode_mode_spec_buf
, "Top%2ld%%", (long)total
);
19731 sprintf (decode_mode_spec_buf
, "%2ld%%", (long)total
);
19732 return decode_mode_spec_buf
;
19737 /* status of process */
19738 obj
= Fget_buffer_process (Fcurrent_buffer ());
19740 return "no process";
19742 obj
= Fsymbol_name (Fprocess_status (obj
));
19748 int count
= inhibit_garbage_collection ();
19749 Lisp_Object val
= call1 (intern ("file-remote-p"),
19750 current_buffer
->directory
);
19751 unbind_to (count
, Qnil
);
19759 case 't': /* indicate TEXT or BINARY */
19760 #ifdef MODE_LINE_BINARY_TEXT
19761 return MODE_LINE_BINARY_TEXT (b
);
19767 /* coding-system (not including end-of-line format) */
19769 /* coding-system (including end-of-line type) */
19771 int eol_flag
= (c
== 'Z');
19772 char *p
= decode_mode_spec_buf
;
19774 if (! FRAME_WINDOW_P (f
))
19776 /* No need to mention EOL here--the terminal never needs
19777 to do EOL conversion. */
19778 p
= decode_mode_spec_coding (CODING_ID_NAME
19779 (FRAME_KEYBOARD_CODING (f
)->id
),
19781 p
= decode_mode_spec_coding (CODING_ID_NAME
19782 (FRAME_TERMINAL_CODING (f
)->id
),
19785 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19788 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19789 #ifdef subprocesses
19790 obj
= Fget_buffer_process (Fcurrent_buffer ());
19791 if (PROCESSP (obj
))
19793 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19795 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19798 #endif /* subprocesses */
19801 return decode_mode_spec_buf
;
19808 return (char *) SDATA (obj
);
19815 /* Count up to COUNT lines starting from START / START_BYTE.
19816 But don't go beyond LIMIT_BYTE.
19817 Return the number of lines thus found (always nonnegative).
19819 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19822 display_count_lines (EMACS_INT start
, EMACS_INT start_byte
,
19823 EMACS_INT limit_byte
, int count
,
19824 EMACS_INT
*byte_pos_ptr
)
19826 register unsigned char *cursor
;
19827 unsigned char *base
;
19829 register int ceiling
;
19830 register unsigned char *ceiling_addr
;
19831 int orig_count
= count
;
19833 /* If we are not in selective display mode,
19834 check only for newlines. */
19835 int selective_display
= (!NILP (current_buffer
->selective_display
)
19836 && !INTEGERP (current_buffer
->selective_display
));
19840 while (start_byte
< limit_byte
)
19842 ceiling
= BUFFER_CEILING_OF (start_byte
);
19843 ceiling
= min (limit_byte
- 1, ceiling
);
19844 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19845 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19848 if (selective_display
)
19849 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19852 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19855 if (cursor
!= ceiling_addr
)
19859 start_byte
+= cursor
- base
+ 1;
19860 *byte_pos_ptr
= start_byte
;
19864 if (++cursor
== ceiling_addr
)
19870 start_byte
+= cursor
- base
;
19875 while (start_byte
> limit_byte
)
19877 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19878 ceiling
= max (limit_byte
, ceiling
);
19879 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19880 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19883 if (selective_display
)
19884 while (--cursor
!= ceiling_addr
19885 && *cursor
!= '\n' && *cursor
!= 015)
19888 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19891 if (cursor
!= ceiling_addr
)
19895 start_byte
+= cursor
- base
+ 1;
19896 *byte_pos_ptr
= start_byte
;
19897 /* When scanning backwards, we should
19898 not count the newline posterior to which we stop. */
19899 return - orig_count
- 1;
19905 /* Here we add 1 to compensate for the last decrement
19906 of CURSOR, which took it past the valid range. */
19907 start_byte
+= cursor
- base
+ 1;
19911 *byte_pos_ptr
= limit_byte
;
19914 return - orig_count
+ count
;
19915 return orig_count
- count
;
19921 /***********************************************************************
19923 ***********************************************************************/
19925 /* Display a NUL-terminated string, starting with index START.
19927 If STRING is non-null, display that C string. Otherwise, the Lisp
19928 string LISP_STRING is displayed. There's a case that STRING is
19929 non-null and LISP_STRING is not nil. It means STRING is a string
19930 data of LISP_STRING. In that case, we display LISP_STRING while
19931 ignoring its text properties.
19933 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19934 FACE_STRING. Display STRING or LISP_STRING with the face at
19935 FACE_STRING_POS in FACE_STRING:
19937 Display the string in the environment given by IT, but use the
19938 standard display table, temporarily.
19940 FIELD_WIDTH is the minimum number of output glyphs to produce.
19941 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19942 with spaces. If STRING has more characters, more than FIELD_WIDTH
19943 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19945 PRECISION is the maximum number of characters to output from
19946 STRING. PRECISION < 0 means don't truncate the string.
19948 This is roughly equivalent to printf format specifiers:
19950 FIELD_WIDTH PRECISION PRINTF
19951 ----------------------------------------
19957 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19958 display them, and < 0 means obey the current buffer's value of
19959 enable_multibyte_characters.
19961 Value is the number of columns displayed. */
19964 display_string (const unsigned char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
19965 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
19966 int field_width
, int precision
, int max_x
, int multibyte
)
19968 int hpos_at_start
= it
->hpos
;
19969 int saved_face_id
= it
->face_id
;
19970 struct glyph_row
*row
= it
->glyph_row
;
19972 /* Initialize the iterator IT for iteration over STRING beginning
19973 with index START. */
19974 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19975 precision
, field_width
, multibyte
);
19976 if (string
&& STRINGP (lisp_string
))
19977 /* LISP_STRING is the one returned by decode_mode_spec. We should
19978 ignore its text properties. */
19979 it
->stop_charpos
= -1;
19981 /* If displaying STRING, set up the face of the iterator
19982 from LISP_STRING, if that's given. */
19983 if (STRINGP (face_string
))
19989 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19990 0, it
->region_beg_charpos
,
19991 it
->region_end_charpos
,
19992 &endptr
, it
->base_face_id
, 0);
19993 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19994 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19997 /* Set max_x to the maximum allowed X position. Don't let it go
19998 beyond the right edge of the window. */
20000 max_x
= it
->last_visible_x
;
20002 max_x
= min (max_x
, it
->last_visible_x
);
20004 /* Skip over display elements that are not visible. because IT->w is
20006 if (it
->current_x
< it
->first_visible_x
)
20007 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20008 MOVE_TO_POS
| MOVE_TO_X
);
20010 row
->ascent
= it
->max_ascent
;
20011 row
->height
= it
->max_ascent
+ it
->max_descent
;
20012 row
->phys_ascent
= it
->max_phys_ascent
;
20013 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20014 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20016 /* This condition is for the case that we are called with current_x
20017 past last_visible_x. */
20018 while (it
->current_x
< max_x
)
20020 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20022 /* Get the next display element. */
20023 if (!get_next_display_element (it
))
20026 /* Produce glyphs. */
20027 x_before
= it
->current_x
;
20028 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20029 PRODUCE_GLYPHS (it
);
20031 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
20034 while (i
< nglyphs
)
20036 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20038 if (it
->line_wrap
!= TRUNCATE
20039 && x
+ glyph
->pixel_width
> max_x
)
20041 /* End of continued line or max_x reached. */
20042 if (CHAR_GLYPH_PADDING_P (*glyph
))
20044 /* A wide character is unbreakable. */
20045 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
20046 it
->current_x
= x_before
;
20050 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20055 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20057 /* Glyph is at least partially visible. */
20059 if (x
< it
->first_visible_x
)
20060 it
->glyph_row
->x
= x
- it
->first_visible_x
;
20064 /* Glyph is off the left margin of the display area.
20065 Should not happen. */
20069 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20070 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20071 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20072 row
->phys_height
= max (row
->phys_height
,
20073 it
->max_phys_ascent
+ it
->max_phys_descent
);
20074 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20075 it
->max_extra_line_spacing
);
20076 x
+= glyph
->pixel_width
;
20080 /* Stop if max_x reached. */
20084 /* Stop at line ends. */
20085 if (ITERATOR_AT_END_OF_LINE_P (it
))
20087 it
->continuation_lines_width
= 0;
20091 set_iterator_to_next (it
, 1);
20093 /* Stop if truncating at the right edge. */
20094 if (it
->line_wrap
== TRUNCATE
20095 && it
->current_x
>= it
->last_visible_x
)
20097 /* Add truncation mark, but don't do it if the line is
20098 truncated at a padding space. */
20099 if (IT_CHARPOS (*it
) < it
->string_nchars
)
20101 if (!FRAME_WINDOW_P (it
->f
))
20105 if (it
->current_x
> it
->last_visible_x
)
20107 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20108 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20110 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20112 row
->used
[TEXT_AREA
] = i
;
20113 produce_special_glyphs (it
, IT_TRUNCATION
);
20116 produce_special_glyphs (it
, IT_TRUNCATION
);
20118 it
->glyph_row
->truncated_on_right_p
= 1;
20124 /* Maybe insert a truncation at the left. */
20125 if (it
->first_visible_x
20126 && IT_CHARPOS (*it
) > 0)
20128 if (!FRAME_WINDOW_P (it
->f
))
20129 insert_left_trunc_glyphs (it
);
20130 it
->glyph_row
->truncated_on_left_p
= 1;
20133 it
->face_id
= saved_face_id
;
20135 /* Value is number of columns displayed. */
20136 return it
->hpos
- hpos_at_start
;
20141 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20142 appears as an element of LIST or as the car of an element of LIST.
20143 If PROPVAL is a list, compare each element against LIST in that
20144 way, and return 1/2 if any element of PROPVAL is found in LIST.
20145 Otherwise return 0. This function cannot quit.
20146 The return value is 2 if the text is invisible but with an ellipsis
20147 and 1 if it's invisible and without an ellipsis. */
20150 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20152 register Lisp_Object tail
, proptail
;
20154 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20156 register Lisp_Object tem
;
20158 if (EQ (propval
, tem
))
20160 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20161 return NILP (XCDR (tem
)) ? 1 : 2;
20164 if (CONSP (propval
))
20166 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20168 Lisp_Object propelt
;
20169 propelt
= XCAR (proptail
);
20170 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20172 register Lisp_Object tem
;
20174 if (EQ (propelt
, tem
))
20176 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20177 return NILP (XCDR (tem
)) ? 1 : 2;
20185 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20186 doc
: /* Non-nil if the property makes the text invisible.
20187 POS-OR-PROP can be a marker or number, in which case it is taken to be
20188 a position in the current buffer and the value of the `invisible' property
20189 is checked; or it can be some other value, which is then presumed to be the
20190 value of the `invisible' property of the text of interest.
20191 The non-nil value returned can be t for truly invisible text or something
20192 else if the text is replaced by an ellipsis. */)
20193 (Lisp_Object pos_or_prop
)
20196 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20197 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20199 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20200 return (invis
== 0 ? Qnil
20202 : make_number (invis
));
20205 /* Calculate a width or height in pixels from a specification using
20206 the following elements:
20209 NUM - a (fractional) multiple of the default font width/height
20210 (NUM) - specifies exactly NUM pixels
20211 UNIT - a fixed number of pixels, see below.
20212 ELEMENT - size of a display element in pixels, see below.
20213 (NUM . SPEC) - equals NUM * SPEC
20214 (+ SPEC SPEC ...) - add pixel values
20215 (- SPEC SPEC ...) - subtract pixel values
20216 (- SPEC) - negate pixel value
20219 INT or FLOAT - a number constant
20220 SYMBOL - use symbol's (buffer local) variable binding.
20223 in - pixels per inch *)
20224 mm - pixels per 1/1000 meter *)
20225 cm - pixels per 1/100 meter *)
20226 width - width of current font in pixels.
20227 height - height of current font in pixels.
20229 *) using the ratio(s) defined in display-pixels-per-inch.
20233 left-fringe - left fringe width in pixels
20234 right-fringe - right fringe width in pixels
20236 left-margin - left margin width in pixels
20237 right-margin - right margin width in pixels
20239 scroll-bar - scroll-bar area width in pixels
20243 Pixels corresponding to 5 inches:
20246 Total width of non-text areas on left side of window (if scroll-bar is on left):
20247 '(space :width (+ left-fringe left-margin scroll-bar))
20249 Align to first text column (in header line):
20250 '(space :align-to 0)
20252 Align to middle of text area minus half the width of variable `my-image'
20253 containing a loaded image:
20254 '(space :align-to (0.5 . (- text my-image)))
20256 Width of left margin minus width of 1 character in the default font:
20257 '(space :width (- left-margin 1))
20259 Width of left margin minus width of 2 characters in the current font:
20260 '(space :width (- left-margin (2 . width)))
20262 Center 1 character over left-margin (in header line):
20263 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20265 Different ways to express width of left fringe plus left margin minus one pixel:
20266 '(space :width (- (+ left-fringe left-margin) (1)))
20267 '(space :width (+ left-fringe left-margin (- (1))))
20268 '(space :width (+ left-fringe left-margin (-1)))
20272 #define NUMVAL(X) \
20273 ((INTEGERP (X) || FLOATP (X)) \
20278 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20279 struct font
*font
, int width_p
, int *align_to
)
20283 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20284 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20287 return OK_PIXELS (0);
20289 xassert (FRAME_LIVE_P (it
->f
));
20291 if (SYMBOLP (prop
))
20293 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20295 char *unit
= SDATA (SYMBOL_NAME (prop
));
20297 if (unit
[0] == 'i' && unit
[1] == 'n')
20299 else if (unit
[0] == 'm' && unit
[1] == 'm')
20301 else if (unit
[0] == 'c' && unit
[1] == 'm')
20308 #ifdef HAVE_WINDOW_SYSTEM
20309 if (FRAME_WINDOW_P (it
->f
)
20311 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20312 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20314 return OK_PIXELS (ppi
/ pixels
);
20317 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20318 || (CONSP (Vdisplay_pixels_per_inch
)
20320 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20321 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20323 return OK_PIXELS (ppi
/ pixels
);
20329 #ifdef HAVE_WINDOW_SYSTEM
20330 if (EQ (prop
, Qheight
))
20331 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20332 if (EQ (prop
, Qwidth
))
20333 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20335 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20336 return OK_PIXELS (1);
20339 if (EQ (prop
, Qtext
))
20340 return OK_PIXELS (width_p
20341 ? window_box_width (it
->w
, TEXT_AREA
)
20342 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20344 if (align_to
&& *align_to
< 0)
20347 if (EQ (prop
, Qleft
))
20348 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20349 if (EQ (prop
, Qright
))
20350 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20351 if (EQ (prop
, Qcenter
))
20352 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20353 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20354 if (EQ (prop
, Qleft_fringe
))
20355 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20356 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20357 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20358 if (EQ (prop
, Qright_fringe
))
20359 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20360 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20361 : window_box_right_offset (it
->w
, TEXT_AREA
));
20362 if (EQ (prop
, Qleft_margin
))
20363 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20364 if (EQ (prop
, Qright_margin
))
20365 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20366 if (EQ (prop
, Qscroll_bar
))
20367 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20369 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20370 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20371 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20376 if (EQ (prop
, Qleft_fringe
))
20377 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20378 if (EQ (prop
, Qright_fringe
))
20379 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20380 if (EQ (prop
, Qleft_margin
))
20381 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20382 if (EQ (prop
, Qright_margin
))
20383 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20384 if (EQ (prop
, Qscroll_bar
))
20385 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20388 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20391 if (INTEGERP (prop
) || FLOATP (prop
))
20393 int base_unit
= (width_p
20394 ? FRAME_COLUMN_WIDTH (it
->f
)
20395 : FRAME_LINE_HEIGHT (it
->f
));
20396 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20401 Lisp_Object car
= XCAR (prop
);
20402 Lisp_Object cdr
= XCDR (prop
);
20406 #ifdef HAVE_WINDOW_SYSTEM
20407 if (FRAME_WINDOW_P (it
->f
)
20408 && valid_image_p (prop
))
20410 int id
= lookup_image (it
->f
, prop
);
20411 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20413 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20416 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20422 while (CONSP (cdr
))
20424 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20425 font
, width_p
, align_to
))
20428 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20433 if (EQ (car
, Qminus
))
20435 return OK_PIXELS (pixels
);
20438 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20441 if (INTEGERP (car
) || FLOATP (car
))
20444 pixels
= XFLOATINT (car
);
20446 return OK_PIXELS (pixels
);
20447 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20448 font
, width_p
, align_to
))
20449 return OK_PIXELS (pixels
* fact
);
20460 /***********************************************************************
20462 ***********************************************************************/
20464 #ifdef HAVE_WINDOW_SYSTEM
20469 dump_glyph_string (s
)
20470 struct glyph_string
*s
;
20472 fprintf (stderr
, "glyph string\n");
20473 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20474 s
->x
, s
->y
, s
->width
, s
->height
);
20475 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20476 fprintf (stderr
, " hl = %d\n", s
->hl
);
20477 fprintf (stderr
, " left overhang = %d, right = %d\n",
20478 s
->left_overhang
, s
->right_overhang
);
20479 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20480 fprintf (stderr
, " extends to end of line = %d\n",
20481 s
->extends_to_end_of_line_p
);
20482 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20483 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20486 #endif /* GLYPH_DEBUG */
20488 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20489 of XChar2b structures for S; it can't be allocated in
20490 init_glyph_string because it must be allocated via `alloca'. W
20491 is the window on which S is drawn. ROW and AREA are the glyph row
20492 and area within the row from which S is constructed. START is the
20493 index of the first glyph structure covered by S. HL is a
20494 face-override for drawing S. */
20497 #define OPTIONAL_HDC(hdc) HDC hdc,
20498 #define DECLARE_HDC(hdc) HDC hdc;
20499 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20500 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20503 #ifndef OPTIONAL_HDC
20504 #define OPTIONAL_HDC(hdc)
20505 #define DECLARE_HDC(hdc)
20506 #define ALLOCATE_HDC(hdc, f)
20507 #define RELEASE_HDC(hdc, f)
20511 init_glyph_string (struct glyph_string
*s
,
20513 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
20514 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
20516 memset (s
, 0, sizeof *s
);
20518 s
->f
= XFRAME (w
->frame
);
20522 s
->display
= FRAME_X_DISPLAY (s
->f
);
20523 s
->window
= FRAME_X_WINDOW (s
->f
);
20524 s
->char2b
= char2b
;
20528 s
->first_glyph
= row
->glyphs
[area
] + start
;
20529 s
->height
= row
->height
;
20530 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20531 s
->ybase
= s
->y
+ row
->ascent
;
20535 /* Append the list of glyph strings with head H and tail T to the list
20536 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20539 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20540 struct glyph_string
*h
, struct glyph_string
*t
)
20554 /* Prepend the list of glyph strings with head H and tail T to the
20555 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20559 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20560 struct glyph_string
*h
, struct glyph_string
*t
)
20574 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20575 Set *HEAD and *TAIL to the resulting list. */
20578 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
20579 struct glyph_string
*s
)
20581 s
->next
= s
->prev
= NULL
;
20582 append_glyph_string_lists (head
, tail
, s
, s
);
20586 /* Get face and two-byte form of character C in face FACE_ID on frame
20587 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
20588 means we want to display multibyte text. DISPLAY_P non-zero means
20589 make sure that X resources for the face returned are allocated.
20590 Value is a pointer to a realized face that is ready for display if
20591 DISPLAY_P is non-zero. */
20593 static INLINE
struct face
*
20594 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
20595 XChar2b
*char2b
, int multibyte_p
, int display_p
)
20597 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20601 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20603 if (code
!= FONT_INVALID_CODE
)
20604 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20606 STORE_XCHAR2B (char2b
, 0, 0);
20609 /* Make sure X resources of the face are allocated. */
20610 #ifdef HAVE_X_WINDOWS
20614 xassert (face
!= NULL
);
20615 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20622 /* Get face and two-byte form of character glyph GLYPH on frame F.
20623 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20624 a pointer to a realized face that is ready for display. */
20626 static INLINE
struct face
*
20627 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
20628 XChar2b
*char2b
, int *two_byte_p
)
20632 xassert (glyph
->type
== CHAR_GLYPH
);
20633 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20642 if (CHAR_BYTE8_P (glyph
->u
.ch
))
20643 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
20645 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20647 if (code
!= FONT_INVALID_CODE
)
20648 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20650 STORE_XCHAR2B (char2b
, 0, 0);
20653 /* Make sure X resources of the face are allocated. */
20654 xassert (face
!= NULL
);
20655 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20660 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
20661 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
20664 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
20668 if (CHAR_BYTE8_P (c
))
20669 code
= CHAR_TO_BYTE8 (c
);
20671 code
= font
->driver
->encode_char (font
, c
);
20673 if (code
== FONT_INVALID_CODE
)
20675 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20680 /* Fill glyph string S with composition components specified by S->cmp.
20682 BASE_FACE is the base face of the composition.
20683 S->cmp_from is the index of the first component for S.
20685 OVERLAPS non-zero means S should draw the foreground only, and use
20686 its physical height for clipping. See also draw_glyphs.
20688 Value is the index of a component not in S. */
20691 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
20695 /* For all glyphs of this composition, starting at the offset
20696 S->cmp_from, until we reach the end of the definition or encounter a
20697 glyph that requires the different face, add it to S. */
20702 s
->for_overlaps
= overlaps
;
20705 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20707 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20711 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20714 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20715 s
->char2b
+ i
, 1, 1);
20721 s
->font
= s
->face
->font
;
20723 else if (s
->face
!= face
)
20731 /* All glyph strings for the same composition has the same width,
20732 i.e. the width set for the first component of the composition. */
20733 s
->width
= s
->first_glyph
->pixel_width
;
20735 /* If the specified font could not be loaded, use the frame's
20736 default font, but record the fact that we couldn't load it in
20737 the glyph string so that we can draw rectangles for the
20738 characters of the glyph string. */
20739 if (s
->font
== NULL
)
20741 s
->font_not_found_p
= 1;
20742 s
->font
= FRAME_FONT (s
->f
);
20745 /* Adjust base line for subscript/superscript text. */
20746 s
->ybase
+= s
->first_glyph
->voffset
;
20748 /* This glyph string must always be drawn with 16-bit functions. */
20755 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
20756 int start
, int end
, int overlaps
)
20758 struct glyph
*glyph
, *last
;
20759 Lisp_Object lgstring
;
20762 s
->for_overlaps
= overlaps
;
20763 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20764 last
= s
->row
->glyphs
[s
->area
] + end
;
20765 s
->cmp_id
= glyph
->u
.cmp
.id
;
20766 s
->cmp_from
= glyph
->slice
.cmp
.from
;
20767 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
20768 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20769 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20770 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20772 while (glyph
< last
20773 && glyph
->u
.cmp
.automatic
20774 && glyph
->u
.cmp
.id
== s
->cmp_id
20775 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
20776 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
20778 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20780 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20781 unsigned code
= LGLYPH_CODE (lglyph
);
20783 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20785 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20786 return glyph
- s
->row
->glyphs
[s
->area
];
20790 /* Fill glyph string S from a sequence glyphs for glyphless characters.
20791 See the comment of fill_glyph_string for arguments.
20792 Value is the index of the first glyph not in S. */
20796 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
20797 int start
, int end
, int overlaps
)
20799 struct glyph
*glyph
, *last
;
20802 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
20803 s
->for_overlaps
= overlaps
;
20804 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20805 last
= s
->row
->glyphs
[s
->area
] + end
;
20806 voffset
= glyph
->voffset
;
20807 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20808 s
->font
= s
->face
->font
;
20810 s
->width
= glyph
->pixel_width
;
20812 while (glyph
< last
20813 && glyph
->type
== GLYPHLESS_GLYPH
20814 && glyph
->voffset
== voffset
20815 && glyph
->face_id
== face_id
)
20818 s
->width
+= glyph
->pixel_width
;
20821 s
->ybase
+= voffset
;
20822 return glyph
- s
->row
->glyphs
[s
->area
];
20826 /* Fill glyph string S from a sequence of character glyphs.
20828 FACE_ID is the face id of the string. START is the index of the
20829 first glyph to consider, END is the index of the last + 1.
20830 OVERLAPS non-zero means S should draw the foreground only, and use
20831 its physical height for clipping. See also draw_glyphs.
20833 Value is the index of the first glyph not in S. */
20836 fill_glyph_string (struct glyph_string
*s
, int face_id
,
20837 int start
, int end
, int overlaps
)
20839 struct glyph
*glyph
, *last
;
20841 int glyph_not_available_p
;
20843 xassert (s
->f
== XFRAME (s
->w
->frame
));
20844 xassert (s
->nchars
== 0);
20845 xassert (start
>= 0 && end
> start
);
20847 s
->for_overlaps
= overlaps
;
20848 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20849 last
= s
->row
->glyphs
[s
->area
] + end
;
20850 voffset
= glyph
->voffset
;
20851 s
->padding_p
= glyph
->padding_p
;
20852 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20854 while (glyph
< last
20855 && glyph
->type
== CHAR_GLYPH
20856 && glyph
->voffset
== voffset
20857 /* Same face id implies same font, nowadays. */
20858 && glyph
->face_id
== face_id
20859 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20863 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20864 s
->char2b
+ s
->nchars
,
20866 s
->two_byte_p
= two_byte_p
;
20868 xassert (s
->nchars
<= end
- start
);
20869 s
->width
+= glyph
->pixel_width
;
20870 if (glyph
++->padding_p
!= s
->padding_p
)
20874 s
->font
= s
->face
->font
;
20876 /* If the specified font could not be loaded, use the frame's font,
20877 but record the fact that we couldn't load it in
20878 S->font_not_found_p so that we can draw rectangles for the
20879 characters of the glyph string. */
20880 if (s
->font
== NULL
|| glyph_not_available_p
)
20882 s
->font_not_found_p
= 1;
20883 s
->font
= FRAME_FONT (s
->f
);
20886 /* Adjust base line for subscript/superscript text. */
20887 s
->ybase
+= voffset
;
20889 xassert (s
->face
&& s
->face
->gc
);
20890 return glyph
- s
->row
->glyphs
[s
->area
];
20894 /* Fill glyph string S from image glyph S->first_glyph. */
20897 fill_image_glyph_string (struct glyph_string
*s
)
20899 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20900 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20902 s
->slice
= s
->first_glyph
->slice
.img
;
20903 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20904 s
->font
= s
->face
->font
;
20905 s
->width
= s
->first_glyph
->pixel_width
;
20907 /* Adjust base line for subscript/superscript text. */
20908 s
->ybase
+= s
->first_glyph
->voffset
;
20912 /* Fill glyph string S from a sequence of stretch glyphs.
20914 ROW is the glyph row in which the glyphs are found, AREA is the
20915 area within the row. START is the index of the first glyph to
20916 consider, END is the index of the last + 1.
20918 Value is the index of the first glyph not in S. */
20921 fill_stretch_glyph_string (struct glyph_string
*s
, struct glyph_row
*row
,
20922 enum glyph_row_area area
, int start
, int end
)
20924 struct glyph
*glyph
, *last
;
20925 int voffset
, face_id
;
20927 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20929 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20930 last
= s
->row
->glyphs
[s
->area
] + end
;
20931 face_id
= glyph
->face_id
;
20932 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20933 s
->font
= s
->face
->font
;
20934 s
->width
= glyph
->pixel_width
;
20936 voffset
= glyph
->voffset
;
20940 && glyph
->type
== STRETCH_GLYPH
20941 && glyph
->voffset
== voffset
20942 && glyph
->face_id
== face_id
);
20944 s
->width
+= glyph
->pixel_width
;
20946 /* Adjust base line for subscript/superscript text. */
20947 s
->ybase
+= voffset
;
20949 /* The case that face->gc == 0 is handled when drawing the glyph
20950 string by calling PREPARE_FACE_FOR_DISPLAY. */
20952 return glyph
- s
->row
->glyphs
[s
->area
];
20955 static struct font_metrics
*
20956 get_per_char_metric (struct frame
*f
, struct font
*font
, XChar2b
*char2b
)
20958 static struct font_metrics metrics
;
20959 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20961 if (! font
|| code
== FONT_INVALID_CODE
)
20963 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20968 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20969 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20970 assumed to be zero. */
20973 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
20975 *left
= *right
= 0;
20977 if (glyph
->type
== CHAR_GLYPH
)
20981 struct font_metrics
*pcm
;
20983 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20984 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20986 if (pcm
->rbearing
> pcm
->width
)
20987 *right
= pcm
->rbearing
- pcm
->width
;
20988 if (pcm
->lbearing
< 0)
20989 *left
= -pcm
->lbearing
;
20992 else if (glyph
->type
== COMPOSITE_GLYPH
)
20994 if (! glyph
->u
.cmp
.automatic
)
20996 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20998 if (cmp
->rbearing
> cmp
->pixel_width
)
20999 *right
= cmp
->rbearing
- cmp
->pixel_width
;
21000 if (cmp
->lbearing
< 0)
21001 *left
= - cmp
->lbearing
;
21005 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21006 struct font_metrics metrics
;
21008 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21009 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21010 if (metrics
.rbearing
> metrics
.width
)
21011 *right
= metrics
.rbearing
- metrics
.width
;
21012 if (metrics
.lbearing
< 0)
21013 *left
= - metrics
.lbearing
;
21019 /* Return the index of the first glyph preceding glyph string S that
21020 is overwritten by S because of S's left overhang. Value is -1
21021 if no glyphs are overwritten. */
21024 left_overwritten (struct glyph_string
*s
)
21028 if (s
->left_overhang
)
21031 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21032 int first
= s
->first_glyph
- glyphs
;
21034 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21035 x
-= glyphs
[i
].pixel_width
;
21046 /* Return the index of the first glyph preceding glyph string S that
21047 is overwriting S because of its right overhang. Value is -1 if no
21048 glyph in front of S overwrites S. */
21051 left_overwriting (struct glyph_string
*s
)
21054 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21055 int first
= s
->first_glyph
- glyphs
;
21059 for (i
= first
- 1; i
>= 0; --i
)
21062 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21065 x
-= glyphs
[i
].pixel_width
;
21072 /* Return the index of the last glyph following glyph string S that is
21073 overwritten by S because of S's right overhang. Value is -1 if
21074 no such glyph is found. */
21077 right_overwritten (struct glyph_string
*s
)
21081 if (s
->right_overhang
)
21084 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21085 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21086 int end
= s
->row
->used
[s
->area
];
21088 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21089 x
+= glyphs
[i
].pixel_width
;
21098 /* Return the index of the last glyph following glyph string S that
21099 overwrites S because of its left overhang. Value is negative
21100 if no such glyph is found. */
21103 right_overwriting (struct glyph_string
*s
)
21106 int end
= s
->row
->used
[s
->area
];
21107 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21108 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21112 for (i
= first
; i
< end
; ++i
)
21115 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21118 x
+= glyphs
[i
].pixel_width
;
21125 /* Set background width of glyph string S. START is the index of the
21126 first glyph following S. LAST_X is the right-most x-position + 1
21127 in the drawing area. */
21130 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21132 /* If the face of this glyph string has to be drawn to the end of
21133 the drawing area, set S->extends_to_end_of_line_p. */
21135 if (start
== s
->row
->used
[s
->area
]
21136 && s
->area
== TEXT_AREA
21137 && ((s
->row
->fill_line_p
21138 && (s
->hl
== DRAW_NORMAL_TEXT
21139 || s
->hl
== DRAW_IMAGE_RAISED
21140 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21141 || s
->hl
== DRAW_MOUSE_FACE
))
21142 s
->extends_to_end_of_line_p
= 1;
21144 /* If S extends its face to the end of the line, set its
21145 background_width to the distance to the right edge of the drawing
21147 if (s
->extends_to_end_of_line_p
)
21148 s
->background_width
= last_x
- s
->x
+ 1;
21150 s
->background_width
= s
->width
;
21154 /* Compute overhangs and x-positions for glyph string S and its
21155 predecessors, or successors. X is the starting x-position for S.
21156 BACKWARD_P non-zero means process predecessors. */
21159 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21165 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21166 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21176 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21177 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21187 /* The following macros are only called from draw_glyphs below.
21188 They reference the following parameters of that function directly:
21189 `w', `row', `area', and `overlap_p'
21190 as well as the following local variables:
21191 `s', `f', and `hdc' (in W32) */
21194 /* On W32, silently add local `hdc' variable to argument list of
21195 init_glyph_string. */
21196 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21197 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21199 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21200 init_glyph_string (s, char2b, w, row, area, start, hl)
21203 /* Add a glyph string for a stretch glyph to the list of strings
21204 between HEAD and TAIL. START is the index of the stretch glyph in
21205 row area AREA of glyph row ROW. END is the index of the last glyph
21206 in that glyph row area. X is the current output position assigned
21207 to the new glyph string constructed. HL overrides that face of the
21208 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21209 is the right-most x-position of the drawing area. */
21211 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21212 and below -- keep them on one line. */
21213 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21216 s = (struct glyph_string *) alloca (sizeof *s); \
21217 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21218 START = fill_stretch_glyph_string (s, row, area, START, END); \
21219 append_glyph_string (&HEAD, &TAIL, s); \
21225 /* Add a glyph string for an image glyph to the list of strings
21226 between HEAD and TAIL. START is the index of the image glyph in
21227 row area AREA of glyph row ROW. END is the index of the last glyph
21228 in that glyph row area. X is the current output position assigned
21229 to the new glyph string constructed. HL overrides that face of the
21230 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21231 is the right-most x-position of the drawing area. */
21233 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21236 s = (struct glyph_string *) alloca (sizeof *s); \
21237 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21238 fill_image_glyph_string (s); \
21239 append_glyph_string (&HEAD, &TAIL, s); \
21246 /* Add a glyph string for a sequence of character glyphs to the list
21247 of strings between HEAD and TAIL. START is the index of the first
21248 glyph in row area AREA of glyph row ROW that is part of the new
21249 glyph string. END is the index of the last glyph in that glyph row
21250 area. X is the current output position assigned to the new glyph
21251 string constructed. HL overrides that face of the glyph; e.g. it
21252 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21253 right-most x-position of the drawing area. */
21255 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21261 face_id = (row)->glyphs[area][START].face_id; \
21263 s = (struct glyph_string *) alloca (sizeof *s); \
21264 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21265 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21266 append_glyph_string (&HEAD, &TAIL, s); \
21268 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21273 /* Add a glyph string for a composite sequence to the list of strings
21274 between HEAD and TAIL. START is the index of the first glyph in
21275 row area AREA of glyph row ROW that is part of the new glyph
21276 string. END is the index of the last glyph in that glyph row area.
21277 X is the current output position assigned to the new glyph string
21278 constructed. HL overrides that face of the glyph; e.g. it is
21279 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21280 x-position of the drawing area. */
21282 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21284 int face_id = (row)->glyphs[area][START].face_id; \
21285 struct face *base_face = FACE_FROM_ID (f, face_id); \
21286 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21287 struct composition *cmp = composition_table[cmp_id]; \
21289 struct glyph_string *first_s; \
21292 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21294 /* Make glyph_strings for each glyph sequence that is drawable by \
21295 the same face, and append them to HEAD/TAIL. */ \
21296 for (n = 0; n < cmp->glyph_len;) \
21298 s = (struct glyph_string *) alloca (sizeof *s); \
21299 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21300 append_glyph_string (&(HEAD), &(TAIL), s); \
21306 n = fill_composite_glyph_string (s, base_face, overlaps); \
21314 /* Add a glyph string for a glyph-string sequence to the list of strings
21315 between HEAD and TAIL. */
21317 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21321 Lisp_Object gstring; \
21323 face_id = (row)->glyphs[area][START].face_id; \
21324 gstring = (composition_gstring_from_id \
21325 ((row)->glyphs[area][START].u.cmp.id)); \
21326 s = (struct glyph_string *) alloca (sizeof *s); \
21327 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21328 * LGSTRING_GLYPH_LEN (gstring)); \
21329 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21330 append_glyph_string (&(HEAD), &(TAIL), s); \
21332 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21336 /* Add a glyph string for a sequence of glyphless character's glyphs
21337 to the list of strings between HEAD and TAIL. The meanings of
21338 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21340 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21346 face_id = (row)->glyphs[area][START].face_id; \
21348 s = (struct glyph_string *) alloca (sizeof *s); \
21349 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21350 append_glyph_string (&HEAD, &TAIL, s); \
21352 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21358 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21359 of AREA of glyph row ROW on window W between indices START and END.
21360 HL overrides the face for drawing glyph strings, e.g. it is
21361 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21362 x-positions of the drawing area.
21364 This is an ugly monster macro construct because we must use alloca
21365 to allocate glyph strings (because draw_glyphs can be called
21366 asynchronously). */
21368 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21371 HEAD = TAIL = NULL; \
21372 while (START < END) \
21374 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21375 switch (first_glyph->type) \
21378 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21382 case COMPOSITE_GLYPH: \
21383 if (first_glyph->u.cmp.automatic) \
21384 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21387 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21391 case STRETCH_GLYPH: \
21392 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21396 case IMAGE_GLYPH: \
21397 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21401 case GLYPHLESS_GLYPH: \
21402 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
21412 set_glyph_string_background_width (s, START, LAST_X); \
21419 /* Draw glyphs between START and END in AREA of ROW on window W,
21420 starting at x-position X. X is relative to AREA in W. HL is a
21421 face-override with the following meaning:
21423 DRAW_NORMAL_TEXT draw normally
21424 DRAW_CURSOR draw in cursor face
21425 DRAW_MOUSE_FACE draw in mouse face.
21426 DRAW_INVERSE_VIDEO draw in mode line face
21427 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21428 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21430 If OVERLAPS is non-zero, draw only the foreground of characters and
21431 clip to the physical height of ROW. Non-zero value also defines
21432 the overlapping part to be drawn:
21434 OVERLAPS_PRED overlap with preceding rows
21435 OVERLAPS_SUCC overlap with succeeding rows
21436 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21437 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21439 Value is the x-position reached, relative to AREA of W. */
21442 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
21443 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
21444 enum draw_glyphs_face hl
, int overlaps
)
21446 struct glyph_string
*head
, *tail
;
21447 struct glyph_string
*s
;
21448 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21449 int i
, j
, x_reached
, last_x
, area_left
= 0;
21450 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21453 ALLOCATE_HDC (hdc
, f
);
21455 /* Let's rather be paranoid than getting a SEGV. */
21456 end
= min (end
, row
->used
[area
]);
21457 start
= max (0, start
);
21458 start
= min (end
, start
);
21460 /* Translate X to frame coordinates. Set last_x to the right
21461 end of the drawing area. */
21462 if (row
->full_width_p
)
21464 /* X is relative to the left edge of W, without scroll bars
21466 area_left
= WINDOW_LEFT_EDGE_X (w
);
21467 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21471 area_left
= window_box_left (w
, area
);
21472 last_x
= area_left
+ window_box_width (w
, area
);
21476 /* Build a doubly-linked list of glyph_string structures between
21477 head and tail from what we have to draw. Note that the macro
21478 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21479 the reason we use a separate variable `i'. */
21481 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21483 x_reached
= tail
->x
+ tail
->background_width
;
21487 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21488 the row, redraw some glyphs in front or following the glyph
21489 strings built above. */
21490 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21492 struct glyph_string
*h
, *t
;
21493 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
21494 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
21497 /* If mouse highlighting is on, we may need to draw adjacent
21498 glyphs using mouse-face highlighting. */
21499 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21501 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21503 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
21504 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
21506 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21508 check_mouse_face
= 1;
21509 mouse_beg_col
= (row
== mouse_beg_row
)
21510 ? hlinfo
->mouse_face_beg_col
: 0;
21511 mouse_end_col
= (row
== mouse_end_row
)
21512 ? hlinfo
->mouse_face_end_col
21513 : row
->used
[TEXT_AREA
];
21517 /* Compute overhangs for all glyph strings. */
21518 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21519 for (s
= head
; s
; s
= s
->next
)
21520 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21522 /* Prepend glyph strings for glyphs in front of the first glyph
21523 string that are overwritten because of the first glyph
21524 string's left overhang. The background of all strings
21525 prepended must be drawn because the first glyph string
21527 i
= left_overwritten (head
);
21530 enum draw_glyphs_face overlap_hl
;
21532 /* If this row contains mouse highlighting, attempt to draw
21533 the overlapped glyphs with the correct highlight. This
21534 code fails if the overlap encompasses more than one glyph
21535 and mouse-highlight spans only some of these glyphs.
21536 However, making it work perfectly involves a lot more
21537 code, and I don't know if the pathological case occurs in
21538 practice, so we'll stick to this for now. --- cyd */
21539 if (check_mouse_face
21540 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21541 overlap_hl
= DRAW_MOUSE_FACE
;
21543 overlap_hl
= DRAW_NORMAL_TEXT
;
21546 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21547 overlap_hl
, dummy_x
, last_x
);
21549 compute_overhangs_and_x (t
, head
->x
, 1);
21550 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21554 /* Prepend glyph strings for glyphs in front of the first glyph
21555 string that overwrite that glyph string because of their
21556 right overhang. For these strings, only the foreground must
21557 be drawn, because it draws over the glyph string at `head'.
21558 The background must not be drawn because this would overwrite
21559 right overhangs of preceding glyphs for which no glyph
21561 i
= left_overwriting (head
);
21564 enum draw_glyphs_face overlap_hl
;
21566 if (check_mouse_face
21567 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21568 overlap_hl
= DRAW_MOUSE_FACE
;
21570 overlap_hl
= DRAW_NORMAL_TEXT
;
21573 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21574 overlap_hl
, dummy_x
, last_x
);
21575 for (s
= h
; s
; s
= s
->next
)
21576 s
->background_filled_p
= 1;
21577 compute_overhangs_and_x (t
, head
->x
, 1);
21578 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21581 /* Append glyphs strings for glyphs following the last glyph
21582 string tail that are overwritten by tail. The background of
21583 these strings has to be drawn because tail's foreground draws
21585 i
= right_overwritten (tail
);
21588 enum draw_glyphs_face overlap_hl
;
21590 if (check_mouse_face
21591 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21592 overlap_hl
= DRAW_MOUSE_FACE
;
21594 overlap_hl
= DRAW_NORMAL_TEXT
;
21596 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21597 overlap_hl
, x
, last_x
);
21598 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21599 we don't have `end = i;' here. */
21600 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21601 append_glyph_string_lists (&head
, &tail
, h
, t
);
21605 /* Append glyph strings for glyphs following the last glyph
21606 string tail that overwrite tail. The foreground of such
21607 glyphs has to be drawn because it writes into the background
21608 of tail. The background must not be drawn because it could
21609 paint over the foreground of following glyphs. */
21610 i
= right_overwriting (tail
);
21613 enum draw_glyphs_face overlap_hl
;
21614 if (check_mouse_face
21615 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21616 overlap_hl
= DRAW_MOUSE_FACE
;
21618 overlap_hl
= DRAW_NORMAL_TEXT
;
21621 i
++; /* We must include the Ith glyph. */
21622 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21623 overlap_hl
, x
, last_x
);
21624 for (s
= h
; s
; s
= s
->next
)
21625 s
->background_filled_p
= 1;
21626 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21627 append_glyph_string_lists (&head
, &tail
, h
, t
);
21629 if (clip_head
|| clip_tail
)
21630 for (s
= head
; s
; s
= s
->next
)
21632 s
->clip_head
= clip_head
;
21633 s
->clip_tail
= clip_tail
;
21637 /* Draw all strings. */
21638 for (s
= head
; s
; s
= s
->next
)
21639 FRAME_RIF (f
)->draw_glyph_string (s
);
21642 /* When focus a sole frame and move horizontally, this sets on_p to 0
21643 causing a failure to erase prev cursor position. */
21644 if (area
== TEXT_AREA
21645 && !row
->full_width_p
21646 /* When drawing overlapping rows, only the glyph strings'
21647 foreground is drawn, which doesn't erase a cursor
21651 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21652 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21653 : (tail
? tail
->x
+ tail
->background_width
: x
));
21657 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21658 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21662 /* Value is the x-position up to which drawn, relative to AREA of W.
21663 This doesn't include parts drawn because of overhangs. */
21664 if (row
->full_width_p
)
21665 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21667 x_reached
-= area_left
;
21669 RELEASE_HDC (hdc
, f
);
21674 /* Expand row matrix if too narrow. Don't expand if area
21677 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21679 if (!fonts_changed_p \
21680 && (it->glyph_row->glyphs[area] \
21681 < it->glyph_row->glyphs[area + 1])) \
21683 it->w->ncols_scale_factor++; \
21684 fonts_changed_p = 1; \
21688 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21689 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21692 append_glyph (struct it
*it
)
21694 struct glyph
*glyph
;
21695 enum glyph_row_area area
= it
->area
;
21697 xassert (it
->glyph_row
);
21698 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21700 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21701 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21703 /* If the glyph row is reversed, we need to prepend the glyph
21704 rather than append it. */
21705 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21709 /* Make room for the additional glyph. */
21710 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21712 glyph
= it
->glyph_row
->glyphs
[area
];
21714 glyph
->charpos
= CHARPOS (it
->position
);
21715 glyph
->object
= it
->object
;
21716 if (it
->pixel_width
> 0)
21718 glyph
->pixel_width
= it
->pixel_width
;
21719 glyph
->padding_p
= 0;
21723 /* Assure at least 1-pixel width. Otherwise, cursor can't
21724 be displayed correctly. */
21725 glyph
->pixel_width
= 1;
21726 glyph
->padding_p
= 1;
21728 glyph
->ascent
= it
->ascent
;
21729 glyph
->descent
= it
->descent
;
21730 glyph
->voffset
= it
->voffset
;
21731 glyph
->type
= CHAR_GLYPH
;
21732 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21733 glyph
->multibyte_p
= it
->multibyte_p
;
21734 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21735 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21736 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21737 || it
->phys_descent
> it
->descent
);
21738 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21739 glyph
->face_id
= it
->face_id
;
21740 glyph
->u
.ch
= it
->char_to_display
;
21741 glyph
->slice
.img
= null_glyph_slice
;
21742 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21745 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21746 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21748 glyph
->bidi_type
= it
->bidi_it
.type
;
21752 glyph
->resolved_level
= 0;
21753 glyph
->bidi_type
= UNKNOWN_BT
;
21755 ++it
->glyph_row
->used
[area
];
21758 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21761 /* Store one glyph for the composition IT->cmp_it.id in
21762 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21766 append_composite_glyph (struct it
*it
)
21768 struct glyph
*glyph
;
21769 enum glyph_row_area area
= it
->area
;
21771 xassert (it
->glyph_row
);
21773 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21774 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21776 /* If the glyph row is reversed, we need to prepend the glyph
21777 rather than append it. */
21778 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
21782 /* Make room for the new glyph. */
21783 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
21785 glyph
= it
->glyph_row
->glyphs
[it
->area
];
21787 glyph
->charpos
= it
->cmp_it
.charpos
;
21788 glyph
->object
= it
->object
;
21789 glyph
->pixel_width
= it
->pixel_width
;
21790 glyph
->ascent
= it
->ascent
;
21791 glyph
->descent
= it
->descent
;
21792 glyph
->voffset
= it
->voffset
;
21793 glyph
->type
= COMPOSITE_GLYPH
;
21794 if (it
->cmp_it
.ch
< 0)
21796 glyph
->u
.cmp
.automatic
= 0;
21797 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21798 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
21802 glyph
->u
.cmp
.automatic
= 1;
21803 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21804 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
21805 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
21807 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21808 glyph
->multibyte_p
= it
->multibyte_p
;
21809 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21810 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21811 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21812 || it
->phys_descent
> it
->descent
);
21813 glyph
->padding_p
= 0;
21814 glyph
->glyph_not_available_p
= 0;
21815 glyph
->face_id
= it
->face_id
;
21816 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21819 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21820 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21822 glyph
->bidi_type
= it
->bidi_it
.type
;
21824 ++it
->glyph_row
->used
[area
];
21827 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21831 /* Change IT->ascent and IT->height according to the setting of
21835 take_vertical_position_into_account (struct it
*it
)
21839 if (it
->voffset
< 0)
21840 /* Increase the ascent so that we can display the text higher
21842 it
->ascent
-= it
->voffset
;
21844 /* Increase the descent so that we can display the text lower
21846 it
->descent
+= it
->voffset
;
21851 /* Produce glyphs/get display metrics for the image IT is loaded with.
21852 See the description of struct display_iterator in dispextern.h for
21853 an overview of struct display_iterator. */
21856 produce_image_glyph (struct it
*it
)
21860 int glyph_ascent
, crop
;
21861 struct glyph_slice slice
;
21863 xassert (it
->what
== IT_IMAGE
);
21865 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21867 /* Make sure X resources of the face is loaded. */
21868 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21870 if (it
->image_id
< 0)
21872 /* Fringe bitmap. */
21873 it
->ascent
= it
->phys_ascent
= 0;
21874 it
->descent
= it
->phys_descent
= 0;
21875 it
->pixel_width
= 0;
21880 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21882 /* Make sure X resources of the image is loaded. */
21883 prepare_image_for_display (it
->f
, img
);
21885 slice
.x
= slice
.y
= 0;
21886 slice
.width
= img
->width
;
21887 slice
.height
= img
->height
;
21889 if (INTEGERP (it
->slice
.x
))
21890 slice
.x
= XINT (it
->slice
.x
);
21891 else if (FLOATP (it
->slice
.x
))
21892 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21894 if (INTEGERP (it
->slice
.y
))
21895 slice
.y
= XINT (it
->slice
.y
);
21896 else if (FLOATP (it
->slice
.y
))
21897 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21899 if (INTEGERP (it
->slice
.width
))
21900 slice
.width
= XINT (it
->slice
.width
);
21901 else if (FLOATP (it
->slice
.width
))
21902 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21904 if (INTEGERP (it
->slice
.height
))
21905 slice
.height
= XINT (it
->slice
.height
);
21906 else if (FLOATP (it
->slice
.height
))
21907 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21909 if (slice
.x
>= img
->width
)
21910 slice
.x
= img
->width
;
21911 if (slice
.y
>= img
->height
)
21912 slice
.y
= img
->height
;
21913 if (slice
.x
+ slice
.width
>= img
->width
)
21914 slice
.width
= img
->width
- slice
.x
;
21915 if (slice
.y
+ slice
.height
> img
->height
)
21916 slice
.height
= img
->height
- slice
.y
;
21918 if (slice
.width
== 0 || slice
.height
== 0)
21921 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21923 it
->descent
= slice
.height
- glyph_ascent
;
21925 it
->descent
+= img
->vmargin
;
21926 if (slice
.y
+ slice
.height
== img
->height
)
21927 it
->descent
+= img
->vmargin
;
21928 it
->phys_descent
= it
->descent
;
21930 it
->pixel_width
= slice
.width
;
21932 it
->pixel_width
+= img
->hmargin
;
21933 if (slice
.x
+ slice
.width
== img
->width
)
21934 it
->pixel_width
+= img
->hmargin
;
21936 /* It's quite possible for images to have an ascent greater than
21937 their height, so don't get confused in that case. */
21938 if (it
->descent
< 0)
21943 if (face
->box
!= FACE_NO_BOX
)
21945 if (face
->box_line_width
> 0)
21948 it
->ascent
+= face
->box_line_width
;
21949 if (slice
.y
+ slice
.height
== img
->height
)
21950 it
->descent
+= face
->box_line_width
;
21953 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21954 it
->pixel_width
+= eabs (face
->box_line_width
);
21955 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21956 it
->pixel_width
+= eabs (face
->box_line_width
);
21959 take_vertical_position_into_account (it
);
21961 /* Automatically crop wide image glyphs at right edge so we can
21962 draw the cursor on same display row. */
21963 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21964 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21966 it
->pixel_width
-= crop
;
21967 slice
.width
-= crop
;
21972 struct glyph
*glyph
;
21973 enum glyph_row_area area
= it
->area
;
21975 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21976 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21978 glyph
->charpos
= CHARPOS (it
->position
);
21979 glyph
->object
= it
->object
;
21980 glyph
->pixel_width
= it
->pixel_width
;
21981 glyph
->ascent
= glyph_ascent
;
21982 glyph
->descent
= it
->descent
;
21983 glyph
->voffset
= it
->voffset
;
21984 glyph
->type
= IMAGE_GLYPH
;
21985 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21986 glyph
->multibyte_p
= it
->multibyte_p
;
21987 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21988 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21989 glyph
->overlaps_vertically_p
= 0;
21990 glyph
->padding_p
= 0;
21991 glyph
->glyph_not_available_p
= 0;
21992 glyph
->face_id
= it
->face_id
;
21993 glyph
->u
.img_id
= img
->id
;
21994 glyph
->slice
.img
= slice
;
21995 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21998 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21999 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22001 glyph
->bidi_type
= it
->bidi_it
.type
;
22003 ++it
->glyph_row
->used
[area
];
22006 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22011 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22012 of the glyph, WIDTH and HEIGHT are the width and height of the
22013 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22016 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22017 int width
, int height
, int ascent
)
22019 struct glyph
*glyph
;
22020 enum glyph_row_area area
= it
->area
;
22022 xassert (ascent
>= 0 && ascent
<= height
);
22024 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22025 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22027 /* If the glyph row is reversed, we need to prepend the glyph
22028 rather than append it. */
22029 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22033 /* Make room for the additional glyph. */
22034 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22036 glyph
= it
->glyph_row
->glyphs
[area
];
22038 glyph
->charpos
= CHARPOS (it
->position
);
22039 glyph
->object
= object
;
22040 glyph
->pixel_width
= width
;
22041 glyph
->ascent
= ascent
;
22042 glyph
->descent
= height
- ascent
;
22043 glyph
->voffset
= it
->voffset
;
22044 glyph
->type
= STRETCH_GLYPH
;
22045 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22046 glyph
->multibyte_p
= it
->multibyte_p
;
22047 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22048 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22049 glyph
->overlaps_vertically_p
= 0;
22050 glyph
->padding_p
= 0;
22051 glyph
->glyph_not_available_p
= 0;
22052 glyph
->face_id
= it
->face_id
;
22053 glyph
->u
.stretch
.ascent
= ascent
;
22054 glyph
->u
.stretch
.height
= height
;
22055 glyph
->slice
.img
= null_glyph_slice
;
22056 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22059 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22060 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22062 glyph
->bidi_type
= it
->bidi_it
.type
;
22066 glyph
->resolved_level
= 0;
22067 glyph
->bidi_type
= UNKNOWN_BT
;
22069 ++it
->glyph_row
->used
[area
];
22072 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22076 /* Produce a stretch glyph for iterator IT. IT->object is the value
22077 of the glyph property displayed. The value must be a list
22078 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22081 1. `:width WIDTH' specifies that the space should be WIDTH *
22082 canonical char width wide. WIDTH may be an integer or floating
22085 2. `:relative-width FACTOR' specifies that the width of the stretch
22086 should be computed from the width of the first character having the
22087 `glyph' property, and should be FACTOR times that width.
22089 3. `:align-to HPOS' specifies that the space should be wide enough
22090 to reach HPOS, a value in canonical character units.
22092 Exactly one of the above pairs must be present.
22094 4. `:height HEIGHT' specifies that the height of the stretch produced
22095 should be HEIGHT, measured in canonical character units.
22097 5. `:relative-height FACTOR' specifies that the height of the
22098 stretch should be FACTOR times the height of the characters having
22099 the glyph property.
22101 Either none or exactly one of 4 or 5 must be present.
22103 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22104 of the stretch should be used for the ascent of the stretch.
22105 ASCENT must be in the range 0 <= ASCENT <= 100. */
22108 produce_stretch_glyph (struct it
*it
)
22110 /* (space :width WIDTH :height HEIGHT ...) */
22111 Lisp_Object prop
, plist
;
22112 int width
= 0, height
= 0, align_to
= -1;
22113 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22116 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22117 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22119 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22121 /* List should start with `space'. */
22122 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22123 plist
= XCDR (it
->object
);
22125 /* Compute the width of the stretch. */
22126 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22127 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22129 /* Absolute width `:width WIDTH' specified and valid. */
22130 zero_width_ok_p
= 1;
22133 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22136 /* Relative width `:relative-width FACTOR' specified and valid.
22137 Compute the width of the characters having the `glyph'
22140 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22143 if (it
->multibyte_p
)
22144 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22147 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22148 if (! ASCII_CHAR_P (it2
.c
))
22149 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22152 it2
.glyph_row
= NULL
;
22153 it2
.what
= IT_CHARACTER
;
22154 x_produce_glyphs (&it2
);
22155 width
= NUMVAL (prop
) * it2
.pixel_width
;
22157 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22158 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22160 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22161 align_to
= (align_to
< 0
22163 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22164 else if (align_to
< 0)
22165 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22166 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22167 zero_width_ok_p
= 1;
22170 /* Nothing specified -> width defaults to canonical char width. */
22171 width
= FRAME_COLUMN_WIDTH (it
->f
);
22173 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22176 /* Compute height. */
22177 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22178 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22181 zero_height_ok_p
= 1;
22183 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22185 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22187 height
= FONT_HEIGHT (font
);
22189 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22192 /* Compute percentage of height used for ascent. If
22193 `:ascent ASCENT' is present and valid, use that. Otherwise,
22194 derive the ascent from the font in use. */
22195 if (prop
= Fplist_get (plist
, QCascent
),
22196 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22197 ascent
= height
* NUMVAL (prop
) / 100.0;
22198 else if (!NILP (prop
)
22199 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22200 ascent
= min (max (0, (int)tem
), height
);
22202 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22204 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22205 && it
->current_x
+ width
> it
->last_visible_x
)
22206 width
= it
->last_visible_x
- it
->current_x
- 1;
22208 if (width
> 0 && height
> 0 && it
->glyph_row
)
22210 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22211 if (!STRINGP (object
))
22212 object
= it
->w
->buffer
;
22213 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22216 it
->pixel_width
= width
;
22217 it
->ascent
= it
->phys_ascent
= ascent
;
22218 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22219 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22221 take_vertical_position_into_account (it
);
22224 /* Calculate line-height and line-spacing properties.
22225 An integer value specifies explicit pixel value.
22226 A float value specifies relative value to current face height.
22227 A cons (float . face-name) specifies relative value to
22228 height of specified face font.
22230 Returns height in pixels, or nil. */
22234 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22235 int boff
, int override
)
22237 Lisp_Object face_name
= Qnil
;
22238 int ascent
, descent
, height
;
22240 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22245 face_name
= XCAR (val
);
22247 if (!NUMBERP (val
))
22248 val
= make_number (1);
22249 if (NILP (face_name
))
22251 height
= it
->ascent
+ it
->descent
;
22256 if (NILP (face_name
))
22258 font
= FRAME_FONT (it
->f
);
22259 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22261 else if (EQ (face_name
, Qt
))
22270 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22272 return make_number (-1);
22274 face
= FACE_FROM_ID (it
->f
, face_id
);
22277 return make_number (-1);
22278 boff
= font
->baseline_offset
;
22279 if (font
->vertical_centering
)
22280 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22283 ascent
= FONT_BASE (font
) + boff
;
22284 descent
= FONT_DESCENT (font
) - boff
;
22288 it
->override_ascent
= ascent
;
22289 it
->override_descent
= descent
;
22290 it
->override_boff
= boff
;
22293 height
= ascent
+ descent
;
22297 height
= (int)(XFLOAT_DATA (val
) * height
);
22298 else if (INTEGERP (val
))
22299 height
*= XINT (val
);
22301 return make_number (height
);
22305 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22306 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22307 and only if this is for a character for which no font was found.
22309 If the display method (it->glyphless_method) is
22310 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22311 length of the acronym or the hexadecimal string, UPPER_XOFF and
22312 UPPER_YOFF are pixel offsets for the upper part of the string,
22313 LOWER_XOFF and LOWER_YOFF are for the lower part.
22315 For the other display methods, LEN through LOWER_YOFF are zero. */
22318 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22319 short upper_xoff
, short upper_yoff
,
22320 short lower_xoff
, short lower_yoff
)
22322 struct glyph
*glyph
;
22323 enum glyph_row_area area
= it
->area
;
22325 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22326 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22328 /* If the glyph row is reversed, we need to prepend the glyph
22329 rather than append it. */
22330 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22334 /* Make room for the additional glyph. */
22335 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22337 glyph
= it
->glyph_row
->glyphs
[area
];
22339 glyph
->charpos
= CHARPOS (it
->position
);
22340 glyph
->object
= it
->object
;
22341 glyph
->pixel_width
= it
->pixel_width
;
22342 glyph
->ascent
= it
->ascent
;
22343 glyph
->descent
= it
->descent
;
22344 glyph
->voffset
= it
->voffset
;
22345 glyph
->type
= GLYPHLESS_GLYPH
;
22346 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22347 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22348 glyph
->u
.glyphless
.len
= len
;
22349 glyph
->u
.glyphless
.ch
= it
->c
;
22350 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22351 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22352 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22353 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22354 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22355 glyph
->multibyte_p
= it
->multibyte_p
;
22356 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22357 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22358 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22359 || it
->phys_descent
> it
->descent
);
22360 glyph
->padding_p
= 0;
22361 glyph
->glyph_not_available_p
= 0;
22362 glyph
->face_id
= face_id
;
22363 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22366 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22367 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22369 glyph
->bidi_type
= it
->bidi_it
.type
;
22371 ++it
->glyph_row
->used
[area
];
22374 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22378 /* Produce a glyph for a glyphless character for iterator IT.
22379 IT->glyphless_method specifies which method to use for displaying
22380 the character. See the description of enum
22381 glyphless_display_method in dispextern.h for the detail.
22383 FOR_NO_FONT is nonzero if and only if this is for a character for
22384 which no font was found. ACRONYM, if non-nil, is an acronym string
22385 for the character. */
22388 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22393 int base_width
, base_height
, width
, height
;
22394 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22397 /* Get the metrics of the base font. We always refer to the current
22399 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22400 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22401 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22402 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
22403 base_height
= it
->ascent
+ it
->descent
;
22404 base_width
= font
->average_width
;
22406 /* Get a face ID for the glyph by utilizing a cache (the same way as
22407 doen for `escape-glyph' in get_next_display_element). */
22408 if (it
->f
== last_glyphless_glyph_frame
22409 && it
->face_id
== last_glyphless_glyph_face_id
)
22411 face_id
= last_glyphless_glyph_merged_face_id
;
22415 /* Merge the `glyphless-char' face into the current face. */
22416 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
22417 last_glyphless_glyph_frame
= it
->f
;
22418 last_glyphless_glyph_face_id
= it
->face_id
;
22419 last_glyphless_glyph_merged_face_id
= face_id
;
22422 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
22424 it
->pixel_width
= THIN_SPACE_WIDTH
;
22426 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22428 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
22430 width
= CHAR_WIDTH (it
->c
);
22433 else if (width
> 4)
22435 it
->pixel_width
= base_width
* width
;
22437 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22442 unsigned int code
[6];
22444 int ascent
, descent
;
22445 struct font_metrics metrics_upper
, metrics_lower
;
22447 face
= FACE_FROM_ID (it
->f
, face_id
);
22448 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22449 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22451 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
22453 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
22454 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
22455 str
= STRINGP (acronym
) ? (char *) SDATA (acronym
) : "";
22459 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
22460 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
22463 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
22464 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
22465 upper_len
= (len
+ 1) / 2;
22466 font
->driver
->text_extents (font
, code
, upper_len
,
22468 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
22473 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
22474 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
22475 upper_xoff
= upper_yoff
= 2; /* the typical case */
22476 if (base_width
>= width
)
22478 /* Align the upper to the left, the lower to the right. */
22479 it
->pixel_width
= base_width
;
22480 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
22484 /* Center the shorter one. */
22485 it
->pixel_width
= width
;
22486 if (metrics_upper
.width
>= metrics_lower
.width
)
22487 lower_xoff
= (width
- metrics_lower
.width
) / 2;
22489 upper_xoff
= (width
- metrics_upper
.width
) / 2;
22492 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
22493 top, bottom, and between upper and lower strings. */
22494 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
22495 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
22496 /* Center vertically.
22497 H:base_height, D:base_descent
22498 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
22500 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
22501 descent = D - H/2 + h/2;
22502 lower_yoff = descent - 2 - ld;
22503 upper_yoff = lower_yoff - la - 1 - ud; */
22504 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
22505 descent
= it
->descent
- (base_height
- height
) / 2;
22506 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
22507 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
22508 - metrics_upper
.descent
);
22509 /* Don't make the height shorter than the base height. */
22510 if (height
> base_height
)
22512 it
->ascent
= ascent
;
22513 it
->descent
= descent
;
22517 it
->phys_ascent
= it
->ascent
;
22518 it
->phys_descent
= it
->descent
;
22520 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
22521 upper_xoff
, upper_yoff
,
22522 lower_xoff
, lower_yoff
);
22524 take_vertical_position_into_account (it
);
22529 Produce glyphs/get display metrics for the display element IT is
22530 loaded with. See the description of struct it in dispextern.h
22531 for an overview of struct it. */
22534 x_produce_glyphs (struct it
*it
)
22536 int extra_line_spacing
= it
->extra_line_spacing
;
22538 it
->glyph_not_available_p
= 0;
22540 if (it
->what
== IT_CHARACTER
)
22543 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22544 struct font
*font
= face
->font
;
22545 struct font_metrics
*pcm
= NULL
;
22546 int boff
; /* baseline offset */
22550 /* When no suitable font is found, display this character by
22551 the method specified in the first extra slot of
22552 Vglyphless_char_display. */
22553 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
22555 xassert (it
->what
== IT_GLYPHLESS
);
22556 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
22560 boff
= font
->baseline_offset
;
22561 if (font
->vertical_centering
)
22562 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22564 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
22570 if (it
->override_ascent
>= 0)
22572 it
->ascent
= it
->override_ascent
;
22573 it
->descent
= it
->override_descent
;
22574 boff
= it
->override_boff
;
22578 it
->ascent
= FONT_BASE (font
) + boff
;
22579 it
->descent
= FONT_DESCENT (font
) - boff
;
22582 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
22584 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22585 if (pcm
->width
== 0
22586 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
22592 it
->phys_ascent
= pcm
->ascent
+ boff
;
22593 it
->phys_descent
= pcm
->descent
- boff
;
22594 it
->pixel_width
= pcm
->width
;
22598 it
->glyph_not_available_p
= 1;
22599 it
->phys_ascent
= it
->ascent
;
22600 it
->phys_descent
= it
->descent
;
22601 it
->pixel_width
= font
->space_width
;
22604 if (it
->constrain_row_ascent_descent_p
)
22606 if (it
->descent
> it
->max_descent
)
22608 it
->ascent
+= it
->descent
- it
->max_descent
;
22609 it
->descent
= it
->max_descent
;
22611 if (it
->ascent
> it
->max_ascent
)
22613 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22614 it
->ascent
= it
->max_ascent
;
22616 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22617 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22618 extra_line_spacing
= 0;
22621 /* If this is a space inside a region of text with
22622 `space-width' property, change its width. */
22623 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22625 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22627 /* If face has a box, add the box thickness to the character
22628 height. If character has a box line to the left and/or
22629 right, add the box line width to the character's width. */
22630 if (face
->box
!= FACE_NO_BOX
)
22632 int thick
= face
->box_line_width
;
22636 it
->ascent
+= thick
;
22637 it
->descent
+= thick
;
22642 if (it
->start_of_box_run_p
)
22643 it
->pixel_width
+= thick
;
22644 if (it
->end_of_box_run_p
)
22645 it
->pixel_width
+= thick
;
22648 /* If face has an overline, add the height of the overline
22649 (1 pixel) and a 1 pixel margin to the character height. */
22650 if (face
->overline_p
)
22651 it
->ascent
+= overline_margin
;
22653 if (it
->constrain_row_ascent_descent_p
)
22655 if (it
->ascent
> it
->max_ascent
)
22656 it
->ascent
= it
->max_ascent
;
22657 if (it
->descent
> it
->max_descent
)
22658 it
->descent
= it
->max_descent
;
22661 take_vertical_position_into_account (it
);
22663 /* If we have to actually produce glyphs, do it. */
22668 /* Translate a space with a `space-width' property
22669 into a stretch glyph. */
22670 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22671 / FONT_HEIGHT (font
));
22672 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22673 it
->ascent
+ it
->descent
, ascent
);
22678 /* If characters with lbearing or rbearing are displayed
22679 in this line, record that fact in a flag of the
22680 glyph row. This is used to optimize X output code. */
22681 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22682 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22684 if (! stretched_p
&& it
->pixel_width
== 0)
22685 /* We assure that all visible glyphs have at least 1-pixel
22687 it
->pixel_width
= 1;
22689 else if (it
->char_to_display
== '\n')
22691 /* A newline has no width, but we need the height of the
22692 line. But if previous part of the line sets a height,
22693 don't increase that height */
22695 Lisp_Object height
;
22696 Lisp_Object total_height
= Qnil
;
22698 it
->override_ascent
= -1;
22699 it
->pixel_width
= 0;
22702 height
= get_it_property (it
, Qline_height
);
22703 /* Split (line-height total-height) list */
22705 && CONSP (XCDR (height
))
22706 && NILP (XCDR (XCDR (height
))))
22708 total_height
= XCAR (XCDR (height
));
22709 height
= XCAR (height
);
22711 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
22713 if (it
->override_ascent
>= 0)
22715 it
->ascent
= it
->override_ascent
;
22716 it
->descent
= it
->override_descent
;
22717 boff
= it
->override_boff
;
22721 it
->ascent
= FONT_BASE (font
) + boff
;
22722 it
->descent
= FONT_DESCENT (font
) - boff
;
22725 if (EQ (height
, Qt
))
22727 if (it
->descent
> it
->max_descent
)
22729 it
->ascent
+= it
->descent
- it
->max_descent
;
22730 it
->descent
= it
->max_descent
;
22732 if (it
->ascent
> it
->max_ascent
)
22734 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22735 it
->ascent
= it
->max_ascent
;
22737 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22738 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22739 it
->constrain_row_ascent_descent_p
= 1;
22740 extra_line_spacing
= 0;
22744 Lisp_Object spacing
;
22746 it
->phys_ascent
= it
->ascent
;
22747 it
->phys_descent
= it
->descent
;
22749 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22750 && face
->box
!= FACE_NO_BOX
22751 && face
->box_line_width
> 0)
22753 it
->ascent
+= face
->box_line_width
;
22754 it
->descent
+= face
->box_line_width
;
22757 && XINT (height
) > it
->ascent
+ it
->descent
)
22758 it
->ascent
= XINT (height
) - it
->descent
;
22760 if (!NILP (total_height
))
22761 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
22764 spacing
= get_it_property (it
, Qline_spacing
);
22765 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
22767 if (INTEGERP (spacing
))
22769 extra_line_spacing
= XINT (spacing
);
22770 if (!NILP (total_height
))
22771 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22775 else /* i.e. (it->char_to_display == '\t') */
22777 if (font
->space_width
> 0)
22779 int tab_width
= it
->tab_width
* font
->space_width
;
22780 int x
= it
->current_x
+ it
->continuation_lines_width
;
22781 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22783 /* If the distance from the current position to the next tab
22784 stop is less than a space character width, use the
22785 tab stop after that. */
22786 if (next_tab_x
- x
< font
->space_width
)
22787 next_tab_x
+= tab_width
;
22789 it
->pixel_width
= next_tab_x
- x
;
22791 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22792 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22796 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22797 it
->ascent
+ it
->descent
, it
->ascent
);
22802 it
->pixel_width
= 0;
22807 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22809 /* A static composition.
22811 Note: A composition is represented as one glyph in the
22812 glyph matrix. There are no padding glyphs.
22814 Important note: pixel_width, ascent, and descent are the
22815 values of what is drawn by draw_glyphs (i.e. the values of
22816 the overall glyphs composed). */
22817 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22818 int boff
; /* baseline offset */
22819 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22820 int glyph_len
= cmp
->glyph_len
;
22821 struct font
*font
= face
->font
;
22825 /* If we have not yet calculated pixel size data of glyphs of
22826 the composition for the current face font, calculate them
22827 now. Theoretically, we have to check all fonts for the
22828 glyphs, but that requires much time and memory space. So,
22829 here we check only the font of the first glyph. This may
22830 lead to incorrect display, but it's very rare, and C-l
22831 (recenter-top-bottom) can correct the display anyway. */
22832 if (! cmp
->font
|| cmp
->font
!= font
)
22834 /* Ascent and descent of the font of the first character
22835 of this composition (adjusted by baseline offset).
22836 Ascent and descent of overall glyphs should not be less
22837 than these, respectively. */
22838 int font_ascent
, font_descent
, font_height
;
22839 /* Bounding box of the overall glyphs. */
22840 int leftmost
, rightmost
, lowest
, highest
;
22841 int lbearing
, rbearing
;
22842 int i
, width
, ascent
, descent
;
22843 int left_padded
= 0, right_padded
= 0;
22846 struct font_metrics
*pcm
;
22847 int font_not_found_p
;
22850 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22851 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22853 if (glyph_len
< cmp
->glyph_len
)
22855 for (i
= 0; i
< glyph_len
; i
++)
22857 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22859 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22864 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22865 : IT_CHARPOS (*it
));
22866 /* If no suitable font is found, use the default font. */
22867 font_not_found_p
= font
== NULL
;
22868 if (font_not_found_p
)
22870 face
= face
->ascii_face
;
22873 boff
= font
->baseline_offset
;
22874 if (font
->vertical_centering
)
22875 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22876 font_ascent
= FONT_BASE (font
) + boff
;
22877 font_descent
= FONT_DESCENT (font
) - boff
;
22878 font_height
= FONT_HEIGHT (font
);
22880 cmp
->font
= (void *) font
;
22883 if (! font_not_found_p
)
22885 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22886 &char2b
, it
->multibyte_p
, 0);
22887 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22890 /* Initialize the bounding box. */
22893 width
= pcm
->width
;
22894 ascent
= pcm
->ascent
;
22895 descent
= pcm
->descent
;
22896 lbearing
= pcm
->lbearing
;
22897 rbearing
= pcm
->rbearing
;
22901 width
= font
->space_width
;
22902 ascent
= FONT_BASE (font
);
22903 descent
= FONT_DESCENT (font
);
22910 lowest
= - descent
+ boff
;
22911 highest
= ascent
+ boff
;
22913 if (! font_not_found_p
22914 && font
->default_ascent
22915 && CHAR_TABLE_P (Vuse_default_ascent
)
22916 && !NILP (Faref (Vuse_default_ascent
,
22917 make_number (it
->char_to_display
))))
22918 highest
= font
->default_ascent
+ boff
;
22920 /* Draw the first glyph at the normal position. It may be
22921 shifted to right later if some other glyphs are drawn
22923 cmp
->offsets
[i
* 2] = 0;
22924 cmp
->offsets
[i
* 2 + 1] = boff
;
22925 cmp
->lbearing
= lbearing
;
22926 cmp
->rbearing
= rbearing
;
22928 /* Set cmp->offsets for the remaining glyphs. */
22929 for (i
++; i
< glyph_len
; i
++)
22931 int left
, right
, btm
, top
;
22932 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22934 struct face
*this_face
;
22939 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22940 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22941 font
= this_face
->font
;
22947 this_boff
= font
->baseline_offset
;
22948 if (font
->vertical_centering
)
22949 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22950 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22951 &char2b
, it
->multibyte_p
, 0);
22952 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22955 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22958 width
= pcm
->width
;
22959 ascent
= pcm
->ascent
;
22960 descent
= pcm
->descent
;
22961 lbearing
= pcm
->lbearing
;
22962 rbearing
= pcm
->rbearing
;
22963 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22965 /* Relative composition with or without
22966 alternate chars. */
22967 left
= (leftmost
+ rightmost
- width
) / 2;
22968 btm
= - descent
+ boff
;
22969 if (font
->relative_compose
22970 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22971 || NILP (Faref (Vignore_relative_composition
,
22972 make_number (ch
)))))
22975 if (- descent
>= font
->relative_compose
)
22976 /* One extra pixel between two glyphs. */
22978 else if (ascent
<= 0)
22979 /* One extra pixel between two glyphs. */
22980 btm
= lowest
- 1 - ascent
- descent
;
22985 /* A composition rule is specified by an integer
22986 value that encodes global and new reference
22987 points (GREF and NREF). GREF and NREF are
22988 specified by numbers as below:
22990 0---1---2 -- ascent
22994 9--10--11 -- center
22996 ---3---4---5--- baseline
22998 6---7---8 -- descent
23000 int rule
= COMPOSITION_RULE (cmp
, i
);
23001 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23003 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23004 grefx
= gref
% 3, nrefx
= nref
% 3;
23005 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23007 xoff
= font_height
* (xoff
- 128) / 256;
23009 yoff
= font_height
* (yoff
- 128) / 256;
23012 + grefx
* (rightmost
- leftmost
) / 2
23013 - nrefx
* width
/ 2
23016 btm
= ((grefy
== 0 ? highest
23018 : grefy
== 2 ? lowest
23019 : (highest
+ lowest
) / 2)
23020 - (nrefy
== 0 ? ascent
+ descent
23021 : nrefy
== 1 ? descent
- boff
23023 : (ascent
+ descent
) / 2)
23027 cmp
->offsets
[i
* 2] = left
;
23028 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23030 /* Update the bounding box of the overall glyphs. */
23033 right
= left
+ width
;
23034 if (left
< leftmost
)
23036 if (right
> rightmost
)
23039 top
= btm
+ descent
+ ascent
;
23045 if (cmp
->lbearing
> left
+ lbearing
)
23046 cmp
->lbearing
= left
+ lbearing
;
23047 if (cmp
->rbearing
< left
+ rbearing
)
23048 cmp
->rbearing
= left
+ rbearing
;
23052 /* If there are glyphs whose x-offsets are negative,
23053 shift all glyphs to the right and make all x-offsets
23057 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23058 cmp
->offsets
[i
* 2] -= leftmost
;
23059 rightmost
-= leftmost
;
23060 cmp
->lbearing
-= leftmost
;
23061 cmp
->rbearing
-= leftmost
;
23064 if (left_padded
&& cmp
->lbearing
< 0)
23066 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23067 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23068 rightmost
-= cmp
->lbearing
;
23069 cmp
->rbearing
-= cmp
->lbearing
;
23072 if (right_padded
&& rightmost
< cmp
->rbearing
)
23074 rightmost
= cmp
->rbearing
;
23077 cmp
->pixel_width
= rightmost
;
23078 cmp
->ascent
= highest
;
23079 cmp
->descent
= - lowest
;
23080 if (cmp
->ascent
< font_ascent
)
23081 cmp
->ascent
= font_ascent
;
23082 if (cmp
->descent
< font_descent
)
23083 cmp
->descent
= font_descent
;
23087 && (cmp
->lbearing
< 0
23088 || cmp
->rbearing
> cmp
->pixel_width
))
23089 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23091 it
->pixel_width
= cmp
->pixel_width
;
23092 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23093 it
->descent
= it
->phys_descent
= cmp
->descent
;
23094 if (face
->box
!= FACE_NO_BOX
)
23096 int thick
= face
->box_line_width
;
23100 it
->ascent
+= thick
;
23101 it
->descent
+= thick
;
23106 if (it
->start_of_box_run_p
)
23107 it
->pixel_width
+= thick
;
23108 if (it
->end_of_box_run_p
)
23109 it
->pixel_width
+= thick
;
23112 /* If face has an overline, add the height of the overline
23113 (1 pixel) and a 1 pixel margin to the character height. */
23114 if (face
->overline_p
)
23115 it
->ascent
+= overline_margin
;
23117 take_vertical_position_into_account (it
);
23118 if (it
->ascent
< 0)
23120 if (it
->descent
< 0)
23124 append_composite_glyph (it
);
23126 else if (it
->what
== IT_COMPOSITION
)
23128 /* A dynamic (automatic) composition. */
23129 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23130 Lisp_Object gstring
;
23131 struct font_metrics metrics
;
23133 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23135 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23138 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23139 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23140 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23141 it
->descent
= it
->phys_descent
= metrics
.descent
;
23142 if (face
->box
!= FACE_NO_BOX
)
23144 int thick
= face
->box_line_width
;
23148 it
->ascent
+= thick
;
23149 it
->descent
+= thick
;
23154 if (it
->start_of_box_run_p
)
23155 it
->pixel_width
+= thick
;
23156 if (it
->end_of_box_run_p
)
23157 it
->pixel_width
+= thick
;
23159 /* If face has an overline, add the height of the overline
23160 (1 pixel) and a 1 pixel margin to the character height. */
23161 if (face
->overline_p
)
23162 it
->ascent
+= overline_margin
;
23163 take_vertical_position_into_account (it
);
23164 if (it
->ascent
< 0)
23166 if (it
->descent
< 0)
23170 append_composite_glyph (it
);
23172 else if (it
->what
== IT_GLYPHLESS
)
23173 produce_glyphless_glyph (it
, 0, Qnil
);
23174 else if (it
->what
== IT_IMAGE
)
23175 produce_image_glyph (it
);
23176 else if (it
->what
== IT_STRETCH
)
23177 produce_stretch_glyph (it
);
23180 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23181 because this isn't true for images with `:ascent 100'. */
23182 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23183 if (it
->area
== TEXT_AREA
)
23184 it
->current_x
+= it
->pixel_width
;
23186 if (extra_line_spacing
> 0)
23188 it
->descent
+= extra_line_spacing
;
23189 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23190 it
->max_extra_line_spacing
= extra_line_spacing
;
23193 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23194 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23195 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23196 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23200 Output LEN glyphs starting at START at the nominal cursor position.
23201 Advance the nominal cursor over the text. The global variable
23202 updated_window contains the window being updated, updated_row is
23203 the glyph row being updated, and updated_area is the area of that
23204 row being updated. */
23207 x_write_glyphs (struct glyph
*start
, int len
)
23211 xassert (updated_window
&& updated_row
);
23214 /* Write glyphs. */
23216 hpos
= start
- updated_row
->glyphs
[updated_area
];
23217 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23218 updated_row
, updated_area
,
23220 DRAW_NORMAL_TEXT
, 0);
23222 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23223 if (updated_area
== TEXT_AREA
23224 && updated_window
->phys_cursor_on_p
23225 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23226 && updated_window
->phys_cursor
.hpos
>= hpos
23227 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23228 updated_window
->phys_cursor_on_p
= 0;
23232 /* Advance the output cursor. */
23233 output_cursor
.hpos
+= len
;
23234 output_cursor
.x
= x
;
23239 Insert LEN glyphs from START at the nominal cursor position. */
23242 x_insert_glyphs (struct glyph
*start
, int len
)
23246 int line_height
, shift_by_width
, shifted_region_width
;
23247 struct glyph_row
*row
;
23248 struct glyph
*glyph
;
23249 int frame_x
, frame_y
;
23252 xassert (updated_window
&& updated_row
);
23254 w
= updated_window
;
23255 f
= XFRAME (WINDOW_FRAME (w
));
23257 /* Get the height of the line we are in. */
23259 line_height
= row
->height
;
23261 /* Get the width of the glyphs to insert. */
23262 shift_by_width
= 0;
23263 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23264 shift_by_width
+= glyph
->pixel_width
;
23266 /* Get the width of the region to shift right. */
23267 shifted_region_width
= (window_box_width (w
, updated_area
)
23272 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23273 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23275 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23276 line_height
, shift_by_width
);
23278 /* Write the glyphs. */
23279 hpos
= start
- row
->glyphs
[updated_area
];
23280 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23282 DRAW_NORMAL_TEXT
, 0);
23284 /* Advance the output cursor. */
23285 output_cursor
.hpos
+= len
;
23286 output_cursor
.x
+= shift_by_width
;
23292 Erase the current text line from the nominal cursor position
23293 (inclusive) to pixel column TO_X (exclusive). The idea is that
23294 everything from TO_X onward is already erased.
23296 TO_X is a pixel position relative to updated_area of
23297 updated_window. TO_X == -1 means clear to the end of this area. */
23300 x_clear_end_of_line (int to_x
)
23303 struct window
*w
= updated_window
;
23304 int max_x
, min_y
, max_y
;
23305 int from_x
, from_y
, to_y
;
23307 xassert (updated_window
&& updated_row
);
23308 f
= XFRAME (w
->frame
);
23310 if (updated_row
->full_width_p
)
23311 max_x
= WINDOW_TOTAL_WIDTH (w
);
23313 max_x
= window_box_width (w
, updated_area
);
23314 max_y
= window_text_bottom_y (w
);
23316 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23317 of window. For TO_X > 0, truncate to end of drawing area. */
23323 to_x
= min (to_x
, max_x
);
23325 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23327 /* Notice if the cursor will be cleared by this operation. */
23328 if (!updated_row
->full_width_p
)
23329 notice_overwritten_cursor (w
, updated_area
,
23330 output_cursor
.x
, -1,
23332 MATRIX_ROW_BOTTOM_Y (updated_row
));
23334 from_x
= output_cursor
.x
;
23336 /* Translate to frame coordinates. */
23337 if (updated_row
->full_width_p
)
23339 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23340 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23344 int area_left
= window_box_left (w
, updated_area
);
23345 from_x
+= area_left
;
23349 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23350 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23351 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23353 /* Prevent inadvertently clearing to end of the X window. */
23354 if (to_x
> from_x
&& to_y
> from_y
)
23357 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23358 to_x
- from_x
, to_y
- from_y
);
23363 #endif /* HAVE_WINDOW_SYSTEM */
23367 /***********************************************************************
23369 ***********************************************************************/
23371 /* Value is the internal representation of the specified cursor type
23372 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23373 of the bar cursor. */
23375 static enum text_cursor_kinds
23376 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23378 enum text_cursor_kinds type
;
23383 if (EQ (arg
, Qbox
))
23384 return FILLED_BOX_CURSOR
;
23386 if (EQ (arg
, Qhollow
))
23387 return HOLLOW_BOX_CURSOR
;
23389 if (EQ (arg
, Qbar
))
23396 && EQ (XCAR (arg
), Qbar
)
23397 && INTEGERP (XCDR (arg
))
23398 && XINT (XCDR (arg
)) >= 0)
23400 *width
= XINT (XCDR (arg
));
23404 if (EQ (arg
, Qhbar
))
23407 return HBAR_CURSOR
;
23411 && EQ (XCAR (arg
), Qhbar
)
23412 && INTEGERP (XCDR (arg
))
23413 && XINT (XCDR (arg
)) >= 0)
23415 *width
= XINT (XCDR (arg
));
23416 return HBAR_CURSOR
;
23419 /* Treat anything unknown as "hollow box cursor".
23420 It was bad to signal an error; people have trouble fixing
23421 .Xdefaults with Emacs, when it has something bad in it. */
23422 type
= HOLLOW_BOX_CURSOR
;
23427 /* Set the default cursor types for specified frame. */
23429 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
23434 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23435 FRAME_CURSOR_WIDTH (f
) = width
;
23437 /* By default, set up the blink-off state depending on the on-state. */
23439 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23442 FRAME_BLINK_OFF_CURSOR (f
)
23443 = get_specified_cursor_type (XCDR (tem
), &width
);
23444 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23447 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23451 #ifdef HAVE_WINDOW_SYSTEM
23453 /* Return the cursor we want to be displayed in window W. Return
23454 width of bar/hbar cursor through WIDTH arg. Return with
23455 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23456 (i.e. if the `system caret' should track this cursor).
23458 In a mini-buffer window, we want the cursor only to appear if we
23459 are reading input from this window. For the selected window, we
23460 want the cursor type given by the frame parameter or buffer local
23461 setting of cursor-type. If explicitly marked off, draw no cursor.
23462 In all other cases, we want a hollow box cursor. */
23464 static enum text_cursor_kinds
23465 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
23466 int *active_cursor
)
23468 struct frame
*f
= XFRAME (w
->frame
);
23469 struct buffer
*b
= XBUFFER (w
->buffer
);
23470 int cursor_type
= DEFAULT_CURSOR
;
23471 Lisp_Object alt_cursor
;
23472 int non_selected
= 0;
23474 *active_cursor
= 1;
23477 if (cursor_in_echo_area
23478 && FRAME_HAS_MINIBUF_P (f
)
23479 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23481 if (w
== XWINDOW (echo_area_window
))
23483 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
23485 *width
= FRAME_CURSOR_WIDTH (f
);
23486 return FRAME_DESIRED_CURSOR (f
);
23489 return get_specified_cursor_type (b
->cursor_type
, width
);
23492 *active_cursor
= 0;
23496 /* Detect a nonselected window or nonselected frame. */
23497 else if (w
!= XWINDOW (f
->selected_window
)
23498 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
23500 *active_cursor
= 0;
23502 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23508 /* Never display a cursor in a window in which cursor-type is nil. */
23509 if (NILP (b
->cursor_type
))
23512 /* Get the normal cursor type for this window. */
23513 if (EQ (b
->cursor_type
, Qt
))
23515 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23516 *width
= FRAME_CURSOR_WIDTH (f
);
23519 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
23521 /* Use cursor-in-non-selected-windows instead
23522 for non-selected window or frame. */
23525 alt_cursor
= b
->cursor_in_non_selected_windows
;
23526 if (!EQ (Qt
, alt_cursor
))
23527 return get_specified_cursor_type (alt_cursor
, width
);
23528 /* t means modify the normal cursor type. */
23529 if (cursor_type
== FILLED_BOX_CURSOR
)
23530 cursor_type
= HOLLOW_BOX_CURSOR
;
23531 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23533 return cursor_type
;
23536 /* Use normal cursor if not blinked off. */
23537 if (!w
->cursor_off_p
)
23539 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23541 if (cursor_type
== FILLED_BOX_CURSOR
)
23543 /* Using a block cursor on large images can be very annoying.
23544 So use a hollow cursor for "large" images.
23545 If image is not transparent (no mask), also use hollow cursor. */
23546 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23547 if (img
!= NULL
&& IMAGEP (img
->spec
))
23549 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23550 where N = size of default frame font size.
23551 This should cover most of the "tiny" icons people may use. */
23553 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23554 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23555 cursor_type
= HOLLOW_BOX_CURSOR
;
23558 else if (cursor_type
!= NO_CURSOR
)
23560 /* Display current only supports BOX and HOLLOW cursors for images.
23561 So for now, unconditionally use a HOLLOW cursor when cursor is
23562 not a solid box cursor. */
23563 cursor_type
= HOLLOW_BOX_CURSOR
;
23566 return cursor_type
;
23569 /* Cursor is blinked off, so determine how to "toggle" it. */
23571 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23572 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
23573 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23575 /* Then see if frame has specified a specific blink off cursor type. */
23576 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23578 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23579 return FRAME_BLINK_OFF_CURSOR (f
);
23583 /* Some people liked having a permanently visible blinking cursor,
23584 while others had very strong opinions against it. So it was
23585 decided to remove it. KFS 2003-09-03 */
23587 /* Finally perform built-in cursor blinking:
23588 filled box <-> hollow box
23589 wide [h]bar <-> narrow [h]bar
23590 narrow [h]bar <-> no cursor
23591 other type <-> no cursor */
23593 if (cursor_type
== FILLED_BOX_CURSOR
)
23594 return HOLLOW_BOX_CURSOR
;
23596 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23599 return cursor_type
;
23607 /* Notice when the text cursor of window W has been completely
23608 overwritten by a drawing operation that outputs glyphs in AREA
23609 starting at X0 and ending at X1 in the line starting at Y0 and
23610 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23611 the rest of the line after X0 has been written. Y coordinates
23612 are window-relative. */
23615 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
23616 int x0
, int x1
, int y0
, int y1
)
23618 int cx0
, cx1
, cy0
, cy1
;
23619 struct glyph_row
*row
;
23621 if (!w
->phys_cursor_on_p
)
23623 if (area
!= TEXT_AREA
)
23626 if (w
->phys_cursor
.vpos
< 0
23627 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23628 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23629 !(row
->enabled_p
&& row
->displays_text_p
)))
23632 if (row
->cursor_in_fringe_p
)
23634 row
->cursor_in_fringe_p
= 0;
23635 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
23636 w
->phys_cursor_on_p
= 0;
23640 cx0
= w
->phys_cursor
.x
;
23641 cx1
= cx0
+ w
->phys_cursor_width
;
23642 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23645 /* The cursor image will be completely removed from the
23646 screen if the output area intersects the cursor area in
23647 y-direction. When we draw in [y0 y1[, and some part of
23648 the cursor is at y < y0, that part must have been drawn
23649 before. When scrolling, the cursor is erased before
23650 actually scrolling, so we don't come here. When not
23651 scrolling, the rows above the old cursor row must have
23652 changed, and in this case these rows must have written
23653 over the cursor image.
23655 Likewise if part of the cursor is below y1, with the
23656 exception of the cursor being in the first blank row at
23657 the buffer and window end because update_text_area
23658 doesn't draw that row. (Except when it does, but
23659 that's handled in update_text_area.) */
23661 cy0
= w
->phys_cursor
.y
;
23662 cy1
= cy0
+ w
->phys_cursor_height
;
23663 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23666 w
->phys_cursor_on_p
= 0;
23669 #endif /* HAVE_WINDOW_SYSTEM */
23672 /************************************************************************
23674 ************************************************************************/
23676 #ifdef HAVE_WINDOW_SYSTEM
23679 Fix the display of area AREA of overlapping row ROW in window W
23680 with respect to the overlapping part OVERLAPS. */
23683 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
23684 enum glyph_row_area area
, int overlaps
)
23691 for (i
= 0; i
< row
->used
[area
];)
23693 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23695 int start
= i
, start_x
= x
;
23699 x
+= row
->glyphs
[area
][i
].pixel_width
;
23702 while (i
< row
->used
[area
]
23703 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23705 draw_glyphs (w
, start_x
, row
, area
,
23707 DRAW_NORMAL_TEXT
, overlaps
);
23711 x
+= row
->glyphs
[area
][i
].pixel_width
;
23721 Draw the cursor glyph of window W in glyph row ROW. See the
23722 comment of draw_glyphs for the meaning of HL. */
23725 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
23726 enum draw_glyphs_face hl
)
23728 /* If cursor hpos is out of bounds, don't draw garbage. This can
23729 happen in mini-buffer windows when switching between echo area
23730 glyphs and mini-buffer. */
23731 if ((row
->reversed_p
23732 ? (w
->phys_cursor
.hpos
>= 0)
23733 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
23735 int on_p
= w
->phys_cursor_on_p
;
23737 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23738 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23740 w
->phys_cursor_on_p
= on_p
;
23742 if (hl
== DRAW_CURSOR
)
23743 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23744 /* When we erase the cursor, and ROW is overlapped by other
23745 rows, make sure that these overlapping parts of other rows
23747 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23749 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23751 if (row
> w
->current_matrix
->rows
23752 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23753 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23754 OVERLAPS_ERASED_CURSOR
);
23756 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23757 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23758 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23759 OVERLAPS_ERASED_CURSOR
);
23766 Erase the image of a cursor of window W from the screen. */
23769 erase_phys_cursor (struct window
*w
)
23771 struct frame
*f
= XFRAME (w
->frame
);
23772 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23773 int hpos
= w
->phys_cursor
.hpos
;
23774 int vpos
= w
->phys_cursor
.vpos
;
23775 int mouse_face_here_p
= 0;
23776 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23777 struct glyph_row
*cursor_row
;
23778 struct glyph
*cursor_glyph
;
23779 enum draw_glyphs_face hl
;
23781 /* No cursor displayed or row invalidated => nothing to do on the
23783 if (w
->phys_cursor_type
== NO_CURSOR
)
23784 goto mark_cursor_off
;
23786 /* VPOS >= active_glyphs->nrows means that window has been resized.
23787 Don't bother to erase the cursor. */
23788 if (vpos
>= active_glyphs
->nrows
)
23789 goto mark_cursor_off
;
23791 /* If row containing cursor is marked invalid, there is nothing we
23793 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23794 if (!cursor_row
->enabled_p
)
23795 goto mark_cursor_off
;
23797 /* If line spacing is > 0, old cursor may only be partially visible in
23798 window after split-window. So adjust visible height. */
23799 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23800 window_text_bottom_y (w
) - cursor_row
->y
);
23802 /* If row is completely invisible, don't attempt to delete a cursor which
23803 isn't there. This can happen if cursor is at top of a window, and
23804 we switch to a buffer with a header line in that window. */
23805 if (cursor_row
->visible_height
<= 0)
23806 goto mark_cursor_off
;
23808 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23809 if (cursor_row
->cursor_in_fringe_p
)
23811 cursor_row
->cursor_in_fringe_p
= 0;
23812 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
23813 goto mark_cursor_off
;
23816 /* This can happen when the new row is shorter than the old one.
23817 In this case, either draw_glyphs or clear_end_of_line
23818 should have cleared the cursor. Note that we wouldn't be
23819 able to erase the cursor in this case because we don't have a
23820 cursor glyph at hand. */
23821 if ((cursor_row
->reversed_p
23822 ? (w
->phys_cursor
.hpos
< 0)
23823 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
23824 goto mark_cursor_off
;
23826 /* If the cursor is in the mouse face area, redisplay that when
23827 we clear the cursor. */
23828 if (! NILP (hlinfo
->mouse_face_window
)
23829 && coords_in_mouse_face_p (w
, hpos
, vpos
)
23830 /* Don't redraw the cursor's spot in mouse face if it is at the
23831 end of a line (on a newline). The cursor appears there, but
23832 mouse highlighting does not. */
23833 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
23834 mouse_face_here_p
= 1;
23836 /* Maybe clear the display under the cursor. */
23837 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23840 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23843 cursor_glyph
= get_phys_cursor_glyph (w
);
23844 if (cursor_glyph
== NULL
)
23845 goto mark_cursor_off
;
23847 width
= cursor_glyph
->pixel_width
;
23848 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23849 x
= w
->phys_cursor
.x
;
23851 width
-= left_x
- x
;
23852 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23853 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23854 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23857 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23860 /* Erase the cursor by redrawing the character underneath it. */
23861 if (mouse_face_here_p
)
23862 hl
= DRAW_MOUSE_FACE
;
23864 hl
= DRAW_NORMAL_TEXT
;
23865 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23868 w
->phys_cursor_on_p
= 0;
23869 w
->phys_cursor_type
= NO_CURSOR
;
23874 Display or clear cursor of window W. If ON is zero, clear the
23875 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23876 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23879 display_and_set_cursor (struct window
*w
, int on
,
23880 int hpos
, int vpos
, int x
, int y
)
23882 struct frame
*f
= XFRAME (w
->frame
);
23883 int new_cursor_type
;
23884 int new_cursor_width
;
23886 struct glyph_row
*glyph_row
;
23887 struct glyph
*glyph
;
23889 /* This is pointless on invisible frames, and dangerous on garbaged
23890 windows and frames; in the latter case, the frame or window may
23891 be in the midst of changing its size, and x and y may be off the
23893 if (! FRAME_VISIBLE_P (f
)
23894 || FRAME_GARBAGED_P (f
)
23895 || vpos
>= w
->current_matrix
->nrows
23896 || hpos
>= w
->current_matrix
->matrix_w
)
23899 /* If cursor is off and we want it off, return quickly. */
23900 if (!on
&& !w
->phys_cursor_on_p
)
23903 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23904 /* If cursor row is not enabled, we don't really know where to
23905 display the cursor. */
23906 if (!glyph_row
->enabled_p
)
23908 w
->phys_cursor_on_p
= 0;
23913 if (!glyph_row
->exact_window_width_line_p
23914 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
23915 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23917 xassert (interrupt_input_blocked
);
23919 /* Set new_cursor_type to the cursor we want to be displayed. */
23920 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23921 &new_cursor_width
, &active_cursor
);
23923 /* If cursor is currently being shown and we don't want it to be or
23924 it is in the wrong place, or the cursor type is not what we want,
23926 if (w
->phys_cursor_on_p
23928 || w
->phys_cursor
.x
!= x
23929 || w
->phys_cursor
.y
!= y
23930 || new_cursor_type
!= w
->phys_cursor_type
23931 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23932 && new_cursor_width
!= w
->phys_cursor_width
)))
23933 erase_phys_cursor (w
);
23935 /* Don't check phys_cursor_on_p here because that flag is only set
23936 to zero in some cases where we know that the cursor has been
23937 completely erased, to avoid the extra work of erasing the cursor
23938 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23939 still not be visible, or it has only been partly erased. */
23942 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23943 w
->phys_cursor_height
= glyph_row
->height
;
23945 /* Set phys_cursor_.* before x_draw_.* is called because some
23946 of them may need the information. */
23947 w
->phys_cursor
.x
= x
;
23948 w
->phys_cursor
.y
= glyph_row
->y
;
23949 w
->phys_cursor
.hpos
= hpos
;
23950 w
->phys_cursor
.vpos
= vpos
;
23953 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23954 new_cursor_type
, new_cursor_width
,
23955 on
, active_cursor
);
23959 /* Switch the display of W's cursor on or off, according to the value
23963 update_window_cursor (struct window
*w
, int on
)
23965 /* Don't update cursor in windows whose frame is in the process
23966 of being deleted. */
23967 if (w
->current_matrix
)
23970 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23971 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23977 /* Call update_window_cursor with parameter ON_P on all leaf windows
23978 in the window tree rooted at W. */
23981 update_cursor_in_window_tree (struct window
*w
, int on_p
)
23985 if (!NILP (w
->hchild
))
23986 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23987 else if (!NILP (w
->vchild
))
23988 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23990 update_window_cursor (w
, on_p
);
23992 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23998 Display the cursor on window W, or clear it, according to ON_P.
23999 Don't change the cursor's position. */
24002 x_update_cursor (struct frame
*f
, int on_p
)
24004 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24009 Clear the cursor of window W to background color, and mark the
24010 cursor as not shown. This is used when the text where the cursor
24011 is about to be rewritten. */
24014 x_clear_cursor (struct window
*w
)
24016 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24017 update_window_cursor (w
, 0);
24020 #endif /* HAVE_WINDOW_SYSTEM */
24022 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24025 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24026 int start_hpos
, int end_hpos
,
24027 enum draw_glyphs_face draw
)
24029 #ifdef HAVE_WINDOW_SYSTEM
24030 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24032 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24036 #if defined (HAVE_GPM) || defined (MSDOS)
24037 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24042 Display the active region described by mouse_face_* according to DRAW. */
24045 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24047 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24048 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24050 if (/* If window is in the process of being destroyed, don't bother
24052 w
->current_matrix
!= NULL
24053 /* Don't update mouse highlight if hidden */
24054 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24055 /* Recognize when we are called to operate on rows that don't exist
24056 anymore. This can happen when a window is split. */
24057 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24059 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24060 struct glyph_row
*row
, *first
, *last
;
24062 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24063 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24065 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24067 int start_hpos
, end_hpos
, start_x
;
24069 /* For all but the first row, the highlight starts at column 0. */
24072 /* R2L rows have BEG and END in reversed order, but the
24073 screen drawing geometry is always left to right. So
24074 we need to mirror the beginning and end of the
24075 highlighted area in R2L rows. */
24076 if (!row
->reversed_p
)
24078 start_hpos
= hlinfo
->mouse_face_beg_col
;
24079 start_x
= hlinfo
->mouse_face_beg_x
;
24081 else if (row
== last
)
24083 start_hpos
= hlinfo
->mouse_face_end_col
;
24084 start_x
= hlinfo
->mouse_face_end_x
;
24092 else if (row
->reversed_p
&& row
== last
)
24094 start_hpos
= hlinfo
->mouse_face_end_col
;
24095 start_x
= hlinfo
->mouse_face_end_x
;
24105 if (!row
->reversed_p
)
24106 end_hpos
= hlinfo
->mouse_face_end_col
;
24107 else if (row
== first
)
24108 end_hpos
= hlinfo
->mouse_face_beg_col
;
24111 end_hpos
= row
->used
[TEXT_AREA
];
24112 if (draw
== DRAW_NORMAL_TEXT
)
24113 row
->fill_line_p
= 1; /* Clear to end of line */
24116 else if (row
->reversed_p
&& row
== first
)
24117 end_hpos
= hlinfo
->mouse_face_beg_col
;
24120 end_hpos
= row
->used
[TEXT_AREA
];
24121 if (draw
== DRAW_NORMAL_TEXT
)
24122 row
->fill_line_p
= 1; /* Clear to end of line */
24125 if (end_hpos
> start_hpos
)
24127 draw_row_with_mouse_face (w
, start_x
, row
,
24128 start_hpos
, end_hpos
, draw
);
24131 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24135 #ifdef HAVE_WINDOW_SYSTEM
24136 /* When we've written over the cursor, arrange for it to
24137 be displayed again. */
24138 if (FRAME_WINDOW_P (f
)
24139 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24142 display_and_set_cursor (w
, 1,
24143 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24144 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24147 #endif /* HAVE_WINDOW_SYSTEM */
24150 #ifdef HAVE_WINDOW_SYSTEM
24151 /* Change the mouse cursor. */
24152 if (FRAME_WINDOW_P (f
))
24154 if (draw
== DRAW_NORMAL_TEXT
24155 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24156 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24157 else if (draw
== DRAW_MOUSE_FACE
)
24158 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24160 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24162 #endif /* HAVE_WINDOW_SYSTEM */
24166 Clear out the mouse-highlighted active region.
24167 Redraw it un-highlighted first. Value is non-zero if mouse
24168 face was actually drawn unhighlighted. */
24171 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24175 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24177 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24181 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24182 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24183 hlinfo
->mouse_face_window
= Qnil
;
24184 hlinfo
->mouse_face_overlay
= Qnil
;
24188 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24189 within the mouse face on that window. */
24191 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24193 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24195 /* Quickly resolve the easy cases. */
24196 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24197 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24199 if (vpos
< hlinfo
->mouse_face_beg_row
24200 || vpos
> hlinfo
->mouse_face_end_row
)
24202 if (vpos
> hlinfo
->mouse_face_beg_row
24203 && vpos
< hlinfo
->mouse_face_end_row
)
24206 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24208 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24210 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24213 else if ((vpos
== hlinfo
->mouse_face_beg_row
24214 && hpos
>= hlinfo
->mouse_face_beg_col
)
24215 || (vpos
== hlinfo
->mouse_face_end_row
24216 && hpos
< hlinfo
->mouse_face_end_col
))
24221 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24223 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24226 else if ((vpos
== hlinfo
->mouse_face_beg_row
24227 && hpos
<= hlinfo
->mouse_face_beg_col
)
24228 || (vpos
== hlinfo
->mouse_face_end_row
24229 && hpos
> hlinfo
->mouse_face_end_col
))
24237 Non-zero if physical cursor of window W is within mouse face. */
24240 cursor_in_mouse_face_p (struct window
*w
)
24242 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24247 /* Find the glyph rows START_ROW and END_ROW of window W that display
24248 characters between buffer positions START_CHARPOS and END_CHARPOS
24249 (excluding END_CHARPOS). This is similar to row_containing_pos,
24250 but is more accurate when bidi reordering makes buffer positions
24251 change non-linearly with glyph rows. */
24253 rows_from_pos_range (struct window
*w
,
24254 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24255 struct glyph_row
**start
, struct glyph_row
**end
)
24257 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24258 int last_y
= window_text_bottom_y (w
);
24259 struct glyph_row
*row
;
24264 while (!first
->enabled_p
24265 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24268 /* Find the START row. */
24270 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24273 /* A row can potentially be the START row if the range of the
24274 characters it displays intersects the range
24275 [START_CHARPOS..END_CHARPOS). */
24276 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24277 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24278 /* See the commentary in row_containing_pos, for the
24279 explanation of the complicated way to check whether
24280 some position is beyond the end of the characters
24281 displayed by a row. */
24282 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24283 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24284 && !row
->ends_at_zv_p
24285 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24286 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24287 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24288 && !row
->ends_at_zv_p
24289 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24291 /* Found a candidate row. Now make sure at least one of the
24292 glyphs it displays has a charpos from the range
24293 [START_CHARPOS..END_CHARPOS).
24295 This is not obvious because bidi reordering could make
24296 buffer positions of a row be 1,2,3,102,101,100, and if we
24297 want to highlight characters in [50..60), we don't want
24298 this row, even though [50..60) does intersect [1..103),
24299 the range of character positions given by the row's start
24300 and end positions. */
24301 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24302 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24306 if (BUFFERP (g
->object
)
24307 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24316 /* Find the END row. */
24318 /* If the last row is partially visible, start looking for END
24319 from that row, instead of starting from FIRST. */
24320 && !(row
->enabled_p
24321 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24323 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24325 struct glyph_row
*next
= row
+ 1;
24327 if (!next
->enabled_p
24328 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24329 /* The first row >= START whose range of displayed characters
24330 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24331 is the row END + 1. */
24332 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24333 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24334 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24335 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24336 && !next
->ends_at_zv_p
24337 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24338 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24339 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24340 && !next
->ends_at_zv_p
24341 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24348 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24349 but none of the characters it displays are in the range, it is
24351 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24352 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24356 if (BUFFERP (g
->object
)
24357 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24370 /* This function sets the mouse_face_* elements of HLINFO, assuming
24371 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24372 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24373 for the overlay or run of text properties specifying the mouse
24374 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24375 before-string and after-string that must also be highlighted.
24376 DISPLAY_STRING, if non-nil, is a display string that may cover some
24377 or all of the highlighted text. */
24380 mouse_face_from_buffer_pos (Lisp_Object window
,
24381 Mouse_HLInfo
*hlinfo
,
24382 EMACS_INT mouse_charpos
,
24383 EMACS_INT start_charpos
,
24384 EMACS_INT end_charpos
,
24385 Lisp_Object before_string
,
24386 Lisp_Object after_string
,
24387 Lisp_Object display_string
)
24389 struct window
*w
= XWINDOW (window
);
24390 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24391 struct glyph_row
*r1
, *r2
;
24392 struct glyph
*glyph
, *end
;
24393 EMACS_INT ignore
, pos
;
24396 xassert (NILP (display_string
) || STRINGP (display_string
));
24397 xassert (NILP (before_string
) || STRINGP (before_string
));
24398 xassert (NILP (after_string
) || STRINGP (after_string
));
24400 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
24401 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
24403 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24404 /* If the before-string or display-string contains newlines,
24405 rows_from_pos_range skips to its last row. Move back. */
24406 if (!NILP (before_string
) || !NILP (display_string
))
24408 struct glyph_row
*prev
;
24409 while ((prev
= r1
- 1, prev
>= first
)
24410 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
24411 && prev
->used
[TEXT_AREA
] > 0)
24413 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
24414 glyph
= beg
+ prev
->used
[TEXT_AREA
];
24415 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
24417 || !(EQ (glyph
->object
, before_string
)
24418 || EQ (glyph
->object
, display_string
)))
24425 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24426 hlinfo
->mouse_face_past_end
= 1;
24428 else if (!NILP (after_string
))
24430 /* If the after-string has newlines, advance to its last row. */
24431 struct glyph_row
*next
;
24432 struct glyph_row
*last
24433 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24435 for (next
= r2
+ 1;
24437 && next
->used
[TEXT_AREA
] > 0
24438 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
24442 /* The rest of the display engine assumes that mouse_face_beg_row is
24443 either above below mouse_face_end_row or identical to it. But
24444 with bidi-reordered continued lines, the row for START_CHARPOS
24445 could be below the row for END_CHARPOS. If so, swap the rows and
24446 store them in correct order. */
24449 struct glyph_row
*tem
= r2
;
24455 hlinfo
->mouse_face_beg_y
= r1
->y
;
24456 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
24457 hlinfo
->mouse_face_end_y
= r2
->y
;
24458 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
24460 /* For a bidi-reordered row, the positions of BEFORE_STRING,
24461 AFTER_STRING, DISPLAY_STRING, START_CHARPOS, and END_CHARPOS
24462 could be anywhere in the row and in any order. The strategy
24463 below is to find the leftmost and the rightmost glyph that
24464 belongs to either of these 3 strings, or whose position is
24465 between START_CHARPOS and END_CHARPOS, and highlight all the
24466 glyphs between those two. This may cover more than just the text
24467 between START_CHARPOS and END_CHARPOS if the range of characters
24468 strides the bidi level boundary, e.g. if the beginning is in R2L
24469 text while the end is in L2R text or vice versa. */
24470 if (!r1
->reversed_p
)
24472 /* This row is in a left to right paragraph. Scan it left to
24474 glyph
= r1
->glyphs
[TEXT_AREA
];
24475 end
= glyph
+ r1
->used
[TEXT_AREA
];
24478 /* Skip truncation glyphs at the start of the glyph row. */
24479 if (r1
->displays_text_p
)
24481 && INTEGERP (glyph
->object
)
24482 && glyph
->charpos
< 0;
24484 x
+= glyph
->pixel_width
;
24486 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24487 or DISPLAY_STRING, and the first glyph from buffer whose
24488 position is between START_CHARPOS and END_CHARPOS. */
24490 && !INTEGERP (glyph
->object
)
24491 && !EQ (glyph
->object
, display_string
)
24492 && !(BUFFERP (glyph
->object
)
24493 && (glyph
->charpos
>= start_charpos
24494 && glyph
->charpos
< end_charpos
));
24497 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24498 are present at buffer positions between START_CHARPOS and
24499 END_CHARPOS, or if they come from an overlay. */
24500 if (EQ (glyph
->object
, before_string
))
24502 pos
= string_buffer_position (w
, before_string
,
24504 /* If pos == 0, it means before_string came from an
24505 overlay, not from a buffer position. */
24506 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24509 else if (EQ (glyph
->object
, after_string
))
24511 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24512 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24515 x
+= glyph
->pixel_width
;
24517 hlinfo
->mouse_face_beg_x
= x
;
24518 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24522 /* This row is in a right to left paragraph. Scan it right to
24526 end
= r1
->glyphs
[TEXT_AREA
] - 1;
24527 glyph
= end
+ r1
->used
[TEXT_AREA
];
24529 /* Skip truncation glyphs at the start of the glyph row. */
24530 if (r1
->displays_text_p
)
24532 && INTEGERP (glyph
->object
)
24533 && glyph
->charpos
< 0;
24537 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24538 or DISPLAY_STRING, and the first glyph from buffer whose
24539 position is between START_CHARPOS and END_CHARPOS. */
24541 && !INTEGERP (glyph
->object
)
24542 && !EQ (glyph
->object
, display_string
)
24543 && !(BUFFERP (glyph
->object
)
24544 && (glyph
->charpos
>= start_charpos
24545 && glyph
->charpos
< end_charpos
));
24548 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24549 are present at buffer positions between START_CHARPOS and
24550 END_CHARPOS, or if they come from an overlay. */
24551 if (EQ (glyph
->object
, before_string
))
24553 pos
= string_buffer_position (w
, before_string
, start_charpos
);
24554 /* If pos == 0, it means before_string came from an
24555 overlay, not from a buffer position. */
24556 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24559 else if (EQ (glyph
->object
, after_string
))
24561 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24562 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24567 glyph
++; /* first glyph to the right of the highlighted area */
24568 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
24569 x
+= g
->pixel_width
;
24570 hlinfo
->mouse_face_beg_x
= x
;
24571 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24574 /* If the highlight ends in a different row, compute GLYPH and END
24575 for the end row. Otherwise, reuse the values computed above for
24576 the row where the highlight begins. */
24579 if (!r2
->reversed_p
)
24581 glyph
= r2
->glyphs
[TEXT_AREA
];
24582 end
= glyph
+ r2
->used
[TEXT_AREA
];
24587 end
= r2
->glyphs
[TEXT_AREA
] - 1;
24588 glyph
= end
+ r2
->used
[TEXT_AREA
];
24592 if (!r2
->reversed_p
)
24594 /* Skip truncation and continuation glyphs near the end of the
24595 row, and also blanks and stretch glyphs inserted by
24596 extend_face_to_end_of_line. */
24598 && INTEGERP ((end
- 1)->object
)
24599 && (end
- 1)->charpos
<= 0)
24601 /* Scan the rest of the glyph row from the end, looking for the
24602 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24603 DISPLAY_STRING, or whose position is between START_CHARPOS
24607 && !INTEGERP (end
->object
)
24608 && !EQ (end
->object
, display_string
)
24609 && !(BUFFERP (end
->object
)
24610 && (end
->charpos
>= start_charpos
24611 && end
->charpos
< end_charpos
));
24614 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24615 are present at buffer positions between START_CHARPOS and
24616 END_CHARPOS, or if they come from an overlay. */
24617 if (EQ (end
->object
, before_string
))
24619 pos
= string_buffer_position (w
, before_string
, start_charpos
);
24620 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24623 else if (EQ (end
->object
, after_string
))
24625 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24626 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24630 /* Find the X coordinate of the last glyph to be highlighted. */
24631 for (; glyph
<= end
; ++glyph
)
24632 x
+= glyph
->pixel_width
;
24634 hlinfo
->mouse_face_end_x
= x
;
24635 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
24639 /* Skip truncation and continuation glyphs near the end of the
24640 row, and also blanks and stretch glyphs inserted by
24641 extend_face_to_end_of_line. */
24645 && INTEGERP (end
->object
)
24646 && end
->charpos
<= 0)
24648 x
+= end
->pixel_width
;
24651 /* Scan the rest of the glyph row from the end, looking for the
24652 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24653 DISPLAY_STRING, or whose position is between START_CHARPOS
24657 && !INTEGERP (end
->object
)
24658 && !EQ (end
->object
, display_string
)
24659 && !(BUFFERP (end
->object
)
24660 && (end
->charpos
>= start_charpos
24661 && end
->charpos
< end_charpos
));
24664 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24665 are present at buffer positions between START_CHARPOS and
24666 END_CHARPOS, or if they come from an overlay. */
24667 if (EQ (end
->object
, before_string
))
24669 pos
= string_buffer_position (w
, before_string
, start_charpos
);
24670 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24673 else if (EQ (end
->object
, after_string
))
24675 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24676 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24679 x
+= end
->pixel_width
;
24681 hlinfo
->mouse_face_end_x
= x
;
24682 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
24685 hlinfo
->mouse_face_window
= window
;
24686 hlinfo
->mouse_face_face_id
24687 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
24689 !hlinfo
->mouse_face_hidden
, -1);
24690 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
24693 /* The following function is not used anymore (replaced with
24694 mouse_face_from_string_pos), but I leave it here for the time
24695 being, in case someone would. */
24697 #if 0 /* not used */
24699 /* Find the position of the glyph for position POS in OBJECT in
24700 window W's current matrix, and return in *X, *Y the pixel
24701 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
24703 RIGHT_P non-zero means return the position of the right edge of the
24704 glyph, RIGHT_P zero means return the left edge position.
24706 If no glyph for POS exists in the matrix, return the position of
24707 the glyph with the next smaller position that is in the matrix, if
24708 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
24709 exists in the matrix, return the position of the glyph with the
24710 next larger position in OBJECT.
24712 Value is non-zero if a glyph was found. */
24715 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
24716 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
24718 int yb
= window_text_bottom_y (w
);
24719 struct glyph_row
*r
;
24720 struct glyph
*best_glyph
= NULL
;
24721 struct glyph_row
*best_row
= NULL
;
24724 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24725 r
->enabled_p
&& r
->y
< yb
;
24728 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
24729 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
24732 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24733 if (EQ (g
->object
, object
))
24735 if (g
->charpos
== pos
)
24742 else if (best_glyph
== NULL
24743 || ((eabs (g
->charpos
- pos
)
24744 < eabs (best_glyph
->charpos
- pos
))
24747 : g
->charpos
> pos
)))
24761 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
24765 *x
+= best_glyph
->pixel_width
;
24770 *vpos
= best_row
- w
->current_matrix
->rows
;
24773 return best_glyph
!= NULL
;
24775 #endif /* not used */
24777 /* Find the positions of the first and the last glyphs in window W's
24778 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
24779 (assumed to be a string), and return in HLINFO's mouse_face_*
24780 members the pixel and column/row coordinates of those glyphs. */
24783 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
24784 Lisp_Object object
,
24785 EMACS_INT startpos
, EMACS_INT endpos
)
24787 int yb
= window_text_bottom_y (w
);
24788 struct glyph_row
*r
;
24789 struct glyph
*g
, *e
;
24793 /* Find the glyph row with at least one position in the range
24794 [STARTPOS..ENDPOS], and the first glyph in that row whose
24795 position belongs to that range. */
24796 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24797 r
->enabled_p
&& r
->y
< yb
;
24800 if (!r
->reversed_p
)
24802 g
= r
->glyphs
[TEXT_AREA
];
24803 e
= g
+ r
->used
[TEXT_AREA
];
24804 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24805 if (EQ (g
->object
, object
)
24806 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24808 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24809 hlinfo
->mouse_face_beg_y
= r
->y
;
24810 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24811 hlinfo
->mouse_face_beg_x
= gx
;
24820 e
= r
->glyphs
[TEXT_AREA
];
24821 g
= e
+ r
->used
[TEXT_AREA
];
24822 for ( ; g
> e
; --g
)
24823 if (EQ ((g
-1)->object
, object
)
24824 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
24826 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24827 hlinfo
->mouse_face_beg_y
= r
->y
;
24828 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24829 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
24830 gx
+= g1
->pixel_width
;
24831 hlinfo
->mouse_face_beg_x
= gx
;
24843 /* Starting with the next row, look for the first row which does NOT
24844 include any glyphs whose positions are in the range. */
24845 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
24847 g
= r
->glyphs
[TEXT_AREA
];
24848 e
= g
+ r
->used
[TEXT_AREA
];
24850 for ( ; g
< e
; ++g
)
24851 if (EQ (g
->object
, object
)
24852 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24861 /* The highlighted region ends on the previous row. */
24864 /* Set the end row and its vertical pixel coordinate. */
24865 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
24866 hlinfo
->mouse_face_end_y
= r
->y
;
24868 /* Compute and set the end column and the end column's horizontal
24869 pixel coordinate. */
24870 if (!r
->reversed_p
)
24872 g
= r
->glyphs
[TEXT_AREA
];
24873 e
= g
+ r
->used
[TEXT_AREA
];
24874 for ( ; e
> g
; --e
)
24875 if (EQ ((e
-1)->object
, object
)
24876 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
24878 hlinfo
->mouse_face_end_col
= e
- g
;
24880 for (gx
= r
->x
; g
< e
; ++g
)
24881 gx
+= g
->pixel_width
;
24882 hlinfo
->mouse_face_end_x
= gx
;
24886 e
= r
->glyphs
[TEXT_AREA
];
24887 g
= e
+ r
->used
[TEXT_AREA
];
24888 for (gx
= r
->x
; e
< g
; ++e
)
24890 if (EQ (e
->object
, object
)
24891 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
24893 gx
+= e
->pixel_width
;
24895 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
24896 hlinfo
->mouse_face_end_x
= gx
;
24900 #ifdef HAVE_WINDOW_SYSTEM
24902 /* See if position X, Y is within a hot-spot of an image. */
24905 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
24907 if (!CONSP (hot_spot
))
24910 if (EQ (XCAR (hot_spot
), Qrect
))
24912 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
24913 Lisp_Object rect
= XCDR (hot_spot
);
24917 if (!CONSP (XCAR (rect
)))
24919 if (!CONSP (XCDR (rect
)))
24921 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
24923 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
24925 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
24927 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
24931 else if (EQ (XCAR (hot_spot
), Qcircle
))
24933 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
24934 Lisp_Object circ
= XCDR (hot_spot
);
24935 Lisp_Object lr
, lx0
, ly0
;
24937 && CONSP (XCAR (circ
))
24938 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
24939 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
24940 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
24942 double r
= XFLOATINT (lr
);
24943 double dx
= XINT (lx0
) - x
;
24944 double dy
= XINT (ly0
) - y
;
24945 return (dx
* dx
+ dy
* dy
<= r
* r
);
24948 else if (EQ (XCAR (hot_spot
), Qpoly
))
24950 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
24951 if (VECTORP (XCDR (hot_spot
)))
24953 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
24954 Lisp_Object
*poly
= v
->contents
;
24958 Lisp_Object lx
, ly
;
24961 /* Need an even number of coordinates, and at least 3 edges. */
24962 if (n
< 6 || n
& 1)
24965 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
24966 If count is odd, we are inside polygon. Pixels on edges
24967 may or may not be included depending on actual geometry of the
24969 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
24970 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
24972 x0
= XINT (lx
), y0
= XINT (ly
);
24973 for (i
= 0; i
< n
; i
+= 2)
24975 int x1
= x0
, y1
= y0
;
24976 if ((lx
= poly
[i
], !INTEGERP (lx
))
24977 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
24979 x0
= XINT (lx
), y0
= XINT (ly
);
24981 /* Does this segment cross the X line? */
24989 if (y
> y0
&& y
> y1
)
24991 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
25001 find_hot_spot (Lisp_Object map
, int x
, int y
)
25003 while (CONSP (map
))
25005 if (CONSP (XCAR (map
))
25006 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25014 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25016 doc
: /* Lookup in image map MAP coordinates X and Y.
25017 An image map is an alist where each element has the format (AREA ID PLIST).
25018 An AREA is specified as either a rectangle, a circle, or a polygon:
25019 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25020 pixel coordinates of the upper left and bottom right corners.
25021 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25022 and the radius of the circle; r may be a float or integer.
25023 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25024 vector describes one corner in the polygon.
25025 Returns the alist element for the first matching AREA in MAP. */)
25026 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25034 return find_hot_spot (map
, XINT (x
), XINT (y
));
25038 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25040 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25042 /* Do not change cursor shape while dragging mouse. */
25043 if (!NILP (do_mouse_tracking
))
25046 if (!NILP (pointer
))
25048 if (EQ (pointer
, Qarrow
))
25049 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25050 else if (EQ (pointer
, Qhand
))
25051 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25052 else if (EQ (pointer
, Qtext
))
25053 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25054 else if (EQ (pointer
, intern ("hdrag")))
25055 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25056 #ifdef HAVE_X_WINDOWS
25057 else if (EQ (pointer
, intern ("vdrag")))
25058 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25060 else if (EQ (pointer
, intern ("hourglass")))
25061 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25062 else if (EQ (pointer
, Qmodeline
))
25063 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25065 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25068 if (cursor
!= No_Cursor
)
25069 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25072 #endif /* HAVE_WINDOW_SYSTEM */
25074 /* Take proper action when mouse has moved to the mode or header line
25075 or marginal area AREA of window W, x-position X and y-position Y.
25076 X is relative to the start of the text display area of W, so the
25077 width of bitmap areas and scroll bars must be subtracted to get a
25078 position relative to the start of the mode line. */
25081 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25082 enum window_part area
)
25084 struct window
*w
= XWINDOW (window
);
25085 struct frame
*f
= XFRAME (w
->frame
);
25086 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25087 #ifdef HAVE_WINDOW_SYSTEM
25088 Display_Info
*dpyinfo
;
25090 Cursor cursor
= No_Cursor
;
25091 Lisp_Object pointer
= Qnil
;
25092 int dx
, dy
, width
, height
;
25094 Lisp_Object string
, object
= Qnil
;
25095 Lisp_Object pos
, help
;
25097 Lisp_Object mouse_face
;
25098 int original_x_pixel
= x
;
25099 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25100 struct glyph_row
*row
;
25102 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25107 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25108 returns them in row/column units! */
25109 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25110 &object
, &dx
, &dy
, &width
, &height
);
25112 row
= (area
== ON_MODE_LINE
25113 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25114 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25116 /* Find the glyph under the mouse pointer. */
25117 if (row
->mode_line_p
&& row
->enabled_p
)
25119 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25120 end
= glyph
+ row
->used
[TEXT_AREA
];
25122 for (x0
= original_x_pixel
;
25123 glyph
< end
&& x0
>= glyph
->pixel_width
;
25125 x0
-= glyph
->pixel_width
;
25133 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25134 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25135 returns them in row/column units! */
25136 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25137 &object
, &dx
, &dy
, &width
, &height
);
25142 #ifdef HAVE_WINDOW_SYSTEM
25143 if (IMAGEP (object
))
25145 Lisp_Object image_map
, hotspot
;
25146 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25148 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25150 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25152 Lisp_Object area_id
, plist
;
25154 area_id
= XCAR (hotspot
);
25155 /* Could check AREA_ID to see if we enter/leave this hot-spot.
25156 If so, we could look for mouse-enter, mouse-leave
25157 properties in PLIST (and do something...). */
25158 hotspot
= XCDR (hotspot
);
25159 if (CONSP (hotspot
)
25160 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25162 pointer
= Fplist_get (plist
, Qpointer
);
25163 if (NILP (pointer
))
25165 help
= Fplist_get (plist
, Qhelp_echo
);
25168 help_echo_string
= help
;
25169 /* Is this correct? ++kfs */
25170 XSETWINDOW (help_echo_window
, w
);
25171 help_echo_object
= w
->buffer
;
25172 help_echo_pos
= charpos
;
25176 if (NILP (pointer
))
25177 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25179 #endif /* HAVE_WINDOW_SYSTEM */
25181 if (STRINGP (string
))
25183 pos
= make_number (charpos
);
25184 /* If we're on a string with `help-echo' text property, arrange
25185 for the help to be displayed. This is done by setting the
25186 global variable help_echo_string to the help string. */
25189 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25192 help_echo_string
= help
;
25193 XSETWINDOW (help_echo_window
, w
);
25194 help_echo_object
= string
;
25195 help_echo_pos
= charpos
;
25199 #ifdef HAVE_WINDOW_SYSTEM
25200 if (FRAME_WINDOW_P (f
))
25202 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25203 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25204 if (NILP (pointer
))
25205 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25207 /* Change the mouse pointer according to what is under X/Y. */
25209 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25212 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25213 if (!KEYMAPP (map
))
25214 map
= Fget_text_property (pos
, Qkeymap
, string
);
25215 if (!KEYMAPP (map
))
25216 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25221 /* Change the mouse face according to what is under X/Y. */
25222 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25223 if (!NILP (mouse_face
)
25224 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25229 struct glyph
* tmp_glyph
;
25233 int total_pixel_width
;
25234 EMACS_INT begpos
, endpos
, ignore
;
25238 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25239 Qmouse_face
, string
, Qnil
);
25245 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25247 endpos
= SCHARS (string
);
25251 /* Calculate the glyph position GPOS of GLYPH in the
25252 displayed string, relative to the beginning of the
25253 highlighted part of the string.
25255 Note: GPOS is different from CHARPOS. CHARPOS is the
25256 position of GLYPH in the internal string object. A mode
25257 line string format has structures which are converted to
25258 a flattened string by the Emacs Lisp interpreter. The
25259 internal string is an element of those structures. The
25260 displayed string is the flattened string. */
25261 tmp_glyph
= row_start_glyph
;
25262 while (tmp_glyph
< glyph
25263 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25264 && begpos
<= tmp_glyph
->charpos
25265 && tmp_glyph
->charpos
< endpos
)))
25267 gpos
= glyph
- tmp_glyph
;
25269 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25270 the highlighted part of the displayed string to which
25271 GLYPH belongs. Note: GSEQ_LENGTH is different from
25272 SCHARS (STRING), because the latter returns the length of
25273 the internal string. */
25274 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25276 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25277 && begpos
<= tmp_glyph
->charpos
25278 && tmp_glyph
->charpos
< endpos
));
25281 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25283 /* Calculate the total pixel width of all the glyphs between
25284 the beginning of the highlighted area and GLYPH. */
25285 total_pixel_width
= 0;
25286 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25287 total_pixel_width
+= tmp_glyph
->pixel_width
;
25289 /* Pre calculation of re-rendering position. Note: X is in
25290 column units here, after the call to mode_line_string or
25291 marginal_area_string. */
25293 vpos
= (area
== ON_MODE_LINE
25294 ? (w
->current_matrix
)->nrows
- 1
25297 /* If GLYPH's position is included in the region that is
25298 already drawn in mouse face, we have nothing to do. */
25299 if ( EQ (window
, hlinfo
->mouse_face_window
)
25300 && (!row
->reversed_p
25301 ? (hlinfo
->mouse_face_beg_col
<= hpos
25302 && hpos
< hlinfo
->mouse_face_end_col
)
25303 /* In R2L rows we swap BEG and END, see below. */
25304 : (hlinfo
->mouse_face_end_col
<= hpos
25305 && hpos
< hlinfo
->mouse_face_beg_col
))
25306 && hlinfo
->mouse_face_beg_row
== vpos
)
25309 if (clear_mouse_face (hlinfo
))
25310 cursor
= No_Cursor
;
25312 if (!row
->reversed_p
)
25314 hlinfo
->mouse_face_beg_col
= hpos
;
25315 hlinfo
->mouse_face_beg_x
= original_x_pixel
25316 - (total_pixel_width
+ dx
);
25317 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25318 hlinfo
->mouse_face_end_x
= 0;
25322 /* In R2L rows, show_mouse_face expects BEG and END
25323 coordinates to be swapped. */
25324 hlinfo
->mouse_face_end_col
= hpos
;
25325 hlinfo
->mouse_face_end_x
= original_x_pixel
25326 - (total_pixel_width
+ dx
);
25327 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25328 hlinfo
->mouse_face_beg_x
= 0;
25331 hlinfo
->mouse_face_beg_row
= vpos
;
25332 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25333 hlinfo
->mouse_face_beg_y
= 0;
25334 hlinfo
->mouse_face_end_y
= 0;
25335 hlinfo
->mouse_face_past_end
= 0;
25336 hlinfo
->mouse_face_window
= window
;
25338 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25344 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25346 if (NILP (pointer
))
25349 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25350 clear_mouse_face (hlinfo
);
25352 #ifdef HAVE_WINDOW_SYSTEM
25353 if (FRAME_WINDOW_P (f
))
25354 define_frame_cursor1 (f
, cursor
, pointer
);
25360 Take proper action when the mouse has moved to position X, Y on
25361 frame F as regards highlighting characters that have mouse-face
25362 properties. Also de-highlighting chars where the mouse was before.
25363 X and Y can be negative or out of range. */
25366 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25368 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25369 enum window_part part
;
25370 Lisp_Object window
;
25372 Cursor cursor
= No_Cursor
;
25373 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25376 /* When a menu is active, don't highlight because this looks odd. */
25377 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25378 if (popup_activated ())
25382 if (NILP (Vmouse_highlight
)
25383 || !f
->glyphs_initialized_p
25384 || f
->pointer_invisible
)
25387 hlinfo
->mouse_face_mouse_x
= x
;
25388 hlinfo
->mouse_face_mouse_y
= y
;
25389 hlinfo
->mouse_face_mouse_frame
= f
;
25391 if (hlinfo
->mouse_face_defer
)
25394 if (gc_in_progress
)
25396 hlinfo
->mouse_face_deferred_gc
= 1;
25400 /* Which window is that in? */
25401 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
25403 /* If we were displaying active text in another window, clear that.
25404 Also clear if we move out of text area in same window. */
25405 if (! EQ (window
, hlinfo
->mouse_face_window
)
25406 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
25407 && !NILP (hlinfo
->mouse_face_window
)))
25408 clear_mouse_face (hlinfo
);
25410 /* Not on a window -> return. */
25411 if (!WINDOWP (window
))
25414 /* Reset help_echo_string. It will get recomputed below. */
25415 help_echo_string
= Qnil
;
25417 /* Convert to window-relative pixel coordinates. */
25418 w
= XWINDOW (window
);
25419 frame_to_window_pixel_xy (w
, &x
, &y
);
25421 #ifdef HAVE_WINDOW_SYSTEM
25422 /* Handle tool-bar window differently since it doesn't display a
25424 if (EQ (window
, f
->tool_bar_window
))
25426 note_tool_bar_highlight (f
, x
, y
);
25431 /* Mouse is on the mode, header line or margin? */
25432 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
25433 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
25435 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
25439 #ifdef HAVE_WINDOW_SYSTEM
25440 if (part
== ON_VERTICAL_BORDER
)
25442 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25443 help_echo_string
= build_string ("drag-mouse-1: resize");
25445 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
25446 || part
== ON_SCROLL_BAR
)
25447 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25449 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25452 /* Are we in a window whose display is up to date?
25453 And verify the buffer's text has not changed. */
25454 b
= XBUFFER (w
->buffer
);
25455 if (part
== ON_TEXT
25456 && EQ (w
->window_end_valid
, w
->buffer
)
25457 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
25458 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
25460 int hpos
, vpos
, i
, dx
, dy
, area
;
25462 struct glyph
*glyph
;
25463 Lisp_Object object
;
25464 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
25465 Lisp_Object
*overlay_vec
= NULL
;
25467 struct buffer
*obuf
;
25468 EMACS_INT obegv
, ozv
;
25471 /* Find the glyph under X/Y. */
25472 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
25474 #ifdef HAVE_WINDOW_SYSTEM
25475 /* Look for :pointer property on image. */
25476 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25478 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25479 if (img
!= NULL
&& IMAGEP (img
->spec
))
25481 Lisp_Object image_map
, hotspot
;
25482 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
25484 && (hotspot
= find_hot_spot (image_map
,
25485 glyph
->slice
.img
.x
+ dx
,
25486 glyph
->slice
.img
.y
+ dy
),
25488 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25490 Lisp_Object area_id
, plist
;
25492 area_id
= XCAR (hotspot
);
25493 /* Could check AREA_ID to see if we enter/leave this hot-spot.
25494 If so, we could look for mouse-enter, mouse-leave
25495 properties in PLIST (and do something...). */
25496 hotspot
= XCDR (hotspot
);
25497 if (CONSP (hotspot
)
25498 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25500 pointer
= Fplist_get (plist
, Qpointer
);
25501 if (NILP (pointer
))
25503 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
25504 if (!NILP (help_echo_string
))
25506 help_echo_window
= window
;
25507 help_echo_object
= glyph
->object
;
25508 help_echo_pos
= glyph
->charpos
;
25512 if (NILP (pointer
))
25513 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
25516 #endif /* HAVE_WINDOW_SYSTEM */
25518 /* Clear mouse face if X/Y not over text. */
25520 || area
!= TEXT_AREA
25521 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
25522 /* Glyph's OBJECT is an integer for glyphs inserted by the
25523 display engine for its internal purposes, like truncation
25524 and continuation glyphs and blanks beyond the end of
25525 line's text on text terminals. If we are over such a
25526 glyph, we are not over any text. */
25527 || INTEGERP (glyph
->object
)
25528 /* R2L rows have a stretch glyph at their front, which
25529 stands for no text, whereas L2R rows have no glyphs at
25530 all beyond the end of text. Treat such stretch glyphs
25531 like we do with NULL glyphs in L2R rows. */
25532 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
25533 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
25534 && glyph
->type
== STRETCH_GLYPH
25535 && glyph
->avoid_cursor_p
))
25537 if (clear_mouse_face (hlinfo
))
25538 cursor
= No_Cursor
;
25539 #ifdef HAVE_WINDOW_SYSTEM
25540 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25542 if (area
!= TEXT_AREA
)
25543 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25545 pointer
= Vvoid_text_area_pointer
;
25551 pos
= glyph
->charpos
;
25552 object
= glyph
->object
;
25553 if (!STRINGP (object
) && !BUFFERP (object
))
25556 /* If we get an out-of-range value, return now; avoid an error. */
25557 if (BUFFERP (object
) && pos
> BUF_Z (b
))
25560 /* Make the window's buffer temporarily current for
25561 overlays_at and compute_char_face. */
25562 obuf
= current_buffer
;
25563 current_buffer
= b
;
25569 /* Is this char mouse-active or does it have help-echo? */
25570 position
= make_number (pos
);
25572 if (BUFFERP (object
))
25574 /* Put all the overlays we want in a vector in overlay_vec. */
25575 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
25576 /* Sort overlays into increasing priority order. */
25577 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
25582 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
25585 cursor
= No_Cursor
;
25587 /* Check mouse-face highlighting. */
25589 /* If there exists an overlay with mouse-face overlapping
25590 the one we are currently highlighting, we have to
25591 check if we enter the overlapping overlay, and then
25592 highlight only that. */
25593 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
25594 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
25596 /* Find the highest priority overlay with a mouse-face. */
25598 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
25600 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
25601 if (!NILP (mouse_face
))
25602 overlay
= overlay_vec
[i
];
25605 /* If we're highlighting the same overlay as before, there's
25606 no need to do that again. */
25607 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
25608 goto check_help_echo
;
25609 hlinfo
->mouse_face_overlay
= overlay
;
25611 /* Clear the display of the old active region, if any. */
25612 if (clear_mouse_face (hlinfo
))
25613 cursor
= No_Cursor
;
25615 /* If no overlay applies, get a text property. */
25616 if (NILP (overlay
))
25617 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
25619 /* Next, compute the bounds of the mouse highlighting and
25621 if (!NILP (mouse_face
) && STRINGP (object
))
25623 /* The mouse-highlighting comes from a display string
25624 with a mouse-face. */
25628 b
= Fprevious_single_property_change
25629 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
25630 e
= Fnext_single_property_change
25631 (position
, Qmouse_face
, object
, Qnil
);
25633 b
= make_number (0);
25635 e
= make_number (SCHARS (object
) - 1);
25636 mouse_face_from_string_pos (w
, hlinfo
, object
,
25637 XINT (b
), XINT (e
));
25638 hlinfo
->mouse_face_past_end
= 0;
25639 hlinfo
->mouse_face_window
= window
;
25640 hlinfo
->mouse_face_face_id
25641 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
25642 glyph
->face_id
, 1);
25643 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25644 cursor
= No_Cursor
;
25648 /* The mouse-highlighting, if any, comes from an overlay
25649 or text property in the buffer. */
25650 Lisp_Object buffer
, display_string
;
25652 if (STRINGP (object
))
25654 /* If we are on a display string with no mouse-face,
25655 check if the text under it has one. */
25656 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
25657 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25658 pos
= string_buffer_position (w
, object
, start
);
25661 mouse_face
= get_char_property_and_overlay
25662 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
25663 buffer
= w
->buffer
;
25664 display_string
= object
;
25670 display_string
= Qnil
;
25673 if (!NILP (mouse_face
))
25675 Lisp_Object before
, after
;
25676 Lisp_Object before_string
, after_string
;
25677 /* To correctly find the limits of mouse highlight
25678 in a bidi-reordered buffer, we must not use the
25679 optimization of limiting the search in
25680 previous-single-property-change and
25681 next-single-property-change, because
25682 rows_from_pos_range needs the real start and end
25683 positions to DTRT in this case. That's because
25684 the first row visible in a window does not
25685 necessarily display the character whose position
25686 is the smallest. */
25688 NILP (XBUFFER (buffer
)->bidi_display_reordering
)
25689 ? Fmarker_position (w
->start
)
25692 NILP (XBUFFER (buffer
)->bidi_display_reordering
)
25693 ? make_number (BUF_Z (XBUFFER (buffer
))
25694 - XFASTINT (w
->window_end_pos
))
25697 if (NILP (overlay
))
25699 /* Handle the text property case. */
25700 before
= Fprevious_single_property_change
25701 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
25702 after
= Fnext_single_property_change
25703 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
25704 before_string
= after_string
= Qnil
;
25708 /* Handle the overlay case. */
25709 before
= Foverlay_start (overlay
);
25710 after
= Foverlay_end (overlay
);
25711 before_string
= Foverlay_get (overlay
, Qbefore_string
);
25712 after_string
= Foverlay_get (overlay
, Qafter_string
);
25714 if (!STRINGP (before_string
)) before_string
= Qnil
;
25715 if (!STRINGP (after_string
)) after_string
= Qnil
;
25718 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
25721 before_string
, after_string
,
25723 cursor
= No_Cursor
;
25730 /* Look for a `help-echo' property. */
25731 if (NILP (help_echo_string
)) {
25732 Lisp_Object help
, overlay
;
25734 /* Check overlays first. */
25735 help
= overlay
= Qnil
;
25736 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
25738 overlay
= overlay_vec
[i
];
25739 help
= Foverlay_get (overlay
, Qhelp_echo
);
25744 help_echo_string
= help
;
25745 help_echo_window
= window
;
25746 help_echo_object
= overlay
;
25747 help_echo_pos
= pos
;
25751 Lisp_Object object
= glyph
->object
;
25752 EMACS_INT charpos
= glyph
->charpos
;
25754 /* Try text properties. */
25755 if (STRINGP (object
)
25757 && charpos
< SCHARS (object
))
25759 help
= Fget_text_property (make_number (charpos
),
25760 Qhelp_echo
, object
);
25763 /* If the string itself doesn't specify a help-echo,
25764 see if the buffer text ``under'' it does. */
25765 struct glyph_row
*r
25766 = MATRIX_ROW (w
->current_matrix
, vpos
);
25767 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25768 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
25771 help
= Fget_char_property (make_number (pos
),
25772 Qhelp_echo
, w
->buffer
);
25776 object
= w
->buffer
;
25781 else if (BUFFERP (object
)
25784 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
25789 help_echo_string
= help
;
25790 help_echo_window
= window
;
25791 help_echo_object
= object
;
25792 help_echo_pos
= charpos
;
25797 #ifdef HAVE_WINDOW_SYSTEM
25798 /* Look for a `pointer' property. */
25799 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25801 /* Check overlays first. */
25802 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
25803 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
25805 if (NILP (pointer
))
25807 Lisp_Object object
= glyph
->object
;
25808 EMACS_INT charpos
= glyph
->charpos
;
25810 /* Try text properties. */
25811 if (STRINGP (object
)
25813 && charpos
< SCHARS (object
))
25815 pointer
= Fget_text_property (make_number (charpos
),
25817 if (NILP (pointer
))
25819 /* If the string itself doesn't specify a pointer,
25820 see if the buffer text ``under'' it does. */
25821 struct glyph_row
*r
25822 = MATRIX_ROW (w
->current_matrix
, vpos
);
25823 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25824 EMACS_INT pos
= string_buffer_position (w
, object
,
25827 pointer
= Fget_char_property (make_number (pos
),
25828 Qpointer
, w
->buffer
);
25831 else if (BUFFERP (object
)
25834 pointer
= Fget_text_property (make_number (charpos
),
25838 #endif /* HAVE_WINDOW_SYSTEM */
25842 current_buffer
= obuf
;
25847 #ifdef HAVE_WINDOW_SYSTEM
25848 if (FRAME_WINDOW_P (f
))
25849 define_frame_cursor1 (f
, cursor
, pointer
);
25851 /* This is here to prevent a compiler error, about "label at end of
25852 compound statement". */
25859 Clear any mouse-face on window W. This function is part of the
25860 redisplay interface, and is called from try_window_id and similar
25861 functions to ensure the mouse-highlight is off. */
25864 x_clear_window_mouse_face (struct window
*w
)
25866 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25867 Lisp_Object window
;
25870 XSETWINDOW (window
, w
);
25871 if (EQ (window
, hlinfo
->mouse_face_window
))
25872 clear_mouse_face (hlinfo
);
25878 Just discard the mouse face information for frame F, if any.
25879 This is used when the size of F is changed. */
25882 cancel_mouse_face (struct frame
*f
)
25884 Lisp_Object window
;
25885 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25887 window
= hlinfo
->mouse_face_window
;
25888 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
25890 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25891 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25892 hlinfo
->mouse_face_window
= Qnil
;
25898 /***********************************************************************
25900 ***********************************************************************/
25902 #ifdef HAVE_WINDOW_SYSTEM
25904 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
25905 which intersects rectangle R. R is in window-relative coordinates. */
25908 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
25909 enum glyph_row_area area
)
25911 struct glyph
*first
= row
->glyphs
[area
];
25912 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
25913 struct glyph
*last
;
25914 int first_x
, start_x
, x
;
25916 if (area
== TEXT_AREA
&& row
->fill_line_p
)
25917 /* If row extends face to end of line write the whole line. */
25918 draw_glyphs (w
, 0, row
, area
,
25919 0, row
->used
[area
],
25920 DRAW_NORMAL_TEXT
, 0);
25923 /* Set START_X to the window-relative start position for drawing glyphs of
25924 AREA. The first glyph of the text area can be partially visible.
25925 The first glyphs of other areas cannot. */
25926 start_x
= window_box_left_offset (w
, area
);
25928 if (area
== TEXT_AREA
)
25931 /* Find the first glyph that must be redrawn. */
25933 && x
+ first
->pixel_width
< r
->x
)
25935 x
+= first
->pixel_width
;
25939 /* Find the last one. */
25943 && x
< r
->x
+ r
->width
)
25945 x
+= last
->pixel_width
;
25951 draw_glyphs (w
, first_x
- start_x
, row
, area
,
25952 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
25953 DRAW_NORMAL_TEXT
, 0);
25958 /* Redraw the parts of the glyph row ROW on window W intersecting
25959 rectangle R. R is in window-relative coordinates. Value is
25960 non-zero if mouse-face was overwritten. */
25963 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
25965 xassert (row
->enabled_p
);
25967 if (row
->mode_line_p
|| w
->pseudo_window_p
)
25968 draw_glyphs (w
, 0, row
, TEXT_AREA
,
25969 0, row
->used
[TEXT_AREA
],
25970 DRAW_NORMAL_TEXT
, 0);
25973 if (row
->used
[LEFT_MARGIN_AREA
])
25974 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
25975 if (row
->used
[TEXT_AREA
])
25976 expose_area (w
, row
, r
, TEXT_AREA
);
25977 if (row
->used
[RIGHT_MARGIN_AREA
])
25978 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
25979 draw_row_fringe_bitmaps (w
, row
);
25982 return row
->mouse_face_p
;
25986 /* Redraw those parts of glyphs rows during expose event handling that
25987 overlap other rows. Redrawing of an exposed line writes over parts
25988 of lines overlapping that exposed line; this function fixes that.
25990 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
25991 row in W's current matrix that is exposed and overlaps other rows.
25992 LAST_OVERLAPPING_ROW is the last such row. */
25995 expose_overlaps (struct window
*w
,
25996 struct glyph_row
*first_overlapping_row
,
25997 struct glyph_row
*last_overlapping_row
,
26000 struct glyph_row
*row
;
26002 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26003 if (row
->overlapping_p
)
26005 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26008 if (row
->used
[LEFT_MARGIN_AREA
])
26009 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26011 if (row
->used
[TEXT_AREA
])
26012 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26014 if (row
->used
[RIGHT_MARGIN_AREA
])
26015 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26021 /* Return non-zero if W's cursor intersects rectangle R. */
26024 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26026 XRectangle cr
, result
;
26027 struct glyph
*cursor_glyph
;
26028 struct glyph_row
*row
;
26030 if (w
->phys_cursor
.vpos
>= 0
26031 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26032 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26034 && row
->cursor_in_fringe_p
)
26036 /* Cursor is in the fringe. */
26037 cr
.x
= window_box_right_offset (w
,
26038 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26039 ? RIGHT_MARGIN_AREA
26042 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26043 cr
.height
= row
->height
;
26044 return x_intersect_rectangles (&cr
, r
, &result
);
26047 cursor_glyph
= get_phys_cursor_glyph (w
);
26050 /* r is relative to W's box, but w->phys_cursor.x is relative
26051 to left edge of W's TEXT area. Adjust it. */
26052 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26053 cr
.y
= w
->phys_cursor
.y
;
26054 cr
.width
= cursor_glyph
->pixel_width
;
26055 cr
.height
= w
->phys_cursor_height
;
26056 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26057 I assume the effect is the same -- and this is portable. */
26058 return x_intersect_rectangles (&cr
, r
, &result
);
26060 /* If we don't understand the format, pretend we're not in the hot-spot. */
26066 Draw a vertical window border to the right of window W if W doesn't
26067 have vertical scroll bars. */
26070 x_draw_vertical_border (struct window
*w
)
26072 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26074 /* We could do better, if we knew what type of scroll-bar the adjacent
26075 windows (on either side) have... But we don't :-(
26076 However, I think this works ok. ++KFS 2003-04-25 */
26078 /* Redraw borders between horizontally adjacent windows. Don't
26079 do it for frames with vertical scroll bars because either the
26080 right scroll bar of a window, or the left scroll bar of its
26081 neighbor will suffice as a border. */
26082 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26085 if (!WINDOW_RIGHTMOST_P (w
)
26086 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26088 int x0
, x1
, y0
, y1
;
26090 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26093 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26096 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26098 else if (!WINDOW_LEFTMOST_P (w
)
26099 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26101 int x0
, x1
, y0
, y1
;
26103 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26106 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26109 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26114 /* Redraw the part of window W intersection rectangle FR. Pixel
26115 coordinates in FR are frame-relative. Call this function with
26116 input blocked. Value is non-zero if the exposure overwrites
26120 expose_window (struct window
*w
, XRectangle
*fr
)
26122 struct frame
*f
= XFRAME (w
->frame
);
26124 int mouse_face_overwritten_p
= 0;
26126 /* If window is not yet fully initialized, do nothing. This can
26127 happen when toolkit scroll bars are used and a window is split.
26128 Reconfiguring the scroll bar will generate an expose for a newly
26130 if (w
->current_matrix
== NULL
)
26133 /* When we're currently updating the window, display and current
26134 matrix usually don't agree. Arrange for a thorough display
26136 if (w
== updated_window
)
26138 SET_FRAME_GARBAGED (f
);
26142 /* Frame-relative pixel rectangle of W. */
26143 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26144 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26145 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26146 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26148 if (x_intersect_rectangles (fr
, &wr
, &r
))
26150 int yb
= window_text_bottom_y (w
);
26151 struct glyph_row
*row
;
26152 int cursor_cleared_p
;
26153 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26155 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26156 r
.x
, r
.y
, r
.width
, r
.height
));
26158 /* Convert to window coordinates. */
26159 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26160 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26162 /* Turn off the cursor. */
26163 if (!w
->pseudo_window_p
26164 && phys_cursor_in_rect_p (w
, &r
))
26166 x_clear_cursor (w
);
26167 cursor_cleared_p
= 1;
26170 cursor_cleared_p
= 0;
26172 /* Update lines intersecting rectangle R. */
26173 first_overlapping_row
= last_overlapping_row
= NULL
;
26174 for (row
= w
->current_matrix
->rows
;
26179 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26181 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26182 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26183 || (r
.y
>= y0
&& r
.y
< y1
)
26184 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26186 /* A header line may be overlapping, but there is no need
26187 to fix overlapping areas for them. KFS 2005-02-12 */
26188 if (row
->overlapping_p
&& !row
->mode_line_p
)
26190 if (first_overlapping_row
== NULL
)
26191 first_overlapping_row
= row
;
26192 last_overlapping_row
= row
;
26196 if (expose_line (w
, row
, &r
))
26197 mouse_face_overwritten_p
= 1;
26200 else if (row
->overlapping_p
)
26202 /* We must redraw a row overlapping the exposed area. */
26204 ? y0
+ row
->phys_height
> r
.y
26205 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26207 if (first_overlapping_row
== NULL
)
26208 first_overlapping_row
= row
;
26209 last_overlapping_row
= row
;
26217 /* Display the mode line if there is one. */
26218 if (WINDOW_WANTS_MODELINE_P (w
)
26219 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26221 && row
->y
< r
.y
+ r
.height
)
26223 if (expose_line (w
, row
, &r
))
26224 mouse_face_overwritten_p
= 1;
26227 if (!w
->pseudo_window_p
)
26229 /* Fix the display of overlapping rows. */
26230 if (first_overlapping_row
)
26231 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26234 /* Draw border between windows. */
26235 x_draw_vertical_border (w
);
26237 /* Turn the cursor on again. */
26238 if (cursor_cleared_p
)
26239 update_window_cursor (w
, 1);
26243 return mouse_face_overwritten_p
;
26248 /* Redraw (parts) of all windows in the window tree rooted at W that
26249 intersect R. R contains frame pixel coordinates. Value is
26250 non-zero if the exposure overwrites mouse-face. */
26253 expose_window_tree (struct window
*w
, XRectangle
*r
)
26255 struct frame
*f
= XFRAME (w
->frame
);
26256 int mouse_face_overwritten_p
= 0;
26258 while (w
&& !FRAME_GARBAGED_P (f
))
26260 if (!NILP (w
->hchild
))
26261 mouse_face_overwritten_p
26262 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26263 else if (!NILP (w
->vchild
))
26264 mouse_face_overwritten_p
26265 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26267 mouse_face_overwritten_p
|= expose_window (w
, r
);
26269 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26272 return mouse_face_overwritten_p
;
26277 Redisplay an exposed area of frame F. X and Y are the upper-left
26278 corner of the exposed rectangle. W and H are width and height of
26279 the exposed area. All are pixel values. W or H zero means redraw
26280 the entire frame. */
26283 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26286 int mouse_face_overwritten_p
= 0;
26288 TRACE ((stderr
, "expose_frame "));
26290 /* No need to redraw if frame will be redrawn soon. */
26291 if (FRAME_GARBAGED_P (f
))
26293 TRACE ((stderr
, " garbaged\n"));
26297 /* If basic faces haven't been realized yet, there is no point in
26298 trying to redraw anything. This can happen when we get an expose
26299 event while Emacs is starting, e.g. by moving another window. */
26300 if (FRAME_FACE_CACHE (f
) == NULL
26301 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26303 TRACE ((stderr
, " no faces\n"));
26307 if (w
== 0 || h
== 0)
26310 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26311 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26321 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26322 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26324 if (WINDOWP (f
->tool_bar_window
))
26325 mouse_face_overwritten_p
26326 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26328 #ifdef HAVE_X_WINDOWS
26330 #ifndef USE_X_TOOLKIT
26331 if (WINDOWP (f
->menu_bar_window
))
26332 mouse_face_overwritten_p
26333 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26334 #endif /* not USE_X_TOOLKIT */
26338 /* Some window managers support a focus-follows-mouse style with
26339 delayed raising of frames. Imagine a partially obscured frame,
26340 and moving the mouse into partially obscured mouse-face on that
26341 frame. The visible part of the mouse-face will be highlighted,
26342 then the WM raises the obscured frame. With at least one WM, KDE
26343 2.1, Emacs is not getting any event for the raising of the frame
26344 (even tried with SubstructureRedirectMask), only Expose events.
26345 These expose events will draw text normally, i.e. not
26346 highlighted. Which means we must redo the highlight here.
26347 Subsume it under ``we love X''. --gerd 2001-08-15 */
26348 /* Included in Windows version because Windows most likely does not
26349 do the right thing if any third party tool offers
26350 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26351 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26353 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26354 if (f
== hlinfo
->mouse_face_mouse_frame
)
26356 int x
= hlinfo
->mouse_face_mouse_x
;
26357 int y
= hlinfo
->mouse_face_mouse_y
;
26358 clear_mouse_face (hlinfo
);
26359 note_mouse_highlight (f
, x
, y
);
26366 Determine the intersection of two rectangles R1 and R2. Return
26367 the intersection in *RESULT. Value is non-zero if RESULT is not
26371 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26373 XRectangle
*left
, *right
;
26374 XRectangle
*upper
, *lower
;
26375 int intersection_p
= 0;
26377 /* Rearrange so that R1 is the left-most rectangle. */
26379 left
= r1
, right
= r2
;
26381 left
= r2
, right
= r1
;
26383 /* X0 of the intersection is right.x0, if this is inside R1,
26384 otherwise there is no intersection. */
26385 if (right
->x
<= left
->x
+ left
->width
)
26387 result
->x
= right
->x
;
26389 /* The right end of the intersection is the minimum of the
26390 the right ends of left and right. */
26391 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26394 /* Same game for Y. */
26396 upper
= r1
, lower
= r2
;
26398 upper
= r2
, lower
= r1
;
26400 /* The upper end of the intersection is lower.y0, if this is inside
26401 of upper. Otherwise, there is no intersection. */
26402 if (lower
->y
<= upper
->y
+ upper
->height
)
26404 result
->y
= lower
->y
;
26406 /* The lower end of the intersection is the minimum of the lower
26407 ends of upper and lower. */
26408 result
->height
= (min (lower
->y
+ lower
->height
,
26409 upper
->y
+ upper
->height
)
26411 intersection_p
= 1;
26415 return intersection_p
;
26418 #endif /* HAVE_WINDOW_SYSTEM */
26421 /***********************************************************************
26423 ***********************************************************************/
26426 syms_of_xdisp (void)
26428 Vwith_echo_area_save_vector
= Qnil
;
26429 staticpro (&Vwith_echo_area_save_vector
);
26431 Vmessage_stack
= Qnil
;
26432 staticpro (&Vmessage_stack
);
26434 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
26435 staticpro (&Qinhibit_redisplay
);
26437 message_dolog_marker1
= Fmake_marker ();
26438 staticpro (&message_dolog_marker1
);
26439 message_dolog_marker2
= Fmake_marker ();
26440 staticpro (&message_dolog_marker2
);
26441 message_dolog_marker3
= Fmake_marker ();
26442 staticpro (&message_dolog_marker3
);
26445 defsubr (&Sdump_frame_glyph_matrix
);
26446 defsubr (&Sdump_glyph_matrix
);
26447 defsubr (&Sdump_glyph_row
);
26448 defsubr (&Sdump_tool_bar_row
);
26449 defsubr (&Strace_redisplay
);
26450 defsubr (&Strace_to_stderr
);
26452 #ifdef HAVE_WINDOW_SYSTEM
26453 defsubr (&Stool_bar_lines_needed
);
26454 defsubr (&Slookup_image_map
);
26456 defsubr (&Sformat_mode_line
);
26457 defsubr (&Sinvisible_p
);
26458 defsubr (&Scurrent_bidi_paragraph_direction
);
26460 staticpro (&Qmenu_bar_update_hook
);
26461 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
26463 staticpro (&Qoverriding_terminal_local_map
);
26464 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
26466 staticpro (&Qoverriding_local_map
);
26467 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
26469 staticpro (&Qwindow_scroll_functions
);
26470 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
26472 staticpro (&Qwindow_text_change_functions
);
26473 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
26475 staticpro (&Qredisplay_end_trigger_functions
);
26476 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
26478 staticpro (&Qinhibit_point_motion_hooks
);
26479 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
26481 Qeval
= intern_c_string ("eval");
26482 staticpro (&Qeval
);
26484 QCdata
= intern_c_string (":data");
26485 staticpro (&QCdata
);
26486 Qdisplay
= intern_c_string ("display");
26487 staticpro (&Qdisplay
);
26488 Qspace_width
= intern_c_string ("space-width");
26489 staticpro (&Qspace_width
);
26490 Qraise
= intern_c_string ("raise");
26491 staticpro (&Qraise
);
26492 Qslice
= intern_c_string ("slice");
26493 staticpro (&Qslice
);
26494 Qspace
= intern_c_string ("space");
26495 staticpro (&Qspace
);
26496 Qmargin
= intern_c_string ("margin");
26497 staticpro (&Qmargin
);
26498 Qpointer
= intern_c_string ("pointer");
26499 staticpro (&Qpointer
);
26500 Qleft_margin
= intern_c_string ("left-margin");
26501 staticpro (&Qleft_margin
);
26502 Qright_margin
= intern_c_string ("right-margin");
26503 staticpro (&Qright_margin
);
26504 Qcenter
= intern_c_string ("center");
26505 staticpro (&Qcenter
);
26506 Qline_height
= intern_c_string ("line-height");
26507 staticpro (&Qline_height
);
26508 QCalign_to
= intern_c_string (":align-to");
26509 staticpro (&QCalign_to
);
26510 QCrelative_width
= intern_c_string (":relative-width");
26511 staticpro (&QCrelative_width
);
26512 QCrelative_height
= intern_c_string (":relative-height");
26513 staticpro (&QCrelative_height
);
26514 QCeval
= intern_c_string (":eval");
26515 staticpro (&QCeval
);
26516 QCpropertize
= intern_c_string (":propertize");
26517 staticpro (&QCpropertize
);
26518 QCfile
= intern_c_string (":file");
26519 staticpro (&QCfile
);
26520 Qfontified
= intern_c_string ("fontified");
26521 staticpro (&Qfontified
);
26522 Qfontification_functions
= intern_c_string ("fontification-functions");
26523 staticpro (&Qfontification_functions
);
26524 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
26525 staticpro (&Qtrailing_whitespace
);
26526 Qescape_glyph
= intern_c_string ("escape-glyph");
26527 staticpro (&Qescape_glyph
);
26528 Qnobreak_space
= intern_c_string ("nobreak-space");
26529 staticpro (&Qnobreak_space
);
26530 Qimage
= intern_c_string ("image");
26531 staticpro (&Qimage
);
26532 Qtext
= intern_c_string ("text");
26533 staticpro (&Qtext
);
26534 Qboth
= intern_c_string ("both");
26535 staticpro (&Qboth
);
26536 Qboth_horiz
= intern_c_string ("both-horiz");
26537 staticpro (&Qboth_horiz
);
26538 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
26539 staticpro (&Qtext_image_horiz
);
26540 QCmap
= intern_c_string (":map");
26541 staticpro (&QCmap
);
26542 QCpointer
= intern_c_string (":pointer");
26543 staticpro (&QCpointer
);
26544 Qrect
= intern_c_string ("rect");
26545 staticpro (&Qrect
);
26546 Qcircle
= intern_c_string ("circle");
26547 staticpro (&Qcircle
);
26548 Qpoly
= intern_c_string ("poly");
26549 staticpro (&Qpoly
);
26550 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
26551 staticpro (&Qmessage_truncate_lines
);
26552 Qgrow_only
= intern_c_string ("grow-only");
26553 staticpro (&Qgrow_only
);
26554 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
26555 staticpro (&Qinhibit_menubar_update
);
26556 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
26557 staticpro (&Qinhibit_eval_during_redisplay
);
26558 Qposition
= intern_c_string ("position");
26559 staticpro (&Qposition
);
26560 Qbuffer_position
= intern_c_string ("buffer-position");
26561 staticpro (&Qbuffer_position
);
26562 Qobject
= intern_c_string ("object");
26563 staticpro (&Qobject
);
26564 Qbar
= intern_c_string ("bar");
26566 Qhbar
= intern_c_string ("hbar");
26567 staticpro (&Qhbar
);
26568 Qbox
= intern_c_string ("box");
26570 Qhollow
= intern_c_string ("hollow");
26571 staticpro (&Qhollow
);
26572 Qhand
= intern_c_string ("hand");
26573 staticpro (&Qhand
);
26574 Qarrow
= intern_c_string ("arrow");
26575 staticpro (&Qarrow
);
26576 Qtext
= intern_c_string ("text");
26577 staticpro (&Qtext
);
26578 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
26579 staticpro (&Qrisky_local_variable
);
26580 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
26581 staticpro (&Qinhibit_free_realized_faces
);
26583 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
26584 Fcons (intern_c_string ("void-variable"), Qnil
)),
26586 staticpro (&list_of_error
);
26588 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
26589 staticpro (&Qlast_arrow_position
);
26590 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
26591 staticpro (&Qlast_arrow_string
);
26593 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
26594 staticpro (&Qoverlay_arrow_string
);
26595 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
26596 staticpro (&Qoverlay_arrow_bitmap
);
26598 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
26599 staticpro (&echo_buffer
[0]);
26600 staticpro (&echo_buffer
[1]);
26602 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
26603 staticpro (&echo_area_buffer
[0]);
26604 staticpro (&echo_area_buffer
[1]);
26606 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
26607 staticpro (&Vmessages_buffer_name
);
26609 mode_line_proptrans_alist
= Qnil
;
26610 staticpro (&mode_line_proptrans_alist
);
26611 mode_line_string_list
= Qnil
;
26612 staticpro (&mode_line_string_list
);
26613 mode_line_string_face
= Qnil
;
26614 staticpro (&mode_line_string_face
);
26615 mode_line_string_face_prop
= Qnil
;
26616 staticpro (&mode_line_string_face_prop
);
26617 Vmode_line_unwind_vector
= Qnil
;
26618 staticpro (&Vmode_line_unwind_vector
);
26620 help_echo_string
= Qnil
;
26621 staticpro (&help_echo_string
);
26622 help_echo_object
= Qnil
;
26623 staticpro (&help_echo_object
);
26624 help_echo_window
= Qnil
;
26625 staticpro (&help_echo_window
);
26626 previous_help_echo_string
= Qnil
;
26627 staticpro (&previous_help_echo_string
);
26628 help_echo_pos
= -1;
26630 Qright_to_left
= intern_c_string ("right-to-left");
26631 staticpro (&Qright_to_left
);
26632 Qleft_to_right
= intern_c_string ("left-to-right");
26633 staticpro (&Qleft_to_right
);
26635 #ifdef HAVE_WINDOW_SYSTEM
26636 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
26637 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
26638 For example, if a block cursor is over a tab, it will be drawn as
26639 wide as that tab on the display. */);
26640 x_stretch_cursor_p
= 0;
26643 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
26644 doc
: /* *Non-nil means highlight trailing whitespace.
26645 The face used for trailing whitespace is `trailing-whitespace'. */);
26646 Vshow_trailing_whitespace
= Qnil
;
26648 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
26649 doc
: /* *Control highlighting of nobreak space and soft hyphen.
26650 A value of t means highlight the character itself (for nobreak space,
26651 use face `nobreak-space').
26652 A value of nil means no highlighting.
26653 Other values mean display the escape glyph followed by an ordinary
26654 space or ordinary hyphen. */);
26655 Vnobreak_char_display
= Qt
;
26657 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
26658 doc
: /* *The pointer shape to show in void text areas.
26659 A value of nil means to show the text pointer. Other options are `arrow',
26660 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
26661 Vvoid_text_area_pointer
= Qarrow
;
26663 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
26664 doc
: /* Non-nil means don't actually do any redisplay.
26665 This is used for internal purposes. */);
26666 Vinhibit_redisplay
= Qnil
;
26668 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
26669 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
26670 Vglobal_mode_string
= Qnil
;
26672 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
26673 doc
: /* Marker for where to display an arrow on top of the buffer text.
26674 This must be the beginning of a line in order to work.
26675 See also `overlay-arrow-string'. */);
26676 Voverlay_arrow_position
= Qnil
;
26678 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
26679 doc
: /* String to display as an arrow in non-window frames.
26680 See also `overlay-arrow-position'. */);
26681 Voverlay_arrow_string
= make_pure_c_string ("=>");
26683 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
26684 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
26685 The symbols on this list are examined during redisplay to determine
26686 where to display overlay arrows. */);
26687 Voverlay_arrow_variable_list
26688 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
26690 DEFVAR_INT ("scroll-step", &scroll_step
,
26691 doc
: /* *The number of lines to try scrolling a window by when point moves out.
26692 If that fails to bring point back on frame, point is centered instead.
26693 If this is zero, point is always centered after it moves off frame.
26694 If you want scrolling to always be a line at a time, you should set
26695 `scroll-conservatively' to a large value rather than set this to 1. */);
26697 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
26698 doc
: /* *Scroll up to this many lines, to bring point back on screen.
26699 If point moves off-screen, redisplay will scroll by up to
26700 `scroll-conservatively' lines in order to bring point just barely
26701 onto the screen again. If that cannot be done, then redisplay
26702 recenters point as usual.
26704 A value of zero means always recenter point if it moves off screen. */);
26705 scroll_conservatively
= 0;
26707 DEFVAR_INT ("scroll-margin", &scroll_margin
,
26708 doc
: /* *Number of lines of margin at the top and bottom of a window.
26709 Recenter the window whenever point gets within this many lines
26710 of the top or bottom of the window. */);
26713 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
26714 doc
: /* Pixels per inch value for non-window system displays.
26715 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
26716 Vdisplay_pixels_per_inch
= make_float (72.0);
26719 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
26722 DEFVAR_LISP ("truncate-partial-width-windows",
26723 &Vtruncate_partial_width_windows
,
26724 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
26725 For an integer value, truncate lines in each window narrower than the
26726 full frame width, provided the window width is less than that integer;
26727 otherwise, respect the value of `truncate-lines'.
26729 For any other non-nil value, truncate lines in all windows that do
26730 not span the full frame width.
26732 A value of nil means to respect the value of `truncate-lines'.
26734 If `word-wrap' is enabled, you might want to reduce this. */);
26735 Vtruncate_partial_width_windows
= make_number (50);
26737 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
26738 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
26739 Any other value means to use the appropriate face, `mode-line',
26740 `header-line', or `menu' respectively. */);
26741 mode_line_inverse_video
= 1;
26743 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
26744 doc
: /* *Maximum buffer size for which line number should be displayed.
26745 If the buffer is bigger than this, the line number does not appear
26746 in the mode line. A value of nil means no limit. */);
26747 Vline_number_display_limit
= Qnil
;
26749 DEFVAR_INT ("line-number-display-limit-width",
26750 &line_number_display_limit_width
,
26751 doc
: /* *Maximum line width (in characters) for line number display.
26752 If the average length of the lines near point is bigger than this, then the
26753 line number may be omitted from the mode line. */);
26754 line_number_display_limit_width
= 200;
26756 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
26757 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
26758 highlight_nonselected_windows
= 0;
26760 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
26761 doc
: /* Non-nil if more than one frame is visible on this display.
26762 Minibuffer-only frames don't count, but iconified frames do.
26763 This variable is not guaranteed to be accurate except while processing
26764 `frame-title-format' and `icon-title-format'. */);
26766 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
26767 doc
: /* Template for displaying the title bar of visible frames.
26768 \(Assuming the window manager supports this feature.)
26770 This variable has the same structure as `mode-line-format', except that
26771 the %c and %l constructs are ignored. It is used only on frames for
26772 which no explicit name has been set \(see `modify-frame-parameters'). */);
26774 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
26775 doc
: /* Template for displaying the title bar of an iconified frame.
26776 \(Assuming the window manager supports this feature.)
26777 This variable has the same structure as `mode-line-format' (which see),
26778 and is used only on frames for which no explicit name has been set
26779 \(see `modify-frame-parameters'). */);
26781 = Vframe_title_format
26782 = pure_cons (intern_c_string ("multiple-frames"),
26783 pure_cons (make_pure_c_string ("%b"),
26784 pure_cons (pure_cons (empty_unibyte_string
,
26785 pure_cons (intern_c_string ("invocation-name"),
26786 pure_cons (make_pure_c_string ("@"),
26787 pure_cons (intern_c_string ("system-name"),
26791 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
26792 doc
: /* Maximum number of lines to keep in the message log buffer.
26793 If nil, disable message logging. If t, log messages but don't truncate
26794 the buffer when it becomes large. */);
26795 Vmessage_log_max
= make_number (100);
26797 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
26798 doc
: /* Functions called before redisplay, if window sizes have changed.
26799 The value should be a list of functions that take one argument.
26800 Just before redisplay, for each frame, if any of its windows have changed
26801 size since the last redisplay, or have been split or deleted,
26802 all the functions in the list are called, with the frame as argument. */);
26803 Vwindow_size_change_functions
= Qnil
;
26805 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
26806 doc
: /* List of functions to call before redisplaying a window with scrolling.
26807 Each function is called with two arguments, the window and its new
26808 display-start position. Note that these functions are also called by
26809 `set-window-buffer'. Also note that the value of `window-end' is not
26810 valid when these functions are called. */);
26811 Vwindow_scroll_functions
= Qnil
;
26813 DEFVAR_LISP ("window-text-change-functions",
26814 &Vwindow_text_change_functions
,
26815 doc
: /* Functions to call in redisplay when text in the window might change. */);
26816 Vwindow_text_change_functions
= Qnil
;
26818 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
26819 doc
: /* Functions called when redisplay of a window reaches the end trigger.
26820 Each function is called with two arguments, the window and the end trigger value.
26821 See `set-window-redisplay-end-trigger'. */);
26822 Vredisplay_end_trigger_functions
= Qnil
;
26824 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
26825 doc
: /* *Non-nil means autoselect window with mouse pointer.
26826 If nil, do not autoselect windows.
26827 A positive number means delay autoselection by that many seconds: a
26828 window is autoselected only after the mouse has remained in that
26829 window for the duration of the delay.
26830 A negative number has a similar effect, but causes windows to be
26831 autoselected only after the mouse has stopped moving. \(Because of
26832 the way Emacs compares mouse events, you will occasionally wait twice
26833 that time before the window gets selected.\)
26834 Any other value means to autoselect window instantaneously when the
26835 mouse pointer enters it.
26837 Autoselection selects the minibuffer only if it is active, and never
26838 unselects the minibuffer if it is active.
26840 When customizing this variable make sure that the actual value of
26841 `focus-follows-mouse' matches the behavior of your window manager. */);
26842 Vmouse_autoselect_window
= Qnil
;
26844 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
26845 doc
: /* *Non-nil means automatically resize tool-bars.
26846 This dynamically changes the tool-bar's height to the minimum height
26847 that is needed to make all tool-bar items visible.
26848 If value is `grow-only', the tool-bar's height is only increased
26849 automatically; to decrease the tool-bar height, use \\[recenter]. */);
26850 Vauto_resize_tool_bars
= Qt
;
26852 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
26853 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
26854 auto_raise_tool_bar_buttons_p
= 1;
26856 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
26857 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
26858 make_cursor_line_fully_visible_p
= 1;
26860 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
26861 doc
: /* *Border below tool-bar in pixels.
26862 If an integer, use it as the height of the border.
26863 If it is one of `internal-border-width' or `border-width', use the
26864 value of the corresponding frame parameter.
26865 Otherwise, no border is added below the tool-bar. */);
26866 Vtool_bar_border
= Qinternal_border_width
;
26868 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
26869 doc
: /* *Margin around tool-bar buttons in pixels.
26870 If an integer, use that for both horizontal and vertical margins.
26871 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
26872 HORZ specifying the horizontal margin, and VERT specifying the
26873 vertical margin. */);
26874 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
26876 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
26877 doc
: /* *Relief thickness of tool-bar buttons. */);
26878 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
26880 DEFVAR_LISP ("tool-bar-style", &Vtool_bar_style
,
26881 doc
: /* *Tool bar style to use.
26883 image - show images only
26884 text - show text only
26885 both - show both, text below image
26886 both-horiz - show text to the right of the image
26887 text-image-horiz - show text to the left of the image
26888 any other - use system default or image if no system default. */);
26889 Vtool_bar_style
= Qnil
;
26891 DEFVAR_INT ("tool-bar-max-label-size", &tool_bar_max_label_size
,
26892 doc
: /* *Maximum number of characters a label can have to be shown.
26893 The tool bar style must also show labels for this to have any effect, see
26894 `tool-bar-style'. */);
26895 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
26897 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
26898 doc
: /* List of functions to call to fontify regions of text.
26899 Each function is called with one argument POS. Functions must
26900 fontify a region starting at POS in the current buffer, and give
26901 fontified regions the property `fontified'. */);
26902 Vfontification_functions
= Qnil
;
26903 Fmake_variable_buffer_local (Qfontification_functions
);
26905 DEFVAR_BOOL ("unibyte-display-via-language-environment",
26906 &unibyte_display_via_language_environment
,
26907 doc
: /* *Non-nil means display unibyte text according to language environment.
26908 Specifically, this means that raw bytes in the range 160-255 decimal
26909 are displayed by converting them to the equivalent multibyte characters
26910 according to the current language environment. As a result, they are
26911 displayed according to the current fontset.
26913 Note that this variable affects only how these bytes are displayed,
26914 but does not change the fact they are interpreted as raw bytes. */);
26915 unibyte_display_via_language_environment
= 0;
26917 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
26918 doc
: /* *Maximum height for resizing mini-windows.
26919 If a float, it specifies a fraction of the mini-window frame's height.
26920 If an integer, it specifies a number of lines. */);
26921 Vmax_mini_window_height
= make_float (0.25);
26923 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
26924 doc
: /* *How to resize mini-windows.
26925 A value of nil means don't automatically resize mini-windows.
26926 A value of t means resize them to fit the text displayed in them.
26927 A value of `grow-only', the default, means let mini-windows grow
26928 only, until their display becomes empty, at which point the windows
26929 go back to their normal size. */);
26930 Vresize_mini_windows
= Qgrow_only
;
26932 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
26933 doc
: /* Alist specifying how to blink the cursor off.
26934 Each element has the form (ON-STATE . OFF-STATE). Whenever the
26935 `cursor-type' frame-parameter or variable equals ON-STATE,
26936 comparing using `equal', Emacs uses OFF-STATE to specify
26937 how to blink it off. ON-STATE and OFF-STATE are values for
26938 the `cursor-type' frame parameter.
26940 If a frame's ON-STATE has no entry in this list,
26941 the frame's other specifications determine how to blink the cursor off. */);
26942 Vblink_cursor_alist
= Qnil
;
26944 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
26945 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
26946 If non-nil, windows are automatically scrolled horizontally to make
26947 point visible. */);
26948 automatic_hscrolling_p
= 1;
26949 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
26950 staticpro (&Qauto_hscroll_mode
);
26952 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
26953 doc
: /* *How many columns away from the window edge point is allowed to get
26954 before automatic hscrolling will horizontally scroll the window. */);
26955 hscroll_margin
= 5;
26957 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
26958 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
26959 When point is less than `hscroll-margin' columns from the window
26960 edge, automatic hscrolling will scroll the window by the amount of columns
26961 determined by this variable. If its value is a positive integer, scroll that
26962 many columns. If it's a positive floating-point number, it specifies the
26963 fraction of the window's width to scroll. If it's nil or zero, point will be
26964 centered horizontally after the scroll. Any other value, including negative
26965 numbers, are treated as if the value were zero.
26967 Automatic hscrolling always moves point outside the scroll margin, so if
26968 point was more than scroll step columns inside the margin, the window will
26969 scroll more than the value given by the scroll step.
26971 Note that the lower bound for automatic hscrolling specified by `scroll-left'
26972 and `scroll-right' overrides this variable's effect. */);
26973 Vhscroll_step
= make_number (0);
26975 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
26976 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
26977 Bind this around calls to `message' to let it take effect. */);
26978 message_truncate_lines
= 0;
26980 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
26981 doc
: /* Normal hook run to update the menu bar definitions.
26982 Redisplay runs this hook before it redisplays the menu bar.
26983 This is used to update submenus such as Buffers,
26984 whose contents depend on various data. */);
26985 Vmenu_bar_update_hook
= Qnil
;
26987 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
26988 doc
: /* Frame for which we are updating a menu.
26989 The enable predicate for a menu binding should check this variable. */);
26990 Vmenu_updating_frame
= Qnil
;
26992 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
26993 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
26994 inhibit_menubar_update
= 0;
26996 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
26997 doc
: /* Prefix prepended to all continuation lines at display time.
26998 The value may be a string, an image, or a stretch-glyph; it is
26999 interpreted in the same way as the value of a `display' text property.
27001 This variable is overridden by any `wrap-prefix' text or overlay
27004 To add a prefix to non-continuation lines, use `line-prefix'. */);
27005 Vwrap_prefix
= Qnil
;
27006 staticpro (&Qwrap_prefix
);
27007 Qwrap_prefix
= intern_c_string ("wrap-prefix");
27008 Fmake_variable_buffer_local (Qwrap_prefix
);
27010 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
27011 doc
: /* Prefix prepended to all non-continuation lines at display time.
27012 The value may be a string, an image, or a stretch-glyph; it is
27013 interpreted in the same way as the value of a `display' text property.
27015 This variable is overridden by any `line-prefix' text or overlay
27018 To add a prefix to continuation lines, use `wrap-prefix'. */);
27019 Vline_prefix
= Qnil
;
27020 staticpro (&Qline_prefix
);
27021 Qline_prefix
= intern_c_string ("line-prefix");
27022 Fmake_variable_buffer_local (Qline_prefix
);
27024 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
27025 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27026 inhibit_eval_during_redisplay
= 0;
27028 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
27029 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27030 inhibit_free_realized_faces
= 0;
27033 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
27034 doc
: /* Inhibit try_window_id display optimization. */);
27035 inhibit_try_window_id
= 0;
27037 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
27038 doc
: /* Inhibit try_window_reusing display optimization. */);
27039 inhibit_try_window_reusing
= 0;
27041 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
27042 doc
: /* Inhibit try_cursor_movement display optimization. */);
27043 inhibit_try_cursor_movement
= 0;
27044 #endif /* GLYPH_DEBUG */
27046 DEFVAR_INT ("overline-margin", &overline_margin
,
27047 doc
: /* *Space between overline and text, in pixels.
27048 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27049 margin to the caracter height. */);
27050 overline_margin
= 2;
27052 DEFVAR_INT ("underline-minimum-offset",
27053 &underline_minimum_offset
,
27054 doc
: /* Minimum distance between baseline and underline.
27055 This can improve legibility of underlined text at small font sizes,
27056 particularly when using variable `x-use-underline-position-properties'
27057 with fonts that specify an UNDERLINE_POSITION relatively close to the
27058 baseline. The default value is 1. */);
27059 underline_minimum_offset
= 1;
27061 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
27062 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27063 This feature only works when on a window system that can change
27064 cursor shapes. */);
27065 display_hourglass_p
= 1;
27067 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
27068 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27069 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27071 hourglass_atimer
= NULL
;
27072 hourglass_shown_p
= 0;
27074 DEFSYM (Qglyphless_char
, "glyphless-char");
27075 DEFSYM (Qhex_code
, "hex-code");
27076 DEFSYM (Qempty_box
, "empty-box");
27077 DEFSYM (Qthin_space
, "thin-space");
27078 DEFSYM (Qzero_width
, "zero-width");
27080 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27081 /* Intern this now in case it isn't already done.
27082 Setting this variable twice is harmless.
27083 But don't staticpro it here--that is done in alloc.c. */
27084 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27085 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27087 DEFVAR_LISP ("glyphless-char-display", &Vglyphless_char_display
,
27088 doc
: /* Char-table to control displaying of glyphless characters.
27089 Each element, if non-nil, is an ASCII acronym string (displayed in a box)
27090 or one of these symbols:
27091 hex-code: display the hexadecimal code of a character in a box
27092 empty-box: display as an empty box
27093 thin-space: display as 1-pixel width space
27094 zero-width: don't display
27096 It has one extra slot to control the display of a character for which
27097 no font is found. The value of the slot is `hex-code' or `empty-box'.
27098 The default is `empty-box'. */);
27099 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27100 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27105 /* Initialize this module when Emacs starts. */
27110 Lisp_Object root_window
;
27111 struct window
*mini_w
;
27113 current_header_line_height
= current_mode_line_height
= -1;
27115 CHARPOS (this_line_start_pos
) = 0;
27117 mini_w
= XWINDOW (minibuf_window
);
27118 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27120 if (!noninteractive
)
27122 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27125 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27126 set_window_height (root_window
,
27127 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27129 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27130 set_window_height (minibuf_window
, 1, 0);
27132 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27133 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27135 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27136 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27137 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27139 /* The default ellipsis glyphs `...'. */
27140 for (i
= 0; i
< 3; ++i
)
27141 default_invis_vector
[i
] = make_number ('.');
27145 /* Allocate the buffer for frame titles.
27146 Also used for `format-mode-line'. */
27148 mode_line_noprop_buf
= (char *) xmalloc (size
);
27149 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27150 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27151 mode_line_target
= MODE_LINE_DISPLAY
;
27154 help_echo_showing_p
= 0;
27157 /* Since w32 does not support atimers, it defines its own implementation of
27158 the following three functions in w32fns.c. */
27161 /* Platform-independent portion of hourglass implementation. */
27163 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27165 hourglass_started (void)
27167 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27170 /* Cancel a currently active hourglass timer, and start a new one. */
27172 start_hourglass (void)
27174 #if defined (HAVE_WINDOW_SYSTEM)
27176 int secs
, usecs
= 0;
27178 cancel_hourglass ();
27180 if (INTEGERP (Vhourglass_delay
)
27181 && XINT (Vhourglass_delay
) > 0)
27182 secs
= XFASTINT (Vhourglass_delay
);
27183 else if (FLOATP (Vhourglass_delay
)
27184 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27187 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27188 secs
= XFASTINT (tem
);
27189 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27192 secs
= DEFAULT_HOURGLASS_DELAY
;
27194 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27195 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27196 show_hourglass
, NULL
);
27201 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27204 cancel_hourglass (void)
27206 #if defined (HAVE_WINDOW_SYSTEM)
27207 if (hourglass_atimer
)
27209 cancel_atimer (hourglass_atimer
);
27210 hourglass_atimer
= NULL
;
27213 if (hourglass_shown_p
)
27217 #endif /* ! WINDOWSNT */