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 Qhexa_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
, &x
, &y
, 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 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2234 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2236 if (w
->pseudo_window_p
)
2239 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2245 case ON_LEFT_MARGIN
:
2246 area
= LEFT_MARGIN_AREA
;
2249 case ON_RIGHT_MARGIN
:
2250 area
= RIGHT_MARGIN_AREA
;
2253 case ON_HEADER_LINE
:
2255 gr
= (part
== ON_HEADER_LINE
2256 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2257 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2260 goto text_glyph_row_found
;
2267 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2268 if (r
->y
+ r
->height
> y
)
2274 text_glyph_row_found
:
2277 struct glyph
*g
= gr
->glyphs
[area
];
2278 struct glyph
*end
= g
+ gr
->used
[area
];
2280 height
= gr
->height
;
2281 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2282 if (gx
+ g
->pixel_width
> x
)
2287 if (g
->type
== IMAGE_GLYPH
)
2289 /* Don't remember when mouse is over image, as
2290 image may have hot-spots. */
2291 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2294 width
= g
->pixel_width
;
2298 /* Use nominal char spacing at end of line. */
2300 gx
+= (x
/ width
) * width
;
2303 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2304 gx
+= window_box_left_offset (w
, area
);
2308 /* Use nominal line height at end of window. */
2309 gx
= (x
/ width
) * width
;
2311 gy
+= (y
/ height
) * height
;
2315 case ON_LEFT_FRINGE
:
2316 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2317 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2318 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2319 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2322 case ON_RIGHT_FRINGE
:
2323 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2324 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2325 : window_box_right_offset (w
, TEXT_AREA
));
2326 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2330 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2332 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2333 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2334 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2336 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2340 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2341 if (r
->y
+ r
->height
> y
)
2348 height
= gr
->height
;
2351 /* Use nominal line height at end of window. */
2353 gy
+= (y
/ height
) * height
;
2360 /* If there is no glyph under the mouse, then we divide the screen
2361 into a grid of the smallest glyph in the frame, and use that
2364 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2365 round down even for negative values. */
2371 gx
= (gx
/ width
) * width
;
2372 gy
= (gy
/ height
) * height
;
2377 gx
+= WINDOW_LEFT_EDGE_X (w
);
2378 gy
+= WINDOW_TOP_EDGE_Y (w
);
2381 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2383 /* Visible feedback for debugging. */
2386 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2387 f
->output_data
.x
->normal_gc
,
2388 gx
, gy
, width
, height
);
2394 #endif /* HAVE_WINDOW_SYSTEM */
2397 /***********************************************************************
2398 Lisp form evaluation
2399 ***********************************************************************/
2401 /* Error handler for safe_eval and safe_call. */
2404 safe_eval_handler (Lisp_Object arg
)
2406 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2411 /* Evaluate SEXPR and return the result, or nil if something went
2412 wrong. Prevent redisplay during the evaluation. */
2414 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2415 Return the result, or nil if something went wrong. Prevent
2416 redisplay during the evaluation. */
2419 safe_call (int nargs
, Lisp_Object
*args
)
2423 if (inhibit_eval_during_redisplay
)
2427 int count
= SPECPDL_INDEX ();
2428 struct gcpro gcpro1
;
2431 gcpro1
.nvars
= nargs
;
2432 specbind (Qinhibit_redisplay
, Qt
);
2433 /* Use Qt to ensure debugger does not run,
2434 so there is no possibility of wanting to redisplay. */
2435 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2438 val
= unbind_to (count
, val
);
2445 /* Call function FN with one argument ARG.
2446 Return the result, or nil if something went wrong. */
2449 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2451 Lisp_Object args
[2];
2454 return safe_call (2, args
);
2457 static Lisp_Object Qeval
;
2460 safe_eval (Lisp_Object sexpr
)
2462 return safe_call1 (Qeval
, sexpr
);
2465 /* Call function FN with one argument ARG.
2466 Return the result, or nil if something went wrong. */
2469 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2471 Lisp_Object args
[3];
2475 return safe_call (3, args
);
2480 /***********************************************************************
2482 ***********************************************************************/
2486 /* Define CHECK_IT to perform sanity checks on iterators.
2487 This is for debugging. It is too slow to do unconditionally. */
2493 if (it
->method
== GET_FROM_STRING
)
2495 xassert (STRINGP (it
->string
));
2496 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2500 xassert (IT_STRING_CHARPOS (*it
) < 0);
2501 if (it
->method
== GET_FROM_BUFFER
)
2503 /* Check that character and byte positions agree. */
2504 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2509 xassert (it
->current
.dpvec_index
>= 0);
2511 xassert (it
->current
.dpvec_index
< 0);
2514 #define CHECK_IT(IT) check_it ((IT))
2518 #define CHECK_IT(IT) (void) 0
2525 /* Check that the window end of window W is what we expect it
2526 to be---the last row in the current matrix displaying text. */
2529 check_window_end (w
)
2532 if (!MINI_WINDOW_P (w
)
2533 && !NILP (w
->window_end_valid
))
2535 struct glyph_row
*row
;
2536 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2537 XFASTINT (w
->window_end_vpos
)),
2539 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2540 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2544 #define CHECK_WINDOW_END(W) check_window_end ((W))
2546 #else /* not GLYPH_DEBUG */
2548 #define CHECK_WINDOW_END(W) (void) 0
2550 #endif /* not GLYPH_DEBUG */
2554 /***********************************************************************
2555 Iterator initialization
2556 ***********************************************************************/
2558 /* Initialize IT for displaying current_buffer in window W, starting
2559 at character position CHARPOS. CHARPOS < 0 means that no buffer
2560 position is specified which is useful when the iterator is assigned
2561 a position later. BYTEPOS is the byte position corresponding to
2562 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2564 If ROW is not null, calls to produce_glyphs with IT as parameter
2565 will produce glyphs in that row.
2567 BASE_FACE_ID is the id of a base face to use. It must be one of
2568 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2569 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2570 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2572 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2573 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2574 will be initialized to use the corresponding mode line glyph row of
2575 the desired matrix of W. */
2578 init_iterator (struct it
*it
, struct window
*w
,
2579 EMACS_INT charpos
, EMACS_INT bytepos
,
2580 struct glyph_row
*row
, enum face_id base_face_id
)
2582 int highlight_region_p
;
2583 enum face_id remapped_base_face_id
= base_face_id
;
2585 /* Some precondition checks. */
2586 xassert (w
!= NULL
&& it
!= NULL
);
2587 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2590 /* If face attributes have been changed since the last redisplay,
2591 free realized faces now because they depend on face definitions
2592 that might have changed. Don't free faces while there might be
2593 desired matrices pending which reference these faces. */
2594 if (face_change_count
&& !inhibit_free_realized_faces
)
2596 face_change_count
= 0;
2597 free_all_realized_faces (Qnil
);
2600 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2601 if (! NILP (Vface_remapping_alist
))
2602 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2604 /* Use one of the mode line rows of W's desired matrix if
2608 if (base_face_id
== MODE_LINE_FACE_ID
2609 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2610 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2611 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2612 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2616 memset (it
, 0, sizeof *it
);
2617 it
->current
.overlay_string_index
= -1;
2618 it
->current
.dpvec_index
= -1;
2619 it
->base_face_id
= remapped_base_face_id
;
2621 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2623 /* The window in which we iterate over current_buffer: */
2624 XSETWINDOW (it
->window
, w
);
2626 it
->f
= XFRAME (w
->frame
);
2630 /* Extra space between lines (on window systems only). */
2631 if (base_face_id
== DEFAULT_FACE_ID
2632 && FRAME_WINDOW_P (it
->f
))
2634 if (NATNUMP (current_buffer
->extra_line_spacing
))
2635 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2636 else if (FLOATP (current_buffer
->extra_line_spacing
))
2637 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2638 * FRAME_LINE_HEIGHT (it
->f
));
2639 else if (it
->f
->extra_line_spacing
> 0)
2640 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2641 it
->max_extra_line_spacing
= 0;
2644 /* If realized faces have been removed, e.g. because of face
2645 attribute changes of named faces, recompute them. When running
2646 in batch mode, the face cache of the initial frame is null. If
2647 we happen to get called, make a dummy face cache. */
2648 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2649 init_frame_faces (it
->f
);
2650 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2651 recompute_basic_faces (it
->f
);
2653 /* Current value of the `slice', `space-width', and 'height' properties. */
2654 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2655 it
->space_width
= Qnil
;
2656 it
->font_height
= Qnil
;
2657 it
->override_ascent
= -1;
2659 /* Are control characters displayed as `^C'? */
2660 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2662 /* -1 means everything between a CR and the following line end
2663 is invisible. >0 means lines indented more than this value are
2665 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2666 ? XFASTINT (current_buffer
->selective_display
)
2667 : (!NILP (current_buffer
->selective_display
)
2669 it
->selective_display_ellipsis_p
2670 = !NILP (current_buffer
->selective_display_ellipses
);
2672 /* Display table to use. */
2673 it
->dp
= window_display_table (w
);
2675 /* Are multibyte characters enabled in current_buffer? */
2676 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2678 /* Do we need to reorder bidirectional text? Not if this is a
2679 unibyte buffer: by definition, none of the single-byte characters
2680 are strong R2L, so no reordering is needed. And bidi.c doesn't
2681 support unibyte buffers anyway. */
2683 = !NILP (current_buffer
->bidi_display_reordering
) && it
->multibyte_p
;
2685 /* Non-zero if we should highlight the region. */
2687 = (!NILP (Vtransient_mark_mode
)
2688 && !NILP (current_buffer
->mark_active
)
2689 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2691 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2692 start and end of a visible region in window IT->w. Set both to
2693 -1 to indicate no region. */
2694 if (highlight_region_p
2695 /* Maybe highlight only in selected window. */
2696 && (/* Either show region everywhere. */
2697 highlight_nonselected_windows
2698 /* Or show region in the selected window. */
2699 || w
== XWINDOW (selected_window
)
2700 /* Or show the region if we are in the mini-buffer and W is
2701 the window the mini-buffer refers to. */
2702 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2703 && WINDOWP (minibuf_selected_window
)
2704 && w
== XWINDOW (minibuf_selected_window
))))
2706 EMACS_INT charpos
= marker_position (current_buffer
->mark
);
2707 it
->region_beg_charpos
= min (PT
, charpos
);
2708 it
->region_end_charpos
= max (PT
, charpos
);
2711 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2713 /* Get the position at which the redisplay_end_trigger hook should
2714 be run, if it is to be run at all. */
2715 if (MARKERP (w
->redisplay_end_trigger
)
2716 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2717 it
->redisplay_end_trigger_charpos
2718 = marker_position (w
->redisplay_end_trigger
);
2719 else if (INTEGERP (w
->redisplay_end_trigger
))
2720 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2722 /* Correct bogus values of tab_width. */
2723 it
->tab_width
= XINT (current_buffer
->tab_width
);
2724 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2727 /* Are lines in the display truncated? */
2728 if (base_face_id
!= DEFAULT_FACE_ID
2729 || XINT (it
->w
->hscroll
)
2730 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2731 && ((!NILP (Vtruncate_partial_width_windows
)
2732 && !INTEGERP (Vtruncate_partial_width_windows
))
2733 || (INTEGERP (Vtruncate_partial_width_windows
)
2734 && (WINDOW_TOTAL_COLS (it
->w
)
2735 < XINT (Vtruncate_partial_width_windows
))))))
2736 it
->line_wrap
= TRUNCATE
;
2737 else if (NILP (current_buffer
->truncate_lines
))
2738 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2739 ? WINDOW_WRAP
: WORD_WRAP
;
2741 it
->line_wrap
= TRUNCATE
;
2743 /* Get dimensions of truncation and continuation glyphs. These are
2744 displayed as fringe bitmaps under X, so we don't need them for such
2746 if (!FRAME_WINDOW_P (it
->f
))
2748 if (it
->line_wrap
== TRUNCATE
)
2750 /* We will need the truncation glyph. */
2751 xassert (it
->glyph_row
== NULL
);
2752 produce_special_glyphs (it
, IT_TRUNCATION
);
2753 it
->truncation_pixel_width
= it
->pixel_width
;
2757 /* We will need the continuation glyph. */
2758 xassert (it
->glyph_row
== NULL
);
2759 produce_special_glyphs (it
, IT_CONTINUATION
);
2760 it
->continuation_pixel_width
= it
->pixel_width
;
2763 /* Reset these values to zero because the produce_special_glyphs
2764 above has changed them. */
2765 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2766 it
->phys_ascent
= it
->phys_descent
= 0;
2769 /* Set this after getting the dimensions of truncation and
2770 continuation glyphs, so that we don't produce glyphs when calling
2771 produce_special_glyphs, above. */
2772 it
->glyph_row
= row
;
2773 it
->area
= TEXT_AREA
;
2775 /* Forget any previous info about this row being reversed. */
2777 it
->glyph_row
->reversed_p
= 0;
2779 /* Get the dimensions of the display area. The display area
2780 consists of the visible window area plus a horizontally scrolled
2781 part to the left of the window. All x-values are relative to the
2782 start of this total display area. */
2783 if (base_face_id
!= DEFAULT_FACE_ID
)
2785 /* Mode lines, menu bar in terminal frames. */
2786 it
->first_visible_x
= 0;
2787 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2792 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2793 it
->last_visible_x
= (it
->first_visible_x
2794 + window_box_width (w
, TEXT_AREA
));
2796 /* If we truncate lines, leave room for the truncator glyph(s) at
2797 the right margin. Otherwise, leave room for the continuation
2798 glyph(s). Truncation and continuation glyphs are not inserted
2799 for window-based redisplay. */
2800 if (!FRAME_WINDOW_P (it
->f
))
2802 if (it
->line_wrap
== TRUNCATE
)
2803 it
->last_visible_x
-= it
->truncation_pixel_width
;
2805 it
->last_visible_x
-= it
->continuation_pixel_width
;
2808 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2809 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2812 /* Leave room for a border glyph. */
2813 if (!FRAME_WINDOW_P (it
->f
)
2814 && !WINDOW_RIGHTMOST_P (it
->w
))
2815 it
->last_visible_x
-= 1;
2817 it
->last_visible_y
= window_text_bottom_y (w
);
2819 /* For mode lines and alike, arrange for the first glyph having a
2820 left box line if the face specifies a box. */
2821 if (base_face_id
!= DEFAULT_FACE_ID
)
2825 it
->face_id
= remapped_base_face_id
;
2827 /* If we have a boxed mode line, make the first character appear
2828 with a left box line. */
2829 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2830 if (face
->box
!= FACE_NO_BOX
)
2831 it
->start_of_box_run_p
= 1;
2834 /* If we are to reorder bidirectional text, init the bidi
2838 /* Note the paragraph direction that this buffer wants to
2840 if (EQ (current_buffer
->bidi_paragraph_direction
, Qleft_to_right
))
2841 it
->paragraph_embedding
= L2R
;
2842 else if (EQ (current_buffer
->bidi_paragraph_direction
, Qright_to_left
))
2843 it
->paragraph_embedding
= R2L
;
2845 it
->paragraph_embedding
= NEUTRAL_DIR
;
2846 bidi_init_it (charpos
, bytepos
, &it
->bidi_it
);
2849 /* If a buffer position was specified, set the iterator there,
2850 getting overlays and face properties from that position. */
2851 if (charpos
>= BUF_BEG (current_buffer
))
2853 it
->end_charpos
= ZV
;
2855 IT_CHARPOS (*it
) = charpos
;
2857 /* Compute byte position if not specified. */
2858 if (bytepos
< charpos
)
2859 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2861 IT_BYTEPOS (*it
) = bytepos
;
2863 it
->start
= it
->current
;
2865 /* Compute faces etc. */
2866 reseat (it
, it
->current
.pos
, 1);
2873 /* Initialize IT for the display of window W with window start POS. */
2876 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2878 struct glyph_row
*row
;
2879 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2881 row
= w
->desired_matrix
->rows
+ first_vpos
;
2882 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2883 it
->first_vpos
= first_vpos
;
2885 /* Don't reseat to previous visible line start if current start
2886 position is in a string or image. */
2887 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2889 int start_at_line_beg_p
;
2890 int first_y
= it
->current_y
;
2892 /* If window start is not at a line start, skip forward to POS to
2893 get the correct continuation lines width. */
2894 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2895 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2896 if (!start_at_line_beg_p
)
2900 reseat_at_previous_visible_line_start (it
);
2901 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2903 new_x
= it
->current_x
+ it
->pixel_width
;
2905 /* If lines are continued, this line may end in the middle
2906 of a multi-glyph character (e.g. a control character
2907 displayed as \003, or in the middle of an overlay
2908 string). In this case move_it_to above will not have
2909 taken us to the start of the continuation line but to the
2910 end of the continued line. */
2911 if (it
->current_x
> 0
2912 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2913 && (/* And glyph doesn't fit on the line. */
2914 new_x
> it
->last_visible_x
2915 /* Or it fits exactly and we're on a window
2917 || (new_x
== it
->last_visible_x
2918 && FRAME_WINDOW_P (it
->f
))))
2920 if (it
->current
.dpvec_index
>= 0
2921 || it
->current
.overlay_string_index
>= 0)
2923 set_iterator_to_next (it
, 1);
2924 move_it_in_display_line_to (it
, -1, -1, 0);
2927 it
->continuation_lines_width
+= it
->current_x
;
2930 /* We're starting a new display line, not affected by the
2931 height of the continued line, so clear the appropriate
2932 fields in the iterator structure. */
2933 it
->max_ascent
= it
->max_descent
= 0;
2934 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2936 it
->current_y
= first_y
;
2938 it
->current_x
= it
->hpos
= 0;
2944 /* Return 1 if POS is a position in ellipses displayed for invisible
2945 text. W is the window we display, for text property lookup. */
2948 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2950 Lisp_Object prop
, window
;
2952 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2954 /* If POS specifies a position in a display vector, this might
2955 be for an ellipsis displayed for invisible text. We won't
2956 get the iterator set up for delivering that ellipsis unless
2957 we make sure that it gets aware of the invisible text. */
2958 if (pos
->dpvec_index
>= 0
2959 && pos
->overlay_string_index
< 0
2960 && CHARPOS (pos
->string_pos
) < 0
2962 && (XSETWINDOW (window
, w
),
2963 prop
= Fget_char_property (make_number (charpos
),
2964 Qinvisible
, window
),
2965 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2967 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2969 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2976 /* Initialize IT for stepping through current_buffer in window W,
2977 starting at position POS that includes overlay string and display
2978 vector/ control character translation position information. Value
2979 is zero if there are overlay strings with newlines at POS. */
2982 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2984 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2985 int i
, overlay_strings_with_newlines
= 0;
2987 /* If POS specifies a position in a display vector, this might
2988 be for an ellipsis displayed for invisible text. We won't
2989 get the iterator set up for delivering that ellipsis unless
2990 we make sure that it gets aware of the invisible text. */
2991 if (in_ellipses_for_invisible_text_p (pos
, w
))
2997 /* Keep in mind: the call to reseat in init_iterator skips invisible
2998 text, so we might end up at a position different from POS. This
2999 is only a problem when POS is a row start after a newline and an
3000 overlay starts there with an after-string, and the overlay has an
3001 invisible property. Since we don't skip invisible text in
3002 display_line and elsewhere immediately after consuming the
3003 newline before the row start, such a POS will not be in a string,
3004 but the call to init_iterator below will move us to the
3006 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3008 /* This only scans the current chunk -- it should scan all chunks.
3009 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3010 to 16 in 22.1 to make this a lesser problem. */
3011 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3013 const char *s
= SDATA (it
->overlay_strings
[i
]);
3014 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3016 while (s
< e
&& *s
!= '\n')
3021 overlay_strings_with_newlines
= 1;
3026 /* If position is within an overlay string, set up IT to the right
3028 if (pos
->overlay_string_index
>= 0)
3032 /* If the first overlay string happens to have a `display'
3033 property for an image, the iterator will be set up for that
3034 image, and we have to undo that setup first before we can
3035 correct the overlay string index. */
3036 if (it
->method
== GET_FROM_IMAGE
)
3039 /* We already have the first chunk of overlay strings in
3040 IT->overlay_strings. Load more until the one for
3041 pos->overlay_string_index is in IT->overlay_strings. */
3042 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3044 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3045 it
->current
.overlay_string_index
= 0;
3048 load_overlay_strings (it
, 0);
3049 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3053 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3054 relative_index
= (it
->current
.overlay_string_index
3055 % OVERLAY_STRING_CHUNK_SIZE
);
3056 it
->string
= it
->overlay_strings
[relative_index
];
3057 xassert (STRINGP (it
->string
));
3058 it
->current
.string_pos
= pos
->string_pos
;
3059 it
->method
= GET_FROM_STRING
;
3062 if (CHARPOS (pos
->string_pos
) >= 0)
3064 /* Recorded position is not in an overlay string, but in another
3065 string. This can only be a string from a `display' property.
3066 IT should already be filled with that string. */
3067 it
->current
.string_pos
= pos
->string_pos
;
3068 xassert (STRINGP (it
->string
));
3071 /* Restore position in display vector translations, control
3072 character translations or ellipses. */
3073 if (pos
->dpvec_index
>= 0)
3075 if (it
->dpvec
== NULL
)
3076 get_next_display_element (it
);
3077 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3078 it
->current
.dpvec_index
= pos
->dpvec_index
;
3082 return !overlay_strings_with_newlines
;
3086 /* Initialize IT for stepping through current_buffer in window W
3087 starting at ROW->start. */
3090 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3092 init_from_display_pos (it
, w
, &row
->start
);
3093 it
->start
= row
->start
;
3094 it
->continuation_lines_width
= row
->continuation_lines_width
;
3099 /* Initialize IT for stepping through current_buffer in window W
3100 starting in the line following ROW, i.e. starting at ROW->end.
3101 Value is zero if there are overlay strings with newlines at ROW's
3105 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3109 if (init_from_display_pos (it
, w
, &row
->end
))
3111 if (row
->continued_p
)
3112 it
->continuation_lines_width
3113 = row
->continuation_lines_width
+ row
->pixel_width
;
3124 /***********************************************************************
3126 ***********************************************************************/
3128 /* Called when IT reaches IT->stop_charpos. Handle text property and
3129 overlay changes. Set IT->stop_charpos to the next position where
3133 handle_stop (struct it
*it
)
3135 enum prop_handled handled
;
3136 int handle_overlay_change_p
;
3140 it
->current
.dpvec_index
= -1;
3141 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3142 it
->ignore_overlay_strings_at_pos_p
= 0;
3145 /* Use face of preceding text for ellipsis (if invisible) */
3146 if (it
->selective_display_ellipsis_p
)
3147 it
->saved_face_id
= it
->face_id
;
3151 handled
= HANDLED_NORMALLY
;
3153 /* Call text property handlers. */
3154 for (p
= it_props
; p
->handler
; ++p
)
3156 handled
= p
->handler (it
);
3158 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3160 else if (handled
== HANDLED_RETURN
)
3162 /* We still want to show before and after strings from
3163 overlays even if the actual buffer text is replaced. */
3164 if (!handle_overlay_change_p
3166 || !get_overlay_strings_1 (it
, 0, 0))
3169 setup_for_ellipsis (it
, 0);
3170 /* When handling a display spec, we might load an
3171 empty string. In that case, discard it here. We
3172 used to discard it in handle_single_display_spec,
3173 but that causes get_overlay_strings_1, above, to
3174 ignore overlay strings that we must check. */
3175 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3179 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3183 it
->ignore_overlay_strings_at_pos_p
= 1;
3184 it
->string_from_display_prop_p
= 0;
3185 handle_overlay_change_p
= 0;
3187 handled
= HANDLED_RECOMPUTE_PROPS
;
3190 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3191 handle_overlay_change_p
= 0;
3194 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3196 /* Don't check for overlay strings below when set to deliver
3197 characters from a display vector. */
3198 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3199 handle_overlay_change_p
= 0;
3201 /* Handle overlay changes.
3202 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3203 if it finds overlays. */
3204 if (handle_overlay_change_p
)
3205 handled
= handle_overlay_change (it
);
3210 setup_for_ellipsis (it
, 0);
3214 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3216 /* Determine where to stop next. */
3217 if (handled
== HANDLED_NORMALLY
)
3218 compute_stop_pos (it
);
3222 /* Compute IT->stop_charpos from text property and overlay change
3223 information for IT's current position. */
3226 compute_stop_pos (struct it
*it
)
3228 register INTERVAL iv
, next_iv
;
3229 Lisp_Object object
, limit
, position
;
3230 EMACS_INT charpos
, bytepos
;
3232 /* If nowhere else, stop at the end. */
3233 it
->stop_charpos
= it
->end_charpos
;
3235 if (STRINGP (it
->string
))
3237 /* Strings are usually short, so don't limit the search for
3239 object
= it
->string
;
3241 charpos
= IT_STRING_CHARPOS (*it
);
3242 bytepos
= IT_STRING_BYTEPOS (*it
);
3248 /* If next overlay change is in front of the current stop pos
3249 (which is IT->end_charpos), stop there. Note: value of
3250 next_overlay_change is point-max if no overlay change
3252 charpos
= IT_CHARPOS (*it
);
3253 bytepos
= IT_BYTEPOS (*it
);
3254 pos
= next_overlay_change (charpos
);
3255 if (pos
< it
->stop_charpos
)
3256 it
->stop_charpos
= pos
;
3258 /* If showing the region, we have to stop at the region
3259 start or end because the face might change there. */
3260 if (it
->region_beg_charpos
> 0)
3262 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3263 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3264 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3265 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3268 /* Set up variables for computing the stop position from text
3269 property changes. */
3270 XSETBUFFER (object
, current_buffer
);
3271 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3274 /* Get the interval containing IT's position. Value is a null
3275 interval if there isn't such an interval. */
3276 position
= make_number (charpos
);
3277 iv
= validate_interval_range (object
, &position
, &position
, 0);
3278 if (!NULL_INTERVAL_P (iv
))
3280 Lisp_Object values_here
[LAST_PROP_IDX
];
3283 /* Get properties here. */
3284 for (p
= it_props
; p
->handler
; ++p
)
3285 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3287 /* Look for an interval following iv that has different
3289 for (next_iv
= next_interval (iv
);
3290 (!NULL_INTERVAL_P (next_iv
)
3292 || XFASTINT (limit
) > next_iv
->position
));
3293 next_iv
= next_interval (next_iv
))
3295 for (p
= it_props
; p
->handler
; ++p
)
3297 Lisp_Object new_value
;
3299 new_value
= textget (next_iv
->plist
, *p
->name
);
3300 if (!EQ (values_here
[p
->idx
], new_value
))
3308 if (!NULL_INTERVAL_P (next_iv
))
3310 if (INTEGERP (limit
)
3311 && next_iv
->position
>= XFASTINT (limit
))
3312 /* No text property change up to limit. */
3313 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3315 /* Text properties change in next_iv. */
3316 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3320 if (it
->cmp_it
.id
< 0)
3322 EMACS_INT stoppos
= it
->end_charpos
;
3324 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3326 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3327 stoppos
, it
->string
);
3330 xassert (STRINGP (it
->string
)
3331 || (it
->stop_charpos
>= BEGV
3332 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3336 /* Return the position of the next overlay change after POS in
3337 current_buffer. Value is point-max if no overlay change
3338 follows. This is like `next-overlay-change' but doesn't use
3342 next_overlay_change (EMACS_INT pos
)
3346 Lisp_Object
*overlays
;
3349 /* Get all overlays at the given position. */
3350 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3352 /* If any of these overlays ends before endpos,
3353 use its ending point instead. */
3354 for (i
= 0; i
< noverlays
; ++i
)
3359 oend
= OVERLAY_END (overlays
[i
]);
3360 oendpos
= OVERLAY_POSITION (oend
);
3361 endpos
= min (endpos
, oendpos
);
3369 /***********************************************************************
3371 ***********************************************************************/
3373 /* Handle changes in the `fontified' property of the current buffer by
3374 calling hook functions from Qfontification_functions to fontify
3377 static enum prop_handled
3378 handle_fontified_prop (struct it
*it
)
3380 Lisp_Object prop
, pos
;
3381 enum prop_handled handled
= HANDLED_NORMALLY
;
3383 if (!NILP (Vmemory_full
))
3386 /* Get the value of the `fontified' property at IT's current buffer
3387 position. (The `fontified' property doesn't have a special
3388 meaning in strings.) If the value is nil, call functions from
3389 Qfontification_functions. */
3390 if (!STRINGP (it
->string
)
3392 && !NILP (Vfontification_functions
)
3393 && !NILP (Vrun_hooks
)
3394 && (pos
= make_number (IT_CHARPOS (*it
)),
3395 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3396 /* Ignore the special cased nil value always present at EOB since
3397 no amount of fontifying will be able to change it. */
3398 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3400 int count
= SPECPDL_INDEX ();
3403 val
= Vfontification_functions
;
3404 specbind (Qfontification_functions
, Qnil
);
3406 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3407 safe_call1 (val
, pos
);
3410 Lisp_Object globals
, fn
;
3411 struct gcpro gcpro1
, gcpro2
;
3414 GCPRO2 (val
, globals
);
3416 for (; CONSP (val
); val
= XCDR (val
))
3422 /* A value of t indicates this hook has a local
3423 binding; it means to run the global binding too.
3424 In a global value, t should not occur. If it
3425 does, we must ignore it to avoid an endless
3427 for (globals
= Fdefault_value (Qfontification_functions
);
3429 globals
= XCDR (globals
))
3431 fn
= XCAR (globals
);
3433 safe_call1 (fn
, pos
);
3437 safe_call1 (fn
, pos
);
3443 unbind_to (count
, Qnil
);
3445 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3446 something. This avoids an endless loop if they failed to
3447 fontify the text for which reason ever. */
3448 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3449 handled
= HANDLED_RECOMPUTE_PROPS
;
3457 /***********************************************************************
3459 ***********************************************************************/
3461 /* Set up iterator IT from face properties at its current position.
3462 Called from handle_stop. */
3464 static enum prop_handled
3465 handle_face_prop (struct it
*it
)
3468 EMACS_INT next_stop
;
3470 if (!STRINGP (it
->string
))
3473 = face_at_buffer_position (it
->w
,
3475 it
->region_beg_charpos
,
3476 it
->region_end_charpos
,
3479 + TEXT_PROP_DISTANCE_LIMIT
),
3480 0, it
->base_face_id
);
3482 /* Is this a start of a run of characters with box face?
3483 Caveat: this can be called for a freshly initialized
3484 iterator; face_id is -1 in this case. We know that the new
3485 face will not change until limit, i.e. if the new face has a
3486 box, all characters up to limit will have one. But, as
3487 usual, we don't know whether limit is really the end. */
3488 if (new_face_id
!= it
->face_id
)
3490 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3492 /* If new face has a box but old face has not, this is
3493 the start of a run of characters with box, i.e. it has
3494 a shadow on the left side. The value of face_id of the
3495 iterator will be -1 if this is the initial call that gets
3496 the face. In this case, we have to look in front of IT's
3497 position and see whether there is a face != new_face_id. */
3498 it
->start_of_box_run_p
3499 = (new_face
->box
!= FACE_NO_BOX
3500 && (it
->face_id
>= 0
3501 || IT_CHARPOS (*it
) == BEG
3502 || new_face_id
!= face_before_it_pos (it
)));
3503 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3511 Lisp_Object from_overlay
3512 = (it
->current
.overlay_string_index
>= 0
3513 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3516 /* See if we got to this string directly or indirectly from
3517 an overlay property. That includes the before-string or
3518 after-string of an overlay, strings in display properties
3519 provided by an overlay, their text properties, etc.
3521 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3522 if (! NILP (from_overlay
))
3523 for (i
= it
->sp
- 1; i
>= 0; i
--)
3525 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3527 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3528 else if (! NILP (it
->stack
[i
].from_overlay
))
3529 from_overlay
= it
->stack
[i
].from_overlay
;
3531 if (!NILP (from_overlay
))
3535 if (! NILP (from_overlay
))
3537 bufpos
= IT_CHARPOS (*it
);
3538 /* For a string from an overlay, the base face depends
3539 only on text properties and ignores overlays. */
3541 = face_for_overlay_string (it
->w
,
3543 it
->region_beg_charpos
,
3544 it
->region_end_charpos
,
3547 + TEXT_PROP_DISTANCE_LIMIT
),
3555 /* For strings from a `display' property, use the face at
3556 IT's current buffer position as the base face to merge
3557 with, so that overlay strings appear in the same face as
3558 surrounding text, unless they specify their own
3560 base_face_id
= underlying_face_id (it
);
3563 new_face_id
= face_at_string_position (it
->w
,
3565 IT_STRING_CHARPOS (*it
),
3567 it
->region_beg_charpos
,
3568 it
->region_end_charpos
,
3572 /* Is this a start of a run of characters with box? Caveat:
3573 this can be called for a freshly allocated iterator; face_id
3574 is -1 is this case. We know that the new face will not
3575 change until the next check pos, i.e. if the new face has a
3576 box, all characters up to that position will have a
3577 box. But, as usual, we don't know whether that position
3578 is really the end. */
3579 if (new_face_id
!= it
->face_id
)
3581 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3582 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3584 /* If new face has a box but old face hasn't, this is the
3585 start of a run of characters with box, i.e. it has a
3586 shadow on the left side. */
3587 it
->start_of_box_run_p
3588 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3589 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3593 it
->face_id
= new_face_id
;
3594 return HANDLED_NORMALLY
;
3598 /* Return the ID of the face ``underlying'' IT's current position,
3599 which is in a string. If the iterator is associated with a
3600 buffer, return the face at IT's current buffer position.
3601 Otherwise, use the iterator's base_face_id. */
3604 underlying_face_id (struct it
*it
)
3606 int face_id
= it
->base_face_id
, i
;
3608 xassert (STRINGP (it
->string
));
3610 for (i
= it
->sp
- 1; i
>= 0; --i
)
3611 if (NILP (it
->stack
[i
].string
))
3612 face_id
= it
->stack
[i
].face_id
;
3618 /* Compute the face one character before or after the current position
3619 of IT. BEFORE_P non-zero means get the face in front of IT's
3620 position. Value is the id of the face. */
3623 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3626 EMACS_INT next_check_charpos
;
3627 struct text_pos pos
;
3629 xassert (it
->s
== NULL
);
3631 if (STRINGP (it
->string
))
3636 /* No face change past the end of the string (for the case
3637 we are padding with spaces). No face change before the
3639 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3640 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3643 /* Set pos to the position before or after IT's current position. */
3645 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3647 /* For composition, we must check the character after the
3649 pos
= (it
->what
== IT_COMPOSITION
3650 ? string_pos (IT_STRING_CHARPOS (*it
)
3651 + it
->cmp_it
.nchars
, it
->string
)
3652 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3654 if (it
->current
.overlay_string_index
>= 0)
3655 bufpos
= IT_CHARPOS (*it
);
3659 base_face_id
= underlying_face_id (it
);
3661 /* Get the face for ASCII, or unibyte. */
3662 face_id
= face_at_string_position (it
->w
,
3666 it
->region_beg_charpos
,
3667 it
->region_end_charpos
,
3668 &next_check_charpos
,
3671 /* Correct the face for charsets different from ASCII. Do it
3672 for the multibyte case only. The face returned above is
3673 suitable for unibyte text if IT->string is unibyte. */
3674 if (STRING_MULTIBYTE (it
->string
))
3676 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3678 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3680 c
= string_char_and_length (p
, &len
);
3681 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3686 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3687 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3690 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3691 pos
= it
->current
.pos
;
3694 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3697 if (it
->what
== IT_COMPOSITION
)
3698 /* For composition, we must check the position after the
3700 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3702 INC_TEXT_POS (pos
, it
->multibyte_p
);
3705 /* Determine face for CHARSET_ASCII, or unibyte. */
3706 face_id
= face_at_buffer_position (it
->w
,
3708 it
->region_beg_charpos
,
3709 it
->region_end_charpos
,
3710 &next_check_charpos
,
3713 /* Correct the face for charsets different from ASCII. Do it
3714 for the multibyte case only. The face returned above is
3715 suitable for unibyte text if current_buffer is unibyte. */
3716 if (it
->multibyte_p
)
3718 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3719 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3720 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3729 /***********************************************************************
3731 ***********************************************************************/
3733 /* Set up iterator IT from invisible properties at its current
3734 position. Called from handle_stop. */
3736 static enum prop_handled
3737 handle_invisible_prop (struct it
*it
)
3739 enum prop_handled handled
= HANDLED_NORMALLY
;
3741 if (STRINGP (it
->string
))
3743 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3745 /* Get the value of the invisible text property at the
3746 current position. Value will be nil if there is no such
3748 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3749 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3752 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3754 handled
= HANDLED_RECOMPUTE_PROPS
;
3756 /* Get the position at which the next change of the
3757 invisible text property can be found in IT->string.
3758 Value will be nil if the property value is the same for
3759 all the rest of IT->string. */
3760 XSETINT (limit
, SCHARS (it
->string
));
3761 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3764 /* Text at current position is invisible. The next
3765 change in the property is at position end_charpos.
3766 Move IT's current position to that position. */
3767 if (INTEGERP (end_charpos
)
3768 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3770 struct text_pos old
;
3771 old
= it
->current
.string_pos
;
3772 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3773 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3777 /* The rest of the string is invisible. If this is an
3778 overlay string, proceed with the next overlay string
3779 or whatever comes and return a character from there. */
3780 if (it
->current
.overlay_string_index
>= 0)
3782 next_overlay_string (it
);
3783 /* Don't check for overlay strings when we just
3784 finished processing them. */
3785 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3789 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3790 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3798 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3799 Lisp_Object pos
, prop
, overlay
;
3801 /* First of all, is there invisible text at this position? */
3802 tem
= start_charpos
= IT_CHARPOS (*it
);
3803 pos
= make_number (tem
);
3804 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3806 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3808 /* If we are on invisible text, skip over it. */
3809 if (invis_p
&& start_charpos
< it
->end_charpos
)
3811 /* Record whether we have to display an ellipsis for the
3813 int display_ellipsis_p
= invis_p
== 2;
3815 handled
= HANDLED_RECOMPUTE_PROPS
;
3817 /* Loop skipping over invisible text. The loop is left at
3818 ZV or with IT on the first char being visible again. */
3821 /* Try to skip some invisible text. Return value is the
3822 position reached which can be equal to where we start
3823 if there is nothing invisible there. This skips both
3824 over invisible text properties and overlays with
3825 invisible property. */
3826 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3828 /* If we skipped nothing at all we weren't at invisible
3829 text in the first place. If everything to the end of
3830 the buffer was skipped, end the loop. */
3831 if (newpos
== tem
|| newpos
>= ZV
)
3835 /* We skipped some characters but not necessarily
3836 all there are. Check if we ended up on visible
3837 text. Fget_char_property returns the property of
3838 the char before the given position, i.e. if we
3839 get invis_p = 0, this means that the char at
3840 newpos is visible. */
3841 pos
= make_number (newpos
);
3842 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3843 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3846 /* If we ended up on invisible text, proceed to
3847 skip starting with next_stop. */
3851 /* If there are adjacent invisible texts, don't lose the
3852 second one's ellipsis. */
3854 display_ellipsis_p
= 1;
3858 /* The position newpos is now either ZV or on visible text. */
3859 if (it
->bidi_p
&& newpos
< ZV
)
3861 /* With bidi iteration, the region of invisible text
3862 could start and/or end in the middle of a non-base
3863 embedding level. Therefore, we need to skip
3864 invisible text using the bidi iterator, starting at
3865 IT's current position, until we find ourselves
3866 outside the invisible text. Skipping invisible text
3867 _after_ bidi iteration avoids affecting the visual
3868 order of the displayed text when invisible properties
3869 are added or removed. */
3870 if (it
->bidi_it
.first_elt
)
3872 /* If we were `reseat'ed to a new paragraph,
3873 determine the paragraph base direction. We need
3874 to do it now because next_element_from_buffer may
3875 not have a chance to do it, if we are going to
3876 skip any text at the beginning, which resets the
3878 bidi_paragraph_init (it
->paragraph_embedding
,
3883 bidi_move_to_visually_next (&it
->bidi_it
);
3885 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3886 && it
->bidi_it
.charpos
< newpos
);
3887 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3888 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3889 /* If we overstepped NEWPOS, record its position in the
3890 iterator, so that we skip invisible text if later the
3891 bidi iteration lands us in the invisible region
3893 if (IT_CHARPOS (*it
) >= newpos
)
3894 it
->prev_stop
= newpos
;
3898 IT_CHARPOS (*it
) = newpos
;
3899 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3902 /* If there are before-strings at the start of invisible
3903 text, and the text is invisible because of a text
3904 property, arrange to show before-strings because 20.x did
3905 it that way. (If the text is invisible because of an
3906 overlay property instead of a text property, this is
3907 already handled in the overlay code.) */
3909 && get_overlay_strings (it
, it
->stop_charpos
))
3911 handled
= HANDLED_RECOMPUTE_PROPS
;
3912 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3914 else if (display_ellipsis_p
)
3916 /* Make sure that the glyphs of the ellipsis will get
3917 correct `charpos' values. If we would not update
3918 it->position here, the glyphs would belong to the
3919 last visible character _before_ the invisible
3920 text, which confuses `set_cursor_from_row'.
3922 We use the last invisible position instead of the
3923 first because this way the cursor is always drawn on
3924 the first "." of the ellipsis, whenever PT is inside
3925 the invisible text. Otherwise the cursor would be
3926 placed _after_ the ellipsis when the point is after the
3927 first invisible character. */
3928 if (!STRINGP (it
->object
))
3930 it
->position
.charpos
= newpos
- 1;
3931 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3934 /* Let the ellipsis display before
3935 considering any properties of the following char.
3936 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3937 handled
= HANDLED_RETURN
;
3946 /* Make iterator IT return `...' next.
3947 Replaces LEN characters from buffer. */
3950 setup_for_ellipsis (struct it
*it
, int len
)
3952 /* Use the display table definition for `...'. Invalid glyphs
3953 will be handled by the method returning elements from dpvec. */
3954 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3956 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3957 it
->dpvec
= v
->contents
;
3958 it
->dpend
= v
->contents
+ v
->size
;
3962 /* Default `...'. */
3963 it
->dpvec
= default_invis_vector
;
3964 it
->dpend
= default_invis_vector
+ 3;
3967 it
->dpvec_char_len
= len
;
3968 it
->current
.dpvec_index
= 0;
3969 it
->dpvec_face_id
= -1;
3971 /* Remember the current face id in case glyphs specify faces.
3972 IT's face is restored in set_iterator_to_next.
3973 saved_face_id was set to preceding char's face in handle_stop. */
3974 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3975 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3977 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3983 /***********************************************************************
3985 ***********************************************************************/
3987 /* Set up iterator IT from `display' property at its current position.
3988 Called from handle_stop.
3989 We return HANDLED_RETURN if some part of the display property
3990 overrides the display of the buffer text itself.
3991 Otherwise we return HANDLED_NORMALLY. */
3993 static enum prop_handled
3994 handle_display_prop (struct it
*it
)
3996 Lisp_Object prop
, object
, overlay
;
3997 struct text_pos
*position
;
3998 /* Nonzero if some property replaces the display of the text itself. */
3999 int display_replaced_p
= 0;
4001 if (STRINGP (it
->string
))
4003 object
= it
->string
;
4004 position
= &it
->current
.string_pos
;
4008 XSETWINDOW (object
, it
->w
);
4009 position
= &it
->current
.pos
;
4012 /* Reset those iterator values set from display property values. */
4013 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4014 it
->space_width
= Qnil
;
4015 it
->font_height
= Qnil
;
4018 /* We don't support recursive `display' properties, i.e. string
4019 values that have a string `display' property, that have a string
4020 `display' property etc. */
4021 if (!it
->string_from_display_prop_p
)
4022 it
->area
= TEXT_AREA
;
4024 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
4025 Qdisplay
, object
, &overlay
);
4027 return HANDLED_NORMALLY
;
4028 /* Now OVERLAY is the overlay that gave us this property, or nil
4029 if it was a text property. */
4031 if (!STRINGP (it
->string
))
4032 object
= it
->w
->buffer
;
4035 /* Simple properties. */
4036 && !EQ (XCAR (prop
), Qimage
)
4037 && !EQ (XCAR (prop
), Qspace
)
4038 && !EQ (XCAR (prop
), Qwhen
)
4039 && !EQ (XCAR (prop
), Qslice
)
4040 && !EQ (XCAR (prop
), Qspace_width
)
4041 && !EQ (XCAR (prop
), Qheight
)
4042 && !EQ (XCAR (prop
), Qraise
)
4043 /* Marginal area specifications. */
4044 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
4045 && !EQ (XCAR (prop
), Qleft_fringe
)
4046 && !EQ (XCAR (prop
), Qright_fringe
)
4047 && !NILP (XCAR (prop
)))
4049 for (; CONSP (prop
); prop
= XCDR (prop
))
4051 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
4052 position
, display_replaced_p
))
4054 display_replaced_p
= 1;
4055 /* If some text in a string is replaced, `position' no
4056 longer points to the position of `object'. */
4057 if (STRINGP (object
))
4062 else if (VECTORP (prop
))
4065 for (i
= 0; i
< ASIZE (prop
); ++i
)
4066 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4067 position
, display_replaced_p
))
4069 display_replaced_p
= 1;
4070 /* If some text in a string is replaced, `position' no
4071 longer points to the position of `object'. */
4072 if (STRINGP (object
))
4078 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4080 display_replaced_p
= 1;
4083 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4087 /* Value is the position of the end of the `display' property starting
4088 at START_POS in OBJECT. */
4090 static struct text_pos
4091 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4094 struct text_pos end_pos
;
4096 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4097 Qdisplay
, object
, Qnil
);
4098 CHARPOS (end_pos
) = XFASTINT (end
);
4099 if (STRINGP (object
))
4100 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4102 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4108 /* Set up IT from a single `display' specification PROP. OBJECT
4109 is the object in which the `display' property was found. *POSITION
4110 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4111 means that we previously saw a display specification which already
4112 replaced text display with something else, for example an image;
4113 we ignore such properties after the first one has been processed.
4115 OVERLAY is the overlay this `display' property came from,
4116 or nil if it was a text property.
4118 If PROP is a `space' or `image' specification, and in some other
4119 cases too, set *POSITION to the position where the `display'
4122 Value is non-zero if something was found which replaces the display
4123 of buffer or string text. */
4126 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4127 Lisp_Object overlay
, struct text_pos
*position
,
4128 int display_replaced_before_p
)
4131 Lisp_Object location
, value
;
4132 struct text_pos start_pos
, save_pos
;
4135 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4136 If the result is non-nil, use VALUE instead of SPEC. */
4138 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4147 if (!NILP (form
) && !EQ (form
, Qt
))
4149 int count
= SPECPDL_INDEX ();
4150 struct gcpro gcpro1
;
4152 /* Bind `object' to the object having the `display' property, a
4153 buffer or string. Bind `position' to the position in the
4154 object where the property was found, and `buffer-position'
4155 to the current position in the buffer. */
4156 specbind (Qobject
, object
);
4157 specbind (Qposition
, make_number (CHARPOS (*position
)));
4158 specbind (Qbuffer_position
,
4159 make_number (STRINGP (object
)
4160 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4162 form
= safe_eval (form
);
4164 unbind_to (count
, Qnil
);
4170 /* Handle `(height HEIGHT)' specifications. */
4172 && EQ (XCAR (spec
), Qheight
)
4173 && CONSP (XCDR (spec
)))
4175 if (!FRAME_WINDOW_P (it
->f
))
4178 it
->font_height
= XCAR (XCDR (spec
));
4179 if (!NILP (it
->font_height
))
4181 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4182 int new_height
= -1;
4184 if (CONSP (it
->font_height
)
4185 && (EQ (XCAR (it
->font_height
), Qplus
)
4186 || EQ (XCAR (it
->font_height
), Qminus
))
4187 && CONSP (XCDR (it
->font_height
))
4188 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4190 /* `(+ N)' or `(- N)' where N is an integer. */
4191 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4192 if (EQ (XCAR (it
->font_height
), Qplus
))
4194 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4196 else if (FUNCTIONP (it
->font_height
))
4198 /* Call function with current height as argument.
4199 Value is the new height. */
4201 height
= safe_call1 (it
->font_height
,
4202 face
->lface
[LFACE_HEIGHT_INDEX
]);
4203 if (NUMBERP (height
))
4204 new_height
= XFLOATINT (height
);
4206 else if (NUMBERP (it
->font_height
))
4208 /* Value is a multiple of the canonical char height. */
4211 face
= FACE_FROM_ID (it
->f
,
4212 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4213 new_height
= (XFLOATINT (it
->font_height
)
4214 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4218 /* Evaluate IT->font_height with `height' bound to the
4219 current specified height to get the new height. */
4220 int count
= SPECPDL_INDEX ();
4222 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4223 value
= safe_eval (it
->font_height
);
4224 unbind_to (count
, Qnil
);
4226 if (NUMBERP (value
))
4227 new_height
= XFLOATINT (value
);
4231 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4237 /* Handle `(space-width WIDTH)'. */
4239 && EQ (XCAR (spec
), Qspace_width
)
4240 && CONSP (XCDR (spec
)))
4242 if (!FRAME_WINDOW_P (it
->f
))
4245 value
= XCAR (XCDR (spec
));
4246 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4247 it
->space_width
= value
;
4252 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4254 && EQ (XCAR (spec
), Qslice
))
4258 if (!FRAME_WINDOW_P (it
->f
))
4261 if (tem
= XCDR (spec
), CONSP (tem
))
4263 it
->slice
.x
= XCAR (tem
);
4264 if (tem
= XCDR (tem
), CONSP (tem
))
4266 it
->slice
.y
= XCAR (tem
);
4267 if (tem
= XCDR (tem
), CONSP (tem
))
4269 it
->slice
.width
= XCAR (tem
);
4270 if (tem
= XCDR (tem
), CONSP (tem
))
4271 it
->slice
.height
= XCAR (tem
);
4279 /* Handle `(raise FACTOR)'. */
4281 && EQ (XCAR (spec
), Qraise
)
4282 && CONSP (XCDR (spec
)))
4284 if (!FRAME_WINDOW_P (it
->f
))
4287 #ifdef HAVE_WINDOW_SYSTEM
4288 value
= XCAR (XCDR (spec
));
4289 if (NUMBERP (value
))
4291 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4292 it
->voffset
= - (XFLOATINT (value
)
4293 * (FONT_HEIGHT (face
->font
)));
4295 #endif /* HAVE_WINDOW_SYSTEM */
4300 /* Don't handle the other kinds of display specifications
4301 inside a string that we got from a `display' property. */
4302 if (it
->string_from_display_prop_p
)
4305 /* Characters having this form of property are not displayed, so
4306 we have to find the end of the property. */
4307 start_pos
= *position
;
4308 *position
= display_prop_end (it
, object
, start_pos
);
4311 /* Stop the scan at that end position--we assume that all
4312 text properties change there. */
4313 it
->stop_charpos
= position
->charpos
;
4315 /* Handle `(left-fringe BITMAP [FACE])'
4316 and `(right-fringe BITMAP [FACE])'. */
4318 && (EQ (XCAR (spec
), Qleft_fringe
)
4319 || EQ (XCAR (spec
), Qright_fringe
))
4320 && CONSP (XCDR (spec
)))
4322 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4325 if (!FRAME_WINDOW_P (it
->f
))
4326 /* If we return here, POSITION has been advanced
4327 across the text with this property. */
4330 #ifdef HAVE_WINDOW_SYSTEM
4331 value
= XCAR (XCDR (spec
));
4332 if (!SYMBOLP (value
)
4333 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4334 /* If we return here, POSITION has been advanced
4335 across the text with this property. */
4338 if (CONSP (XCDR (XCDR (spec
))))
4340 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4341 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4347 /* Save current settings of IT so that we can restore them
4348 when we are finished with the glyph property value. */
4350 save_pos
= it
->position
;
4351 it
->position
= *position
;
4353 it
->position
= save_pos
;
4355 it
->area
= TEXT_AREA
;
4356 it
->what
= IT_IMAGE
;
4357 it
->image_id
= -1; /* no image */
4358 it
->position
= start_pos
;
4359 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4360 it
->method
= GET_FROM_IMAGE
;
4361 it
->from_overlay
= Qnil
;
4362 it
->face_id
= face_id
;
4364 /* Say that we haven't consumed the characters with
4365 `display' property yet. The call to pop_it in
4366 set_iterator_to_next will clean this up. */
4367 *position
= start_pos
;
4369 if (EQ (XCAR (spec
), Qleft_fringe
))
4371 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4372 it
->left_user_fringe_face_id
= face_id
;
4376 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4377 it
->right_user_fringe_face_id
= face_id
;
4379 #endif /* HAVE_WINDOW_SYSTEM */
4383 /* Prepare to handle `((margin left-margin) ...)',
4384 `((margin right-margin) ...)' and `((margin nil) ...)'
4385 prefixes for display specifications. */
4386 location
= Qunbound
;
4387 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4391 value
= XCDR (spec
);
4393 value
= XCAR (value
);
4396 if (EQ (XCAR (tem
), Qmargin
)
4397 && (tem
= XCDR (tem
),
4398 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4400 || EQ (tem
, Qleft_margin
)
4401 || EQ (tem
, Qright_margin
))))
4405 if (EQ (location
, Qunbound
))
4411 /* After this point, VALUE is the property after any
4412 margin prefix has been stripped. It must be a string,
4413 an image specification, or `(space ...)'.
4415 LOCATION specifies where to display: `left-margin',
4416 `right-margin' or nil. */
4418 valid_p
= (STRINGP (value
)
4419 #ifdef HAVE_WINDOW_SYSTEM
4420 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4421 #endif /* not HAVE_WINDOW_SYSTEM */
4422 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4424 if (valid_p
&& !display_replaced_before_p
)
4426 /* Save current settings of IT so that we can restore them
4427 when we are finished with the glyph property value. */
4428 save_pos
= it
->position
;
4429 it
->position
= *position
;
4431 it
->position
= save_pos
;
4432 it
->from_overlay
= overlay
;
4434 if (NILP (location
))
4435 it
->area
= TEXT_AREA
;
4436 else if (EQ (location
, Qleft_margin
))
4437 it
->area
= LEFT_MARGIN_AREA
;
4439 it
->area
= RIGHT_MARGIN_AREA
;
4441 if (STRINGP (value
))
4444 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4445 it
->current
.overlay_string_index
= -1;
4446 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4447 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4448 it
->method
= GET_FROM_STRING
;
4449 it
->stop_charpos
= 0;
4450 it
->string_from_display_prop_p
= 1;
4451 /* Say that we haven't consumed the characters with
4452 `display' property yet. The call to pop_it in
4453 set_iterator_to_next will clean this up. */
4454 if (BUFFERP (object
))
4455 *position
= start_pos
;
4457 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4459 it
->method
= GET_FROM_STRETCH
;
4461 *position
= it
->position
= start_pos
;
4463 #ifdef HAVE_WINDOW_SYSTEM
4466 it
->what
= IT_IMAGE
;
4467 it
->image_id
= lookup_image (it
->f
, value
);
4468 it
->position
= start_pos
;
4469 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4470 it
->method
= GET_FROM_IMAGE
;
4472 /* Say that we haven't consumed the characters with
4473 `display' property yet. The call to pop_it in
4474 set_iterator_to_next will clean this up. */
4475 *position
= start_pos
;
4477 #endif /* HAVE_WINDOW_SYSTEM */
4482 /* Invalid property or property not supported. Restore
4483 POSITION to what it was before. */
4484 *position
= start_pos
;
4489 /* Check if SPEC is a display sub-property value whose text should be
4490 treated as intangible. */
4493 single_display_spec_intangible_p (Lisp_Object prop
)
4495 /* Skip over `when FORM'. */
4496 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4510 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4511 we don't need to treat text as intangible. */
4512 if (EQ (XCAR (prop
), Qmargin
))
4520 || EQ (XCAR (prop
), Qleft_margin
)
4521 || EQ (XCAR (prop
), Qright_margin
))
4525 return (CONSP (prop
)
4526 && (EQ (XCAR (prop
), Qimage
)
4527 || EQ (XCAR (prop
), Qspace
)));
4531 /* Check if PROP is a display property value whose text should be
4532 treated as intangible. */
4535 display_prop_intangible_p (Lisp_Object prop
)
4538 && CONSP (XCAR (prop
))
4539 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4541 /* A list of sub-properties. */
4542 while (CONSP (prop
))
4544 if (single_display_spec_intangible_p (XCAR (prop
)))
4549 else if (VECTORP (prop
))
4551 /* A vector of sub-properties. */
4553 for (i
= 0; i
< ASIZE (prop
); ++i
)
4554 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4558 return single_display_spec_intangible_p (prop
);
4564 /* Return 1 if PROP is a display sub-property value containing STRING. */
4567 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4569 if (EQ (string
, prop
))
4572 /* Skip over `when FORM'. */
4573 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4582 /* Skip over `margin LOCATION'. */
4583 if (EQ (XCAR (prop
), Qmargin
))
4594 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4598 /* Return 1 if STRING appears in the `display' property PROP. */
4601 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4604 && CONSP (XCAR (prop
))
4605 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4607 /* A list of sub-properties. */
4608 while (CONSP (prop
))
4610 if (single_display_spec_string_p (XCAR (prop
), string
))
4615 else if (VECTORP (prop
))
4617 /* A vector of sub-properties. */
4619 for (i
= 0; i
< ASIZE (prop
); ++i
)
4620 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4624 return single_display_spec_string_p (prop
, string
);
4629 /* Look for STRING in overlays and text properties in W's buffer,
4630 between character positions FROM and TO (excluding TO).
4631 BACK_P non-zero means look back (in this case, TO is supposed to be
4633 Value is the first character position where STRING was found, or
4634 zero if it wasn't found before hitting TO.
4636 W's buffer must be current.
4638 This function may only use code that doesn't eval because it is
4639 called asynchronously from note_mouse_highlight. */
4642 string_buffer_position_lim (struct window
*w
, Lisp_Object string
,
4643 EMACS_INT from
, EMACS_INT to
, int back_p
)
4645 Lisp_Object limit
, prop
, pos
;
4648 pos
= make_number (from
);
4650 if (!back_p
) /* looking forward */
4652 limit
= make_number (min (to
, ZV
));
4653 while (!found
&& !EQ (pos
, limit
))
4655 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4656 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4659 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4663 else /* looking back */
4665 limit
= make_number (max (to
, BEGV
));
4666 while (!found
&& !EQ (pos
, limit
))
4668 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4669 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4672 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4677 return found
? XINT (pos
) : 0;
4680 /* Determine which buffer position in W's buffer STRING comes from.
4681 AROUND_CHARPOS is an approximate position where it could come from.
4682 Value is the buffer position or 0 if it couldn't be determined.
4684 W's buffer must be current.
4686 This function is necessary because we don't record buffer positions
4687 in glyphs generated from strings (to keep struct glyph small).
4688 This function may only use code that doesn't eval because it is
4689 called asynchronously from note_mouse_highlight. */
4692 string_buffer_position (struct window
*w
, Lisp_Object string
, EMACS_INT around_charpos
)
4694 const int MAX_DISTANCE
= 1000;
4695 EMACS_INT found
= string_buffer_position_lim (w
, string
, around_charpos
,
4696 around_charpos
+ MAX_DISTANCE
,
4700 found
= string_buffer_position_lim (w
, string
, around_charpos
,
4701 around_charpos
- MAX_DISTANCE
, 1);
4707 /***********************************************************************
4708 `composition' property
4709 ***********************************************************************/
4711 /* Set up iterator IT from `composition' property at its current
4712 position. Called from handle_stop. */
4714 static enum prop_handled
4715 handle_composition_prop (struct it
*it
)
4717 Lisp_Object prop
, string
;
4718 EMACS_INT pos
, pos_byte
, start
, end
;
4720 if (STRINGP (it
->string
))
4724 pos
= IT_STRING_CHARPOS (*it
);
4725 pos_byte
= IT_STRING_BYTEPOS (*it
);
4726 string
= it
->string
;
4727 s
= SDATA (string
) + pos_byte
;
4728 it
->c
= STRING_CHAR (s
);
4732 pos
= IT_CHARPOS (*it
);
4733 pos_byte
= IT_BYTEPOS (*it
);
4735 it
->c
= FETCH_CHAR (pos_byte
);
4738 /* If there's a valid composition and point is not inside of the
4739 composition (in the case that the composition is from the current
4740 buffer), draw a glyph composed from the composition components. */
4741 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4742 && COMPOSITION_VALID_P (start
, end
, prop
)
4743 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4747 if (STRINGP (it
->string
))
4748 pos_byte
= string_char_to_byte (it
->string
, start
);
4750 pos_byte
= CHAR_TO_BYTE (start
);
4752 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4755 if (it
->cmp_it
.id
>= 0)
4758 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4759 it
->cmp_it
.nglyphs
= -1;
4763 return HANDLED_NORMALLY
;
4768 /***********************************************************************
4770 ***********************************************************************/
4772 /* The following structure is used to record overlay strings for
4773 later sorting in load_overlay_strings. */
4775 struct overlay_entry
4777 Lisp_Object overlay
;
4784 /* Set up iterator IT from overlay strings at its current position.
4785 Called from handle_stop. */
4787 static enum prop_handled
4788 handle_overlay_change (struct it
*it
)
4790 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4791 return HANDLED_RECOMPUTE_PROPS
;
4793 return HANDLED_NORMALLY
;
4797 /* Set up the next overlay string for delivery by IT, if there is an
4798 overlay string to deliver. Called by set_iterator_to_next when the
4799 end of the current overlay string is reached. If there are more
4800 overlay strings to display, IT->string and
4801 IT->current.overlay_string_index are set appropriately here.
4802 Otherwise IT->string is set to nil. */
4805 next_overlay_string (struct it
*it
)
4807 ++it
->current
.overlay_string_index
;
4808 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4810 /* No more overlay strings. Restore IT's settings to what
4811 they were before overlay strings were processed, and
4812 continue to deliver from current_buffer. */
4814 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4817 || (NILP (it
->string
)
4818 && it
->method
== GET_FROM_BUFFER
4819 && it
->stop_charpos
>= BEGV
4820 && it
->stop_charpos
<= it
->end_charpos
));
4821 it
->current
.overlay_string_index
= -1;
4822 it
->n_overlay_strings
= 0;
4824 /* If we're at the end of the buffer, record that we have
4825 processed the overlay strings there already, so that
4826 next_element_from_buffer doesn't try it again. */
4827 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4828 it
->overlay_strings_at_end_processed_p
= 1;
4832 /* There are more overlay strings to process. If
4833 IT->current.overlay_string_index has advanced to a position
4834 where we must load IT->overlay_strings with more strings, do
4836 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4838 if (it
->current
.overlay_string_index
&& i
== 0)
4839 load_overlay_strings (it
, 0);
4841 /* Initialize IT to deliver display elements from the overlay
4843 it
->string
= it
->overlay_strings
[i
];
4844 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4845 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4846 it
->method
= GET_FROM_STRING
;
4847 it
->stop_charpos
= 0;
4848 if (it
->cmp_it
.stop_pos
>= 0)
4849 it
->cmp_it
.stop_pos
= 0;
4856 /* Compare two overlay_entry structures E1 and E2. Used as a
4857 comparison function for qsort in load_overlay_strings. Overlay
4858 strings for the same position are sorted so that
4860 1. All after-strings come in front of before-strings, except
4861 when they come from the same overlay.
4863 2. Within after-strings, strings are sorted so that overlay strings
4864 from overlays with higher priorities come first.
4866 2. Within before-strings, strings are sorted so that overlay
4867 strings from overlays with higher priorities come last.
4869 Value is analogous to strcmp. */
4873 compare_overlay_entries (const void *e1
, const void *e2
)
4875 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4876 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4879 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4881 /* Let after-strings appear in front of before-strings if
4882 they come from different overlays. */
4883 if (EQ (entry1
->overlay
, entry2
->overlay
))
4884 result
= entry1
->after_string_p
? 1 : -1;
4886 result
= entry1
->after_string_p
? -1 : 1;
4888 else if (entry1
->after_string_p
)
4889 /* After-strings sorted in order of decreasing priority. */
4890 result
= entry2
->priority
- entry1
->priority
;
4892 /* Before-strings sorted in order of increasing priority. */
4893 result
= entry1
->priority
- entry2
->priority
;
4899 /* Load the vector IT->overlay_strings with overlay strings from IT's
4900 current buffer position, or from CHARPOS if that is > 0. Set
4901 IT->n_overlays to the total number of overlay strings found.
4903 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4904 a time. On entry into load_overlay_strings,
4905 IT->current.overlay_string_index gives the number of overlay
4906 strings that have already been loaded by previous calls to this
4909 IT->add_overlay_start contains an additional overlay start
4910 position to consider for taking overlay strings from, if non-zero.
4911 This position comes into play when the overlay has an `invisible'
4912 property, and both before and after-strings. When we've skipped to
4913 the end of the overlay, because of its `invisible' property, we
4914 nevertheless want its before-string to appear.
4915 IT->add_overlay_start will contain the overlay start position
4918 Overlay strings are sorted so that after-string strings come in
4919 front of before-string strings. Within before and after-strings,
4920 strings are sorted by overlay priority. See also function
4921 compare_overlay_entries. */
4924 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4926 Lisp_Object overlay
, window
, str
, invisible
;
4927 struct Lisp_Overlay
*ov
;
4928 EMACS_INT start
, end
;
4930 int n
= 0, i
, j
, invis_p
;
4931 struct overlay_entry
*entries
4932 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4935 charpos
= IT_CHARPOS (*it
);
4937 /* Append the overlay string STRING of overlay OVERLAY to vector
4938 `entries' which has size `size' and currently contains `n'
4939 elements. AFTER_P non-zero means STRING is an after-string of
4941 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4944 Lisp_Object priority; \
4948 int new_size = 2 * size; \
4949 struct overlay_entry *old = entries; \
4951 (struct overlay_entry *) alloca (new_size \
4952 * sizeof *entries); \
4953 memcpy (entries, old, size * sizeof *entries); \
4957 entries[n].string = (STRING); \
4958 entries[n].overlay = (OVERLAY); \
4959 priority = Foverlay_get ((OVERLAY), Qpriority); \
4960 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4961 entries[n].after_string_p = (AFTER_P); \
4966 /* Process overlay before the overlay center. */
4967 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4969 XSETMISC (overlay
, ov
);
4970 xassert (OVERLAYP (overlay
));
4971 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4972 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4977 /* Skip this overlay if it doesn't start or end at IT's current
4979 if (end
!= charpos
&& start
!= charpos
)
4982 /* Skip this overlay if it doesn't apply to IT->w. */
4983 window
= Foverlay_get (overlay
, Qwindow
);
4984 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4987 /* If the text ``under'' the overlay is invisible, both before-
4988 and after-strings from this overlay are visible; start and
4989 end position are indistinguishable. */
4990 invisible
= Foverlay_get (overlay
, Qinvisible
);
4991 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4993 /* If overlay has a non-empty before-string, record it. */
4994 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4995 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4997 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4999 /* If overlay has a non-empty after-string, record it. */
5000 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5001 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5003 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5006 /* Process overlays after the overlay center. */
5007 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5009 XSETMISC (overlay
, ov
);
5010 xassert (OVERLAYP (overlay
));
5011 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5012 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5014 if (start
> charpos
)
5017 /* Skip this overlay if it doesn't start or end at IT's current
5019 if (end
!= charpos
&& start
!= charpos
)
5022 /* Skip this overlay if it doesn't apply to IT->w. */
5023 window
= Foverlay_get (overlay
, Qwindow
);
5024 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5027 /* If the text ``under'' the overlay is invisible, it has a zero
5028 dimension, and both before- and after-strings apply. */
5029 invisible
= Foverlay_get (overlay
, Qinvisible
);
5030 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5032 /* If overlay has a non-empty before-string, record it. */
5033 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5034 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5036 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5038 /* If overlay has a non-empty after-string, record it. */
5039 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5040 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5042 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5045 #undef RECORD_OVERLAY_STRING
5049 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5051 /* Record the total number of strings to process. */
5052 it
->n_overlay_strings
= n
;
5054 /* IT->current.overlay_string_index is the number of overlay strings
5055 that have already been consumed by IT. Copy some of the
5056 remaining overlay strings to IT->overlay_strings. */
5058 j
= it
->current
.overlay_string_index
;
5059 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5061 it
->overlay_strings
[i
] = entries
[j
].string
;
5062 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5069 /* Get the first chunk of overlay strings at IT's current buffer
5070 position, or at CHARPOS if that is > 0. Value is non-zero if at
5071 least one overlay string was found. */
5074 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
5076 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5077 process. This fills IT->overlay_strings with strings, and sets
5078 IT->n_overlay_strings to the total number of strings to process.
5079 IT->pos.overlay_string_index has to be set temporarily to zero
5080 because load_overlay_strings needs this; it must be set to -1
5081 when no overlay strings are found because a zero value would
5082 indicate a position in the first overlay string. */
5083 it
->current
.overlay_string_index
= 0;
5084 load_overlay_strings (it
, charpos
);
5086 /* If we found overlay strings, set up IT to deliver display
5087 elements from the first one. Otherwise set up IT to deliver
5088 from current_buffer. */
5089 if (it
->n_overlay_strings
)
5091 /* Make sure we know settings in current_buffer, so that we can
5092 restore meaningful values when we're done with the overlay
5095 compute_stop_pos (it
);
5096 xassert (it
->face_id
>= 0);
5098 /* Save IT's settings. They are restored after all overlay
5099 strings have been processed. */
5100 xassert (!compute_stop_p
|| it
->sp
== 0);
5102 /* When called from handle_stop, there might be an empty display
5103 string loaded. In that case, don't bother saving it. */
5104 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5107 /* Set up IT to deliver display elements from the first overlay
5109 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5110 it
->string
= it
->overlay_strings
[0];
5111 it
->from_overlay
= Qnil
;
5112 it
->stop_charpos
= 0;
5113 xassert (STRINGP (it
->string
));
5114 it
->end_charpos
= SCHARS (it
->string
);
5115 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5116 it
->method
= GET_FROM_STRING
;
5120 it
->current
.overlay_string_index
= -1;
5125 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5128 it
->method
= GET_FROM_BUFFER
;
5130 (void) get_overlay_strings_1 (it
, charpos
, 1);
5134 /* Value is non-zero if we found at least one overlay string. */
5135 return STRINGP (it
->string
);
5140 /***********************************************************************
5141 Saving and restoring state
5142 ***********************************************************************/
5144 /* Save current settings of IT on IT->stack. Called, for example,
5145 before setting up IT for an overlay string, to be able to restore
5146 IT's settings to what they were after the overlay string has been
5150 push_it (struct it
*it
)
5152 struct iterator_stack_entry
*p
;
5154 xassert (it
->sp
< IT_STACK_SIZE
);
5155 p
= it
->stack
+ it
->sp
;
5157 p
->stop_charpos
= it
->stop_charpos
;
5158 p
->prev_stop
= it
->prev_stop
;
5159 p
->base_level_stop
= it
->base_level_stop
;
5160 p
->cmp_it
= it
->cmp_it
;
5161 xassert (it
->face_id
>= 0);
5162 p
->face_id
= it
->face_id
;
5163 p
->string
= it
->string
;
5164 p
->method
= it
->method
;
5165 p
->from_overlay
= it
->from_overlay
;
5168 case GET_FROM_IMAGE
:
5169 p
->u
.image
.object
= it
->object
;
5170 p
->u
.image
.image_id
= it
->image_id
;
5171 p
->u
.image
.slice
= it
->slice
;
5173 case GET_FROM_STRETCH
:
5174 p
->u
.stretch
.object
= it
->object
;
5177 p
->position
= it
->position
;
5178 p
->current
= it
->current
;
5179 p
->end_charpos
= it
->end_charpos
;
5180 p
->string_nchars
= it
->string_nchars
;
5182 p
->multibyte_p
= it
->multibyte_p
;
5183 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5184 p
->space_width
= it
->space_width
;
5185 p
->font_height
= it
->font_height
;
5186 p
->voffset
= it
->voffset
;
5187 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5188 p
->display_ellipsis_p
= 0;
5189 p
->line_wrap
= it
->line_wrap
;
5194 iterate_out_of_display_property (struct it
*it
)
5196 /* Maybe initialize paragraph direction. If we are at the beginning
5197 of a new paragraph, next_element_from_buffer may not have a
5198 chance to do that. */
5199 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
5200 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5201 /* prev_stop can be zero, so check against BEGV as well. */
5202 while (it
->bidi_it
.charpos
>= BEGV
5203 && it
->prev_stop
<= it
->bidi_it
.charpos
5204 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5205 bidi_move_to_visually_next (&it
->bidi_it
);
5206 /* Record the stop_pos we just crossed, for when we cross it
5208 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5209 it
->prev_stop
= CHARPOS (it
->position
);
5210 /* If we ended up not where pop_it put us, resync IT's
5211 positional members with the bidi iterator. */
5212 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5214 SET_TEXT_POS (it
->position
,
5215 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5216 it
->current
.pos
= it
->position
;
5220 /* Restore IT's settings from IT->stack. Called, for example, when no
5221 more overlay strings must be processed, and we return to delivering
5222 display elements from a buffer, or when the end of a string from a
5223 `display' property is reached and we return to delivering display
5224 elements from an overlay string, or from a buffer. */
5227 pop_it (struct it
*it
)
5229 struct iterator_stack_entry
*p
;
5231 xassert (it
->sp
> 0);
5233 p
= it
->stack
+ it
->sp
;
5234 it
->stop_charpos
= p
->stop_charpos
;
5235 it
->prev_stop
= p
->prev_stop
;
5236 it
->base_level_stop
= p
->base_level_stop
;
5237 it
->cmp_it
= p
->cmp_it
;
5238 it
->face_id
= p
->face_id
;
5239 it
->current
= p
->current
;
5240 it
->position
= p
->position
;
5241 it
->string
= p
->string
;
5242 it
->from_overlay
= p
->from_overlay
;
5243 if (NILP (it
->string
))
5244 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5245 it
->method
= p
->method
;
5248 case GET_FROM_IMAGE
:
5249 it
->image_id
= p
->u
.image
.image_id
;
5250 it
->object
= p
->u
.image
.object
;
5251 it
->slice
= p
->u
.image
.slice
;
5253 case GET_FROM_STRETCH
:
5254 it
->object
= p
->u
.comp
.object
;
5256 case GET_FROM_BUFFER
:
5257 it
->object
= it
->w
->buffer
;
5260 /* Bidi-iterate until we get out of the portion of text, if
5261 any, covered by a `display' text property or an overlay
5262 with `display' property. (We cannot just jump there,
5263 because the internal coherency of the bidi iterator state
5264 can not be preserved across such jumps.) We also must
5265 determine the paragraph base direction if the overlay we
5266 just processed is at the beginning of a new
5268 iterate_out_of_display_property (it
);
5271 case GET_FROM_STRING
:
5272 it
->object
= it
->string
;
5274 case GET_FROM_DISPLAY_VECTOR
:
5276 it
->method
= GET_FROM_C_STRING
;
5277 else if (STRINGP (it
->string
))
5278 it
->method
= GET_FROM_STRING
;
5281 it
->method
= GET_FROM_BUFFER
;
5282 it
->object
= it
->w
->buffer
;
5285 it
->end_charpos
= p
->end_charpos
;
5286 it
->string_nchars
= p
->string_nchars
;
5288 it
->multibyte_p
= p
->multibyte_p
;
5289 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5290 it
->space_width
= p
->space_width
;
5291 it
->font_height
= p
->font_height
;
5292 it
->voffset
= p
->voffset
;
5293 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5294 it
->line_wrap
= p
->line_wrap
;
5299 /***********************************************************************
5301 ***********************************************************************/
5303 /* Set IT's current position to the previous line start. */
5306 back_to_previous_line_start (struct it
*it
)
5308 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5309 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5313 /* Move IT to the next line start.
5315 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5316 we skipped over part of the text (as opposed to moving the iterator
5317 continuously over the text). Otherwise, don't change the value
5320 Newlines may come from buffer text, overlay strings, or strings
5321 displayed via the `display' property. That's the reason we can't
5322 simply use find_next_newline_no_quit.
5324 Note that this function may not skip over invisible text that is so
5325 because of text properties and immediately follows a newline. If
5326 it would, function reseat_at_next_visible_line_start, when called
5327 from set_iterator_to_next, would effectively make invisible
5328 characters following a newline part of the wrong glyph row, which
5329 leads to wrong cursor motion. */
5332 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5334 int old_selective
, newline_found_p
, n
;
5335 const int MAX_NEWLINE_DISTANCE
= 500;
5337 /* If already on a newline, just consume it to avoid unintended
5338 skipping over invisible text below. */
5339 if (it
->what
== IT_CHARACTER
5341 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5343 set_iterator_to_next (it
, 0);
5348 /* Don't handle selective display in the following. It's (a)
5349 unnecessary because it's done by the caller, and (b) leads to an
5350 infinite recursion because next_element_from_ellipsis indirectly
5351 calls this function. */
5352 old_selective
= it
->selective
;
5355 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5356 from buffer text. */
5357 for (n
= newline_found_p
= 0;
5358 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5359 n
+= STRINGP (it
->string
) ? 0 : 1)
5361 if (!get_next_display_element (it
))
5363 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5364 set_iterator_to_next (it
, 0);
5367 /* If we didn't find a newline near enough, see if we can use a
5369 if (!newline_found_p
)
5371 EMACS_INT start
= IT_CHARPOS (*it
);
5372 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5375 xassert (!STRINGP (it
->string
));
5377 /* If there isn't any `display' property in sight, and no
5378 overlays, we can just use the position of the newline in
5380 if (it
->stop_charpos
>= limit
5381 || ((pos
= Fnext_single_property_change (make_number (start
),
5383 Qnil
, make_number (limit
)),
5385 && next_overlay_change (start
) == ZV
))
5387 IT_CHARPOS (*it
) = limit
;
5388 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5389 *skipped_p
= newline_found_p
= 1;
5393 while (get_next_display_element (it
)
5394 && !newline_found_p
)
5396 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5397 set_iterator_to_next (it
, 0);
5402 it
->selective
= old_selective
;
5403 return newline_found_p
;
5407 /* Set IT's current position to the previous visible line start. Skip
5408 invisible text that is so either due to text properties or due to
5409 selective display. Caution: this does not change IT->current_x and
5413 back_to_previous_visible_line_start (struct it
*it
)
5415 while (IT_CHARPOS (*it
) > BEGV
)
5417 back_to_previous_line_start (it
);
5419 if (IT_CHARPOS (*it
) <= BEGV
)
5422 /* If selective > 0, then lines indented more than its value are
5424 if (it
->selective
> 0
5425 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5426 (double) it
->selective
)) /* iftc */
5429 /* Check the newline before point for invisibility. */
5432 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5433 Qinvisible
, it
->window
);
5434 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5438 if (IT_CHARPOS (*it
) <= BEGV
)
5445 Lisp_Object val
, overlay
;
5447 /* If newline is part of a composition, continue from start of composition */
5448 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5449 && beg
< IT_CHARPOS (*it
))
5452 /* If newline is replaced by a display property, find start of overlay
5453 or interval and continue search from that point. */
5455 pos
= --IT_CHARPOS (it2
);
5458 it2
.string_from_display_prop_p
= 0;
5459 if (handle_display_prop (&it2
) == HANDLED_RETURN
5460 && !NILP (val
= get_char_property_and_overlay
5461 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5462 && (OVERLAYP (overlay
)
5463 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5464 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5467 /* Newline is not replaced by anything -- so we are done. */
5473 IT_CHARPOS (*it
) = beg
;
5474 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5478 it
->continuation_lines_width
= 0;
5480 xassert (IT_CHARPOS (*it
) >= BEGV
);
5481 xassert (IT_CHARPOS (*it
) == BEGV
5482 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5487 /* Reseat iterator IT at the previous visible line start. Skip
5488 invisible text that is so either due to text properties or due to
5489 selective display. At the end, update IT's overlay information,
5490 face information etc. */
5493 reseat_at_previous_visible_line_start (struct it
*it
)
5495 back_to_previous_visible_line_start (it
);
5496 reseat (it
, it
->current
.pos
, 1);
5501 /* Reseat iterator IT on the next visible line start in the current
5502 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5503 preceding the line start. Skip over invisible text that is so
5504 because of selective display. Compute faces, overlays etc at the
5505 new position. Note that this function does not skip over text that
5506 is invisible because of text properties. */
5509 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5511 int newline_found_p
, skipped_p
= 0;
5513 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5515 /* Skip over lines that are invisible because they are indented
5516 more than the value of IT->selective. */
5517 if (it
->selective
> 0)
5518 while (IT_CHARPOS (*it
) < ZV
5519 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5520 (double) it
->selective
)) /* iftc */
5522 xassert (IT_BYTEPOS (*it
) == BEGV
5523 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5524 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5527 /* Position on the newline if that's what's requested. */
5528 if (on_newline_p
&& newline_found_p
)
5530 if (STRINGP (it
->string
))
5532 if (IT_STRING_CHARPOS (*it
) > 0)
5534 --IT_STRING_CHARPOS (*it
);
5535 --IT_STRING_BYTEPOS (*it
);
5538 else if (IT_CHARPOS (*it
) > BEGV
)
5542 reseat (it
, it
->current
.pos
, 0);
5546 reseat (it
, it
->current
.pos
, 0);
5553 /***********************************************************************
5554 Changing an iterator's position
5555 ***********************************************************************/
5557 /* Change IT's current position to POS in current_buffer. If FORCE_P
5558 is non-zero, always check for text properties at the new position.
5559 Otherwise, text properties are only looked up if POS >=
5560 IT->check_charpos of a property. */
5563 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5565 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5567 reseat_1 (it
, pos
, 0);
5569 /* Determine where to check text properties. Avoid doing it
5570 where possible because text property lookup is very expensive. */
5572 || CHARPOS (pos
) > it
->stop_charpos
5573 || CHARPOS (pos
) < original_pos
)
5577 /* For bidi iteration, we need to prime prev_stop and
5578 base_level_stop with our best estimations. */
5579 if (CHARPOS (pos
) < it
->prev_stop
)
5581 handle_stop_backwards (it
, BEGV
);
5582 if (CHARPOS (pos
) < it
->base_level_stop
)
5583 it
->base_level_stop
= 0;
5585 else if (CHARPOS (pos
) > it
->stop_charpos
5586 && it
->stop_charpos
>= BEGV
)
5587 handle_stop_backwards (it
, it
->stop_charpos
);
5594 it
->prev_stop
= it
->base_level_stop
= 0;
5603 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5604 IT->stop_pos to POS, also. */
5607 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5609 /* Don't call this function when scanning a C string. */
5610 xassert (it
->s
== NULL
);
5612 /* POS must be a reasonable value. */
5613 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5615 it
->current
.pos
= it
->position
= pos
;
5616 it
->end_charpos
= ZV
;
5618 it
->current
.dpvec_index
= -1;
5619 it
->current
.overlay_string_index
= -1;
5620 IT_STRING_CHARPOS (*it
) = -1;
5621 IT_STRING_BYTEPOS (*it
) = -1;
5623 it
->string_from_display_prop_p
= 0;
5624 it
->method
= GET_FROM_BUFFER
;
5625 it
->object
= it
->w
->buffer
;
5626 it
->area
= TEXT_AREA
;
5627 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5629 it
->string_from_display_prop_p
= 0;
5630 it
->face_before_selective_p
= 0;
5633 it
->bidi_it
.first_elt
= 1;
5634 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5639 it
->stop_charpos
= CHARPOS (pos
);
5640 it
->base_level_stop
= CHARPOS (pos
);
5645 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5646 If S is non-null, it is a C string to iterate over. Otherwise,
5647 STRING gives a Lisp string to iterate over.
5649 If PRECISION > 0, don't return more then PRECISION number of
5650 characters from the string.
5652 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5653 characters have been returned. FIELD_WIDTH < 0 means an infinite
5656 MULTIBYTE = 0 means disable processing of multibyte characters,
5657 MULTIBYTE > 0 means enable it,
5658 MULTIBYTE < 0 means use IT->multibyte_p.
5660 IT must be initialized via a prior call to init_iterator before
5661 calling this function. */
5664 reseat_to_string (struct it
*it
, const unsigned char *s
, Lisp_Object string
,
5665 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5668 /* No region in strings. */
5669 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5671 /* No text property checks performed by default, but see below. */
5672 it
->stop_charpos
= -1;
5674 /* Set iterator position and end position. */
5675 memset (&it
->current
, 0, sizeof it
->current
);
5676 it
->current
.overlay_string_index
= -1;
5677 it
->current
.dpvec_index
= -1;
5678 xassert (charpos
>= 0);
5680 /* If STRING is specified, use its multibyteness, otherwise use the
5681 setting of MULTIBYTE, if specified. */
5683 it
->multibyte_p
= multibyte
> 0;
5687 xassert (STRINGP (string
));
5688 it
->string
= string
;
5690 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5691 it
->method
= GET_FROM_STRING
;
5692 it
->current
.string_pos
= string_pos (charpos
, string
);
5699 /* Note that we use IT->current.pos, not it->current.string_pos,
5700 for displaying C strings. */
5701 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5702 if (it
->multibyte_p
)
5704 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5705 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5709 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5710 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5713 it
->method
= GET_FROM_C_STRING
;
5716 /* PRECISION > 0 means don't return more than PRECISION characters
5718 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5719 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5721 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5722 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5723 FIELD_WIDTH < 0 means infinite field width. This is useful for
5724 padding with `-' at the end of a mode line. */
5725 if (field_width
< 0)
5726 field_width
= INFINITY
;
5727 if (field_width
> it
->end_charpos
- charpos
)
5728 it
->end_charpos
= charpos
+ field_width
;
5730 /* Use the standard display table for displaying strings. */
5731 if (DISP_TABLE_P (Vstandard_display_table
))
5732 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5734 it
->stop_charpos
= charpos
;
5735 if (s
== NULL
&& it
->multibyte_p
)
5737 EMACS_INT endpos
= SCHARS (it
->string
);
5738 if (endpos
> it
->end_charpos
)
5739 endpos
= it
->end_charpos
;
5740 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5748 /***********************************************************************
5750 ***********************************************************************/
5752 /* Map enum it_method value to corresponding next_element_from_* function. */
5754 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5756 next_element_from_buffer
,
5757 next_element_from_display_vector
,
5758 next_element_from_string
,
5759 next_element_from_c_string
,
5760 next_element_from_image
,
5761 next_element_from_stretch
5764 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5767 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5768 (possibly with the following characters). */
5770 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5771 ((IT)->cmp_it.id >= 0 \
5772 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5773 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5774 END_CHARPOS, (IT)->w, \
5775 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5779 /* Lookup the char-table Vglyphless_char_display for character C (-1
5780 if we want information for no-font case), and return the display
5781 method symbol. By side-effect, update it->what and
5782 it->glyphless_method. This function is called from
5783 get_next_display_element for each character element, and from
5784 x_produce_glyphs when no suitable font was found. */
5787 lookup_glyphless_char_display (int c
, struct it
*it
)
5789 Lisp_Object glyphless_method
= Qnil
;
5791 if (CHAR_TABLE_P (Vglyphless_char_display
)
5792 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5793 glyphless_method
= (c
>= 0
5794 ? CHAR_TABLE_REF (Vglyphless_char_display
, c
)
5795 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
5797 if (NILP (glyphless_method
))
5800 /* The default is to display the character by a proper font. */
5802 /* The default for the no-font case is to display an empty box. */
5803 glyphless_method
= Qempty_box
;
5805 if (EQ (glyphless_method
, Qzero_width
))
5808 return glyphless_method
;
5809 /* This method can't be used for the no-font case. */
5810 glyphless_method
= Qempty_box
;
5812 if (EQ (glyphless_method
, Qthin_space
))
5813 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5814 else if (EQ (glyphless_method
, Qempty_box
))
5815 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5816 else if (EQ (glyphless_method
, Qhexa_code
))
5817 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEXA_CODE
;
5818 else if (STRINGP (glyphless_method
))
5819 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5822 /* Invalid value. We use the default method. */
5823 glyphless_method
= Qnil
;
5826 it
->what
= IT_GLYPHLESS
;
5827 return glyphless_method
;
5830 /* Load IT's display element fields with information about the next
5831 display element from the current position of IT. Value is zero if
5832 end of buffer (or C string) is reached. */
5834 static struct frame
*last_escape_glyph_frame
= NULL
;
5835 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5836 static int last_escape_glyph_merged_face_id
= 0;
5838 struct frame
*last_glyphless_glyph_frame
= NULL
;
5839 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
5840 int last_glyphless_glyph_merged_face_id
= 0;
5843 get_next_display_element (struct it
*it
)
5845 /* Non-zero means that we found a display element. Zero means that
5846 we hit the end of what we iterate over. Performance note: the
5847 function pointer `method' used here turns out to be faster than
5848 using a sequence of if-statements. */
5852 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5854 if (it
->what
== IT_CHARACTER
)
5856 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5857 and only if (a) the resolved directionality of that character
5859 /* FIXME: Do we need an exception for characters from display
5861 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5862 it
->c
= bidi_mirror_char (it
->c
);
5863 /* Map via display table or translate control characters.
5864 IT->c, IT->len etc. have been set to the next character by
5865 the function call above. If we have a display table, and it
5866 contains an entry for IT->c, translate it. Don't do this if
5867 IT->c itself comes from a display table, otherwise we could
5868 end up in an infinite recursion. (An alternative could be to
5869 count the recursion depth of this function and signal an
5870 error when a certain maximum depth is reached.) Is it worth
5872 if (success_p
&& it
->dpvec
== NULL
)
5875 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5876 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5877 nbsp_or_shy
= char_is_other
;
5878 int c
= it
->c
; /* This is the character to display. */
5880 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
5882 xassert (SINGLE_BYTE_CHAR_P (c
));
5883 if (unibyte_display_via_language_environment
)
5885 c
= DECODE_CHAR (unibyte
, c
);
5887 c
= BYTE8_TO_CHAR (it
->c
);
5890 c
= BYTE8_TO_CHAR (it
->c
);
5894 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
5897 struct Lisp_Vector
*v
= XVECTOR (dv
);
5899 /* Return the first character from the display table
5900 entry, if not empty. If empty, don't display the
5901 current character. */
5904 it
->dpvec_char_len
= it
->len
;
5905 it
->dpvec
= v
->contents
;
5906 it
->dpend
= v
->contents
+ v
->size
;
5907 it
->current
.dpvec_index
= 0;
5908 it
->dpvec_face_id
= -1;
5909 it
->saved_face_id
= it
->face_id
;
5910 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5915 set_iterator_to_next (it
, 0);
5920 if (! NILP (lookup_glyphless_char_display (c
, it
)))
5922 if (it
->what
== IT_GLYPHLESS
)
5924 /* Don't display this character. */
5925 set_iterator_to_next (it
, 0);
5929 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
5930 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
5931 : c
== 0xAD ? char_is_soft_hyphen
5934 /* Translate control characters into `\003' or `^C' form.
5935 Control characters coming from a display table entry are
5936 currently not translated because we use IT->dpvec to hold
5937 the translation. This could easily be changed but I
5938 don't believe that it is worth doing.
5940 NBSP and SOFT-HYPEN are property translated too.
5942 Non-printable characters and raw-byte characters are also
5943 translated to octal form. */
5944 if (((c
< ' ' || c
== 127) /* ASCII control chars */
5945 ? (it
->area
!= TEXT_AREA
5946 /* In mode line, treat \n, \t like other crl chars. */
5949 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5950 || (c
!= '\n' && c
!= '\t'))
5953 || ! CHAR_PRINTABLE_P (c
))))
5955 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
5956 or a non-printable character which must be displayed
5957 either as '\003' or as `^C' where the '\\' and '^'
5958 can be defined in the display table. Fill
5959 IT->ctl_chars with glyphs for what we have to
5960 display. Then, set IT->dpvec to these glyphs. */
5963 int face_id
, lface_id
= 0 ;
5966 /* Handle control characters with ^. */
5968 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
5972 g
= '^'; /* default glyph for Control */
5973 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5975 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5976 && GLYPH_CODE_CHAR_VALID_P (gc
))
5978 g
= GLYPH_CODE_CHAR (gc
);
5979 lface_id
= GLYPH_CODE_FACE (gc
);
5983 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5985 else if (it
->f
== last_escape_glyph_frame
5986 && it
->face_id
== last_escape_glyph_face_id
)
5988 face_id
= last_escape_glyph_merged_face_id
;
5992 /* Merge the escape-glyph face into the current face. */
5993 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5995 last_escape_glyph_frame
= it
->f
;
5996 last_escape_glyph_face_id
= it
->face_id
;
5997 last_escape_glyph_merged_face_id
= face_id
;
6000 XSETINT (it
->ctl_chars
[0], g
);
6001 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6003 goto display_control
;
6006 /* Handle non-break space in the mode where it only gets
6009 if (EQ (Vnobreak_char_display
, Qt
)
6010 && nbsp_or_shy
== char_is_nbsp
)
6012 /* Merge the no-break-space face into the current face. */
6013 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6017 XSETINT (it
->ctl_chars
[0], ' ');
6019 goto display_control
;
6022 /* Handle sequences that start with the "escape glyph". */
6024 /* the default escape glyph is \. */
6025 escape_glyph
= '\\';
6028 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6029 && GLYPH_CODE_CHAR_VALID_P (gc
))
6031 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6032 lface_id
= GLYPH_CODE_FACE (gc
);
6036 /* The display table specified a face.
6037 Merge it into face_id and also into escape_glyph. */
6038 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6041 else if (it
->f
== last_escape_glyph_frame
6042 && it
->face_id
== last_escape_glyph_face_id
)
6044 face_id
= last_escape_glyph_merged_face_id
;
6048 /* Merge the escape-glyph face into the current face. */
6049 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6051 last_escape_glyph_frame
= it
->f
;
6052 last_escape_glyph_face_id
= it
->face_id
;
6053 last_escape_glyph_merged_face_id
= face_id
;
6056 /* Handle soft hyphens in the mode where they only get
6059 if (EQ (Vnobreak_char_display
, Qt
)
6060 && nbsp_or_shy
== char_is_soft_hyphen
)
6062 XSETINT (it
->ctl_chars
[0], '-');
6064 goto display_control
;
6067 /* Handle non-break space and soft hyphen
6068 with the escape glyph. */
6072 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6073 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6074 XSETINT (it
->ctl_chars
[1], c
);
6076 goto display_control
;
6083 if (CHAR_BYTE8_P (c
))
6084 /* Display \200 instead of \17777600. */
6085 c
= CHAR_TO_BYTE8 (c
);
6086 len
= sprintf (str
, "%03o", c
);
6088 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6089 for (i
= 0; i
< len
; i
++)
6090 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6095 /* Set up IT->dpvec and return first character from it. */
6096 it
->dpvec_char_len
= it
->len
;
6097 it
->dpvec
= it
->ctl_chars
;
6098 it
->dpend
= it
->dpvec
+ ctl_len
;
6099 it
->current
.dpvec_index
= 0;
6100 it
->dpvec_face_id
= face_id
;
6101 it
->saved_face_id
= it
->face_id
;
6102 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6106 it
->char_to_display
= c
;
6110 it
->char_to_display
= it
->c
;
6114 #ifdef HAVE_WINDOW_SYSTEM
6115 /* Adjust face id for a multibyte character. There are no multibyte
6116 character in unibyte text. */
6117 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6120 && FRAME_WINDOW_P (it
->f
))
6122 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6124 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6126 /* Automatic composition with glyph-string. */
6127 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6129 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6133 EMACS_INT pos
= (it
->s
? -1
6134 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6135 : IT_CHARPOS (*it
));
6137 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
6144 /* Is this character the last one of a run of characters with
6145 box? If yes, set IT->end_of_box_run_p to 1. */
6149 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6151 int face_id
= underlying_face_id (it
);
6152 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6156 if (face
->box
== FACE_NO_BOX
)
6158 /* If the box comes from face properties in a
6159 display string, check faces in that string. */
6160 int string_face_id
= face_after_it_pos (it
);
6161 it
->end_of_box_run_p
6162 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6165 /* Otherwise, the box comes from the underlying face.
6166 If this is the last string character displayed, check
6167 the next buffer location. */
6168 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6169 && (it
->current
.overlay_string_index
6170 == it
->n_overlay_strings
- 1))
6174 struct text_pos pos
= it
->current
.pos
;
6175 INC_TEXT_POS (pos
, it
->multibyte_p
);
6177 next_face_id
= face_at_buffer_position
6178 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6179 it
->region_end_charpos
, &ignore
,
6180 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6182 it
->end_of_box_run_p
6183 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6190 int face_id
= face_after_it_pos (it
);
6191 it
->end_of_box_run_p
6192 = (face_id
!= it
->face_id
6193 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6197 /* Value is 0 if end of buffer or string reached. */
6202 /* Move IT to the next display element.
6204 RESEAT_P non-zero means if called on a newline in buffer text,
6205 skip to the next visible line start.
6207 Functions get_next_display_element and set_iterator_to_next are
6208 separate because I find this arrangement easier to handle than a
6209 get_next_display_element function that also increments IT's
6210 position. The way it is we can first look at an iterator's current
6211 display element, decide whether it fits on a line, and if it does,
6212 increment the iterator position. The other way around we probably
6213 would either need a flag indicating whether the iterator has to be
6214 incremented the next time, or we would have to implement a
6215 decrement position function which would not be easy to write. */
6218 set_iterator_to_next (struct it
*it
, int reseat_p
)
6220 /* Reset flags indicating start and end of a sequence of characters
6221 with box. Reset them at the start of this function because
6222 moving the iterator to a new position might set them. */
6223 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6227 case GET_FROM_BUFFER
:
6228 /* The current display element of IT is a character from
6229 current_buffer. Advance in the buffer, and maybe skip over
6230 invisible lines that are so because of selective display. */
6231 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6232 reseat_at_next_visible_line_start (it
, 0);
6233 else if (it
->cmp_it
.id
>= 0)
6235 /* We are currently getting glyphs from a composition. */
6240 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6241 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6242 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6244 it
->cmp_it
.from
= it
->cmp_it
.to
;
6249 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6251 it
->end_charpos
, Qnil
);
6254 else if (! it
->cmp_it
.reversed_p
)
6256 /* Composition created while scanning forward. */
6257 /* Update IT's char/byte positions to point to the first
6258 character of the next grapheme cluster, or to the
6259 character visually after the current composition. */
6260 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6261 bidi_move_to_visually_next (&it
->bidi_it
);
6262 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6263 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6265 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6267 /* Proceed to the next grapheme cluster. */
6268 it
->cmp_it
.from
= it
->cmp_it
.to
;
6272 /* No more grapheme clusters in this composition.
6273 Find the next stop position. */
6274 EMACS_INT stop
= it
->end_charpos
;
6275 if (it
->bidi_it
.scan_dir
< 0)
6276 /* Now we are scanning backward and don't know
6279 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6280 IT_BYTEPOS (*it
), stop
, Qnil
);
6285 /* Composition created while scanning backward. */
6286 /* Update IT's char/byte positions to point to the last
6287 character of the previous grapheme cluster, or the
6288 character visually after the current composition. */
6289 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6290 bidi_move_to_visually_next (&it
->bidi_it
);
6291 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6292 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6293 if (it
->cmp_it
.from
> 0)
6295 /* Proceed to the previous grapheme cluster. */
6296 it
->cmp_it
.to
= it
->cmp_it
.from
;
6300 /* No more grapheme clusters in this composition.
6301 Find the next stop position. */
6302 EMACS_INT stop
= it
->end_charpos
;
6303 if (it
->bidi_it
.scan_dir
< 0)
6304 /* Now we are scanning backward and don't know
6307 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6308 IT_BYTEPOS (*it
), stop
, Qnil
);
6314 xassert (it
->len
!= 0);
6318 IT_BYTEPOS (*it
) += it
->len
;
6319 IT_CHARPOS (*it
) += 1;
6323 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6324 /* If this is a new paragraph, determine its base
6325 direction (a.k.a. its base embedding level). */
6326 if (it
->bidi_it
.new_paragraph
)
6327 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6328 bidi_move_to_visually_next (&it
->bidi_it
);
6329 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6330 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6331 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6333 /* As the scan direction was changed, we must
6334 re-compute the stop position for composition. */
6335 EMACS_INT stop
= it
->end_charpos
;
6336 if (it
->bidi_it
.scan_dir
< 0)
6338 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6339 IT_BYTEPOS (*it
), stop
, Qnil
);
6342 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6346 case GET_FROM_C_STRING
:
6347 /* Current display element of IT is from a C string. */
6348 IT_BYTEPOS (*it
) += it
->len
;
6349 IT_CHARPOS (*it
) += 1;
6352 case GET_FROM_DISPLAY_VECTOR
:
6353 /* Current display element of IT is from a display table entry.
6354 Advance in the display table definition. Reset it to null if
6355 end reached, and continue with characters from buffers/
6357 ++it
->current
.dpvec_index
;
6359 /* Restore face of the iterator to what they were before the
6360 display vector entry (these entries may contain faces). */
6361 it
->face_id
= it
->saved_face_id
;
6363 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6365 int recheck_faces
= it
->ellipsis_p
;
6368 it
->method
= GET_FROM_C_STRING
;
6369 else if (STRINGP (it
->string
))
6370 it
->method
= GET_FROM_STRING
;
6373 it
->method
= GET_FROM_BUFFER
;
6374 it
->object
= it
->w
->buffer
;
6378 it
->current
.dpvec_index
= -1;
6380 /* Skip over characters which were displayed via IT->dpvec. */
6381 if (it
->dpvec_char_len
< 0)
6382 reseat_at_next_visible_line_start (it
, 1);
6383 else if (it
->dpvec_char_len
> 0)
6385 if (it
->method
== GET_FROM_STRING
6386 && it
->n_overlay_strings
> 0)
6387 it
->ignore_overlay_strings_at_pos_p
= 1;
6388 it
->len
= it
->dpvec_char_len
;
6389 set_iterator_to_next (it
, reseat_p
);
6392 /* Maybe recheck faces after display vector */
6394 it
->stop_charpos
= IT_CHARPOS (*it
);
6398 case GET_FROM_STRING
:
6399 /* Current display element is a character from a Lisp string. */
6400 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6401 if (it
->cmp_it
.id
>= 0)
6403 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6404 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6405 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6406 it
->cmp_it
.from
= it
->cmp_it
.to
;
6410 composition_compute_stop_pos (&it
->cmp_it
,
6411 IT_STRING_CHARPOS (*it
),
6412 IT_STRING_BYTEPOS (*it
),
6413 it
->end_charpos
, it
->string
);
6418 IT_STRING_BYTEPOS (*it
) += it
->len
;
6419 IT_STRING_CHARPOS (*it
) += 1;
6422 consider_string_end
:
6424 if (it
->current
.overlay_string_index
>= 0)
6426 /* IT->string is an overlay string. Advance to the
6427 next, if there is one. */
6428 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6431 next_overlay_string (it
);
6433 setup_for_ellipsis (it
, 0);
6438 /* IT->string is not an overlay string. If we reached
6439 its end, and there is something on IT->stack, proceed
6440 with what is on the stack. This can be either another
6441 string, this time an overlay string, or a buffer. */
6442 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6446 if (it
->method
== GET_FROM_STRING
)
6447 goto consider_string_end
;
6452 case GET_FROM_IMAGE
:
6453 case GET_FROM_STRETCH
:
6454 /* The position etc with which we have to proceed are on
6455 the stack. The position may be at the end of a string,
6456 if the `display' property takes up the whole string. */
6457 xassert (it
->sp
> 0);
6459 if (it
->method
== GET_FROM_STRING
)
6460 goto consider_string_end
;
6464 /* There are no other methods defined, so this should be a bug. */
6468 xassert (it
->method
!= GET_FROM_STRING
6469 || (STRINGP (it
->string
)
6470 && IT_STRING_CHARPOS (*it
) >= 0));
6473 /* Load IT's display element fields with information about the next
6474 display element which comes from a display table entry or from the
6475 result of translating a control character to one of the forms `^C'
6478 IT->dpvec holds the glyphs to return as characters.
6479 IT->saved_face_id holds the face id before the display vector--it
6480 is restored into IT->face_id in set_iterator_to_next. */
6483 next_element_from_display_vector (struct it
*it
)
6488 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6490 it
->face_id
= it
->saved_face_id
;
6492 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6493 That seemed totally bogus - so I changed it... */
6494 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6496 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6498 it
->c
= GLYPH_CODE_CHAR (gc
);
6499 it
->len
= CHAR_BYTES (it
->c
);
6501 /* The entry may contain a face id to use. Such a face id is
6502 the id of a Lisp face, not a realized face. A face id of
6503 zero means no face is specified. */
6504 if (it
->dpvec_face_id
>= 0)
6505 it
->face_id
= it
->dpvec_face_id
;
6508 int lface_id
= GLYPH_CODE_FACE (gc
);
6510 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6515 /* Display table entry is invalid. Return a space. */
6516 it
->c
= ' ', it
->len
= 1;
6518 /* Don't change position and object of the iterator here. They are
6519 still the values of the character that had this display table
6520 entry or was translated, and that's what we want. */
6521 it
->what
= IT_CHARACTER
;
6526 /* Load IT with the next display element from Lisp string IT->string.
6527 IT->current.string_pos is the current position within the string.
6528 If IT->current.overlay_string_index >= 0, the Lisp string is an
6532 next_element_from_string (struct it
*it
)
6534 struct text_pos position
;
6536 xassert (STRINGP (it
->string
));
6537 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6538 position
= it
->current
.string_pos
;
6540 /* Time to check for invisible text? */
6541 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6542 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6546 /* Since a handler may have changed IT->method, we must
6548 return GET_NEXT_DISPLAY_ELEMENT (it
);
6551 if (it
->current
.overlay_string_index
>= 0)
6553 /* Get the next character from an overlay string. In overlay
6554 strings, There is no field width or padding with spaces to
6556 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6561 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6562 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6563 && next_element_from_composition (it
))
6567 else if (STRING_MULTIBYTE (it
->string
))
6569 const unsigned char *s
= (SDATA (it
->string
)
6570 + IT_STRING_BYTEPOS (*it
));
6571 it
->c
= string_char_and_length (s
, &it
->len
);
6575 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6581 /* Get the next character from a Lisp string that is not an
6582 overlay string. Such strings come from the mode line, for
6583 example. We may have to pad with spaces, or truncate the
6584 string. See also next_element_from_c_string. */
6585 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6590 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6592 /* Pad with spaces. */
6593 it
->c
= ' ', it
->len
= 1;
6594 CHARPOS (position
) = BYTEPOS (position
) = -1;
6596 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6597 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6598 && next_element_from_composition (it
))
6602 else if (STRING_MULTIBYTE (it
->string
))
6604 const unsigned char *s
= (SDATA (it
->string
)
6605 + IT_STRING_BYTEPOS (*it
));
6606 it
->c
= string_char_and_length (s
, &it
->len
);
6610 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6615 /* Record what we have and where it came from. */
6616 it
->what
= IT_CHARACTER
;
6617 it
->object
= it
->string
;
6618 it
->position
= position
;
6623 /* Load IT with next display element from C string IT->s.
6624 IT->string_nchars is the maximum number of characters to return
6625 from the string. IT->end_charpos may be greater than
6626 IT->string_nchars when this function is called, in which case we
6627 may have to return padding spaces. Value is zero if end of string
6628 reached, including padding spaces. */
6631 next_element_from_c_string (struct it
*it
)
6636 it
->what
= IT_CHARACTER
;
6637 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6640 /* IT's position can be greater IT->string_nchars in case a field
6641 width or precision has been specified when the iterator was
6643 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6645 /* End of the game. */
6649 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6651 /* Pad with spaces. */
6652 it
->c
= ' ', it
->len
= 1;
6653 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6655 else if (it
->multibyte_p
)
6656 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6658 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6664 /* Set up IT to return characters from an ellipsis, if appropriate.
6665 The definition of the ellipsis glyphs may come from a display table
6666 entry. This function fills IT with the first glyph from the
6667 ellipsis if an ellipsis is to be displayed. */
6670 next_element_from_ellipsis (struct it
*it
)
6672 if (it
->selective_display_ellipsis_p
)
6673 setup_for_ellipsis (it
, it
->len
);
6676 /* The face at the current position may be different from the
6677 face we find after the invisible text. Remember what it
6678 was in IT->saved_face_id, and signal that it's there by
6679 setting face_before_selective_p. */
6680 it
->saved_face_id
= it
->face_id
;
6681 it
->method
= GET_FROM_BUFFER
;
6682 it
->object
= it
->w
->buffer
;
6683 reseat_at_next_visible_line_start (it
, 1);
6684 it
->face_before_selective_p
= 1;
6687 return GET_NEXT_DISPLAY_ELEMENT (it
);
6691 /* Deliver an image display element. The iterator IT is already
6692 filled with image information (done in handle_display_prop). Value
6697 next_element_from_image (struct it
*it
)
6699 it
->what
= IT_IMAGE
;
6700 it
->ignore_overlay_strings_at_pos_p
= 0;
6705 /* Fill iterator IT with next display element from a stretch glyph
6706 property. IT->object is the value of the text property. Value is
6710 next_element_from_stretch (struct it
*it
)
6712 it
->what
= IT_STRETCH
;
6716 /* Scan forward from CHARPOS in the current buffer, until we find a
6717 stop position > current IT's position. Then handle the stop
6718 position before that. This is called when we bump into a stop
6719 position while reordering bidirectional text. CHARPOS should be
6720 the last previously processed stop_pos (or BEGV, if none were
6721 processed yet) whose position is less that IT's current
6725 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
6727 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6728 struct display_pos save_current
= it
->current
;
6729 struct text_pos save_position
= it
->position
;
6730 struct text_pos pos1
;
6731 EMACS_INT next_stop
;
6733 /* Scan in strict logical order. */
6737 it
->prev_stop
= charpos
;
6738 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6739 reseat_1 (it
, pos1
, 0);
6740 compute_stop_pos (it
);
6741 /* We must advance forward, right? */
6742 if (it
->stop_charpos
<= it
->prev_stop
)
6744 charpos
= it
->stop_charpos
;
6746 while (charpos
<= where_we_are
);
6748 next_stop
= it
->stop_charpos
;
6749 it
->stop_charpos
= it
->prev_stop
;
6751 it
->current
= save_current
;
6752 it
->position
= save_position
;
6754 it
->stop_charpos
= next_stop
;
6757 /* Load IT with the next display element from current_buffer. Value
6758 is zero if end of buffer reached. IT->stop_charpos is the next
6759 position at which to stop and check for text properties or buffer
6763 next_element_from_buffer (struct it
*it
)
6767 xassert (IT_CHARPOS (*it
) >= BEGV
);
6769 /* With bidi reordering, the character to display might not be the
6770 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6771 we were reseat()ed to a new buffer position, which is potentially
6772 a different paragraph. */
6773 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6775 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6776 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6777 if (it
->bidi_it
.bytepos
== ZV_BYTE
)
6779 /* Nothing to do, but reset the FIRST_ELT flag, like
6780 bidi_paragraph_init does, because we are not going to
6782 it
->bidi_it
.first_elt
= 0;
6784 else if (it
->bidi_it
.bytepos
== BEGV_BYTE
6785 /* FIXME: Should support all Unicode line separators. */
6786 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6787 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6789 /* If we are at the beginning of a line, we can produce the
6790 next element right away. */
6791 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6792 bidi_move_to_visually_next (&it
->bidi_it
);
6796 EMACS_INT orig_bytepos
= IT_BYTEPOS (*it
);
6798 /* We need to prime the bidi iterator starting at the line's
6799 beginning, before we will be able to produce the next
6801 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6802 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6803 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6804 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6805 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6808 /* Now return to buffer position where we were asked to
6809 get the next display element, and produce that. */
6810 bidi_move_to_visually_next (&it
->bidi_it
);
6812 while (it
->bidi_it
.bytepos
!= orig_bytepos
6813 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6816 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6817 /* Adjust IT's position information to where we ended up. */
6818 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6819 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6820 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6822 EMACS_INT stop
= it
->end_charpos
;
6823 if (it
->bidi_it
.scan_dir
< 0)
6825 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6826 IT_BYTEPOS (*it
), stop
, Qnil
);
6830 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6832 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6834 int overlay_strings_follow_p
;
6836 /* End of the game, except when overlay strings follow that
6837 haven't been returned yet. */
6838 if (it
->overlay_strings_at_end_processed_p
)
6839 overlay_strings_follow_p
= 0;
6842 it
->overlay_strings_at_end_processed_p
= 1;
6843 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6846 if (overlay_strings_follow_p
)
6847 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6851 it
->position
= it
->current
.pos
;
6855 else if (!(!it
->bidi_p
6856 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6857 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6859 /* With bidi non-linear iteration, we could find ourselves
6860 far beyond the last computed stop_charpos, with several
6861 other stop positions in between that we missed. Scan
6862 them all now, in buffer's logical order, until we find
6863 and handle the last stop_charpos that precedes our
6864 current position. */
6865 handle_stop_backwards (it
, it
->stop_charpos
);
6866 return GET_NEXT_DISPLAY_ELEMENT (it
);
6872 /* Take note of the stop position we just moved across,
6873 for when we will move back across it. */
6874 it
->prev_stop
= it
->stop_charpos
;
6875 /* If we are at base paragraph embedding level, take
6876 note of the last stop position seen at this
6878 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6879 it
->base_level_stop
= it
->stop_charpos
;
6882 return GET_NEXT_DISPLAY_ELEMENT (it
);
6886 /* We can sometimes back up for reasons that have nothing
6887 to do with bidi reordering. E.g., compositions. The
6888 code below is only needed when we are above the base
6889 embedding level, so test for that explicitly. */
6890 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6891 && IT_CHARPOS (*it
) < it
->prev_stop
)
6893 if (it
->base_level_stop
<= 0)
6894 it
->base_level_stop
= BEGV
;
6895 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6897 handle_stop_backwards (it
, it
->base_level_stop
);
6898 return GET_NEXT_DISPLAY_ELEMENT (it
);
6902 /* No face changes, overlays etc. in sight, so just return a
6903 character from current_buffer. */
6907 /* Maybe run the redisplay end trigger hook. Performance note:
6908 This doesn't seem to cost measurable time. */
6909 if (it
->redisplay_end_trigger_charpos
6911 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6912 run_redisplay_end_trigger_hook (it
);
6914 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
6915 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6917 && next_element_from_composition (it
))
6922 /* Get the next character, maybe multibyte. */
6923 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6924 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6925 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6927 it
->c
= *p
, it
->len
= 1;
6929 /* Record what we have and where it came from. */
6930 it
->what
= IT_CHARACTER
;
6931 it
->object
= it
->w
->buffer
;
6932 it
->position
= it
->current
.pos
;
6934 /* Normally we return the character found above, except when we
6935 really want to return an ellipsis for selective display. */
6940 /* A value of selective > 0 means hide lines indented more
6941 than that number of columns. */
6942 if (it
->selective
> 0
6943 && IT_CHARPOS (*it
) + 1 < ZV
6944 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6945 IT_BYTEPOS (*it
) + 1,
6946 (double) it
->selective
)) /* iftc */
6948 success_p
= next_element_from_ellipsis (it
);
6949 it
->dpvec_char_len
= -1;
6952 else if (it
->c
== '\r' && it
->selective
== -1)
6954 /* A value of selective == -1 means that everything from the
6955 CR to the end of the line is invisible, with maybe an
6956 ellipsis displayed for it. */
6957 success_p
= next_element_from_ellipsis (it
);
6958 it
->dpvec_char_len
= -1;
6963 /* Value is zero if end of buffer reached. */
6964 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6969 /* Run the redisplay end trigger hook for IT. */
6972 run_redisplay_end_trigger_hook (struct it
*it
)
6974 Lisp_Object args
[3];
6976 /* IT->glyph_row should be non-null, i.e. we should be actually
6977 displaying something, or otherwise we should not run the hook. */
6978 xassert (it
->glyph_row
);
6980 /* Set up hook arguments. */
6981 args
[0] = Qredisplay_end_trigger_functions
;
6982 args
[1] = it
->window
;
6983 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6984 it
->redisplay_end_trigger_charpos
= 0;
6986 /* Since we are *trying* to run these functions, don't try to run
6987 them again, even if they get an error. */
6988 it
->w
->redisplay_end_trigger
= Qnil
;
6989 Frun_hook_with_args (3, args
);
6991 /* Notice if it changed the face of the character we are on. */
6992 handle_face_prop (it
);
6996 /* Deliver a composition display element. Unlike the other
6997 next_element_from_XXX, this function is not registered in the array
6998 get_next_element[]. It is called from next_element_from_buffer and
6999 next_element_from_string when necessary. */
7002 next_element_from_composition (struct it
*it
)
7004 it
->what
= IT_COMPOSITION
;
7005 it
->len
= it
->cmp_it
.nbytes
;
7006 if (STRINGP (it
->string
))
7010 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7011 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7014 it
->position
= it
->current
.string_pos
;
7015 it
->object
= it
->string
;
7016 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7017 IT_STRING_BYTEPOS (*it
), it
->string
);
7023 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7024 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7027 if (it
->bidi_it
.new_paragraph
)
7028 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7029 /* Resync the bidi iterator with IT's new position.
7030 FIXME: this doesn't support bidirectional text. */
7031 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7032 bidi_move_to_visually_next (&it
->bidi_it
);
7036 it
->position
= it
->current
.pos
;
7037 it
->object
= it
->w
->buffer
;
7038 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7039 IT_BYTEPOS (*it
), Qnil
);
7046 /***********************************************************************
7047 Moving an iterator without producing glyphs
7048 ***********************************************************************/
7050 /* Check if iterator is at a position corresponding to a valid buffer
7051 position after some move_it_ call. */
7053 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7054 ((it)->method == GET_FROM_STRING \
7055 ? IT_STRING_CHARPOS (*it) == 0 \
7059 /* Move iterator IT to a specified buffer or X position within one
7060 line on the display without producing glyphs.
7062 OP should be a bit mask including some or all of these bits:
7063 MOVE_TO_X: Stop upon reaching x-position TO_X.
7064 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7065 Regardless of OP's value, stop upon reaching the end of the display line.
7067 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7068 This means, in particular, that TO_X includes window's horizontal
7071 The return value has several possible values that
7072 say what condition caused the scan to stop:
7074 MOVE_POS_MATCH_OR_ZV
7075 - when TO_POS or ZV was reached.
7078 -when TO_X was reached before TO_POS or ZV were reached.
7081 - when we reached the end of the display area and the line must
7085 - when we reached the end of the display area and the line is
7089 - when we stopped at a line end, i.e. a newline or a CR and selective
7092 static enum move_it_result
7093 move_it_in_display_line_to (struct it
*it
,
7094 EMACS_INT to_charpos
, int to_x
,
7095 enum move_operation_enum op
)
7097 enum move_it_result result
= MOVE_UNDEFINED
;
7098 struct glyph_row
*saved_glyph_row
;
7099 struct it wrap_it
, atpos_it
, atx_it
;
7101 enum it_method prev_method
= it
->method
;
7102 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7104 /* Don't produce glyphs in produce_glyphs. */
7105 saved_glyph_row
= it
->glyph_row
;
7106 it
->glyph_row
= NULL
;
7108 /* Use wrap_it to save a copy of IT wherever a word wrap could
7109 occur. Use atpos_it to save a copy of IT at the desired buffer
7110 position, if found, so that we can scan ahead and check if the
7111 word later overshoots the window edge. Use atx_it similarly, for
7117 #define BUFFER_POS_REACHED_P() \
7118 ((op & MOVE_TO_POS) != 0 \
7119 && BUFFERP (it->object) \
7120 && (IT_CHARPOS (*it) == to_charpos \
7121 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
7122 && (it->method == GET_FROM_BUFFER \
7123 || (it->method == GET_FROM_DISPLAY_VECTOR \
7124 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7126 /* If there's a line-/wrap-prefix, handle it. */
7127 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7128 && it
->current_y
< it
->last_visible_y
)
7129 handle_line_prefix (it
);
7133 int x
, i
, ascent
= 0, descent
= 0;
7135 /* Utility macro to reset an iterator with x, ascent, and descent. */
7136 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7137 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7138 (IT)->max_descent = descent)
7140 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7142 if ((op
& MOVE_TO_POS
) != 0
7143 && BUFFERP (it
->object
)
7144 && it
->method
== GET_FROM_BUFFER
7145 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7147 && (prev_method
== GET_FROM_IMAGE
7148 || prev_method
== GET_FROM_STRETCH
)
7149 /* Passed TO_CHARPOS from left to right. */
7150 && ((prev_pos
< to_charpos
7151 && IT_CHARPOS (*it
) > to_charpos
)
7152 /* Passed TO_CHARPOS from right to left. */
7153 || (prev_pos
> to_charpos
7154 && IT_CHARPOS (*it
) < to_charpos
)))))
7156 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7158 result
= MOVE_POS_MATCH_OR_ZV
;
7161 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7162 /* If wrap_it is valid, the current position might be in a
7163 word that is wrapped. So, save the iterator in
7164 atpos_it and continue to see if wrapping happens. */
7168 prev_method
= it
->method
;
7169 if (it
->method
== GET_FROM_BUFFER
)
7170 prev_pos
= IT_CHARPOS (*it
);
7171 /* Stop when ZV reached.
7172 We used to stop here when TO_CHARPOS reached as well, but that is
7173 too soon if this glyph does not fit on this line. So we handle it
7174 explicitly below. */
7175 if (!get_next_display_element (it
))
7177 result
= MOVE_POS_MATCH_OR_ZV
;
7181 if (it
->line_wrap
== TRUNCATE
)
7183 if (BUFFER_POS_REACHED_P ())
7185 result
= MOVE_POS_MATCH_OR_ZV
;
7191 if (it
->line_wrap
== WORD_WRAP
)
7193 if (IT_DISPLAYING_WHITESPACE (it
))
7197 /* We have reached a glyph that follows one or more
7198 whitespace characters. If the position is
7199 already found, we are done. */
7200 if (atpos_it
.sp
>= 0)
7203 result
= MOVE_POS_MATCH_OR_ZV
;
7209 result
= MOVE_X_REACHED
;
7212 /* Otherwise, we can wrap here. */
7219 /* Remember the line height for the current line, in case
7220 the next element doesn't fit on the line. */
7221 ascent
= it
->max_ascent
;
7222 descent
= it
->max_descent
;
7224 /* The call to produce_glyphs will get the metrics of the
7225 display element IT is loaded with. Record the x-position
7226 before this display element, in case it doesn't fit on the
7230 PRODUCE_GLYPHS (it
);
7232 if (it
->area
!= TEXT_AREA
)
7234 set_iterator_to_next (it
, 1);
7238 /* The number of glyphs we get back in IT->nglyphs will normally
7239 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7240 character on a terminal frame, or (iii) a line end. For the
7241 second case, IT->nglyphs - 1 padding glyphs will be present.
7242 (On X frames, there is only one glyph produced for a
7243 composite character.)
7245 The behavior implemented below means, for continuation lines,
7246 that as many spaces of a TAB as fit on the current line are
7247 displayed there. For terminal frames, as many glyphs of a
7248 multi-glyph character are displayed in the current line, too.
7249 This is what the old redisplay code did, and we keep it that
7250 way. Under X, the whole shape of a complex character must
7251 fit on the line or it will be completely displayed in the
7254 Note that both for tabs and padding glyphs, all glyphs have
7258 /* More than one glyph or glyph doesn't fit on line. All
7259 glyphs have the same width. */
7260 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7262 int x_before_this_char
= x
;
7263 int hpos_before_this_char
= it
->hpos
;
7265 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7267 new_x
= x
+ single_glyph_width
;
7269 /* We want to leave anything reaching TO_X to the caller. */
7270 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7272 if (BUFFER_POS_REACHED_P ())
7274 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7275 goto buffer_pos_reached
;
7276 if (atpos_it
.sp
< 0)
7279 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7284 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7287 result
= MOVE_X_REACHED
;
7293 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7298 if (/* Lines are continued. */
7299 it
->line_wrap
!= TRUNCATE
7300 && (/* And glyph doesn't fit on the line. */
7301 new_x
> it
->last_visible_x
7302 /* Or it fits exactly and we're on a window
7304 || (new_x
== it
->last_visible_x
7305 && FRAME_WINDOW_P (it
->f
))))
7307 if (/* IT->hpos == 0 means the very first glyph
7308 doesn't fit on the line, e.g. a wide image. */
7310 || (new_x
== it
->last_visible_x
7311 && FRAME_WINDOW_P (it
->f
)))
7314 it
->current_x
= new_x
;
7316 /* The character's last glyph just barely fits
7318 if (i
== it
->nglyphs
- 1)
7320 /* If this is the destination position,
7321 return a position *before* it in this row,
7322 now that we know it fits in this row. */
7323 if (BUFFER_POS_REACHED_P ())
7325 if (it
->line_wrap
!= WORD_WRAP
7328 it
->hpos
= hpos_before_this_char
;
7329 it
->current_x
= x_before_this_char
;
7330 result
= MOVE_POS_MATCH_OR_ZV
;
7333 if (it
->line_wrap
== WORD_WRAP
7337 atpos_it
.current_x
= x_before_this_char
;
7338 atpos_it
.hpos
= hpos_before_this_char
;
7342 set_iterator_to_next (it
, 1);
7343 /* On graphical terminals, newlines may
7344 "overflow" into the fringe if
7345 overflow-newline-into-fringe is non-nil.
7346 On text-only terminals, newlines may
7347 overflow into the last glyph on the
7349 if (!FRAME_WINDOW_P (it
->f
)
7350 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7352 if (!get_next_display_element (it
))
7354 result
= MOVE_POS_MATCH_OR_ZV
;
7357 if (BUFFER_POS_REACHED_P ())
7359 if (ITERATOR_AT_END_OF_LINE_P (it
))
7360 result
= MOVE_POS_MATCH_OR_ZV
;
7362 result
= MOVE_LINE_CONTINUED
;
7365 if (ITERATOR_AT_END_OF_LINE_P (it
))
7367 result
= MOVE_NEWLINE_OR_CR
;
7374 IT_RESET_X_ASCENT_DESCENT (it
);
7376 if (wrap_it
.sp
>= 0)
7383 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7385 result
= MOVE_LINE_CONTINUED
;
7389 if (BUFFER_POS_REACHED_P ())
7391 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7392 goto buffer_pos_reached
;
7393 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7396 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7400 if (new_x
> it
->first_visible_x
)
7402 /* Glyph is visible. Increment number of glyphs that
7403 would be displayed. */
7408 if (result
!= MOVE_UNDEFINED
)
7411 else if (BUFFER_POS_REACHED_P ())
7414 IT_RESET_X_ASCENT_DESCENT (it
);
7415 result
= MOVE_POS_MATCH_OR_ZV
;
7418 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7420 /* Stop when TO_X specified and reached. This check is
7421 necessary here because of lines consisting of a line end,
7422 only. The line end will not produce any glyphs and we
7423 would never get MOVE_X_REACHED. */
7424 xassert (it
->nglyphs
== 0);
7425 result
= MOVE_X_REACHED
;
7429 /* Is this a line end? If yes, we're done. */
7430 if (ITERATOR_AT_END_OF_LINE_P (it
))
7432 result
= MOVE_NEWLINE_OR_CR
;
7436 if (it
->method
== GET_FROM_BUFFER
)
7437 prev_pos
= IT_CHARPOS (*it
);
7438 /* The current display element has been consumed. Advance
7440 set_iterator_to_next (it
, 1);
7442 /* Stop if lines are truncated and IT's current x-position is
7443 past the right edge of the window now. */
7444 if (it
->line_wrap
== TRUNCATE
7445 && it
->current_x
>= it
->last_visible_x
)
7447 if (!FRAME_WINDOW_P (it
->f
)
7448 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7450 if (!get_next_display_element (it
)
7451 || BUFFER_POS_REACHED_P ())
7453 result
= MOVE_POS_MATCH_OR_ZV
;
7456 if (ITERATOR_AT_END_OF_LINE_P (it
))
7458 result
= MOVE_NEWLINE_OR_CR
;
7462 result
= MOVE_LINE_TRUNCATED
;
7465 #undef IT_RESET_X_ASCENT_DESCENT
7468 #undef BUFFER_POS_REACHED_P
7470 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7471 restore the saved iterator. */
7472 if (atpos_it
.sp
>= 0)
7474 else if (atx_it
.sp
>= 0)
7479 /* Restore the iterator settings altered at the beginning of this
7481 it
->glyph_row
= saved_glyph_row
;
7485 /* For external use. */
7487 move_it_in_display_line (struct it
*it
,
7488 EMACS_INT to_charpos
, int to_x
,
7489 enum move_operation_enum op
)
7491 if (it
->line_wrap
== WORD_WRAP
7492 && (op
& MOVE_TO_X
))
7494 struct it save_it
= *it
;
7495 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7496 /* When word-wrap is on, TO_X may lie past the end
7497 of a wrapped line. Then it->current is the
7498 character on the next line, so backtrack to the
7499 space before the wrap point. */
7500 if (skip
== MOVE_LINE_CONTINUED
)
7502 int prev_x
= max (it
->current_x
- 1, 0);
7504 move_it_in_display_line_to
7505 (it
, -1, prev_x
, MOVE_TO_X
);
7509 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7513 /* Move IT forward until it satisfies one or more of the criteria in
7514 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7516 OP is a bit-mask that specifies where to stop, and in particular,
7517 which of those four position arguments makes a difference. See the
7518 description of enum move_operation_enum.
7520 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7521 screen line, this function will set IT to the next position >
7525 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7527 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7528 int line_height
, line_start_x
= 0, reached
= 0;
7532 if (op
& MOVE_TO_VPOS
)
7534 /* If no TO_CHARPOS and no TO_X specified, stop at the
7535 start of the line TO_VPOS. */
7536 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7538 if (it
->vpos
== to_vpos
)
7544 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7548 /* TO_VPOS >= 0 means stop at TO_X in the line at
7549 TO_VPOS, or at TO_POS, whichever comes first. */
7550 if (it
->vpos
== to_vpos
)
7556 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7558 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7563 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7565 /* We have reached TO_X but not in the line we want. */
7566 skip
= move_it_in_display_line_to (it
, to_charpos
,
7568 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7576 else if (op
& MOVE_TO_Y
)
7578 struct it it_backup
;
7580 if (it
->line_wrap
== WORD_WRAP
)
7583 /* TO_Y specified means stop at TO_X in the line containing
7584 TO_Y---or at TO_CHARPOS if this is reached first. The
7585 problem is that we can't really tell whether the line
7586 contains TO_Y before we have completely scanned it, and
7587 this may skip past TO_X. What we do is to first scan to
7590 If TO_X is not specified, use a TO_X of zero. The reason
7591 is to make the outcome of this function more predictable.
7592 If we didn't use TO_X == 0, we would stop at the end of
7593 the line which is probably not what a caller would expect
7595 skip
= move_it_in_display_line_to
7596 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7597 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7599 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7600 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7602 else if (skip
== MOVE_X_REACHED
)
7604 /* If TO_X was reached, we want to know whether TO_Y is
7605 in the line. We know this is the case if the already
7606 scanned glyphs make the line tall enough. Otherwise,
7607 we must check by scanning the rest of the line. */
7608 line_height
= it
->max_ascent
+ it
->max_descent
;
7609 if (to_y
>= it
->current_y
7610 && to_y
< it
->current_y
+ line_height
)
7616 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7617 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7619 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7620 line_height
= it
->max_ascent
+ it
->max_descent
;
7621 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7623 if (to_y
>= it
->current_y
7624 && to_y
< it
->current_y
+ line_height
)
7626 /* If TO_Y is in this line and TO_X was reached
7627 above, we scanned too far. We have to restore
7628 IT's settings to the ones before skipping. */
7635 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7641 /* Check whether TO_Y is in this line. */
7642 line_height
= it
->max_ascent
+ it
->max_descent
;
7643 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7645 if (to_y
>= it
->current_y
7646 && to_y
< it
->current_y
+ line_height
)
7648 /* When word-wrap is on, TO_X may lie past the end
7649 of a wrapped line. Then it->current is the
7650 character on the next line, so backtrack to the
7651 space before the wrap point. */
7652 if (skip
== MOVE_LINE_CONTINUED
7653 && it
->line_wrap
== WORD_WRAP
)
7655 int prev_x
= max (it
->current_x
- 1, 0);
7657 skip
= move_it_in_display_line_to
7658 (it
, -1, prev_x
, MOVE_TO_X
);
7667 else if (BUFFERP (it
->object
)
7668 && (it
->method
== GET_FROM_BUFFER
7669 || it
->method
== GET_FROM_STRETCH
)
7670 && IT_CHARPOS (*it
) >= to_charpos
)
7671 skip
= MOVE_POS_MATCH_OR_ZV
;
7673 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7677 case MOVE_POS_MATCH_OR_ZV
:
7681 case MOVE_NEWLINE_OR_CR
:
7682 set_iterator_to_next (it
, 1);
7683 it
->continuation_lines_width
= 0;
7686 case MOVE_LINE_TRUNCATED
:
7687 it
->continuation_lines_width
= 0;
7688 reseat_at_next_visible_line_start (it
, 0);
7689 if ((op
& MOVE_TO_POS
) != 0
7690 && IT_CHARPOS (*it
) > to_charpos
)
7697 case MOVE_LINE_CONTINUED
:
7698 /* For continued lines ending in a tab, some of the glyphs
7699 associated with the tab are displayed on the current
7700 line. Since it->current_x does not include these glyphs,
7701 we use it->last_visible_x instead. */
7704 it
->continuation_lines_width
+= it
->last_visible_x
;
7705 /* When moving by vpos, ensure that the iterator really
7706 advances to the next line (bug#847, bug#969). Fixme:
7707 do we need to do this in other circumstances? */
7708 if (it
->current_x
!= it
->last_visible_x
7709 && (op
& MOVE_TO_VPOS
)
7710 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7712 line_start_x
= it
->current_x
+ it
->pixel_width
7713 - it
->last_visible_x
;
7714 set_iterator_to_next (it
, 0);
7718 it
->continuation_lines_width
+= it
->current_x
;
7725 /* Reset/increment for the next run. */
7726 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7727 it
->current_x
= line_start_x
;
7730 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7732 last_height
= it
->max_ascent
+ it
->max_descent
;
7733 last_max_ascent
= it
->max_ascent
;
7734 it
->max_ascent
= it
->max_descent
= 0;
7739 /* On text terminals, we may stop at the end of a line in the middle
7740 of a multi-character glyph. If the glyph itself is continued,
7741 i.e. it is actually displayed on the next line, don't treat this
7742 stopping point as valid; move to the next line instead (unless
7743 that brings us offscreen). */
7744 if (!FRAME_WINDOW_P (it
->f
)
7746 && IT_CHARPOS (*it
) == to_charpos
7747 && it
->what
== IT_CHARACTER
7749 && it
->line_wrap
== WINDOW_WRAP
7750 && it
->current_x
== it
->last_visible_x
- 1
7753 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7755 it
->continuation_lines_width
+= it
->current_x
;
7756 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7757 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7759 last_height
= it
->max_ascent
+ it
->max_descent
;
7760 last_max_ascent
= it
->max_ascent
;
7763 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7767 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7769 If DY > 0, move IT backward at least that many pixels. DY = 0
7770 means move IT backward to the preceding line start or BEGV. This
7771 function may move over more than DY pixels if IT->current_y - DY
7772 ends up in the middle of a line; in this case IT->current_y will be
7773 set to the top of the line moved to. */
7776 move_it_vertically_backward (struct it
*it
, int dy
)
7780 EMACS_INT start_pos
;
7785 start_pos
= IT_CHARPOS (*it
);
7787 /* Estimate how many newlines we must move back. */
7788 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7790 /* Set the iterator's position that many lines back. */
7791 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7792 back_to_previous_visible_line_start (it
);
7794 /* Reseat the iterator here. When moving backward, we don't want
7795 reseat to skip forward over invisible text, set up the iterator
7796 to deliver from overlay strings at the new position etc. So,
7797 use reseat_1 here. */
7798 reseat_1 (it
, it
->current
.pos
, 1);
7800 /* We are now surely at a line start. */
7801 it
->current_x
= it
->hpos
= 0;
7802 it
->continuation_lines_width
= 0;
7804 /* Move forward and see what y-distance we moved. First move to the
7805 start of the next line so that we get its height. We need this
7806 height to be able to tell whether we reached the specified
7809 it2
.max_ascent
= it2
.max_descent
= 0;
7812 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7813 MOVE_TO_POS
| MOVE_TO_VPOS
);
7815 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7816 xassert (IT_CHARPOS (*it
) >= BEGV
);
7819 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7820 xassert (IT_CHARPOS (*it
) >= BEGV
);
7821 /* H is the actual vertical distance from the position in *IT
7822 and the starting position. */
7823 h
= it2
.current_y
- it
->current_y
;
7824 /* NLINES is the distance in number of lines. */
7825 nlines
= it2
.vpos
- it
->vpos
;
7827 /* Correct IT's y and vpos position
7828 so that they are relative to the starting point. */
7834 /* DY == 0 means move to the start of the screen line. The
7835 value of nlines is > 0 if continuation lines were involved. */
7837 move_it_by_lines (it
, nlines
, 1);
7841 /* The y-position we try to reach, relative to *IT.
7842 Note that H has been subtracted in front of the if-statement. */
7843 int target_y
= it
->current_y
+ h
- dy
;
7844 int y0
= it3
.current_y
;
7845 int y1
= line_bottom_y (&it3
);
7846 int line_height
= y1
- y0
;
7848 /* If we did not reach target_y, try to move further backward if
7849 we can. If we moved too far backward, try to move forward. */
7850 if (target_y
< it
->current_y
7851 /* This is heuristic. In a window that's 3 lines high, with
7852 a line height of 13 pixels each, recentering with point
7853 on the bottom line will try to move -39/2 = 19 pixels
7854 backward. Try to avoid moving into the first line. */
7855 && (it
->current_y
- target_y
7856 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7857 && IT_CHARPOS (*it
) > BEGV
)
7859 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7860 target_y
- it
->current_y
));
7861 dy
= it
->current_y
- target_y
;
7862 goto move_further_back
;
7864 else if (target_y
>= it
->current_y
+ line_height
7865 && IT_CHARPOS (*it
) < ZV
)
7867 /* Should move forward by at least one line, maybe more.
7869 Note: Calling move_it_by_lines can be expensive on
7870 terminal frames, where compute_motion is used (via
7871 vmotion) to do the job, when there are very long lines
7872 and truncate-lines is nil. That's the reason for
7873 treating terminal frames specially here. */
7875 if (!FRAME_WINDOW_P (it
->f
))
7876 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7881 move_it_by_lines (it
, 1, 1);
7883 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7890 /* Move IT by a specified amount of pixel lines DY. DY negative means
7891 move backwards. DY = 0 means move to start of screen line. At the
7892 end, IT will be on the start of a screen line. */
7895 move_it_vertically (struct it
*it
, int dy
)
7898 move_it_vertically_backward (it
, -dy
);
7901 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7902 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7903 MOVE_TO_POS
| MOVE_TO_Y
);
7904 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7906 /* If buffer ends in ZV without a newline, move to the start of
7907 the line to satisfy the post-condition. */
7908 if (IT_CHARPOS (*it
) == ZV
7910 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7911 move_it_by_lines (it
, 0, 0);
7916 /* Move iterator IT past the end of the text line it is in. */
7919 move_it_past_eol (struct it
*it
)
7921 enum move_it_result rc
;
7923 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7924 if (rc
== MOVE_NEWLINE_OR_CR
)
7925 set_iterator_to_next (it
, 0);
7929 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7930 negative means move up. DVPOS == 0 means move to the start of the
7931 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7932 NEED_Y_P is zero, IT->current_y will be left unchanged.
7934 Further optimization ideas: If we would know that IT->f doesn't use
7935 a face with proportional font, we could be faster for
7936 truncate-lines nil. */
7939 move_it_by_lines (struct it
*it
, int dvpos
, int need_y_p
)
7942 /* The commented-out optimization uses vmotion on terminals. This
7943 gives bad results, because elements like it->what, on which
7944 callers such as pos_visible_p rely, aren't updated. */
7945 /* struct position pos;
7946 if (!FRAME_WINDOW_P (it->f))
7948 struct text_pos textpos;
7950 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7951 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7952 reseat (it, textpos, 1);
7953 it->vpos += pos.vpos;
7954 it->current_y += pos.vpos;
7960 /* DVPOS == 0 means move to the start of the screen line. */
7961 move_it_vertically_backward (it
, 0);
7962 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7963 /* Let next call to line_bottom_y calculate real line height */
7968 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7969 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7970 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7975 EMACS_INT start_charpos
, i
;
7977 /* Start at the beginning of the screen line containing IT's
7978 position. This may actually move vertically backwards,
7979 in case of overlays, so adjust dvpos accordingly. */
7981 move_it_vertically_backward (it
, 0);
7984 /* Go back -DVPOS visible lines and reseat the iterator there. */
7985 start_charpos
= IT_CHARPOS (*it
);
7986 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7987 back_to_previous_visible_line_start (it
);
7988 reseat (it
, it
->current
.pos
, 1);
7990 /* Move further back if we end up in a string or an image. */
7991 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7993 /* First try to move to start of display line. */
7995 move_it_vertically_backward (it
, 0);
7997 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7999 /* If start of line is still in string or image,
8000 move further back. */
8001 back_to_previous_visible_line_start (it
);
8002 reseat (it
, it
->current
.pos
, 1);
8006 it
->current_x
= it
->hpos
= 0;
8008 /* Above call may have moved too far if continuation lines
8009 are involved. Scan forward and see if it did. */
8011 it2
.vpos
= it2
.current_y
= 0;
8012 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
8013 it
->vpos
-= it2
.vpos
;
8014 it
->current_y
-= it2
.current_y
;
8015 it
->current_x
= it
->hpos
= 0;
8017 /* If we moved too far back, move IT some lines forward. */
8018 if (it2
.vpos
> -dvpos
)
8020 int delta
= it2
.vpos
+ dvpos
;
8022 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
8023 /* Move back again if we got too far ahead. */
8024 if (IT_CHARPOS (*it
) >= start_charpos
)
8030 /* Return 1 if IT points into the middle of a display vector. */
8033 in_display_vector_p (struct it
*it
)
8035 return (it
->method
== GET_FROM_DISPLAY_VECTOR
8036 && it
->current
.dpvec_index
> 0
8037 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
8041 /***********************************************************************
8043 ***********************************************************************/
8046 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
8050 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
8052 Lisp_Object args
[3];
8053 Lisp_Object msg
, fmt
;
8056 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8059 /* Do nothing if called asynchronously. Inserting text into
8060 a buffer may call after-change-functions and alike and
8061 that would means running Lisp asynchronously. */
8062 if (handling_signal
)
8066 GCPRO4 (fmt
, msg
, arg1
, arg2
);
8068 args
[0] = fmt
= build_string (format
);
8071 msg
= Fformat (3, args
);
8073 len
= SBYTES (msg
) + 1;
8074 SAFE_ALLOCA (buffer
, char *, len
);
8075 memcpy (buffer
, SDATA (msg
), len
);
8077 message_dolog (buffer
, len
- 1, 1, 0);
8084 /* Output a newline in the *Messages* buffer if "needs" one. */
8087 message_log_maybe_newline (void)
8089 if (message_log_need_newline
)
8090 message_dolog ("", 0, 1, 0);
8094 /* Add a string M of length NBYTES to the message log, optionally
8095 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8096 nonzero, means interpret the contents of M as multibyte. This
8097 function calls low-level routines in order to bypass text property
8098 hooks, etc. which might not be safe to run.
8100 This may GC (insert may run before/after change hooks),
8101 so the buffer M must NOT point to a Lisp string. */
8104 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
8106 if (!NILP (Vmemory_full
))
8109 if (!NILP (Vmessage_log_max
))
8111 struct buffer
*oldbuf
;
8112 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8113 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8114 EMACS_INT point_at_end
= 0;
8115 EMACS_INT zv_at_end
= 0;
8116 Lisp_Object old_deactivate_mark
, tem
;
8117 struct gcpro gcpro1
;
8119 old_deactivate_mark
= Vdeactivate_mark
;
8120 oldbuf
= current_buffer
;
8121 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8122 current_buffer
->undo_list
= Qt
;
8124 oldpoint
= message_dolog_marker1
;
8125 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8126 oldbegv
= message_dolog_marker2
;
8127 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8128 oldzv
= message_dolog_marker3
;
8129 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8130 GCPRO1 (old_deactivate_mark
);
8138 BEGV_BYTE
= BEG_BYTE
;
8141 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8143 /* Insert the string--maybe converting multibyte to single byte
8144 or vice versa, so that all the text fits the buffer. */
8146 && NILP (current_buffer
->enable_multibyte_characters
))
8150 unsigned char work
[1];
8152 /* Convert a multibyte string to single-byte
8153 for the *Message* buffer. */
8154 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8156 c
= string_char_and_length (m
+ i
, &char_bytes
);
8157 work
[0] = (ASCII_CHAR_P (c
)
8159 : multibyte_char_to_unibyte (c
, Qnil
));
8160 insert_1_both (work
, 1, 1, 1, 0, 0);
8163 else if (! multibyte
8164 && ! NILP (current_buffer
->enable_multibyte_characters
))
8168 unsigned char *msg
= (unsigned char *) m
;
8169 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8170 /* Convert a single-byte string to multibyte
8171 for the *Message* buffer. */
8172 for (i
= 0; i
< nbytes
; i
++)
8175 MAKE_CHAR_MULTIBYTE (c
);
8176 char_bytes
= CHAR_STRING (c
, str
);
8177 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
8181 insert_1 (m
, nbytes
, 1, 0, 0);
8185 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8187 insert_1 ("\n", 1, 1, 0, 0);
8189 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8191 this_bol_byte
= PT_BYTE
;
8193 /* See if this line duplicates the previous one.
8194 If so, combine duplicates. */
8197 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8199 prev_bol_byte
= PT_BYTE
;
8201 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
8202 this_bol
, this_bol_byte
);
8205 del_range_both (prev_bol
, prev_bol_byte
,
8206 this_bol
, this_bol_byte
, 0);
8212 /* If you change this format, don't forget to also
8213 change message_log_check_duplicate. */
8214 sprintf (dupstr
, " [%d times]", dup
);
8215 duplen
= strlen (dupstr
);
8216 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8217 insert_1 (dupstr
, duplen
, 1, 0, 1);
8222 /* If we have more than the desired maximum number of lines
8223 in the *Messages* buffer now, delete the oldest ones.
8224 This is safe because we don't have undo in this buffer. */
8226 if (NATNUMP (Vmessage_log_max
))
8228 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8229 -XFASTINT (Vmessage_log_max
) - 1, 0);
8230 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8233 BEGV
= XMARKER (oldbegv
)->charpos
;
8234 BEGV_BYTE
= marker_byte_position (oldbegv
);
8243 ZV
= XMARKER (oldzv
)->charpos
;
8244 ZV_BYTE
= marker_byte_position (oldzv
);
8248 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8250 /* We can't do Fgoto_char (oldpoint) because it will run some
8252 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8253 XMARKER (oldpoint
)->bytepos
);
8256 unchain_marker (XMARKER (oldpoint
));
8257 unchain_marker (XMARKER (oldbegv
));
8258 unchain_marker (XMARKER (oldzv
));
8260 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8261 set_buffer_internal (oldbuf
);
8263 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8264 message_log_need_newline
= !nlflag
;
8265 Vdeactivate_mark
= old_deactivate_mark
;
8270 /* We are at the end of the buffer after just having inserted a newline.
8271 (Note: We depend on the fact we won't be crossing the gap.)
8272 Check to see if the most recent message looks a lot like the previous one.
8273 Return 0 if different, 1 if the new one should just replace it, or a
8274 value N > 1 if we should also append " [N times]". */
8277 message_log_check_duplicate (EMACS_INT prev_bol
, EMACS_INT prev_bol_byte
,
8278 EMACS_INT this_bol
, EMACS_INT this_bol_byte
)
8281 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8283 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8284 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8286 for (i
= 0; i
< len
; i
++)
8288 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8296 if (*p1
++ == ' ' && *p1
++ == '[')
8299 while (*p1
>= '0' && *p1
<= '9')
8300 n
= n
* 10 + *p1
++ - '0';
8301 if (strncmp (p1
, " times]\n", 8) == 0)
8308 /* Display an echo area message M with a specified length of NBYTES
8309 bytes. The string may include null characters. If M is 0, clear
8310 out any existing message, and let the mini-buffer text show
8313 This may GC, so the buffer M must NOT point to a Lisp string. */
8316 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8318 /* First flush out any partial line written with print. */
8319 message_log_maybe_newline ();
8321 message_dolog (m
, nbytes
, 1, multibyte
);
8322 message2_nolog (m
, nbytes
, multibyte
);
8326 /* The non-logging counterpart of message2. */
8329 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8331 struct frame
*sf
= SELECTED_FRAME ();
8332 message_enable_multibyte
= multibyte
;
8334 if (FRAME_INITIAL_P (sf
))
8336 if (noninteractive_need_newline
)
8337 putc ('\n', stderr
);
8338 noninteractive_need_newline
= 0;
8340 fwrite (m
, nbytes
, 1, stderr
);
8341 if (cursor_in_echo_area
== 0)
8342 fprintf (stderr
, "\n");
8345 /* A null message buffer means that the frame hasn't really been
8346 initialized yet. Error messages get reported properly by
8347 cmd_error, so this must be just an informative message; toss it. */
8348 else if (INTERACTIVE
8349 && sf
->glyphs_initialized_p
8350 && FRAME_MESSAGE_BUF (sf
))
8352 Lisp_Object mini_window
;
8355 /* Get the frame containing the mini-buffer
8356 that the selected frame is using. */
8357 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8358 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8360 FRAME_SAMPLE_VISIBILITY (f
);
8361 if (FRAME_VISIBLE_P (sf
)
8362 && ! FRAME_VISIBLE_P (f
))
8363 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8367 set_message (m
, Qnil
, nbytes
, multibyte
);
8368 if (minibuffer_auto_raise
)
8369 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8372 clear_message (1, 1);
8374 do_pending_window_change (0);
8375 echo_area_display (1);
8376 do_pending_window_change (0);
8377 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8378 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8383 /* Display an echo area message M with a specified length of NBYTES
8384 bytes. The string may include null characters. If M is not a
8385 string, clear out any existing message, and let the mini-buffer
8388 This function cancels echoing. */
8391 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8393 struct gcpro gcpro1
;
8396 clear_message (1,1);
8399 /* First flush out any partial line written with print. */
8400 message_log_maybe_newline ();
8406 SAFE_ALLOCA (buffer
, char *, nbytes
);
8407 memcpy (buffer
, SDATA (m
), nbytes
);
8408 message_dolog (buffer
, nbytes
, 1, multibyte
);
8411 message3_nolog (m
, nbytes
, multibyte
);
8417 /* The non-logging version of message3.
8418 This does not cancel echoing, because it is used for echoing.
8419 Perhaps we need to make a separate function for echoing
8420 and make this cancel echoing. */
8423 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8425 struct frame
*sf
= SELECTED_FRAME ();
8426 message_enable_multibyte
= multibyte
;
8428 if (FRAME_INITIAL_P (sf
))
8430 if (noninteractive_need_newline
)
8431 putc ('\n', stderr
);
8432 noninteractive_need_newline
= 0;
8434 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8435 if (cursor_in_echo_area
== 0)
8436 fprintf (stderr
, "\n");
8439 /* A null message buffer means that the frame hasn't really been
8440 initialized yet. Error messages get reported properly by
8441 cmd_error, so this must be just an informative message; toss it. */
8442 else if (INTERACTIVE
8443 && sf
->glyphs_initialized_p
8444 && FRAME_MESSAGE_BUF (sf
))
8446 Lisp_Object mini_window
;
8450 /* Get the frame containing the mini-buffer
8451 that the selected frame is using. */
8452 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8453 frame
= XWINDOW (mini_window
)->frame
;
8456 FRAME_SAMPLE_VISIBILITY (f
);
8457 if (FRAME_VISIBLE_P (sf
)
8458 && !FRAME_VISIBLE_P (f
))
8459 Fmake_frame_visible (frame
);
8461 if (STRINGP (m
) && SCHARS (m
) > 0)
8463 set_message (NULL
, m
, nbytes
, multibyte
);
8464 if (minibuffer_auto_raise
)
8465 Fraise_frame (frame
);
8466 /* Assume we are not echoing.
8467 (If we are, echo_now will override this.) */
8468 echo_message_buffer
= Qnil
;
8471 clear_message (1, 1);
8473 do_pending_window_change (0);
8474 echo_area_display (1);
8475 do_pending_window_change (0);
8476 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8477 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8482 /* Display a null-terminated echo area message M. If M is 0, clear
8483 out any existing message, and let the mini-buffer text show through.
8485 The buffer M must continue to exist until after the echo area gets
8486 cleared or some other message gets displayed there. Do not pass
8487 text that is stored in a Lisp string. Do not pass text in a buffer
8488 that was alloca'd. */
8491 message1 (const char *m
)
8493 message2 (m
, (m
? strlen (m
) : 0), 0);
8497 /* The non-logging counterpart of message1. */
8500 message1_nolog (const char *m
)
8502 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8505 /* Display a message M which contains a single %s
8506 which gets replaced with STRING. */
8509 message_with_string (const char *m
, Lisp_Object string
, int log
)
8511 CHECK_STRING (string
);
8517 if (noninteractive_need_newline
)
8518 putc ('\n', stderr
);
8519 noninteractive_need_newline
= 0;
8520 fprintf (stderr
, m
, SDATA (string
));
8521 if (!cursor_in_echo_area
)
8522 fprintf (stderr
, "\n");
8526 else if (INTERACTIVE
)
8528 /* The frame whose minibuffer we're going to display the message on.
8529 It may be larger than the selected frame, so we need
8530 to use its buffer, not the selected frame's buffer. */
8531 Lisp_Object mini_window
;
8532 struct frame
*f
, *sf
= SELECTED_FRAME ();
8534 /* Get the frame containing the minibuffer
8535 that the selected frame is using. */
8536 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8537 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8539 /* A null message buffer means that the frame hasn't really been
8540 initialized yet. Error messages get reported properly by
8541 cmd_error, so this must be just an informative message; toss it. */
8542 if (FRAME_MESSAGE_BUF (f
))
8544 Lisp_Object args
[2], message
;
8545 struct gcpro gcpro1
, gcpro2
;
8547 args
[0] = build_string (m
);
8548 args
[1] = message
= string
;
8549 GCPRO2 (args
[0], message
);
8552 message
= Fformat (2, args
);
8555 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8557 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8561 /* Print should start at the beginning of the message
8562 buffer next time. */
8563 message_buf_print
= 0;
8569 /* Dump an informative message to the minibuf. If M is 0, clear out
8570 any existing message, and let the mini-buffer text show through. */
8573 vmessage (const char *m
, va_list ap
)
8579 if (noninteractive_need_newline
)
8580 putc ('\n', stderr
);
8581 noninteractive_need_newline
= 0;
8582 vfprintf (stderr
, m
, ap
);
8583 if (cursor_in_echo_area
== 0)
8584 fprintf (stderr
, "\n");
8588 else if (INTERACTIVE
)
8590 /* The frame whose mini-buffer we're going to display the message
8591 on. It may be larger than the selected frame, so we need to
8592 use its buffer, not the selected frame's buffer. */
8593 Lisp_Object mini_window
;
8594 struct frame
*f
, *sf
= SELECTED_FRAME ();
8596 /* Get the frame containing the mini-buffer
8597 that the selected frame is using. */
8598 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8599 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8601 /* A null message buffer means that the frame hasn't really been
8602 initialized yet. Error messages get reported properly by
8603 cmd_error, so this must be just an informative message; toss
8605 if (FRAME_MESSAGE_BUF (f
))
8611 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8612 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
8614 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8619 /* Print should start at the beginning of the message
8620 buffer next time. */
8621 message_buf_print
= 0;
8627 message (const char *m
, ...)
8636 /* The non-logging version of message. */
8639 message_nolog (const char *m
, ...)
8641 Lisp_Object old_log_max
;
8644 old_log_max
= Vmessage_log_max
;
8645 Vmessage_log_max
= Qnil
;
8647 Vmessage_log_max
= old_log_max
;
8652 /* Display the current message in the current mini-buffer. This is
8653 only called from error handlers in process.c, and is not time
8657 update_echo_area (void)
8659 if (!NILP (echo_area_buffer
[0]))
8662 string
= Fcurrent_message ();
8663 message3 (string
, SBYTES (string
),
8664 !NILP (current_buffer
->enable_multibyte_characters
));
8669 /* Make sure echo area buffers in `echo_buffers' are live.
8670 If they aren't, make new ones. */
8673 ensure_echo_area_buffers (void)
8677 for (i
= 0; i
< 2; ++i
)
8678 if (!BUFFERP (echo_buffer
[i
])
8679 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8682 Lisp_Object old_buffer
;
8685 old_buffer
= echo_buffer
[i
];
8686 sprintf (name
, " *Echo Area %d*", i
);
8687 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8688 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8689 /* to force word wrap in echo area -
8690 it was decided to postpone this*/
8691 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8693 for (j
= 0; j
< 2; ++j
)
8694 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8695 echo_area_buffer
[j
] = echo_buffer
[i
];
8700 /* Call FN with args A1..A4 with either the current or last displayed
8701 echo_area_buffer as current buffer.
8703 WHICH zero means use the current message buffer
8704 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8705 from echo_buffer[] and clear it.
8707 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8708 suitable buffer from echo_buffer[] and clear it.
8710 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8711 that the current message becomes the last displayed one, make
8712 choose a suitable buffer for echo_area_buffer[0], and clear it.
8714 Value is what FN returns. */
8717 with_echo_area_buffer (struct window
*w
, int which
,
8718 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
8719 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8722 int this_one
, the_other
, clear_buffer_p
, rc
;
8723 int count
= SPECPDL_INDEX ();
8725 /* If buffers aren't live, make new ones. */
8726 ensure_echo_area_buffers ();
8731 this_one
= 0, the_other
= 1;
8733 this_one
= 1, the_other
= 0;
8736 this_one
= 0, the_other
= 1;
8739 /* We need a fresh one in case the current echo buffer equals
8740 the one containing the last displayed echo area message. */
8741 if (!NILP (echo_area_buffer
[this_one
])
8742 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8743 echo_area_buffer
[this_one
] = Qnil
;
8746 /* Choose a suitable buffer from echo_buffer[] is we don't
8748 if (NILP (echo_area_buffer
[this_one
]))
8750 echo_area_buffer
[this_one
]
8751 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8752 ? echo_buffer
[the_other
]
8753 : echo_buffer
[this_one
]);
8757 buffer
= echo_area_buffer
[this_one
];
8759 /* Don't get confused by reusing the buffer used for echoing
8760 for a different purpose. */
8761 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8764 record_unwind_protect (unwind_with_echo_area_buffer
,
8765 with_echo_area_buffer_unwind_data (w
));
8767 /* Make the echo area buffer current. Note that for display
8768 purposes, it is not necessary that the displayed window's buffer
8769 == current_buffer, except for text property lookup. So, let's
8770 only set that buffer temporarily here without doing a full
8771 Fset_window_buffer. We must also change w->pointm, though,
8772 because otherwise an assertions in unshow_buffer fails, and Emacs
8774 set_buffer_internal_1 (XBUFFER (buffer
));
8778 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8781 current_buffer
->undo_list
= Qt
;
8782 current_buffer
->read_only
= Qnil
;
8783 specbind (Qinhibit_read_only
, Qt
);
8784 specbind (Qinhibit_modification_hooks
, Qt
);
8786 if (clear_buffer_p
&& Z
> BEG
)
8789 xassert (BEGV
>= BEG
);
8790 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8792 rc
= fn (a1
, a2
, a3
, a4
);
8794 xassert (BEGV
>= BEG
);
8795 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8797 unbind_to (count
, Qnil
);
8802 /* Save state that should be preserved around the call to the function
8803 FN called in with_echo_area_buffer. */
8806 with_echo_area_buffer_unwind_data (struct window
*w
)
8809 Lisp_Object vector
, tmp
;
8811 /* Reduce consing by keeping one vector in
8812 Vwith_echo_area_save_vector. */
8813 vector
= Vwith_echo_area_save_vector
;
8814 Vwith_echo_area_save_vector
= Qnil
;
8817 vector
= Fmake_vector (make_number (7), Qnil
);
8819 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8820 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8821 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8825 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8826 ASET (vector
, i
, w
->buffer
); ++i
;
8827 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8828 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8833 for (; i
< end
; ++i
)
8834 ASET (vector
, i
, Qnil
);
8837 xassert (i
== ASIZE (vector
));
8842 /* Restore global state from VECTOR which was created by
8843 with_echo_area_buffer_unwind_data. */
8846 unwind_with_echo_area_buffer (Lisp_Object vector
)
8848 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8849 Vdeactivate_mark
= AREF (vector
, 1);
8850 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8852 if (WINDOWP (AREF (vector
, 3)))
8855 Lisp_Object buffer
, charpos
, bytepos
;
8857 w
= XWINDOW (AREF (vector
, 3));
8858 buffer
= AREF (vector
, 4);
8859 charpos
= AREF (vector
, 5);
8860 bytepos
= AREF (vector
, 6);
8863 set_marker_both (w
->pointm
, buffer
,
8864 XFASTINT (charpos
), XFASTINT (bytepos
));
8867 Vwith_echo_area_save_vector
= vector
;
8872 /* Set up the echo area for use by print functions. MULTIBYTE_P
8873 non-zero means we will print multibyte. */
8876 setup_echo_area_for_printing (int multibyte_p
)
8878 /* If we can't find an echo area any more, exit. */
8879 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8882 ensure_echo_area_buffers ();
8884 if (!message_buf_print
)
8886 /* A message has been output since the last time we printed.
8887 Choose a fresh echo area buffer. */
8888 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8889 echo_area_buffer
[0] = echo_buffer
[1];
8891 echo_area_buffer
[0] = echo_buffer
[0];
8893 /* Switch to that buffer and clear it. */
8894 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8895 current_buffer
->truncate_lines
= Qnil
;
8899 int count
= SPECPDL_INDEX ();
8900 specbind (Qinhibit_read_only
, Qt
);
8901 /* Note that undo recording is always disabled. */
8903 unbind_to (count
, Qnil
);
8905 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8907 /* Set up the buffer for the multibyteness we need. */
8909 != !NILP (current_buffer
->enable_multibyte_characters
))
8910 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8912 /* Raise the frame containing the echo area. */
8913 if (minibuffer_auto_raise
)
8915 struct frame
*sf
= SELECTED_FRAME ();
8916 Lisp_Object mini_window
;
8917 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8918 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8921 message_log_maybe_newline ();
8922 message_buf_print
= 1;
8926 if (NILP (echo_area_buffer
[0]))
8928 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8929 echo_area_buffer
[0] = echo_buffer
[1];
8931 echo_area_buffer
[0] = echo_buffer
[0];
8934 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8936 /* Someone switched buffers between print requests. */
8937 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8938 current_buffer
->truncate_lines
= Qnil
;
8944 /* Display an echo area message in window W. Value is non-zero if W's
8945 height is changed. If display_last_displayed_message_p is
8946 non-zero, display the message that was last displayed, otherwise
8947 display the current message. */
8950 display_echo_area (struct window
*w
)
8952 int i
, no_message_p
, window_height_changed_p
, count
;
8954 /* Temporarily disable garbage collections while displaying the echo
8955 area. This is done because a GC can print a message itself.
8956 That message would modify the echo area buffer's contents while a
8957 redisplay of the buffer is going on, and seriously confuse
8959 count
= inhibit_garbage_collection ();
8961 /* If there is no message, we must call display_echo_area_1
8962 nevertheless because it resizes the window. But we will have to
8963 reset the echo_area_buffer in question to nil at the end because
8964 with_echo_area_buffer will sets it to an empty buffer. */
8965 i
= display_last_displayed_message_p
? 1 : 0;
8966 no_message_p
= NILP (echo_area_buffer
[i
]);
8968 window_height_changed_p
8969 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8970 display_echo_area_1
,
8971 (EMACS_INT
) w
, Qnil
, 0, 0);
8974 echo_area_buffer
[i
] = Qnil
;
8976 unbind_to (count
, Qnil
);
8977 return window_height_changed_p
;
8981 /* Helper for display_echo_area. Display the current buffer which
8982 contains the current echo area message in window W, a mini-window,
8983 a pointer to which is passed in A1. A2..A4 are currently not used.
8984 Change the height of W so that all of the message is displayed.
8985 Value is non-zero if height of W was changed. */
8988 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8990 struct window
*w
= (struct window
*) a1
;
8992 struct text_pos start
;
8993 int window_height_changed_p
= 0;
8995 /* Do this before displaying, so that we have a large enough glyph
8996 matrix for the display. If we can't get enough space for the
8997 whole text, display the last N lines. That works by setting w->start. */
8998 window_height_changed_p
= resize_mini_window (w
, 0);
9000 /* Use the starting position chosen by resize_mini_window. */
9001 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9004 clear_glyph_matrix (w
->desired_matrix
);
9005 XSETWINDOW (window
, w
);
9006 try_window (window
, start
, 0);
9008 return window_height_changed_p
;
9012 /* Resize the echo area window to exactly the size needed for the
9013 currently displayed message, if there is one. If a mini-buffer
9014 is active, don't shrink it. */
9017 resize_echo_area_exactly (void)
9019 if (BUFFERP (echo_area_buffer
[0])
9020 && WINDOWP (echo_area_window
))
9022 struct window
*w
= XWINDOW (echo_area_window
);
9024 Lisp_Object resize_exactly
;
9026 if (minibuf_level
== 0)
9027 resize_exactly
= Qt
;
9029 resize_exactly
= Qnil
;
9031 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
9032 (EMACS_INT
) w
, resize_exactly
, 0, 0);
9035 ++windows_or_buffers_changed
;
9036 ++update_mode_lines
;
9037 redisplay_internal (0);
9043 /* Callback function for with_echo_area_buffer, when used from
9044 resize_echo_area_exactly. A1 contains a pointer to the window to
9045 resize, EXACTLY non-nil means resize the mini-window exactly to the
9046 size of the text displayed. A3 and A4 are not used. Value is what
9047 resize_mini_window returns. */
9050 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
9052 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
9056 /* Resize mini-window W to fit the size of its contents. EXACT_P
9057 means size the window exactly to the size needed. Otherwise, it's
9058 only enlarged until W's buffer is empty.
9060 Set W->start to the right place to begin display. If the whole
9061 contents fit, start at the beginning. Otherwise, start so as
9062 to make the end of the contents appear. This is particularly
9063 important for y-or-n-p, but seems desirable generally.
9065 Value is non-zero if the window height has been changed. */
9068 resize_mini_window (struct window
*w
, int exact_p
)
9070 struct frame
*f
= XFRAME (w
->frame
);
9071 int window_height_changed_p
= 0;
9073 xassert (MINI_WINDOW_P (w
));
9075 /* By default, start display at the beginning. */
9076 set_marker_both (w
->start
, w
->buffer
,
9077 BUF_BEGV (XBUFFER (w
->buffer
)),
9078 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9080 /* Don't resize windows while redisplaying a window; it would
9081 confuse redisplay functions when the size of the window they are
9082 displaying changes from under them. Such a resizing can happen,
9083 for instance, when which-func prints a long message while
9084 we are running fontification-functions. We're running these
9085 functions with safe_call which binds inhibit-redisplay to t. */
9086 if (!NILP (Vinhibit_redisplay
))
9089 /* Nil means don't try to resize. */
9090 if (NILP (Vresize_mini_windows
)
9091 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9094 if (!FRAME_MINIBUF_ONLY_P (f
))
9097 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9098 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9099 int height
, max_height
;
9100 int unit
= FRAME_LINE_HEIGHT (f
);
9101 struct text_pos start
;
9102 struct buffer
*old_current_buffer
= NULL
;
9104 if (current_buffer
!= XBUFFER (w
->buffer
))
9106 old_current_buffer
= current_buffer
;
9107 set_buffer_internal (XBUFFER (w
->buffer
));
9110 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9112 /* Compute the max. number of lines specified by the user. */
9113 if (FLOATP (Vmax_mini_window_height
))
9114 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9115 else if (INTEGERP (Vmax_mini_window_height
))
9116 max_height
= XINT (Vmax_mini_window_height
);
9118 max_height
= total_height
/ 4;
9120 /* Correct that max. height if it's bogus. */
9121 max_height
= max (1, max_height
);
9122 max_height
= min (total_height
, max_height
);
9124 /* Find out the height of the text in the window. */
9125 if (it
.line_wrap
== TRUNCATE
)
9130 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9131 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9132 height
= it
.current_y
+ last_height
;
9134 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9135 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9136 height
= (height
+ unit
- 1) / unit
;
9139 /* Compute a suitable window start. */
9140 if (height
> max_height
)
9142 height
= max_height
;
9143 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9144 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9145 start
= it
.current
.pos
;
9148 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9149 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9151 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9153 /* Let it grow only, until we display an empty message, in which
9154 case the window shrinks again. */
9155 if (height
> WINDOW_TOTAL_LINES (w
))
9157 int old_height
= WINDOW_TOTAL_LINES (w
);
9158 freeze_window_starts (f
, 1);
9159 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9160 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9162 else if (height
< WINDOW_TOTAL_LINES (w
)
9163 && (exact_p
|| BEGV
== ZV
))
9165 int old_height
= WINDOW_TOTAL_LINES (w
);
9166 freeze_window_starts (f
, 0);
9167 shrink_mini_window (w
);
9168 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9173 /* Always resize to exact size needed. */
9174 if (height
> WINDOW_TOTAL_LINES (w
))
9176 int old_height
= WINDOW_TOTAL_LINES (w
);
9177 freeze_window_starts (f
, 1);
9178 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9179 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9181 else if (height
< WINDOW_TOTAL_LINES (w
))
9183 int old_height
= WINDOW_TOTAL_LINES (w
);
9184 freeze_window_starts (f
, 0);
9185 shrink_mini_window (w
);
9189 freeze_window_starts (f
, 1);
9190 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9193 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9197 if (old_current_buffer
)
9198 set_buffer_internal (old_current_buffer
);
9201 return window_height_changed_p
;
9205 /* Value is the current message, a string, or nil if there is no
9209 current_message (void)
9213 if (!BUFFERP (echo_area_buffer
[0]))
9217 with_echo_area_buffer (0, 0, current_message_1
,
9218 (EMACS_INT
) &msg
, Qnil
, 0, 0);
9220 echo_area_buffer
[0] = Qnil
;
9228 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9230 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
9233 *msg
= make_buffer_string (BEG
, Z
, 1);
9240 /* Push the current message on Vmessage_stack for later restauration
9241 by restore_message. Value is non-zero if the current message isn't
9242 empty. This is a relatively infrequent operation, so it's not
9243 worth optimizing. */
9249 msg
= current_message ();
9250 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9251 return STRINGP (msg
);
9255 /* Restore message display from the top of Vmessage_stack. */
9258 restore_message (void)
9262 xassert (CONSP (Vmessage_stack
));
9263 msg
= XCAR (Vmessage_stack
);
9265 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9267 message3_nolog (msg
, 0, 0);
9271 /* Handler for record_unwind_protect calling pop_message. */
9274 pop_message_unwind (Lisp_Object dummy
)
9280 /* Pop the top-most entry off Vmessage_stack. */
9285 xassert (CONSP (Vmessage_stack
));
9286 Vmessage_stack
= XCDR (Vmessage_stack
);
9290 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9291 exits. If the stack is not empty, we have a missing pop_message
9295 check_message_stack (void)
9297 if (!NILP (Vmessage_stack
))
9302 /* Truncate to NCHARS what will be displayed in the echo area the next
9303 time we display it---but don't redisplay it now. */
9306 truncate_echo_area (EMACS_INT nchars
)
9309 echo_area_buffer
[0] = Qnil
;
9310 /* A null message buffer means that the frame hasn't really been
9311 initialized yet. Error messages get reported properly by
9312 cmd_error, so this must be just an informative message; toss it. */
9313 else if (!noninteractive
9315 && !NILP (echo_area_buffer
[0]))
9317 struct frame
*sf
= SELECTED_FRAME ();
9318 if (FRAME_MESSAGE_BUF (sf
))
9319 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9324 /* Helper function for truncate_echo_area. Truncate the current
9325 message to at most NCHARS characters. */
9328 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9330 if (BEG
+ nchars
< Z
)
9331 del_range (BEG
+ nchars
, Z
);
9333 echo_area_buffer
[0] = Qnil
;
9338 /* Set the current message to a substring of S or STRING.
9340 If STRING is a Lisp string, set the message to the first NBYTES
9341 bytes from STRING. NBYTES zero means use the whole string. If
9342 STRING is multibyte, the message will be displayed multibyte.
9344 If S is not null, set the message to the first LEN bytes of S. LEN
9345 zero means use the whole string. MULTIBYTE_P non-zero means S is
9346 multibyte. Display the message multibyte in that case.
9348 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9349 to t before calling set_message_1 (which calls insert).
9353 set_message (const char *s
, Lisp_Object string
,
9354 EMACS_INT nbytes
, int multibyte_p
)
9356 message_enable_multibyte
9357 = ((s
&& multibyte_p
)
9358 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9360 with_echo_area_buffer (0, -1, set_message_1
,
9361 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9362 message_buf_print
= 0;
9363 help_echo_showing_p
= 0;
9367 /* Helper function for set_message. Arguments have the same meaning
9368 as there, with A1 corresponding to S and A2 corresponding to STRING
9369 This function is called with the echo area buffer being
9373 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9375 const char *s
= (const char *) a1
;
9376 Lisp_Object string
= a2
;
9378 /* Change multibyteness of the echo buffer appropriately. */
9379 if (message_enable_multibyte
9380 != !NILP (current_buffer
->enable_multibyte_characters
))
9381 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9383 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9385 /* Insert new message at BEG. */
9386 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9388 if (STRINGP (string
))
9393 nbytes
= SBYTES (string
);
9394 nchars
= string_byte_to_char (string
, nbytes
);
9396 /* This function takes care of single/multibyte conversion. We
9397 just have to ensure that the echo area buffer has the right
9398 setting of enable_multibyte_characters. */
9399 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9404 nbytes
= strlen (s
);
9406 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9408 /* Convert from multi-byte to single-byte. */
9411 unsigned char work
[1];
9413 /* Convert a multibyte string to single-byte. */
9414 for (i
= 0; i
< nbytes
; i
+= n
)
9416 c
= string_char_and_length (s
+ i
, &n
);
9417 work
[0] = (ASCII_CHAR_P (c
)
9419 : multibyte_char_to_unibyte (c
, Qnil
));
9420 insert_1_both (work
, 1, 1, 1, 0, 0);
9423 else if (!multibyte_p
9424 && !NILP (current_buffer
->enable_multibyte_characters
))
9426 /* Convert from single-byte to multi-byte. */
9429 const unsigned char *msg
= (const unsigned char *) s
;
9430 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9432 /* Convert a single-byte string to multibyte. */
9433 for (i
= 0; i
< nbytes
; i
++)
9436 MAKE_CHAR_MULTIBYTE (c
);
9437 n
= CHAR_STRING (c
, str
);
9438 insert_1_both (str
, 1, n
, 1, 0, 0);
9442 insert_1 (s
, nbytes
, 1, 0, 0);
9449 /* Clear messages. CURRENT_P non-zero means clear the current
9450 message. LAST_DISPLAYED_P non-zero means clear the message
9454 clear_message (int current_p
, int last_displayed_p
)
9458 echo_area_buffer
[0] = Qnil
;
9459 message_cleared_p
= 1;
9462 if (last_displayed_p
)
9463 echo_area_buffer
[1] = Qnil
;
9465 message_buf_print
= 0;
9468 /* Clear garbaged frames.
9470 This function is used where the old redisplay called
9471 redraw_garbaged_frames which in turn called redraw_frame which in
9472 turn called clear_frame. The call to clear_frame was a source of
9473 flickering. I believe a clear_frame is not necessary. It should
9474 suffice in the new redisplay to invalidate all current matrices,
9475 and ensure a complete redisplay of all windows. */
9478 clear_garbaged_frames (void)
9482 Lisp_Object tail
, frame
;
9483 int changed_count
= 0;
9485 FOR_EACH_FRAME (tail
, frame
)
9487 struct frame
*f
= XFRAME (frame
);
9489 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9493 Fredraw_frame (frame
);
9494 f
->force_flush_display_p
= 1;
9496 clear_current_matrices (f
);
9505 ++windows_or_buffers_changed
;
9510 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9511 is non-zero update selected_frame. Value is non-zero if the
9512 mini-windows height has been changed. */
9515 echo_area_display (int update_frame_p
)
9517 Lisp_Object mini_window
;
9520 int window_height_changed_p
= 0;
9521 struct frame
*sf
= SELECTED_FRAME ();
9523 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9524 w
= XWINDOW (mini_window
);
9525 f
= XFRAME (WINDOW_FRAME (w
));
9527 /* Don't display if frame is invisible or not yet initialized. */
9528 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9531 #ifdef HAVE_WINDOW_SYSTEM
9532 /* When Emacs starts, selected_frame may be the initial terminal
9533 frame. If we let this through, a message would be displayed on
9535 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9537 #endif /* HAVE_WINDOW_SYSTEM */
9539 /* Redraw garbaged frames. */
9541 clear_garbaged_frames ();
9543 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9545 echo_area_window
= mini_window
;
9546 window_height_changed_p
= display_echo_area (w
);
9547 w
->must_be_updated_p
= 1;
9549 /* Update the display, unless called from redisplay_internal.
9550 Also don't update the screen during redisplay itself. The
9551 update will happen at the end of redisplay, and an update
9552 here could cause confusion. */
9553 if (update_frame_p
&& !redisplaying_p
)
9557 /* If the display update has been interrupted by pending
9558 input, update mode lines in the frame. Due to the
9559 pending input, it might have been that redisplay hasn't
9560 been called, so that mode lines above the echo area are
9561 garbaged. This looks odd, so we prevent it here. */
9562 if (!display_completed
)
9563 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9565 if (window_height_changed_p
9566 /* Don't do this if Emacs is shutting down. Redisplay
9567 needs to run hooks. */
9568 && !NILP (Vrun_hooks
))
9570 /* Must update other windows. Likewise as in other
9571 cases, don't let this update be interrupted by
9573 int count
= SPECPDL_INDEX ();
9574 specbind (Qredisplay_dont_pause
, Qt
);
9575 windows_or_buffers_changed
= 1;
9576 redisplay_internal (0);
9577 unbind_to (count
, Qnil
);
9579 else if (FRAME_WINDOW_P (f
) && n
== 0)
9581 /* Window configuration is the same as before.
9582 Can do with a display update of the echo area,
9583 unless we displayed some mode lines. */
9584 update_single_window (w
, 1);
9585 FRAME_RIF (f
)->flush_display (f
);
9588 update_frame (f
, 1, 1);
9590 /* If cursor is in the echo area, make sure that the next
9591 redisplay displays the minibuffer, so that the cursor will
9592 be replaced with what the minibuffer wants. */
9593 if (cursor_in_echo_area
)
9594 ++windows_or_buffers_changed
;
9597 else if (!EQ (mini_window
, selected_window
))
9598 windows_or_buffers_changed
++;
9600 /* Last displayed message is now the current message. */
9601 echo_area_buffer
[1] = echo_area_buffer
[0];
9602 /* Inform read_char that we're not echoing. */
9603 echo_message_buffer
= Qnil
;
9605 /* Prevent redisplay optimization in redisplay_internal by resetting
9606 this_line_start_pos. This is done because the mini-buffer now
9607 displays the message instead of its buffer text. */
9608 if (EQ (mini_window
, selected_window
))
9609 CHARPOS (this_line_start_pos
) = 0;
9611 return window_height_changed_p
;
9616 /***********************************************************************
9617 Mode Lines and Frame Titles
9618 ***********************************************************************/
9620 /* A buffer for constructing non-propertized mode-line strings and
9621 frame titles in it; allocated from the heap in init_xdisp and
9622 resized as needed in store_mode_line_noprop_char. */
9624 static char *mode_line_noprop_buf
;
9626 /* The buffer's end, and a current output position in it. */
9628 static char *mode_line_noprop_buf_end
;
9629 static char *mode_line_noprop_ptr
;
9631 #define MODE_LINE_NOPROP_LEN(start) \
9632 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9635 MODE_LINE_DISPLAY
= 0,
9641 /* Alist that caches the results of :propertize.
9642 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9643 static Lisp_Object mode_line_proptrans_alist
;
9645 /* List of strings making up the mode-line. */
9646 static Lisp_Object mode_line_string_list
;
9648 /* Base face property when building propertized mode line string. */
9649 static Lisp_Object mode_line_string_face
;
9650 static Lisp_Object mode_line_string_face_prop
;
9653 /* Unwind data for mode line strings */
9655 static Lisp_Object Vmode_line_unwind_vector
;
9658 format_mode_line_unwind_data (struct buffer
*obuf
,
9662 Lisp_Object vector
, tmp
;
9664 /* Reduce consing by keeping one vector in
9665 Vwith_echo_area_save_vector. */
9666 vector
= Vmode_line_unwind_vector
;
9667 Vmode_line_unwind_vector
= Qnil
;
9670 vector
= Fmake_vector (make_number (8), Qnil
);
9672 ASET (vector
, 0, make_number (mode_line_target
));
9673 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9674 ASET (vector
, 2, mode_line_string_list
);
9675 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9676 ASET (vector
, 4, mode_line_string_face
);
9677 ASET (vector
, 5, mode_line_string_face_prop
);
9680 XSETBUFFER (tmp
, obuf
);
9683 ASET (vector
, 6, tmp
);
9684 ASET (vector
, 7, owin
);
9690 unwind_format_mode_line (Lisp_Object vector
)
9692 mode_line_target
= XINT (AREF (vector
, 0));
9693 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9694 mode_line_string_list
= AREF (vector
, 2);
9695 if (! EQ (AREF (vector
, 3), Qt
))
9696 mode_line_proptrans_alist
= AREF (vector
, 3);
9697 mode_line_string_face
= AREF (vector
, 4);
9698 mode_line_string_face_prop
= AREF (vector
, 5);
9700 if (!NILP (AREF (vector
, 7)))
9701 /* Select window before buffer, since it may change the buffer. */
9702 Fselect_window (AREF (vector
, 7), Qt
);
9704 if (!NILP (AREF (vector
, 6)))
9706 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9707 ASET (vector
, 6, Qnil
);
9710 Vmode_line_unwind_vector
= vector
;
9715 /* Store a single character C for the frame title in mode_line_noprop_buf.
9716 Re-allocate mode_line_noprop_buf if necessary. */
9719 store_mode_line_noprop_char (char c
)
9721 /* If output position has reached the end of the allocated buffer,
9722 double the buffer's size. */
9723 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9725 int len
= MODE_LINE_NOPROP_LEN (0);
9726 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9727 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9728 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9729 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9732 *mode_line_noprop_ptr
++ = c
;
9736 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9737 mode_line_noprop_ptr. STR is the string to store. Do not copy
9738 characters that yield more columns than PRECISION; PRECISION <= 0
9739 means copy the whole string. Pad with spaces until FIELD_WIDTH
9740 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9741 pad. Called from display_mode_element when it is used to build a
9745 store_mode_line_noprop (const unsigned char *str
, int field_width
, int precision
)
9748 EMACS_INT dummy
, nbytes
;
9750 /* Copy at most PRECISION chars from STR. */
9751 nbytes
= strlen (str
);
9752 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9754 store_mode_line_noprop_char (*str
++);
9756 /* Fill up with spaces until FIELD_WIDTH reached. */
9757 while (field_width
> 0
9760 store_mode_line_noprop_char (' ');
9767 /***********************************************************************
9769 ***********************************************************************/
9771 #ifdef HAVE_WINDOW_SYSTEM
9773 /* Set the title of FRAME, if it has changed. The title format is
9774 Vicon_title_format if FRAME is iconified, otherwise it is
9775 frame_title_format. */
9778 x_consider_frame_title (Lisp_Object frame
)
9780 struct frame
*f
= XFRAME (frame
);
9782 if (FRAME_WINDOW_P (f
)
9783 || FRAME_MINIBUF_ONLY_P (f
)
9784 || f
->explicit_name
)
9786 /* Do we have more than one visible frame on this X display? */
9793 int count
= SPECPDL_INDEX ();
9795 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9797 Lisp_Object other_frame
= XCAR (tail
);
9798 struct frame
*tf
= XFRAME (other_frame
);
9801 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9802 && !FRAME_MINIBUF_ONLY_P (tf
)
9803 && !EQ (other_frame
, tip_frame
)
9804 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9808 /* Set global variable indicating that multiple frames exist. */
9809 multiple_frames
= CONSP (tail
);
9811 /* Switch to the buffer of selected window of the frame. Set up
9812 mode_line_target so that display_mode_element will output into
9813 mode_line_noprop_buf; then display the title. */
9814 record_unwind_protect (unwind_format_mode_line
,
9815 format_mode_line_unwind_data
9816 (current_buffer
, selected_window
, 0));
9818 Fselect_window (f
->selected_window
, Qt
);
9819 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9820 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9822 mode_line_target
= MODE_LINE_TITLE
;
9823 title_start
= MODE_LINE_NOPROP_LEN (0);
9824 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9825 NULL
, DEFAULT_FACE_ID
);
9826 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9827 len
= MODE_LINE_NOPROP_LEN (title_start
);
9828 title
= mode_line_noprop_buf
+ title_start
;
9829 unbind_to (count
, Qnil
);
9831 /* Set the title only if it's changed. This avoids consing in
9832 the common case where it hasn't. (If it turns out that we've
9833 already wasted too much time by walking through the list with
9834 display_mode_element, then we might need to optimize at a
9835 higher level than this.) */
9836 if (! STRINGP (f
->name
)
9837 || SBYTES (f
->name
) != len
9838 || memcmp (title
, SDATA (f
->name
), len
) != 0)
9839 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9843 #endif /* not HAVE_WINDOW_SYSTEM */
9848 /***********************************************************************
9850 ***********************************************************************/
9853 /* Prepare for redisplay by updating menu-bar item lists when
9854 appropriate. This can call eval. */
9857 prepare_menu_bars (void)
9860 struct gcpro gcpro1
, gcpro2
;
9862 Lisp_Object tooltip_frame
;
9864 #ifdef HAVE_WINDOW_SYSTEM
9865 tooltip_frame
= tip_frame
;
9867 tooltip_frame
= Qnil
;
9870 /* Update all frame titles based on their buffer names, etc. We do
9871 this before the menu bars so that the buffer-menu will show the
9872 up-to-date frame titles. */
9873 #ifdef HAVE_WINDOW_SYSTEM
9874 if (windows_or_buffers_changed
|| update_mode_lines
)
9876 Lisp_Object tail
, frame
;
9878 FOR_EACH_FRAME (tail
, frame
)
9881 if (!EQ (frame
, tooltip_frame
)
9882 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9883 x_consider_frame_title (frame
);
9886 #endif /* HAVE_WINDOW_SYSTEM */
9888 /* Update the menu bar item lists, if appropriate. This has to be
9889 done before any actual redisplay or generation of display lines. */
9890 all_windows
= (update_mode_lines
9891 || buffer_shared
> 1
9892 || windows_or_buffers_changed
);
9895 Lisp_Object tail
, frame
;
9896 int count
= SPECPDL_INDEX ();
9897 /* 1 means that update_menu_bar has run its hooks
9898 so any further calls to update_menu_bar shouldn't do so again. */
9899 int menu_bar_hooks_run
= 0;
9901 record_unwind_save_match_data ();
9903 FOR_EACH_FRAME (tail
, frame
)
9907 /* Ignore tooltip frame. */
9908 if (EQ (frame
, tooltip_frame
))
9911 /* If a window on this frame changed size, report that to
9912 the user and clear the size-change flag. */
9913 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9915 Lisp_Object functions
;
9917 /* Clear flag first in case we get an error below. */
9918 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9919 functions
= Vwindow_size_change_functions
;
9920 GCPRO2 (tail
, functions
);
9922 while (CONSP (functions
))
9924 if (!EQ (XCAR (functions
), Qt
))
9925 call1 (XCAR (functions
), frame
);
9926 functions
= XCDR (functions
);
9932 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9933 #ifdef HAVE_WINDOW_SYSTEM
9934 update_tool_bar (f
, 0);
9937 if (windows_or_buffers_changed
9939 ns_set_doc_edited (f
, Fbuffer_modified_p
9940 (XWINDOW (f
->selected_window
)->buffer
));
9945 unbind_to (count
, Qnil
);
9949 struct frame
*sf
= SELECTED_FRAME ();
9950 update_menu_bar (sf
, 1, 0);
9951 #ifdef HAVE_WINDOW_SYSTEM
9952 update_tool_bar (sf
, 1);
9958 /* Update the menu bar item list for frame F. This has to be done
9959 before we start to fill in any display lines, because it can call
9962 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9964 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9965 already ran the menu bar hooks for this redisplay, so there
9966 is no need to run them again. The return value is the
9967 updated value of this flag, to pass to the next call. */
9970 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
9973 register struct window
*w
;
9975 /* If called recursively during a menu update, do nothing. This can
9976 happen when, for instance, an activate-menubar-hook causes a
9978 if (inhibit_menubar_update
)
9981 window
= FRAME_SELECTED_WINDOW (f
);
9982 w
= XWINDOW (window
);
9984 if (FRAME_WINDOW_P (f
)
9986 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9987 || defined (HAVE_NS) || defined (USE_GTK)
9988 FRAME_EXTERNAL_MENU_BAR (f
)
9990 FRAME_MENU_BAR_LINES (f
) > 0
9992 : FRAME_MENU_BAR_LINES (f
) > 0)
9994 /* If the user has switched buffers or windows, we need to
9995 recompute to reflect the new bindings. But we'll
9996 recompute when update_mode_lines is set too; that means
9997 that people can use force-mode-line-update to request
9998 that the menu bar be recomputed. The adverse effect on
9999 the rest of the redisplay algorithm is about the same as
10000 windows_or_buffers_changed anyway. */
10001 if (windows_or_buffers_changed
10002 /* This used to test w->update_mode_line, but we believe
10003 there is no need to recompute the menu in that case. */
10004 || update_mode_lines
10005 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10006 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10007 != !NILP (w
->last_had_star
))
10008 || ((!NILP (Vtransient_mark_mode
)
10009 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10010 != !NILP (w
->region_showing
)))
10012 struct buffer
*prev
= current_buffer
;
10013 int count
= SPECPDL_INDEX ();
10015 specbind (Qinhibit_menubar_update
, Qt
);
10017 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10018 if (save_match_data
)
10019 record_unwind_save_match_data ();
10020 if (NILP (Voverriding_local_map_menu_flag
))
10022 specbind (Qoverriding_terminal_local_map
, Qnil
);
10023 specbind (Qoverriding_local_map
, Qnil
);
10028 /* Run the Lucid hook. */
10029 safe_run_hooks (Qactivate_menubar_hook
);
10031 /* If it has changed current-menubar from previous value,
10032 really recompute the menu-bar from the value. */
10033 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10034 call0 (Qrecompute_lucid_menubar
);
10036 safe_run_hooks (Qmenu_bar_update_hook
);
10041 XSETFRAME (Vmenu_updating_frame
, f
);
10042 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10044 /* Redisplay the menu bar in case we changed it. */
10045 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10046 || defined (HAVE_NS) || defined (USE_GTK)
10047 if (FRAME_WINDOW_P (f
))
10049 #if defined (HAVE_NS)
10050 /* All frames on Mac OS share the same menubar. So only
10051 the selected frame should be allowed to set it. */
10052 if (f
== SELECTED_FRAME ())
10054 set_frame_menubar (f
, 0, 0);
10057 /* On a terminal screen, the menu bar is an ordinary screen
10058 line, and this makes it get updated. */
10059 w
->update_mode_line
= Qt
;
10060 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10061 /* In the non-toolkit version, the menu bar is an ordinary screen
10062 line, and this makes it get updated. */
10063 w
->update_mode_line
= Qt
;
10064 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10066 unbind_to (count
, Qnil
);
10067 set_buffer_internal_1 (prev
);
10076 /***********************************************************************
10078 ***********************************************************************/
10080 #ifdef HAVE_WINDOW_SYSTEM
10083 Nominal cursor position -- where to draw output.
10084 HPOS and VPOS are window relative glyph matrix coordinates.
10085 X and Y are window relative pixel coordinates. */
10087 struct cursor_pos output_cursor
;
10091 Set the global variable output_cursor to CURSOR. All cursor
10092 positions are relative to updated_window. */
10095 set_output_cursor (struct cursor_pos
*cursor
)
10097 output_cursor
.hpos
= cursor
->hpos
;
10098 output_cursor
.vpos
= cursor
->vpos
;
10099 output_cursor
.x
= cursor
->x
;
10100 output_cursor
.y
= cursor
->y
;
10105 Set a nominal cursor position.
10107 HPOS and VPOS are column/row positions in a window glyph matrix. X
10108 and Y are window text area relative pixel positions.
10110 If this is done during an update, updated_window will contain the
10111 window that is being updated and the position is the future output
10112 cursor position for that window. If updated_window is null, use
10113 selected_window and display the cursor at the given position. */
10116 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10120 /* If updated_window is not set, work on selected_window. */
10121 if (updated_window
)
10122 w
= updated_window
;
10124 w
= XWINDOW (selected_window
);
10126 /* Set the output cursor. */
10127 output_cursor
.hpos
= hpos
;
10128 output_cursor
.vpos
= vpos
;
10129 output_cursor
.x
= x
;
10130 output_cursor
.y
= y
;
10132 /* If not called as part of an update, really display the cursor.
10133 This will also set the cursor position of W. */
10134 if (updated_window
== NULL
)
10137 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10138 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10139 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10144 #endif /* HAVE_WINDOW_SYSTEM */
10147 /***********************************************************************
10149 ***********************************************************************/
10151 #ifdef HAVE_WINDOW_SYSTEM
10153 /* Where the mouse was last time we reported a mouse event. */
10155 FRAME_PTR last_mouse_frame
;
10157 /* Tool-bar item index of the item on which a mouse button was pressed
10160 int last_tool_bar_item
;
10164 update_tool_bar_unwind (Lisp_Object frame
)
10166 selected_frame
= frame
;
10170 /* Update the tool-bar item list for frame F. This has to be done
10171 before we start to fill in any display lines. Called from
10172 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10173 and restore it here. */
10176 update_tool_bar (struct frame
*f
, int save_match_data
)
10178 #if defined (USE_GTK) || defined (HAVE_NS)
10179 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10181 int do_update
= WINDOWP (f
->tool_bar_window
)
10182 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10187 Lisp_Object window
;
10190 window
= FRAME_SELECTED_WINDOW (f
);
10191 w
= XWINDOW (window
);
10193 /* If the user has switched buffers or windows, we need to
10194 recompute to reflect the new bindings. But we'll
10195 recompute when update_mode_lines is set too; that means
10196 that people can use force-mode-line-update to request
10197 that the menu bar be recomputed. The adverse effect on
10198 the rest of the redisplay algorithm is about the same as
10199 windows_or_buffers_changed anyway. */
10200 if (windows_or_buffers_changed
10201 || !NILP (w
->update_mode_line
)
10202 || update_mode_lines
10203 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10204 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10205 != !NILP (w
->last_had_star
))
10206 || ((!NILP (Vtransient_mark_mode
)
10207 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10208 != !NILP (w
->region_showing
)))
10210 struct buffer
*prev
= current_buffer
;
10211 int count
= SPECPDL_INDEX ();
10212 Lisp_Object frame
, new_tool_bar
;
10213 int new_n_tool_bar
;
10214 struct gcpro gcpro1
;
10216 /* Set current_buffer to the buffer of the selected
10217 window of the frame, so that we get the right local
10219 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10221 /* Save match data, if we must. */
10222 if (save_match_data
)
10223 record_unwind_save_match_data ();
10225 /* Make sure that we don't accidentally use bogus keymaps. */
10226 if (NILP (Voverriding_local_map_menu_flag
))
10228 specbind (Qoverriding_terminal_local_map
, Qnil
);
10229 specbind (Qoverriding_local_map
, Qnil
);
10232 GCPRO1 (new_tool_bar
);
10234 /* We must temporarily set the selected frame to this frame
10235 before calling tool_bar_items, because the calculation of
10236 the tool-bar keymap uses the selected frame (see
10237 `tool-bar-make-keymap' in tool-bar.el). */
10238 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10239 XSETFRAME (frame
, f
);
10240 selected_frame
= frame
;
10242 /* Build desired tool-bar items from keymaps. */
10243 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10246 /* Redisplay the tool-bar if we changed it. */
10247 if (new_n_tool_bar
!= f
->n_tool_bar_items
10248 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10250 /* Redisplay that happens asynchronously due to an expose event
10251 may access f->tool_bar_items. Make sure we update both
10252 variables within BLOCK_INPUT so no such event interrupts. */
10254 f
->tool_bar_items
= new_tool_bar
;
10255 f
->n_tool_bar_items
= new_n_tool_bar
;
10256 w
->update_mode_line
= Qt
;
10262 unbind_to (count
, Qnil
);
10263 set_buffer_internal_1 (prev
);
10269 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10270 F's desired tool-bar contents. F->tool_bar_items must have
10271 been set up previously by calling prepare_menu_bars. */
10274 build_desired_tool_bar_string (struct frame
*f
)
10276 int i
, size
, size_needed
;
10277 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10278 Lisp_Object image
, plist
, props
;
10280 image
= plist
= props
= Qnil
;
10281 GCPRO3 (image
, plist
, props
);
10283 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10284 Otherwise, make a new string. */
10286 /* The size of the string we might be able to reuse. */
10287 size
= (STRINGP (f
->desired_tool_bar_string
)
10288 ? SCHARS (f
->desired_tool_bar_string
)
10291 /* We need one space in the string for each image. */
10292 size_needed
= f
->n_tool_bar_items
;
10294 /* Reuse f->desired_tool_bar_string, if possible. */
10295 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10296 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10297 make_number (' '));
10300 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10301 Fremove_text_properties (make_number (0), make_number (size
),
10302 props
, f
->desired_tool_bar_string
);
10305 /* Put a `display' property on the string for the images to display,
10306 put a `menu_item' property on tool-bar items with a value that
10307 is the index of the item in F's tool-bar item vector. */
10308 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10310 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10312 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10313 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10314 int hmargin
, vmargin
, relief
, idx
, end
;
10316 /* If image is a vector, choose the image according to the
10318 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10319 if (VECTORP (image
))
10323 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10324 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10327 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10328 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10330 xassert (ASIZE (image
) >= idx
);
10331 image
= AREF (image
, idx
);
10336 /* Ignore invalid image specifications. */
10337 if (!valid_image_p (image
))
10340 /* Display the tool-bar button pressed, or depressed. */
10341 plist
= Fcopy_sequence (XCDR (image
));
10343 /* Compute margin and relief to draw. */
10344 relief
= (tool_bar_button_relief
>= 0
10345 ? tool_bar_button_relief
10346 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10347 hmargin
= vmargin
= relief
;
10349 if (INTEGERP (Vtool_bar_button_margin
)
10350 && XINT (Vtool_bar_button_margin
) > 0)
10352 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10353 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10355 else if (CONSP (Vtool_bar_button_margin
))
10357 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10358 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10359 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10361 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10362 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10363 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10366 if (auto_raise_tool_bar_buttons_p
)
10368 /* Add a `:relief' property to the image spec if the item is
10372 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10379 /* If image is selected, display it pressed, i.e. with a
10380 negative relief. If it's not selected, display it with a
10382 plist
= Fplist_put (plist
, QCrelief
,
10384 ? make_number (-relief
)
10385 : make_number (relief
)));
10390 /* Put a margin around the image. */
10391 if (hmargin
|| vmargin
)
10393 if (hmargin
== vmargin
)
10394 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10396 plist
= Fplist_put (plist
, QCmargin
,
10397 Fcons (make_number (hmargin
),
10398 make_number (vmargin
)));
10401 /* If button is not enabled, and we don't have special images
10402 for the disabled state, make the image appear disabled by
10403 applying an appropriate algorithm to it. */
10404 if (!enabled_p
&& idx
< 0)
10405 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10407 /* Put a `display' text property on the string for the image to
10408 display. Put a `menu-item' property on the string that gives
10409 the start of this item's properties in the tool-bar items
10411 image
= Fcons (Qimage
, plist
);
10412 props
= list4 (Qdisplay
, image
,
10413 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10415 /* Let the last image hide all remaining spaces in the tool bar
10416 string. The string can be longer than needed when we reuse a
10417 previous string. */
10418 if (i
+ 1 == f
->n_tool_bar_items
)
10419 end
= SCHARS (f
->desired_tool_bar_string
);
10422 Fadd_text_properties (make_number (i
), make_number (end
),
10423 props
, f
->desired_tool_bar_string
);
10431 /* Display one line of the tool-bar of frame IT->f.
10433 HEIGHT specifies the desired height of the tool-bar line.
10434 If the actual height of the glyph row is less than HEIGHT, the
10435 row's height is increased to HEIGHT, and the icons are centered
10436 vertically in the new height.
10438 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10439 count a final empty row in case the tool-bar width exactly matches
10444 display_tool_bar_line (struct it
*it
, int height
)
10446 struct glyph_row
*row
= it
->glyph_row
;
10447 int max_x
= it
->last_visible_x
;
10448 struct glyph
*last
;
10450 prepare_desired_row (row
);
10451 row
->y
= it
->current_y
;
10453 /* Note that this isn't made use of if the face hasn't a box,
10454 so there's no need to check the face here. */
10455 it
->start_of_box_run_p
= 1;
10457 while (it
->current_x
< max_x
)
10459 int x
, n_glyphs_before
, i
, nglyphs
;
10460 struct it it_before
;
10462 /* Get the next display element. */
10463 if (!get_next_display_element (it
))
10465 /* Don't count empty row if we are counting needed tool-bar lines. */
10466 if (height
< 0 && !it
->hpos
)
10471 /* Produce glyphs. */
10472 n_glyphs_before
= row
->used
[TEXT_AREA
];
10475 PRODUCE_GLYPHS (it
);
10477 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10479 x
= it_before
.current_x
;
10480 while (i
< nglyphs
)
10482 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10484 if (x
+ glyph
->pixel_width
> max_x
)
10486 /* Glyph doesn't fit on line. Backtrack. */
10487 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10489 /* If this is the only glyph on this line, it will never fit on the
10490 toolbar, so skip it. But ensure there is at least one glyph,
10491 so we don't accidentally disable the tool-bar. */
10492 if (n_glyphs_before
== 0
10493 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10499 x
+= glyph
->pixel_width
;
10503 /* Stop at line ends. */
10504 if (ITERATOR_AT_END_OF_LINE_P (it
))
10507 set_iterator_to_next (it
, 1);
10512 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10514 /* Use default face for the border below the tool bar.
10516 FIXME: When auto-resize-tool-bars is grow-only, there is
10517 no additional border below the possibly empty tool-bar lines.
10518 So to make the extra empty lines look "normal", we have to
10519 use the tool-bar face for the border too. */
10520 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10521 it
->face_id
= DEFAULT_FACE_ID
;
10523 extend_face_to_end_of_line (it
);
10524 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10525 last
->right_box_line_p
= 1;
10526 if (last
== row
->glyphs
[TEXT_AREA
])
10527 last
->left_box_line_p
= 1;
10529 /* Make line the desired height and center it vertically. */
10530 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10532 /* Don't add more than one line height. */
10533 height
%= FRAME_LINE_HEIGHT (it
->f
);
10534 it
->max_ascent
+= height
/ 2;
10535 it
->max_descent
+= (height
+ 1) / 2;
10538 compute_line_metrics (it
);
10540 /* If line is empty, make it occupy the rest of the tool-bar. */
10541 if (!row
->displays_text_p
)
10543 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10544 row
->visible_height
= row
->height
;
10545 row
->ascent
= row
->phys_ascent
= 0;
10546 row
->extra_line_spacing
= 0;
10549 row
->full_width_p
= 1;
10550 row
->continued_p
= 0;
10551 row
->truncated_on_left_p
= 0;
10552 row
->truncated_on_right_p
= 0;
10554 it
->current_x
= it
->hpos
= 0;
10555 it
->current_y
+= row
->height
;
10561 /* Max tool-bar height. */
10563 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10564 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10566 /* Value is the number of screen lines needed to make all tool-bar
10567 items of frame F visible. The number of actual rows needed is
10568 returned in *N_ROWS if non-NULL. */
10571 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10573 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10575 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10576 the desired matrix, so use (unused) mode-line row as temporary row to
10577 avoid destroying the first tool-bar row. */
10578 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10580 /* Initialize an iterator for iteration over
10581 F->desired_tool_bar_string in the tool-bar window of frame F. */
10582 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10583 it
.first_visible_x
= 0;
10584 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10585 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10587 while (!ITERATOR_AT_END_P (&it
))
10589 clear_glyph_row (temp_row
);
10590 it
.glyph_row
= temp_row
;
10591 display_tool_bar_line (&it
, -1);
10593 clear_glyph_row (temp_row
);
10595 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10597 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10599 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10603 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10605 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10606 (Lisp_Object frame
)
10613 frame
= selected_frame
;
10615 CHECK_FRAME (frame
);
10616 f
= XFRAME (frame
);
10618 if (WINDOWP (f
->tool_bar_window
)
10619 || (w
= XWINDOW (f
->tool_bar_window
),
10620 WINDOW_TOTAL_LINES (w
) > 0))
10622 update_tool_bar (f
, 1);
10623 if (f
->n_tool_bar_items
)
10625 build_desired_tool_bar_string (f
);
10626 nlines
= tool_bar_lines_needed (f
, NULL
);
10630 return make_number (nlines
);
10634 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10635 height should be changed. */
10638 redisplay_tool_bar (struct frame
*f
)
10642 struct glyph_row
*row
;
10644 #if defined (USE_GTK) || defined (HAVE_NS)
10645 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10646 update_frame_tool_bar (f
);
10650 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10651 do anything. This means you must start with tool-bar-lines
10652 non-zero to get the auto-sizing effect. Or in other words, you
10653 can turn off tool-bars by specifying tool-bar-lines zero. */
10654 if (!WINDOWP (f
->tool_bar_window
)
10655 || (w
= XWINDOW (f
->tool_bar_window
),
10656 WINDOW_TOTAL_LINES (w
) == 0))
10659 /* Set up an iterator for the tool-bar window. */
10660 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10661 it
.first_visible_x
= 0;
10662 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10663 row
= it
.glyph_row
;
10665 /* Build a string that represents the contents of the tool-bar. */
10666 build_desired_tool_bar_string (f
);
10667 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10669 if (f
->n_tool_bar_rows
== 0)
10673 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10674 nlines
!= WINDOW_TOTAL_LINES (w
)))
10677 int old_height
= WINDOW_TOTAL_LINES (w
);
10679 XSETFRAME (frame
, f
);
10680 Fmodify_frame_parameters (frame
,
10681 Fcons (Fcons (Qtool_bar_lines
,
10682 make_number (nlines
)),
10684 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10686 clear_glyph_matrix (w
->desired_matrix
);
10687 fonts_changed_p
= 1;
10693 /* Display as many lines as needed to display all tool-bar items. */
10695 if (f
->n_tool_bar_rows
> 0)
10697 int border
, rows
, height
, extra
;
10699 if (INTEGERP (Vtool_bar_border
))
10700 border
= XINT (Vtool_bar_border
);
10701 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10702 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10703 else if (EQ (Vtool_bar_border
, Qborder_width
))
10704 border
= f
->border_width
;
10710 rows
= f
->n_tool_bar_rows
;
10711 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10712 extra
= it
.last_visible_y
- border
- height
* rows
;
10714 while (it
.current_y
< it
.last_visible_y
)
10717 if (extra
> 0 && rows
-- > 0)
10719 h
= (extra
+ rows
- 1) / rows
;
10722 display_tool_bar_line (&it
, height
+ h
);
10727 while (it
.current_y
< it
.last_visible_y
)
10728 display_tool_bar_line (&it
, 0);
10731 /* It doesn't make much sense to try scrolling in the tool-bar
10732 window, so don't do it. */
10733 w
->desired_matrix
->no_scrolling_p
= 1;
10734 w
->must_be_updated_p
= 1;
10736 if (!NILP (Vauto_resize_tool_bars
))
10738 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10739 int change_height_p
= 0;
10741 /* If we couldn't display everything, change the tool-bar's
10742 height if there is room for more. */
10743 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10744 && it
.current_y
< max_tool_bar_height
)
10745 change_height_p
= 1;
10747 row
= it
.glyph_row
- 1;
10749 /* If there are blank lines at the end, except for a partially
10750 visible blank line at the end that is smaller than
10751 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10752 if (!row
->displays_text_p
10753 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10754 change_height_p
= 1;
10756 /* If row displays tool-bar items, but is partially visible,
10757 change the tool-bar's height. */
10758 if (row
->displays_text_p
10759 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10760 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10761 change_height_p
= 1;
10763 /* Resize windows as needed by changing the `tool-bar-lines'
10764 frame parameter. */
10765 if (change_height_p
)
10768 int old_height
= WINDOW_TOTAL_LINES (w
);
10770 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10772 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10773 && !f
->minimize_tool_bar_window_p
)
10774 ? (nlines
> old_height
)
10775 : (nlines
!= old_height
));
10776 f
->minimize_tool_bar_window_p
= 0;
10778 if (change_height_p
)
10780 XSETFRAME (frame
, f
);
10781 Fmodify_frame_parameters (frame
,
10782 Fcons (Fcons (Qtool_bar_lines
,
10783 make_number (nlines
)),
10785 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10787 clear_glyph_matrix (w
->desired_matrix
);
10788 f
->n_tool_bar_rows
= nrows
;
10789 fonts_changed_p
= 1;
10796 f
->minimize_tool_bar_window_p
= 0;
10801 /* Get information about the tool-bar item which is displayed in GLYPH
10802 on frame F. Return in *PROP_IDX the index where tool-bar item
10803 properties start in F->tool_bar_items. Value is zero if
10804 GLYPH doesn't display a tool-bar item. */
10807 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
10813 /* This function can be called asynchronously, which means we must
10814 exclude any possibility that Fget_text_property signals an
10816 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10817 charpos
= max (0, charpos
);
10819 /* Get the text property `menu-item' at pos. The value of that
10820 property is the start index of this item's properties in
10821 F->tool_bar_items. */
10822 prop
= Fget_text_property (make_number (charpos
),
10823 Qmenu_item
, f
->current_tool_bar_string
);
10824 if (INTEGERP (prop
))
10826 *prop_idx
= XINT (prop
);
10836 /* Get information about the tool-bar item at position X/Y on frame F.
10837 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10838 the current matrix of the tool-bar window of F, or NULL if not
10839 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10840 item in F->tool_bar_items. Value is
10842 -1 if X/Y is not on a tool-bar item
10843 0 if X/Y is on the same item that was highlighted before.
10847 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
10848 int *hpos
, int *vpos
, int *prop_idx
)
10850 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10851 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10854 /* Find the glyph under X/Y. */
10855 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10856 if (*glyph
== NULL
)
10859 /* Get the start of this tool-bar item's properties in
10860 f->tool_bar_items. */
10861 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10864 /* Is mouse on the highlighted item? */
10865 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
10866 && *vpos
>= hlinfo
->mouse_face_beg_row
10867 && *vpos
<= hlinfo
->mouse_face_end_row
10868 && (*vpos
> hlinfo
->mouse_face_beg_row
10869 || *hpos
>= hlinfo
->mouse_face_beg_col
)
10870 && (*vpos
< hlinfo
->mouse_face_end_row
10871 || *hpos
< hlinfo
->mouse_face_end_col
10872 || hlinfo
->mouse_face_past_end
))
10880 Handle mouse button event on the tool-bar of frame F, at
10881 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10882 0 for button release. MODIFIERS is event modifiers for button
10886 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
10887 unsigned int modifiers
)
10889 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10890 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10891 int hpos
, vpos
, prop_idx
;
10892 struct glyph
*glyph
;
10893 Lisp_Object enabled_p
;
10895 /* If not on the highlighted tool-bar item, return. */
10896 frame_to_window_pixel_xy (w
, &x
, &y
);
10897 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10900 /* If item is disabled, do nothing. */
10901 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10902 if (NILP (enabled_p
))
10907 /* Show item in pressed state. */
10908 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
10909 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10910 last_tool_bar_item
= prop_idx
;
10914 Lisp_Object key
, frame
;
10915 struct input_event event
;
10916 EVENT_INIT (event
);
10918 /* Show item in released state. */
10919 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
10920 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10922 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10924 XSETFRAME (frame
, f
);
10925 event
.kind
= TOOL_BAR_EVENT
;
10926 event
.frame_or_window
= frame
;
10928 kbd_buffer_store_event (&event
);
10930 event
.kind
= TOOL_BAR_EVENT
;
10931 event
.frame_or_window
= frame
;
10933 event
.modifiers
= modifiers
;
10934 kbd_buffer_store_event (&event
);
10935 last_tool_bar_item
= -1;
10940 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10941 tool-bar window-relative coordinates X/Y. Called from
10942 note_mouse_highlight. */
10945 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
10947 Lisp_Object window
= f
->tool_bar_window
;
10948 struct window
*w
= XWINDOW (window
);
10949 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10950 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10952 struct glyph
*glyph
;
10953 struct glyph_row
*row
;
10955 Lisp_Object enabled_p
;
10957 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10958 int mouse_down_p
, rc
;
10960 /* Function note_mouse_highlight is called with negative X/Y
10961 values when mouse moves outside of the frame. */
10962 if (x
<= 0 || y
<= 0)
10964 clear_mouse_face (hlinfo
);
10968 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10971 /* Not on tool-bar item. */
10972 clear_mouse_face (hlinfo
);
10976 /* On same tool-bar item as before. */
10977 goto set_help_echo
;
10979 clear_mouse_face (hlinfo
);
10981 /* Mouse is down, but on different tool-bar item? */
10982 mouse_down_p
= (dpyinfo
->grabbed
10983 && f
== last_mouse_frame
10984 && FRAME_LIVE_P (f
));
10986 && last_tool_bar_item
!= prop_idx
)
10989 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10990 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10992 /* If tool-bar item is not enabled, don't highlight it. */
10993 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10994 if (!NILP (enabled_p
))
10996 /* Compute the x-position of the glyph. In front and past the
10997 image is a space. We include this in the highlighted area. */
10998 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10999 for (i
= x
= 0; i
< hpos
; ++i
)
11000 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11002 /* Record this as the current active region. */
11003 hlinfo
->mouse_face_beg_col
= hpos
;
11004 hlinfo
->mouse_face_beg_row
= vpos
;
11005 hlinfo
->mouse_face_beg_x
= x
;
11006 hlinfo
->mouse_face_beg_y
= row
->y
;
11007 hlinfo
->mouse_face_past_end
= 0;
11009 hlinfo
->mouse_face_end_col
= hpos
+ 1;
11010 hlinfo
->mouse_face_end_row
= vpos
;
11011 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11012 hlinfo
->mouse_face_end_y
= row
->y
;
11013 hlinfo
->mouse_face_window
= window
;
11014 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11016 /* Display it as active. */
11017 show_mouse_face (hlinfo
, draw
);
11018 hlinfo
->mouse_face_image_state
= draw
;
11023 /* Set help_echo_string to a help string to display for this tool-bar item.
11024 XTread_socket does the rest. */
11025 help_echo_object
= help_echo_window
= Qnil
;
11026 help_echo_pos
= -1;
11027 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11028 if (NILP (help_echo_string
))
11029 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11032 #endif /* HAVE_WINDOW_SYSTEM */
11036 /************************************************************************
11037 Horizontal scrolling
11038 ************************************************************************/
11040 static int hscroll_window_tree (Lisp_Object
);
11041 static int hscroll_windows (Lisp_Object
);
11043 /* For all leaf windows in the window tree rooted at WINDOW, set their
11044 hscroll value so that PT is (i) visible in the window, and (ii) so
11045 that it is not within a certain margin at the window's left and
11046 right border. Value is non-zero if any window's hscroll has been
11050 hscroll_window_tree (Lisp_Object window
)
11052 int hscrolled_p
= 0;
11053 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11054 int hscroll_step_abs
= 0;
11055 double hscroll_step_rel
= 0;
11057 if (hscroll_relative_p
)
11059 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11060 if (hscroll_step_rel
< 0)
11062 hscroll_relative_p
= 0;
11063 hscroll_step_abs
= 0;
11066 else if (INTEGERP (Vhscroll_step
))
11068 hscroll_step_abs
= XINT (Vhscroll_step
);
11069 if (hscroll_step_abs
< 0)
11070 hscroll_step_abs
= 0;
11073 hscroll_step_abs
= 0;
11075 while (WINDOWP (window
))
11077 struct window
*w
= XWINDOW (window
);
11079 if (WINDOWP (w
->hchild
))
11080 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11081 else if (WINDOWP (w
->vchild
))
11082 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11083 else if (w
->cursor
.vpos
>= 0)
11086 int text_area_width
;
11087 struct glyph_row
*current_cursor_row
11088 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11089 struct glyph_row
*desired_cursor_row
11090 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11091 struct glyph_row
*cursor_row
11092 = (desired_cursor_row
->enabled_p
11093 ? desired_cursor_row
11094 : current_cursor_row
);
11096 text_area_width
= window_box_width (w
, TEXT_AREA
);
11098 /* Scroll when cursor is inside this scroll margin. */
11099 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11101 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11102 && ((XFASTINT (w
->hscroll
)
11103 && w
->cursor
.x
<= h_margin
)
11104 || (cursor_row
->enabled_p
11105 && cursor_row
->truncated_on_right_p
11106 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11110 struct buffer
*saved_current_buffer
;
11114 /* Find point in a display of infinite width. */
11115 saved_current_buffer
= current_buffer
;
11116 current_buffer
= XBUFFER (w
->buffer
);
11118 if (w
== XWINDOW (selected_window
))
11119 pt
= BUF_PT (current_buffer
);
11122 pt
= marker_position (w
->pointm
);
11123 pt
= max (BEGV
, pt
);
11127 /* Move iterator to pt starting at cursor_row->start in
11128 a line with infinite width. */
11129 init_to_row_start (&it
, w
, cursor_row
);
11130 it
.last_visible_x
= INFINITY
;
11131 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11132 current_buffer
= saved_current_buffer
;
11134 /* Position cursor in window. */
11135 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11136 hscroll
= max (0, (it
.current_x
11137 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11138 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11139 : (text_area_width
/ 2))))
11140 / FRAME_COLUMN_WIDTH (it
.f
);
11141 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11143 if (hscroll_relative_p
)
11144 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11147 wanted_x
= text_area_width
11148 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11151 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11155 if (hscroll_relative_p
)
11156 wanted_x
= text_area_width
* hscroll_step_rel
11159 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11162 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11164 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11166 /* Don't call Fset_window_hscroll if value hasn't
11167 changed because it will prevent redisplay
11169 if (XFASTINT (w
->hscroll
) != hscroll
)
11171 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11172 w
->hscroll
= make_number (hscroll
);
11181 /* Value is non-zero if hscroll of any leaf window has been changed. */
11182 return hscrolled_p
;
11186 /* Set hscroll so that cursor is visible and not inside horizontal
11187 scroll margins for all windows in the tree rooted at WINDOW. See
11188 also hscroll_window_tree above. Value is non-zero if any window's
11189 hscroll has been changed. If it has, desired matrices on the frame
11190 of WINDOW are cleared. */
11193 hscroll_windows (Lisp_Object window
)
11195 int hscrolled_p
= hscroll_window_tree (window
);
11197 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11198 return hscrolled_p
;
11203 /************************************************************************
11205 ************************************************************************/
11207 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11208 to a non-zero value. This is sometimes handy to have in a debugger
11213 /* First and last unchanged row for try_window_id. */
11215 int debug_first_unchanged_at_end_vpos
;
11216 int debug_last_unchanged_at_beg_vpos
;
11218 /* Delta vpos and y. */
11220 int debug_dvpos
, debug_dy
;
11222 /* Delta in characters and bytes for try_window_id. */
11224 EMACS_INT debug_delta
, debug_delta_bytes
;
11226 /* Values of window_end_pos and window_end_vpos at the end of
11229 EMACS_INT debug_end_pos
, debug_end_vpos
;
11231 /* Append a string to W->desired_matrix->method. FMT is a printf
11232 format string. A1...A9 are a supplement for a variable-length
11233 argument list. If trace_redisplay_p is non-zero also printf the
11234 resulting string to stderr. */
11237 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11240 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11243 char *method
= w
->desired_matrix
->method
;
11244 int len
= strlen (method
);
11245 int size
= sizeof w
->desired_matrix
->method
;
11246 int remaining
= size
- len
- 1;
11248 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11249 if (len
&& remaining
)
11252 --remaining
, ++len
;
11255 strncpy (method
+ len
, buffer
, remaining
);
11257 if (trace_redisplay_p
)
11258 fprintf (stderr
, "%p (%s): %s\n",
11260 ((BUFFERP (w
->buffer
)
11261 && STRINGP (XBUFFER (w
->buffer
)->name
))
11262 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
11267 #endif /* GLYPH_DEBUG */
11270 /* Value is non-zero if all changes in window W, which displays
11271 current_buffer, are in the text between START and END. START is a
11272 buffer position, END is given as a distance from Z. Used in
11273 redisplay_internal for display optimization. */
11276 text_outside_line_unchanged_p (struct window
*w
,
11277 EMACS_INT start
, EMACS_INT end
)
11279 int unchanged_p
= 1;
11281 /* If text or overlays have changed, see where. */
11282 if (XFASTINT (w
->last_modified
) < MODIFF
11283 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11285 /* Gap in the line? */
11286 if (GPT
< start
|| Z
- GPT
< end
)
11289 /* Changes start in front of the line, or end after it? */
11291 && (BEG_UNCHANGED
< start
- 1
11292 || END_UNCHANGED
< end
))
11295 /* If selective display, can't optimize if changes start at the
11296 beginning of the line. */
11298 && INTEGERP (current_buffer
->selective_display
)
11299 && XINT (current_buffer
->selective_display
) > 0
11300 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11303 /* If there are overlays at the start or end of the line, these
11304 may have overlay strings with newlines in them. A change at
11305 START, for instance, may actually concern the display of such
11306 overlay strings as well, and they are displayed on different
11307 lines. So, quickly rule out this case. (For the future, it
11308 might be desirable to implement something more telling than
11309 just BEG/END_UNCHANGED.) */
11312 if (BEG
+ BEG_UNCHANGED
== start
11313 && overlay_touches_p (start
))
11315 if (END_UNCHANGED
== end
11316 && overlay_touches_p (Z
- end
))
11320 /* Under bidi reordering, adding or deleting a character in the
11321 beginning of a paragraph, before the first strong directional
11322 character, can change the base direction of the paragraph (unless
11323 the buffer specifies a fixed paragraph direction), which will
11324 require to redisplay the whole paragraph. It might be worthwhile
11325 to find the paragraph limits and widen the range of redisplayed
11326 lines to that, but for now just give up this optimization. */
11327 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
11328 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
11332 return unchanged_p
;
11336 /* Do a frame update, taking possible shortcuts into account. This is
11337 the main external entry point for redisplay.
11339 If the last redisplay displayed an echo area message and that message
11340 is no longer requested, we clear the echo area or bring back the
11341 mini-buffer if that is in use. */
11346 redisplay_internal (0);
11351 overlay_arrow_string_or_property (Lisp_Object var
)
11355 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11358 return Voverlay_arrow_string
;
11361 /* Return 1 if there are any overlay-arrows in current_buffer. */
11363 overlay_arrow_in_current_buffer_p (void)
11367 for (vlist
= Voverlay_arrow_variable_list
;
11369 vlist
= XCDR (vlist
))
11371 Lisp_Object var
= XCAR (vlist
);
11374 if (!SYMBOLP (var
))
11376 val
= find_symbol_value (var
);
11378 && current_buffer
== XMARKER (val
)->buffer
)
11385 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11389 overlay_arrows_changed_p (void)
11393 for (vlist
= Voverlay_arrow_variable_list
;
11395 vlist
= XCDR (vlist
))
11397 Lisp_Object var
= XCAR (vlist
);
11398 Lisp_Object val
, pstr
;
11400 if (!SYMBOLP (var
))
11402 val
= find_symbol_value (var
);
11403 if (!MARKERP (val
))
11405 if (! EQ (COERCE_MARKER (val
),
11406 Fget (var
, Qlast_arrow_position
))
11407 || ! (pstr
= overlay_arrow_string_or_property (var
),
11408 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11414 /* Mark overlay arrows to be updated on next redisplay. */
11417 update_overlay_arrows (int up_to_date
)
11421 for (vlist
= Voverlay_arrow_variable_list
;
11423 vlist
= XCDR (vlist
))
11425 Lisp_Object var
= XCAR (vlist
);
11427 if (!SYMBOLP (var
))
11430 if (up_to_date
> 0)
11432 Lisp_Object val
= find_symbol_value (var
);
11433 Fput (var
, Qlast_arrow_position
,
11434 COERCE_MARKER (val
));
11435 Fput (var
, Qlast_arrow_string
,
11436 overlay_arrow_string_or_property (var
));
11438 else if (up_to_date
< 0
11439 || !NILP (Fget (var
, Qlast_arrow_position
)))
11441 Fput (var
, Qlast_arrow_position
, Qt
);
11442 Fput (var
, Qlast_arrow_string
, Qt
);
11448 /* Return overlay arrow string to display at row.
11449 Return integer (bitmap number) for arrow bitmap in left fringe.
11450 Return nil if no overlay arrow. */
11453 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11457 for (vlist
= Voverlay_arrow_variable_list
;
11459 vlist
= XCDR (vlist
))
11461 Lisp_Object var
= XCAR (vlist
);
11464 if (!SYMBOLP (var
))
11467 val
= find_symbol_value (var
);
11470 && current_buffer
== XMARKER (val
)->buffer
11471 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11473 if (FRAME_WINDOW_P (it
->f
)
11474 /* FIXME: if ROW->reversed_p is set, this should test
11475 the right fringe, not the left one. */
11476 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11478 #ifdef HAVE_WINDOW_SYSTEM
11479 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11482 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11483 return make_number (fringe_bitmap
);
11486 return make_number (-1); /* Use default arrow bitmap */
11488 return overlay_arrow_string_or_property (var
);
11495 /* Return 1 if point moved out of or into a composition. Otherwise
11496 return 0. PREV_BUF and PREV_PT are the last point buffer and
11497 position. BUF and PT are the current point buffer and position. */
11500 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11501 struct buffer
*buf
, EMACS_INT pt
)
11503 EMACS_INT start
, end
;
11505 Lisp_Object buffer
;
11507 XSETBUFFER (buffer
, buf
);
11508 /* Check a composition at the last point if point moved within the
11510 if (prev_buf
== buf
)
11513 /* Point didn't move. */
11516 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11517 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11518 && COMPOSITION_VALID_P (start
, end
, prop
)
11519 && start
< prev_pt
&& end
> prev_pt
)
11520 /* The last point was within the composition. Return 1 iff
11521 point moved out of the composition. */
11522 return (pt
<= start
|| pt
>= end
);
11525 /* Check a composition at the current point. */
11526 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11527 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11528 && COMPOSITION_VALID_P (start
, end
, prop
)
11529 && start
< pt
&& end
> pt
);
11533 /* Reconsider the setting of B->clip_changed which is displayed
11537 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11539 if (b
->clip_changed
11540 && !NILP (w
->window_end_valid
)
11541 && w
->current_matrix
->buffer
== b
11542 && w
->current_matrix
->zv
== BUF_ZV (b
)
11543 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11544 b
->clip_changed
= 0;
11546 /* If display wasn't paused, and W is not a tool bar window, see if
11547 point has been moved into or out of a composition. In that case,
11548 we set b->clip_changed to 1 to force updating the screen. If
11549 b->clip_changed has already been set to 1, we can skip this
11551 if (!b
->clip_changed
11552 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11556 if (w
== XWINDOW (selected_window
))
11557 pt
= BUF_PT (current_buffer
);
11559 pt
= marker_position (w
->pointm
);
11561 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11562 || pt
!= XINT (w
->last_point
))
11563 && check_point_in_composition (w
->current_matrix
->buffer
,
11564 XINT (w
->last_point
),
11565 XBUFFER (w
->buffer
), pt
))
11566 b
->clip_changed
= 1;
11571 /* Select FRAME to forward the values of frame-local variables into C
11572 variables so that the redisplay routines can access those values
11576 select_frame_for_redisplay (Lisp_Object frame
)
11578 Lisp_Object tail
, tem
;
11579 Lisp_Object old
= selected_frame
;
11580 struct Lisp_Symbol
*sym
;
11582 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11584 selected_frame
= frame
;
11587 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11588 if (CONSP (XCAR (tail
))
11589 && (tem
= XCAR (XCAR (tail
)),
11591 && (sym
= indirect_variable (XSYMBOL (tem
)),
11592 sym
->redirect
== SYMBOL_LOCALIZED
)
11593 && sym
->val
.blv
->frame_local
)
11594 /* Use find_symbol_value rather than Fsymbol_value
11595 to avoid an error if it is void. */
11596 find_symbol_value (tem
);
11597 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11601 #define STOP_POLLING \
11602 do { if (! polling_stopped_here) stop_polling (); \
11603 polling_stopped_here = 1; } while (0)
11605 #define RESUME_POLLING \
11606 do { if (polling_stopped_here) start_polling (); \
11607 polling_stopped_here = 0; } while (0)
11610 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11611 response to any user action; therefore, we should preserve the echo
11612 area. (Actually, our caller does that job.) Perhaps in the future
11613 avoid recentering windows if it is not necessary; currently that
11614 causes some problems. */
11617 redisplay_internal (int preserve_echo_area
)
11619 struct window
*w
= XWINDOW (selected_window
);
11622 int must_finish
= 0;
11623 struct text_pos tlbufpos
, tlendpos
;
11624 int number_of_visible_frames
;
11627 int polling_stopped_here
= 0;
11628 Lisp_Object old_frame
= selected_frame
;
11630 /* Non-zero means redisplay has to consider all windows on all
11631 frames. Zero means, only selected_window is considered. */
11632 int consider_all_windows_p
;
11634 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11636 /* No redisplay if running in batch mode or frame is not yet fully
11637 initialized, or redisplay is explicitly turned off by setting
11638 Vinhibit_redisplay. */
11639 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11640 || !NILP (Vinhibit_redisplay
))
11643 /* Don't examine these until after testing Vinhibit_redisplay.
11644 When Emacs is shutting down, perhaps because its connection to
11645 X has dropped, we should not look at them at all. */
11646 f
= XFRAME (w
->frame
);
11647 sf
= SELECTED_FRAME ();
11649 if (!f
->glyphs_initialized_p
)
11652 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11653 if (popup_activated ())
11657 /* I don't think this happens but let's be paranoid. */
11658 if (redisplaying_p
)
11661 /* Record a function that resets redisplaying_p to its old value
11662 when we leave this function. */
11663 count
= SPECPDL_INDEX ();
11664 record_unwind_protect (unwind_redisplay
,
11665 Fcons (make_number (redisplaying_p
), selected_frame
));
11667 specbind (Qinhibit_free_realized_faces
, Qnil
);
11670 Lisp_Object tail
, frame
;
11672 FOR_EACH_FRAME (tail
, frame
)
11674 struct frame
*f
= XFRAME (frame
);
11675 f
->already_hscrolled_p
= 0;
11680 if (!EQ (old_frame
, selected_frame
)
11681 && FRAME_LIVE_P (XFRAME (old_frame
)))
11682 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11683 selected_frame and selected_window to be temporarily out-of-sync so
11684 when we come back here via `goto retry', we need to resync because we
11685 may need to run Elisp code (via prepare_menu_bars). */
11686 select_frame_for_redisplay (old_frame
);
11689 reconsider_clip_changes (w
, current_buffer
);
11690 last_escape_glyph_frame
= NULL
;
11691 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11692 last_glyphless_glyph_frame
= NULL
;
11693 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
11695 /* If new fonts have been loaded that make a glyph matrix adjustment
11696 necessary, do it. */
11697 if (fonts_changed_p
)
11699 adjust_glyphs (NULL
);
11700 ++windows_or_buffers_changed
;
11701 fonts_changed_p
= 0;
11704 /* If face_change_count is non-zero, init_iterator will free all
11705 realized faces, which includes the faces referenced from current
11706 matrices. So, we can't reuse current matrices in this case. */
11707 if (face_change_count
)
11708 ++windows_or_buffers_changed
;
11710 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11711 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11713 /* Since frames on a single ASCII terminal share the same
11714 display area, displaying a different frame means redisplay
11715 the whole thing. */
11716 windows_or_buffers_changed
++;
11717 SET_FRAME_GARBAGED (sf
);
11719 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11721 FRAME_TTY (sf
)->previous_frame
= sf
;
11724 /* Set the visible flags for all frames. Do this before checking
11725 for resized or garbaged frames; they want to know if their frames
11726 are visible. See the comment in frame.h for
11727 FRAME_SAMPLE_VISIBILITY. */
11729 Lisp_Object tail
, frame
;
11731 number_of_visible_frames
= 0;
11733 FOR_EACH_FRAME (tail
, frame
)
11735 struct frame
*f
= XFRAME (frame
);
11737 FRAME_SAMPLE_VISIBILITY (f
);
11738 if (FRAME_VISIBLE_P (f
))
11739 ++number_of_visible_frames
;
11740 clear_desired_matrices (f
);
11744 /* Notice any pending interrupt request to change frame size. */
11745 do_pending_window_change (1);
11747 /* Clear frames marked as garbaged. */
11748 if (frame_garbaged
)
11749 clear_garbaged_frames ();
11751 /* Build menubar and tool-bar items. */
11752 if (NILP (Vmemory_full
))
11753 prepare_menu_bars ();
11755 if (windows_or_buffers_changed
)
11756 update_mode_lines
++;
11758 /* Detect case that we need to write or remove a star in the mode line. */
11759 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11761 w
->update_mode_line
= Qt
;
11762 if (buffer_shared
> 1)
11763 update_mode_lines
++;
11766 /* Avoid invocation of point motion hooks by `current_column' below. */
11767 count1
= SPECPDL_INDEX ();
11768 specbind (Qinhibit_point_motion_hooks
, Qt
);
11770 /* If %c is in the mode line, update it if needed. */
11771 if (!NILP (w
->column_number_displayed
)
11772 /* This alternative quickly identifies a common case
11773 where no change is needed. */
11774 && !(PT
== XFASTINT (w
->last_point
)
11775 && XFASTINT (w
->last_modified
) >= MODIFF
11776 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11777 && (XFASTINT (w
->column_number_displayed
)
11778 != (int) current_column ())) /* iftc */
11779 w
->update_mode_line
= Qt
;
11781 unbind_to (count1
, Qnil
);
11783 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11785 /* The variable buffer_shared is set in redisplay_window and
11786 indicates that we redisplay a buffer in different windows. See
11788 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11789 || cursor_type_changed
);
11791 /* If specs for an arrow have changed, do thorough redisplay
11792 to ensure we remove any arrow that should no longer exist. */
11793 if (overlay_arrows_changed_p ())
11794 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11796 /* Normally the message* functions will have already displayed and
11797 updated the echo area, but the frame may have been trashed, or
11798 the update may have been preempted, so display the echo area
11799 again here. Checking message_cleared_p captures the case that
11800 the echo area should be cleared. */
11801 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11802 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11803 || (message_cleared_p
11804 && minibuf_level
== 0
11805 /* If the mini-window is currently selected, this means the
11806 echo-area doesn't show through. */
11807 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11809 int window_height_changed_p
= echo_area_display (0);
11812 /* If we don't display the current message, don't clear the
11813 message_cleared_p flag, because, if we did, we wouldn't clear
11814 the echo area in the next redisplay which doesn't preserve
11816 if (!display_last_displayed_message_p
)
11817 message_cleared_p
= 0;
11819 if (fonts_changed_p
)
11821 else if (window_height_changed_p
)
11823 consider_all_windows_p
= 1;
11824 ++update_mode_lines
;
11825 ++windows_or_buffers_changed
;
11827 /* If window configuration was changed, frames may have been
11828 marked garbaged. Clear them or we will experience
11829 surprises wrt scrolling. */
11830 if (frame_garbaged
)
11831 clear_garbaged_frames ();
11834 else if (EQ (selected_window
, minibuf_window
)
11835 && (current_buffer
->clip_changed
11836 || XFASTINT (w
->last_modified
) < MODIFF
11837 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11838 && resize_mini_window (w
, 0))
11840 /* Resized active mini-window to fit the size of what it is
11841 showing if its contents might have changed. */
11843 /* FIXME: this causes all frames to be updated, which seems unnecessary
11844 since only the current frame needs to be considered. This function needs
11845 to be rewritten with two variables, consider_all_windows and
11846 consider_all_frames. */
11847 consider_all_windows_p
= 1;
11848 ++windows_or_buffers_changed
;
11849 ++update_mode_lines
;
11851 /* If window configuration was changed, frames may have been
11852 marked garbaged. Clear them or we will experience
11853 surprises wrt scrolling. */
11854 if (frame_garbaged
)
11855 clear_garbaged_frames ();
11859 /* If showing the region, and mark has changed, we must redisplay
11860 the whole window. The assignment to this_line_start_pos prevents
11861 the optimization directly below this if-statement. */
11862 if (((!NILP (Vtransient_mark_mode
)
11863 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11864 != !NILP (w
->region_showing
))
11865 || (!NILP (w
->region_showing
)
11866 && !EQ (w
->region_showing
,
11867 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11868 CHARPOS (this_line_start_pos
) = 0;
11870 /* Optimize the case that only the line containing the cursor in the
11871 selected window has changed. Variables starting with this_ are
11872 set in display_line and record information about the line
11873 containing the cursor. */
11874 tlbufpos
= this_line_start_pos
;
11875 tlendpos
= this_line_end_pos
;
11876 if (!consider_all_windows_p
11877 && CHARPOS (tlbufpos
) > 0
11878 && NILP (w
->update_mode_line
)
11879 && !current_buffer
->clip_changed
11880 && !current_buffer
->prevent_redisplay_optimizations_p
11881 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11882 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11883 /* Make sure recorded data applies to current buffer, etc. */
11884 && this_line_buffer
== current_buffer
11885 && current_buffer
== XBUFFER (w
->buffer
)
11886 && NILP (w
->force_start
)
11887 && NILP (w
->optional_new_start
)
11888 /* Point must be on the line that we have info recorded about. */
11889 && PT
>= CHARPOS (tlbufpos
)
11890 && PT
<= Z
- CHARPOS (tlendpos
)
11891 /* All text outside that line, including its final newline,
11892 must be unchanged. */
11893 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11894 CHARPOS (tlendpos
)))
11896 if (CHARPOS (tlbufpos
) > BEGV
11897 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11898 && (CHARPOS (tlbufpos
) == ZV
11899 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11900 /* Former continuation line has disappeared by becoming empty. */
11902 else if (XFASTINT (w
->last_modified
) < MODIFF
11903 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11904 || MINI_WINDOW_P (w
))
11906 /* We have to handle the case of continuation around a
11907 wide-column character (see the comment in indent.c around
11910 For instance, in the following case:
11912 -------- Insert --------
11913 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11914 J_I_ ==> J_I_ `^^' are cursors.
11918 As we have to redraw the line above, we cannot use this
11922 int line_height_before
= this_line_pixel_height
;
11924 /* Note that start_display will handle the case that the
11925 line starting at tlbufpos is a continuation line. */
11926 start_display (&it
, w
, tlbufpos
);
11928 /* Implementation note: It this still necessary? */
11929 if (it
.current_x
!= this_line_start_x
)
11932 TRACE ((stderr
, "trying display optimization 1\n"));
11933 w
->cursor
.vpos
= -1;
11934 overlay_arrow_seen
= 0;
11935 it
.vpos
= this_line_vpos
;
11936 it
.current_y
= this_line_y
;
11937 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11938 display_line (&it
);
11940 /* If line contains point, is not continued,
11941 and ends at same distance from eob as before, we win. */
11942 if (w
->cursor
.vpos
>= 0
11943 /* Line is not continued, otherwise this_line_start_pos
11944 would have been set to 0 in display_line. */
11945 && CHARPOS (this_line_start_pos
)
11946 /* Line ends as before. */
11947 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11948 /* Line has same height as before. Otherwise other lines
11949 would have to be shifted up or down. */
11950 && this_line_pixel_height
== line_height_before
)
11952 /* If this is not the window's last line, we must adjust
11953 the charstarts of the lines below. */
11954 if (it
.current_y
< it
.last_visible_y
)
11956 struct glyph_row
*row
11957 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11958 EMACS_INT delta
, delta_bytes
;
11960 /* We used to distinguish between two cases here,
11961 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11962 when the line ends in a newline or the end of the
11963 buffer's accessible portion. But both cases did
11964 the same, so they were collapsed. */
11966 - CHARPOS (tlendpos
)
11967 - MATRIX_ROW_START_CHARPOS (row
));
11968 delta_bytes
= (Z_BYTE
11969 - BYTEPOS (tlendpos
)
11970 - MATRIX_ROW_START_BYTEPOS (row
));
11972 increment_matrix_positions (w
->current_matrix
,
11973 this_line_vpos
+ 1,
11974 w
->current_matrix
->nrows
,
11975 delta
, delta_bytes
);
11978 /* If this row displays text now but previously didn't,
11979 or vice versa, w->window_end_vpos may have to be
11981 if ((it
.glyph_row
- 1)->displays_text_p
)
11983 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11984 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11986 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11987 && this_line_vpos
> 0)
11988 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11989 w
->window_end_valid
= Qnil
;
11991 /* Update hint: No need to try to scroll in update_window. */
11992 w
->desired_matrix
->no_scrolling_p
= 1;
11995 *w
->desired_matrix
->method
= 0;
11996 debug_method_add (w
, "optimization 1");
11998 #ifdef HAVE_WINDOW_SYSTEM
11999 update_window_fringes (w
, 0);
12006 else if (/* Cursor position hasn't changed. */
12007 PT
== XFASTINT (w
->last_point
)
12008 /* Make sure the cursor was last displayed
12009 in this window. Otherwise we have to reposition it. */
12010 && 0 <= w
->cursor
.vpos
12011 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12015 do_pending_window_change (1);
12017 /* We used to always goto end_of_redisplay here, but this
12018 isn't enough if we have a blinking cursor. */
12019 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12020 goto end_of_redisplay
;
12024 /* If highlighting the region, or if the cursor is in the echo area,
12025 then we can't just move the cursor. */
12026 else if (! (!NILP (Vtransient_mark_mode
)
12027 && !NILP (current_buffer
->mark_active
))
12028 && (EQ (selected_window
, current_buffer
->last_selected_window
)
12029 || highlight_nonselected_windows
)
12030 && NILP (w
->region_showing
)
12031 && NILP (Vshow_trailing_whitespace
)
12032 && !cursor_in_echo_area
)
12035 struct glyph_row
*row
;
12037 /* Skip from tlbufpos to PT and see where it is. Note that
12038 PT may be in invisible text. If so, we will end at the
12039 next visible position. */
12040 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12041 NULL
, DEFAULT_FACE_ID
);
12042 it
.current_x
= this_line_start_x
;
12043 it
.current_y
= this_line_y
;
12044 it
.vpos
= this_line_vpos
;
12046 /* The call to move_it_to stops in front of PT, but
12047 moves over before-strings. */
12048 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12050 if (it
.vpos
== this_line_vpos
12051 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12054 xassert (this_line_vpos
== it
.vpos
);
12055 xassert (this_line_y
== it
.current_y
);
12056 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12058 *w
->desired_matrix
->method
= 0;
12059 debug_method_add (w
, "optimization 3");
12068 /* Text changed drastically or point moved off of line. */
12069 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12072 CHARPOS (this_line_start_pos
) = 0;
12073 consider_all_windows_p
|= buffer_shared
> 1;
12074 ++clear_face_cache_count
;
12075 #ifdef HAVE_WINDOW_SYSTEM
12076 ++clear_image_cache_count
;
12079 /* Build desired matrices, and update the display. If
12080 consider_all_windows_p is non-zero, do it for all windows on all
12081 frames. Otherwise do it for selected_window, only. */
12083 if (consider_all_windows_p
)
12085 Lisp_Object tail
, frame
;
12087 FOR_EACH_FRAME (tail
, frame
)
12088 XFRAME (frame
)->updated_p
= 0;
12090 /* Recompute # windows showing selected buffer. This will be
12091 incremented each time such a window is displayed. */
12094 FOR_EACH_FRAME (tail
, frame
)
12096 struct frame
*f
= XFRAME (frame
);
12098 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12100 if (! EQ (frame
, selected_frame
))
12101 /* Select the frame, for the sake of frame-local
12103 select_frame_for_redisplay (frame
);
12105 /* Mark all the scroll bars to be removed; we'll redeem
12106 the ones we want when we redisplay their windows. */
12107 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12108 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12110 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12111 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12113 /* The X error handler may have deleted that frame. */
12114 if (!FRAME_LIVE_P (f
))
12117 /* Any scroll bars which redisplay_windows should have
12118 nuked should now go away. */
12119 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12120 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12122 /* If fonts changed, display again. */
12123 /* ??? rms: I suspect it is a mistake to jump all the way
12124 back to retry here. It should just retry this frame. */
12125 if (fonts_changed_p
)
12128 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12130 /* See if we have to hscroll. */
12131 if (!f
->already_hscrolled_p
)
12133 f
->already_hscrolled_p
= 1;
12134 if (hscroll_windows (f
->root_window
))
12138 /* Prevent various kinds of signals during display
12139 update. stdio is not robust about handling
12140 signals, which can cause an apparent I/O
12142 if (interrupt_input
)
12143 unrequest_sigio ();
12146 /* Update the display. */
12147 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12148 pause
|= update_frame (f
, 0, 0);
12154 if (!EQ (old_frame
, selected_frame
)
12155 && FRAME_LIVE_P (XFRAME (old_frame
)))
12156 /* We played a bit fast-and-loose above and allowed selected_frame
12157 and selected_window to be temporarily out-of-sync but let's make
12158 sure this stays contained. */
12159 select_frame_for_redisplay (old_frame
);
12160 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12164 /* Do the mark_window_display_accurate after all windows have
12165 been redisplayed because this call resets flags in buffers
12166 which are needed for proper redisplay. */
12167 FOR_EACH_FRAME (tail
, frame
)
12169 struct frame
*f
= XFRAME (frame
);
12172 mark_window_display_accurate (f
->root_window
, 1);
12173 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12174 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12179 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12181 Lisp_Object mini_window
;
12182 struct frame
*mini_frame
;
12184 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12185 /* Use list_of_error, not Qerror, so that
12186 we catch only errors and don't run the debugger. */
12187 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12189 redisplay_window_error
);
12191 /* Compare desired and current matrices, perform output. */
12194 /* If fonts changed, display again. */
12195 if (fonts_changed_p
)
12198 /* Prevent various kinds of signals during display update.
12199 stdio is not robust about handling signals,
12200 which can cause an apparent I/O error. */
12201 if (interrupt_input
)
12202 unrequest_sigio ();
12205 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12207 if (hscroll_windows (selected_window
))
12210 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12211 pause
= update_frame (sf
, 0, 0);
12214 /* We may have called echo_area_display at the top of this
12215 function. If the echo area is on another frame, that may
12216 have put text on a frame other than the selected one, so the
12217 above call to update_frame would not have caught it. Catch
12219 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12220 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12222 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12224 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12225 pause
|= update_frame (mini_frame
, 0, 0);
12226 if (!pause
&& hscroll_windows (mini_window
))
12231 /* If display was paused because of pending input, make sure we do a
12232 thorough update the next time. */
12235 /* Prevent the optimization at the beginning of
12236 redisplay_internal that tries a single-line update of the
12237 line containing the cursor in the selected window. */
12238 CHARPOS (this_line_start_pos
) = 0;
12240 /* Let the overlay arrow be updated the next time. */
12241 update_overlay_arrows (0);
12243 /* If we pause after scrolling, some rows in the current
12244 matrices of some windows are not valid. */
12245 if (!WINDOW_FULL_WIDTH_P (w
)
12246 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12247 update_mode_lines
= 1;
12251 if (!consider_all_windows_p
)
12253 /* This has already been done above if
12254 consider_all_windows_p is set. */
12255 mark_window_display_accurate_1 (w
, 1);
12257 /* Say overlay arrows are up to date. */
12258 update_overlay_arrows (1);
12260 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12261 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12264 update_mode_lines
= 0;
12265 windows_or_buffers_changed
= 0;
12266 cursor_type_changed
= 0;
12269 /* Start SIGIO interrupts coming again. Having them off during the
12270 code above makes it less likely one will discard output, but not
12271 impossible, since there might be stuff in the system buffer here.
12272 But it is much hairier to try to do anything about that. */
12273 if (interrupt_input
)
12277 /* If a frame has become visible which was not before, redisplay
12278 again, so that we display it. Expose events for such a frame
12279 (which it gets when becoming visible) don't call the parts of
12280 redisplay constructing glyphs, so simply exposing a frame won't
12281 display anything in this case. So, we have to display these
12282 frames here explicitly. */
12285 Lisp_Object tail
, frame
;
12288 FOR_EACH_FRAME (tail
, frame
)
12290 int this_is_visible
= 0;
12292 if (XFRAME (frame
)->visible
)
12293 this_is_visible
= 1;
12294 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12295 if (XFRAME (frame
)->visible
)
12296 this_is_visible
= 1;
12298 if (this_is_visible
)
12302 if (new_count
!= number_of_visible_frames
)
12303 windows_or_buffers_changed
++;
12306 /* Change frame size now if a change is pending. */
12307 do_pending_window_change (1);
12309 /* If we just did a pending size change, or have additional
12310 visible frames, redisplay again. */
12311 if (windows_or_buffers_changed
&& !pause
)
12314 /* Clear the face and image caches.
12316 We used to do this only if consider_all_windows_p. But the cache
12317 needs to be cleared if a timer creates images in the current
12318 buffer (e.g. the test case in Bug#6230). */
12320 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12322 clear_face_cache (0);
12323 clear_face_cache_count
= 0;
12326 #ifdef HAVE_WINDOW_SYSTEM
12327 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12329 clear_image_caches (Qnil
);
12330 clear_image_cache_count
= 0;
12332 #endif /* HAVE_WINDOW_SYSTEM */
12335 unbind_to (count
, Qnil
);
12340 /* Redisplay, but leave alone any recent echo area message unless
12341 another message has been requested in its place.
12343 This is useful in situations where you need to redisplay but no
12344 user action has occurred, making it inappropriate for the message
12345 area to be cleared. See tracking_off and
12346 wait_reading_process_output for examples of these situations.
12348 FROM_WHERE is an integer saying from where this function was
12349 called. This is useful for debugging. */
12352 redisplay_preserve_echo_area (int from_where
)
12354 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12356 if (!NILP (echo_area_buffer
[1]))
12358 /* We have a previously displayed message, but no current
12359 message. Redisplay the previous message. */
12360 display_last_displayed_message_p
= 1;
12361 redisplay_internal (1);
12362 display_last_displayed_message_p
= 0;
12365 redisplay_internal (1);
12367 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12368 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12369 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12373 /* Function registered with record_unwind_protect in
12374 redisplay_internal. Reset redisplaying_p to the value it had
12375 before redisplay_internal was called, and clear
12376 prevent_freeing_realized_faces_p. It also selects the previously
12377 selected frame, unless it has been deleted (by an X connection
12378 failure during redisplay, for example). */
12381 unwind_redisplay (Lisp_Object val
)
12383 Lisp_Object old_redisplaying_p
, old_frame
;
12385 old_redisplaying_p
= XCAR (val
);
12386 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12387 old_frame
= XCDR (val
);
12388 if (! EQ (old_frame
, selected_frame
)
12389 && FRAME_LIVE_P (XFRAME (old_frame
)))
12390 select_frame_for_redisplay (old_frame
);
12395 /* Mark the display of window W as accurate or inaccurate. If
12396 ACCURATE_P is non-zero mark display of W as accurate. If
12397 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12398 redisplay_internal is called. */
12401 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12403 if (BUFFERP (w
->buffer
))
12405 struct buffer
*b
= XBUFFER (w
->buffer
);
12408 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12409 w
->last_overlay_modified
12410 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12412 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12416 b
->clip_changed
= 0;
12417 b
->prevent_redisplay_optimizations_p
= 0;
12419 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12420 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12421 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12422 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12424 w
->current_matrix
->buffer
= b
;
12425 w
->current_matrix
->begv
= BUF_BEGV (b
);
12426 w
->current_matrix
->zv
= BUF_ZV (b
);
12428 w
->last_cursor
= w
->cursor
;
12429 w
->last_cursor_off_p
= w
->cursor_off_p
;
12431 if (w
== XWINDOW (selected_window
))
12432 w
->last_point
= make_number (BUF_PT (b
));
12434 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12440 w
->window_end_valid
= w
->buffer
;
12441 w
->update_mode_line
= Qnil
;
12446 /* Mark the display of windows in the window tree rooted at WINDOW as
12447 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12448 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12449 be redisplayed the next time redisplay_internal is called. */
12452 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12456 for (; !NILP (window
); window
= w
->next
)
12458 w
= XWINDOW (window
);
12459 mark_window_display_accurate_1 (w
, accurate_p
);
12461 if (!NILP (w
->vchild
))
12462 mark_window_display_accurate (w
->vchild
, accurate_p
);
12463 if (!NILP (w
->hchild
))
12464 mark_window_display_accurate (w
->hchild
, accurate_p
);
12469 update_overlay_arrows (1);
12473 /* Force a thorough redisplay the next time by setting
12474 last_arrow_position and last_arrow_string to t, which is
12475 unequal to any useful value of Voverlay_arrow_... */
12476 update_overlay_arrows (-1);
12481 /* Return value in display table DP (Lisp_Char_Table *) for character
12482 C. Since a display table doesn't have any parent, we don't have to
12483 follow parent. Do not call this function directly but use the
12484 macro DISP_CHAR_VECTOR. */
12487 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12491 if (ASCII_CHAR_P (c
))
12494 if (SUB_CHAR_TABLE_P (val
))
12495 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12501 XSETCHAR_TABLE (table
, dp
);
12502 val
= char_table_ref (table
, c
);
12511 /***********************************************************************
12513 ***********************************************************************/
12515 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12518 redisplay_windows (Lisp_Object window
)
12520 while (!NILP (window
))
12522 struct window
*w
= XWINDOW (window
);
12524 if (!NILP (w
->hchild
))
12525 redisplay_windows (w
->hchild
);
12526 else if (!NILP (w
->vchild
))
12527 redisplay_windows (w
->vchild
);
12528 else if (!NILP (w
->buffer
))
12530 displayed_buffer
= XBUFFER (w
->buffer
);
12531 /* Use list_of_error, not Qerror, so that
12532 we catch only errors and don't run the debugger. */
12533 internal_condition_case_1 (redisplay_window_0
, window
,
12535 redisplay_window_error
);
12543 redisplay_window_error (Lisp_Object ignore
)
12545 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12550 redisplay_window_0 (Lisp_Object window
)
12552 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12553 redisplay_window (window
, 0);
12558 redisplay_window_1 (Lisp_Object window
)
12560 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12561 redisplay_window (window
, 1);
12566 /* Increment GLYPH until it reaches END or CONDITION fails while
12567 adding (GLYPH)->pixel_width to X. */
12569 #define SKIP_GLYPHS(glyph, end, x, condition) \
12572 (x) += (glyph)->pixel_width; \
12575 while ((glyph) < (end) && (condition))
12578 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12579 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12580 which positions recorded in ROW differ from current buffer
12583 Return 0 if cursor is not on this row, 1 otherwise. */
12586 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
12587 struct glyph_matrix
*matrix
,
12588 EMACS_INT delta
, EMACS_INT delta_bytes
,
12591 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12592 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12593 struct glyph
*cursor
= NULL
;
12594 /* The last known character position in row. */
12595 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12597 EMACS_INT pt_old
= PT
- delta
;
12598 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12599 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12600 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12601 /* A glyph beyond the edge of TEXT_AREA which we should never
12603 struct glyph
*glyphs_end
= end
;
12604 /* Non-zero means we've found a match for cursor position, but that
12605 glyph has the avoid_cursor_p flag set. */
12606 int match_with_avoid_cursor
= 0;
12607 /* Non-zero means we've seen at least one glyph that came from a
12609 int string_seen
= 0;
12610 /* Largest and smalles buffer positions seen so far during scan of
12612 EMACS_INT bpos_max
= pos_before
;
12613 EMACS_INT bpos_min
= pos_after
;
12614 /* Last buffer position covered by an overlay string with an integer
12615 `cursor' property. */
12616 EMACS_INT bpos_covered
= 0;
12618 /* Skip over glyphs not having an object at the start and the end of
12619 the row. These are special glyphs like truncation marks on
12620 terminal frames. */
12621 if (row
->displays_text_p
)
12623 if (!row
->reversed_p
)
12626 && INTEGERP (glyph
->object
)
12627 && glyph
->charpos
< 0)
12629 x
+= glyph
->pixel_width
;
12633 && INTEGERP ((end
- 1)->object
)
12634 /* CHARPOS is zero for blanks and stretch glyphs
12635 inserted by extend_face_to_end_of_line. */
12636 && (end
- 1)->charpos
<= 0)
12638 glyph_before
= glyph
- 1;
12645 /* If the glyph row is reversed, we need to process it from back
12646 to front, so swap the edge pointers. */
12647 glyphs_end
= end
= glyph
- 1;
12648 glyph
+= row
->used
[TEXT_AREA
] - 1;
12650 while (glyph
> end
+ 1
12651 && INTEGERP (glyph
->object
)
12652 && glyph
->charpos
< 0)
12655 x
-= glyph
->pixel_width
;
12657 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12659 /* By default, in reversed rows we put the cursor on the
12660 rightmost (first in the reading order) glyph. */
12661 for (g
= end
+ 1; g
< glyph
; g
++)
12662 x
+= g
->pixel_width
;
12664 && INTEGERP ((end
+ 1)->object
)
12665 && (end
+ 1)->charpos
<= 0)
12667 glyph_before
= glyph
+ 1;
12671 else if (row
->reversed_p
)
12673 /* In R2L rows that don't display text, put the cursor on the
12674 rightmost glyph. Case in point: an empty last line that is
12675 part of an R2L paragraph. */
12677 /* Avoid placing the cursor on the last glyph of the row, where
12678 on terminal frames we hold the vertical border between
12679 adjacent windows. */
12680 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
12681 && !WINDOW_RIGHTMOST_P (w
)
12682 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
12684 x
= -1; /* will be computed below, at label compute_x */
12687 /* Step 1: Try to find the glyph whose character position
12688 corresponds to point. If that's not possible, find 2 glyphs
12689 whose character positions are the closest to point, one before
12690 point, the other after it. */
12691 if (!row
->reversed_p
)
12692 while (/* not marched to end of glyph row */
12694 /* glyph was not inserted by redisplay for internal purposes */
12695 && !INTEGERP (glyph
->object
))
12697 if (BUFFERP (glyph
->object
))
12699 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12701 if (glyph
->charpos
> bpos_max
)
12702 bpos_max
= glyph
->charpos
;
12703 if (glyph
->charpos
< bpos_min
)
12704 bpos_min
= glyph
->charpos
;
12705 if (!glyph
->avoid_cursor_p
)
12707 /* If we hit point, we've found the glyph on which to
12708 display the cursor. */
12711 match_with_avoid_cursor
= 0;
12714 /* See if we've found a better approximation to
12715 POS_BEFORE or to POS_AFTER. Note that we want the
12716 first (leftmost) glyph of all those that are the
12717 closest from below, and the last (rightmost) of all
12718 those from above. */
12719 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12721 pos_before
= glyph
->charpos
;
12722 glyph_before
= glyph
;
12724 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12726 pos_after
= glyph
->charpos
;
12727 glyph_after
= glyph
;
12730 else if (dpos
== 0)
12731 match_with_avoid_cursor
= 1;
12733 else if (STRINGP (glyph
->object
))
12735 Lisp_Object chprop
;
12736 EMACS_INT glyph_pos
= glyph
->charpos
;
12738 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12740 if (INTEGERP (chprop
))
12742 bpos_covered
= bpos_max
+ XINT (chprop
);
12743 /* If the `cursor' property covers buffer positions up
12744 to and including point, we should display cursor on
12745 this glyph. Note that overlays and text properties
12746 with string values stop bidi reordering, so every
12747 buffer position to the left of the string is always
12748 smaller than any position to the right of the
12749 string. Therefore, if a `cursor' property on one
12750 of the string's characters has an integer value, we
12751 will break out of the loop below _before_ we get to
12752 the position match above. IOW, integer values of
12753 the `cursor' property override the "exact match for
12754 point" strategy of positioning the cursor. */
12755 /* Implementation note: bpos_max == pt_old when, e.g.,
12756 we are in an empty line, where bpos_max is set to
12757 MATRIX_ROW_START_CHARPOS, see above. */
12758 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12767 x
+= glyph
->pixel_width
;
12770 else if (glyph
> end
) /* row is reversed */
12771 while (!INTEGERP (glyph
->object
))
12773 if (BUFFERP (glyph
->object
))
12775 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12777 if (glyph
->charpos
> bpos_max
)
12778 bpos_max
= glyph
->charpos
;
12779 if (glyph
->charpos
< bpos_min
)
12780 bpos_min
= glyph
->charpos
;
12781 if (!glyph
->avoid_cursor_p
)
12785 match_with_avoid_cursor
= 0;
12788 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12790 pos_before
= glyph
->charpos
;
12791 glyph_before
= glyph
;
12793 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12795 pos_after
= glyph
->charpos
;
12796 glyph_after
= glyph
;
12799 else if (dpos
== 0)
12800 match_with_avoid_cursor
= 1;
12802 else if (STRINGP (glyph
->object
))
12804 Lisp_Object chprop
;
12805 EMACS_INT glyph_pos
= glyph
->charpos
;
12807 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12809 if (INTEGERP (chprop
))
12811 bpos_covered
= bpos_max
+ XINT (chprop
);
12812 /* If the `cursor' property covers buffer positions up
12813 to and including point, we should display cursor on
12815 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12824 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
12826 x
--; /* can't use any pixel_width */
12829 x
-= glyph
->pixel_width
;
12832 /* Step 2: If we didn't find an exact match for point, we need to
12833 look for a proper place to put the cursor among glyphs between
12834 GLYPH_BEFORE and GLYPH_AFTER. */
12835 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12836 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12837 && bpos_covered
< pt_old
)
12839 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12841 EMACS_INT ellipsis_pos
;
12843 /* Scan back over the ellipsis glyphs. */
12844 if (!row
->reversed_p
)
12846 ellipsis_pos
= (glyph
- 1)->charpos
;
12847 while (glyph
> row
->glyphs
[TEXT_AREA
]
12848 && (glyph
- 1)->charpos
== ellipsis_pos
)
12849 glyph
--, x
-= glyph
->pixel_width
;
12850 /* That loop always goes one position too far, including
12851 the glyph before the ellipsis. So scan forward over
12853 x
+= glyph
->pixel_width
;
12856 else /* row is reversed */
12858 ellipsis_pos
= (glyph
+ 1)->charpos
;
12859 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12860 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12861 glyph
++, x
+= glyph
->pixel_width
;
12862 x
-= glyph
->pixel_width
;
12866 else if (match_with_avoid_cursor
12867 /* A truncated row may not include PT among its
12868 character positions. Setting the cursor inside the
12869 scroll margin will trigger recalculation of hscroll
12870 in hscroll_window_tree. */
12871 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
12872 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
12873 /* Zero-width characters produce no glyphs. */
12874 || ((row
->reversed_p
12875 ? glyph_after
> glyphs_end
12876 : glyph_after
< glyphs_end
)
12877 && eabs (glyph_after
- glyph_before
) == 1))
12879 cursor
= glyph_after
;
12882 else if (string_seen
)
12884 int incr
= row
->reversed_p
? -1 : +1;
12886 /* Need to find the glyph that came out of a string which is
12887 present at point. That glyph is somewhere between
12888 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12889 positioned between POS_BEFORE and POS_AFTER in the
12891 struct glyph
*stop
= glyph_after
;
12892 EMACS_INT pos
= pos_before
;
12895 for (glyph
= glyph_before
+ incr
;
12896 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12899 /* Any glyphs that come from the buffer are here because
12900 of bidi reordering. Skip them, and only pay
12901 attention to glyphs that came from some string. */
12902 if (STRINGP (glyph
->object
))
12907 str
= glyph
->object
;
12908 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12909 if (tem
== 0 /* from overlay */
12912 /* If the string from which this glyph came is
12913 found in the buffer at point, then we've
12914 found the glyph we've been looking for. If
12915 it comes from an overlay (tem == 0), and it
12916 has the `cursor' property on one of its
12917 glyphs, record that glyph as a candidate for
12918 displaying the cursor. (As in the
12919 unidirectional version, we will display the
12920 cursor on the last candidate we find.) */
12921 if (tem
== 0 || tem
== pt_old
)
12923 /* The glyphs from this string could have
12924 been reordered. Find the one with the
12925 smallest string position. Or there could
12926 be a character in the string with the
12927 `cursor' property, which means display
12928 cursor on that character's glyph. */
12929 EMACS_INT strpos
= glyph
->charpos
;
12932 for (glyph
+= incr
;
12933 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12934 && EQ (glyph
->object
, str
);
12938 EMACS_INT gpos
= glyph
->charpos
;
12940 cprop
= Fget_char_property (make_number (gpos
),
12948 if (glyph
->charpos
< strpos
)
12950 strpos
= glyph
->charpos
;
12959 pos
= tem
+ 1; /* don't find previous instances */
12961 /* This string is not what we want; skip all of the
12962 glyphs that came from it. */
12965 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12966 && EQ (glyph
->object
, str
));
12972 /* If we reached the end of the line, and END was from a string,
12973 the cursor is not on this line. */
12975 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
12976 && STRINGP (end
->object
)
12977 && row
->continued_p
)
12983 if (cursor
!= NULL
)
12989 /* Need to compute x that corresponds to GLYPH. */
12990 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12992 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12994 x
+= g
->pixel_width
;
12998 /* ROW could be part of a continued line, which, under bidi
12999 reordering, might have other rows whose start and end charpos
13000 occlude point. Only set w->cursor if we found a better
13001 approximation to the cursor position than we have from previously
13002 examined candidate rows belonging to the same continued line. */
13003 if (/* we already have a candidate row */
13004 w
->cursor
.vpos
>= 0
13005 /* that candidate is not the row we are processing */
13006 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
13007 /* the row we are processing is part of a continued line */
13008 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
13009 /* Make sure cursor.vpos specifies a row whose start and end
13010 charpos occlude point. This is because some callers of this
13011 function leave cursor.vpos at the row where the cursor was
13012 displayed during the last redisplay cycle. */
13013 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13014 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13017 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13019 /* Don't consider glyphs that are outside TEXT_AREA. */
13020 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13022 /* Keep the candidate whose buffer position is the closest to
13024 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13025 w
->cursor
.hpos
>= 0
13026 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13027 && BUFFERP (g1
->object
)
13028 && (g1
->charpos
== pt_old
/* an exact match always wins */
13029 || (BUFFERP (glyph
->object
)
13030 && eabs (g1
->charpos
- pt_old
)
13031 < eabs (glyph
->charpos
- pt_old
))))
13033 /* If this candidate gives an exact match, use that. */
13034 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13035 /* Otherwise, keep the candidate that comes from a row
13036 spanning less buffer positions. This may win when one or
13037 both candidate positions are on glyphs that came from
13038 display strings, for which we cannot compare buffer
13040 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13041 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13042 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13045 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13047 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13048 w
->cursor
.y
= row
->y
+ dy
;
13050 if (w
== XWINDOW (selected_window
))
13052 if (!row
->continued_p
13053 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13056 this_line_buffer
= XBUFFER (w
->buffer
);
13058 CHARPOS (this_line_start_pos
)
13059 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13060 BYTEPOS (this_line_start_pos
)
13061 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13063 CHARPOS (this_line_end_pos
)
13064 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13065 BYTEPOS (this_line_end_pos
)
13066 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13068 this_line_y
= w
->cursor
.y
;
13069 this_line_pixel_height
= row
->height
;
13070 this_line_vpos
= w
->cursor
.vpos
;
13071 this_line_start_x
= row
->x
;
13074 CHARPOS (this_line_start_pos
) = 0;
13081 /* Run window scroll functions, if any, for WINDOW with new window
13082 start STARTP. Sets the window start of WINDOW to that position.
13084 We assume that the window's buffer is really current. */
13086 static INLINE
struct text_pos
13087 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13089 struct window
*w
= XWINDOW (window
);
13090 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13092 if (current_buffer
!= XBUFFER (w
->buffer
))
13095 if (!NILP (Vwindow_scroll_functions
))
13097 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13098 make_number (CHARPOS (startp
)));
13099 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13100 /* In case the hook functions switch buffers. */
13101 if (current_buffer
!= XBUFFER (w
->buffer
))
13102 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13109 /* Make sure the line containing the cursor is fully visible.
13110 A value of 1 means there is nothing to be done.
13111 (Either the line is fully visible, or it cannot be made so,
13112 or we cannot tell.)
13114 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13115 is higher than window.
13117 A value of 0 means the caller should do scrolling
13118 as if point had gone off the screen. */
13121 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13123 struct glyph_matrix
*matrix
;
13124 struct glyph_row
*row
;
13127 if (!make_cursor_line_fully_visible_p
)
13130 /* It's not always possible to find the cursor, e.g, when a window
13131 is full of overlay strings. Don't do anything in that case. */
13132 if (w
->cursor
.vpos
< 0)
13135 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13136 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13138 /* If the cursor row is not partially visible, there's nothing to do. */
13139 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13142 /* If the row the cursor is in is taller than the window's height,
13143 it's not clear what to do, so do nothing. */
13144 window_height
= window_box_height (w
);
13145 if (row
->height
>= window_height
)
13147 if (!force_p
|| MINI_WINDOW_P (w
)
13148 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13155 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13156 non-zero means only WINDOW is redisplayed in redisplay_internal.
13157 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13158 in redisplay_window to bring a partially visible line into view in
13159 the case that only the cursor has moved.
13161 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13162 last screen line's vertical height extends past the end of the screen.
13166 1 if scrolling succeeded
13168 0 if scrolling didn't find point.
13170 -1 if new fonts have been loaded so that we must interrupt
13171 redisplay, adjust glyph matrices, and try again. */
13177 SCROLLING_NEED_LARGER_MATRICES
13181 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13182 EMACS_INT scroll_conservatively
, EMACS_INT scroll_step
,
13183 int temp_scroll_step
, int last_line_misfit
)
13185 struct window
*w
= XWINDOW (window
);
13186 struct frame
*f
= XFRAME (w
->frame
);
13187 struct text_pos pos
, startp
;
13189 int this_scroll_margin
, scroll_max
, rc
, height
;
13190 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13191 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13192 Lisp_Object aggressive
;
13193 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13196 debug_method_add (w
, "try_scrolling");
13199 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13201 /* Compute scroll margin height in pixels. We scroll when point is
13202 within this distance from the top or bottom of the window. */
13203 if (scroll_margin
> 0)
13204 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13205 * FRAME_LINE_HEIGHT (f
);
13207 this_scroll_margin
= 0;
13209 /* Force scroll_conservatively to have a reasonable value, to avoid
13210 overflow while computing how much to scroll. Note that the user
13211 can supply scroll-conservatively equal to `most-positive-fixnum',
13212 which can be larger than INT_MAX. */
13213 if (scroll_conservatively
> scroll_limit
)
13215 scroll_conservatively
= scroll_limit
;
13216 scroll_max
= INT_MAX
;
13218 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13219 /* Compute how much we should try to scroll maximally to bring
13220 point into view. */
13221 scroll_max
= (max (scroll_step
,
13222 max (scroll_conservatively
, temp_scroll_step
))
13223 * FRAME_LINE_HEIGHT (f
));
13224 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13225 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13226 /* We're trying to scroll because of aggressive scrolling but no
13227 scroll_step is set. Choose an arbitrary one. */
13228 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13234 /* Decide whether to scroll down. */
13235 if (PT
> CHARPOS (startp
))
13237 int scroll_margin_y
;
13239 /* Compute the pixel ypos of the scroll margin, then move it to
13240 either that ypos or PT, whichever comes first. */
13241 start_display (&it
, w
, startp
);
13242 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13243 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13244 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13245 (MOVE_TO_POS
| MOVE_TO_Y
));
13247 if (PT
> CHARPOS (it
.current
.pos
))
13249 int y0
= line_bottom_y (&it
);
13250 /* Compute how many pixels below window bottom to stop searching
13251 for PT. This avoids costly search for PT that is far away if
13252 the user limited scrolling by a small number of lines, but
13253 always finds PT if scroll_conservatively is set to a large
13254 number, such as most-positive-fixnum. */
13255 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13257 slack
>= INT_MAX
- it
.last_visible_y
13259 : it
.last_visible_y
+ slack
;
13261 /* Compute the distance from the scroll margin to PT or to
13262 the scroll limit, whichever comes first. This should
13263 include the height of the cursor line, to make that line
13265 move_it_to (&it
, PT
, -1, y_to_move
,
13266 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13267 dy
= line_bottom_y (&it
) - y0
;
13269 if (dy
> scroll_max
)
13270 return SCROLLING_FAILED
;
13278 /* Point is in or below the bottom scroll margin, so move the
13279 window start down. If scrolling conservatively, move it just
13280 enough down to make point visible. If scroll_step is set,
13281 move it down by scroll_step. */
13282 if (scroll_conservatively
)
13284 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13285 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13286 else if (scroll_step
|| temp_scroll_step
)
13287 amount_to_scroll
= scroll_max
;
13290 aggressive
= current_buffer
->scroll_up_aggressively
;
13291 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13292 if (NUMBERP (aggressive
))
13294 double float_amount
= XFLOATINT (aggressive
) * height
;
13295 amount_to_scroll
= float_amount
;
13296 if (amount_to_scroll
== 0 && float_amount
> 0)
13297 amount_to_scroll
= 1;
13301 if (amount_to_scroll
<= 0)
13302 return SCROLLING_FAILED
;
13304 start_display (&it
, w
, startp
);
13305 if (scroll_max
< INT_MAX
)
13306 move_it_vertically (&it
, amount_to_scroll
);
13309 /* Extra precision for users who set scroll-conservatively
13310 to most-positive-fixnum: make sure the amount we scroll
13311 the window start is never less than amount_to_scroll,
13312 which was computed as distance from window bottom to
13313 point. This matters when lines at window top and lines
13314 below window bottom have different height. */
13315 struct it it1
= it
;
13316 /* We use a temporary it1 because line_bottom_y can modify
13317 its argument, if it moves one line down; see there. */
13318 int start_y
= line_bottom_y (&it1
);
13321 move_it_by_lines (&it
, 1, 1);
13323 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13326 /* If STARTP is unchanged, move it down another screen line. */
13327 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13328 move_it_by_lines (&it
, 1, 1);
13329 startp
= it
.current
.pos
;
13333 struct text_pos scroll_margin_pos
= startp
;
13335 /* See if point is inside the scroll margin at the top of the
13337 if (this_scroll_margin
)
13339 start_display (&it
, w
, startp
);
13340 move_it_vertically (&it
, this_scroll_margin
);
13341 scroll_margin_pos
= it
.current
.pos
;
13344 if (PT
< CHARPOS (scroll_margin_pos
))
13346 /* Point is in the scroll margin at the top of the window or
13347 above what is displayed in the window. */
13350 /* Compute the vertical distance from PT to the scroll
13351 margin position. Give up if distance is greater than
13353 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13354 start_display (&it
, w
, pos
);
13356 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13357 it
.last_visible_y
, -1,
13358 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13359 dy
= it
.current_y
- y0
;
13360 if (dy
> scroll_max
)
13361 return SCROLLING_FAILED
;
13363 /* Compute new window start. */
13364 start_display (&it
, w
, startp
);
13366 if (scroll_conservatively
)
13368 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13369 else if (scroll_step
|| temp_scroll_step
)
13370 amount_to_scroll
= scroll_max
;
13373 aggressive
= current_buffer
->scroll_down_aggressively
;
13374 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13375 if (NUMBERP (aggressive
))
13377 double float_amount
= XFLOATINT (aggressive
) * height
;
13378 amount_to_scroll
= float_amount
;
13379 if (amount_to_scroll
== 0 && float_amount
> 0)
13380 amount_to_scroll
= 1;
13384 if (amount_to_scroll
<= 0)
13385 return SCROLLING_FAILED
;
13387 move_it_vertically_backward (&it
, amount_to_scroll
);
13388 startp
= it
.current
.pos
;
13392 /* Run window scroll functions. */
13393 startp
= run_window_scroll_functions (window
, startp
);
13395 /* Display the window. Give up if new fonts are loaded, or if point
13397 if (!try_window (window
, startp
, 0))
13398 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13399 else if (w
->cursor
.vpos
< 0)
13401 clear_glyph_matrix (w
->desired_matrix
);
13402 rc
= SCROLLING_FAILED
;
13406 /* Maybe forget recorded base line for line number display. */
13407 if (!just_this_one_p
13408 || current_buffer
->clip_changed
13409 || BEG_UNCHANGED
< CHARPOS (startp
))
13410 w
->base_line_number
= Qnil
;
13412 /* If cursor ends up on a partially visible line,
13413 treat that as being off the bottom of the screen. */
13414 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13416 clear_glyph_matrix (w
->desired_matrix
);
13417 ++extra_scroll_margin_lines
;
13420 rc
= SCROLLING_SUCCESS
;
13427 /* Compute a suitable window start for window W if display of W starts
13428 on a continuation line. Value is non-zero if a new window start
13431 The new window start will be computed, based on W's width, starting
13432 from the start of the continued line. It is the start of the
13433 screen line with the minimum distance from the old start W->start. */
13436 compute_window_start_on_continuation_line (struct window
*w
)
13438 struct text_pos pos
, start_pos
;
13439 int window_start_changed_p
= 0;
13441 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13443 /* If window start is on a continuation line... Window start may be
13444 < BEGV in case there's invisible text at the start of the
13445 buffer (M-x rmail, for example). */
13446 if (CHARPOS (start_pos
) > BEGV
13447 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13450 struct glyph_row
*row
;
13452 /* Handle the case that the window start is out of range. */
13453 if (CHARPOS (start_pos
) < BEGV
)
13454 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13455 else if (CHARPOS (start_pos
) > ZV
)
13456 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13458 /* Find the start of the continued line. This should be fast
13459 because scan_buffer is fast (newline cache). */
13460 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13461 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13462 row
, DEFAULT_FACE_ID
);
13463 reseat_at_previous_visible_line_start (&it
);
13465 /* If the line start is "too far" away from the window start,
13466 say it takes too much time to compute a new window start. */
13467 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13468 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13470 int min_distance
, distance
;
13472 /* Move forward by display lines to find the new window
13473 start. If window width was enlarged, the new start can
13474 be expected to be > the old start. If window width was
13475 decreased, the new window start will be < the old start.
13476 So, we're looking for the display line start with the
13477 minimum distance from the old window start. */
13478 pos
= it
.current
.pos
;
13479 min_distance
= INFINITY
;
13480 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13481 distance
< min_distance
)
13483 min_distance
= distance
;
13484 pos
= it
.current
.pos
;
13485 move_it_by_lines (&it
, 1, 0);
13488 /* Set the window start there. */
13489 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13490 window_start_changed_p
= 1;
13494 return window_start_changed_p
;
13498 /* Try cursor movement in case text has not changed in window WINDOW,
13499 with window start STARTP. Value is
13501 CURSOR_MOVEMENT_SUCCESS if successful
13503 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13505 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13506 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13507 we want to scroll as if scroll-step were set to 1. See the code.
13509 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13510 which case we have to abort this redisplay, and adjust matrices
13515 CURSOR_MOVEMENT_SUCCESS
,
13516 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13517 CURSOR_MOVEMENT_MUST_SCROLL
,
13518 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13522 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13524 struct window
*w
= XWINDOW (window
);
13525 struct frame
*f
= XFRAME (w
->frame
);
13526 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13529 if (inhibit_try_cursor_movement
)
13533 /* Handle case where text has not changed, only point, and it has
13534 not moved off the frame. */
13535 if (/* Point may be in this window. */
13536 PT
>= CHARPOS (startp
)
13537 /* Selective display hasn't changed. */
13538 && !current_buffer
->clip_changed
13539 /* Function force-mode-line-update is used to force a thorough
13540 redisplay. It sets either windows_or_buffers_changed or
13541 update_mode_lines. So don't take a shortcut here for these
13543 && !update_mode_lines
13544 && !windows_or_buffers_changed
13545 && !cursor_type_changed
13546 /* Can't use this case if highlighting a region. When a
13547 region exists, cursor movement has to do more than just
13549 && !(!NILP (Vtransient_mark_mode
)
13550 && !NILP (current_buffer
->mark_active
))
13551 && NILP (w
->region_showing
)
13552 && NILP (Vshow_trailing_whitespace
)
13553 /* Right after splitting windows, last_point may be nil. */
13554 && INTEGERP (w
->last_point
)
13555 /* This code is not used for mini-buffer for the sake of the case
13556 of redisplaying to replace an echo area message; since in
13557 that case the mini-buffer contents per se are usually
13558 unchanged. This code is of no real use in the mini-buffer
13559 since the handling of this_line_start_pos, etc., in redisplay
13560 handles the same cases. */
13561 && !EQ (window
, minibuf_window
)
13562 /* When splitting windows or for new windows, it happens that
13563 redisplay is called with a nil window_end_vpos or one being
13564 larger than the window. This should really be fixed in
13565 window.c. I don't have this on my list, now, so we do
13566 approximately the same as the old redisplay code. --gerd. */
13567 && INTEGERP (w
->window_end_vpos
)
13568 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13569 && (FRAME_WINDOW_P (f
)
13570 || !overlay_arrow_in_current_buffer_p ()))
13572 int this_scroll_margin
, top_scroll_margin
;
13573 struct glyph_row
*row
= NULL
;
13576 debug_method_add (w
, "cursor movement");
13579 /* Scroll if point within this distance from the top or bottom
13580 of the window. This is a pixel value. */
13581 if (scroll_margin
> 0)
13583 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13584 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13587 this_scroll_margin
= 0;
13589 top_scroll_margin
= this_scroll_margin
;
13590 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13591 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13593 /* Start with the row the cursor was displayed during the last
13594 not paused redisplay. Give up if that row is not valid. */
13595 if (w
->last_cursor
.vpos
< 0
13596 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13597 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13600 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13601 if (row
->mode_line_p
)
13603 if (!row
->enabled_p
)
13604 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13607 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13609 int scroll_p
= 0, must_scroll
= 0;
13610 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13612 if (PT
> XFASTINT (w
->last_point
))
13614 /* Point has moved forward. */
13615 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13616 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13618 xassert (row
->enabled_p
);
13622 /* If the end position of a row equals the start
13623 position of the next row, and PT is at that position,
13624 we would rather display cursor in the next line. */
13625 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13626 && MATRIX_ROW_END_CHARPOS (row
) == PT
13627 && row
< w
->current_matrix
->rows
13628 + w
->current_matrix
->nrows
- 1
13629 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
13630 && !cursor_row_p (w
, row
))
13633 /* If within the scroll margin, scroll. Note that
13634 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13635 the next line would be drawn, and that
13636 this_scroll_margin can be zero. */
13637 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13638 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13639 /* Line is completely visible last line in window
13640 and PT is to be set in the next line. */
13641 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13642 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13643 && !row
->ends_at_zv_p
13644 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13647 else if (PT
< XFASTINT (w
->last_point
))
13649 /* Cursor has to be moved backward. Note that PT >=
13650 CHARPOS (startp) because of the outer if-statement. */
13651 while (!row
->mode_line_p
13652 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13653 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13654 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13655 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13656 row
> w
->current_matrix
->rows
13657 && (row
-1)->ends_in_newline_from_string_p
))))
13658 && (row
->y
> top_scroll_margin
13659 || CHARPOS (startp
) == BEGV
))
13661 xassert (row
->enabled_p
);
13665 /* Consider the following case: Window starts at BEGV,
13666 there is invisible, intangible text at BEGV, so that
13667 display starts at some point START > BEGV. It can
13668 happen that we are called with PT somewhere between
13669 BEGV and START. Try to handle that case. */
13670 if (row
< w
->current_matrix
->rows
13671 || row
->mode_line_p
)
13673 row
= w
->current_matrix
->rows
;
13674 if (row
->mode_line_p
)
13678 /* Due to newlines in overlay strings, we may have to
13679 skip forward over overlay strings. */
13680 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13681 && MATRIX_ROW_END_CHARPOS (row
) == PT
13682 && !cursor_row_p (w
, row
))
13685 /* If within the scroll margin, scroll. */
13686 if (row
->y
< top_scroll_margin
13687 && CHARPOS (startp
) != BEGV
)
13692 /* Cursor did not move. So don't scroll even if cursor line
13693 is partially visible, as it was so before. */
13694 rc
= CURSOR_MOVEMENT_SUCCESS
;
13697 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13698 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13700 /* if PT is not in the glyph row, give up. */
13701 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13704 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13705 && !NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13707 /* If rows are bidi-reordered and point moved, back up
13708 until we find a row that does not belong to a
13709 continuation line. This is because we must consider
13710 all rows of a continued line as candidates for the
13711 new cursor positioning, since row start and end
13712 positions change non-linearly with vertical position
13714 /* FIXME: Revisit this when glyph ``spilling'' in
13715 continuation lines' rows is implemented for
13716 bidi-reordered rows. */
13717 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13719 xassert (row
->enabled_p
);
13721 /* If we hit the beginning of the displayed portion
13722 without finding the first row of a continued
13724 if (row
<= w
->current_matrix
->rows
)
13726 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13734 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13735 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13736 && make_cursor_line_fully_visible_p
)
13738 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13739 && !row
->ends_at_zv_p
13740 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13741 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13742 else if (row
->height
> window_box_height (w
))
13744 /* If we end up in a partially visible line, let's
13745 make it fully visible, except when it's taller
13746 than the window, in which case we can't do much
13749 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13753 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13754 if (!cursor_row_fully_visible_p (w
, 0, 1))
13755 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13757 rc
= CURSOR_MOVEMENT_SUCCESS
;
13761 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13762 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13763 && !NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13765 /* With bidi-reordered rows, there could be more than
13766 one candidate row whose start and end positions
13767 occlude point. We need to let set_cursor_from_row
13768 find the best candidate. */
13769 /* FIXME: Revisit this when glyph ``spilling'' in
13770 continuation lines' rows is implemented for
13771 bidi-reordered rows. */
13776 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
13777 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13778 && cursor_row_p (w
, row
))
13779 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13781 /* As soon as we've found the first suitable row
13782 whose ends_at_zv_p flag is set, we are done. */
13784 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13786 rc
= CURSOR_MOVEMENT_SUCCESS
;
13791 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
13792 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
13793 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13794 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
13795 /* If we didn't find any candidate rows, or exited the
13796 loop before all the candidates were examined, signal
13797 to the caller that this method failed. */
13798 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13799 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
13800 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13802 rc
= CURSOR_MOVEMENT_SUCCESS
;
13808 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13810 rc
= CURSOR_MOVEMENT_SUCCESS
;
13815 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13816 && MATRIX_ROW_START_CHARPOS (row
) == PT
13817 && cursor_row_p (w
, row
));
13826 set_vertical_scroll_bar (struct window
*w
)
13828 EMACS_INT start
, end
, whole
;
13830 /* Calculate the start and end positions for the current window.
13831 At some point, it would be nice to choose between scrollbars
13832 which reflect the whole buffer size, with special markers
13833 indicating narrowing, and scrollbars which reflect only the
13836 Note that mini-buffers sometimes aren't displaying any text. */
13837 if (!MINI_WINDOW_P (w
)
13838 || (w
== XWINDOW (minibuf_window
)
13839 && NILP (echo_area_buffer
[0])))
13841 struct buffer
*buf
= XBUFFER (w
->buffer
);
13842 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13843 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13844 /* I don't think this is guaranteed to be right. For the
13845 moment, we'll pretend it is. */
13846 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13850 if (whole
< (end
- start
))
13851 whole
= end
- start
;
13854 start
= end
= whole
= 0;
13856 /* Indicate what this scroll bar ought to be displaying now. */
13857 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13858 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13859 (w
, end
- start
, whole
, start
);
13863 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13864 selected_window is redisplayed.
13866 We can return without actually redisplaying the window if
13867 fonts_changed_p is nonzero. In that case, redisplay_internal will
13871 redisplay_window (Lisp_Object window
, int just_this_one_p
)
13873 struct window
*w
= XWINDOW (window
);
13874 struct frame
*f
= XFRAME (w
->frame
);
13875 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13876 struct buffer
*old
= current_buffer
;
13877 struct text_pos lpoint
, opoint
, startp
;
13878 int update_mode_line
;
13881 /* Record it now because it's overwritten. */
13882 int current_matrix_up_to_date_p
= 0;
13883 int used_current_matrix_p
= 0;
13884 /* This is less strict than current_matrix_up_to_date_p.
13885 It indictes that the buffer contents and narrowing are unchanged. */
13886 int buffer_unchanged_p
= 0;
13887 int temp_scroll_step
= 0;
13888 int count
= SPECPDL_INDEX ();
13890 int centering_position
= -1;
13891 int last_line_misfit
= 0;
13892 EMACS_INT beg_unchanged
, end_unchanged
;
13894 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13897 /* W must be a leaf window here. */
13898 xassert (!NILP (w
->buffer
));
13900 *w
->desired_matrix
->method
= 0;
13904 reconsider_clip_changes (w
, buffer
);
13906 /* Has the mode line to be updated? */
13907 update_mode_line
= (!NILP (w
->update_mode_line
)
13908 || update_mode_lines
13909 || buffer
->clip_changed
13910 || buffer
->prevent_redisplay_optimizations_p
);
13912 if (MINI_WINDOW_P (w
))
13914 if (w
== XWINDOW (echo_area_window
)
13915 && !NILP (echo_area_buffer
[0]))
13917 if (update_mode_line
)
13918 /* We may have to update a tty frame's menu bar or a
13919 tool-bar. Example `M-x C-h C-h C-g'. */
13920 goto finish_menu_bars
;
13922 /* We've already displayed the echo area glyphs in this window. */
13923 goto finish_scroll_bars
;
13925 else if ((w
!= XWINDOW (minibuf_window
)
13926 || minibuf_level
== 0)
13927 /* When buffer is nonempty, redisplay window normally. */
13928 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13929 /* Quail displays non-mini buffers in minibuffer window.
13930 In that case, redisplay the window normally. */
13931 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13933 /* W is a mini-buffer window, but it's not active, so clear
13935 int yb
= window_text_bottom_y (w
);
13936 struct glyph_row
*row
;
13939 for (y
= 0, row
= w
->desired_matrix
->rows
;
13941 y
+= row
->height
, ++row
)
13942 blank_row (w
, row
, y
);
13943 goto finish_scroll_bars
;
13946 clear_glyph_matrix (w
->desired_matrix
);
13949 /* Otherwise set up data on this window; select its buffer and point
13951 /* Really select the buffer, for the sake of buffer-local
13953 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13955 current_matrix_up_to_date_p
13956 = (!NILP (w
->window_end_valid
)
13957 && !current_buffer
->clip_changed
13958 && !current_buffer
->prevent_redisplay_optimizations_p
13959 && XFASTINT (w
->last_modified
) >= MODIFF
13960 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13962 /* Run the window-bottom-change-functions
13963 if it is possible that the text on the screen has changed
13964 (either due to modification of the text, or any other reason). */
13965 if (!current_matrix_up_to_date_p
13966 && !NILP (Vwindow_text_change_functions
))
13968 safe_run_hooks (Qwindow_text_change_functions
);
13972 beg_unchanged
= BEG_UNCHANGED
;
13973 end_unchanged
= END_UNCHANGED
;
13975 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13977 specbind (Qinhibit_point_motion_hooks
, Qt
);
13980 = (!NILP (w
->window_end_valid
)
13981 && !current_buffer
->clip_changed
13982 && XFASTINT (w
->last_modified
) >= MODIFF
13983 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13985 /* When windows_or_buffers_changed is non-zero, we can't rely on
13986 the window end being valid, so set it to nil there. */
13987 if (windows_or_buffers_changed
)
13989 /* If window starts on a continuation line, maybe adjust the
13990 window start in case the window's width changed. */
13991 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13992 compute_window_start_on_continuation_line (w
);
13994 w
->window_end_valid
= Qnil
;
13997 /* Some sanity checks. */
13998 CHECK_WINDOW_END (w
);
13999 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14001 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14004 /* If %c is in mode line, update it if needed. */
14005 if (!NILP (w
->column_number_displayed
)
14006 /* This alternative quickly identifies a common case
14007 where no change is needed. */
14008 && !(PT
== XFASTINT (w
->last_point
)
14009 && XFASTINT (w
->last_modified
) >= MODIFF
14010 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14011 && (XFASTINT (w
->column_number_displayed
)
14012 != (int) current_column ())) /* iftc */
14013 update_mode_line
= 1;
14015 /* Count number of windows showing the selected buffer. An indirect
14016 buffer counts as its base buffer. */
14017 if (!just_this_one_p
)
14019 struct buffer
*current_base
, *window_base
;
14020 current_base
= current_buffer
;
14021 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14022 if (current_base
->base_buffer
)
14023 current_base
= current_base
->base_buffer
;
14024 if (window_base
->base_buffer
)
14025 window_base
= window_base
->base_buffer
;
14026 if (current_base
== window_base
)
14030 /* Point refers normally to the selected window. For any other
14031 window, set up appropriate value. */
14032 if (!EQ (window
, selected_window
))
14034 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14035 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14039 new_pt_byte
= BEGV_BYTE
;
14040 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14042 else if (new_pt
> (ZV
- 1))
14045 new_pt_byte
= ZV_BYTE
;
14046 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14049 /* We don't use SET_PT so that the point-motion hooks don't run. */
14050 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14053 /* If any of the character widths specified in the display table
14054 have changed, invalidate the width run cache. It's true that
14055 this may be a bit late to catch such changes, but the rest of
14056 redisplay goes (non-fatally) haywire when the display table is
14057 changed, so why should we worry about doing any better? */
14058 if (current_buffer
->width_run_cache
)
14060 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14062 if (! disptab_matches_widthtab (disptab
,
14063 XVECTOR (current_buffer
->width_table
)))
14065 invalidate_region_cache (current_buffer
,
14066 current_buffer
->width_run_cache
,
14068 recompute_width_table (current_buffer
, disptab
);
14072 /* If window-start is screwed up, choose a new one. */
14073 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14076 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14078 /* If someone specified a new starting point but did not insist,
14079 check whether it can be used. */
14080 if (!NILP (w
->optional_new_start
)
14081 && CHARPOS (startp
) >= BEGV
14082 && CHARPOS (startp
) <= ZV
)
14084 w
->optional_new_start
= Qnil
;
14085 start_display (&it
, w
, startp
);
14086 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14087 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14088 if (IT_CHARPOS (it
) == PT
)
14089 w
->force_start
= Qt
;
14090 /* IT may overshoot PT if text at PT is invisible. */
14091 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14092 w
->force_start
= Qt
;
14097 /* Handle case where place to start displaying has been specified,
14098 unless the specified location is outside the accessible range. */
14099 if (!NILP (w
->force_start
)
14100 || w
->frozen_window_start_p
)
14102 /* We set this later on if we have to adjust point. */
14105 w
->force_start
= Qnil
;
14107 w
->window_end_valid
= Qnil
;
14109 /* Forget any recorded base line for line number display. */
14110 if (!buffer_unchanged_p
)
14111 w
->base_line_number
= Qnil
;
14113 /* Redisplay the mode line. Select the buffer properly for that.
14114 Also, run the hook window-scroll-functions
14115 because we have scrolled. */
14116 /* Note, we do this after clearing force_start because
14117 if there's an error, it is better to forget about force_start
14118 than to get into an infinite loop calling the hook functions
14119 and having them get more errors. */
14120 if (!update_mode_line
14121 || ! NILP (Vwindow_scroll_functions
))
14123 update_mode_line
= 1;
14124 w
->update_mode_line
= Qt
;
14125 startp
= run_window_scroll_functions (window
, startp
);
14128 w
->last_modified
= make_number (0);
14129 w
->last_overlay_modified
= make_number (0);
14130 if (CHARPOS (startp
) < BEGV
)
14131 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14132 else if (CHARPOS (startp
) > ZV
)
14133 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14135 /* Redisplay, then check if cursor has been set during the
14136 redisplay. Give up if new fonts were loaded. */
14137 /* We used to issue a CHECK_MARGINS argument to try_window here,
14138 but this causes scrolling to fail when point begins inside
14139 the scroll margin (bug#148) -- cyd */
14140 if (!try_window (window
, startp
, 0))
14142 w
->force_start
= Qt
;
14143 clear_glyph_matrix (w
->desired_matrix
);
14144 goto need_larger_matrices
;
14147 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14149 /* If point does not appear, try to move point so it does
14150 appear. The desired matrix has been built above, so we
14151 can use it here. */
14152 new_vpos
= window_box_height (w
) / 2;
14155 if (!cursor_row_fully_visible_p (w
, 0, 0))
14157 /* Point does appear, but on a line partly visible at end of window.
14158 Move it back to a fully-visible line. */
14159 new_vpos
= window_box_height (w
);
14162 /* If we need to move point for either of the above reasons,
14163 now actually do it. */
14166 struct glyph_row
*row
;
14168 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14169 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14172 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14173 MATRIX_ROW_START_BYTEPOS (row
));
14175 if (w
!= XWINDOW (selected_window
))
14176 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14177 else if (current_buffer
== old
)
14178 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14180 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14182 /* If we are highlighting the region, then we just changed
14183 the region, so redisplay to show it. */
14184 if (!NILP (Vtransient_mark_mode
)
14185 && !NILP (current_buffer
->mark_active
))
14187 clear_glyph_matrix (w
->desired_matrix
);
14188 if (!try_window (window
, startp
, 0))
14189 goto need_larger_matrices
;
14194 debug_method_add (w
, "forced window start");
14199 /* Handle case where text has not changed, only point, and it has
14200 not moved off the frame, and we are not retrying after hscroll.
14201 (current_matrix_up_to_date_p is nonzero when retrying.) */
14202 if (current_matrix_up_to_date_p
14203 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14204 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14208 case CURSOR_MOVEMENT_SUCCESS
:
14209 used_current_matrix_p
= 1;
14212 case CURSOR_MOVEMENT_MUST_SCROLL
:
14213 goto try_to_scroll
;
14219 /* If current starting point was originally the beginning of a line
14220 but no longer is, find a new starting point. */
14221 else if (!NILP (w
->start_at_line_beg
)
14222 && !(CHARPOS (startp
) <= BEGV
14223 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14226 debug_method_add (w
, "recenter 1");
14231 /* Try scrolling with try_window_id. Value is > 0 if update has
14232 been done, it is -1 if we know that the same window start will
14233 not work. It is 0 if unsuccessful for some other reason. */
14234 else if ((tem
= try_window_id (w
)) != 0)
14237 debug_method_add (w
, "try_window_id %d", tem
);
14240 if (fonts_changed_p
)
14241 goto need_larger_matrices
;
14245 /* Otherwise try_window_id has returned -1 which means that we
14246 don't want the alternative below this comment to execute. */
14248 else if (CHARPOS (startp
) >= BEGV
14249 && CHARPOS (startp
) <= ZV
14250 && PT
>= CHARPOS (startp
)
14251 && (CHARPOS (startp
) < ZV
14252 /* Avoid starting at end of buffer. */
14253 || CHARPOS (startp
) == BEGV
14254 || (XFASTINT (w
->last_modified
) >= MODIFF
14255 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14258 /* If first window line is a continuation line, and window start
14259 is inside the modified region, but the first change is before
14260 current window start, we must select a new window start.
14262 However, if this is the result of a down-mouse event (e.g. by
14263 extending the mouse-drag-overlay), we don't want to select a
14264 new window start, since that would change the position under
14265 the mouse, resulting in an unwanted mouse-movement rather
14266 than a simple mouse-click. */
14267 if (NILP (w
->start_at_line_beg
)
14268 && NILP (do_mouse_tracking
)
14269 && CHARPOS (startp
) > BEGV
14270 && CHARPOS (startp
) > BEG
+ beg_unchanged
14271 && CHARPOS (startp
) <= Z
- end_unchanged
14272 /* Even if w->start_at_line_beg is nil, a new window may
14273 start at a line_beg, since that's how set_buffer_window
14274 sets it. So, we need to check the return value of
14275 compute_window_start_on_continuation_line. (See also
14277 && XMARKER (w
->start
)->buffer
== current_buffer
14278 && compute_window_start_on_continuation_line (w
))
14280 w
->force_start
= Qt
;
14281 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14286 debug_method_add (w
, "same window start");
14289 /* Try to redisplay starting at same place as before.
14290 If point has not moved off frame, accept the results. */
14291 if (!current_matrix_up_to_date_p
14292 /* Don't use try_window_reusing_current_matrix in this case
14293 because a window scroll function can have changed the
14295 || !NILP (Vwindow_scroll_functions
)
14296 || MINI_WINDOW_P (w
)
14297 || !(used_current_matrix_p
14298 = try_window_reusing_current_matrix (w
)))
14300 IF_DEBUG (debug_method_add (w
, "1"));
14301 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14302 /* -1 means we need to scroll.
14303 0 means we need new matrices, but fonts_changed_p
14304 is set in that case, so we will detect it below. */
14305 goto try_to_scroll
;
14308 if (fonts_changed_p
)
14309 goto need_larger_matrices
;
14311 if (w
->cursor
.vpos
>= 0)
14313 if (!just_this_one_p
14314 || current_buffer
->clip_changed
14315 || BEG_UNCHANGED
< CHARPOS (startp
))
14316 /* Forget any recorded base line for line number display. */
14317 w
->base_line_number
= Qnil
;
14319 if (!cursor_row_fully_visible_p (w
, 1, 0))
14321 clear_glyph_matrix (w
->desired_matrix
);
14322 last_line_misfit
= 1;
14324 /* Drop through and scroll. */
14329 clear_glyph_matrix (w
->desired_matrix
);
14334 w
->last_modified
= make_number (0);
14335 w
->last_overlay_modified
= make_number (0);
14337 /* Redisplay the mode line. Select the buffer properly for that. */
14338 if (!update_mode_line
)
14340 update_mode_line
= 1;
14341 w
->update_mode_line
= Qt
;
14344 /* Try to scroll by specified few lines. */
14345 if ((scroll_conservatively
14347 || temp_scroll_step
14348 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14349 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14350 && !current_buffer
->clip_changed
14351 && CHARPOS (startp
) >= BEGV
14352 && CHARPOS (startp
) <= ZV
)
14354 /* The function returns -1 if new fonts were loaded, 1 if
14355 successful, 0 if not successful. */
14356 int rc
= try_scrolling (window
, just_this_one_p
,
14357 scroll_conservatively
,
14359 temp_scroll_step
, last_line_misfit
);
14362 case SCROLLING_SUCCESS
:
14365 case SCROLLING_NEED_LARGER_MATRICES
:
14366 goto need_larger_matrices
;
14368 case SCROLLING_FAILED
:
14376 /* Finally, just choose place to start which centers point */
14379 if (centering_position
< 0)
14380 centering_position
= window_box_height (w
) / 2;
14383 debug_method_add (w
, "recenter");
14386 /* w->vscroll = 0; */
14388 /* Forget any previously recorded base line for line number display. */
14389 if (!buffer_unchanged_p
)
14390 w
->base_line_number
= Qnil
;
14392 /* Move backward half the height of the window. */
14393 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14394 it
.current_y
= it
.last_visible_y
;
14395 move_it_vertically_backward (&it
, centering_position
);
14396 xassert (IT_CHARPOS (it
) >= BEGV
);
14398 /* The function move_it_vertically_backward may move over more
14399 than the specified y-distance. If it->w is small, e.g. a
14400 mini-buffer window, we may end up in front of the window's
14401 display area. Start displaying at the start of the line
14402 containing PT in this case. */
14403 if (it
.current_y
<= 0)
14405 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14406 move_it_vertically_backward (&it
, 0);
14410 it
.current_x
= it
.hpos
= 0;
14412 /* Set startp here explicitly in case that helps avoid an infinite loop
14413 in case the window-scroll-functions functions get errors. */
14414 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14416 /* Run scroll hooks. */
14417 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14419 /* Redisplay the window. */
14420 if (!current_matrix_up_to_date_p
14421 || windows_or_buffers_changed
14422 || cursor_type_changed
14423 /* Don't use try_window_reusing_current_matrix in this case
14424 because it can have changed the buffer. */
14425 || !NILP (Vwindow_scroll_functions
)
14426 || !just_this_one_p
14427 || MINI_WINDOW_P (w
)
14428 || !(used_current_matrix_p
14429 = try_window_reusing_current_matrix (w
)))
14430 try_window (window
, startp
, 0);
14432 /* If new fonts have been loaded (due to fontsets), give up. We
14433 have to start a new redisplay since we need to re-adjust glyph
14435 if (fonts_changed_p
)
14436 goto need_larger_matrices
;
14438 /* If cursor did not appear assume that the middle of the window is
14439 in the first line of the window. Do it again with the next line.
14440 (Imagine a window of height 100, displaying two lines of height
14441 60. Moving back 50 from it->last_visible_y will end in the first
14443 if (w
->cursor
.vpos
< 0)
14445 if (!NILP (w
->window_end_valid
)
14446 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14448 clear_glyph_matrix (w
->desired_matrix
);
14449 move_it_by_lines (&it
, 1, 0);
14450 try_window (window
, it
.current
.pos
, 0);
14452 else if (PT
< IT_CHARPOS (it
))
14454 clear_glyph_matrix (w
->desired_matrix
);
14455 move_it_by_lines (&it
, -1, 0);
14456 try_window (window
, it
.current
.pos
, 0);
14460 /* Not much we can do about it. */
14464 /* Consider the following case: Window starts at BEGV, there is
14465 invisible, intangible text at BEGV, so that display starts at
14466 some point START > BEGV. It can happen that we are called with
14467 PT somewhere between BEGV and START. Try to handle that case. */
14468 if (w
->cursor
.vpos
< 0)
14470 struct glyph_row
*row
= w
->current_matrix
->rows
;
14471 if (row
->mode_line_p
)
14473 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14476 if (!cursor_row_fully_visible_p (w
, 0, 0))
14478 /* If vscroll is enabled, disable it and try again. */
14482 clear_glyph_matrix (w
->desired_matrix
);
14486 /* If centering point failed to make the whole line visible,
14487 put point at the top instead. That has to make the whole line
14488 visible, if it can be done. */
14489 if (centering_position
== 0)
14492 clear_glyph_matrix (w
->desired_matrix
);
14493 centering_position
= 0;
14499 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14500 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14501 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14504 /* Display the mode line, if we must. */
14505 if ((update_mode_line
14506 /* If window not full width, must redo its mode line
14507 if (a) the window to its side is being redone and
14508 (b) we do a frame-based redisplay. This is a consequence
14509 of how inverted lines are drawn in frame-based redisplay. */
14510 || (!just_this_one_p
14511 && !FRAME_WINDOW_P (f
)
14512 && !WINDOW_FULL_WIDTH_P (w
))
14513 /* Line number to display. */
14514 || INTEGERP (w
->base_line_pos
)
14515 /* Column number is displayed and different from the one displayed. */
14516 || (!NILP (w
->column_number_displayed
)
14517 && (XFASTINT (w
->column_number_displayed
)
14518 != (int) current_column ()))) /* iftc */
14519 /* This means that the window has a mode line. */
14520 && (WINDOW_WANTS_MODELINE_P (w
)
14521 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14523 display_mode_lines (w
);
14525 /* If mode line height has changed, arrange for a thorough
14526 immediate redisplay using the correct mode line height. */
14527 if (WINDOW_WANTS_MODELINE_P (w
)
14528 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14530 fonts_changed_p
= 1;
14531 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14532 = DESIRED_MODE_LINE_HEIGHT (w
);
14535 /* If header line height has changed, arrange for a thorough
14536 immediate redisplay using the correct header line height. */
14537 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14538 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14540 fonts_changed_p
= 1;
14541 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14542 = DESIRED_HEADER_LINE_HEIGHT (w
);
14545 if (fonts_changed_p
)
14546 goto need_larger_matrices
;
14549 if (!line_number_displayed
14550 && !BUFFERP (w
->base_line_pos
))
14552 w
->base_line_pos
= Qnil
;
14553 w
->base_line_number
= Qnil
;
14558 /* When we reach a frame's selected window, redo the frame's menu bar. */
14559 if (update_mode_line
14560 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14562 int redisplay_menu_p
= 0;
14563 int redisplay_tool_bar_p
= 0;
14565 if (FRAME_WINDOW_P (f
))
14567 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14568 || defined (HAVE_NS) || defined (USE_GTK)
14569 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14571 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14575 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14577 if (redisplay_menu_p
)
14578 display_menu_bar (w
);
14580 #ifdef HAVE_WINDOW_SYSTEM
14581 if (FRAME_WINDOW_P (f
))
14583 #if defined (USE_GTK) || defined (HAVE_NS)
14584 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14586 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14587 && (FRAME_TOOL_BAR_LINES (f
) > 0
14588 || !NILP (Vauto_resize_tool_bars
));
14591 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14593 ignore_mouse_drag_p
= 1;
14599 #ifdef HAVE_WINDOW_SYSTEM
14600 if (FRAME_WINDOW_P (f
)
14601 && update_window_fringes (w
, (just_this_one_p
14602 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14603 || w
->pseudo_window_p
)))
14607 if (draw_window_fringes (w
, 1))
14608 x_draw_vertical_border (w
);
14612 #endif /* HAVE_WINDOW_SYSTEM */
14614 /* We go to this label, with fonts_changed_p nonzero,
14615 if it is necessary to try again using larger glyph matrices.
14616 We have to redeem the scroll bar even in this case,
14617 because the loop in redisplay_internal expects that. */
14618 need_larger_matrices
:
14620 finish_scroll_bars
:
14622 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14624 /* Set the thumb's position and size. */
14625 set_vertical_scroll_bar (w
);
14627 /* Note that we actually used the scroll bar attached to this
14628 window, so it shouldn't be deleted at the end of redisplay. */
14629 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14630 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14633 /* Restore current_buffer and value of point in it. The window
14634 update may have changed the buffer, so first make sure `opoint'
14635 is still valid (Bug#6177). */
14636 if (CHARPOS (opoint
) < BEGV
)
14637 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14638 else if (CHARPOS (opoint
) > ZV
)
14639 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
14641 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14643 set_buffer_internal_1 (old
);
14644 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14645 shorter. This can be caused by log truncation in *Messages*. */
14646 if (CHARPOS (lpoint
) <= ZV
)
14647 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14649 unbind_to (count
, Qnil
);
14653 /* Build the complete desired matrix of WINDOW with a window start
14654 buffer position POS.
14656 Value is 1 if successful. It is zero if fonts were loaded during
14657 redisplay which makes re-adjusting glyph matrices necessary, and -1
14658 if point would appear in the scroll margins.
14659 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
14660 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
14664 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
14666 struct window
*w
= XWINDOW (window
);
14668 struct glyph_row
*last_text_row
= NULL
;
14669 struct frame
*f
= XFRAME (w
->frame
);
14671 /* Make POS the new window start. */
14672 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14674 /* Mark cursor position as unknown. No overlay arrow seen. */
14675 w
->cursor
.vpos
= -1;
14676 overlay_arrow_seen
= 0;
14678 /* Initialize iterator and info to start at POS. */
14679 start_display (&it
, w
, pos
);
14681 /* Display all lines of W. */
14682 while (it
.current_y
< it
.last_visible_y
)
14684 if (display_line (&it
))
14685 last_text_row
= it
.glyph_row
- 1;
14686 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
14690 /* Don't let the cursor end in the scroll margins. */
14691 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
14692 && !MINI_WINDOW_P (w
))
14694 int this_scroll_margin
;
14696 if (scroll_margin
> 0)
14698 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14699 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14702 this_scroll_margin
= 0;
14704 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14705 && w
->cursor
.y
< this_scroll_margin
14706 && CHARPOS (pos
) > BEGV
14707 && IT_CHARPOS (it
) < ZV
)
14708 /* rms: considering make_cursor_line_fully_visible_p here
14709 seems to give wrong results. We don't want to recenter
14710 when the last line is partly visible, we want to allow
14711 that case to be handled in the usual way. */
14712 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14714 w
->cursor
.vpos
= -1;
14715 clear_glyph_matrix (w
->desired_matrix
);
14720 /* If bottom moved off end of frame, change mode line percentage. */
14721 if (XFASTINT (w
->window_end_pos
) <= 0
14722 && Z
!= IT_CHARPOS (it
))
14723 w
->update_mode_line
= Qt
;
14725 /* Set window_end_pos to the offset of the last character displayed
14726 on the window from the end of current_buffer. Set
14727 window_end_vpos to its row number. */
14730 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14731 w
->window_end_bytepos
14732 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14734 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14736 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14737 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14738 ->displays_text_p
);
14742 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14743 w
->window_end_pos
= make_number (Z
- ZV
);
14744 w
->window_end_vpos
= make_number (0);
14747 /* But that is not valid info until redisplay finishes. */
14748 w
->window_end_valid
= Qnil
;
14754 /************************************************************************
14755 Window redisplay reusing current matrix when buffer has not changed
14756 ************************************************************************/
14758 /* Try redisplay of window W showing an unchanged buffer with a
14759 different window start than the last time it was displayed by
14760 reusing its current matrix. Value is non-zero if successful.
14761 W->start is the new window start. */
14764 try_window_reusing_current_matrix (struct window
*w
)
14766 struct frame
*f
= XFRAME (w
->frame
);
14767 struct glyph_row
*row
, *bottom_row
;
14770 struct text_pos start
, new_start
;
14771 int nrows_scrolled
, i
;
14772 struct glyph_row
*last_text_row
;
14773 struct glyph_row
*last_reused_text_row
;
14774 struct glyph_row
*start_row
;
14775 int start_vpos
, min_y
, max_y
;
14778 if (inhibit_try_window_reusing
)
14782 if (/* This function doesn't handle terminal frames. */
14783 !FRAME_WINDOW_P (f
)
14784 /* Don't try to reuse the display if windows have been split
14786 || windows_or_buffers_changed
14787 || cursor_type_changed
)
14790 /* Can't do this if region may have changed. */
14791 if ((!NILP (Vtransient_mark_mode
)
14792 && !NILP (current_buffer
->mark_active
))
14793 || !NILP (w
->region_showing
)
14794 || !NILP (Vshow_trailing_whitespace
))
14797 /* If top-line visibility has changed, give up. */
14798 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14799 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14802 /* Give up if old or new display is scrolled vertically. We could
14803 make this function handle this, but right now it doesn't. */
14804 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14805 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14808 /* The variable new_start now holds the new window start. The old
14809 start `start' can be determined from the current matrix. */
14810 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14811 start
= start_row
->minpos
;
14812 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14814 /* Clear the desired matrix for the display below. */
14815 clear_glyph_matrix (w
->desired_matrix
);
14817 if (CHARPOS (new_start
) <= CHARPOS (start
))
14821 /* Don't use this method if the display starts with an ellipsis
14822 displayed for invisible text. It's not easy to handle that case
14823 below, and it's certainly not worth the effort since this is
14824 not a frequent case. */
14825 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14828 IF_DEBUG (debug_method_add (w
, "twu1"));
14830 /* Display up to a row that can be reused. The variable
14831 last_text_row is set to the last row displayed that displays
14832 text. Note that it.vpos == 0 if or if not there is a
14833 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14834 start_display (&it
, w
, new_start
);
14835 first_row_y
= it
.current_y
;
14836 w
->cursor
.vpos
= -1;
14837 last_text_row
= last_reused_text_row
= NULL
;
14839 while (it
.current_y
< it
.last_visible_y
14840 && !fonts_changed_p
)
14842 /* If we have reached into the characters in the START row,
14843 that means the line boundaries have changed. So we
14844 can't start copying with the row START. Maybe it will
14845 work to start copying with the following row. */
14846 while (IT_CHARPOS (it
) > CHARPOS (start
))
14848 /* Advance to the next row as the "start". */
14850 start
= start_row
->minpos
;
14851 /* If there are no more rows to try, or just one, give up. */
14852 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14853 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14854 || CHARPOS (start
) == ZV
)
14856 clear_glyph_matrix (w
->desired_matrix
);
14860 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14862 /* If we have reached alignment,
14863 we can copy the rest of the rows. */
14864 if (IT_CHARPOS (it
) == CHARPOS (start
))
14867 if (display_line (&it
))
14868 last_text_row
= it
.glyph_row
- 1;
14871 /* A value of current_y < last_visible_y means that we stopped
14872 at the previous window start, which in turn means that we
14873 have at least one reusable row. */
14874 if (it
.current_y
< it
.last_visible_y
)
14876 /* IT.vpos always starts from 0; it counts text lines. */
14877 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14879 /* Find PT if not already found in the lines displayed. */
14880 if (w
->cursor
.vpos
< 0)
14882 int dy
= it
.current_y
- start_row
->y
;
14884 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14885 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14887 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14888 dy
, nrows_scrolled
);
14891 clear_glyph_matrix (w
->desired_matrix
);
14896 /* Scroll the display. Do it before the current matrix is
14897 changed. The problem here is that update has not yet
14898 run, i.e. part of the current matrix is not up to date.
14899 scroll_run_hook will clear the cursor, and use the
14900 current matrix to get the height of the row the cursor is
14902 run
.current_y
= start_row
->y
;
14903 run
.desired_y
= it
.current_y
;
14904 run
.height
= it
.last_visible_y
- it
.current_y
;
14906 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14909 FRAME_RIF (f
)->update_window_begin_hook (w
);
14910 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14911 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14912 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14916 /* Shift current matrix down by nrows_scrolled lines. */
14917 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14918 rotate_matrix (w
->current_matrix
,
14920 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14923 /* Disable lines that must be updated. */
14924 for (i
= 0; i
< nrows_scrolled
; ++i
)
14925 (start_row
+ i
)->enabled_p
= 0;
14927 /* Re-compute Y positions. */
14928 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14929 max_y
= it
.last_visible_y
;
14930 for (row
= start_row
+ nrows_scrolled
;
14934 row
->y
= it
.current_y
;
14935 row
->visible_height
= row
->height
;
14937 if (row
->y
< min_y
)
14938 row
->visible_height
-= min_y
- row
->y
;
14939 if (row
->y
+ row
->height
> max_y
)
14940 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14941 row
->redraw_fringe_bitmaps_p
= 1;
14943 it
.current_y
+= row
->height
;
14945 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14946 last_reused_text_row
= row
;
14947 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14951 /* Disable lines in the current matrix which are now
14952 below the window. */
14953 for (++row
; row
< bottom_row
; ++row
)
14954 row
->enabled_p
= row
->mode_line_p
= 0;
14957 /* Update window_end_pos etc.; last_reused_text_row is the last
14958 reused row from the current matrix containing text, if any.
14959 The value of last_text_row is the last displayed line
14960 containing text. */
14961 if (last_reused_text_row
)
14963 w
->window_end_bytepos
14964 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14966 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14968 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14969 w
->current_matrix
));
14971 else if (last_text_row
)
14973 w
->window_end_bytepos
14974 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14976 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14978 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14982 /* This window must be completely empty. */
14983 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14984 w
->window_end_pos
= make_number (Z
- ZV
);
14985 w
->window_end_vpos
= make_number (0);
14987 w
->window_end_valid
= Qnil
;
14989 /* Update hint: don't try scrolling again in update_window. */
14990 w
->desired_matrix
->no_scrolling_p
= 1;
14993 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14997 else if (CHARPOS (new_start
) > CHARPOS (start
))
14999 struct glyph_row
*pt_row
, *row
;
15000 struct glyph_row
*first_reusable_row
;
15001 struct glyph_row
*first_row_to_display
;
15003 int yb
= window_text_bottom_y (w
);
15005 /* Find the row starting at new_start, if there is one. Don't
15006 reuse a partially visible line at the end. */
15007 first_reusable_row
= start_row
;
15008 while (first_reusable_row
->enabled_p
15009 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15010 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15011 < CHARPOS (new_start
)))
15012 ++first_reusable_row
;
15014 /* Give up if there is no row to reuse. */
15015 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15016 || !first_reusable_row
->enabled_p
15017 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15018 != CHARPOS (new_start
)))
15021 /* We can reuse fully visible rows beginning with
15022 first_reusable_row to the end of the window. Set
15023 first_row_to_display to the first row that cannot be reused.
15024 Set pt_row to the row containing point, if there is any. */
15026 for (first_row_to_display
= first_reusable_row
;
15027 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15028 ++first_row_to_display
)
15030 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15031 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15032 pt_row
= first_row_to_display
;
15035 /* Start displaying at the start of first_row_to_display. */
15036 xassert (first_row_to_display
->y
< yb
);
15037 init_to_row_start (&it
, w
, first_row_to_display
);
15039 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15041 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15043 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15044 + WINDOW_HEADER_LINE_HEIGHT (w
));
15046 /* Display lines beginning with first_row_to_display in the
15047 desired matrix. Set last_text_row to the last row displayed
15048 that displays text. */
15049 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15050 if (pt_row
== NULL
)
15051 w
->cursor
.vpos
= -1;
15052 last_text_row
= NULL
;
15053 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15054 if (display_line (&it
))
15055 last_text_row
= it
.glyph_row
- 1;
15057 /* If point is in a reused row, adjust y and vpos of the cursor
15061 w
->cursor
.vpos
-= nrows_scrolled
;
15062 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15065 /* Give up if point isn't in a row displayed or reused. (This
15066 also handles the case where w->cursor.vpos < nrows_scrolled
15067 after the calls to display_line, which can happen with scroll
15068 margins. See bug#1295.) */
15069 if (w
->cursor
.vpos
< 0)
15071 clear_glyph_matrix (w
->desired_matrix
);
15075 /* Scroll the display. */
15076 run
.current_y
= first_reusable_row
->y
;
15077 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15078 run
.height
= it
.last_visible_y
- run
.current_y
;
15079 dy
= run
.current_y
- run
.desired_y
;
15084 FRAME_RIF (f
)->update_window_begin_hook (w
);
15085 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15086 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15087 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15091 /* Adjust Y positions of reused rows. */
15092 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15093 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15094 max_y
= it
.last_visible_y
;
15095 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15098 row
->visible_height
= row
->height
;
15099 if (row
->y
< min_y
)
15100 row
->visible_height
-= min_y
- row
->y
;
15101 if (row
->y
+ row
->height
> max_y
)
15102 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15103 row
->redraw_fringe_bitmaps_p
= 1;
15106 /* Scroll the current matrix. */
15107 xassert (nrows_scrolled
> 0);
15108 rotate_matrix (w
->current_matrix
,
15110 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15113 /* Disable rows not reused. */
15114 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15115 row
->enabled_p
= 0;
15117 /* Point may have moved to a different line, so we cannot assume that
15118 the previous cursor position is valid; locate the correct row. */
15121 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15122 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15126 w
->cursor
.y
= row
->y
;
15128 if (row
< bottom_row
)
15130 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15131 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15133 /* Can't use this optimization with bidi-reordered glyph
15134 rows, unless cursor is already at point. */
15135 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
15137 if (!(w
->cursor
.hpos
>= 0
15138 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15139 && BUFFERP (glyph
->object
)
15140 && glyph
->charpos
== PT
))
15145 && (!BUFFERP (glyph
->object
)
15146 || glyph
->charpos
< PT
);
15150 w
->cursor
.x
+= glyph
->pixel_width
;
15155 /* Adjust window end. A null value of last_text_row means that
15156 the window end is in reused rows which in turn means that
15157 only its vpos can have changed. */
15160 w
->window_end_bytepos
15161 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15163 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15165 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15170 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15173 w
->window_end_valid
= Qnil
;
15174 w
->desired_matrix
->no_scrolling_p
= 1;
15177 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15187 /************************************************************************
15188 Window redisplay reusing current matrix when buffer has changed
15189 ************************************************************************/
15191 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15192 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15193 EMACS_INT
*, EMACS_INT
*);
15194 static struct glyph_row
*
15195 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15196 struct glyph_row
*);
15199 /* Return the last row in MATRIX displaying text. If row START is
15200 non-null, start searching with that row. IT gives the dimensions
15201 of the display. Value is null if matrix is empty; otherwise it is
15202 a pointer to the row found. */
15204 static struct glyph_row
*
15205 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15206 struct glyph_row
*start
)
15208 struct glyph_row
*row
, *row_found
;
15210 /* Set row_found to the last row in IT->w's current matrix
15211 displaying text. The loop looks funny but think of partially
15214 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15215 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15217 xassert (row
->enabled_p
);
15219 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15228 /* Return the last row in the current matrix of W that is not affected
15229 by changes at the start of current_buffer that occurred since W's
15230 current matrix was built. Value is null if no such row exists.
15232 BEG_UNCHANGED us the number of characters unchanged at the start of
15233 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15234 first changed character in current_buffer. Characters at positions <
15235 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15236 when the current matrix was built. */
15238 static struct glyph_row
*
15239 find_last_unchanged_at_beg_row (struct window
*w
)
15241 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15242 struct glyph_row
*row
;
15243 struct glyph_row
*row_found
= NULL
;
15244 int yb
= window_text_bottom_y (w
);
15246 /* Find the last row displaying unchanged text. */
15247 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15248 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15249 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15252 if (/* If row ends before first_changed_pos, it is unchanged,
15253 except in some case. */
15254 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15255 /* When row ends in ZV and we write at ZV it is not
15257 && !row
->ends_at_zv_p
15258 /* When first_changed_pos is the end of a continued line,
15259 row is not unchanged because it may be no longer
15261 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15262 && (row
->continued_p
15263 || row
->exact_window_width_line_p
)))
15266 /* Stop if last visible row. */
15267 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15275 /* Find the first glyph row in the current matrix of W that is not
15276 affected by changes at the end of current_buffer since the
15277 time W's current matrix was built.
15279 Return in *DELTA the number of chars by which buffer positions in
15280 unchanged text at the end of current_buffer must be adjusted.
15282 Return in *DELTA_BYTES the corresponding number of bytes.
15284 Value is null if no such row exists, i.e. all rows are affected by
15287 static struct glyph_row
*
15288 find_first_unchanged_at_end_row (struct window
*w
,
15289 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15291 struct glyph_row
*row
;
15292 struct glyph_row
*row_found
= NULL
;
15294 *delta
= *delta_bytes
= 0;
15296 /* Display must not have been paused, otherwise the current matrix
15297 is not up to date. */
15298 eassert (!NILP (w
->window_end_valid
));
15300 /* A value of window_end_pos >= END_UNCHANGED means that the window
15301 end is in the range of changed text. If so, there is no
15302 unchanged row at the end of W's current matrix. */
15303 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15306 /* Set row to the last row in W's current matrix displaying text. */
15307 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15309 /* If matrix is entirely empty, no unchanged row exists. */
15310 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15312 /* The value of row is the last glyph row in the matrix having a
15313 meaningful buffer position in it. The end position of row
15314 corresponds to window_end_pos. This allows us to translate
15315 buffer positions in the current matrix to current buffer
15316 positions for characters not in changed text. */
15318 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15319 EMACS_INT Z_BYTE_old
=
15320 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15321 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15322 struct glyph_row
*first_text_row
15323 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15325 *delta
= Z
- Z_old
;
15326 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15328 /* Set last_unchanged_pos to the buffer position of the last
15329 character in the buffer that has not been changed. Z is the
15330 index + 1 of the last character in current_buffer, i.e. by
15331 subtracting END_UNCHANGED we get the index of the last
15332 unchanged character, and we have to add BEG to get its buffer
15334 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15335 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15337 /* Search backward from ROW for a row displaying a line that
15338 starts at a minimum position >= last_unchanged_pos_old. */
15339 for (; row
> first_text_row
; --row
)
15341 /* This used to abort, but it can happen.
15342 It is ok to just stop the search instead here. KFS. */
15343 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15346 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15351 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15357 /* Make sure that glyph rows in the current matrix of window W
15358 reference the same glyph memory as corresponding rows in the
15359 frame's frame matrix. This function is called after scrolling W's
15360 current matrix on a terminal frame in try_window_id and
15361 try_window_reusing_current_matrix. */
15364 sync_frame_with_window_matrix_rows (struct window
*w
)
15366 struct frame
*f
= XFRAME (w
->frame
);
15367 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15369 /* Preconditions: W must be a leaf window and full-width. Its frame
15370 must have a frame matrix. */
15371 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15372 xassert (WINDOW_FULL_WIDTH_P (w
));
15373 xassert (!FRAME_WINDOW_P (f
));
15375 /* If W is a full-width window, glyph pointers in W's current matrix
15376 have, by definition, to be the same as glyph pointers in the
15377 corresponding frame matrix. Note that frame matrices have no
15378 marginal areas (see build_frame_matrix). */
15379 window_row
= w
->current_matrix
->rows
;
15380 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15381 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15382 while (window_row
< window_row_end
)
15384 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15385 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15387 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15388 frame_row
->glyphs
[TEXT_AREA
] = start
;
15389 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15390 frame_row
->glyphs
[LAST_AREA
] = end
;
15392 /* Disable frame rows whose corresponding window rows have
15393 been disabled in try_window_id. */
15394 if (!window_row
->enabled_p
)
15395 frame_row
->enabled_p
= 0;
15397 ++window_row
, ++frame_row
;
15402 /* Find the glyph row in window W containing CHARPOS. Consider all
15403 rows between START and END (not inclusive). END null means search
15404 all rows to the end of the display area of W. Value is the row
15405 containing CHARPOS or null. */
15408 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15409 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15411 struct glyph_row
*row
= start
;
15412 struct glyph_row
*best_row
= NULL
;
15413 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15416 /* If we happen to start on a header-line, skip that. */
15417 if (row
->mode_line_p
)
15420 if ((end
&& row
>= end
) || !row
->enabled_p
)
15423 last_y
= window_text_bottom_y (w
) - dy
;
15427 /* Give up if we have gone too far. */
15428 if (end
&& row
>= end
)
15430 /* This formerly returned if they were equal.
15431 I think that both quantities are of a "last plus one" type;
15432 if so, when they are equal, the row is within the screen. -- rms. */
15433 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15436 /* If it is in this row, return this row. */
15437 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15438 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15439 /* The end position of a row equals the start
15440 position of the next row. If CHARPOS is there, we
15441 would rather display it in the next line, except
15442 when this line ends in ZV. */
15443 && !row
->ends_at_zv_p
15444 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15445 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15449 if (NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15450 || (!best_row
&& !row
->continued_p
))
15452 /* In bidi-reordered rows, there could be several rows
15453 occluding point, all of them belonging to the same
15454 continued line. We need to find the row which fits
15455 CHARPOS the best. */
15456 for (g
= row
->glyphs
[TEXT_AREA
];
15457 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15460 if (!STRINGP (g
->object
))
15462 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15464 mindif
= eabs (g
->charpos
- charpos
);
15466 /* Exact match always wins. */
15473 else if (best_row
&& !row
->continued_p
)
15480 /* Try to redisplay window W by reusing its existing display. W's
15481 current matrix must be up to date when this function is called,
15482 i.e. window_end_valid must not be nil.
15486 1 if display has been updated
15487 0 if otherwise unsuccessful
15488 -1 if redisplay with same window start is known not to succeed
15490 The following steps are performed:
15492 1. Find the last row in the current matrix of W that is not
15493 affected by changes at the start of current_buffer. If no such row
15496 2. Find the first row in W's current matrix that is not affected by
15497 changes at the end of current_buffer. Maybe there is no such row.
15499 3. Display lines beginning with the row + 1 found in step 1 to the
15500 row found in step 2 or, if step 2 didn't find a row, to the end of
15503 4. If cursor is not known to appear on the window, give up.
15505 5. If display stopped at the row found in step 2, scroll the
15506 display and current matrix as needed.
15508 6. Maybe display some lines at the end of W, if we must. This can
15509 happen under various circumstances, like a partially visible line
15510 becoming fully visible, or because newly displayed lines are displayed
15511 in smaller font sizes.
15513 7. Update W's window end information. */
15516 try_window_id (struct window
*w
)
15518 struct frame
*f
= XFRAME (w
->frame
);
15519 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15520 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15521 struct glyph_row
*last_unchanged_at_beg_row
;
15522 struct glyph_row
*first_unchanged_at_end_row
;
15523 struct glyph_row
*row
;
15524 struct glyph_row
*bottom_row
;
15527 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
15529 struct text_pos start_pos
;
15531 int first_unchanged_at_end_vpos
= 0;
15532 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15533 struct text_pos start
;
15534 EMACS_INT first_changed_charpos
, last_changed_charpos
;
15537 if (inhibit_try_window_id
)
15541 /* This is handy for debugging. */
15543 #define GIVE_UP(X) \
15545 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15549 #define GIVE_UP(X) return 0
15552 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15554 /* Don't use this for mini-windows because these can show
15555 messages and mini-buffers, and we don't handle that here. */
15556 if (MINI_WINDOW_P (w
))
15559 /* This flag is used to prevent redisplay optimizations. */
15560 if (windows_or_buffers_changed
|| cursor_type_changed
)
15563 /* Verify that narrowing has not changed.
15564 Also verify that we were not told to prevent redisplay optimizations.
15565 It would be nice to further
15566 reduce the number of cases where this prevents try_window_id. */
15567 if (current_buffer
->clip_changed
15568 || current_buffer
->prevent_redisplay_optimizations_p
)
15571 /* Window must either use window-based redisplay or be full width. */
15572 if (!FRAME_WINDOW_P (f
)
15573 && (!FRAME_LINE_INS_DEL_OK (f
)
15574 || !WINDOW_FULL_WIDTH_P (w
)))
15577 /* Give up if point is known NOT to appear in W. */
15578 if (PT
< CHARPOS (start
))
15581 /* Another way to prevent redisplay optimizations. */
15582 if (XFASTINT (w
->last_modified
) == 0)
15585 /* Verify that window is not hscrolled. */
15586 if (XFASTINT (w
->hscroll
) != 0)
15589 /* Verify that display wasn't paused. */
15590 if (NILP (w
->window_end_valid
))
15593 /* Can't use this if highlighting a region because a cursor movement
15594 will do more than just set the cursor. */
15595 if (!NILP (Vtransient_mark_mode
)
15596 && !NILP (current_buffer
->mark_active
))
15599 /* Likewise if highlighting trailing whitespace. */
15600 if (!NILP (Vshow_trailing_whitespace
))
15603 /* Likewise if showing a region. */
15604 if (!NILP (w
->region_showing
))
15607 /* Can't use this if overlay arrow position and/or string have
15609 if (overlay_arrows_changed_p ())
15612 /* When word-wrap is on, adding a space to the first word of a
15613 wrapped line can change the wrap position, altering the line
15614 above it. It might be worthwhile to handle this more
15615 intelligently, but for now just redisplay from scratch. */
15616 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15619 /* Under bidi reordering, adding or deleting a character in the
15620 beginning of a paragraph, before the first strong directional
15621 character, can change the base direction of the paragraph (unless
15622 the buffer specifies a fixed paragraph direction), which will
15623 require to redisplay the whole paragraph. It might be worthwhile
15624 to find the paragraph limits and widen the range of redisplayed
15625 lines to that, but for now just give up this optimization and
15626 redisplay from scratch. */
15627 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15628 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15631 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15632 only if buffer has really changed. The reason is that the gap is
15633 initially at Z for freshly visited files. The code below would
15634 set end_unchanged to 0 in that case. */
15635 if (MODIFF
> SAVE_MODIFF
15636 /* This seems to happen sometimes after saving a buffer. */
15637 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15639 if (GPT
- BEG
< BEG_UNCHANGED
)
15640 BEG_UNCHANGED
= GPT
- BEG
;
15641 if (Z
- GPT
< END_UNCHANGED
)
15642 END_UNCHANGED
= Z
- GPT
;
15645 /* The position of the first and last character that has been changed. */
15646 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15647 last_changed_charpos
= Z
- END_UNCHANGED
;
15649 /* If window starts after a line end, and the last change is in
15650 front of that newline, then changes don't affect the display.
15651 This case happens with stealth-fontification. Note that although
15652 the display is unchanged, glyph positions in the matrix have to
15653 be adjusted, of course. */
15654 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15655 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15656 && ((last_changed_charpos
< CHARPOS (start
)
15657 && CHARPOS (start
) == BEGV
)
15658 || (last_changed_charpos
< CHARPOS (start
) - 1
15659 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15661 EMACS_INT Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15662 struct glyph_row
*r0
;
15664 /* Compute how many chars/bytes have been added to or removed
15665 from the buffer. */
15666 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15667 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15669 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15671 /* Give up if PT is not in the window. Note that it already has
15672 been checked at the start of try_window_id that PT is not in
15673 front of the window start. */
15674 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15677 /* If window start is unchanged, we can reuse the whole matrix
15678 as is, after adjusting glyph positions. No need to compute
15679 the window end again, since its offset from Z hasn't changed. */
15680 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15681 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15682 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15683 /* PT must not be in a partially visible line. */
15684 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15685 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15687 /* Adjust positions in the glyph matrix. */
15688 if (delta
|| delta_bytes
)
15690 struct glyph_row
*r1
15691 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15692 increment_matrix_positions (w
->current_matrix
,
15693 MATRIX_ROW_VPOS (r0
, current_matrix
),
15694 MATRIX_ROW_VPOS (r1
, current_matrix
),
15695 delta
, delta_bytes
);
15698 /* Set the cursor. */
15699 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15701 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15708 /* Handle the case that changes are all below what is displayed in
15709 the window, and that PT is in the window. This shortcut cannot
15710 be taken if ZV is visible in the window, and text has been added
15711 there that is visible in the window. */
15712 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15713 /* ZV is not visible in the window, or there are no
15714 changes at ZV, actually. */
15715 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15716 || first_changed_charpos
== last_changed_charpos
))
15718 struct glyph_row
*r0
;
15720 /* Give up if PT is not in the window. Note that it already has
15721 been checked at the start of try_window_id that PT is not in
15722 front of the window start. */
15723 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15726 /* If window start is unchanged, we can reuse the whole matrix
15727 as is, without changing glyph positions since no text has
15728 been added/removed in front of the window end. */
15729 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15730 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
15731 /* PT must not be in a partially visible line. */
15732 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15733 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15735 /* We have to compute the window end anew since text
15736 could have been added/removed after it. */
15738 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15739 w
->window_end_bytepos
15740 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15742 /* Set the cursor. */
15743 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15745 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15752 /* Give up if window start is in the changed area.
15754 The condition used to read
15756 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15758 but why that was tested escapes me at the moment. */
15759 if (CHARPOS (start
) >= first_changed_charpos
15760 && CHARPOS (start
) <= last_changed_charpos
)
15763 /* Check that window start agrees with the start of the first glyph
15764 row in its current matrix. Check this after we know the window
15765 start is not in changed text, otherwise positions would not be
15767 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15768 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
15771 /* Give up if the window ends in strings. Overlay strings
15772 at the end are difficult to handle, so don't try. */
15773 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15774 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15777 /* Compute the position at which we have to start displaying new
15778 lines. Some of the lines at the top of the window might be
15779 reusable because they are not displaying changed text. Find the
15780 last row in W's current matrix not affected by changes at the
15781 start of current_buffer. Value is null if changes start in the
15782 first line of window. */
15783 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15784 if (last_unchanged_at_beg_row
)
15786 /* Avoid starting to display in the moddle of a character, a TAB
15787 for instance. This is easier than to set up the iterator
15788 exactly, and it's not a frequent case, so the additional
15789 effort wouldn't really pay off. */
15790 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15791 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15792 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15793 --last_unchanged_at_beg_row
;
15795 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15798 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15800 start_pos
= it
.current
.pos
;
15802 /* Start displaying new lines in the desired matrix at the same
15803 vpos we would use in the current matrix, i.e. below
15804 last_unchanged_at_beg_row. */
15805 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15807 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15808 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15810 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15814 /* There are no reusable lines at the start of the window.
15815 Start displaying in the first text line. */
15816 start_display (&it
, w
, start
);
15817 it
.vpos
= it
.first_vpos
;
15818 start_pos
= it
.current
.pos
;
15821 /* Find the first row that is not affected by changes at the end of
15822 the buffer. Value will be null if there is no unchanged row, in
15823 which case we must redisplay to the end of the window. delta
15824 will be set to the value by which buffer positions beginning with
15825 first_unchanged_at_end_row have to be adjusted due to text
15827 first_unchanged_at_end_row
15828 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15829 IF_DEBUG (debug_delta
= delta
);
15830 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15832 /* Set stop_pos to the buffer position up to which we will have to
15833 display new lines. If first_unchanged_at_end_row != NULL, this
15834 is the buffer position of the start of the line displayed in that
15835 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15836 that we don't stop at a buffer position. */
15838 if (first_unchanged_at_end_row
)
15840 xassert (last_unchanged_at_beg_row
== NULL
15841 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15843 /* If this is a continuation line, move forward to the next one
15844 that isn't. Changes in lines above affect this line.
15845 Caution: this may move first_unchanged_at_end_row to a row
15846 not displaying text. */
15847 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15848 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15849 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15850 < it
.last_visible_y
))
15851 ++first_unchanged_at_end_row
;
15853 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15854 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15855 >= it
.last_visible_y
))
15856 first_unchanged_at_end_row
= NULL
;
15859 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15861 first_unchanged_at_end_vpos
15862 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15863 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15866 else if (last_unchanged_at_beg_row
== NULL
)
15872 /* Either there is no unchanged row at the end, or the one we have
15873 now displays text. This is a necessary condition for the window
15874 end pos calculation at the end of this function. */
15875 xassert (first_unchanged_at_end_row
== NULL
15876 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15878 debug_last_unchanged_at_beg_vpos
15879 = (last_unchanged_at_beg_row
15880 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15882 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15884 #endif /* GLYPH_DEBUG != 0 */
15887 /* Display new lines. Set last_text_row to the last new line
15888 displayed which has text on it, i.e. might end up as being the
15889 line where the window_end_vpos is. */
15890 w
->cursor
.vpos
= -1;
15891 last_text_row
= NULL
;
15892 overlay_arrow_seen
= 0;
15893 while (it
.current_y
< it
.last_visible_y
15894 && !fonts_changed_p
15895 && (first_unchanged_at_end_row
== NULL
15896 || IT_CHARPOS (it
) < stop_pos
))
15898 if (display_line (&it
))
15899 last_text_row
= it
.glyph_row
- 1;
15902 if (fonts_changed_p
)
15906 /* Compute differences in buffer positions, y-positions etc. for
15907 lines reused at the bottom of the window. Compute what we can
15909 if (first_unchanged_at_end_row
15910 /* No lines reused because we displayed everything up to the
15911 bottom of the window. */
15912 && it
.current_y
< it
.last_visible_y
)
15915 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15917 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15918 run
.current_y
= first_unchanged_at_end_row
->y
;
15919 run
.desired_y
= run
.current_y
+ dy
;
15920 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15924 delta
= delta_bytes
= dvpos
= dy
15925 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15926 first_unchanged_at_end_row
= NULL
;
15928 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15931 /* Find the cursor if not already found. We have to decide whether
15932 PT will appear on this window (it sometimes doesn't, but this is
15933 not a very frequent case.) This decision has to be made before
15934 the current matrix is altered. A value of cursor.vpos < 0 means
15935 that PT is either in one of the lines beginning at
15936 first_unchanged_at_end_row or below the window. Don't care for
15937 lines that might be displayed later at the window end; as
15938 mentioned, this is not a frequent case. */
15939 if (w
->cursor
.vpos
< 0)
15941 /* Cursor in unchanged rows at the top? */
15942 if (PT
< CHARPOS (start_pos
)
15943 && last_unchanged_at_beg_row
)
15945 row
= row_containing_pos (w
, PT
,
15946 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15947 last_unchanged_at_beg_row
+ 1, 0);
15949 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15952 /* Start from first_unchanged_at_end_row looking for PT. */
15953 else if (first_unchanged_at_end_row
)
15955 row
= row_containing_pos (w
, PT
- delta
,
15956 first_unchanged_at_end_row
, NULL
, 0);
15958 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15959 delta_bytes
, dy
, dvpos
);
15962 /* Give up if cursor was not found. */
15963 if (w
->cursor
.vpos
< 0)
15965 clear_glyph_matrix (w
->desired_matrix
);
15970 /* Don't let the cursor end in the scroll margins. */
15972 int this_scroll_margin
, cursor_height
;
15974 this_scroll_margin
= max (0, scroll_margin
);
15975 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15976 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15977 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15979 if ((w
->cursor
.y
< this_scroll_margin
15980 && CHARPOS (start
) > BEGV
)
15981 /* Old redisplay didn't take scroll margin into account at the bottom,
15982 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15983 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15984 ? cursor_height
+ this_scroll_margin
15985 : 1)) > it
.last_visible_y
)
15987 w
->cursor
.vpos
= -1;
15988 clear_glyph_matrix (w
->desired_matrix
);
15993 /* Scroll the display. Do it before changing the current matrix so
15994 that xterm.c doesn't get confused about where the cursor glyph is
15996 if (dy
&& run
.height
)
16000 if (FRAME_WINDOW_P (f
))
16002 FRAME_RIF (f
)->update_window_begin_hook (w
);
16003 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16004 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16005 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16009 /* Terminal frame. In this case, dvpos gives the number of
16010 lines to scroll by; dvpos < 0 means scroll up. */
16011 int first_unchanged_at_end_vpos
16012 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16013 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
16014 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16015 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16016 + window_internal_height (w
));
16018 #if defined (HAVE_GPM) || defined (MSDOS)
16019 x_clear_window_mouse_face (w
);
16021 /* Perform the operation on the screen. */
16024 /* Scroll last_unchanged_at_beg_row to the end of the
16025 window down dvpos lines. */
16026 set_terminal_window (f
, end
);
16028 /* On dumb terminals delete dvpos lines at the end
16029 before inserting dvpos empty lines. */
16030 if (!FRAME_SCROLL_REGION_OK (f
))
16031 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16033 /* Insert dvpos empty lines in front of
16034 last_unchanged_at_beg_row. */
16035 ins_del_lines (f
, from
, dvpos
);
16037 else if (dvpos
< 0)
16039 /* Scroll up last_unchanged_at_beg_vpos to the end of
16040 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16041 set_terminal_window (f
, end
);
16043 /* Delete dvpos lines in front of
16044 last_unchanged_at_beg_vpos. ins_del_lines will set
16045 the cursor to the given vpos and emit |dvpos| delete
16047 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16049 /* On a dumb terminal insert dvpos empty lines at the
16051 if (!FRAME_SCROLL_REGION_OK (f
))
16052 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16055 set_terminal_window (f
, 0);
16061 /* Shift reused rows of the current matrix to the right position.
16062 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16064 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16065 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16068 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16069 bottom_vpos
, dvpos
);
16070 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16073 else if (dvpos
> 0)
16075 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16076 bottom_vpos
, dvpos
);
16077 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16078 first_unchanged_at_end_vpos
+ dvpos
, 0);
16081 /* For frame-based redisplay, make sure that current frame and window
16082 matrix are in sync with respect to glyph memory. */
16083 if (!FRAME_WINDOW_P (f
))
16084 sync_frame_with_window_matrix_rows (w
);
16086 /* Adjust buffer positions in reused rows. */
16087 if (delta
|| delta_bytes
)
16088 increment_matrix_positions (current_matrix
,
16089 first_unchanged_at_end_vpos
+ dvpos
,
16090 bottom_vpos
, delta
, delta_bytes
);
16092 /* Adjust Y positions. */
16094 shift_glyph_matrix (w
, current_matrix
,
16095 first_unchanged_at_end_vpos
+ dvpos
,
16098 if (first_unchanged_at_end_row
)
16100 first_unchanged_at_end_row
+= dvpos
;
16101 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16102 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16103 first_unchanged_at_end_row
= NULL
;
16106 /* If scrolling up, there may be some lines to display at the end of
16108 last_text_row_at_end
= NULL
;
16111 /* Scrolling up can leave for example a partially visible line
16112 at the end of the window to be redisplayed. */
16113 /* Set last_row to the glyph row in the current matrix where the
16114 window end line is found. It has been moved up or down in
16115 the matrix by dvpos. */
16116 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16117 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16119 /* If last_row is the window end line, it should display text. */
16120 xassert (last_row
->displays_text_p
);
16122 /* If window end line was partially visible before, begin
16123 displaying at that line. Otherwise begin displaying with the
16124 line following it. */
16125 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16127 init_to_row_start (&it
, w
, last_row
);
16128 it
.vpos
= last_vpos
;
16129 it
.current_y
= last_row
->y
;
16133 init_to_row_end (&it
, w
, last_row
);
16134 it
.vpos
= 1 + last_vpos
;
16135 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16139 /* We may start in a continuation line. If so, we have to
16140 get the right continuation_lines_width and current_x. */
16141 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16142 it
.hpos
= it
.current_x
= 0;
16144 /* Display the rest of the lines at the window end. */
16145 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16146 while (it
.current_y
< it
.last_visible_y
16147 && !fonts_changed_p
)
16149 /* Is it always sure that the display agrees with lines in
16150 the current matrix? I don't think so, so we mark rows
16151 displayed invalid in the current matrix by setting their
16152 enabled_p flag to zero. */
16153 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16154 if (display_line (&it
))
16155 last_text_row_at_end
= it
.glyph_row
- 1;
16159 /* Update window_end_pos and window_end_vpos. */
16160 if (first_unchanged_at_end_row
16161 && !last_text_row_at_end
)
16163 /* Window end line if one of the preserved rows from the current
16164 matrix. Set row to the last row displaying text in current
16165 matrix starting at first_unchanged_at_end_row, after
16167 xassert (first_unchanged_at_end_row
->displays_text_p
);
16168 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16169 first_unchanged_at_end_row
);
16170 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16172 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16173 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16175 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16176 xassert (w
->window_end_bytepos
>= 0);
16177 IF_DEBUG (debug_method_add (w
, "A"));
16179 else if (last_text_row_at_end
)
16182 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16183 w
->window_end_bytepos
16184 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16186 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16187 xassert (w
->window_end_bytepos
>= 0);
16188 IF_DEBUG (debug_method_add (w
, "B"));
16190 else if (last_text_row
)
16192 /* We have displayed either to the end of the window or at the
16193 end of the window, i.e. the last row with text is to be found
16194 in the desired matrix. */
16196 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16197 w
->window_end_bytepos
16198 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16200 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16201 xassert (w
->window_end_bytepos
>= 0);
16203 else if (first_unchanged_at_end_row
== NULL
16204 && last_text_row
== NULL
16205 && last_text_row_at_end
== NULL
)
16207 /* Displayed to end of window, but no line containing text was
16208 displayed. Lines were deleted at the end of the window. */
16209 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16210 int vpos
= XFASTINT (w
->window_end_vpos
);
16211 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16212 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16215 row
== NULL
&& vpos
>= first_vpos
;
16216 --vpos
, --current_row
, --desired_row
)
16218 if (desired_row
->enabled_p
)
16220 if (desired_row
->displays_text_p
)
16223 else if (current_row
->displays_text_p
)
16227 xassert (row
!= NULL
);
16228 w
->window_end_vpos
= make_number (vpos
+ 1);
16229 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16230 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16231 xassert (w
->window_end_bytepos
>= 0);
16232 IF_DEBUG (debug_method_add (w
, "C"));
16237 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16238 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16240 /* Record that display has not been completed. */
16241 w
->window_end_valid
= Qnil
;
16242 w
->desired_matrix
->no_scrolling_p
= 1;
16250 /***********************************************************************
16251 More debugging support
16252 ***********************************************************************/
16256 void dump_glyph_row (struct glyph_row
*, int, int);
16257 void dump_glyph_matrix (struct glyph_matrix
*, int);
16258 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16261 /* Dump the contents of glyph matrix MATRIX on stderr.
16263 GLYPHS 0 means don't show glyph contents.
16264 GLYPHS 1 means show glyphs in short form
16265 GLYPHS > 1 means show glyphs in long form. */
16268 dump_glyph_matrix (matrix
, glyphs
)
16269 struct glyph_matrix
*matrix
;
16273 for (i
= 0; i
< matrix
->nrows
; ++i
)
16274 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16278 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16279 the glyph row and area where the glyph comes from. */
16282 dump_glyph (row
, glyph
, area
)
16283 struct glyph_row
*row
;
16284 struct glyph
*glyph
;
16287 if (glyph
->type
== CHAR_GLYPH
)
16290 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16291 glyph
- row
->glyphs
[TEXT_AREA
],
16294 (BUFFERP (glyph
->object
)
16296 : (STRINGP (glyph
->object
)
16299 glyph
->pixel_width
,
16301 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16305 glyph
->left_box_line_p
,
16306 glyph
->right_box_line_p
);
16308 else if (glyph
->type
== STRETCH_GLYPH
)
16311 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16312 glyph
- row
->glyphs
[TEXT_AREA
],
16315 (BUFFERP (glyph
->object
)
16317 : (STRINGP (glyph
->object
)
16320 glyph
->pixel_width
,
16324 glyph
->left_box_line_p
,
16325 glyph
->right_box_line_p
);
16327 else if (glyph
->type
== IMAGE_GLYPH
)
16330 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16331 glyph
- row
->glyphs
[TEXT_AREA
],
16334 (BUFFERP (glyph
->object
)
16336 : (STRINGP (glyph
->object
)
16339 glyph
->pixel_width
,
16343 glyph
->left_box_line_p
,
16344 glyph
->right_box_line_p
);
16346 else if (glyph
->type
== COMPOSITE_GLYPH
)
16349 " %5d %4c %6d %c %3d 0x%05x",
16350 glyph
- row
->glyphs
[TEXT_AREA
],
16353 (BUFFERP (glyph
->object
)
16355 : (STRINGP (glyph
->object
)
16358 glyph
->pixel_width
,
16360 if (glyph
->u
.cmp
.automatic
)
16363 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16364 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16366 glyph
->left_box_line_p
,
16367 glyph
->right_box_line_p
);
16372 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16373 GLYPHS 0 means don't show glyph contents.
16374 GLYPHS 1 means show glyphs in short form
16375 GLYPHS > 1 means show glyphs in long form. */
16378 dump_glyph_row (row
, vpos
, glyphs
)
16379 struct glyph_row
*row
;
16384 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16385 fprintf (stderr
, "======================================================================\n");
16387 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16388 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16390 MATRIX_ROW_START_CHARPOS (row
),
16391 MATRIX_ROW_END_CHARPOS (row
),
16392 row
->used
[TEXT_AREA
],
16393 row
->contains_overlapping_glyphs_p
,
16395 row
->truncated_on_left_p
,
16396 row
->truncated_on_right_p
,
16398 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16399 row
->displays_text_p
,
16402 row
->ends_in_middle_of_char_p
,
16403 row
->starts_in_middle_of_char_p
,
16409 row
->visible_height
,
16412 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16413 row
->end
.overlay_string_index
,
16414 row
->continuation_lines_width
);
16415 fprintf (stderr
, "%9d %5d\n",
16416 CHARPOS (row
->start
.string_pos
),
16417 CHARPOS (row
->end
.string_pos
));
16418 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16419 row
->end
.dpvec_index
);
16426 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16428 struct glyph
*glyph
= row
->glyphs
[area
];
16429 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16431 /* Glyph for a line end in text. */
16432 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16435 if (glyph
< glyph_end
)
16436 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16438 for (; glyph
< glyph_end
; ++glyph
)
16439 dump_glyph (row
, glyph
, area
);
16442 else if (glyphs
== 1)
16446 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16448 char *s
= (char *) alloca (row
->used
[area
] + 1);
16451 for (i
= 0; i
< row
->used
[area
]; ++i
)
16453 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16454 if (glyph
->type
== CHAR_GLYPH
16455 && glyph
->u
.ch
< 0x80
16456 && glyph
->u
.ch
>= ' ')
16457 s
[i
] = glyph
->u
.ch
;
16463 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16469 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16470 Sdump_glyph_matrix
, 0, 1, "p",
16471 doc
: /* Dump the current matrix of the selected window to stderr.
16472 Shows contents of glyph row structures. With non-nil
16473 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16474 glyphs in short form, otherwise show glyphs in long form. */)
16475 (Lisp_Object glyphs
)
16477 struct window
*w
= XWINDOW (selected_window
);
16478 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16480 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16481 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16482 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16483 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16484 fprintf (stderr
, "=============================================\n");
16485 dump_glyph_matrix (w
->current_matrix
,
16486 NILP (glyphs
) ? 0 : XINT (glyphs
));
16491 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16492 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16495 struct frame
*f
= XFRAME (selected_frame
);
16496 dump_glyph_matrix (f
->current_matrix
, 1);
16501 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16502 doc
: /* Dump glyph row ROW to stderr.
16503 GLYPH 0 means don't dump glyphs.
16504 GLYPH 1 means dump glyphs in short form.
16505 GLYPH > 1 or omitted means dump glyphs in long form. */)
16506 (Lisp_Object row
, Lisp_Object glyphs
)
16508 struct glyph_matrix
*matrix
;
16511 CHECK_NUMBER (row
);
16512 matrix
= XWINDOW (selected_window
)->current_matrix
;
16514 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16515 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16517 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16522 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16523 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16524 GLYPH 0 means don't dump glyphs.
16525 GLYPH 1 means dump glyphs in short form.
16526 GLYPH > 1 or omitted means dump glyphs in long form. */)
16527 (Lisp_Object row
, Lisp_Object glyphs
)
16529 struct frame
*sf
= SELECTED_FRAME ();
16530 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16533 CHECK_NUMBER (row
);
16535 if (vpos
>= 0 && vpos
< m
->nrows
)
16536 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16537 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16542 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16543 doc
: /* Toggle tracing of redisplay.
16544 With ARG, turn tracing on if and only if ARG is positive. */)
16548 trace_redisplay_p
= !trace_redisplay_p
;
16551 arg
= Fprefix_numeric_value (arg
);
16552 trace_redisplay_p
= XINT (arg
) > 0;
16559 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16560 doc
: /* Like `format', but print result to stderr.
16561 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16562 (int nargs
, Lisp_Object
*args
)
16564 Lisp_Object s
= Fformat (nargs
, args
);
16565 fprintf (stderr
, "%s", SDATA (s
));
16569 #endif /* GLYPH_DEBUG */
16573 /***********************************************************************
16574 Building Desired Matrix Rows
16575 ***********************************************************************/
16577 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16578 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16580 static struct glyph_row
*
16581 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
16583 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16584 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16585 struct buffer
*old
= current_buffer
;
16586 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16587 int arrow_len
= SCHARS (overlay_arrow_string
);
16588 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16589 const unsigned char *p
;
16592 int n_glyphs_before
;
16594 set_buffer_temp (buffer
);
16595 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16596 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16597 SET_TEXT_POS (it
.position
, 0, 0);
16599 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16601 while (p
< arrow_end
)
16603 Lisp_Object face
, ilisp
;
16605 /* Get the next character. */
16607 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
16610 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
16611 if (! ASCII_CHAR_P (it
.c
))
16612 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
16616 /* Get its face. */
16617 ilisp
= make_number (p
- arrow_string
);
16618 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16619 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
16621 /* Compute its width, get its glyphs. */
16622 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16623 SET_TEXT_POS (it
.position
, -1, -1);
16624 PRODUCE_GLYPHS (&it
);
16626 /* If this character doesn't fit any more in the line, we have
16627 to remove some glyphs. */
16628 if (it
.current_x
> it
.last_visible_x
)
16630 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16635 set_buffer_temp (old
);
16636 return it
.glyph_row
;
16640 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16641 glyphs are only inserted for terminal frames since we can't really
16642 win with truncation glyphs when partially visible glyphs are
16643 involved. Which glyphs to insert is determined by
16644 produce_special_glyphs. */
16647 insert_left_trunc_glyphs (struct it
*it
)
16649 struct it truncate_it
;
16650 struct glyph
*from
, *end
, *to
, *toend
;
16652 xassert (!FRAME_WINDOW_P (it
->f
));
16654 /* Get the truncation glyphs. */
16656 truncate_it
.current_x
= 0;
16657 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16658 truncate_it
.glyph_row
= &scratch_glyph_row
;
16659 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16660 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16661 truncate_it
.object
= make_number (0);
16662 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16664 /* Overwrite glyphs from IT with truncation glyphs. */
16665 if (!it
->glyph_row
->reversed_p
)
16667 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16668 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16669 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16670 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16675 /* There may be padding glyphs left over. Overwrite them too. */
16676 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16678 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16684 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16688 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
16689 that back to front. */
16690 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16691 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16692 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16693 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16695 while (from
>= end
&& to
>= toend
)
16697 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
16700 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
16701 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16702 while (from
>= end
&& to
>= toend
)
16707 /* Need to free some room before prepending additional
16709 int move_by
= from
- end
+ 1;
16710 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16711 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16713 for ( ; g
>= g0
; g
--)
16715 while (from
>= end
)
16717 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
16723 /* Compute the pixel height and width of IT->glyph_row.
16725 Most of the time, ascent and height of a display line will be equal
16726 to the max_ascent and max_height values of the display iterator
16727 structure. This is not the case if
16729 1. We hit ZV without displaying anything. In this case, max_ascent
16730 and max_height will be zero.
16732 2. We have some glyphs that don't contribute to the line height.
16733 (The glyph row flag contributes_to_line_height_p is for future
16734 pixmap extensions).
16736 The first case is easily covered by using default values because in
16737 these cases, the line height does not really matter, except that it
16738 must not be zero. */
16741 compute_line_metrics (struct it
*it
)
16743 struct glyph_row
*row
= it
->glyph_row
;
16746 if (FRAME_WINDOW_P (it
->f
))
16748 int i
, min_y
, max_y
;
16750 /* The line may consist of one space only, that was added to
16751 place the cursor on it. If so, the row's height hasn't been
16753 if (row
->height
== 0)
16755 if (it
->max_ascent
+ it
->max_descent
== 0)
16756 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16757 row
->ascent
= it
->max_ascent
;
16758 row
->height
= it
->max_ascent
+ it
->max_descent
;
16759 row
->phys_ascent
= it
->max_phys_ascent
;
16760 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16761 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16764 /* Compute the width of this line. */
16765 row
->pixel_width
= row
->x
;
16766 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16767 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16769 xassert (row
->pixel_width
>= 0);
16770 xassert (row
->ascent
>= 0 && row
->height
> 0);
16772 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16773 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16775 /* If first line's physical ascent is larger than its logical
16776 ascent, use the physical ascent, and make the row taller.
16777 This makes accented characters fully visible. */
16778 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16779 && row
->phys_ascent
> row
->ascent
)
16781 row
->height
+= row
->phys_ascent
- row
->ascent
;
16782 row
->ascent
= row
->phys_ascent
;
16785 /* Compute how much of the line is visible. */
16786 row
->visible_height
= row
->height
;
16788 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16789 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16791 if (row
->y
< min_y
)
16792 row
->visible_height
-= min_y
- row
->y
;
16793 if (row
->y
+ row
->height
> max_y
)
16794 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16798 row
->pixel_width
= row
->used
[TEXT_AREA
];
16799 if (row
->continued_p
)
16800 row
->pixel_width
-= it
->continuation_pixel_width
;
16801 else if (row
->truncated_on_right_p
)
16802 row
->pixel_width
-= it
->truncation_pixel_width
;
16803 row
->ascent
= row
->phys_ascent
= 0;
16804 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16805 row
->extra_line_spacing
= 0;
16808 /* Compute a hash code for this row. */
16810 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16811 for (i
= 0; i
< row
->used
[area
]; ++i
)
16812 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16813 + row
->glyphs
[area
][i
].u
.val
16814 + row
->glyphs
[area
][i
].face_id
16815 + row
->glyphs
[area
][i
].padding_p
16816 + (row
->glyphs
[area
][i
].type
<< 2));
16818 it
->max_ascent
= it
->max_descent
= 0;
16819 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16823 /* Append one space to the glyph row of iterator IT if doing a
16824 window-based redisplay. The space has the same face as
16825 IT->face_id. Value is non-zero if a space was added.
16827 This function is called to make sure that there is always one glyph
16828 at the end of a glyph row that the cursor can be set on under
16829 window-systems. (If there weren't such a glyph we would not know
16830 how wide and tall a box cursor should be displayed).
16832 At the same time this space let's a nicely handle clearing to the
16833 end of the line if the row ends in italic text. */
16836 append_space_for_newline (struct it
*it
, int default_face_p
)
16838 if (FRAME_WINDOW_P (it
->f
))
16840 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16842 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16843 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16845 /* Save some values that must not be changed.
16846 Must save IT->c and IT->len because otherwise
16847 ITERATOR_AT_END_P wouldn't work anymore after
16848 append_space_for_newline has been called. */
16849 enum display_element_type saved_what
= it
->what
;
16850 int saved_c
= it
->c
, saved_len
= it
->len
;
16851 int saved_char_to_display
= it
->char_to_display
;
16852 int saved_x
= it
->current_x
;
16853 int saved_face_id
= it
->face_id
;
16854 struct text_pos saved_pos
;
16855 Lisp_Object saved_object
;
16858 saved_object
= it
->object
;
16859 saved_pos
= it
->position
;
16861 it
->what
= IT_CHARACTER
;
16862 memset (&it
->position
, 0, sizeof it
->position
);
16863 it
->object
= make_number (0);
16864 it
->c
= it
->char_to_display
= ' ';
16867 if (default_face_p
)
16868 it
->face_id
= DEFAULT_FACE_ID
;
16869 else if (it
->face_before_selective_p
)
16870 it
->face_id
= it
->saved_face_id
;
16871 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16872 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16874 PRODUCE_GLYPHS (it
);
16876 it
->override_ascent
= -1;
16877 it
->constrain_row_ascent_descent_p
= 0;
16878 it
->current_x
= saved_x
;
16879 it
->object
= saved_object
;
16880 it
->position
= saved_pos
;
16881 it
->what
= saved_what
;
16882 it
->face_id
= saved_face_id
;
16883 it
->len
= saved_len
;
16885 it
->char_to_display
= saved_char_to_display
;
16894 /* Extend the face of the last glyph in the text area of IT->glyph_row
16895 to the end of the display line. Called from display_line. If the
16896 glyph row is empty, add a space glyph to it so that we know the
16897 face to draw. Set the glyph row flag fill_line_p. If the glyph
16898 row is R2L, prepend a stretch glyph to cover the empty space to the
16899 left of the leftmost glyph. */
16902 extend_face_to_end_of_line (struct it
*it
)
16905 struct frame
*f
= it
->f
;
16907 /* If line is already filled, do nothing. Non window-system frames
16908 get a grace of one more ``pixel'' because their characters are
16909 1-``pixel'' wide, so they hit the equality too early. This grace
16910 is needed only for R2L rows that are not continued, to produce
16911 one extra blank where we could display the cursor. */
16912 if (it
->current_x
>= it
->last_visible_x
16913 + (!FRAME_WINDOW_P (f
)
16914 && it
->glyph_row
->reversed_p
16915 && !it
->glyph_row
->continued_p
))
16918 /* Face extension extends the background and box of IT->face_id
16919 to the end of the line. If the background equals the background
16920 of the frame, we don't have to do anything. */
16921 if (it
->face_before_selective_p
)
16922 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
16924 face
= FACE_FROM_ID (f
, it
->face_id
);
16926 if (FRAME_WINDOW_P (f
)
16927 && it
->glyph_row
->displays_text_p
16928 && face
->box
== FACE_NO_BOX
16929 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16931 && !it
->glyph_row
->reversed_p
)
16934 /* Set the glyph row flag indicating that the face of the last glyph
16935 in the text area has to be drawn to the end of the text area. */
16936 it
->glyph_row
->fill_line_p
= 1;
16938 /* If current character of IT is not ASCII, make sure we have the
16939 ASCII face. This will be automatically undone the next time
16940 get_next_display_element returns a multibyte character. Note
16941 that the character will always be single byte in unibyte
16943 if (!ASCII_CHAR_P (it
->c
))
16945 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16948 if (FRAME_WINDOW_P (f
))
16950 /* If the row is empty, add a space with the current face of IT,
16951 so that we know which face to draw. */
16952 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16954 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16955 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16956 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16958 #ifdef HAVE_WINDOW_SYSTEM
16959 if (it
->glyph_row
->reversed_p
)
16961 /* Prepend a stretch glyph to the row, such that the
16962 rightmost glyph will be drawn flushed all the way to the
16963 right margin of the window. The stretch glyph that will
16964 occupy the empty space, if any, to the left of the
16966 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
16967 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16968 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
16970 int row_width
, stretch_ascent
, stretch_width
;
16971 struct text_pos saved_pos
;
16972 int saved_face_id
, saved_avoid_cursor
;
16974 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
16975 row_width
+= g
->pixel_width
;
16976 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
16977 if (stretch_width
> 0)
16980 (((it
->ascent
+ it
->descent
)
16981 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
16982 saved_pos
= it
->position
;
16983 memset (&it
->position
, 0, sizeof it
->position
);
16984 saved_avoid_cursor
= it
->avoid_cursor_p
;
16985 it
->avoid_cursor_p
= 1;
16986 saved_face_id
= it
->face_id
;
16987 /* The last row's stretch glyph should get the default
16988 face, to avoid painting the rest of the window with
16989 the region face, if the region ends at ZV. */
16990 if (it
->glyph_row
->ends_at_zv_p
)
16991 it
->face_id
= DEFAULT_FACE_ID
;
16993 it
->face_id
= face
->id
;
16994 append_stretch_glyph (it
, make_number (0), stretch_width
,
16995 it
->ascent
+ it
->descent
, stretch_ascent
);
16996 it
->position
= saved_pos
;
16997 it
->avoid_cursor_p
= saved_avoid_cursor
;
16998 it
->face_id
= saved_face_id
;
17001 #endif /* HAVE_WINDOW_SYSTEM */
17005 /* Save some values that must not be changed. */
17006 int saved_x
= it
->current_x
;
17007 struct text_pos saved_pos
;
17008 Lisp_Object saved_object
;
17009 enum display_element_type saved_what
= it
->what
;
17010 int saved_face_id
= it
->face_id
;
17012 saved_object
= it
->object
;
17013 saved_pos
= it
->position
;
17015 it
->what
= IT_CHARACTER
;
17016 memset (&it
->position
, 0, sizeof it
->position
);
17017 it
->object
= make_number (0);
17018 it
->c
= it
->char_to_display
= ' ';
17020 /* The last row's blank glyphs should get the default face, to
17021 avoid painting the rest of the window with the region face,
17022 if the region ends at ZV. */
17023 if (it
->glyph_row
->ends_at_zv_p
)
17024 it
->face_id
= DEFAULT_FACE_ID
;
17026 it
->face_id
= face
->id
;
17028 PRODUCE_GLYPHS (it
);
17030 while (it
->current_x
<= it
->last_visible_x
)
17031 PRODUCE_GLYPHS (it
);
17033 /* Don't count these blanks really. It would let us insert a left
17034 truncation glyph below and make us set the cursor on them, maybe. */
17035 it
->current_x
= saved_x
;
17036 it
->object
= saved_object
;
17037 it
->position
= saved_pos
;
17038 it
->what
= saved_what
;
17039 it
->face_id
= saved_face_id
;
17044 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17045 trailing whitespace. */
17048 trailing_whitespace_p (EMACS_INT charpos
)
17050 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17053 while (bytepos
< ZV_BYTE
17054 && (c
= FETCH_CHAR (bytepos
),
17055 c
== ' ' || c
== '\t'))
17058 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17060 if (bytepos
!= PT_BYTE
)
17067 /* Highlight trailing whitespace, if any, in ROW. */
17070 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17072 int used
= row
->used
[TEXT_AREA
];
17076 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17077 struct glyph
*glyph
= start
+ used
- 1;
17079 if (row
->reversed_p
)
17081 /* Right-to-left rows need to be processed in the opposite
17082 direction, so swap the edge pointers. */
17084 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17087 /* Skip over glyphs inserted to display the cursor at the
17088 end of a line, for extending the face of the last glyph
17089 to the end of the line on terminals, and for truncation
17090 and continuation glyphs. */
17091 if (!row
->reversed_p
)
17093 while (glyph
>= start
17094 && glyph
->type
== CHAR_GLYPH
17095 && INTEGERP (glyph
->object
))
17100 while (glyph
<= start
17101 && glyph
->type
== CHAR_GLYPH
17102 && INTEGERP (glyph
->object
))
17106 /* If last glyph is a space or stretch, and it's trailing
17107 whitespace, set the face of all trailing whitespace glyphs in
17108 IT->glyph_row to `trailing-whitespace'. */
17109 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17110 && BUFFERP (glyph
->object
)
17111 && (glyph
->type
== STRETCH_GLYPH
17112 || (glyph
->type
== CHAR_GLYPH
17113 && glyph
->u
.ch
== ' '))
17114 && trailing_whitespace_p (glyph
->charpos
))
17116 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17120 if (!row
->reversed_p
)
17122 while (glyph
>= start
17123 && BUFFERP (glyph
->object
)
17124 && (glyph
->type
== STRETCH_GLYPH
17125 || (glyph
->type
== CHAR_GLYPH
17126 && glyph
->u
.ch
== ' ')))
17127 (glyph
--)->face_id
= face_id
;
17131 while (glyph
<= start
17132 && BUFFERP (glyph
->object
)
17133 && (glyph
->type
== STRETCH_GLYPH
17134 || (glyph
->type
== CHAR_GLYPH
17135 && glyph
->u
.ch
== ' ')))
17136 (glyph
++)->face_id
= face_id
;
17143 /* Value is non-zero if glyph row ROW in window W should be
17144 used to hold the cursor. */
17147 cursor_row_p (struct window
*w
, struct glyph_row
*row
)
17149 int cursor_row_p
= 1;
17151 if (PT
== CHARPOS (row
->end
.pos
))
17153 /* Suppose the row ends on a string.
17154 Unless the row is continued, that means it ends on a newline
17155 in the string. If it's anything other than a display string
17156 (e.g. a before-string from an overlay), we don't want the
17157 cursor there. (This heuristic seems to give the optimal
17158 behavior for the various types of multi-line strings.) */
17159 if (CHARPOS (row
->end
.string_pos
) >= 0)
17161 if (row
->continued_p
)
17165 /* Check for `display' property. */
17166 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17167 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17168 struct glyph
*glyph
;
17171 for (glyph
= end
; glyph
>= beg
; --glyph
)
17172 if (STRINGP (glyph
->object
))
17175 = Fget_char_property (make_number (PT
),
17179 && display_prop_string_p (prop
, glyph
->object
));
17184 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17186 /* If the row ends in middle of a real character,
17187 and the line is continued, we want the cursor here.
17188 That's because CHARPOS (ROW->end.pos) would equal
17189 PT if PT is before the character. */
17190 if (!row
->ends_in_ellipsis_p
)
17191 cursor_row_p
= row
->continued_p
;
17193 /* If the row ends in an ellipsis, then
17194 CHARPOS (ROW->end.pos) will equal point after the
17195 invisible text. We want that position to be displayed
17196 after the ellipsis. */
17199 /* If the row ends at ZV, display the cursor at the end of that
17200 row instead of at the start of the row below. */
17201 else if (row
->ends_at_zv_p
)
17207 return cursor_row_p
;
17212 /* Push the display property PROP so that it will be rendered at the
17213 current position in IT. Return 1 if PROP was successfully pushed,
17217 push_display_prop (struct it
*it
, Lisp_Object prop
)
17221 if (STRINGP (prop
))
17223 if (SCHARS (prop
) == 0)
17230 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17231 it
->current
.overlay_string_index
= -1;
17232 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17233 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17234 it
->method
= GET_FROM_STRING
;
17235 it
->stop_charpos
= 0;
17237 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17239 it
->method
= GET_FROM_STRETCH
;
17242 #ifdef HAVE_WINDOW_SYSTEM
17243 else if (IMAGEP (prop
))
17245 it
->what
= IT_IMAGE
;
17246 it
->image_id
= lookup_image (it
->f
, prop
);
17247 it
->method
= GET_FROM_IMAGE
;
17249 #endif /* HAVE_WINDOW_SYSTEM */
17252 pop_it (it
); /* bogus display property, give up */
17259 /* Return the character-property PROP at the current position in IT. */
17262 get_it_property (struct it
*it
, Lisp_Object prop
)
17264 Lisp_Object position
;
17266 if (STRINGP (it
->object
))
17267 position
= make_number (IT_STRING_CHARPOS (*it
));
17268 else if (BUFFERP (it
->object
))
17269 position
= make_number (IT_CHARPOS (*it
));
17273 return Fget_char_property (position
, prop
, it
->object
);
17276 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17279 handle_line_prefix (struct it
*it
)
17281 Lisp_Object prefix
;
17282 if (it
->continuation_lines_width
> 0)
17284 prefix
= get_it_property (it
, Qwrap_prefix
);
17286 prefix
= Vwrap_prefix
;
17290 prefix
= get_it_property (it
, Qline_prefix
);
17292 prefix
= Vline_prefix
;
17294 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17296 /* If the prefix is wider than the window, and we try to wrap
17297 it, it would acquire its own wrap prefix, and so on till the
17298 iterator stack overflows. So, don't wrap the prefix. */
17299 it
->line_wrap
= TRUNCATE
;
17300 it
->avoid_cursor_p
= 1;
17306 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17307 only for R2L lines from display_line, when it decides that too many
17308 glyphs were produced by PRODUCE_GLYPHS, and the line needs to be
17311 unproduce_glyphs (struct it
*it
, int n
)
17313 struct glyph
*glyph
, *end
;
17315 xassert (it
->glyph_row
);
17316 xassert (it
->glyph_row
->reversed_p
);
17317 xassert (it
->area
== TEXT_AREA
);
17318 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17320 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17321 n
= it
->glyph_row
->used
[TEXT_AREA
];
17322 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17323 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17324 for ( ; glyph
< end
; glyph
++)
17325 glyph
[-n
] = *glyph
;
17328 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17329 and ROW->maxpos. */
17331 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17332 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17333 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17335 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17336 lines' rows is implemented for bidi-reordered rows. */
17338 /* ROW->minpos is the value of min_pos, the minimal buffer position
17341 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17344 /* We didn't find _any_ valid buffer positions in any of the
17345 glyphs, so we must trust the iterator's computed
17347 row
->minpos
= row
->start
.pos
;
17348 max_pos
= CHARPOS (it
->current
.pos
);
17349 max_bpos
= BYTEPOS (it
->current
.pos
);
17355 /* Here are the various use-cases for ending the row, and the
17356 corresponding values for ROW->maxpos:
17358 Line ends in a newline from buffer eol_pos + 1
17359 Line is continued from buffer max_pos + 1
17360 Line is truncated on right it->current.pos
17361 Line ends in a newline from string max_pos
17362 Line is continued from string max_pos
17363 Line is continued from display vector max_pos
17364 Line is entirely from a string min_pos == max_pos
17365 Line is entirely from a display vector min_pos == max_pos
17366 Line that ends at ZV ZV
17368 If you discover other use-cases, please add them here as
17370 if (row
->ends_at_zv_p
)
17371 row
->maxpos
= it
->current
.pos
;
17372 else if (row
->used
[TEXT_AREA
])
17374 if (row
->ends_in_newline_from_string_p
)
17375 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17376 else if (CHARPOS (it
->eol_pos
) > 0)
17377 SET_TEXT_POS (row
->maxpos
,
17378 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17379 else if (row
->continued_p
)
17381 /* If max_pos is different from IT's current position, it
17382 means IT->method does not belong to the display element
17383 at max_pos. However, it also means that the display
17384 element at max_pos was displayed in its entirety on this
17385 line, which is equivalent to saying that the next line
17386 starts at the next buffer position. */
17387 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17388 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17391 INC_BOTH (max_pos
, max_bpos
);
17392 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17395 else if (row
->truncated_on_right_p
)
17396 /* display_line already called reseat_at_next_visible_line_start,
17397 which puts the iterator at the beginning of the next line, in
17398 the logical order. */
17399 row
->maxpos
= it
->current
.pos
;
17400 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17401 /* A line that is entirely from a string/image/stretch... */
17402 row
->maxpos
= row
->minpos
;
17407 row
->maxpos
= it
->current
.pos
;
17410 /* Construct the glyph row IT->glyph_row in the desired matrix of
17411 IT->w from text at the current position of IT. See dispextern.h
17412 for an overview of struct it. Value is non-zero if
17413 IT->glyph_row displays text, as opposed to a line displaying ZV
17417 display_line (struct it
*it
)
17419 struct glyph_row
*row
= it
->glyph_row
;
17420 Lisp_Object overlay_arrow_string
;
17422 int may_wrap
= 0, wrap_x
;
17423 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
17424 int wrap_row_phys_ascent
, wrap_row_phys_height
;
17425 int wrap_row_extra_line_spacing
;
17426 EMACS_INT wrap_row_min_pos
, wrap_row_min_bpos
;
17427 EMACS_INT wrap_row_max_pos
, wrap_row_max_bpos
;
17429 EMACS_INT min_pos
= ZV
+ 1, min_bpos
, max_pos
= 0, max_bpos
;
17431 /* We always start displaying at hpos zero even if hscrolled. */
17432 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17434 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17435 >= it
->w
->desired_matrix
->nrows
)
17437 it
->w
->nrows_scale_factor
++;
17438 fonts_changed_p
= 1;
17442 /* Is IT->w showing the region? */
17443 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17445 /* Clear the result glyph row and enable it. */
17446 prepare_desired_row (row
);
17448 row
->y
= it
->current_y
;
17449 row
->start
= it
->start
;
17450 row
->continuation_lines_width
= it
->continuation_lines_width
;
17451 row
->displays_text_p
= 1;
17452 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17453 it
->starts_in_middle_of_char_p
= 0;
17455 /* Arrange the overlays nicely for our purposes. Usually, we call
17456 display_line on only one line at a time, in which case this
17457 can't really hurt too much, or we call it on lines which appear
17458 one after another in the buffer, in which case all calls to
17459 recenter_overlay_lists but the first will be pretty cheap. */
17460 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17462 /* Move over display elements that are not visible because we are
17463 hscrolled. This may stop at an x-position < IT->first_visible_x
17464 if the first glyph is partially visible or if we hit a line end. */
17465 if (it
->current_x
< it
->first_visible_x
)
17467 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17468 MOVE_TO_POS
| MOVE_TO_X
);
17472 /* We only do this when not calling `move_it_in_display_line_to'
17473 above, because move_it_in_display_line_to calls
17474 handle_line_prefix itself. */
17475 handle_line_prefix (it
);
17478 /* Get the initial row height. This is either the height of the
17479 text hscrolled, if there is any, or zero. */
17480 row
->ascent
= it
->max_ascent
;
17481 row
->height
= it
->max_ascent
+ it
->max_descent
;
17482 row
->phys_ascent
= it
->max_phys_ascent
;
17483 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17484 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17486 /* Utility macro to record max and min buffer positions seen until now. */
17487 #define RECORD_MAX_MIN_POS(IT) \
17490 if (IT_CHARPOS (*(IT)) < min_pos) \
17492 min_pos = IT_CHARPOS (*(IT)); \
17493 min_bpos = IT_BYTEPOS (*(IT)); \
17495 if (IT_CHARPOS (*(IT)) > max_pos) \
17497 max_pos = IT_CHARPOS (*(IT)); \
17498 max_bpos = IT_BYTEPOS (*(IT)); \
17503 /* Loop generating characters. The loop is left with IT on the next
17504 character to display. */
17507 int n_glyphs_before
, hpos_before
, x_before
;
17509 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17511 /* Retrieve the next thing to display. Value is zero if end of
17513 if (!get_next_display_element (it
))
17515 /* Maybe add a space at the end of this line that is used to
17516 display the cursor there under X. Set the charpos of the
17517 first glyph of blank lines not corresponding to any text
17519 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17520 row
->exact_window_width_line_p
= 1;
17521 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17522 || row
->used
[TEXT_AREA
] == 0)
17524 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17525 row
->displays_text_p
= 0;
17527 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17528 && (!MINI_WINDOW_P (it
->w
)
17529 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17530 row
->indicate_empty_line_p
= 1;
17533 it
->continuation_lines_width
= 0;
17534 row
->ends_at_zv_p
= 1;
17535 /* A row that displays right-to-left text must always have
17536 its last face extended all the way to the end of line,
17537 even if this row ends in ZV, because we still write to
17538 the screen left to right. */
17539 if (row
->reversed_p
)
17540 extend_face_to_end_of_line (it
);
17544 /* Now, get the metrics of what we want to display. This also
17545 generates glyphs in `row' (which is IT->glyph_row). */
17546 n_glyphs_before
= row
->used
[TEXT_AREA
];
17549 /* Remember the line height so far in case the next element doesn't
17550 fit on the line. */
17551 if (it
->line_wrap
!= TRUNCATE
)
17553 ascent
= it
->max_ascent
;
17554 descent
= it
->max_descent
;
17555 phys_ascent
= it
->max_phys_ascent
;
17556 phys_descent
= it
->max_phys_descent
;
17558 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17560 if (IT_DISPLAYING_WHITESPACE (it
))
17566 wrap_row_used
= row
->used
[TEXT_AREA
];
17567 wrap_row_ascent
= row
->ascent
;
17568 wrap_row_height
= row
->height
;
17569 wrap_row_phys_ascent
= row
->phys_ascent
;
17570 wrap_row_phys_height
= row
->phys_height
;
17571 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17572 wrap_row_min_pos
= min_pos
;
17573 wrap_row_min_bpos
= min_bpos
;
17574 wrap_row_max_pos
= max_pos
;
17575 wrap_row_max_bpos
= max_bpos
;
17581 PRODUCE_GLYPHS (it
);
17583 /* If this display element was in marginal areas, continue with
17585 if (it
->area
!= TEXT_AREA
)
17587 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17588 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17589 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17590 row
->phys_height
= max (row
->phys_height
,
17591 it
->max_phys_ascent
+ it
->max_phys_descent
);
17592 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17593 it
->max_extra_line_spacing
);
17594 set_iterator_to_next (it
, 1);
17598 /* Does the display element fit on the line? If we truncate
17599 lines, we should draw past the right edge of the window. If
17600 we don't truncate, we want to stop so that we can display the
17601 continuation glyph before the right margin. If lines are
17602 continued, there are two possible strategies for characters
17603 resulting in more than 1 glyph (e.g. tabs): Display as many
17604 glyphs as possible in this line and leave the rest for the
17605 continuation line, or display the whole element in the next
17606 line. Original redisplay did the former, so we do it also. */
17607 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17608 hpos_before
= it
->hpos
;
17611 if (/* Not a newline. */
17613 /* Glyphs produced fit entirely in the line. */
17614 && it
->current_x
< it
->last_visible_x
)
17616 it
->hpos
+= nglyphs
;
17617 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17618 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17619 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17620 row
->phys_height
= max (row
->phys_height
,
17621 it
->max_phys_ascent
+ it
->max_phys_descent
);
17622 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17623 it
->max_extra_line_spacing
);
17624 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17625 row
->x
= x
- it
->first_visible_x
;
17626 /* Record the maximum and minimum buffer positions seen so
17627 far in glyphs that will be displayed by this row. */
17629 RECORD_MAX_MIN_POS (it
);
17634 struct glyph
*glyph
;
17636 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17638 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17639 new_x
= x
+ glyph
->pixel_width
;
17641 if (/* Lines are continued. */
17642 it
->line_wrap
!= TRUNCATE
17643 && (/* Glyph doesn't fit on the line. */
17644 new_x
> it
->last_visible_x
17645 /* Or it fits exactly on a window system frame. */
17646 || (new_x
== it
->last_visible_x
17647 && FRAME_WINDOW_P (it
->f
))))
17649 /* End of a continued line. */
17652 || (new_x
== it
->last_visible_x
17653 && FRAME_WINDOW_P (it
->f
)))
17655 /* Current glyph is the only one on the line or
17656 fits exactly on the line. We must continue
17657 the line because we can't draw the cursor
17658 after the glyph. */
17659 row
->continued_p
= 1;
17660 it
->current_x
= new_x
;
17661 it
->continuation_lines_width
+= new_x
;
17663 /* Record the maximum and minimum buffer
17664 positions seen so far in glyphs that will be
17665 displayed by this row. */
17667 RECORD_MAX_MIN_POS (it
);
17668 if (i
== nglyphs
- 1)
17670 /* If line-wrap is on, check if a previous
17671 wrap point was found. */
17672 if (wrap_row_used
> 0
17673 /* Even if there is a previous wrap
17674 point, continue the line here as
17675 usual, if (i) the previous character
17676 was a space or tab AND (ii) the
17677 current character is not. */
17679 || IT_DISPLAYING_WHITESPACE (it
)))
17682 set_iterator_to_next (it
, 1);
17683 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17685 if (!get_next_display_element (it
))
17687 row
->exact_window_width_line_p
= 1;
17688 it
->continuation_lines_width
= 0;
17689 row
->continued_p
= 0;
17690 row
->ends_at_zv_p
= 1;
17692 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17694 row
->continued_p
= 0;
17695 row
->exact_window_width_line_p
= 1;
17700 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17701 && !FRAME_WINDOW_P (it
->f
))
17703 /* A padding glyph that doesn't fit on this line.
17704 This means the whole character doesn't fit
17706 if (row
->reversed_p
)
17707 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17708 - n_glyphs_before
);
17709 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17711 /* Fill the rest of the row with continuation
17712 glyphs like in 20.x. */
17713 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17714 < row
->glyphs
[1 + TEXT_AREA
])
17715 produce_special_glyphs (it
, IT_CONTINUATION
);
17717 row
->continued_p
= 1;
17718 it
->current_x
= x_before
;
17719 it
->continuation_lines_width
+= x_before
;
17721 /* Restore the height to what it was before the
17722 element not fitting on the line. */
17723 it
->max_ascent
= ascent
;
17724 it
->max_descent
= descent
;
17725 it
->max_phys_ascent
= phys_ascent
;
17726 it
->max_phys_descent
= phys_descent
;
17728 else if (wrap_row_used
> 0)
17731 if (row
->reversed_p
)
17732 unproduce_glyphs (it
,
17733 row
->used
[TEXT_AREA
] - wrap_row_used
);
17735 it
->continuation_lines_width
+= wrap_x
;
17736 row
->used
[TEXT_AREA
] = wrap_row_used
;
17737 row
->ascent
= wrap_row_ascent
;
17738 row
->height
= wrap_row_height
;
17739 row
->phys_ascent
= wrap_row_phys_ascent
;
17740 row
->phys_height
= wrap_row_phys_height
;
17741 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17742 min_pos
= wrap_row_min_pos
;
17743 min_bpos
= wrap_row_min_bpos
;
17744 max_pos
= wrap_row_max_pos
;
17745 max_bpos
= wrap_row_max_bpos
;
17746 row
->continued_p
= 1;
17747 row
->ends_at_zv_p
= 0;
17748 row
->exact_window_width_line_p
= 0;
17749 it
->continuation_lines_width
+= x
;
17751 /* Make sure that a non-default face is extended
17752 up to the right margin of the window. */
17753 extend_face_to_end_of_line (it
);
17755 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17757 /* A TAB that extends past the right edge of the
17758 window. This produces a single glyph on
17759 window system frames. We leave the glyph in
17760 this row and let it fill the row, but don't
17761 consume the TAB. */
17762 it
->continuation_lines_width
+= it
->last_visible_x
;
17763 row
->ends_in_middle_of_char_p
= 1;
17764 row
->continued_p
= 1;
17765 glyph
->pixel_width
= it
->last_visible_x
- x
;
17766 it
->starts_in_middle_of_char_p
= 1;
17770 /* Something other than a TAB that draws past
17771 the right edge of the window. Restore
17772 positions to values before the element. */
17773 if (row
->reversed_p
)
17774 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17775 - (n_glyphs_before
+ i
));
17776 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17778 /* Display continuation glyphs. */
17779 if (!FRAME_WINDOW_P (it
->f
))
17780 produce_special_glyphs (it
, IT_CONTINUATION
);
17781 row
->continued_p
= 1;
17783 it
->current_x
= x_before
;
17784 it
->continuation_lines_width
+= x
;
17785 extend_face_to_end_of_line (it
);
17787 if (nglyphs
> 1 && i
> 0)
17789 row
->ends_in_middle_of_char_p
= 1;
17790 it
->starts_in_middle_of_char_p
= 1;
17793 /* Restore the height to what it was before the
17794 element not fitting on the line. */
17795 it
->max_ascent
= ascent
;
17796 it
->max_descent
= descent
;
17797 it
->max_phys_ascent
= phys_ascent
;
17798 it
->max_phys_descent
= phys_descent
;
17803 else if (new_x
> it
->first_visible_x
)
17805 /* Increment number of glyphs actually displayed. */
17808 /* Record the maximum and minimum buffer positions
17809 seen so far in glyphs that will be displayed by
17812 RECORD_MAX_MIN_POS (it
);
17814 if (x
< it
->first_visible_x
)
17815 /* Glyph is partially visible, i.e. row starts at
17816 negative X position. */
17817 row
->x
= x
- it
->first_visible_x
;
17821 /* Glyph is completely off the left margin of the
17822 window. This should not happen because of the
17823 move_it_in_display_line at the start of this
17824 function, unless the text display area of the
17825 window is empty. */
17826 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17830 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17831 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17832 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17833 row
->phys_height
= max (row
->phys_height
,
17834 it
->max_phys_ascent
+ it
->max_phys_descent
);
17835 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17836 it
->max_extra_line_spacing
);
17838 /* End of this display line if row is continued. */
17839 if (row
->continued_p
|| row
->ends_at_zv_p
)
17844 /* Is this a line end? If yes, we're also done, after making
17845 sure that a non-default face is extended up to the right
17846 margin of the window. */
17847 if (ITERATOR_AT_END_OF_LINE_P (it
))
17849 int used_before
= row
->used
[TEXT_AREA
];
17851 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17853 /* Add a space at the end of the line that is used to
17854 display the cursor there. */
17855 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17856 append_space_for_newline (it
, 0);
17858 /* Extend the face to the end of the line. */
17859 extend_face_to_end_of_line (it
);
17861 /* Make sure we have the position. */
17862 if (used_before
== 0)
17863 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17865 /* Record the position of the newline, for use in
17867 it
->eol_pos
= it
->current
.pos
;
17869 /* Consume the line end. This skips over invisible lines. */
17870 set_iterator_to_next (it
, 1);
17871 it
->continuation_lines_width
= 0;
17875 /* Proceed with next display element. Note that this skips
17876 over lines invisible because of selective display. */
17877 set_iterator_to_next (it
, 1);
17879 /* If we truncate lines, we are done when the last displayed
17880 glyphs reach past the right margin of the window. */
17881 if (it
->line_wrap
== TRUNCATE
17882 && (FRAME_WINDOW_P (it
->f
)
17883 ? (it
->current_x
>= it
->last_visible_x
)
17884 : (it
->current_x
> it
->last_visible_x
)))
17886 /* Maybe add truncation glyphs. */
17887 if (!FRAME_WINDOW_P (it
->f
))
17891 if (!row
->reversed_p
)
17893 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17894 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17899 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
17900 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17902 /* Remove any padding glyphs at the front of ROW, to
17903 make room for the truncation glyphs we will be
17904 adding below. The loop below always inserts at
17905 least one truncation glyph, so also remove the
17906 last glyph added to ROW. */
17907 unproduce_glyphs (it
, i
+ 1);
17908 /* Adjust i for the loop below. */
17909 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
17912 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17914 row
->used
[TEXT_AREA
] = i
;
17915 produce_special_glyphs (it
, IT_TRUNCATION
);
17918 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17920 /* Don't truncate if we can overflow newline into fringe. */
17921 if (!get_next_display_element (it
))
17923 it
->continuation_lines_width
= 0;
17924 row
->ends_at_zv_p
= 1;
17925 row
->exact_window_width_line_p
= 1;
17928 if (ITERATOR_AT_END_OF_LINE_P (it
))
17930 row
->exact_window_width_line_p
= 1;
17931 goto at_end_of_line
;
17935 row
->truncated_on_right_p
= 1;
17936 it
->continuation_lines_width
= 0;
17937 reseat_at_next_visible_line_start (it
, 0);
17938 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17939 it
->hpos
= hpos_before
;
17940 it
->current_x
= x_before
;
17945 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17946 at the left window margin. */
17947 if (it
->first_visible_x
17948 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
17950 if (!FRAME_WINDOW_P (it
->f
))
17951 insert_left_trunc_glyphs (it
);
17952 row
->truncated_on_left_p
= 1;
17955 /* Remember the position at which this line ends.
17957 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
17958 cannot be before the call to find_row_edges below, since that is
17959 where these positions are determined. */
17960 row
->end
= it
->current
;
17963 row
->minpos
= row
->start
.pos
;
17964 row
->maxpos
= row
->end
.pos
;
17968 /* ROW->minpos and ROW->maxpos must be the smallest and
17969 `1 + the largest' buffer positions in ROW. But if ROW was
17970 bidi-reordered, these two positions can be anywhere in the
17971 row, so we must determine them now. */
17972 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
17975 /* If the start of this line is the overlay arrow-position, then
17976 mark this glyph row as the one containing the overlay arrow.
17977 This is clearly a mess with variable size fonts. It would be
17978 better to let it be displayed like cursors under X. */
17979 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17980 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17981 !NILP (overlay_arrow_string
)))
17983 /* Overlay arrow in window redisplay is a fringe bitmap. */
17984 if (STRINGP (overlay_arrow_string
))
17986 struct glyph_row
*arrow_row
17987 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17988 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17989 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17990 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17991 struct glyph
*p2
, *end
;
17993 /* Copy the arrow glyphs. */
17994 while (glyph
< arrow_end
)
17997 /* Throw away padding glyphs. */
17999 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18000 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18006 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18011 xassert (INTEGERP (overlay_arrow_string
));
18012 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18014 overlay_arrow_seen
= 1;
18017 /* Compute pixel dimensions of this line. */
18018 compute_line_metrics (it
);
18020 /* Record whether this row ends inside an ellipsis. */
18021 row
->ends_in_ellipsis_p
18022 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18023 && it
->ellipsis_p
);
18025 /* Save fringe bitmaps in this row. */
18026 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18027 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18028 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18029 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18031 it
->left_user_fringe_bitmap
= 0;
18032 it
->left_user_fringe_face_id
= 0;
18033 it
->right_user_fringe_bitmap
= 0;
18034 it
->right_user_fringe_face_id
= 0;
18036 /* Maybe set the cursor. */
18037 cvpos
= it
->w
->cursor
.vpos
;
18039 /* In bidi-reordered rows, keep checking for proper cursor
18040 position even if one has been found already, because buffer
18041 positions in such rows change non-linearly with ROW->VPOS,
18042 when a line is continued. One exception: when we are at ZV,
18043 display cursor on the first suitable glyph row, since all
18044 the empty rows after that also have their position set to ZV. */
18045 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18046 lines' rows is implemented for bidi-reordered rows. */
18048 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18049 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18050 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18051 && cursor_row_p (it
->w
, row
))
18052 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18054 /* Highlight trailing whitespace. */
18055 if (!NILP (Vshow_trailing_whitespace
))
18056 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18058 /* Prepare for the next line. This line starts horizontally at (X
18059 HPOS) = (0 0). Vertical positions are incremented. As a
18060 convenience for the caller, IT->glyph_row is set to the next
18062 it
->current_x
= it
->hpos
= 0;
18063 it
->current_y
+= row
->height
;
18064 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18067 /* The next row should by default use the same value of the
18068 reversed_p flag as this one. set_iterator_to_next decides when
18069 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18070 the flag accordingly. */
18071 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18072 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18073 it
->start
= row
->end
;
18074 return row
->displays_text_p
;
18076 #undef RECORD_MAX_MIN_POS
18079 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18080 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18081 doc
: /* Return paragraph direction at point in BUFFER.
18082 Value is either `left-to-right' or `right-to-left'.
18083 If BUFFER is omitted or nil, it defaults to the current buffer.
18085 Paragraph direction determines how the text in the paragraph is displayed.
18086 In left-to-right paragraphs, text begins at the left margin of the window
18087 and the reading direction is generally left to right. In right-to-left
18088 paragraphs, text begins at the right margin and is read from right to left.
18090 See also `bidi-paragraph-direction'. */)
18091 (Lisp_Object buffer
)
18093 struct buffer
*buf
;
18094 struct buffer
*old
;
18097 buf
= current_buffer
;
18100 CHECK_BUFFER (buffer
);
18101 buf
= XBUFFER (buffer
);
18102 old
= current_buffer
;
18105 if (NILP (buf
->bidi_display_reordering
))
18106 return Qleft_to_right
;
18107 else if (!NILP (buf
->bidi_paragraph_direction
))
18108 return buf
->bidi_paragraph_direction
;
18111 /* Determine the direction from buffer text. We could try to
18112 use current_matrix if it is up to date, but this seems fast
18113 enough as it is. */
18114 struct bidi_it itb
;
18115 EMACS_INT pos
= BUF_PT (buf
);
18116 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18119 if (buf
!= current_buffer
)
18120 set_buffer_temp (buf
);
18121 /* bidi_paragraph_init finds the base direction of the paragraph
18122 by searching forward from paragraph start. We need the base
18123 direction of the current or _previous_ paragraph, so we need
18124 to make sure we are within that paragraph. To that end, find
18125 the previous non-empty line. */
18126 if (pos
>= ZV
&& pos
> BEGV
)
18129 bytepos
= CHAR_TO_BYTE (pos
);
18131 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18132 || c
== ' ' || c
== '\t' || c
== '\f')
18134 if (bytepos
<= BEGV_BYTE
)
18139 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18142 itb
.bytepos
= bytepos
;
18144 itb
.separator_limit
= -1;
18145 itb
.paragraph_dir
= NEUTRAL_DIR
;
18147 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18148 if (buf
!= current_buffer
)
18149 set_buffer_temp (old
);
18150 switch (itb
.paragraph_dir
)
18153 return Qleft_to_right
;
18156 return Qright_to_left
;
18166 /***********************************************************************
18168 ***********************************************************************/
18170 /* Redisplay the menu bar in the frame for window W.
18172 The menu bar of X frames that don't have X toolkit support is
18173 displayed in a special window W->frame->menu_bar_window.
18175 The menu bar of terminal frames is treated specially as far as
18176 glyph matrices are concerned. Menu bar lines are not part of
18177 windows, so the update is done directly on the frame matrix rows
18178 for the menu bar. */
18181 display_menu_bar (struct window
*w
)
18183 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18188 /* Don't do all this for graphical frames. */
18190 if (FRAME_W32_P (f
))
18193 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18199 if (FRAME_NS_P (f
))
18201 #endif /* HAVE_NS */
18203 #ifdef USE_X_TOOLKIT
18204 xassert (!FRAME_WINDOW_P (f
));
18205 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18206 it
.first_visible_x
= 0;
18207 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18208 #else /* not USE_X_TOOLKIT */
18209 if (FRAME_WINDOW_P (f
))
18211 /* Menu bar lines are displayed in the desired matrix of the
18212 dummy window menu_bar_window. */
18213 struct window
*menu_w
;
18214 xassert (WINDOWP (f
->menu_bar_window
));
18215 menu_w
= XWINDOW (f
->menu_bar_window
);
18216 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18218 it
.first_visible_x
= 0;
18219 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18223 /* This is a TTY frame, i.e. character hpos/vpos are used as
18225 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18227 it
.first_visible_x
= 0;
18228 it
.last_visible_x
= FRAME_COLS (f
);
18230 #endif /* not USE_X_TOOLKIT */
18232 if (! mode_line_inverse_video
)
18233 /* Force the menu-bar to be displayed in the default face. */
18234 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18236 /* Clear all rows of the menu bar. */
18237 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18239 struct glyph_row
*row
= it
.glyph_row
+ i
;
18240 clear_glyph_row (row
);
18241 row
->enabled_p
= 1;
18242 row
->full_width_p
= 1;
18245 /* Display all items of the menu bar. */
18246 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18247 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
18249 Lisp_Object string
;
18251 /* Stop at nil string. */
18252 string
= AREF (items
, i
+ 1);
18256 /* Remember where item was displayed. */
18257 ASET (items
, i
+ 3, make_number (it
.hpos
));
18259 /* Display the item, pad with one space. */
18260 if (it
.current_x
< it
.last_visible_x
)
18261 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18262 SCHARS (string
) + 1, 0, 0, -1);
18265 /* Fill out the line with spaces. */
18266 if (it
.current_x
< it
.last_visible_x
)
18267 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18269 /* Compute the total height of the lines. */
18270 compute_line_metrics (&it
);
18275 /***********************************************************************
18277 ***********************************************************************/
18279 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18280 FORCE is non-zero, redisplay mode lines unconditionally.
18281 Otherwise, redisplay only mode lines that are garbaged. Value is
18282 the number of windows whose mode lines were redisplayed. */
18285 redisplay_mode_lines (Lisp_Object window
, int force
)
18289 while (!NILP (window
))
18291 struct window
*w
= XWINDOW (window
);
18293 if (WINDOWP (w
->hchild
))
18294 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18295 else if (WINDOWP (w
->vchild
))
18296 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18298 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18299 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18301 struct text_pos lpoint
;
18302 struct buffer
*old
= current_buffer
;
18304 /* Set the window's buffer for the mode line display. */
18305 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18306 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18308 /* Point refers normally to the selected window. For any
18309 other window, set up appropriate value. */
18310 if (!EQ (window
, selected_window
))
18312 struct text_pos pt
;
18314 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18315 if (CHARPOS (pt
) < BEGV
)
18316 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18317 else if (CHARPOS (pt
) > (ZV
- 1))
18318 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18320 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18323 /* Display mode lines. */
18324 clear_glyph_matrix (w
->desired_matrix
);
18325 if (display_mode_lines (w
))
18328 w
->must_be_updated_p
= 1;
18331 /* Restore old settings. */
18332 set_buffer_internal_1 (old
);
18333 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18343 /* Display the mode and/or header line of window W. Value is the
18344 sum number of mode lines and header lines displayed. */
18347 display_mode_lines (struct window
*w
)
18349 Lisp_Object old_selected_window
, old_selected_frame
;
18352 old_selected_frame
= selected_frame
;
18353 selected_frame
= w
->frame
;
18354 old_selected_window
= selected_window
;
18355 XSETWINDOW (selected_window
, w
);
18357 /* These will be set while the mode line specs are processed. */
18358 line_number_displayed
= 0;
18359 w
->column_number_displayed
= Qnil
;
18361 if (WINDOW_WANTS_MODELINE_P (w
))
18363 struct window
*sel_w
= XWINDOW (old_selected_window
);
18365 /* Select mode line face based on the real selected window. */
18366 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18367 current_buffer
->mode_line_format
);
18371 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18373 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18374 current_buffer
->header_line_format
);
18378 selected_frame
= old_selected_frame
;
18379 selected_window
= old_selected_window
;
18384 /* Display mode or header line of window W. FACE_ID specifies which
18385 line to display; it is either MODE_LINE_FACE_ID or
18386 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18387 display. Value is the pixel height of the mode/header line
18391 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18395 int count
= SPECPDL_INDEX ();
18397 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18398 /* Don't extend on a previously drawn mode-line.
18399 This may happen if called from pos_visible_p. */
18400 it
.glyph_row
->enabled_p
= 0;
18401 prepare_desired_row (it
.glyph_row
);
18403 it
.glyph_row
->mode_line_p
= 1;
18405 if (! mode_line_inverse_video
)
18406 /* Force the mode-line to be displayed in the default face. */
18407 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18409 record_unwind_protect (unwind_format_mode_line
,
18410 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18412 mode_line_target
= MODE_LINE_DISPLAY
;
18414 /* Temporarily make frame's keyboard the current kboard so that
18415 kboard-local variables in the mode_line_format will get the right
18417 push_kboard (FRAME_KBOARD (it
.f
));
18418 record_unwind_save_match_data ();
18419 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18422 unbind_to (count
, Qnil
);
18424 /* Fill up with spaces. */
18425 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18427 compute_line_metrics (&it
);
18428 it
.glyph_row
->full_width_p
= 1;
18429 it
.glyph_row
->continued_p
= 0;
18430 it
.glyph_row
->truncated_on_left_p
= 0;
18431 it
.glyph_row
->truncated_on_right_p
= 0;
18433 /* Make a 3D mode-line have a shadow at its right end. */
18434 face
= FACE_FROM_ID (it
.f
, face_id
);
18435 extend_face_to_end_of_line (&it
);
18436 if (face
->box
!= FACE_NO_BOX
)
18438 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18439 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18440 last
->right_box_line_p
= 1;
18443 return it
.glyph_row
->height
;
18446 /* Move element ELT in LIST to the front of LIST.
18447 Return the updated list. */
18450 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
18452 register Lisp_Object tail
, prev
;
18453 register Lisp_Object tem
;
18457 while (CONSP (tail
))
18463 /* Splice out the link TAIL. */
18465 list
= XCDR (tail
);
18467 Fsetcdr (prev
, XCDR (tail
));
18469 /* Now make it the first. */
18470 Fsetcdr (tail
, list
);
18475 tail
= XCDR (tail
);
18479 /* Not found--return unchanged LIST. */
18483 /* Contribute ELT to the mode line for window IT->w. How it
18484 translates into text depends on its data type.
18486 IT describes the display environment in which we display, as usual.
18488 DEPTH is the depth in recursion. It is used to prevent
18489 infinite recursion here.
18491 FIELD_WIDTH is the number of characters the display of ELT should
18492 occupy in the mode line, and PRECISION is the maximum number of
18493 characters to display from ELT's representation. See
18494 display_string for details.
18496 Returns the hpos of the end of the text generated by ELT.
18498 PROPS is a property list to add to any string we encounter.
18500 If RISKY is nonzero, remove (disregard) any properties in any string
18501 we encounter, and ignore :eval and :propertize.
18503 The global variable `mode_line_target' determines whether the
18504 output is passed to `store_mode_line_noprop',
18505 `store_mode_line_string', or `display_string'. */
18508 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
18509 Lisp_Object elt
, Lisp_Object props
, int risky
)
18511 int n
= 0, field
, prec
;
18516 elt
= build_string ("*too-deep*");
18520 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18524 /* A string: output it and check for %-constructs within it. */
18526 EMACS_INT offset
= 0;
18528 if (SCHARS (elt
) > 0
18529 && (!NILP (props
) || risky
))
18531 Lisp_Object oprops
, aelt
;
18532 oprops
= Ftext_properties_at (make_number (0), elt
);
18534 /* If the starting string's properties are not what
18535 we want, translate the string. Also, if the string
18536 is risky, do that anyway. */
18538 if (NILP (Fequal (props
, oprops
)) || risky
)
18540 /* If the starting string has properties,
18541 merge the specified ones onto the existing ones. */
18542 if (! NILP (oprops
) && !risky
)
18546 oprops
= Fcopy_sequence (oprops
);
18548 while (CONSP (tem
))
18550 oprops
= Fplist_put (oprops
, XCAR (tem
),
18551 XCAR (XCDR (tem
)));
18552 tem
= XCDR (XCDR (tem
));
18557 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18558 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18560 /* AELT is what we want. Move it to the front
18561 without consing. */
18563 mode_line_proptrans_alist
18564 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18570 /* If AELT has the wrong props, it is useless.
18571 so get rid of it. */
18573 mode_line_proptrans_alist
18574 = Fdelq (aelt
, mode_line_proptrans_alist
);
18576 elt
= Fcopy_sequence (elt
);
18577 Fset_text_properties (make_number (0), Flength (elt
),
18579 /* Add this item to mode_line_proptrans_alist. */
18580 mode_line_proptrans_alist
18581 = Fcons (Fcons (elt
, props
),
18582 mode_line_proptrans_alist
);
18583 /* Truncate mode_line_proptrans_alist
18584 to at most 50 elements. */
18585 tem
= Fnthcdr (make_number (50),
18586 mode_line_proptrans_alist
);
18588 XSETCDR (tem
, Qnil
);
18597 prec
= precision
- n
;
18598 switch (mode_line_target
)
18600 case MODE_LINE_NOPROP
:
18601 case MODE_LINE_TITLE
:
18602 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
18604 case MODE_LINE_STRING
:
18605 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18607 case MODE_LINE_DISPLAY
:
18608 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18609 0, prec
, 0, STRING_MULTIBYTE (elt
));
18616 /* Handle the non-literal case. */
18618 while ((precision
<= 0 || n
< precision
)
18619 && SREF (elt
, offset
) != 0
18620 && (mode_line_target
!= MODE_LINE_DISPLAY
18621 || it
->current_x
< it
->last_visible_x
))
18623 EMACS_INT last_offset
= offset
;
18625 /* Advance to end of string or next format specifier. */
18626 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18629 if (offset
- 1 != last_offset
)
18631 EMACS_INT nchars
, nbytes
;
18633 /* Output to end of string or up to '%'. Field width
18634 is length of string. Don't output more than
18635 PRECISION allows us. */
18638 prec
= c_string_width (SDATA (elt
) + last_offset
,
18639 offset
- last_offset
, precision
- n
,
18642 switch (mode_line_target
)
18644 case MODE_LINE_NOPROP
:
18645 case MODE_LINE_TITLE
:
18646 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18648 case MODE_LINE_STRING
:
18650 EMACS_INT bytepos
= last_offset
;
18651 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18652 EMACS_INT endpos
= (precision
<= 0
18653 ? string_byte_to_char (elt
, offset
)
18654 : charpos
+ nchars
);
18656 n
+= store_mode_line_string (NULL
,
18657 Fsubstring (elt
, make_number (charpos
),
18658 make_number (endpos
)),
18662 case MODE_LINE_DISPLAY
:
18664 EMACS_INT bytepos
= last_offset
;
18665 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18667 if (precision
<= 0)
18668 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18669 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18671 STRING_MULTIBYTE (elt
));
18676 else /* c == '%' */
18678 EMACS_INT percent_position
= offset
;
18680 /* Get the specified minimum width. Zero means
18683 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18684 field
= field
* 10 + c
- '0';
18686 /* Don't pad beyond the total padding allowed. */
18687 if (field_width
- n
> 0 && field
> field_width
- n
)
18688 field
= field_width
- n
;
18690 /* Note that either PRECISION <= 0 or N < PRECISION. */
18691 prec
= precision
- n
;
18694 n
+= display_mode_element (it
, depth
, field
, prec
,
18695 Vglobal_mode_string
, props
,
18700 EMACS_INT bytepos
, charpos
;
18701 const unsigned char *spec
;
18702 Lisp_Object string
;
18704 bytepos
= percent_position
;
18705 charpos
= (STRING_MULTIBYTE (elt
)
18706 ? string_byte_to_char (elt
, bytepos
)
18708 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
18709 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18711 switch (mode_line_target
)
18713 case MODE_LINE_NOPROP
:
18714 case MODE_LINE_TITLE
:
18715 n
+= store_mode_line_noprop (spec
, field
, prec
);
18717 case MODE_LINE_STRING
:
18719 int len
= strlen (spec
);
18720 Lisp_Object tem
= make_string (spec
, len
);
18721 props
= Ftext_properties_at (make_number (charpos
), elt
);
18722 /* Should only keep face property in props */
18723 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18726 case MODE_LINE_DISPLAY
:
18728 int nglyphs_before
, nwritten
;
18730 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18731 nwritten
= display_string (spec
, string
, elt
,
18736 /* Assign to the glyphs written above the
18737 string where the `%x' came from, position
18741 struct glyph
*glyph
18742 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18746 for (i
= 0; i
< nwritten
; ++i
)
18748 glyph
[i
].object
= elt
;
18749 glyph
[i
].charpos
= charpos
;
18766 /* A symbol: process the value of the symbol recursively
18767 as if it appeared here directly. Avoid error if symbol void.
18768 Special case: if value of symbol is a string, output the string
18771 register Lisp_Object tem
;
18773 /* If the variable is not marked as risky to set
18774 then its contents are risky to use. */
18775 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18778 tem
= Fboundp (elt
);
18781 tem
= Fsymbol_value (elt
);
18782 /* If value is a string, output that string literally:
18783 don't check for % within it. */
18787 if (!EQ (tem
, elt
))
18789 /* Give up right away for nil or t. */
18799 register Lisp_Object car
, tem
;
18801 /* A cons cell: five distinct cases.
18802 If first element is :eval or :propertize, do something special.
18803 If first element is a string or a cons, process all the elements
18804 and effectively concatenate them.
18805 If first element is a negative number, truncate displaying cdr to
18806 at most that many characters. If positive, pad (with spaces)
18807 to at least that many characters.
18808 If first element is a symbol, process the cadr or caddr recursively
18809 according to whether the symbol's value is non-nil or nil. */
18811 if (EQ (car
, QCeval
))
18813 /* An element of the form (:eval FORM) means evaluate FORM
18814 and use the result as mode line elements. */
18819 if (CONSP (XCDR (elt
)))
18822 spec
= safe_eval (XCAR (XCDR (elt
)));
18823 n
+= display_mode_element (it
, depth
, field_width
- n
,
18824 precision
- n
, spec
, props
,
18828 else if (EQ (car
, QCpropertize
))
18830 /* An element of the form (:propertize ELT PROPS...)
18831 means display ELT but applying properties PROPS. */
18836 if (CONSP (XCDR (elt
)))
18837 n
+= display_mode_element (it
, depth
, field_width
- n
,
18838 precision
- n
, XCAR (XCDR (elt
)),
18839 XCDR (XCDR (elt
)), risky
);
18841 else if (SYMBOLP (car
))
18843 tem
= Fboundp (car
);
18847 /* elt is now the cdr, and we know it is a cons cell.
18848 Use its car if CAR has a non-nil value. */
18851 tem
= Fsymbol_value (car
);
18858 /* Symbol's value is nil (or symbol is unbound)
18859 Get the cddr of the original list
18860 and if possible find the caddr and use that. */
18864 else if (!CONSP (elt
))
18869 else if (INTEGERP (car
))
18871 register int lim
= XINT (car
);
18875 /* Negative int means reduce maximum width. */
18876 if (precision
<= 0)
18879 precision
= min (precision
, -lim
);
18883 /* Padding specified. Don't let it be more than
18884 current maximum. */
18886 lim
= min (precision
, lim
);
18888 /* If that's more padding than already wanted, queue it.
18889 But don't reduce padding already specified even if
18890 that is beyond the current truncation point. */
18891 field_width
= max (lim
, field_width
);
18895 else if (STRINGP (car
) || CONSP (car
))
18897 Lisp_Object halftail
= elt
;
18901 && (precision
<= 0 || n
< precision
))
18903 n
+= display_mode_element (it
, depth
,
18904 /* Do padding only after the last
18905 element in the list. */
18906 (! CONSP (XCDR (elt
))
18909 precision
- n
, XCAR (elt
),
18913 if ((len
& 1) == 0)
18914 halftail
= XCDR (halftail
);
18915 /* Check for cycle. */
18916 if (EQ (halftail
, elt
))
18925 elt
= build_string ("*invalid*");
18929 /* Pad to FIELD_WIDTH. */
18930 if (field_width
> 0 && n
< field_width
)
18932 switch (mode_line_target
)
18934 case MODE_LINE_NOPROP
:
18935 case MODE_LINE_TITLE
:
18936 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18938 case MODE_LINE_STRING
:
18939 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18941 case MODE_LINE_DISPLAY
:
18942 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18951 /* Store a mode-line string element in mode_line_string_list.
18953 If STRING is non-null, display that C string. Otherwise, the Lisp
18954 string LISP_STRING is displayed.
18956 FIELD_WIDTH is the minimum number of output glyphs to produce.
18957 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18958 with spaces. FIELD_WIDTH <= 0 means don't pad.
18960 PRECISION is the maximum number of characters to output from
18961 STRING. PRECISION <= 0 means don't truncate the string.
18963 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18964 properties to the string.
18966 PROPS are the properties to add to the string.
18967 The mode_line_string_face face property is always added to the string.
18971 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
18972 int field_width
, int precision
, Lisp_Object props
)
18977 if (string
!= NULL
)
18979 len
= strlen (string
);
18980 if (precision
> 0 && len
> precision
)
18982 lisp_string
= make_string (string
, len
);
18984 props
= mode_line_string_face_prop
;
18985 else if (!NILP (mode_line_string_face
))
18987 Lisp_Object face
= Fplist_get (props
, Qface
);
18988 props
= Fcopy_sequence (props
);
18990 face
= mode_line_string_face
;
18992 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18993 props
= Fplist_put (props
, Qface
, face
);
18995 Fadd_text_properties (make_number (0), make_number (len
),
18996 props
, lisp_string
);
19000 len
= XFASTINT (Flength (lisp_string
));
19001 if (precision
> 0 && len
> precision
)
19004 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19007 if (!NILP (mode_line_string_face
))
19011 props
= Ftext_properties_at (make_number (0), lisp_string
);
19012 face
= Fplist_get (props
, Qface
);
19014 face
= mode_line_string_face
;
19016 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19017 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19019 lisp_string
= Fcopy_sequence (lisp_string
);
19022 Fadd_text_properties (make_number (0), make_number (len
),
19023 props
, lisp_string
);
19028 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19032 if (field_width
> len
)
19034 field_width
-= len
;
19035 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19037 Fadd_text_properties (make_number (0), make_number (field_width
),
19038 props
, lisp_string
);
19039 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19047 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19049 doc
: /* Format a string out of a mode line format specification.
19050 First arg FORMAT specifies the mode line format (see `mode-line-format'
19051 for details) to use.
19053 Optional second arg FACE specifies the face property to put
19054 on all characters for which no face is specified.
19055 The value t means whatever face the window's mode line currently uses
19056 \(either `mode-line' or `mode-line-inactive', depending).
19057 A value of nil means the default is no face property.
19058 If FACE is an integer, the value string has no text properties.
19060 Optional third and fourth args WINDOW and BUFFER specify the window
19061 and buffer to use as the context for the formatting (defaults
19062 are the selected window and the window's buffer). */)
19063 (Lisp_Object format
, Lisp_Object face
, Lisp_Object window
, Lisp_Object buffer
)
19068 struct buffer
*old_buffer
= NULL
;
19070 int no_props
= INTEGERP (face
);
19071 int count
= SPECPDL_INDEX ();
19073 int string_start
= 0;
19076 window
= selected_window
;
19077 CHECK_WINDOW (window
);
19078 w
= XWINDOW (window
);
19081 buffer
= w
->buffer
;
19082 CHECK_BUFFER (buffer
);
19084 /* Make formatting the modeline a non-op when noninteractive, otherwise
19085 there will be problems later caused by a partially initialized frame. */
19086 if (NILP (format
) || noninteractive
)
19087 return empty_unibyte_string
;
19095 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
19096 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
19100 face_id
= DEFAULT_FACE_ID
;
19102 if (XBUFFER (buffer
) != current_buffer
)
19103 old_buffer
= current_buffer
;
19105 /* Save things including mode_line_proptrans_alist,
19106 and set that to nil so that we don't alter the outer value. */
19107 record_unwind_protect (unwind_format_mode_line
,
19108 format_mode_line_unwind_data
19109 (old_buffer
, selected_window
, 1));
19110 mode_line_proptrans_alist
= Qnil
;
19112 Fselect_window (window
, Qt
);
19114 set_buffer_internal_1 (XBUFFER (buffer
));
19116 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19120 mode_line_target
= MODE_LINE_NOPROP
;
19121 mode_line_string_face_prop
= Qnil
;
19122 mode_line_string_list
= Qnil
;
19123 string_start
= MODE_LINE_NOPROP_LEN (0);
19127 mode_line_target
= MODE_LINE_STRING
;
19128 mode_line_string_list
= Qnil
;
19129 mode_line_string_face
= face
;
19130 mode_line_string_face_prop
19131 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19134 push_kboard (FRAME_KBOARD (it
.f
));
19135 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19140 len
= MODE_LINE_NOPROP_LEN (string_start
);
19141 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19145 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19146 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19147 empty_unibyte_string
);
19150 unbind_to (count
, Qnil
);
19154 /* Write a null-terminated, right justified decimal representation of
19155 the positive integer D to BUF using a minimal field width WIDTH. */
19158 pint2str (register char *buf
, register int width
, register int d
)
19160 register char *p
= buf
;
19168 *p
++ = d
% 10 + '0';
19173 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19184 /* Write a null-terminated, right justified decimal and "human
19185 readable" representation of the nonnegative integer D to BUF using
19186 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19188 static const char power_letter
[] =
19202 pint2hrstr (char *buf
, int width
, int d
)
19204 /* We aim to represent the nonnegative integer D as
19205 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19208 /* -1 means: do not use TENTHS. */
19212 /* Length of QUOTIENT.TENTHS as a string. */
19218 if (1000 <= quotient
)
19220 /* Scale to the appropriate EXPONENT. */
19223 remainder
= quotient
% 1000;
19227 while (1000 <= quotient
);
19229 /* Round to nearest and decide whether to use TENTHS or not. */
19232 tenths
= remainder
/ 100;
19233 if (50 <= remainder
% 100)
19240 if (quotient
== 10)
19248 if (500 <= remainder
)
19250 if (quotient
< 999)
19261 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19262 if (tenths
== -1 && quotient
<= 99)
19269 p
= psuffix
= buf
+ max (width
, length
);
19271 /* Print EXPONENT. */
19273 *psuffix
++ = power_letter
[exponent
];
19276 /* Print TENTHS. */
19279 *--p
= '0' + tenths
;
19283 /* Print QUOTIENT. */
19286 int digit
= quotient
% 10;
19287 *--p
= '0' + digit
;
19289 while ((quotient
/= 10) != 0);
19291 /* Print leading spaces. */
19296 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19297 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19298 type of CODING_SYSTEM. Return updated pointer into BUF. */
19300 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19303 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19306 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
19307 const unsigned char *eol_str
;
19309 /* The EOL conversion we are using. */
19310 Lisp_Object eoltype
;
19312 val
= CODING_SYSTEM_SPEC (coding_system
);
19315 if (!VECTORP (val
)) /* Not yet decided. */
19320 eoltype
= eol_mnemonic_undecided
;
19321 /* Don't mention EOL conversion if it isn't decided. */
19326 Lisp_Object eolvalue
;
19328 attrs
= AREF (val
, 0);
19329 eolvalue
= AREF (val
, 2);
19332 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19336 /* The EOL conversion that is normal on this system. */
19338 if (NILP (eolvalue
)) /* Not yet decided. */
19339 eoltype
= eol_mnemonic_undecided
;
19340 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19341 eoltype
= eol_mnemonic_undecided
;
19342 else /* eolvalue is Qunix, Qdos, or Qmac. */
19343 eoltype
= (EQ (eolvalue
, Qunix
)
19344 ? eol_mnemonic_unix
19345 : (EQ (eolvalue
, Qdos
) == 1
19346 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19352 /* Mention the EOL conversion if it is not the usual one. */
19353 if (STRINGP (eoltype
))
19355 eol_str
= SDATA (eoltype
);
19356 eol_str_len
= SBYTES (eoltype
);
19358 else if (CHARACTERP (eoltype
))
19360 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19361 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19366 eol_str
= invalid_eol_type
;
19367 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19369 memcpy (buf
, eol_str
, eol_str_len
);
19370 buf
+= eol_str_len
;
19376 /* Return a string for the output of a mode line %-spec for window W,
19377 generated by character C. PRECISION >= 0 means don't return a
19378 string longer than that value. FIELD_WIDTH > 0 means pad the
19379 string returned with spaces to that value. Return a Lisp string in
19380 *STRING if the resulting string is taken from that Lisp string.
19382 Note we operate on the current buffer for most purposes,
19383 the exception being w->base_line_pos. */
19385 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19387 static const char *
19388 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19389 int precision
, Lisp_Object
*string
)
19392 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19393 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19394 struct buffer
*b
= current_buffer
;
19402 if (!NILP (b
->read_only
))
19404 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19409 /* This differs from %* only for a modified read-only buffer. */
19410 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19412 if (!NILP (b
->read_only
))
19417 /* This differs from %* in ignoring read-only-ness. */
19418 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19430 if (command_loop_level
> 5)
19432 p
= decode_mode_spec_buf
;
19433 for (i
= 0; i
< command_loop_level
; i
++)
19436 return decode_mode_spec_buf
;
19444 if (command_loop_level
> 5)
19446 p
= decode_mode_spec_buf
;
19447 for (i
= 0; i
< command_loop_level
; i
++)
19450 return decode_mode_spec_buf
;
19457 /* Let lots_of_dashes be a string of infinite length. */
19458 if (mode_line_target
== MODE_LINE_NOPROP
||
19459 mode_line_target
== MODE_LINE_STRING
)
19461 if (field_width
<= 0
19462 || field_width
> sizeof (lots_of_dashes
))
19464 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19465 decode_mode_spec_buf
[i
] = '-';
19466 decode_mode_spec_buf
[i
] = '\0';
19467 return decode_mode_spec_buf
;
19470 return lots_of_dashes
;
19478 /* %c and %l are ignored in `frame-title-format'.
19479 (In redisplay_internal, the frame title is drawn _before_ the
19480 windows are updated, so the stuff which depends on actual
19481 window contents (such as %l) may fail to render properly, or
19482 even crash emacs.) */
19483 if (mode_line_target
== MODE_LINE_TITLE
)
19487 int col
= (int) current_column (); /* iftc */
19488 w
->column_number_displayed
= make_number (col
);
19489 pint2str (decode_mode_spec_buf
, field_width
, col
);
19490 return decode_mode_spec_buf
;
19494 #ifndef SYSTEM_MALLOC
19496 if (NILP (Vmemory_full
))
19499 return "!MEM FULL! ";
19506 /* %F displays the frame name. */
19507 if (!NILP (f
->title
))
19508 return (char *) SDATA (f
->title
);
19509 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19510 return (char *) SDATA (f
->name
);
19519 EMACS_INT size
= ZV
- BEGV
;
19520 pint2str (decode_mode_spec_buf
, field_width
, size
);
19521 return decode_mode_spec_buf
;
19526 EMACS_INT size
= ZV
- BEGV
;
19527 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19528 return decode_mode_spec_buf
;
19533 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19534 int topline
, nlines
, height
;
19537 /* %c and %l are ignored in `frame-title-format'. */
19538 if (mode_line_target
== MODE_LINE_TITLE
)
19541 startpos
= XMARKER (w
->start
)->charpos
;
19542 startpos_byte
= marker_byte_position (w
->start
);
19543 height
= WINDOW_TOTAL_LINES (w
);
19545 /* If we decided that this buffer isn't suitable for line numbers,
19546 don't forget that too fast. */
19547 if (EQ (w
->base_line_pos
, w
->buffer
))
19549 /* But do forget it, if the window shows a different buffer now. */
19550 else if (BUFFERP (w
->base_line_pos
))
19551 w
->base_line_pos
= Qnil
;
19553 /* If the buffer is very big, don't waste time. */
19554 if (INTEGERP (Vline_number_display_limit
)
19555 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19557 w
->base_line_pos
= Qnil
;
19558 w
->base_line_number
= Qnil
;
19562 if (INTEGERP (w
->base_line_number
)
19563 && INTEGERP (w
->base_line_pos
)
19564 && XFASTINT (w
->base_line_pos
) <= startpos
)
19566 line
= XFASTINT (w
->base_line_number
);
19567 linepos
= XFASTINT (w
->base_line_pos
);
19568 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19573 linepos
= BUF_BEGV (b
);
19574 linepos_byte
= BUF_BEGV_BYTE (b
);
19577 /* Count lines from base line to window start position. */
19578 nlines
= display_count_lines (linepos
, linepos_byte
,
19582 topline
= nlines
+ line
;
19584 /* Determine a new base line, if the old one is too close
19585 or too far away, or if we did not have one.
19586 "Too close" means it's plausible a scroll-down would
19587 go back past it. */
19588 if (startpos
== BUF_BEGV (b
))
19590 w
->base_line_number
= make_number (topline
);
19591 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19593 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19594 || linepos
== BUF_BEGV (b
))
19596 EMACS_INT limit
= BUF_BEGV (b
);
19597 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
19598 EMACS_INT position
;
19599 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
19601 if (startpos
- distance
> limit
)
19603 limit
= startpos
- distance
;
19604 limit_byte
= CHAR_TO_BYTE (limit
);
19607 nlines
= display_count_lines (startpos
, startpos_byte
,
19609 - (height
* 2 + 30),
19611 /* If we couldn't find the lines we wanted within
19612 line_number_display_limit_width chars per line,
19613 give up on line numbers for this window. */
19614 if (position
== limit_byte
&& limit
== startpos
- distance
)
19616 w
->base_line_pos
= w
->buffer
;
19617 w
->base_line_number
= Qnil
;
19621 w
->base_line_number
= make_number (topline
- nlines
);
19622 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19625 /* Now count lines from the start pos to point. */
19626 nlines
= display_count_lines (startpos
, startpos_byte
,
19627 PT_BYTE
, PT
, &junk
);
19629 /* Record that we did display the line number. */
19630 line_number_displayed
= 1;
19632 /* Make the string to show. */
19633 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19634 return decode_mode_spec_buf
;
19637 char* p
= decode_mode_spec_buf
;
19638 int pad
= field_width
- 2;
19644 return decode_mode_spec_buf
;
19650 obj
= b
->mode_name
;
19654 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19660 EMACS_INT pos
= marker_position (w
->start
);
19661 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19663 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19665 if (pos
<= BUF_BEGV (b
))
19670 else if (pos
<= BUF_BEGV (b
))
19674 if (total
> 1000000)
19675 /* Do it differently for a large value, to avoid overflow. */
19676 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19678 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19679 /* We can't normally display a 3-digit number,
19680 so get us a 2-digit number that is close. */
19683 sprintf (decode_mode_spec_buf
, "%2ld%%", (long)total
);
19684 return decode_mode_spec_buf
;
19688 /* Display percentage of size above the bottom of the screen. */
19691 EMACS_INT toppos
= marker_position (w
->start
);
19692 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19693 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19695 if (botpos
>= BUF_ZV (b
))
19697 if (toppos
<= BUF_BEGV (b
))
19704 if (total
> 1000000)
19705 /* Do it differently for a large value, to avoid overflow. */
19706 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19708 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19709 /* We can't normally display a 3-digit number,
19710 so get us a 2-digit number that is close. */
19713 if (toppos
<= BUF_BEGV (b
))
19714 sprintf (decode_mode_spec_buf
, "Top%2ld%%", (long)total
);
19716 sprintf (decode_mode_spec_buf
, "%2ld%%", (long)total
);
19717 return decode_mode_spec_buf
;
19722 /* status of process */
19723 obj
= Fget_buffer_process (Fcurrent_buffer ());
19725 return "no process";
19727 obj
= Fsymbol_name (Fprocess_status (obj
));
19733 int count
= inhibit_garbage_collection ();
19734 Lisp_Object val
= call1 (intern ("file-remote-p"),
19735 current_buffer
->directory
);
19736 unbind_to (count
, Qnil
);
19744 case 't': /* indicate TEXT or BINARY */
19745 #ifdef MODE_LINE_BINARY_TEXT
19746 return MODE_LINE_BINARY_TEXT (b
);
19752 /* coding-system (not including end-of-line format) */
19754 /* coding-system (including end-of-line type) */
19756 int eol_flag
= (c
== 'Z');
19757 char *p
= decode_mode_spec_buf
;
19759 if (! FRAME_WINDOW_P (f
))
19761 /* No need to mention EOL here--the terminal never needs
19762 to do EOL conversion. */
19763 p
= decode_mode_spec_coding (CODING_ID_NAME
19764 (FRAME_KEYBOARD_CODING (f
)->id
),
19766 p
= decode_mode_spec_coding (CODING_ID_NAME
19767 (FRAME_TERMINAL_CODING (f
)->id
),
19770 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19773 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19774 #ifdef subprocesses
19775 obj
= Fget_buffer_process (Fcurrent_buffer ());
19776 if (PROCESSP (obj
))
19778 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19780 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19783 #endif /* subprocesses */
19786 return decode_mode_spec_buf
;
19793 return (char *) SDATA (obj
);
19800 /* Count up to COUNT lines starting from START / START_BYTE.
19801 But don't go beyond LIMIT_BYTE.
19802 Return the number of lines thus found (always nonnegative).
19804 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19807 display_count_lines (EMACS_INT start
, EMACS_INT start_byte
,
19808 EMACS_INT limit_byte
, int count
,
19809 EMACS_INT
*byte_pos_ptr
)
19811 register unsigned char *cursor
;
19812 unsigned char *base
;
19814 register int ceiling
;
19815 register unsigned char *ceiling_addr
;
19816 int orig_count
= count
;
19818 /* If we are not in selective display mode,
19819 check only for newlines. */
19820 int selective_display
= (!NILP (current_buffer
->selective_display
)
19821 && !INTEGERP (current_buffer
->selective_display
));
19825 while (start_byte
< limit_byte
)
19827 ceiling
= BUFFER_CEILING_OF (start_byte
);
19828 ceiling
= min (limit_byte
- 1, ceiling
);
19829 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19830 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19833 if (selective_display
)
19834 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19837 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19840 if (cursor
!= ceiling_addr
)
19844 start_byte
+= cursor
- base
+ 1;
19845 *byte_pos_ptr
= start_byte
;
19849 if (++cursor
== ceiling_addr
)
19855 start_byte
+= cursor
- base
;
19860 while (start_byte
> limit_byte
)
19862 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19863 ceiling
= max (limit_byte
, ceiling
);
19864 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19865 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19868 if (selective_display
)
19869 while (--cursor
!= ceiling_addr
19870 && *cursor
!= '\n' && *cursor
!= 015)
19873 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19876 if (cursor
!= ceiling_addr
)
19880 start_byte
+= cursor
- base
+ 1;
19881 *byte_pos_ptr
= start_byte
;
19882 /* When scanning backwards, we should
19883 not count the newline posterior to which we stop. */
19884 return - orig_count
- 1;
19890 /* Here we add 1 to compensate for the last decrement
19891 of CURSOR, which took it past the valid range. */
19892 start_byte
+= cursor
- base
+ 1;
19896 *byte_pos_ptr
= limit_byte
;
19899 return - orig_count
+ count
;
19900 return orig_count
- count
;
19906 /***********************************************************************
19908 ***********************************************************************/
19910 /* Display a NUL-terminated string, starting with index START.
19912 If STRING is non-null, display that C string. Otherwise, the Lisp
19913 string LISP_STRING is displayed. There's a case that STRING is
19914 non-null and LISP_STRING is not nil. It means STRING is a string
19915 data of LISP_STRING. In that case, we display LISP_STRING while
19916 ignoring its text properties.
19918 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19919 FACE_STRING. Display STRING or LISP_STRING with the face at
19920 FACE_STRING_POS in FACE_STRING:
19922 Display the string in the environment given by IT, but use the
19923 standard display table, temporarily.
19925 FIELD_WIDTH is the minimum number of output glyphs to produce.
19926 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19927 with spaces. If STRING has more characters, more than FIELD_WIDTH
19928 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19930 PRECISION is the maximum number of characters to output from
19931 STRING. PRECISION < 0 means don't truncate the string.
19933 This is roughly equivalent to printf format specifiers:
19935 FIELD_WIDTH PRECISION PRINTF
19936 ----------------------------------------
19942 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19943 display them, and < 0 means obey the current buffer's value of
19944 enable_multibyte_characters.
19946 Value is the number of columns displayed. */
19949 display_string (const unsigned char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
19950 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
19951 int field_width
, int precision
, int max_x
, int multibyte
)
19953 int hpos_at_start
= it
->hpos
;
19954 int saved_face_id
= it
->face_id
;
19955 struct glyph_row
*row
= it
->glyph_row
;
19957 /* Initialize the iterator IT for iteration over STRING beginning
19958 with index START. */
19959 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19960 precision
, field_width
, multibyte
);
19961 if (string
&& STRINGP (lisp_string
))
19962 /* LISP_STRING is the one returned by decode_mode_spec. We should
19963 ignore its text properties. */
19964 it
->stop_charpos
= -1;
19966 /* If displaying STRING, set up the face of the iterator
19967 from LISP_STRING, if that's given. */
19968 if (STRINGP (face_string
))
19974 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19975 0, it
->region_beg_charpos
,
19976 it
->region_end_charpos
,
19977 &endptr
, it
->base_face_id
, 0);
19978 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19979 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19982 /* Set max_x to the maximum allowed X position. Don't let it go
19983 beyond the right edge of the window. */
19985 max_x
= it
->last_visible_x
;
19987 max_x
= min (max_x
, it
->last_visible_x
);
19989 /* Skip over display elements that are not visible. because IT->w is
19991 if (it
->current_x
< it
->first_visible_x
)
19992 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
19993 MOVE_TO_POS
| MOVE_TO_X
);
19995 row
->ascent
= it
->max_ascent
;
19996 row
->height
= it
->max_ascent
+ it
->max_descent
;
19997 row
->phys_ascent
= it
->max_phys_ascent
;
19998 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19999 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20001 /* This condition is for the case that we are called with current_x
20002 past last_visible_x. */
20003 while (it
->current_x
< max_x
)
20005 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20007 /* Get the next display element. */
20008 if (!get_next_display_element (it
))
20011 /* Produce glyphs. */
20012 x_before
= it
->current_x
;
20013 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20014 PRODUCE_GLYPHS (it
);
20016 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
20019 while (i
< nglyphs
)
20021 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20023 if (it
->line_wrap
!= TRUNCATE
20024 && x
+ glyph
->pixel_width
> max_x
)
20026 /* End of continued line or max_x reached. */
20027 if (CHAR_GLYPH_PADDING_P (*glyph
))
20029 /* A wide character is unbreakable. */
20030 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
20031 it
->current_x
= x_before
;
20035 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20040 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20042 /* Glyph is at least partially visible. */
20044 if (x
< it
->first_visible_x
)
20045 it
->glyph_row
->x
= x
- it
->first_visible_x
;
20049 /* Glyph is off the left margin of the display area.
20050 Should not happen. */
20054 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20055 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20056 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20057 row
->phys_height
= max (row
->phys_height
,
20058 it
->max_phys_ascent
+ it
->max_phys_descent
);
20059 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20060 it
->max_extra_line_spacing
);
20061 x
+= glyph
->pixel_width
;
20065 /* Stop if max_x reached. */
20069 /* Stop at line ends. */
20070 if (ITERATOR_AT_END_OF_LINE_P (it
))
20072 it
->continuation_lines_width
= 0;
20076 set_iterator_to_next (it
, 1);
20078 /* Stop if truncating at the right edge. */
20079 if (it
->line_wrap
== TRUNCATE
20080 && it
->current_x
>= it
->last_visible_x
)
20082 /* Add truncation mark, but don't do it if the line is
20083 truncated at a padding space. */
20084 if (IT_CHARPOS (*it
) < it
->string_nchars
)
20086 if (!FRAME_WINDOW_P (it
->f
))
20090 if (it
->current_x
> it
->last_visible_x
)
20092 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20093 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20095 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20097 row
->used
[TEXT_AREA
] = i
;
20098 produce_special_glyphs (it
, IT_TRUNCATION
);
20101 produce_special_glyphs (it
, IT_TRUNCATION
);
20103 it
->glyph_row
->truncated_on_right_p
= 1;
20109 /* Maybe insert a truncation at the left. */
20110 if (it
->first_visible_x
20111 && IT_CHARPOS (*it
) > 0)
20113 if (!FRAME_WINDOW_P (it
->f
))
20114 insert_left_trunc_glyphs (it
);
20115 it
->glyph_row
->truncated_on_left_p
= 1;
20118 it
->face_id
= saved_face_id
;
20120 /* Value is number of columns displayed. */
20121 return it
->hpos
- hpos_at_start
;
20126 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20127 appears as an element of LIST or as the car of an element of LIST.
20128 If PROPVAL is a list, compare each element against LIST in that
20129 way, and return 1/2 if any element of PROPVAL is found in LIST.
20130 Otherwise return 0. This function cannot quit.
20131 The return value is 2 if the text is invisible but with an ellipsis
20132 and 1 if it's invisible and without an ellipsis. */
20135 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20137 register Lisp_Object tail
, proptail
;
20139 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20141 register Lisp_Object tem
;
20143 if (EQ (propval
, tem
))
20145 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20146 return NILP (XCDR (tem
)) ? 1 : 2;
20149 if (CONSP (propval
))
20151 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20153 Lisp_Object propelt
;
20154 propelt
= XCAR (proptail
);
20155 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20157 register Lisp_Object tem
;
20159 if (EQ (propelt
, tem
))
20161 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20162 return NILP (XCDR (tem
)) ? 1 : 2;
20170 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20171 doc
: /* Non-nil if the property makes the text invisible.
20172 POS-OR-PROP can be a marker or number, in which case it is taken to be
20173 a position in the current buffer and the value of the `invisible' property
20174 is checked; or it can be some other value, which is then presumed to be the
20175 value of the `invisible' property of the text of interest.
20176 The non-nil value returned can be t for truly invisible text or something
20177 else if the text is replaced by an ellipsis. */)
20178 (Lisp_Object pos_or_prop
)
20181 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20182 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20184 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20185 return (invis
== 0 ? Qnil
20187 : make_number (invis
));
20190 /* Calculate a width or height in pixels from a specification using
20191 the following elements:
20194 NUM - a (fractional) multiple of the default font width/height
20195 (NUM) - specifies exactly NUM pixels
20196 UNIT - a fixed number of pixels, see below.
20197 ELEMENT - size of a display element in pixels, see below.
20198 (NUM . SPEC) - equals NUM * SPEC
20199 (+ SPEC SPEC ...) - add pixel values
20200 (- SPEC SPEC ...) - subtract pixel values
20201 (- SPEC) - negate pixel value
20204 INT or FLOAT - a number constant
20205 SYMBOL - use symbol's (buffer local) variable binding.
20208 in - pixels per inch *)
20209 mm - pixels per 1/1000 meter *)
20210 cm - pixels per 1/100 meter *)
20211 width - width of current font in pixels.
20212 height - height of current font in pixels.
20214 *) using the ratio(s) defined in display-pixels-per-inch.
20218 left-fringe - left fringe width in pixels
20219 right-fringe - right fringe width in pixels
20221 left-margin - left margin width in pixels
20222 right-margin - right margin width in pixels
20224 scroll-bar - scroll-bar area width in pixels
20228 Pixels corresponding to 5 inches:
20231 Total width of non-text areas on left side of window (if scroll-bar is on left):
20232 '(space :width (+ left-fringe left-margin scroll-bar))
20234 Align to first text column (in header line):
20235 '(space :align-to 0)
20237 Align to middle of text area minus half the width of variable `my-image'
20238 containing a loaded image:
20239 '(space :align-to (0.5 . (- text my-image)))
20241 Width of left margin minus width of 1 character in the default font:
20242 '(space :width (- left-margin 1))
20244 Width of left margin minus width of 2 characters in the current font:
20245 '(space :width (- left-margin (2 . width)))
20247 Center 1 character over left-margin (in header line):
20248 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20250 Different ways to express width of left fringe plus left margin minus one pixel:
20251 '(space :width (- (+ left-fringe left-margin) (1)))
20252 '(space :width (+ left-fringe left-margin (- (1))))
20253 '(space :width (+ left-fringe left-margin (-1)))
20257 #define NUMVAL(X) \
20258 ((INTEGERP (X) || FLOATP (X)) \
20263 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20264 struct font
*font
, int width_p
, int *align_to
)
20268 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20269 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20272 return OK_PIXELS (0);
20274 xassert (FRAME_LIVE_P (it
->f
));
20276 if (SYMBOLP (prop
))
20278 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20280 char *unit
= SDATA (SYMBOL_NAME (prop
));
20282 if (unit
[0] == 'i' && unit
[1] == 'n')
20284 else if (unit
[0] == 'm' && unit
[1] == 'm')
20286 else if (unit
[0] == 'c' && unit
[1] == 'm')
20293 #ifdef HAVE_WINDOW_SYSTEM
20294 if (FRAME_WINDOW_P (it
->f
)
20296 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20297 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20299 return OK_PIXELS (ppi
/ pixels
);
20302 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20303 || (CONSP (Vdisplay_pixels_per_inch
)
20305 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20306 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20308 return OK_PIXELS (ppi
/ pixels
);
20314 #ifdef HAVE_WINDOW_SYSTEM
20315 if (EQ (prop
, Qheight
))
20316 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20317 if (EQ (prop
, Qwidth
))
20318 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20320 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20321 return OK_PIXELS (1);
20324 if (EQ (prop
, Qtext
))
20325 return OK_PIXELS (width_p
20326 ? window_box_width (it
->w
, TEXT_AREA
)
20327 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20329 if (align_to
&& *align_to
< 0)
20332 if (EQ (prop
, Qleft
))
20333 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20334 if (EQ (prop
, Qright
))
20335 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20336 if (EQ (prop
, Qcenter
))
20337 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20338 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20339 if (EQ (prop
, Qleft_fringe
))
20340 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20341 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20342 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20343 if (EQ (prop
, Qright_fringe
))
20344 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20345 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20346 : window_box_right_offset (it
->w
, TEXT_AREA
));
20347 if (EQ (prop
, Qleft_margin
))
20348 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20349 if (EQ (prop
, Qright_margin
))
20350 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20351 if (EQ (prop
, Qscroll_bar
))
20352 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20354 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20355 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20356 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20361 if (EQ (prop
, Qleft_fringe
))
20362 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20363 if (EQ (prop
, Qright_fringe
))
20364 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20365 if (EQ (prop
, Qleft_margin
))
20366 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20367 if (EQ (prop
, Qright_margin
))
20368 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20369 if (EQ (prop
, Qscroll_bar
))
20370 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20373 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20376 if (INTEGERP (prop
) || FLOATP (prop
))
20378 int base_unit
= (width_p
20379 ? FRAME_COLUMN_WIDTH (it
->f
)
20380 : FRAME_LINE_HEIGHT (it
->f
));
20381 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20386 Lisp_Object car
= XCAR (prop
);
20387 Lisp_Object cdr
= XCDR (prop
);
20391 #ifdef HAVE_WINDOW_SYSTEM
20392 if (FRAME_WINDOW_P (it
->f
)
20393 && valid_image_p (prop
))
20395 int id
= lookup_image (it
->f
, prop
);
20396 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20398 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20401 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20407 while (CONSP (cdr
))
20409 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20410 font
, width_p
, align_to
))
20413 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20418 if (EQ (car
, Qminus
))
20420 return OK_PIXELS (pixels
);
20423 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20426 if (INTEGERP (car
) || FLOATP (car
))
20429 pixels
= XFLOATINT (car
);
20431 return OK_PIXELS (pixels
);
20432 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20433 font
, width_p
, align_to
))
20434 return OK_PIXELS (pixels
* fact
);
20445 /***********************************************************************
20447 ***********************************************************************/
20449 #ifdef HAVE_WINDOW_SYSTEM
20454 dump_glyph_string (s
)
20455 struct glyph_string
*s
;
20457 fprintf (stderr
, "glyph string\n");
20458 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20459 s
->x
, s
->y
, s
->width
, s
->height
);
20460 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20461 fprintf (stderr
, " hl = %d\n", s
->hl
);
20462 fprintf (stderr
, " left overhang = %d, right = %d\n",
20463 s
->left_overhang
, s
->right_overhang
);
20464 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20465 fprintf (stderr
, " extends to end of line = %d\n",
20466 s
->extends_to_end_of_line_p
);
20467 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20468 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20471 #endif /* GLYPH_DEBUG */
20473 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20474 of XChar2b structures for S; it can't be allocated in
20475 init_glyph_string because it must be allocated via `alloca'. W
20476 is the window on which S is drawn. ROW and AREA are the glyph row
20477 and area within the row from which S is constructed. START is the
20478 index of the first glyph structure covered by S. HL is a
20479 face-override for drawing S. */
20482 #define OPTIONAL_HDC(hdc) HDC hdc,
20483 #define DECLARE_HDC(hdc) HDC hdc;
20484 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20485 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20488 #ifndef OPTIONAL_HDC
20489 #define OPTIONAL_HDC(hdc)
20490 #define DECLARE_HDC(hdc)
20491 #define ALLOCATE_HDC(hdc, f)
20492 #define RELEASE_HDC(hdc, f)
20496 init_glyph_string (struct glyph_string
*s
,
20498 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
20499 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
20501 memset (s
, 0, sizeof *s
);
20503 s
->f
= XFRAME (w
->frame
);
20507 s
->display
= FRAME_X_DISPLAY (s
->f
);
20508 s
->window
= FRAME_X_WINDOW (s
->f
);
20509 s
->char2b
= char2b
;
20513 s
->first_glyph
= row
->glyphs
[area
] + start
;
20514 s
->height
= row
->height
;
20515 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20516 s
->ybase
= s
->y
+ row
->ascent
;
20520 /* Append the list of glyph strings with head H and tail T to the list
20521 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20524 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20525 struct glyph_string
*h
, struct glyph_string
*t
)
20539 /* Prepend the list of glyph strings with head H and tail T to the
20540 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20544 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20545 struct glyph_string
*h
, struct glyph_string
*t
)
20559 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20560 Set *HEAD and *TAIL to the resulting list. */
20563 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
20564 struct glyph_string
*s
)
20566 s
->next
= s
->prev
= NULL
;
20567 append_glyph_string_lists (head
, tail
, s
, s
);
20571 /* Get face and two-byte form of character C in face FACE_ID on frame
20572 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
20573 means we want to display multibyte text. DISPLAY_P non-zero means
20574 make sure that X resources for the face returned are allocated.
20575 Value is a pointer to a realized face that is ready for display if
20576 DISPLAY_P is non-zero. */
20578 static INLINE
struct face
*
20579 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
20580 XChar2b
*char2b
, int multibyte_p
, int display_p
)
20582 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20586 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20588 if (code
!= FONT_INVALID_CODE
)
20589 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20591 STORE_XCHAR2B (char2b
, 0, 0);
20594 /* Make sure X resources of the face are allocated. */
20595 #ifdef HAVE_X_WINDOWS
20599 xassert (face
!= NULL
);
20600 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20607 /* Get face and two-byte form of character glyph GLYPH on frame F.
20608 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20609 a pointer to a realized face that is ready for display. */
20611 static INLINE
struct face
*
20612 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
20613 XChar2b
*char2b
, int *two_byte_p
)
20617 xassert (glyph
->type
== CHAR_GLYPH
);
20618 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20627 if (CHAR_BYTE8_P (glyph
->u
.ch
))
20628 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
20630 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20632 if (code
!= FONT_INVALID_CODE
)
20633 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20635 STORE_XCHAR2B (char2b
, 0, 0);
20638 /* Make sure X resources of the face are allocated. */
20639 xassert (face
!= NULL
);
20640 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20645 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
20646 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
20649 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
20653 if (CHAR_BYTE8_P (c
))
20654 code
= CHAR_TO_BYTE8 (c
);
20656 code
= font
->driver
->encode_char (font
, c
);
20658 if (code
== FONT_INVALID_CODE
)
20660 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20665 /* Fill glyph string S with composition components specified by S->cmp.
20667 BASE_FACE is the base face of the composition.
20668 S->cmp_from is the index of the first component for S.
20670 OVERLAPS non-zero means S should draw the foreground only, and use
20671 its physical height for clipping. See also draw_glyphs.
20673 Value is the index of a component not in S. */
20676 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
20680 /* For all glyphs of this composition, starting at the offset
20681 S->cmp_from, until we reach the end of the definition or encounter a
20682 glyph that requires the different face, add it to S. */
20687 s
->for_overlaps
= overlaps
;
20690 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20692 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20696 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20699 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20700 s
->char2b
+ i
, 1, 1);
20706 s
->font
= s
->face
->font
;
20708 else if (s
->face
!= face
)
20716 /* All glyph strings for the same composition has the same width,
20717 i.e. the width set for the first component of the composition. */
20718 s
->width
= s
->first_glyph
->pixel_width
;
20720 /* If the specified font could not be loaded, use the frame's
20721 default font, but record the fact that we couldn't load it in
20722 the glyph string so that we can draw rectangles for the
20723 characters of the glyph string. */
20724 if (s
->font
== NULL
)
20726 s
->font_not_found_p
= 1;
20727 s
->font
= FRAME_FONT (s
->f
);
20730 /* Adjust base line for subscript/superscript text. */
20731 s
->ybase
+= s
->first_glyph
->voffset
;
20733 /* This glyph string must always be drawn with 16-bit functions. */
20740 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
20741 int start
, int end
, int overlaps
)
20743 struct glyph
*glyph
, *last
;
20744 Lisp_Object lgstring
;
20747 s
->for_overlaps
= overlaps
;
20748 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20749 last
= s
->row
->glyphs
[s
->area
] + end
;
20750 s
->cmp_id
= glyph
->u
.cmp
.id
;
20751 s
->cmp_from
= glyph
->slice
.cmp
.from
;
20752 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
20753 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20754 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20755 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20757 while (glyph
< last
20758 && glyph
->u
.cmp
.automatic
20759 && glyph
->u
.cmp
.id
== s
->cmp_id
20760 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
20761 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
20763 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20765 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20766 unsigned code
= LGLYPH_CODE (lglyph
);
20768 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20770 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20771 return glyph
- s
->row
->glyphs
[s
->area
];
20775 /* Fill glyph string S from a sequence glyphs for glyphless characters.
20776 See the comment of fill_glyph_string for arguments.
20777 Value is the index of the first glyph not in S. */
20781 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
20782 int start
, int end
, int overlaps
)
20784 struct glyph
*glyph
, *last
;
20787 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
20788 s
->for_overlaps
= overlaps
;
20789 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20790 last
= s
->row
->glyphs
[s
->area
] + end
;
20791 voffset
= glyph
->voffset
;
20792 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20793 s
->font
= s
->face
->font
;
20795 s
->width
= glyph
->pixel_width
;
20797 while (glyph
< last
20798 && glyph
->type
== GLYPHLESS_GLYPH
20799 && glyph
->voffset
== voffset
20800 && glyph
->face_id
== face_id
)
20803 s
->width
+= glyph
->pixel_width
;
20806 s
->ybase
+= voffset
;
20807 return glyph
- s
->row
->glyphs
[s
->area
];
20811 /* Fill glyph string S from a sequence of character glyphs.
20813 FACE_ID is the face id of the string. START is the index of the
20814 first glyph to consider, END is the index of the last + 1.
20815 OVERLAPS non-zero means S should draw the foreground only, and use
20816 its physical height for clipping. See also draw_glyphs.
20818 Value is the index of the first glyph not in S. */
20821 fill_glyph_string (struct glyph_string
*s
, int face_id
,
20822 int start
, int end
, int overlaps
)
20824 struct glyph
*glyph
, *last
;
20826 int glyph_not_available_p
;
20828 xassert (s
->f
== XFRAME (s
->w
->frame
));
20829 xassert (s
->nchars
== 0);
20830 xassert (start
>= 0 && end
> start
);
20832 s
->for_overlaps
= overlaps
;
20833 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20834 last
= s
->row
->glyphs
[s
->area
] + end
;
20835 voffset
= glyph
->voffset
;
20836 s
->padding_p
= glyph
->padding_p
;
20837 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20839 while (glyph
< last
20840 && glyph
->type
== CHAR_GLYPH
20841 && glyph
->voffset
== voffset
20842 /* Same face id implies same font, nowadays. */
20843 && glyph
->face_id
== face_id
20844 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20848 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20849 s
->char2b
+ s
->nchars
,
20851 s
->two_byte_p
= two_byte_p
;
20853 xassert (s
->nchars
<= end
- start
);
20854 s
->width
+= glyph
->pixel_width
;
20855 if (glyph
++->padding_p
!= s
->padding_p
)
20859 s
->font
= s
->face
->font
;
20861 /* If the specified font could not be loaded, use the frame's font,
20862 but record the fact that we couldn't load it in
20863 S->font_not_found_p so that we can draw rectangles for the
20864 characters of the glyph string. */
20865 if (s
->font
== NULL
|| glyph_not_available_p
)
20867 s
->font_not_found_p
= 1;
20868 s
->font
= FRAME_FONT (s
->f
);
20871 /* Adjust base line for subscript/superscript text. */
20872 s
->ybase
+= voffset
;
20874 xassert (s
->face
&& s
->face
->gc
);
20875 return glyph
- s
->row
->glyphs
[s
->area
];
20879 /* Fill glyph string S from image glyph S->first_glyph. */
20882 fill_image_glyph_string (struct glyph_string
*s
)
20884 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20885 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20887 s
->slice
= s
->first_glyph
->slice
.img
;
20888 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20889 s
->font
= s
->face
->font
;
20890 s
->width
= s
->first_glyph
->pixel_width
;
20892 /* Adjust base line for subscript/superscript text. */
20893 s
->ybase
+= s
->first_glyph
->voffset
;
20897 /* Fill glyph string S from a sequence of stretch glyphs.
20899 ROW is the glyph row in which the glyphs are found, AREA is the
20900 area within the row. START is the index of the first glyph to
20901 consider, END is the index of the last + 1.
20903 Value is the index of the first glyph not in S. */
20906 fill_stretch_glyph_string (struct glyph_string
*s
, struct glyph_row
*row
,
20907 enum glyph_row_area area
, int start
, int end
)
20909 struct glyph
*glyph
, *last
;
20910 int voffset
, face_id
;
20912 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20914 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20915 last
= s
->row
->glyphs
[s
->area
] + end
;
20916 face_id
= glyph
->face_id
;
20917 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20918 s
->font
= s
->face
->font
;
20919 s
->width
= glyph
->pixel_width
;
20921 voffset
= glyph
->voffset
;
20925 && glyph
->type
== STRETCH_GLYPH
20926 && glyph
->voffset
== voffset
20927 && glyph
->face_id
== face_id
);
20929 s
->width
+= glyph
->pixel_width
;
20931 /* Adjust base line for subscript/superscript text. */
20932 s
->ybase
+= voffset
;
20934 /* The case that face->gc == 0 is handled when drawing the glyph
20935 string by calling PREPARE_FACE_FOR_DISPLAY. */
20937 return glyph
- s
->row
->glyphs
[s
->area
];
20940 static struct font_metrics
*
20941 get_per_char_metric (struct frame
*f
, struct font
*font
, XChar2b
*char2b
)
20943 static struct font_metrics metrics
;
20944 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20946 if (! font
|| code
== FONT_INVALID_CODE
)
20948 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20953 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20954 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20955 assumed to be zero. */
20958 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
20960 *left
= *right
= 0;
20962 if (glyph
->type
== CHAR_GLYPH
)
20966 struct font_metrics
*pcm
;
20968 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20969 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20971 if (pcm
->rbearing
> pcm
->width
)
20972 *right
= pcm
->rbearing
- pcm
->width
;
20973 if (pcm
->lbearing
< 0)
20974 *left
= -pcm
->lbearing
;
20977 else if (glyph
->type
== COMPOSITE_GLYPH
)
20979 if (! glyph
->u
.cmp
.automatic
)
20981 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20983 if (cmp
->rbearing
> cmp
->pixel_width
)
20984 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20985 if (cmp
->lbearing
< 0)
20986 *left
= - cmp
->lbearing
;
20990 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
20991 struct font_metrics metrics
;
20993 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
20994 glyph
->slice
.cmp
.to
+ 1, &metrics
);
20995 if (metrics
.rbearing
> metrics
.width
)
20996 *right
= metrics
.rbearing
- metrics
.width
;
20997 if (metrics
.lbearing
< 0)
20998 *left
= - metrics
.lbearing
;
21004 /* Return the index of the first glyph preceding glyph string S that
21005 is overwritten by S because of S's left overhang. Value is -1
21006 if no glyphs are overwritten. */
21009 left_overwritten (struct glyph_string
*s
)
21013 if (s
->left_overhang
)
21016 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21017 int first
= s
->first_glyph
- glyphs
;
21019 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21020 x
-= glyphs
[i
].pixel_width
;
21031 /* Return the index of the first glyph preceding glyph string S that
21032 is overwriting S because of its right overhang. Value is -1 if no
21033 glyph in front of S overwrites S. */
21036 left_overwriting (struct glyph_string
*s
)
21039 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21040 int first
= s
->first_glyph
- glyphs
;
21044 for (i
= first
- 1; i
>= 0; --i
)
21047 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21050 x
-= glyphs
[i
].pixel_width
;
21057 /* Return the index of the last glyph following glyph string S that is
21058 overwritten by S because of S's right overhang. Value is -1 if
21059 no such glyph is found. */
21062 right_overwritten (struct glyph_string
*s
)
21066 if (s
->right_overhang
)
21069 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21070 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21071 int end
= s
->row
->used
[s
->area
];
21073 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21074 x
+= glyphs
[i
].pixel_width
;
21083 /* Return the index of the last glyph following glyph string S that
21084 overwrites S because of its left overhang. Value is negative
21085 if no such glyph is found. */
21088 right_overwriting (struct glyph_string
*s
)
21091 int end
= s
->row
->used
[s
->area
];
21092 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21093 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21097 for (i
= first
; i
< end
; ++i
)
21100 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21103 x
+= glyphs
[i
].pixel_width
;
21110 /* Set background width of glyph string S. START is the index of the
21111 first glyph following S. LAST_X is the right-most x-position + 1
21112 in the drawing area. */
21115 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21117 /* If the face of this glyph string has to be drawn to the end of
21118 the drawing area, set S->extends_to_end_of_line_p. */
21120 if (start
== s
->row
->used
[s
->area
]
21121 && s
->area
== TEXT_AREA
21122 && ((s
->row
->fill_line_p
21123 && (s
->hl
== DRAW_NORMAL_TEXT
21124 || s
->hl
== DRAW_IMAGE_RAISED
21125 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21126 || s
->hl
== DRAW_MOUSE_FACE
))
21127 s
->extends_to_end_of_line_p
= 1;
21129 /* If S extends its face to the end of the line, set its
21130 background_width to the distance to the right edge of the drawing
21132 if (s
->extends_to_end_of_line_p
)
21133 s
->background_width
= last_x
- s
->x
+ 1;
21135 s
->background_width
= s
->width
;
21139 /* Compute overhangs and x-positions for glyph string S and its
21140 predecessors, or successors. X is the starting x-position for S.
21141 BACKWARD_P non-zero means process predecessors. */
21144 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21150 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21151 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21161 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21162 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21172 /* The following macros are only called from draw_glyphs below.
21173 They reference the following parameters of that function directly:
21174 `w', `row', `area', and `overlap_p'
21175 as well as the following local variables:
21176 `s', `f', and `hdc' (in W32) */
21179 /* On W32, silently add local `hdc' variable to argument list of
21180 init_glyph_string. */
21181 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21182 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21184 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21185 init_glyph_string (s, char2b, w, row, area, start, hl)
21188 /* Add a glyph string for a stretch glyph to the list of strings
21189 between HEAD and TAIL. START is the index of the stretch glyph in
21190 row area AREA of glyph row ROW. END is the index of the last glyph
21191 in that glyph row area. X is the current output position assigned
21192 to the new glyph string constructed. HL overrides that face of the
21193 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21194 is the right-most x-position of the drawing area. */
21196 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21197 and below -- keep them on one line. */
21198 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21201 s = (struct glyph_string *) alloca (sizeof *s); \
21202 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21203 START = fill_stretch_glyph_string (s, row, area, START, END); \
21204 append_glyph_string (&HEAD, &TAIL, s); \
21210 /* Add a glyph string for an image glyph to the list of strings
21211 between HEAD and TAIL. START is the index of the image glyph in
21212 row area AREA of glyph row ROW. END is the index of the last glyph
21213 in that glyph row area. X is the current output position assigned
21214 to the new glyph string constructed. HL overrides that face of the
21215 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21216 is the right-most x-position of the drawing area. */
21218 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21221 s = (struct glyph_string *) alloca (sizeof *s); \
21222 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21223 fill_image_glyph_string (s); \
21224 append_glyph_string (&HEAD, &TAIL, s); \
21231 /* Add a glyph string for a sequence of character glyphs to the list
21232 of strings between HEAD and TAIL. START is the index of the first
21233 glyph in row area AREA of glyph row ROW that is part of the new
21234 glyph string. END is the index of the last glyph in that glyph row
21235 area. X is the current output position assigned to the new glyph
21236 string constructed. HL overrides that face of the glyph; e.g. it
21237 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21238 right-most x-position of the drawing area. */
21240 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21246 face_id = (row)->glyphs[area][START].face_id; \
21248 s = (struct glyph_string *) alloca (sizeof *s); \
21249 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21250 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21251 append_glyph_string (&HEAD, &TAIL, s); \
21253 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21258 /* Add a glyph string for a composite sequence to the list of strings
21259 between HEAD and TAIL. START is the index of the first glyph in
21260 row area AREA of glyph row ROW that is part of the new glyph
21261 string. END is the index of the last glyph in that glyph row area.
21262 X is the current output position assigned to the new glyph string
21263 constructed. HL overrides that face of the glyph; e.g. it is
21264 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21265 x-position of the drawing area. */
21267 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21269 int face_id = (row)->glyphs[area][START].face_id; \
21270 struct face *base_face = FACE_FROM_ID (f, face_id); \
21271 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21272 struct composition *cmp = composition_table[cmp_id]; \
21274 struct glyph_string *first_s; \
21277 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21279 /* Make glyph_strings for each glyph sequence that is drawable by \
21280 the same face, and append them to HEAD/TAIL. */ \
21281 for (n = 0; n < cmp->glyph_len;) \
21283 s = (struct glyph_string *) alloca (sizeof *s); \
21284 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21285 append_glyph_string (&(HEAD), &(TAIL), s); \
21291 n = fill_composite_glyph_string (s, base_face, overlaps); \
21299 /* Add a glyph string for a glyph-string sequence to the list of strings
21300 between HEAD and TAIL. */
21302 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21306 Lisp_Object gstring; \
21308 face_id = (row)->glyphs[area][START].face_id; \
21309 gstring = (composition_gstring_from_id \
21310 ((row)->glyphs[area][START].u.cmp.id)); \
21311 s = (struct glyph_string *) alloca (sizeof *s); \
21312 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21313 * LGSTRING_GLYPH_LEN (gstring)); \
21314 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21315 append_glyph_string (&(HEAD), &(TAIL), s); \
21317 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21321 /* Add a glyph string for a sequence of glyphless character's glyphs
21322 to the list of strings between HEAD and TAIL. The meanings of
21323 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21325 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21331 face_id = (row)->glyphs[area][START].face_id; \
21333 s = (struct glyph_string *) alloca (sizeof *s); \
21334 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21335 append_glyph_string (&HEAD, &TAIL, s); \
21337 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21343 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21344 of AREA of glyph row ROW on window W between indices START and END.
21345 HL overrides the face for drawing glyph strings, e.g. it is
21346 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21347 x-positions of the drawing area.
21349 This is an ugly monster macro construct because we must use alloca
21350 to allocate glyph strings (because draw_glyphs can be called
21351 asynchronously). */
21353 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21356 HEAD = TAIL = NULL; \
21357 while (START < END) \
21359 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21360 switch (first_glyph->type) \
21363 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21367 case COMPOSITE_GLYPH: \
21368 if (first_glyph->u.cmp.automatic) \
21369 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21372 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21376 case STRETCH_GLYPH: \
21377 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21381 case IMAGE_GLYPH: \
21382 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21386 case GLYPHLESS_GLYPH: \
21387 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
21397 set_glyph_string_background_width (s, START, LAST_X); \
21404 /* Draw glyphs between START and END in AREA of ROW on window W,
21405 starting at x-position X. X is relative to AREA in W. HL is a
21406 face-override with the following meaning:
21408 DRAW_NORMAL_TEXT draw normally
21409 DRAW_CURSOR draw in cursor face
21410 DRAW_MOUSE_FACE draw in mouse face.
21411 DRAW_INVERSE_VIDEO draw in mode line face
21412 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21413 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21415 If OVERLAPS is non-zero, draw only the foreground of characters and
21416 clip to the physical height of ROW. Non-zero value also defines
21417 the overlapping part to be drawn:
21419 OVERLAPS_PRED overlap with preceding rows
21420 OVERLAPS_SUCC overlap with succeeding rows
21421 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21422 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21424 Value is the x-position reached, relative to AREA of W. */
21427 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
21428 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
21429 enum draw_glyphs_face hl
, int overlaps
)
21431 struct glyph_string
*head
, *tail
;
21432 struct glyph_string
*s
;
21433 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21434 int i
, j
, x_reached
, last_x
, area_left
= 0;
21435 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21438 ALLOCATE_HDC (hdc
, f
);
21440 /* Let's rather be paranoid than getting a SEGV. */
21441 end
= min (end
, row
->used
[area
]);
21442 start
= max (0, start
);
21443 start
= min (end
, start
);
21445 /* Translate X to frame coordinates. Set last_x to the right
21446 end of the drawing area. */
21447 if (row
->full_width_p
)
21449 /* X is relative to the left edge of W, without scroll bars
21451 area_left
= WINDOW_LEFT_EDGE_X (w
);
21452 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21456 area_left
= window_box_left (w
, area
);
21457 last_x
= area_left
+ window_box_width (w
, area
);
21461 /* Build a doubly-linked list of glyph_string structures between
21462 head and tail from what we have to draw. Note that the macro
21463 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21464 the reason we use a separate variable `i'. */
21466 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21468 x_reached
= tail
->x
+ tail
->background_width
;
21472 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21473 the row, redraw some glyphs in front or following the glyph
21474 strings built above. */
21475 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21477 struct glyph_string
*h
, *t
;
21478 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
21479 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
21482 /* If mouse highlighting is on, we may need to draw adjacent
21483 glyphs using mouse-face highlighting. */
21484 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21486 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21488 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
21489 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
21491 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21493 check_mouse_face
= 1;
21494 mouse_beg_col
= (row
== mouse_beg_row
)
21495 ? hlinfo
->mouse_face_beg_col
: 0;
21496 mouse_end_col
= (row
== mouse_end_row
)
21497 ? hlinfo
->mouse_face_end_col
21498 : row
->used
[TEXT_AREA
];
21502 /* Compute overhangs for all glyph strings. */
21503 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21504 for (s
= head
; s
; s
= s
->next
)
21505 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21507 /* Prepend glyph strings for glyphs in front of the first glyph
21508 string that are overwritten because of the first glyph
21509 string's left overhang. The background of all strings
21510 prepended must be drawn because the first glyph string
21512 i
= left_overwritten (head
);
21515 enum draw_glyphs_face overlap_hl
;
21517 /* If this row contains mouse highlighting, attempt to draw
21518 the overlapped glyphs with the correct highlight. This
21519 code fails if the overlap encompasses more than one glyph
21520 and mouse-highlight spans only some of these glyphs.
21521 However, making it work perfectly involves a lot more
21522 code, and I don't know if the pathological case occurs in
21523 practice, so we'll stick to this for now. --- cyd */
21524 if (check_mouse_face
21525 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21526 overlap_hl
= DRAW_MOUSE_FACE
;
21528 overlap_hl
= DRAW_NORMAL_TEXT
;
21531 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21532 overlap_hl
, dummy_x
, last_x
);
21534 compute_overhangs_and_x (t
, head
->x
, 1);
21535 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21539 /* Prepend glyph strings for glyphs in front of the first glyph
21540 string that overwrite that glyph string because of their
21541 right overhang. For these strings, only the foreground must
21542 be drawn, because it draws over the glyph string at `head'.
21543 The background must not be drawn because this would overwrite
21544 right overhangs of preceding glyphs for which no glyph
21546 i
= left_overwriting (head
);
21549 enum draw_glyphs_face overlap_hl
;
21551 if (check_mouse_face
21552 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21553 overlap_hl
= DRAW_MOUSE_FACE
;
21555 overlap_hl
= DRAW_NORMAL_TEXT
;
21558 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21559 overlap_hl
, dummy_x
, last_x
);
21560 for (s
= h
; s
; s
= s
->next
)
21561 s
->background_filled_p
= 1;
21562 compute_overhangs_and_x (t
, head
->x
, 1);
21563 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21566 /* Append glyphs strings for glyphs following the last glyph
21567 string tail that are overwritten by tail. The background of
21568 these strings has to be drawn because tail's foreground draws
21570 i
= right_overwritten (tail
);
21573 enum draw_glyphs_face overlap_hl
;
21575 if (check_mouse_face
21576 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21577 overlap_hl
= DRAW_MOUSE_FACE
;
21579 overlap_hl
= DRAW_NORMAL_TEXT
;
21581 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21582 overlap_hl
, x
, last_x
);
21583 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21584 we don't have `end = i;' here. */
21585 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21586 append_glyph_string_lists (&head
, &tail
, h
, t
);
21590 /* Append glyph strings for glyphs following the last glyph
21591 string tail that overwrite tail. The foreground of such
21592 glyphs has to be drawn because it writes into the background
21593 of tail. The background must not be drawn because it could
21594 paint over the foreground of following glyphs. */
21595 i
= right_overwriting (tail
);
21598 enum draw_glyphs_face overlap_hl
;
21599 if (check_mouse_face
21600 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21601 overlap_hl
= DRAW_MOUSE_FACE
;
21603 overlap_hl
= DRAW_NORMAL_TEXT
;
21606 i
++; /* We must include the Ith glyph. */
21607 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21608 overlap_hl
, x
, last_x
);
21609 for (s
= h
; s
; s
= s
->next
)
21610 s
->background_filled_p
= 1;
21611 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21612 append_glyph_string_lists (&head
, &tail
, h
, t
);
21614 if (clip_head
|| clip_tail
)
21615 for (s
= head
; s
; s
= s
->next
)
21617 s
->clip_head
= clip_head
;
21618 s
->clip_tail
= clip_tail
;
21622 /* Draw all strings. */
21623 for (s
= head
; s
; s
= s
->next
)
21624 FRAME_RIF (f
)->draw_glyph_string (s
);
21627 /* When focus a sole frame and move horizontally, this sets on_p to 0
21628 causing a failure to erase prev cursor position. */
21629 if (area
== TEXT_AREA
21630 && !row
->full_width_p
21631 /* When drawing overlapping rows, only the glyph strings'
21632 foreground is drawn, which doesn't erase a cursor
21636 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21637 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21638 : (tail
? tail
->x
+ tail
->background_width
: x
));
21642 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21643 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21647 /* Value is the x-position up to which drawn, relative to AREA of W.
21648 This doesn't include parts drawn because of overhangs. */
21649 if (row
->full_width_p
)
21650 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21652 x_reached
-= area_left
;
21654 RELEASE_HDC (hdc
, f
);
21659 /* Expand row matrix if too narrow. Don't expand if area
21662 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21664 if (!fonts_changed_p \
21665 && (it->glyph_row->glyphs[area] \
21666 < it->glyph_row->glyphs[area + 1])) \
21668 it->w->ncols_scale_factor++; \
21669 fonts_changed_p = 1; \
21673 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21674 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21677 append_glyph (struct it
*it
)
21679 struct glyph
*glyph
;
21680 enum glyph_row_area area
= it
->area
;
21682 xassert (it
->glyph_row
);
21683 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21685 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21686 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21688 /* If the glyph row is reversed, we need to prepend the glyph
21689 rather than append it. */
21690 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21694 /* Make room for the additional glyph. */
21695 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21697 glyph
= it
->glyph_row
->glyphs
[area
];
21699 glyph
->charpos
= CHARPOS (it
->position
);
21700 glyph
->object
= it
->object
;
21701 if (it
->pixel_width
> 0)
21703 glyph
->pixel_width
= it
->pixel_width
;
21704 glyph
->padding_p
= 0;
21708 /* Assure at least 1-pixel width. Otherwise, cursor can't
21709 be displayed correctly. */
21710 glyph
->pixel_width
= 1;
21711 glyph
->padding_p
= 1;
21713 glyph
->ascent
= it
->ascent
;
21714 glyph
->descent
= it
->descent
;
21715 glyph
->voffset
= it
->voffset
;
21716 glyph
->type
= CHAR_GLYPH
;
21717 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21718 glyph
->multibyte_p
= it
->multibyte_p
;
21719 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21720 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21721 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21722 || it
->phys_descent
> it
->descent
);
21723 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21724 glyph
->face_id
= it
->face_id
;
21725 glyph
->u
.ch
= it
->char_to_display
;
21726 glyph
->slice
.img
= null_glyph_slice
;
21727 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21730 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21731 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21733 glyph
->bidi_type
= it
->bidi_it
.type
;
21737 glyph
->resolved_level
= 0;
21738 glyph
->bidi_type
= UNKNOWN_BT
;
21740 ++it
->glyph_row
->used
[area
];
21743 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21746 /* Store one glyph for the composition IT->cmp_it.id in
21747 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21751 append_composite_glyph (struct it
*it
)
21753 struct glyph
*glyph
;
21754 enum glyph_row_area area
= it
->area
;
21756 xassert (it
->glyph_row
);
21758 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21759 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21761 /* If the glyph row is reversed, we need to prepend the glyph
21762 rather than append it. */
21763 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
21767 /* Make room for the new glyph. */
21768 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
21770 glyph
= it
->glyph_row
->glyphs
[it
->area
];
21772 glyph
->charpos
= it
->cmp_it
.charpos
;
21773 glyph
->object
= it
->object
;
21774 glyph
->pixel_width
= it
->pixel_width
;
21775 glyph
->ascent
= it
->ascent
;
21776 glyph
->descent
= it
->descent
;
21777 glyph
->voffset
= it
->voffset
;
21778 glyph
->type
= COMPOSITE_GLYPH
;
21779 if (it
->cmp_it
.ch
< 0)
21781 glyph
->u
.cmp
.automatic
= 0;
21782 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21783 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
21787 glyph
->u
.cmp
.automatic
= 1;
21788 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21789 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
21790 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
21792 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21793 glyph
->multibyte_p
= it
->multibyte_p
;
21794 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21795 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21796 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21797 || it
->phys_descent
> it
->descent
);
21798 glyph
->padding_p
= 0;
21799 glyph
->glyph_not_available_p
= 0;
21800 glyph
->face_id
= it
->face_id
;
21801 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21804 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21805 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21807 glyph
->bidi_type
= it
->bidi_it
.type
;
21809 ++it
->glyph_row
->used
[area
];
21812 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21816 /* Change IT->ascent and IT->height according to the setting of
21820 take_vertical_position_into_account (struct it
*it
)
21824 if (it
->voffset
< 0)
21825 /* Increase the ascent so that we can display the text higher
21827 it
->ascent
-= it
->voffset
;
21829 /* Increase the descent so that we can display the text lower
21831 it
->descent
+= it
->voffset
;
21836 /* Produce glyphs/get display metrics for the image IT is loaded with.
21837 See the description of struct display_iterator in dispextern.h for
21838 an overview of struct display_iterator. */
21841 produce_image_glyph (struct it
*it
)
21845 int glyph_ascent
, crop
;
21846 struct glyph_slice slice
;
21848 xassert (it
->what
== IT_IMAGE
);
21850 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21852 /* Make sure X resources of the face is loaded. */
21853 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21855 if (it
->image_id
< 0)
21857 /* Fringe bitmap. */
21858 it
->ascent
= it
->phys_ascent
= 0;
21859 it
->descent
= it
->phys_descent
= 0;
21860 it
->pixel_width
= 0;
21865 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21867 /* Make sure X resources of the image is loaded. */
21868 prepare_image_for_display (it
->f
, img
);
21870 slice
.x
= slice
.y
= 0;
21871 slice
.width
= img
->width
;
21872 slice
.height
= img
->height
;
21874 if (INTEGERP (it
->slice
.x
))
21875 slice
.x
= XINT (it
->slice
.x
);
21876 else if (FLOATP (it
->slice
.x
))
21877 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21879 if (INTEGERP (it
->slice
.y
))
21880 slice
.y
= XINT (it
->slice
.y
);
21881 else if (FLOATP (it
->slice
.y
))
21882 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21884 if (INTEGERP (it
->slice
.width
))
21885 slice
.width
= XINT (it
->slice
.width
);
21886 else if (FLOATP (it
->slice
.width
))
21887 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21889 if (INTEGERP (it
->slice
.height
))
21890 slice
.height
= XINT (it
->slice
.height
);
21891 else if (FLOATP (it
->slice
.height
))
21892 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21894 if (slice
.x
>= img
->width
)
21895 slice
.x
= img
->width
;
21896 if (slice
.y
>= img
->height
)
21897 slice
.y
= img
->height
;
21898 if (slice
.x
+ slice
.width
>= img
->width
)
21899 slice
.width
= img
->width
- slice
.x
;
21900 if (slice
.y
+ slice
.height
> img
->height
)
21901 slice
.height
= img
->height
- slice
.y
;
21903 if (slice
.width
== 0 || slice
.height
== 0)
21906 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21908 it
->descent
= slice
.height
- glyph_ascent
;
21910 it
->descent
+= img
->vmargin
;
21911 if (slice
.y
+ slice
.height
== img
->height
)
21912 it
->descent
+= img
->vmargin
;
21913 it
->phys_descent
= it
->descent
;
21915 it
->pixel_width
= slice
.width
;
21917 it
->pixel_width
+= img
->hmargin
;
21918 if (slice
.x
+ slice
.width
== img
->width
)
21919 it
->pixel_width
+= img
->hmargin
;
21921 /* It's quite possible for images to have an ascent greater than
21922 their height, so don't get confused in that case. */
21923 if (it
->descent
< 0)
21928 if (face
->box
!= FACE_NO_BOX
)
21930 if (face
->box_line_width
> 0)
21933 it
->ascent
+= face
->box_line_width
;
21934 if (slice
.y
+ slice
.height
== img
->height
)
21935 it
->descent
+= face
->box_line_width
;
21938 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21939 it
->pixel_width
+= eabs (face
->box_line_width
);
21940 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21941 it
->pixel_width
+= eabs (face
->box_line_width
);
21944 take_vertical_position_into_account (it
);
21946 /* Automatically crop wide image glyphs at right edge so we can
21947 draw the cursor on same display row. */
21948 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21949 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21951 it
->pixel_width
-= crop
;
21952 slice
.width
-= crop
;
21957 struct glyph
*glyph
;
21958 enum glyph_row_area area
= it
->area
;
21960 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21961 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21963 glyph
->charpos
= CHARPOS (it
->position
);
21964 glyph
->object
= it
->object
;
21965 glyph
->pixel_width
= it
->pixel_width
;
21966 glyph
->ascent
= glyph_ascent
;
21967 glyph
->descent
= it
->descent
;
21968 glyph
->voffset
= it
->voffset
;
21969 glyph
->type
= IMAGE_GLYPH
;
21970 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21971 glyph
->multibyte_p
= it
->multibyte_p
;
21972 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21973 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21974 glyph
->overlaps_vertically_p
= 0;
21975 glyph
->padding_p
= 0;
21976 glyph
->glyph_not_available_p
= 0;
21977 glyph
->face_id
= it
->face_id
;
21978 glyph
->u
.img_id
= img
->id
;
21979 glyph
->slice
.img
= slice
;
21980 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21983 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21984 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21986 glyph
->bidi_type
= it
->bidi_it
.type
;
21988 ++it
->glyph_row
->used
[area
];
21991 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21996 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
21997 of the glyph, WIDTH and HEIGHT are the width and height of the
21998 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22001 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22002 int width
, int height
, int ascent
)
22004 struct glyph
*glyph
;
22005 enum glyph_row_area area
= it
->area
;
22007 xassert (ascent
>= 0 && ascent
<= height
);
22009 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22010 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22012 /* If the glyph row is reversed, we need to prepend the glyph
22013 rather than append it. */
22014 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22018 /* Make room for the additional glyph. */
22019 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22021 glyph
= it
->glyph_row
->glyphs
[area
];
22023 glyph
->charpos
= CHARPOS (it
->position
);
22024 glyph
->object
= object
;
22025 glyph
->pixel_width
= width
;
22026 glyph
->ascent
= ascent
;
22027 glyph
->descent
= height
- ascent
;
22028 glyph
->voffset
= it
->voffset
;
22029 glyph
->type
= STRETCH_GLYPH
;
22030 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22031 glyph
->multibyte_p
= it
->multibyte_p
;
22032 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22033 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22034 glyph
->overlaps_vertically_p
= 0;
22035 glyph
->padding_p
= 0;
22036 glyph
->glyph_not_available_p
= 0;
22037 glyph
->face_id
= it
->face_id
;
22038 glyph
->u
.stretch
.ascent
= ascent
;
22039 glyph
->u
.stretch
.height
= height
;
22040 glyph
->slice
.img
= null_glyph_slice
;
22041 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22044 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22045 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22047 glyph
->bidi_type
= it
->bidi_it
.type
;
22051 glyph
->resolved_level
= 0;
22052 glyph
->bidi_type
= UNKNOWN_BT
;
22054 ++it
->glyph_row
->used
[area
];
22057 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22061 /* Produce a stretch glyph for iterator IT. IT->object is the value
22062 of the glyph property displayed. The value must be a list
22063 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22066 1. `:width WIDTH' specifies that the space should be WIDTH *
22067 canonical char width wide. WIDTH may be an integer or floating
22070 2. `:relative-width FACTOR' specifies that the width of the stretch
22071 should be computed from the width of the first character having the
22072 `glyph' property, and should be FACTOR times that width.
22074 3. `:align-to HPOS' specifies that the space should be wide enough
22075 to reach HPOS, a value in canonical character units.
22077 Exactly one of the above pairs must be present.
22079 4. `:height HEIGHT' specifies that the height of the stretch produced
22080 should be HEIGHT, measured in canonical character units.
22082 5. `:relative-height FACTOR' specifies that the height of the
22083 stretch should be FACTOR times the height of the characters having
22084 the glyph property.
22086 Either none or exactly one of 4 or 5 must be present.
22088 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22089 of the stretch should be used for the ascent of the stretch.
22090 ASCENT must be in the range 0 <= ASCENT <= 100. */
22093 produce_stretch_glyph (struct it
*it
)
22095 /* (space :width WIDTH :height HEIGHT ...) */
22096 Lisp_Object prop
, plist
;
22097 int width
= 0, height
= 0, align_to
= -1;
22098 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22101 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22102 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22104 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22106 /* List should start with `space'. */
22107 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22108 plist
= XCDR (it
->object
);
22110 /* Compute the width of the stretch. */
22111 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22112 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22114 /* Absolute width `:width WIDTH' specified and valid. */
22115 zero_width_ok_p
= 1;
22118 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22121 /* Relative width `:relative-width FACTOR' specified and valid.
22122 Compute the width of the characters having the `glyph'
22125 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22128 if (it
->multibyte_p
)
22129 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22132 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22133 if (! ASCII_CHAR_P (it2
.c
))
22134 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22137 it2
.glyph_row
= NULL
;
22138 it2
.what
= IT_CHARACTER
;
22139 x_produce_glyphs (&it2
);
22140 width
= NUMVAL (prop
) * it2
.pixel_width
;
22142 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22143 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22145 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22146 align_to
= (align_to
< 0
22148 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22149 else if (align_to
< 0)
22150 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22151 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22152 zero_width_ok_p
= 1;
22155 /* Nothing specified -> width defaults to canonical char width. */
22156 width
= FRAME_COLUMN_WIDTH (it
->f
);
22158 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22161 /* Compute height. */
22162 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22163 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22166 zero_height_ok_p
= 1;
22168 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22170 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22172 height
= FONT_HEIGHT (font
);
22174 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22177 /* Compute percentage of height used for ascent. If
22178 `:ascent ASCENT' is present and valid, use that. Otherwise,
22179 derive the ascent from the font in use. */
22180 if (prop
= Fplist_get (plist
, QCascent
),
22181 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22182 ascent
= height
* NUMVAL (prop
) / 100.0;
22183 else if (!NILP (prop
)
22184 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22185 ascent
= min (max (0, (int)tem
), height
);
22187 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22189 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22190 && it
->current_x
+ width
> it
->last_visible_x
)
22191 width
= it
->last_visible_x
- it
->current_x
- 1;
22193 if (width
> 0 && height
> 0 && it
->glyph_row
)
22195 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22196 if (!STRINGP (object
))
22197 object
= it
->w
->buffer
;
22198 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22201 it
->pixel_width
= width
;
22202 it
->ascent
= it
->phys_ascent
= ascent
;
22203 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22204 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22206 take_vertical_position_into_account (it
);
22209 /* Calculate line-height and line-spacing properties.
22210 An integer value specifies explicit pixel value.
22211 A float value specifies relative value to current face height.
22212 A cons (float . face-name) specifies relative value to
22213 height of specified face font.
22215 Returns height in pixels, or nil. */
22219 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22220 int boff
, int override
)
22222 Lisp_Object face_name
= Qnil
;
22223 int ascent
, descent
, height
;
22225 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22230 face_name
= XCAR (val
);
22232 if (!NUMBERP (val
))
22233 val
= make_number (1);
22234 if (NILP (face_name
))
22236 height
= it
->ascent
+ it
->descent
;
22241 if (NILP (face_name
))
22243 font
= FRAME_FONT (it
->f
);
22244 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22246 else if (EQ (face_name
, Qt
))
22255 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22257 return make_number (-1);
22259 face
= FACE_FROM_ID (it
->f
, face_id
);
22262 return make_number (-1);
22263 boff
= font
->baseline_offset
;
22264 if (font
->vertical_centering
)
22265 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22268 ascent
= FONT_BASE (font
) + boff
;
22269 descent
= FONT_DESCENT (font
) - boff
;
22273 it
->override_ascent
= ascent
;
22274 it
->override_descent
= descent
;
22275 it
->override_boff
= boff
;
22278 height
= ascent
+ descent
;
22282 height
= (int)(XFLOAT_DATA (val
) * height
);
22283 else if (INTEGERP (val
))
22284 height
*= XINT (val
);
22286 return make_number (height
);
22290 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22291 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22292 and only if this is for a character for which no font was found.
22294 If the display method (it->glyphless_method) is
22295 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEXA_CODE, LEN is a
22296 length of the acronym or the hexadecimal string, UPPER_XOFF and
22297 UPPER_YOFF are pixel offsets for the upper part of the string,
22298 LOWER_XOFF and LOWER_YOFF are for the lower part.
22300 For the other display methods, LEN through LOWER_YOFF are zero. */
22303 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22304 short upper_xoff
, short upper_yoff
,
22305 short lower_xoff
, short lower_yoff
)
22307 struct glyph
*glyph
;
22308 enum glyph_row_area area
= it
->area
;
22310 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22311 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22313 /* If the glyph row is reversed, we need to prepend the glyph
22314 rather than append it. */
22315 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22319 /* Make room for the additional glyph. */
22320 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22322 glyph
= it
->glyph_row
->glyphs
[area
];
22324 glyph
->charpos
= CHARPOS (it
->position
);
22325 glyph
->object
= it
->object
;
22326 glyph
->pixel_width
= it
->pixel_width
;
22327 glyph
->ascent
= it
->ascent
;
22328 glyph
->descent
= it
->descent
;
22329 glyph
->voffset
= it
->voffset
;
22330 glyph
->type
= GLYPHLESS_GLYPH
;
22331 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22332 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22333 glyph
->u
.glyphless
.len
= len
;
22334 glyph
->u
.glyphless
.ch
= it
->c
;
22335 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22336 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22337 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22338 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22339 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22340 glyph
->multibyte_p
= it
->multibyte_p
;
22341 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22342 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22343 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22344 || it
->phys_descent
> it
->descent
);
22345 glyph
->padding_p
= 0;
22346 glyph
->glyph_not_available_p
= 0;
22347 glyph
->face_id
= face_id
;
22348 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22351 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22352 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22354 glyph
->bidi_type
= it
->bidi_it
.type
;
22356 ++it
->glyph_row
->used
[area
];
22359 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22363 /* Produce a glyph for a glyphless character for iterator IT.
22364 IT->glyphless_method specifies which method to use for displaying
22365 the character. See the description of enum
22366 glyphless_display_method in dispextern.h for the detail.
22368 FOR_NO_FONT is nonzero if and only if this is for a character for
22369 which no font was found. ACRONYM, if non-nil, is an acronym string
22370 for the character. */
22373 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22378 int base_width
, base_height
, width
, height
;
22379 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22382 /* Get the metrics of the base font. We always refer to the current
22384 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22385 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22386 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22387 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
22388 base_height
= it
->ascent
+ it
->descent
;
22389 base_width
= font
->average_width
;
22391 /* Get a face ID for the glyph by utilizing a cache (the same way as
22392 doen for `escape-glyph' in get_next_display_element). */
22393 if (it
->f
== last_glyphless_glyph_frame
22394 && it
->face_id
== last_glyphless_glyph_face_id
)
22396 face_id
= last_glyphless_glyph_merged_face_id
;
22400 /* Merge the `glyphless-char' face into the current face. */
22401 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
22402 last_glyphless_glyph_frame
= it
->f
;
22403 last_glyphless_glyph_face_id
= it
->face_id
;
22404 last_glyphless_glyph_merged_face_id
= face_id
;
22407 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
22409 it
->pixel_width
= THIN_SPACE_WIDTH
;
22411 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22413 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
22415 width
= CHAR_WIDTH (it
->c
);
22418 else if (width
> 4)
22420 it
->pixel_width
= base_width
* width
;
22422 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22427 unsigned int code
[6];
22429 int ascent
, descent
;
22430 struct font_metrics metrics_upper
, metrics_lower
;
22432 face
= FACE_FROM_ID (it
->f
, face_id
);
22433 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22434 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22436 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
22438 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
22439 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
22440 str
= STRINGP (acronym
) ? (char *) SDATA (acronym
) : "";
22444 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEXA_CODE
);
22445 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
22448 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
22449 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
22450 upper_len
= (len
+ 1) / 2;
22451 font
->driver
->text_extents (font
, code
, upper_len
,
22453 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
22458 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
22459 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
22460 upper_xoff
= upper_yoff
= 2; /* the typical case */
22461 if (base_width
>= width
)
22463 /* Align the upper to the left, the lower to the right. */
22464 it
->pixel_width
= base_width
;
22465 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
22469 /* Center the shorter one. */
22470 it
->pixel_width
= width
;
22471 if (metrics_upper
.width
>= metrics_lower
.width
)
22472 lower_xoff
= (width
- metrics_lower
.width
) / 2;
22474 upper_xoff
= (width
- metrics_upper
.width
) / 2;
22477 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
22478 top, bottom, and between upper and lower strings. */
22479 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
22480 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
22481 /* Center vertically.
22482 H:base_height, D:base_descent
22483 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
22485 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
22486 descent = D - H/2 + h/2;
22487 lower_yoff = descent - 2 - ld;
22488 upper_yoff = lower_yoff - la - 1 - ud; */
22489 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
22490 descent
= it
->descent
- (base_height
- height
) / 2;
22491 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
22492 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
22493 - metrics_upper
.descent
);
22494 /* Don't make the height shorter than the base height. */
22495 if (height
> base_height
)
22497 it
->ascent
= ascent
;
22498 it
->descent
= descent
;
22502 it
->phys_ascent
= it
->ascent
;
22503 it
->phys_descent
= it
->descent
;
22505 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
22506 upper_xoff
, upper_yoff
,
22507 lower_xoff
, lower_yoff
);
22509 take_vertical_position_into_account (it
);
22514 Produce glyphs/get display metrics for the display element IT is
22515 loaded with. See the description of struct it in dispextern.h
22516 for an overview of struct it. */
22519 x_produce_glyphs (struct it
*it
)
22521 int extra_line_spacing
= it
->extra_line_spacing
;
22523 it
->glyph_not_available_p
= 0;
22525 if (it
->what
== IT_CHARACTER
)
22528 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22529 struct font
*font
= face
->font
;
22530 struct font_metrics
*pcm
= NULL
;
22531 int boff
; /* baseline offset */
22535 /* When no suitable font is found, display this character by
22536 the method specified in the first extra slot of
22537 Vglyphless_char_display. */
22538 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
22540 xassert (it
->what
== IT_GLYPHLESS
);
22541 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
22545 boff
= font
->baseline_offset
;
22546 if (font
->vertical_centering
)
22547 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22549 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
22555 if (it
->override_ascent
>= 0)
22557 it
->ascent
= it
->override_ascent
;
22558 it
->descent
= it
->override_descent
;
22559 boff
= it
->override_boff
;
22563 it
->ascent
= FONT_BASE (font
) + boff
;
22564 it
->descent
= FONT_DESCENT (font
) - boff
;
22567 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
22569 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22570 if (pcm
->width
== 0
22571 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
22577 it
->phys_ascent
= pcm
->ascent
+ boff
;
22578 it
->phys_descent
= pcm
->descent
- boff
;
22579 it
->pixel_width
= pcm
->width
;
22583 it
->glyph_not_available_p
= 1;
22584 it
->phys_ascent
= it
->ascent
;
22585 it
->phys_descent
= it
->descent
;
22586 it
->pixel_width
= font
->space_width
;
22589 if (it
->constrain_row_ascent_descent_p
)
22591 if (it
->descent
> it
->max_descent
)
22593 it
->ascent
+= it
->descent
- it
->max_descent
;
22594 it
->descent
= it
->max_descent
;
22596 if (it
->ascent
> it
->max_ascent
)
22598 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22599 it
->ascent
= it
->max_ascent
;
22601 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22602 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22603 extra_line_spacing
= 0;
22606 /* If this is a space inside a region of text with
22607 `space-width' property, change its width. */
22608 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22610 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22612 /* If face has a box, add the box thickness to the character
22613 height. If character has a box line to the left and/or
22614 right, add the box line width to the character's width. */
22615 if (face
->box
!= FACE_NO_BOX
)
22617 int thick
= face
->box_line_width
;
22621 it
->ascent
+= thick
;
22622 it
->descent
+= thick
;
22627 if (it
->start_of_box_run_p
)
22628 it
->pixel_width
+= thick
;
22629 if (it
->end_of_box_run_p
)
22630 it
->pixel_width
+= thick
;
22633 /* If face has an overline, add the height of the overline
22634 (1 pixel) and a 1 pixel margin to the character height. */
22635 if (face
->overline_p
)
22636 it
->ascent
+= overline_margin
;
22638 if (it
->constrain_row_ascent_descent_p
)
22640 if (it
->ascent
> it
->max_ascent
)
22641 it
->ascent
= it
->max_ascent
;
22642 if (it
->descent
> it
->max_descent
)
22643 it
->descent
= it
->max_descent
;
22646 take_vertical_position_into_account (it
);
22648 /* If we have to actually produce glyphs, do it. */
22653 /* Translate a space with a `space-width' property
22654 into a stretch glyph. */
22655 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22656 / FONT_HEIGHT (font
));
22657 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22658 it
->ascent
+ it
->descent
, ascent
);
22663 /* If characters with lbearing or rbearing are displayed
22664 in this line, record that fact in a flag of the
22665 glyph row. This is used to optimize X output code. */
22666 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22667 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22669 if (! stretched_p
&& it
->pixel_width
== 0)
22670 /* We assure that all visible glyphs have at least 1-pixel
22672 it
->pixel_width
= 1;
22674 else if (it
->char_to_display
== '\n')
22676 /* A newline has no width, but we need the height of the
22677 line. But if previous part of the line sets a height,
22678 don't increase that height */
22680 Lisp_Object height
;
22681 Lisp_Object total_height
= Qnil
;
22683 it
->override_ascent
= -1;
22684 it
->pixel_width
= 0;
22687 height
= get_it_property (it
, Qline_height
);
22688 /* Split (line-height total-height) list */
22690 && CONSP (XCDR (height
))
22691 && NILP (XCDR (XCDR (height
))))
22693 total_height
= XCAR (XCDR (height
));
22694 height
= XCAR (height
);
22696 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
22698 if (it
->override_ascent
>= 0)
22700 it
->ascent
= it
->override_ascent
;
22701 it
->descent
= it
->override_descent
;
22702 boff
= it
->override_boff
;
22706 it
->ascent
= FONT_BASE (font
) + boff
;
22707 it
->descent
= FONT_DESCENT (font
) - boff
;
22710 if (EQ (height
, Qt
))
22712 if (it
->descent
> it
->max_descent
)
22714 it
->ascent
+= it
->descent
- it
->max_descent
;
22715 it
->descent
= it
->max_descent
;
22717 if (it
->ascent
> it
->max_ascent
)
22719 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22720 it
->ascent
= it
->max_ascent
;
22722 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22723 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22724 it
->constrain_row_ascent_descent_p
= 1;
22725 extra_line_spacing
= 0;
22729 Lisp_Object spacing
;
22731 it
->phys_ascent
= it
->ascent
;
22732 it
->phys_descent
= it
->descent
;
22734 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22735 && face
->box
!= FACE_NO_BOX
22736 && face
->box_line_width
> 0)
22738 it
->ascent
+= face
->box_line_width
;
22739 it
->descent
+= face
->box_line_width
;
22742 && XINT (height
) > it
->ascent
+ it
->descent
)
22743 it
->ascent
= XINT (height
) - it
->descent
;
22745 if (!NILP (total_height
))
22746 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
22749 spacing
= get_it_property (it
, Qline_spacing
);
22750 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
22752 if (INTEGERP (spacing
))
22754 extra_line_spacing
= XINT (spacing
);
22755 if (!NILP (total_height
))
22756 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22760 else /* i.e. (it->char_to_display == '\t') */
22762 if (font
->space_width
> 0)
22764 int tab_width
= it
->tab_width
* font
->space_width
;
22765 int x
= it
->current_x
+ it
->continuation_lines_width
;
22766 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22768 /* If the distance from the current position to the next tab
22769 stop is less than a space character width, use the
22770 tab stop after that. */
22771 if (next_tab_x
- x
< font
->space_width
)
22772 next_tab_x
+= tab_width
;
22774 it
->pixel_width
= next_tab_x
- x
;
22776 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22777 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22781 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22782 it
->ascent
+ it
->descent
, it
->ascent
);
22787 it
->pixel_width
= 0;
22792 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22794 /* A static composition.
22796 Note: A composition is represented as one glyph in the
22797 glyph matrix. There are no padding glyphs.
22799 Important note: pixel_width, ascent, and descent are the
22800 values of what is drawn by draw_glyphs (i.e. the values of
22801 the overall glyphs composed). */
22802 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22803 int boff
; /* baseline offset */
22804 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22805 int glyph_len
= cmp
->glyph_len
;
22806 struct font
*font
= face
->font
;
22810 /* If we have not yet calculated pixel size data of glyphs of
22811 the composition for the current face font, calculate them
22812 now. Theoretically, we have to check all fonts for the
22813 glyphs, but that requires much time and memory space. So,
22814 here we check only the font of the first glyph. This may
22815 lead to incorrect display, but it's very rare, and C-l
22816 (recenter-top-bottom) can correct the display anyway. */
22817 if (! cmp
->font
|| cmp
->font
!= font
)
22819 /* Ascent and descent of the font of the first character
22820 of this composition (adjusted by baseline offset).
22821 Ascent and descent of overall glyphs should not be less
22822 than these, respectively. */
22823 int font_ascent
, font_descent
, font_height
;
22824 /* Bounding box of the overall glyphs. */
22825 int leftmost
, rightmost
, lowest
, highest
;
22826 int lbearing
, rbearing
;
22827 int i
, width
, ascent
, descent
;
22828 int left_padded
= 0, right_padded
= 0;
22831 struct font_metrics
*pcm
;
22832 int font_not_found_p
;
22835 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22836 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22838 if (glyph_len
< cmp
->glyph_len
)
22840 for (i
= 0; i
< glyph_len
; i
++)
22842 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22844 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22849 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22850 : IT_CHARPOS (*it
));
22851 /* If no suitable font is found, use the default font. */
22852 font_not_found_p
= font
== NULL
;
22853 if (font_not_found_p
)
22855 face
= face
->ascii_face
;
22858 boff
= font
->baseline_offset
;
22859 if (font
->vertical_centering
)
22860 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22861 font_ascent
= FONT_BASE (font
) + boff
;
22862 font_descent
= FONT_DESCENT (font
) - boff
;
22863 font_height
= FONT_HEIGHT (font
);
22865 cmp
->font
= (void *) font
;
22868 if (! font_not_found_p
)
22870 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22871 &char2b
, it
->multibyte_p
, 0);
22872 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22875 /* Initialize the bounding box. */
22878 width
= pcm
->width
;
22879 ascent
= pcm
->ascent
;
22880 descent
= pcm
->descent
;
22881 lbearing
= pcm
->lbearing
;
22882 rbearing
= pcm
->rbearing
;
22886 width
= font
->space_width
;
22887 ascent
= FONT_BASE (font
);
22888 descent
= FONT_DESCENT (font
);
22895 lowest
= - descent
+ boff
;
22896 highest
= ascent
+ boff
;
22898 if (! font_not_found_p
22899 && font
->default_ascent
22900 && CHAR_TABLE_P (Vuse_default_ascent
)
22901 && !NILP (Faref (Vuse_default_ascent
,
22902 make_number (it
->char_to_display
))))
22903 highest
= font
->default_ascent
+ boff
;
22905 /* Draw the first glyph at the normal position. It may be
22906 shifted to right later if some other glyphs are drawn
22908 cmp
->offsets
[i
* 2] = 0;
22909 cmp
->offsets
[i
* 2 + 1] = boff
;
22910 cmp
->lbearing
= lbearing
;
22911 cmp
->rbearing
= rbearing
;
22913 /* Set cmp->offsets for the remaining glyphs. */
22914 for (i
++; i
< glyph_len
; i
++)
22916 int left
, right
, btm
, top
;
22917 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22919 struct face
*this_face
;
22924 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22925 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22926 font
= this_face
->font
;
22932 this_boff
= font
->baseline_offset
;
22933 if (font
->vertical_centering
)
22934 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22935 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22936 &char2b
, it
->multibyte_p
, 0);
22937 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22940 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22943 width
= pcm
->width
;
22944 ascent
= pcm
->ascent
;
22945 descent
= pcm
->descent
;
22946 lbearing
= pcm
->lbearing
;
22947 rbearing
= pcm
->rbearing
;
22948 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22950 /* Relative composition with or without
22951 alternate chars. */
22952 left
= (leftmost
+ rightmost
- width
) / 2;
22953 btm
= - descent
+ boff
;
22954 if (font
->relative_compose
22955 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22956 || NILP (Faref (Vignore_relative_composition
,
22957 make_number (ch
)))))
22960 if (- descent
>= font
->relative_compose
)
22961 /* One extra pixel between two glyphs. */
22963 else if (ascent
<= 0)
22964 /* One extra pixel between two glyphs. */
22965 btm
= lowest
- 1 - ascent
- descent
;
22970 /* A composition rule is specified by an integer
22971 value that encodes global and new reference
22972 points (GREF and NREF). GREF and NREF are
22973 specified by numbers as below:
22975 0---1---2 -- ascent
22979 9--10--11 -- center
22981 ---3---4---5--- baseline
22983 6---7---8 -- descent
22985 int rule
= COMPOSITION_RULE (cmp
, i
);
22986 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
22988 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
22989 grefx
= gref
% 3, nrefx
= nref
% 3;
22990 grefy
= gref
/ 3, nrefy
= nref
/ 3;
22992 xoff
= font_height
* (xoff
- 128) / 256;
22994 yoff
= font_height
* (yoff
- 128) / 256;
22997 + grefx
* (rightmost
- leftmost
) / 2
22998 - nrefx
* width
/ 2
23001 btm
= ((grefy
== 0 ? highest
23003 : grefy
== 2 ? lowest
23004 : (highest
+ lowest
) / 2)
23005 - (nrefy
== 0 ? ascent
+ descent
23006 : nrefy
== 1 ? descent
- boff
23008 : (ascent
+ descent
) / 2)
23012 cmp
->offsets
[i
* 2] = left
;
23013 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23015 /* Update the bounding box of the overall glyphs. */
23018 right
= left
+ width
;
23019 if (left
< leftmost
)
23021 if (right
> rightmost
)
23024 top
= btm
+ descent
+ ascent
;
23030 if (cmp
->lbearing
> left
+ lbearing
)
23031 cmp
->lbearing
= left
+ lbearing
;
23032 if (cmp
->rbearing
< left
+ rbearing
)
23033 cmp
->rbearing
= left
+ rbearing
;
23037 /* If there are glyphs whose x-offsets are negative,
23038 shift all glyphs to the right and make all x-offsets
23042 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23043 cmp
->offsets
[i
* 2] -= leftmost
;
23044 rightmost
-= leftmost
;
23045 cmp
->lbearing
-= leftmost
;
23046 cmp
->rbearing
-= leftmost
;
23049 if (left_padded
&& cmp
->lbearing
< 0)
23051 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23052 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23053 rightmost
-= cmp
->lbearing
;
23054 cmp
->rbearing
-= cmp
->lbearing
;
23057 if (right_padded
&& rightmost
< cmp
->rbearing
)
23059 rightmost
= cmp
->rbearing
;
23062 cmp
->pixel_width
= rightmost
;
23063 cmp
->ascent
= highest
;
23064 cmp
->descent
= - lowest
;
23065 if (cmp
->ascent
< font_ascent
)
23066 cmp
->ascent
= font_ascent
;
23067 if (cmp
->descent
< font_descent
)
23068 cmp
->descent
= font_descent
;
23072 && (cmp
->lbearing
< 0
23073 || cmp
->rbearing
> cmp
->pixel_width
))
23074 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23076 it
->pixel_width
= cmp
->pixel_width
;
23077 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23078 it
->descent
= it
->phys_descent
= cmp
->descent
;
23079 if (face
->box
!= FACE_NO_BOX
)
23081 int thick
= face
->box_line_width
;
23085 it
->ascent
+= thick
;
23086 it
->descent
+= thick
;
23091 if (it
->start_of_box_run_p
)
23092 it
->pixel_width
+= thick
;
23093 if (it
->end_of_box_run_p
)
23094 it
->pixel_width
+= thick
;
23097 /* If face has an overline, add the height of the overline
23098 (1 pixel) and a 1 pixel margin to the character height. */
23099 if (face
->overline_p
)
23100 it
->ascent
+= overline_margin
;
23102 take_vertical_position_into_account (it
);
23103 if (it
->ascent
< 0)
23105 if (it
->descent
< 0)
23109 append_composite_glyph (it
);
23111 else if (it
->what
== IT_COMPOSITION
)
23113 /* A dynamic (automatic) composition. */
23114 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23115 Lisp_Object gstring
;
23116 struct font_metrics metrics
;
23118 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23120 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23123 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23124 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23125 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23126 it
->descent
= it
->phys_descent
= metrics
.descent
;
23127 if (face
->box
!= FACE_NO_BOX
)
23129 int thick
= face
->box_line_width
;
23133 it
->ascent
+= thick
;
23134 it
->descent
+= thick
;
23139 if (it
->start_of_box_run_p
)
23140 it
->pixel_width
+= thick
;
23141 if (it
->end_of_box_run_p
)
23142 it
->pixel_width
+= thick
;
23144 /* If face has an overline, add the height of the overline
23145 (1 pixel) and a 1 pixel margin to the character height. */
23146 if (face
->overline_p
)
23147 it
->ascent
+= overline_margin
;
23148 take_vertical_position_into_account (it
);
23149 if (it
->ascent
< 0)
23151 if (it
->descent
< 0)
23155 append_composite_glyph (it
);
23157 else if (it
->what
== IT_GLYPHLESS
)
23158 produce_glyphless_glyph (it
, 0, Qnil
);
23159 else if (it
->what
== IT_IMAGE
)
23160 produce_image_glyph (it
);
23161 else if (it
->what
== IT_STRETCH
)
23162 produce_stretch_glyph (it
);
23165 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23166 because this isn't true for images with `:ascent 100'. */
23167 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23168 if (it
->area
== TEXT_AREA
)
23169 it
->current_x
+= it
->pixel_width
;
23171 if (extra_line_spacing
> 0)
23173 it
->descent
+= extra_line_spacing
;
23174 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23175 it
->max_extra_line_spacing
= extra_line_spacing
;
23178 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23179 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23180 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23181 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23185 Output LEN glyphs starting at START at the nominal cursor position.
23186 Advance the nominal cursor over the text. The global variable
23187 updated_window contains the window being updated, updated_row is
23188 the glyph row being updated, and updated_area is the area of that
23189 row being updated. */
23192 x_write_glyphs (struct glyph
*start
, int len
)
23196 xassert (updated_window
&& updated_row
);
23199 /* Write glyphs. */
23201 hpos
= start
- updated_row
->glyphs
[updated_area
];
23202 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23203 updated_row
, updated_area
,
23205 DRAW_NORMAL_TEXT
, 0);
23207 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23208 if (updated_area
== TEXT_AREA
23209 && updated_window
->phys_cursor_on_p
23210 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23211 && updated_window
->phys_cursor
.hpos
>= hpos
23212 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23213 updated_window
->phys_cursor_on_p
= 0;
23217 /* Advance the output cursor. */
23218 output_cursor
.hpos
+= len
;
23219 output_cursor
.x
= x
;
23224 Insert LEN glyphs from START at the nominal cursor position. */
23227 x_insert_glyphs (struct glyph
*start
, int len
)
23231 int line_height
, shift_by_width
, shifted_region_width
;
23232 struct glyph_row
*row
;
23233 struct glyph
*glyph
;
23234 int frame_x
, frame_y
;
23237 xassert (updated_window
&& updated_row
);
23239 w
= updated_window
;
23240 f
= XFRAME (WINDOW_FRAME (w
));
23242 /* Get the height of the line we are in. */
23244 line_height
= row
->height
;
23246 /* Get the width of the glyphs to insert. */
23247 shift_by_width
= 0;
23248 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23249 shift_by_width
+= glyph
->pixel_width
;
23251 /* Get the width of the region to shift right. */
23252 shifted_region_width
= (window_box_width (w
, updated_area
)
23257 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23258 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23260 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23261 line_height
, shift_by_width
);
23263 /* Write the glyphs. */
23264 hpos
= start
- row
->glyphs
[updated_area
];
23265 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23267 DRAW_NORMAL_TEXT
, 0);
23269 /* Advance the output cursor. */
23270 output_cursor
.hpos
+= len
;
23271 output_cursor
.x
+= shift_by_width
;
23277 Erase the current text line from the nominal cursor position
23278 (inclusive) to pixel column TO_X (exclusive). The idea is that
23279 everything from TO_X onward is already erased.
23281 TO_X is a pixel position relative to updated_area of
23282 updated_window. TO_X == -1 means clear to the end of this area. */
23285 x_clear_end_of_line (int to_x
)
23288 struct window
*w
= updated_window
;
23289 int max_x
, min_y
, max_y
;
23290 int from_x
, from_y
, to_y
;
23292 xassert (updated_window
&& updated_row
);
23293 f
= XFRAME (w
->frame
);
23295 if (updated_row
->full_width_p
)
23296 max_x
= WINDOW_TOTAL_WIDTH (w
);
23298 max_x
= window_box_width (w
, updated_area
);
23299 max_y
= window_text_bottom_y (w
);
23301 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23302 of window. For TO_X > 0, truncate to end of drawing area. */
23308 to_x
= min (to_x
, max_x
);
23310 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23312 /* Notice if the cursor will be cleared by this operation. */
23313 if (!updated_row
->full_width_p
)
23314 notice_overwritten_cursor (w
, updated_area
,
23315 output_cursor
.x
, -1,
23317 MATRIX_ROW_BOTTOM_Y (updated_row
));
23319 from_x
= output_cursor
.x
;
23321 /* Translate to frame coordinates. */
23322 if (updated_row
->full_width_p
)
23324 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23325 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23329 int area_left
= window_box_left (w
, updated_area
);
23330 from_x
+= area_left
;
23334 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23335 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23336 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23338 /* Prevent inadvertently clearing to end of the X window. */
23339 if (to_x
> from_x
&& to_y
> from_y
)
23342 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23343 to_x
- from_x
, to_y
- from_y
);
23348 #endif /* HAVE_WINDOW_SYSTEM */
23352 /***********************************************************************
23354 ***********************************************************************/
23356 /* Value is the internal representation of the specified cursor type
23357 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23358 of the bar cursor. */
23360 static enum text_cursor_kinds
23361 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23363 enum text_cursor_kinds type
;
23368 if (EQ (arg
, Qbox
))
23369 return FILLED_BOX_CURSOR
;
23371 if (EQ (arg
, Qhollow
))
23372 return HOLLOW_BOX_CURSOR
;
23374 if (EQ (arg
, Qbar
))
23381 && EQ (XCAR (arg
), Qbar
)
23382 && INTEGERP (XCDR (arg
))
23383 && XINT (XCDR (arg
)) >= 0)
23385 *width
= XINT (XCDR (arg
));
23389 if (EQ (arg
, Qhbar
))
23392 return HBAR_CURSOR
;
23396 && EQ (XCAR (arg
), Qhbar
)
23397 && INTEGERP (XCDR (arg
))
23398 && XINT (XCDR (arg
)) >= 0)
23400 *width
= XINT (XCDR (arg
));
23401 return HBAR_CURSOR
;
23404 /* Treat anything unknown as "hollow box cursor".
23405 It was bad to signal an error; people have trouble fixing
23406 .Xdefaults with Emacs, when it has something bad in it. */
23407 type
= HOLLOW_BOX_CURSOR
;
23412 /* Set the default cursor types for specified frame. */
23414 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
23419 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23420 FRAME_CURSOR_WIDTH (f
) = width
;
23422 /* By default, set up the blink-off state depending on the on-state. */
23424 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23427 FRAME_BLINK_OFF_CURSOR (f
)
23428 = get_specified_cursor_type (XCDR (tem
), &width
);
23429 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23432 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23436 #ifdef HAVE_WINDOW_SYSTEM
23438 /* Return the cursor we want to be displayed in window W. Return
23439 width of bar/hbar cursor through WIDTH arg. Return with
23440 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23441 (i.e. if the `system caret' should track this cursor).
23443 In a mini-buffer window, we want the cursor only to appear if we
23444 are reading input from this window. For the selected window, we
23445 want the cursor type given by the frame parameter or buffer local
23446 setting of cursor-type. If explicitly marked off, draw no cursor.
23447 In all other cases, we want a hollow box cursor. */
23449 static enum text_cursor_kinds
23450 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
23451 int *active_cursor
)
23453 struct frame
*f
= XFRAME (w
->frame
);
23454 struct buffer
*b
= XBUFFER (w
->buffer
);
23455 int cursor_type
= DEFAULT_CURSOR
;
23456 Lisp_Object alt_cursor
;
23457 int non_selected
= 0;
23459 *active_cursor
= 1;
23462 if (cursor_in_echo_area
23463 && FRAME_HAS_MINIBUF_P (f
)
23464 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23466 if (w
== XWINDOW (echo_area_window
))
23468 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
23470 *width
= FRAME_CURSOR_WIDTH (f
);
23471 return FRAME_DESIRED_CURSOR (f
);
23474 return get_specified_cursor_type (b
->cursor_type
, width
);
23477 *active_cursor
= 0;
23481 /* Detect a nonselected window or nonselected frame. */
23482 else if (w
!= XWINDOW (f
->selected_window
)
23483 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
23485 *active_cursor
= 0;
23487 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23493 /* Never display a cursor in a window in which cursor-type is nil. */
23494 if (NILP (b
->cursor_type
))
23497 /* Get the normal cursor type for this window. */
23498 if (EQ (b
->cursor_type
, Qt
))
23500 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23501 *width
= FRAME_CURSOR_WIDTH (f
);
23504 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
23506 /* Use cursor-in-non-selected-windows instead
23507 for non-selected window or frame. */
23510 alt_cursor
= b
->cursor_in_non_selected_windows
;
23511 if (!EQ (Qt
, alt_cursor
))
23512 return get_specified_cursor_type (alt_cursor
, width
);
23513 /* t means modify the normal cursor type. */
23514 if (cursor_type
== FILLED_BOX_CURSOR
)
23515 cursor_type
= HOLLOW_BOX_CURSOR
;
23516 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23518 return cursor_type
;
23521 /* Use normal cursor if not blinked off. */
23522 if (!w
->cursor_off_p
)
23524 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23526 if (cursor_type
== FILLED_BOX_CURSOR
)
23528 /* Using a block cursor on large images can be very annoying.
23529 So use a hollow cursor for "large" images.
23530 If image is not transparent (no mask), also use hollow cursor. */
23531 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23532 if (img
!= NULL
&& IMAGEP (img
->spec
))
23534 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23535 where N = size of default frame font size.
23536 This should cover most of the "tiny" icons people may use. */
23538 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23539 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23540 cursor_type
= HOLLOW_BOX_CURSOR
;
23543 else if (cursor_type
!= NO_CURSOR
)
23545 /* Display current only supports BOX and HOLLOW cursors for images.
23546 So for now, unconditionally use a HOLLOW cursor when cursor is
23547 not a solid box cursor. */
23548 cursor_type
= HOLLOW_BOX_CURSOR
;
23551 return cursor_type
;
23554 /* Cursor is blinked off, so determine how to "toggle" it. */
23556 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23557 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
23558 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23560 /* Then see if frame has specified a specific blink off cursor type. */
23561 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23563 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23564 return FRAME_BLINK_OFF_CURSOR (f
);
23568 /* Some people liked having a permanently visible blinking cursor,
23569 while others had very strong opinions against it. So it was
23570 decided to remove it. KFS 2003-09-03 */
23572 /* Finally perform built-in cursor blinking:
23573 filled box <-> hollow box
23574 wide [h]bar <-> narrow [h]bar
23575 narrow [h]bar <-> no cursor
23576 other type <-> no cursor */
23578 if (cursor_type
== FILLED_BOX_CURSOR
)
23579 return HOLLOW_BOX_CURSOR
;
23581 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23584 return cursor_type
;
23592 /* Notice when the text cursor of window W has been completely
23593 overwritten by a drawing operation that outputs glyphs in AREA
23594 starting at X0 and ending at X1 in the line starting at Y0 and
23595 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23596 the rest of the line after X0 has been written. Y coordinates
23597 are window-relative. */
23600 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
23601 int x0
, int x1
, int y0
, int y1
)
23603 int cx0
, cx1
, cy0
, cy1
;
23604 struct glyph_row
*row
;
23606 if (!w
->phys_cursor_on_p
)
23608 if (area
!= TEXT_AREA
)
23611 if (w
->phys_cursor
.vpos
< 0
23612 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23613 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23614 !(row
->enabled_p
&& row
->displays_text_p
)))
23617 if (row
->cursor_in_fringe_p
)
23619 row
->cursor_in_fringe_p
= 0;
23620 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
23621 w
->phys_cursor_on_p
= 0;
23625 cx0
= w
->phys_cursor
.x
;
23626 cx1
= cx0
+ w
->phys_cursor_width
;
23627 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23630 /* The cursor image will be completely removed from the
23631 screen if the output area intersects the cursor area in
23632 y-direction. When we draw in [y0 y1[, and some part of
23633 the cursor is at y < y0, that part must have been drawn
23634 before. When scrolling, the cursor is erased before
23635 actually scrolling, so we don't come here. When not
23636 scrolling, the rows above the old cursor row must have
23637 changed, and in this case these rows must have written
23638 over the cursor image.
23640 Likewise if part of the cursor is below y1, with the
23641 exception of the cursor being in the first blank row at
23642 the buffer and window end because update_text_area
23643 doesn't draw that row. (Except when it does, but
23644 that's handled in update_text_area.) */
23646 cy0
= w
->phys_cursor
.y
;
23647 cy1
= cy0
+ w
->phys_cursor_height
;
23648 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23651 w
->phys_cursor_on_p
= 0;
23654 #endif /* HAVE_WINDOW_SYSTEM */
23657 /************************************************************************
23659 ************************************************************************/
23661 #ifdef HAVE_WINDOW_SYSTEM
23664 Fix the display of area AREA of overlapping row ROW in window W
23665 with respect to the overlapping part OVERLAPS. */
23668 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
23669 enum glyph_row_area area
, int overlaps
)
23676 for (i
= 0; i
< row
->used
[area
];)
23678 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23680 int start
= i
, start_x
= x
;
23684 x
+= row
->glyphs
[area
][i
].pixel_width
;
23687 while (i
< row
->used
[area
]
23688 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23690 draw_glyphs (w
, start_x
, row
, area
,
23692 DRAW_NORMAL_TEXT
, overlaps
);
23696 x
+= row
->glyphs
[area
][i
].pixel_width
;
23706 Draw the cursor glyph of window W in glyph row ROW. See the
23707 comment of draw_glyphs for the meaning of HL. */
23710 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
23711 enum draw_glyphs_face hl
)
23713 /* If cursor hpos is out of bounds, don't draw garbage. This can
23714 happen in mini-buffer windows when switching between echo area
23715 glyphs and mini-buffer. */
23716 if ((row
->reversed_p
23717 ? (w
->phys_cursor
.hpos
>= 0)
23718 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
23720 int on_p
= w
->phys_cursor_on_p
;
23722 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23723 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23725 w
->phys_cursor_on_p
= on_p
;
23727 if (hl
== DRAW_CURSOR
)
23728 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23729 /* When we erase the cursor, and ROW is overlapped by other
23730 rows, make sure that these overlapping parts of other rows
23732 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23734 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23736 if (row
> w
->current_matrix
->rows
23737 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23738 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23739 OVERLAPS_ERASED_CURSOR
);
23741 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23742 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23743 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23744 OVERLAPS_ERASED_CURSOR
);
23751 Erase the image of a cursor of window W from the screen. */
23754 erase_phys_cursor (struct window
*w
)
23756 struct frame
*f
= XFRAME (w
->frame
);
23757 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23758 int hpos
= w
->phys_cursor
.hpos
;
23759 int vpos
= w
->phys_cursor
.vpos
;
23760 int mouse_face_here_p
= 0;
23761 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23762 struct glyph_row
*cursor_row
;
23763 struct glyph
*cursor_glyph
;
23764 enum draw_glyphs_face hl
;
23766 /* No cursor displayed or row invalidated => nothing to do on the
23768 if (w
->phys_cursor_type
== NO_CURSOR
)
23769 goto mark_cursor_off
;
23771 /* VPOS >= active_glyphs->nrows means that window has been resized.
23772 Don't bother to erase the cursor. */
23773 if (vpos
>= active_glyphs
->nrows
)
23774 goto mark_cursor_off
;
23776 /* If row containing cursor is marked invalid, there is nothing we
23778 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23779 if (!cursor_row
->enabled_p
)
23780 goto mark_cursor_off
;
23782 /* If line spacing is > 0, old cursor may only be partially visible in
23783 window after split-window. So adjust visible height. */
23784 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23785 window_text_bottom_y (w
) - cursor_row
->y
);
23787 /* If row is completely invisible, don't attempt to delete a cursor which
23788 isn't there. This can happen if cursor is at top of a window, and
23789 we switch to a buffer with a header line in that window. */
23790 if (cursor_row
->visible_height
<= 0)
23791 goto mark_cursor_off
;
23793 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23794 if (cursor_row
->cursor_in_fringe_p
)
23796 cursor_row
->cursor_in_fringe_p
= 0;
23797 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
23798 goto mark_cursor_off
;
23801 /* This can happen when the new row is shorter than the old one.
23802 In this case, either draw_glyphs or clear_end_of_line
23803 should have cleared the cursor. Note that we wouldn't be
23804 able to erase the cursor in this case because we don't have a
23805 cursor glyph at hand. */
23806 if ((cursor_row
->reversed_p
23807 ? (w
->phys_cursor
.hpos
< 0)
23808 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
23809 goto mark_cursor_off
;
23811 /* If the cursor is in the mouse face area, redisplay that when
23812 we clear the cursor. */
23813 if (! NILP (hlinfo
->mouse_face_window
)
23814 && coords_in_mouse_face_p (w
, hpos
, vpos
)
23815 /* Don't redraw the cursor's spot in mouse face if it is at the
23816 end of a line (on a newline). The cursor appears there, but
23817 mouse highlighting does not. */
23818 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
23819 mouse_face_here_p
= 1;
23821 /* Maybe clear the display under the cursor. */
23822 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23825 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23828 cursor_glyph
= get_phys_cursor_glyph (w
);
23829 if (cursor_glyph
== NULL
)
23830 goto mark_cursor_off
;
23832 width
= cursor_glyph
->pixel_width
;
23833 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23834 x
= w
->phys_cursor
.x
;
23836 width
-= left_x
- x
;
23837 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23838 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23839 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23842 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23845 /* Erase the cursor by redrawing the character underneath it. */
23846 if (mouse_face_here_p
)
23847 hl
= DRAW_MOUSE_FACE
;
23849 hl
= DRAW_NORMAL_TEXT
;
23850 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23853 w
->phys_cursor_on_p
= 0;
23854 w
->phys_cursor_type
= NO_CURSOR
;
23859 Display or clear cursor of window W. If ON is zero, clear the
23860 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23861 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23864 display_and_set_cursor (struct window
*w
, int on
,
23865 int hpos
, int vpos
, int x
, int y
)
23867 struct frame
*f
= XFRAME (w
->frame
);
23868 int new_cursor_type
;
23869 int new_cursor_width
;
23871 struct glyph_row
*glyph_row
;
23872 struct glyph
*glyph
;
23874 /* This is pointless on invisible frames, and dangerous on garbaged
23875 windows and frames; in the latter case, the frame or window may
23876 be in the midst of changing its size, and x and y may be off the
23878 if (! FRAME_VISIBLE_P (f
)
23879 || FRAME_GARBAGED_P (f
)
23880 || vpos
>= w
->current_matrix
->nrows
23881 || hpos
>= w
->current_matrix
->matrix_w
)
23884 /* If cursor is off and we want it off, return quickly. */
23885 if (!on
&& !w
->phys_cursor_on_p
)
23888 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23889 /* If cursor row is not enabled, we don't really know where to
23890 display the cursor. */
23891 if (!glyph_row
->enabled_p
)
23893 w
->phys_cursor_on_p
= 0;
23898 if (!glyph_row
->exact_window_width_line_p
23899 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
23900 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23902 xassert (interrupt_input_blocked
);
23904 /* Set new_cursor_type to the cursor we want to be displayed. */
23905 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23906 &new_cursor_width
, &active_cursor
);
23908 /* If cursor is currently being shown and we don't want it to be or
23909 it is in the wrong place, or the cursor type is not what we want,
23911 if (w
->phys_cursor_on_p
23913 || w
->phys_cursor
.x
!= x
23914 || w
->phys_cursor
.y
!= y
23915 || new_cursor_type
!= w
->phys_cursor_type
23916 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23917 && new_cursor_width
!= w
->phys_cursor_width
)))
23918 erase_phys_cursor (w
);
23920 /* Don't check phys_cursor_on_p here because that flag is only set
23921 to zero in some cases where we know that the cursor has been
23922 completely erased, to avoid the extra work of erasing the cursor
23923 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23924 still not be visible, or it has only been partly erased. */
23927 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23928 w
->phys_cursor_height
= glyph_row
->height
;
23930 /* Set phys_cursor_.* before x_draw_.* is called because some
23931 of them may need the information. */
23932 w
->phys_cursor
.x
= x
;
23933 w
->phys_cursor
.y
= glyph_row
->y
;
23934 w
->phys_cursor
.hpos
= hpos
;
23935 w
->phys_cursor
.vpos
= vpos
;
23938 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23939 new_cursor_type
, new_cursor_width
,
23940 on
, active_cursor
);
23944 /* Switch the display of W's cursor on or off, according to the value
23948 update_window_cursor (struct window
*w
, int on
)
23950 /* Don't update cursor in windows whose frame is in the process
23951 of being deleted. */
23952 if (w
->current_matrix
)
23955 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23956 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23962 /* Call update_window_cursor with parameter ON_P on all leaf windows
23963 in the window tree rooted at W. */
23966 update_cursor_in_window_tree (struct window
*w
, int on_p
)
23970 if (!NILP (w
->hchild
))
23971 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23972 else if (!NILP (w
->vchild
))
23973 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23975 update_window_cursor (w
, on_p
);
23977 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23983 Display the cursor on window W, or clear it, according to ON_P.
23984 Don't change the cursor's position. */
23987 x_update_cursor (struct frame
*f
, int on_p
)
23989 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
23994 Clear the cursor of window W to background color, and mark the
23995 cursor as not shown. This is used when the text where the cursor
23996 is about to be rewritten. */
23999 x_clear_cursor (struct window
*w
)
24001 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24002 update_window_cursor (w
, 0);
24005 #endif /* HAVE_WINDOW_SYSTEM */
24007 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24010 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24011 int start_hpos
, int end_hpos
,
24012 enum draw_glyphs_face draw
)
24014 #ifdef HAVE_WINDOW_SYSTEM
24015 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24017 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24021 #if defined (HAVE_GPM) || defined (MSDOS)
24022 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24027 Display the active region described by mouse_face_* according to DRAW. */
24030 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24032 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24033 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24035 if (/* If window is in the process of being destroyed, don't bother
24037 w
->current_matrix
!= NULL
24038 /* Don't update mouse highlight if hidden */
24039 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24040 /* Recognize when we are called to operate on rows that don't exist
24041 anymore. This can happen when a window is split. */
24042 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24044 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24045 struct glyph_row
*row
, *first
, *last
;
24047 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24048 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24050 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24052 int start_hpos
, end_hpos
, start_x
;
24054 /* For all but the first row, the highlight starts at column 0. */
24057 /* R2L rows have BEG and END in reversed order, but the
24058 screen drawing geometry is always left to right. So
24059 we need to mirror the beginning and end of the
24060 highlighted area in R2L rows. */
24061 if (!row
->reversed_p
)
24063 start_hpos
= hlinfo
->mouse_face_beg_col
;
24064 start_x
= hlinfo
->mouse_face_beg_x
;
24066 else if (row
== last
)
24068 start_hpos
= hlinfo
->mouse_face_end_col
;
24069 start_x
= hlinfo
->mouse_face_end_x
;
24077 else if (row
->reversed_p
&& row
== last
)
24079 start_hpos
= hlinfo
->mouse_face_end_col
;
24080 start_x
= hlinfo
->mouse_face_end_x
;
24090 if (!row
->reversed_p
)
24091 end_hpos
= hlinfo
->mouse_face_end_col
;
24092 else if (row
== first
)
24093 end_hpos
= hlinfo
->mouse_face_beg_col
;
24096 end_hpos
= row
->used
[TEXT_AREA
];
24097 if (draw
== DRAW_NORMAL_TEXT
)
24098 row
->fill_line_p
= 1; /* Clear to end of line */
24101 else if (row
->reversed_p
&& row
== first
)
24102 end_hpos
= hlinfo
->mouse_face_beg_col
;
24105 end_hpos
= row
->used
[TEXT_AREA
];
24106 if (draw
== DRAW_NORMAL_TEXT
)
24107 row
->fill_line_p
= 1; /* Clear to end of line */
24110 if (end_hpos
> start_hpos
)
24112 draw_row_with_mouse_face (w
, start_x
, row
,
24113 start_hpos
, end_hpos
, draw
);
24116 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24120 #ifdef HAVE_WINDOW_SYSTEM
24121 /* When we've written over the cursor, arrange for it to
24122 be displayed again. */
24123 if (FRAME_WINDOW_P (f
)
24124 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24127 display_and_set_cursor (w
, 1,
24128 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24129 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24132 #endif /* HAVE_WINDOW_SYSTEM */
24135 #ifdef HAVE_WINDOW_SYSTEM
24136 /* Change the mouse cursor. */
24137 if (FRAME_WINDOW_P (f
))
24139 if (draw
== DRAW_NORMAL_TEXT
24140 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24141 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24142 else if (draw
== DRAW_MOUSE_FACE
)
24143 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24145 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24147 #endif /* HAVE_WINDOW_SYSTEM */
24151 Clear out the mouse-highlighted active region.
24152 Redraw it un-highlighted first. Value is non-zero if mouse
24153 face was actually drawn unhighlighted. */
24156 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24160 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24162 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24166 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24167 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24168 hlinfo
->mouse_face_window
= Qnil
;
24169 hlinfo
->mouse_face_overlay
= Qnil
;
24173 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24174 within the mouse face on that window. */
24176 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24178 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24180 /* Quickly resolve the easy cases. */
24181 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24182 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24184 if (vpos
< hlinfo
->mouse_face_beg_row
24185 || vpos
> hlinfo
->mouse_face_end_row
)
24187 if (vpos
> hlinfo
->mouse_face_beg_row
24188 && vpos
< hlinfo
->mouse_face_end_row
)
24191 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24193 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24195 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24198 else if ((vpos
== hlinfo
->mouse_face_beg_row
24199 && hpos
>= hlinfo
->mouse_face_beg_col
)
24200 || (vpos
== hlinfo
->mouse_face_end_row
24201 && hpos
< hlinfo
->mouse_face_end_col
))
24206 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24208 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24211 else if ((vpos
== hlinfo
->mouse_face_beg_row
24212 && hpos
<= hlinfo
->mouse_face_beg_col
)
24213 || (vpos
== hlinfo
->mouse_face_end_row
24214 && hpos
> hlinfo
->mouse_face_end_col
))
24222 Non-zero if physical cursor of window W is within mouse face. */
24225 cursor_in_mouse_face_p (struct window
*w
)
24227 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24232 /* Find the glyph rows START_ROW and END_ROW of window W that display
24233 characters between buffer positions START_CHARPOS and END_CHARPOS
24234 (excluding END_CHARPOS). This is similar to row_containing_pos,
24235 but is more accurate when bidi reordering makes buffer positions
24236 change non-linearly with glyph rows. */
24238 rows_from_pos_range (struct window
*w
,
24239 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24240 struct glyph_row
**start
, struct glyph_row
**end
)
24242 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24243 int last_y
= window_text_bottom_y (w
);
24244 struct glyph_row
*row
;
24249 while (!first
->enabled_p
24250 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24253 /* Find the START row. */
24255 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24258 /* A row can potentially be the START row if the range of the
24259 characters it displays intersects the range
24260 [START_CHARPOS..END_CHARPOS). */
24261 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24262 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24263 /* See the commentary in row_containing_pos, for the
24264 explanation of the complicated way to check whether
24265 some position is beyond the end of the characters
24266 displayed by a row. */
24267 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24268 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24269 && !row
->ends_at_zv_p
24270 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24271 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24272 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24273 && !row
->ends_at_zv_p
24274 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24276 /* Found a candidate row. Now make sure at least one of the
24277 glyphs it displays has a charpos from the range
24278 [START_CHARPOS..END_CHARPOS).
24280 This is not obvious because bidi reordering could make
24281 buffer positions of a row be 1,2,3,102,101,100, and if we
24282 want to highlight characters in [50..60), we don't want
24283 this row, even though [50..60) does intersect [1..103),
24284 the range of character positions given by the row's start
24285 and end positions. */
24286 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24287 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24291 if (BUFFERP (g
->object
)
24292 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24301 /* Find the END row. */
24303 /* If the last row is partially visible, start looking for END
24304 from that row, instead of starting from FIRST. */
24305 && !(row
->enabled_p
24306 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24308 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24310 struct glyph_row
*next
= row
+ 1;
24312 if (!next
->enabled_p
24313 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24314 /* The first row >= START whose range of displayed characters
24315 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24316 is the row END + 1. */
24317 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24318 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24319 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24320 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24321 && !next
->ends_at_zv_p
24322 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24323 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24324 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24325 && !next
->ends_at_zv_p
24326 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24333 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24334 but none of the characters it displays are in the range, it is
24336 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24337 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24341 if (BUFFERP (g
->object
)
24342 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24355 /* This function sets the mouse_face_* elements of HLINFO, assuming
24356 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24357 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24358 for the overlay or run of text properties specifying the mouse
24359 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24360 before-string and after-string that must also be highlighted.
24361 DISPLAY_STRING, if non-nil, is a display string that may cover some
24362 or all of the highlighted text. */
24365 mouse_face_from_buffer_pos (Lisp_Object window
,
24366 Mouse_HLInfo
*hlinfo
,
24367 EMACS_INT mouse_charpos
,
24368 EMACS_INT start_charpos
,
24369 EMACS_INT end_charpos
,
24370 Lisp_Object before_string
,
24371 Lisp_Object after_string
,
24372 Lisp_Object display_string
)
24374 struct window
*w
= XWINDOW (window
);
24375 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24376 struct glyph_row
*r1
, *r2
;
24377 struct glyph
*glyph
, *end
;
24378 EMACS_INT ignore
, pos
;
24381 xassert (NILP (display_string
) || STRINGP (display_string
));
24382 xassert (NILP (before_string
) || STRINGP (before_string
));
24383 xassert (NILP (after_string
) || STRINGP (after_string
));
24385 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
24386 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
24388 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24389 /* If the before-string or display-string contains newlines,
24390 rows_from_pos_range skips to its last row. Move back. */
24391 if (!NILP (before_string
) || !NILP (display_string
))
24393 struct glyph_row
*prev
;
24394 while ((prev
= r1
- 1, prev
>= first
)
24395 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
24396 && prev
->used
[TEXT_AREA
] > 0)
24398 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
24399 glyph
= beg
+ prev
->used
[TEXT_AREA
];
24400 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
24402 || !(EQ (glyph
->object
, before_string
)
24403 || EQ (glyph
->object
, display_string
)))
24410 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24411 hlinfo
->mouse_face_past_end
= 1;
24413 else if (!NILP (after_string
))
24415 /* If the after-string has newlines, advance to its last row. */
24416 struct glyph_row
*next
;
24417 struct glyph_row
*last
24418 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24420 for (next
= r2
+ 1;
24422 && next
->used
[TEXT_AREA
] > 0
24423 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
24427 /* The rest of the display engine assumes that mouse_face_beg_row is
24428 either above below mouse_face_end_row or identical to it. But
24429 with bidi-reordered continued lines, the row for START_CHARPOS
24430 could be below the row for END_CHARPOS. If so, swap the rows and
24431 store them in correct order. */
24434 struct glyph_row
*tem
= r2
;
24440 hlinfo
->mouse_face_beg_y
= r1
->y
;
24441 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
24442 hlinfo
->mouse_face_end_y
= r2
->y
;
24443 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
24445 /* For a bidi-reordered row, the positions of BEFORE_STRING,
24446 AFTER_STRING, DISPLAY_STRING, START_CHARPOS, and END_CHARPOS
24447 could be anywhere in the row and in any order. The strategy
24448 below is to find the leftmost and the rightmost glyph that
24449 belongs to either of these 3 strings, or whose position is
24450 between START_CHARPOS and END_CHARPOS, and highlight all the
24451 glyphs between those two. This may cover more than just the text
24452 between START_CHARPOS and END_CHARPOS if the range of characters
24453 strides the bidi level boundary, e.g. if the beginning is in R2L
24454 text while the end is in L2R text or vice versa. */
24455 if (!r1
->reversed_p
)
24457 /* This row is in a left to right paragraph. Scan it left to
24459 glyph
= r1
->glyphs
[TEXT_AREA
];
24460 end
= glyph
+ r1
->used
[TEXT_AREA
];
24463 /* Skip truncation glyphs at the start of the glyph row. */
24464 if (r1
->displays_text_p
)
24466 && INTEGERP (glyph
->object
)
24467 && glyph
->charpos
< 0;
24469 x
+= glyph
->pixel_width
;
24471 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24472 or DISPLAY_STRING, and the first glyph from buffer whose
24473 position is between START_CHARPOS and END_CHARPOS. */
24475 && !INTEGERP (glyph
->object
)
24476 && !EQ (glyph
->object
, display_string
)
24477 && !(BUFFERP (glyph
->object
)
24478 && (glyph
->charpos
>= start_charpos
24479 && glyph
->charpos
< end_charpos
));
24482 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24483 are present at buffer positions between START_CHARPOS and
24484 END_CHARPOS, or if they come from an overlay. */
24485 if (EQ (glyph
->object
, before_string
))
24487 pos
= string_buffer_position (w
, before_string
,
24489 /* If pos == 0, it means before_string came from an
24490 overlay, not from a buffer position. */
24491 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24494 else if (EQ (glyph
->object
, after_string
))
24496 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24497 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24500 x
+= glyph
->pixel_width
;
24502 hlinfo
->mouse_face_beg_x
= x
;
24503 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24507 /* This row is in a right to left paragraph. Scan it right to
24511 end
= r1
->glyphs
[TEXT_AREA
] - 1;
24512 glyph
= end
+ r1
->used
[TEXT_AREA
];
24514 /* Skip truncation glyphs at the start of the glyph row. */
24515 if (r1
->displays_text_p
)
24517 && INTEGERP (glyph
->object
)
24518 && glyph
->charpos
< 0;
24522 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24523 or DISPLAY_STRING, and the first glyph from buffer whose
24524 position is between START_CHARPOS and END_CHARPOS. */
24526 && !INTEGERP (glyph
->object
)
24527 && !EQ (glyph
->object
, display_string
)
24528 && !(BUFFERP (glyph
->object
)
24529 && (glyph
->charpos
>= start_charpos
24530 && glyph
->charpos
< end_charpos
));
24533 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24534 are present at buffer positions between START_CHARPOS and
24535 END_CHARPOS, or if they come from an overlay. */
24536 if (EQ (glyph
->object
, before_string
))
24538 pos
= string_buffer_position (w
, before_string
, start_charpos
);
24539 /* If pos == 0, it means before_string came from an
24540 overlay, not from a buffer position. */
24541 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24544 else if (EQ (glyph
->object
, after_string
))
24546 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24547 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24552 glyph
++; /* first glyph to the right of the highlighted area */
24553 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
24554 x
+= g
->pixel_width
;
24555 hlinfo
->mouse_face_beg_x
= x
;
24556 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24559 /* If the highlight ends in a different row, compute GLYPH and END
24560 for the end row. Otherwise, reuse the values computed above for
24561 the row where the highlight begins. */
24564 if (!r2
->reversed_p
)
24566 glyph
= r2
->glyphs
[TEXT_AREA
];
24567 end
= glyph
+ r2
->used
[TEXT_AREA
];
24572 end
= r2
->glyphs
[TEXT_AREA
] - 1;
24573 glyph
= end
+ r2
->used
[TEXT_AREA
];
24577 if (!r2
->reversed_p
)
24579 /* Skip truncation and continuation glyphs near the end of the
24580 row, and also blanks and stretch glyphs inserted by
24581 extend_face_to_end_of_line. */
24583 && INTEGERP ((end
- 1)->object
)
24584 && (end
- 1)->charpos
<= 0)
24586 /* Scan the rest of the glyph row from the end, looking for the
24587 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24588 DISPLAY_STRING, or whose position is between START_CHARPOS
24592 && !INTEGERP (end
->object
)
24593 && !EQ (end
->object
, display_string
)
24594 && !(BUFFERP (end
->object
)
24595 && (end
->charpos
>= start_charpos
24596 && end
->charpos
< end_charpos
));
24599 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24600 are present at buffer positions between START_CHARPOS and
24601 END_CHARPOS, or if they come from an overlay. */
24602 if (EQ (end
->object
, before_string
))
24604 pos
= string_buffer_position (w
, before_string
, start_charpos
);
24605 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24608 else if (EQ (end
->object
, after_string
))
24610 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24611 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24615 /* Find the X coordinate of the last glyph to be highlighted. */
24616 for (; glyph
<= end
; ++glyph
)
24617 x
+= glyph
->pixel_width
;
24619 hlinfo
->mouse_face_end_x
= x
;
24620 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
24624 /* Skip truncation and continuation glyphs near the end of the
24625 row, and also blanks and stretch glyphs inserted by
24626 extend_face_to_end_of_line. */
24630 && INTEGERP (end
->object
)
24631 && end
->charpos
<= 0)
24633 x
+= end
->pixel_width
;
24636 /* Scan the rest of the glyph row from the end, looking for the
24637 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24638 DISPLAY_STRING, or whose position is between START_CHARPOS
24642 && !INTEGERP (end
->object
)
24643 && !EQ (end
->object
, display_string
)
24644 && !(BUFFERP (end
->object
)
24645 && (end
->charpos
>= start_charpos
24646 && end
->charpos
< end_charpos
));
24649 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24650 are present at buffer positions between START_CHARPOS and
24651 END_CHARPOS, or if they come from an overlay. */
24652 if (EQ (end
->object
, before_string
))
24654 pos
= string_buffer_position (w
, before_string
, start_charpos
);
24655 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24658 else if (EQ (end
->object
, after_string
))
24660 pos
= string_buffer_position (w
, after_string
, end_charpos
);
24661 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24664 x
+= end
->pixel_width
;
24666 hlinfo
->mouse_face_end_x
= x
;
24667 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
24670 hlinfo
->mouse_face_window
= window
;
24671 hlinfo
->mouse_face_face_id
24672 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
24674 !hlinfo
->mouse_face_hidden
, -1);
24675 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
24678 /* The following function is not used anymore (replaced with
24679 mouse_face_from_string_pos), but I leave it here for the time
24680 being, in case someone would. */
24682 #if 0 /* not used */
24684 /* Find the position of the glyph for position POS in OBJECT in
24685 window W's current matrix, and return in *X, *Y the pixel
24686 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
24688 RIGHT_P non-zero means return the position of the right edge of the
24689 glyph, RIGHT_P zero means return the left edge position.
24691 If no glyph for POS exists in the matrix, return the position of
24692 the glyph with the next smaller position that is in the matrix, if
24693 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
24694 exists in the matrix, return the position of the glyph with the
24695 next larger position in OBJECT.
24697 Value is non-zero if a glyph was found. */
24700 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
24701 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
24703 int yb
= window_text_bottom_y (w
);
24704 struct glyph_row
*r
;
24705 struct glyph
*best_glyph
= NULL
;
24706 struct glyph_row
*best_row
= NULL
;
24709 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24710 r
->enabled_p
&& r
->y
< yb
;
24713 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
24714 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
24717 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24718 if (EQ (g
->object
, object
))
24720 if (g
->charpos
== pos
)
24727 else if (best_glyph
== NULL
24728 || ((eabs (g
->charpos
- pos
)
24729 < eabs (best_glyph
->charpos
- pos
))
24732 : g
->charpos
> pos
)))
24746 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
24750 *x
+= best_glyph
->pixel_width
;
24755 *vpos
= best_row
- w
->current_matrix
->rows
;
24758 return best_glyph
!= NULL
;
24760 #endif /* not used */
24762 /* Find the positions of the first and the last glyphs in window W's
24763 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
24764 (assumed to be a string), and return in HLINFO's mouse_face_*
24765 members the pixel and column/row coordinates of those glyphs. */
24768 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
24769 Lisp_Object object
,
24770 EMACS_INT startpos
, EMACS_INT endpos
)
24772 int yb
= window_text_bottom_y (w
);
24773 struct glyph_row
*r
;
24774 struct glyph
*g
, *e
;
24778 /* Find the glyph row with at least one position in the range
24779 [STARTPOS..ENDPOS], and the first glyph in that row whose
24780 position belongs to that range. */
24781 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24782 r
->enabled_p
&& r
->y
< yb
;
24785 if (!r
->reversed_p
)
24787 g
= r
->glyphs
[TEXT_AREA
];
24788 e
= g
+ r
->used
[TEXT_AREA
];
24789 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24790 if (EQ (g
->object
, object
)
24791 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24793 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24794 hlinfo
->mouse_face_beg_y
= r
->y
;
24795 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24796 hlinfo
->mouse_face_beg_x
= gx
;
24805 e
= r
->glyphs
[TEXT_AREA
];
24806 g
= e
+ r
->used
[TEXT_AREA
];
24807 for ( ; g
> e
; --g
)
24808 if (EQ ((g
-1)->object
, object
)
24809 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
24811 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24812 hlinfo
->mouse_face_beg_y
= r
->y
;
24813 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24814 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
24815 gx
+= g1
->pixel_width
;
24816 hlinfo
->mouse_face_beg_x
= gx
;
24828 /* Starting with the next row, look for the first row which does NOT
24829 include any glyphs whose positions are in the range. */
24830 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
24832 g
= r
->glyphs
[TEXT_AREA
];
24833 e
= g
+ r
->used
[TEXT_AREA
];
24835 for ( ; g
< e
; ++g
)
24836 if (EQ (g
->object
, object
)
24837 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24846 /* The highlighted region ends on the previous row. */
24849 /* Set the end row and its vertical pixel coordinate. */
24850 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
24851 hlinfo
->mouse_face_end_y
= r
->y
;
24853 /* Compute and set the end column and the end column's horizontal
24854 pixel coordinate. */
24855 if (!r
->reversed_p
)
24857 g
= r
->glyphs
[TEXT_AREA
];
24858 e
= g
+ r
->used
[TEXT_AREA
];
24859 for ( ; e
> g
; --e
)
24860 if (EQ ((e
-1)->object
, object
)
24861 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
24863 hlinfo
->mouse_face_end_col
= e
- g
;
24865 for (gx
= r
->x
; g
< e
; ++g
)
24866 gx
+= g
->pixel_width
;
24867 hlinfo
->mouse_face_end_x
= gx
;
24871 e
= r
->glyphs
[TEXT_AREA
];
24872 g
= e
+ r
->used
[TEXT_AREA
];
24873 for (gx
= r
->x
; e
< g
; ++e
)
24875 if (EQ (e
->object
, object
)
24876 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
24878 gx
+= e
->pixel_width
;
24880 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
24881 hlinfo
->mouse_face_end_x
= gx
;
24885 #ifdef HAVE_WINDOW_SYSTEM
24887 /* See if position X, Y is within a hot-spot of an image. */
24890 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
24892 if (!CONSP (hot_spot
))
24895 if (EQ (XCAR (hot_spot
), Qrect
))
24897 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
24898 Lisp_Object rect
= XCDR (hot_spot
);
24902 if (!CONSP (XCAR (rect
)))
24904 if (!CONSP (XCDR (rect
)))
24906 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
24908 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
24910 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
24912 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
24916 else if (EQ (XCAR (hot_spot
), Qcircle
))
24918 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
24919 Lisp_Object circ
= XCDR (hot_spot
);
24920 Lisp_Object lr
, lx0
, ly0
;
24922 && CONSP (XCAR (circ
))
24923 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
24924 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
24925 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
24927 double r
= XFLOATINT (lr
);
24928 double dx
= XINT (lx0
) - x
;
24929 double dy
= XINT (ly0
) - y
;
24930 return (dx
* dx
+ dy
* dy
<= r
* r
);
24933 else if (EQ (XCAR (hot_spot
), Qpoly
))
24935 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
24936 if (VECTORP (XCDR (hot_spot
)))
24938 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
24939 Lisp_Object
*poly
= v
->contents
;
24943 Lisp_Object lx
, ly
;
24946 /* Need an even number of coordinates, and at least 3 edges. */
24947 if (n
< 6 || n
& 1)
24950 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
24951 If count is odd, we are inside polygon. Pixels on edges
24952 may or may not be included depending on actual geometry of the
24954 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
24955 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
24957 x0
= XINT (lx
), y0
= XINT (ly
);
24958 for (i
= 0; i
< n
; i
+= 2)
24960 int x1
= x0
, y1
= y0
;
24961 if ((lx
= poly
[i
], !INTEGERP (lx
))
24962 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
24964 x0
= XINT (lx
), y0
= XINT (ly
);
24966 /* Does this segment cross the X line? */
24974 if (y
> y0
&& y
> y1
)
24976 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
24986 find_hot_spot (Lisp_Object map
, int x
, int y
)
24988 while (CONSP (map
))
24990 if (CONSP (XCAR (map
))
24991 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
24999 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25001 doc
: /* Lookup in image map MAP coordinates X and Y.
25002 An image map is an alist where each element has the format (AREA ID PLIST).
25003 An AREA is specified as either a rectangle, a circle, or a polygon:
25004 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25005 pixel coordinates of the upper left and bottom right corners.
25006 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25007 and the radius of the circle; r may be a float or integer.
25008 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25009 vector describes one corner in the polygon.
25010 Returns the alist element for the first matching AREA in MAP. */)
25011 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25019 return find_hot_spot (map
, XINT (x
), XINT (y
));
25023 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25025 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25027 /* Do not change cursor shape while dragging mouse. */
25028 if (!NILP (do_mouse_tracking
))
25031 if (!NILP (pointer
))
25033 if (EQ (pointer
, Qarrow
))
25034 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25035 else if (EQ (pointer
, Qhand
))
25036 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25037 else if (EQ (pointer
, Qtext
))
25038 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25039 else if (EQ (pointer
, intern ("hdrag")))
25040 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25041 #ifdef HAVE_X_WINDOWS
25042 else if (EQ (pointer
, intern ("vdrag")))
25043 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25045 else if (EQ (pointer
, intern ("hourglass")))
25046 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25047 else if (EQ (pointer
, Qmodeline
))
25048 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25050 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25053 if (cursor
!= No_Cursor
)
25054 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25057 #endif /* HAVE_WINDOW_SYSTEM */
25059 /* Take proper action when mouse has moved to the mode or header line
25060 or marginal area AREA of window W, x-position X and y-position Y.
25061 X is relative to the start of the text display area of W, so the
25062 width of bitmap areas and scroll bars must be subtracted to get a
25063 position relative to the start of the mode line. */
25066 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25067 enum window_part area
)
25069 struct window
*w
= XWINDOW (window
);
25070 struct frame
*f
= XFRAME (w
->frame
);
25071 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25072 #ifdef HAVE_WINDOW_SYSTEM
25073 Display_Info
*dpyinfo
;
25075 Cursor cursor
= No_Cursor
;
25076 Lisp_Object pointer
= Qnil
;
25077 int dx
, dy
, width
, height
;
25079 Lisp_Object string
, object
= Qnil
;
25080 Lisp_Object pos
, help
;
25082 Lisp_Object mouse_face
;
25083 int original_x_pixel
= x
;
25084 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25085 struct glyph_row
*row
;
25087 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25092 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25093 returns them in row/column units! */
25094 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25095 &object
, &dx
, &dy
, &width
, &height
);
25097 row
= (area
== ON_MODE_LINE
25098 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25099 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25101 /* Find the glyph under the mouse pointer. */
25102 if (row
->mode_line_p
&& row
->enabled_p
)
25104 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25105 end
= glyph
+ row
->used
[TEXT_AREA
];
25107 for (x0
= original_x_pixel
;
25108 glyph
< end
&& x0
>= glyph
->pixel_width
;
25110 x0
-= glyph
->pixel_width
;
25118 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25119 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25120 returns them in row/column units! */
25121 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25122 &object
, &dx
, &dy
, &width
, &height
);
25127 #ifdef HAVE_WINDOW_SYSTEM
25128 if (IMAGEP (object
))
25130 Lisp_Object image_map
, hotspot
;
25131 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25133 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25135 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25137 Lisp_Object area_id
, plist
;
25139 area_id
= XCAR (hotspot
);
25140 /* Could check AREA_ID to see if we enter/leave this hot-spot.
25141 If so, we could look for mouse-enter, mouse-leave
25142 properties in PLIST (and do something...). */
25143 hotspot
= XCDR (hotspot
);
25144 if (CONSP (hotspot
)
25145 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25147 pointer
= Fplist_get (plist
, Qpointer
);
25148 if (NILP (pointer
))
25150 help
= Fplist_get (plist
, Qhelp_echo
);
25153 help_echo_string
= help
;
25154 /* Is this correct? ++kfs */
25155 XSETWINDOW (help_echo_window
, w
);
25156 help_echo_object
= w
->buffer
;
25157 help_echo_pos
= charpos
;
25161 if (NILP (pointer
))
25162 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25164 #endif /* HAVE_WINDOW_SYSTEM */
25166 if (STRINGP (string
))
25168 pos
= make_number (charpos
);
25169 /* If we're on a string with `help-echo' text property, arrange
25170 for the help to be displayed. This is done by setting the
25171 global variable help_echo_string to the help string. */
25174 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25177 help_echo_string
= help
;
25178 XSETWINDOW (help_echo_window
, w
);
25179 help_echo_object
= string
;
25180 help_echo_pos
= charpos
;
25184 #ifdef HAVE_WINDOW_SYSTEM
25185 if (FRAME_WINDOW_P (f
))
25187 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25188 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25189 if (NILP (pointer
))
25190 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25192 /* Change the mouse pointer according to what is under X/Y. */
25194 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25197 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25198 if (!KEYMAPP (map
))
25199 map
= Fget_text_property (pos
, Qkeymap
, string
);
25200 if (!KEYMAPP (map
))
25201 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25206 /* Change the mouse face according to what is under X/Y. */
25207 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25208 if (!NILP (mouse_face
)
25209 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25214 struct glyph
* tmp_glyph
;
25218 int total_pixel_width
;
25219 EMACS_INT begpos
, endpos
, ignore
;
25223 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25224 Qmouse_face
, string
, Qnil
);
25230 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25232 endpos
= SCHARS (string
);
25236 /* Calculate the glyph position GPOS of GLYPH in the
25237 displayed string, relative to the beginning of the
25238 highlighted part of the string.
25240 Note: GPOS is different from CHARPOS. CHARPOS is the
25241 position of GLYPH in the internal string object. A mode
25242 line string format has structures which are converted to
25243 a flattened string by the Emacs Lisp interpreter. The
25244 internal string is an element of those structures. The
25245 displayed string is the flattened string. */
25246 tmp_glyph
= row_start_glyph
;
25247 while (tmp_glyph
< glyph
25248 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25249 && begpos
<= tmp_glyph
->charpos
25250 && tmp_glyph
->charpos
< endpos
)))
25252 gpos
= glyph
- tmp_glyph
;
25254 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25255 the highlighted part of the displayed string to which
25256 GLYPH belongs. Note: GSEQ_LENGTH is different from
25257 SCHARS (STRING), because the latter returns the length of
25258 the internal string. */
25259 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25261 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25262 && begpos
<= tmp_glyph
->charpos
25263 && tmp_glyph
->charpos
< endpos
));
25266 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25268 /* Calculate the total pixel width of all the glyphs between
25269 the beginning of the highlighted area and GLYPH. */
25270 total_pixel_width
= 0;
25271 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25272 total_pixel_width
+= tmp_glyph
->pixel_width
;
25274 /* Pre calculation of re-rendering position. Note: X is in
25275 column units here, after the call to mode_line_string or
25276 marginal_area_string. */
25278 vpos
= (area
== ON_MODE_LINE
25279 ? (w
->current_matrix
)->nrows
- 1
25282 /* If GLYPH's position is included in the region that is
25283 already drawn in mouse face, we have nothing to do. */
25284 if ( EQ (window
, hlinfo
->mouse_face_window
)
25285 && (!row
->reversed_p
25286 ? (hlinfo
->mouse_face_beg_col
<= hpos
25287 && hpos
< hlinfo
->mouse_face_end_col
)
25288 /* In R2L rows we swap BEG and END, see below. */
25289 : (hlinfo
->mouse_face_end_col
<= hpos
25290 && hpos
< hlinfo
->mouse_face_beg_col
))
25291 && hlinfo
->mouse_face_beg_row
== vpos
)
25294 if (clear_mouse_face (hlinfo
))
25295 cursor
= No_Cursor
;
25297 if (!row
->reversed_p
)
25299 hlinfo
->mouse_face_beg_col
= hpos
;
25300 hlinfo
->mouse_face_beg_x
= original_x_pixel
25301 - (total_pixel_width
+ dx
);
25302 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25303 hlinfo
->mouse_face_end_x
= 0;
25307 /* In R2L rows, show_mouse_face expects BEG and END
25308 coordinates to be swapped. */
25309 hlinfo
->mouse_face_end_col
= hpos
;
25310 hlinfo
->mouse_face_end_x
= original_x_pixel
25311 - (total_pixel_width
+ dx
);
25312 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25313 hlinfo
->mouse_face_beg_x
= 0;
25316 hlinfo
->mouse_face_beg_row
= vpos
;
25317 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25318 hlinfo
->mouse_face_beg_y
= 0;
25319 hlinfo
->mouse_face_end_y
= 0;
25320 hlinfo
->mouse_face_past_end
= 0;
25321 hlinfo
->mouse_face_window
= window
;
25323 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25329 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25331 if (NILP (pointer
))
25334 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25335 clear_mouse_face (hlinfo
);
25337 #ifdef HAVE_WINDOW_SYSTEM
25338 if (FRAME_WINDOW_P (f
))
25339 define_frame_cursor1 (f
, cursor
, pointer
);
25345 Take proper action when the mouse has moved to position X, Y on
25346 frame F as regards highlighting characters that have mouse-face
25347 properties. Also de-highlighting chars where the mouse was before.
25348 X and Y can be negative or out of range. */
25351 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25353 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25354 enum window_part part
;
25355 Lisp_Object window
;
25357 Cursor cursor
= No_Cursor
;
25358 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25361 /* When a menu is active, don't highlight because this looks odd. */
25362 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25363 if (popup_activated ())
25367 if (NILP (Vmouse_highlight
)
25368 || !f
->glyphs_initialized_p
25369 || f
->pointer_invisible
)
25372 hlinfo
->mouse_face_mouse_x
= x
;
25373 hlinfo
->mouse_face_mouse_y
= y
;
25374 hlinfo
->mouse_face_mouse_frame
= f
;
25376 if (hlinfo
->mouse_face_defer
)
25379 if (gc_in_progress
)
25381 hlinfo
->mouse_face_deferred_gc
= 1;
25385 /* Which window is that in? */
25386 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
25388 /* If we were displaying active text in another window, clear that.
25389 Also clear if we move out of text area in same window. */
25390 if (! EQ (window
, hlinfo
->mouse_face_window
)
25391 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
25392 && !NILP (hlinfo
->mouse_face_window
)))
25393 clear_mouse_face (hlinfo
);
25395 /* Not on a window -> return. */
25396 if (!WINDOWP (window
))
25399 /* Reset help_echo_string. It will get recomputed below. */
25400 help_echo_string
= Qnil
;
25402 /* Convert to window-relative pixel coordinates. */
25403 w
= XWINDOW (window
);
25404 frame_to_window_pixel_xy (w
, &x
, &y
);
25406 #ifdef HAVE_WINDOW_SYSTEM
25407 /* Handle tool-bar window differently since it doesn't display a
25409 if (EQ (window
, f
->tool_bar_window
))
25411 note_tool_bar_highlight (f
, x
, y
);
25416 /* Mouse is on the mode, header line or margin? */
25417 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
25418 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
25420 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
25424 #ifdef HAVE_WINDOW_SYSTEM
25425 if (part
== ON_VERTICAL_BORDER
)
25427 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25428 help_echo_string
= build_string ("drag-mouse-1: resize");
25430 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
25431 || part
== ON_SCROLL_BAR
)
25432 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25434 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25437 /* Are we in a window whose display is up to date?
25438 And verify the buffer's text has not changed. */
25439 b
= XBUFFER (w
->buffer
);
25440 if (part
== ON_TEXT
25441 && EQ (w
->window_end_valid
, w
->buffer
)
25442 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
25443 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
25445 int hpos
, vpos
, i
, dx
, dy
, area
;
25447 struct glyph
*glyph
;
25448 Lisp_Object object
;
25449 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
25450 Lisp_Object
*overlay_vec
= NULL
;
25452 struct buffer
*obuf
;
25453 EMACS_INT obegv
, ozv
;
25456 /* Find the glyph under X/Y. */
25457 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
25459 #ifdef HAVE_WINDOW_SYSTEM
25460 /* Look for :pointer property on image. */
25461 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25463 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25464 if (img
!= NULL
&& IMAGEP (img
->spec
))
25466 Lisp_Object image_map
, hotspot
;
25467 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
25469 && (hotspot
= find_hot_spot (image_map
,
25470 glyph
->slice
.img
.x
+ dx
,
25471 glyph
->slice
.img
.y
+ dy
),
25473 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25475 Lisp_Object area_id
, plist
;
25477 area_id
= XCAR (hotspot
);
25478 /* Could check AREA_ID to see if we enter/leave this hot-spot.
25479 If so, we could look for mouse-enter, mouse-leave
25480 properties in PLIST (and do something...). */
25481 hotspot
= XCDR (hotspot
);
25482 if (CONSP (hotspot
)
25483 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25485 pointer
= Fplist_get (plist
, Qpointer
);
25486 if (NILP (pointer
))
25488 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
25489 if (!NILP (help_echo_string
))
25491 help_echo_window
= window
;
25492 help_echo_object
= glyph
->object
;
25493 help_echo_pos
= glyph
->charpos
;
25497 if (NILP (pointer
))
25498 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
25501 #endif /* HAVE_WINDOW_SYSTEM */
25503 /* Clear mouse face if X/Y not over text. */
25505 || area
!= TEXT_AREA
25506 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
25507 /* Glyph's OBJECT is an integer for glyphs inserted by the
25508 display engine for its internal purposes, like truncation
25509 and continuation glyphs and blanks beyond the end of
25510 line's text on text terminals. If we are over such a
25511 glyph, we are not over any text. */
25512 || INTEGERP (glyph
->object
)
25513 /* R2L rows have a stretch glyph at their front, which
25514 stands for no text, whereas L2R rows have no glyphs at
25515 all beyond the end of text. Treat such stretch glyphs
25516 like we do with NULL glyphs in L2R rows. */
25517 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
25518 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
25519 && glyph
->type
== STRETCH_GLYPH
25520 && glyph
->avoid_cursor_p
))
25522 if (clear_mouse_face (hlinfo
))
25523 cursor
= No_Cursor
;
25524 #ifdef HAVE_WINDOW_SYSTEM
25525 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25527 if (area
!= TEXT_AREA
)
25528 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25530 pointer
= Vvoid_text_area_pointer
;
25536 pos
= glyph
->charpos
;
25537 object
= glyph
->object
;
25538 if (!STRINGP (object
) && !BUFFERP (object
))
25541 /* If we get an out-of-range value, return now; avoid an error. */
25542 if (BUFFERP (object
) && pos
> BUF_Z (b
))
25545 /* Make the window's buffer temporarily current for
25546 overlays_at and compute_char_face. */
25547 obuf
= current_buffer
;
25548 current_buffer
= b
;
25554 /* Is this char mouse-active or does it have help-echo? */
25555 position
= make_number (pos
);
25557 if (BUFFERP (object
))
25559 /* Put all the overlays we want in a vector in overlay_vec. */
25560 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
25561 /* Sort overlays into increasing priority order. */
25562 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
25567 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
25570 cursor
= No_Cursor
;
25572 /* Check mouse-face highlighting. */
25574 /* If there exists an overlay with mouse-face overlapping
25575 the one we are currently highlighting, we have to
25576 check if we enter the overlapping overlay, and then
25577 highlight only that. */
25578 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
25579 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
25581 /* Find the highest priority overlay with a mouse-face. */
25583 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
25585 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
25586 if (!NILP (mouse_face
))
25587 overlay
= overlay_vec
[i
];
25590 /* If we're highlighting the same overlay as before, there's
25591 no need to do that again. */
25592 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
25593 goto check_help_echo
;
25594 hlinfo
->mouse_face_overlay
= overlay
;
25596 /* Clear the display of the old active region, if any. */
25597 if (clear_mouse_face (hlinfo
))
25598 cursor
= No_Cursor
;
25600 /* If no overlay applies, get a text property. */
25601 if (NILP (overlay
))
25602 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
25604 /* Next, compute the bounds of the mouse highlighting and
25606 if (!NILP (mouse_face
) && STRINGP (object
))
25608 /* The mouse-highlighting comes from a display string
25609 with a mouse-face. */
25613 b
= Fprevious_single_property_change
25614 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
25615 e
= Fnext_single_property_change
25616 (position
, Qmouse_face
, object
, Qnil
);
25618 b
= make_number (0);
25620 e
= make_number (SCHARS (object
) - 1);
25621 mouse_face_from_string_pos (w
, hlinfo
, object
,
25622 XINT (b
), XINT (e
));
25623 hlinfo
->mouse_face_past_end
= 0;
25624 hlinfo
->mouse_face_window
= window
;
25625 hlinfo
->mouse_face_face_id
25626 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
25627 glyph
->face_id
, 1);
25628 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25629 cursor
= No_Cursor
;
25633 /* The mouse-highlighting, if any, comes from an overlay
25634 or text property in the buffer. */
25635 Lisp_Object buffer
, display_string
;
25637 if (STRINGP (object
))
25639 /* If we are on a display string with no mouse-face,
25640 check if the text under it has one. */
25641 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
25642 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25643 pos
= string_buffer_position (w
, object
, start
);
25646 mouse_face
= get_char_property_and_overlay
25647 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
25648 buffer
= w
->buffer
;
25649 display_string
= object
;
25655 display_string
= Qnil
;
25658 if (!NILP (mouse_face
))
25660 Lisp_Object before
, after
;
25661 Lisp_Object before_string
, after_string
;
25662 /* To correctly find the limits of mouse highlight
25663 in a bidi-reordered buffer, we must not use the
25664 optimization of limiting the search in
25665 previous-single-property-change and
25666 next-single-property-change, because
25667 rows_from_pos_range needs the real start and end
25668 positions to DTRT in this case. That's because
25669 the first row visible in a window does not
25670 necessarily display the character whose position
25671 is the smallest. */
25673 NILP (XBUFFER (buffer
)->bidi_display_reordering
)
25674 ? Fmarker_position (w
->start
)
25677 NILP (XBUFFER (buffer
)->bidi_display_reordering
)
25678 ? make_number (BUF_Z (XBUFFER (buffer
))
25679 - XFASTINT (w
->window_end_pos
))
25682 if (NILP (overlay
))
25684 /* Handle the text property case. */
25685 before
= Fprevious_single_property_change
25686 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
25687 after
= Fnext_single_property_change
25688 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
25689 before_string
= after_string
= Qnil
;
25693 /* Handle the overlay case. */
25694 before
= Foverlay_start (overlay
);
25695 after
= Foverlay_end (overlay
);
25696 before_string
= Foverlay_get (overlay
, Qbefore_string
);
25697 after_string
= Foverlay_get (overlay
, Qafter_string
);
25699 if (!STRINGP (before_string
)) before_string
= Qnil
;
25700 if (!STRINGP (after_string
)) after_string
= Qnil
;
25703 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
25706 before_string
, after_string
,
25708 cursor
= No_Cursor
;
25715 /* Look for a `help-echo' property. */
25716 if (NILP (help_echo_string
)) {
25717 Lisp_Object help
, overlay
;
25719 /* Check overlays first. */
25720 help
= overlay
= Qnil
;
25721 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
25723 overlay
= overlay_vec
[i
];
25724 help
= Foverlay_get (overlay
, Qhelp_echo
);
25729 help_echo_string
= help
;
25730 help_echo_window
= window
;
25731 help_echo_object
= overlay
;
25732 help_echo_pos
= pos
;
25736 Lisp_Object object
= glyph
->object
;
25737 EMACS_INT charpos
= glyph
->charpos
;
25739 /* Try text properties. */
25740 if (STRINGP (object
)
25742 && charpos
< SCHARS (object
))
25744 help
= Fget_text_property (make_number (charpos
),
25745 Qhelp_echo
, object
);
25748 /* If the string itself doesn't specify a help-echo,
25749 see if the buffer text ``under'' it does. */
25750 struct glyph_row
*r
25751 = MATRIX_ROW (w
->current_matrix
, vpos
);
25752 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25753 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
25756 help
= Fget_char_property (make_number (pos
),
25757 Qhelp_echo
, w
->buffer
);
25761 object
= w
->buffer
;
25766 else if (BUFFERP (object
)
25769 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
25774 help_echo_string
= help
;
25775 help_echo_window
= window
;
25776 help_echo_object
= object
;
25777 help_echo_pos
= charpos
;
25782 #ifdef HAVE_WINDOW_SYSTEM
25783 /* Look for a `pointer' property. */
25784 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25786 /* Check overlays first. */
25787 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
25788 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
25790 if (NILP (pointer
))
25792 Lisp_Object object
= glyph
->object
;
25793 EMACS_INT charpos
= glyph
->charpos
;
25795 /* Try text properties. */
25796 if (STRINGP (object
)
25798 && charpos
< SCHARS (object
))
25800 pointer
= Fget_text_property (make_number (charpos
),
25802 if (NILP (pointer
))
25804 /* If the string itself doesn't specify a pointer,
25805 see if the buffer text ``under'' it does. */
25806 struct glyph_row
*r
25807 = MATRIX_ROW (w
->current_matrix
, vpos
);
25808 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25809 EMACS_INT pos
= string_buffer_position (w
, object
,
25812 pointer
= Fget_char_property (make_number (pos
),
25813 Qpointer
, w
->buffer
);
25816 else if (BUFFERP (object
)
25819 pointer
= Fget_text_property (make_number (charpos
),
25823 #endif /* HAVE_WINDOW_SYSTEM */
25827 current_buffer
= obuf
;
25832 #ifdef HAVE_WINDOW_SYSTEM
25833 if (FRAME_WINDOW_P (f
))
25834 define_frame_cursor1 (f
, cursor
, pointer
);
25836 /* This is here to prevent a compiler error, about "label at end of
25837 compound statement". */
25844 Clear any mouse-face on window W. This function is part of the
25845 redisplay interface, and is called from try_window_id and similar
25846 functions to ensure the mouse-highlight is off. */
25849 x_clear_window_mouse_face (struct window
*w
)
25851 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25852 Lisp_Object window
;
25855 XSETWINDOW (window
, w
);
25856 if (EQ (window
, hlinfo
->mouse_face_window
))
25857 clear_mouse_face (hlinfo
);
25863 Just discard the mouse face information for frame F, if any.
25864 This is used when the size of F is changed. */
25867 cancel_mouse_face (struct frame
*f
)
25869 Lisp_Object window
;
25870 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25872 window
= hlinfo
->mouse_face_window
;
25873 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
25875 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25876 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25877 hlinfo
->mouse_face_window
= Qnil
;
25883 /***********************************************************************
25885 ***********************************************************************/
25887 #ifdef HAVE_WINDOW_SYSTEM
25889 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
25890 which intersects rectangle R. R is in window-relative coordinates. */
25893 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
25894 enum glyph_row_area area
)
25896 struct glyph
*first
= row
->glyphs
[area
];
25897 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
25898 struct glyph
*last
;
25899 int first_x
, start_x
, x
;
25901 if (area
== TEXT_AREA
&& row
->fill_line_p
)
25902 /* If row extends face to end of line write the whole line. */
25903 draw_glyphs (w
, 0, row
, area
,
25904 0, row
->used
[area
],
25905 DRAW_NORMAL_TEXT
, 0);
25908 /* Set START_X to the window-relative start position for drawing glyphs of
25909 AREA. The first glyph of the text area can be partially visible.
25910 The first glyphs of other areas cannot. */
25911 start_x
= window_box_left_offset (w
, area
);
25913 if (area
== TEXT_AREA
)
25916 /* Find the first glyph that must be redrawn. */
25918 && x
+ first
->pixel_width
< r
->x
)
25920 x
+= first
->pixel_width
;
25924 /* Find the last one. */
25928 && x
< r
->x
+ r
->width
)
25930 x
+= last
->pixel_width
;
25936 draw_glyphs (w
, first_x
- start_x
, row
, area
,
25937 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
25938 DRAW_NORMAL_TEXT
, 0);
25943 /* Redraw the parts of the glyph row ROW on window W intersecting
25944 rectangle R. R is in window-relative coordinates. Value is
25945 non-zero if mouse-face was overwritten. */
25948 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
25950 xassert (row
->enabled_p
);
25952 if (row
->mode_line_p
|| w
->pseudo_window_p
)
25953 draw_glyphs (w
, 0, row
, TEXT_AREA
,
25954 0, row
->used
[TEXT_AREA
],
25955 DRAW_NORMAL_TEXT
, 0);
25958 if (row
->used
[LEFT_MARGIN_AREA
])
25959 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
25960 if (row
->used
[TEXT_AREA
])
25961 expose_area (w
, row
, r
, TEXT_AREA
);
25962 if (row
->used
[RIGHT_MARGIN_AREA
])
25963 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
25964 draw_row_fringe_bitmaps (w
, row
);
25967 return row
->mouse_face_p
;
25971 /* Redraw those parts of glyphs rows during expose event handling that
25972 overlap other rows. Redrawing of an exposed line writes over parts
25973 of lines overlapping that exposed line; this function fixes that.
25975 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
25976 row in W's current matrix that is exposed and overlaps other rows.
25977 LAST_OVERLAPPING_ROW is the last such row. */
25980 expose_overlaps (struct window
*w
,
25981 struct glyph_row
*first_overlapping_row
,
25982 struct glyph_row
*last_overlapping_row
,
25985 struct glyph_row
*row
;
25987 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
25988 if (row
->overlapping_p
)
25990 xassert (row
->enabled_p
&& !row
->mode_line_p
);
25993 if (row
->used
[LEFT_MARGIN_AREA
])
25994 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
25996 if (row
->used
[TEXT_AREA
])
25997 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
25999 if (row
->used
[RIGHT_MARGIN_AREA
])
26000 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26006 /* Return non-zero if W's cursor intersects rectangle R. */
26009 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26011 XRectangle cr
, result
;
26012 struct glyph
*cursor_glyph
;
26013 struct glyph_row
*row
;
26015 if (w
->phys_cursor
.vpos
>= 0
26016 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26017 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26019 && row
->cursor_in_fringe_p
)
26021 /* Cursor is in the fringe. */
26022 cr
.x
= window_box_right_offset (w
,
26023 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26024 ? RIGHT_MARGIN_AREA
26027 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26028 cr
.height
= row
->height
;
26029 return x_intersect_rectangles (&cr
, r
, &result
);
26032 cursor_glyph
= get_phys_cursor_glyph (w
);
26035 /* r is relative to W's box, but w->phys_cursor.x is relative
26036 to left edge of W's TEXT area. Adjust it. */
26037 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26038 cr
.y
= w
->phys_cursor
.y
;
26039 cr
.width
= cursor_glyph
->pixel_width
;
26040 cr
.height
= w
->phys_cursor_height
;
26041 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26042 I assume the effect is the same -- and this is portable. */
26043 return x_intersect_rectangles (&cr
, r
, &result
);
26045 /* If we don't understand the format, pretend we're not in the hot-spot. */
26051 Draw a vertical window border to the right of window W if W doesn't
26052 have vertical scroll bars. */
26055 x_draw_vertical_border (struct window
*w
)
26057 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26059 /* We could do better, if we knew what type of scroll-bar the adjacent
26060 windows (on either side) have... But we don't :-(
26061 However, I think this works ok. ++KFS 2003-04-25 */
26063 /* Redraw borders between horizontally adjacent windows. Don't
26064 do it for frames with vertical scroll bars because either the
26065 right scroll bar of a window, or the left scroll bar of its
26066 neighbor will suffice as a border. */
26067 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26070 if (!WINDOW_RIGHTMOST_P (w
)
26071 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26073 int x0
, x1
, y0
, y1
;
26075 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26078 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26081 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26083 else if (!WINDOW_LEFTMOST_P (w
)
26084 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26086 int x0
, x1
, y0
, y1
;
26088 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26091 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26094 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26099 /* Redraw the part of window W intersection rectangle FR. Pixel
26100 coordinates in FR are frame-relative. Call this function with
26101 input blocked. Value is non-zero if the exposure overwrites
26105 expose_window (struct window
*w
, XRectangle
*fr
)
26107 struct frame
*f
= XFRAME (w
->frame
);
26109 int mouse_face_overwritten_p
= 0;
26111 /* If window is not yet fully initialized, do nothing. This can
26112 happen when toolkit scroll bars are used and a window is split.
26113 Reconfiguring the scroll bar will generate an expose for a newly
26115 if (w
->current_matrix
== NULL
)
26118 /* When we're currently updating the window, display and current
26119 matrix usually don't agree. Arrange for a thorough display
26121 if (w
== updated_window
)
26123 SET_FRAME_GARBAGED (f
);
26127 /* Frame-relative pixel rectangle of W. */
26128 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26129 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26130 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26131 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26133 if (x_intersect_rectangles (fr
, &wr
, &r
))
26135 int yb
= window_text_bottom_y (w
);
26136 struct glyph_row
*row
;
26137 int cursor_cleared_p
;
26138 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26140 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26141 r
.x
, r
.y
, r
.width
, r
.height
));
26143 /* Convert to window coordinates. */
26144 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26145 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26147 /* Turn off the cursor. */
26148 if (!w
->pseudo_window_p
26149 && phys_cursor_in_rect_p (w
, &r
))
26151 x_clear_cursor (w
);
26152 cursor_cleared_p
= 1;
26155 cursor_cleared_p
= 0;
26157 /* Update lines intersecting rectangle R. */
26158 first_overlapping_row
= last_overlapping_row
= NULL
;
26159 for (row
= w
->current_matrix
->rows
;
26164 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26166 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26167 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26168 || (r
.y
>= y0
&& r
.y
< y1
)
26169 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26171 /* A header line may be overlapping, but there is no need
26172 to fix overlapping areas for them. KFS 2005-02-12 */
26173 if (row
->overlapping_p
&& !row
->mode_line_p
)
26175 if (first_overlapping_row
== NULL
)
26176 first_overlapping_row
= row
;
26177 last_overlapping_row
= row
;
26181 if (expose_line (w
, row
, &r
))
26182 mouse_face_overwritten_p
= 1;
26185 else if (row
->overlapping_p
)
26187 /* We must redraw a row overlapping the exposed area. */
26189 ? y0
+ row
->phys_height
> r
.y
26190 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26192 if (first_overlapping_row
== NULL
)
26193 first_overlapping_row
= row
;
26194 last_overlapping_row
= row
;
26202 /* Display the mode line if there is one. */
26203 if (WINDOW_WANTS_MODELINE_P (w
)
26204 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26206 && row
->y
< r
.y
+ r
.height
)
26208 if (expose_line (w
, row
, &r
))
26209 mouse_face_overwritten_p
= 1;
26212 if (!w
->pseudo_window_p
)
26214 /* Fix the display of overlapping rows. */
26215 if (first_overlapping_row
)
26216 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26219 /* Draw border between windows. */
26220 x_draw_vertical_border (w
);
26222 /* Turn the cursor on again. */
26223 if (cursor_cleared_p
)
26224 update_window_cursor (w
, 1);
26228 return mouse_face_overwritten_p
;
26233 /* Redraw (parts) of all windows in the window tree rooted at W that
26234 intersect R. R contains frame pixel coordinates. Value is
26235 non-zero if the exposure overwrites mouse-face. */
26238 expose_window_tree (struct window
*w
, XRectangle
*r
)
26240 struct frame
*f
= XFRAME (w
->frame
);
26241 int mouse_face_overwritten_p
= 0;
26243 while (w
&& !FRAME_GARBAGED_P (f
))
26245 if (!NILP (w
->hchild
))
26246 mouse_face_overwritten_p
26247 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26248 else if (!NILP (w
->vchild
))
26249 mouse_face_overwritten_p
26250 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26252 mouse_face_overwritten_p
|= expose_window (w
, r
);
26254 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26257 return mouse_face_overwritten_p
;
26262 Redisplay an exposed area of frame F. X and Y are the upper-left
26263 corner of the exposed rectangle. W and H are width and height of
26264 the exposed area. All are pixel values. W or H zero means redraw
26265 the entire frame. */
26268 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26271 int mouse_face_overwritten_p
= 0;
26273 TRACE ((stderr
, "expose_frame "));
26275 /* No need to redraw if frame will be redrawn soon. */
26276 if (FRAME_GARBAGED_P (f
))
26278 TRACE ((stderr
, " garbaged\n"));
26282 /* If basic faces haven't been realized yet, there is no point in
26283 trying to redraw anything. This can happen when we get an expose
26284 event while Emacs is starting, e.g. by moving another window. */
26285 if (FRAME_FACE_CACHE (f
) == NULL
26286 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26288 TRACE ((stderr
, " no faces\n"));
26292 if (w
== 0 || h
== 0)
26295 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26296 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26306 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26307 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26309 if (WINDOWP (f
->tool_bar_window
))
26310 mouse_face_overwritten_p
26311 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26313 #ifdef HAVE_X_WINDOWS
26315 #ifndef USE_X_TOOLKIT
26316 if (WINDOWP (f
->menu_bar_window
))
26317 mouse_face_overwritten_p
26318 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26319 #endif /* not USE_X_TOOLKIT */
26323 /* Some window managers support a focus-follows-mouse style with
26324 delayed raising of frames. Imagine a partially obscured frame,
26325 and moving the mouse into partially obscured mouse-face on that
26326 frame. The visible part of the mouse-face will be highlighted,
26327 then the WM raises the obscured frame. With at least one WM, KDE
26328 2.1, Emacs is not getting any event for the raising of the frame
26329 (even tried with SubstructureRedirectMask), only Expose events.
26330 These expose events will draw text normally, i.e. not
26331 highlighted. Which means we must redo the highlight here.
26332 Subsume it under ``we love X''. --gerd 2001-08-15 */
26333 /* Included in Windows version because Windows most likely does not
26334 do the right thing if any third party tool offers
26335 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26336 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26338 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26339 if (f
== hlinfo
->mouse_face_mouse_frame
)
26341 int x
= hlinfo
->mouse_face_mouse_x
;
26342 int y
= hlinfo
->mouse_face_mouse_y
;
26343 clear_mouse_face (hlinfo
);
26344 note_mouse_highlight (f
, x
, y
);
26351 Determine the intersection of two rectangles R1 and R2. Return
26352 the intersection in *RESULT. Value is non-zero if RESULT is not
26356 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26358 XRectangle
*left
, *right
;
26359 XRectangle
*upper
, *lower
;
26360 int intersection_p
= 0;
26362 /* Rearrange so that R1 is the left-most rectangle. */
26364 left
= r1
, right
= r2
;
26366 left
= r2
, right
= r1
;
26368 /* X0 of the intersection is right.x0, if this is inside R1,
26369 otherwise there is no intersection. */
26370 if (right
->x
<= left
->x
+ left
->width
)
26372 result
->x
= right
->x
;
26374 /* The right end of the intersection is the minimum of the
26375 the right ends of left and right. */
26376 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26379 /* Same game for Y. */
26381 upper
= r1
, lower
= r2
;
26383 upper
= r2
, lower
= r1
;
26385 /* The upper end of the intersection is lower.y0, if this is inside
26386 of upper. Otherwise, there is no intersection. */
26387 if (lower
->y
<= upper
->y
+ upper
->height
)
26389 result
->y
= lower
->y
;
26391 /* The lower end of the intersection is the minimum of the lower
26392 ends of upper and lower. */
26393 result
->height
= (min (lower
->y
+ lower
->height
,
26394 upper
->y
+ upper
->height
)
26396 intersection_p
= 1;
26400 return intersection_p
;
26403 #endif /* HAVE_WINDOW_SYSTEM */
26406 /***********************************************************************
26408 ***********************************************************************/
26411 syms_of_xdisp (void)
26413 Vwith_echo_area_save_vector
= Qnil
;
26414 staticpro (&Vwith_echo_area_save_vector
);
26416 Vmessage_stack
= Qnil
;
26417 staticpro (&Vmessage_stack
);
26419 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
26420 staticpro (&Qinhibit_redisplay
);
26422 message_dolog_marker1
= Fmake_marker ();
26423 staticpro (&message_dolog_marker1
);
26424 message_dolog_marker2
= Fmake_marker ();
26425 staticpro (&message_dolog_marker2
);
26426 message_dolog_marker3
= Fmake_marker ();
26427 staticpro (&message_dolog_marker3
);
26430 defsubr (&Sdump_frame_glyph_matrix
);
26431 defsubr (&Sdump_glyph_matrix
);
26432 defsubr (&Sdump_glyph_row
);
26433 defsubr (&Sdump_tool_bar_row
);
26434 defsubr (&Strace_redisplay
);
26435 defsubr (&Strace_to_stderr
);
26437 #ifdef HAVE_WINDOW_SYSTEM
26438 defsubr (&Stool_bar_lines_needed
);
26439 defsubr (&Slookup_image_map
);
26441 defsubr (&Sformat_mode_line
);
26442 defsubr (&Sinvisible_p
);
26443 defsubr (&Scurrent_bidi_paragraph_direction
);
26445 staticpro (&Qmenu_bar_update_hook
);
26446 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
26448 staticpro (&Qoverriding_terminal_local_map
);
26449 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
26451 staticpro (&Qoverriding_local_map
);
26452 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
26454 staticpro (&Qwindow_scroll_functions
);
26455 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
26457 staticpro (&Qwindow_text_change_functions
);
26458 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
26460 staticpro (&Qredisplay_end_trigger_functions
);
26461 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
26463 staticpro (&Qinhibit_point_motion_hooks
);
26464 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
26466 Qeval
= intern_c_string ("eval");
26467 staticpro (&Qeval
);
26469 QCdata
= intern_c_string (":data");
26470 staticpro (&QCdata
);
26471 Qdisplay
= intern_c_string ("display");
26472 staticpro (&Qdisplay
);
26473 Qspace_width
= intern_c_string ("space-width");
26474 staticpro (&Qspace_width
);
26475 Qraise
= intern_c_string ("raise");
26476 staticpro (&Qraise
);
26477 Qslice
= intern_c_string ("slice");
26478 staticpro (&Qslice
);
26479 Qspace
= intern_c_string ("space");
26480 staticpro (&Qspace
);
26481 Qmargin
= intern_c_string ("margin");
26482 staticpro (&Qmargin
);
26483 Qpointer
= intern_c_string ("pointer");
26484 staticpro (&Qpointer
);
26485 Qleft_margin
= intern_c_string ("left-margin");
26486 staticpro (&Qleft_margin
);
26487 Qright_margin
= intern_c_string ("right-margin");
26488 staticpro (&Qright_margin
);
26489 Qcenter
= intern_c_string ("center");
26490 staticpro (&Qcenter
);
26491 Qline_height
= intern_c_string ("line-height");
26492 staticpro (&Qline_height
);
26493 QCalign_to
= intern_c_string (":align-to");
26494 staticpro (&QCalign_to
);
26495 QCrelative_width
= intern_c_string (":relative-width");
26496 staticpro (&QCrelative_width
);
26497 QCrelative_height
= intern_c_string (":relative-height");
26498 staticpro (&QCrelative_height
);
26499 QCeval
= intern_c_string (":eval");
26500 staticpro (&QCeval
);
26501 QCpropertize
= intern_c_string (":propertize");
26502 staticpro (&QCpropertize
);
26503 QCfile
= intern_c_string (":file");
26504 staticpro (&QCfile
);
26505 Qfontified
= intern_c_string ("fontified");
26506 staticpro (&Qfontified
);
26507 Qfontification_functions
= intern_c_string ("fontification-functions");
26508 staticpro (&Qfontification_functions
);
26509 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
26510 staticpro (&Qtrailing_whitespace
);
26511 Qescape_glyph
= intern_c_string ("escape-glyph");
26512 staticpro (&Qescape_glyph
);
26513 Qnobreak_space
= intern_c_string ("nobreak-space");
26514 staticpro (&Qnobreak_space
);
26515 Qimage
= intern_c_string ("image");
26516 staticpro (&Qimage
);
26517 Qtext
= intern_c_string ("text");
26518 staticpro (&Qtext
);
26519 Qboth
= intern_c_string ("both");
26520 staticpro (&Qboth
);
26521 Qboth_horiz
= intern_c_string ("both-horiz");
26522 staticpro (&Qboth_horiz
);
26523 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
26524 staticpro (&Qtext_image_horiz
);
26525 QCmap
= intern_c_string (":map");
26526 staticpro (&QCmap
);
26527 QCpointer
= intern_c_string (":pointer");
26528 staticpro (&QCpointer
);
26529 Qrect
= intern_c_string ("rect");
26530 staticpro (&Qrect
);
26531 Qcircle
= intern_c_string ("circle");
26532 staticpro (&Qcircle
);
26533 Qpoly
= intern_c_string ("poly");
26534 staticpro (&Qpoly
);
26535 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
26536 staticpro (&Qmessage_truncate_lines
);
26537 Qgrow_only
= intern_c_string ("grow-only");
26538 staticpro (&Qgrow_only
);
26539 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
26540 staticpro (&Qinhibit_menubar_update
);
26541 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
26542 staticpro (&Qinhibit_eval_during_redisplay
);
26543 Qposition
= intern_c_string ("position");
26544 staticpro (&Qposition
);
26545 Qbuffer_position
= intern_c_string ("buffer-position");
26546 staticpro (&Qbuffer_position
);
26547 Qobject
= intern_c_string ("object");
26548 staticpro (&Qobject
);
26549 Qbar
= intern_c_string ("bar");
26551 Qhbar
= intern_c_string ("hbar");
26552 staticpro (&Qhbar
);
26553 Qbox
= intern_c_string ("box");
26555 Qhollow
= intern_c_string ("hollow");
26556 staticpro (&Qhollow
);
26557 Qhand
= intern_c_string ("hand");
26558 staticpro (&Qhand
);
26559 Qarrow
= intern_c_string ("arrow");
26560 staticpro (&Qarrow
);
26561 Qtext
= intern_c_string ("text");
26562 staticpro (&Qtext
);
26563 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
26564 staticpro (&Qrisky_local_variable
);
26565 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
26566 staticpro (&Qinhibit_free_realized_faces
);
26568 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
26569 Fcons (intern_c_string ("void-variable"), Qnil
)),
26571 staticpro (&list_of_error
);
26573 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
26574 staticpro (&Qlast_arrow_position
);
26575 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
26576 staticpro (&Qlast_arrow_string
);
26578 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
26579 staticpro (&Qoverlay_arrow_string
);
26580 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
26581 staticpro (&Qoverlay_arrow_bitmap
);
26583 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
26584 staticpro (&echo_buffer
[0]);
26585 staticpro (&echo_buffer
[1]);
26587 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
26588 staticpro (&echo_area_buffer
[0]);
26589 staticpro (&echo_area_buffer
[1]);
26591 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
26592 staticpro (&Vmessages_buffer_name
);
26594 mode_line_proptrans_alist
= Qnil
;
26595 staticpro (&mode_line_proptrans_alist
);
26596 mode_line_string_list
= Qnil
;
26597 staticpro (&mode_line_string_list
);
26598 mode_line_string_face
= Qnil
;
26599 staticpro (&mode_line_string_face
);
26600 mode_line_string_face_prop
= Qnil
;
26601 staticpro (&mode_line_string_face_prop
);
26602 Vmode_line_unwind_vector
= Qnil
;
26603 staticpro (&Vmode_line_unwind_vector
);
26605 help_echo_string
= Qnil
;
26606 staticpro (&help_echo_string
);
26607 help_echo_object
= Qnil
;
26608 staticpro (&help_echo_object
);
26609 help_echo_window
= Qnil
;
26610 staticpro (&help_echo_window
);
26611 previous_help_echo_string
= Qnil
;
26612 staticpro (&previous_help_echo_string
);
26613 help_echo_pos
= -1;
26615 Qright_to_left
= intern_c_string ("right-to-left");
26616 staticpro (&Qright_to_left
);
26617 Qleft_to_right
= intern_c_string ("left-to-right");
26618 staticpro (&Qleft_to_right
);
26620 #ifdef HAVE_WINDOW_SYSTEM
26621 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
26622 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
26623 For example, if a block cursor is over a tab, it will be drawn as
26624 wide as that tab on the display. */);
26625 x_stretch_cursor_p
= 0;
26628 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
26629 doc
: /* *Non-nil means highlight trailing whitespace.
26630 The face used for trailing whitespace is `trailing-whitespace'. */);
26631 Vshow_trailing_whitespace
= Qnil
;
26633 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
26634 doc
: /* *Control highlighting of nobreak space and soft hyphen.
26635 A value of t means highlight the character itself (for nobreak space,
26636 use face `nobreak-space').
26637 A value of nil means no highlighting.
26638 Other values mean display the escape glyph followed by an ordinary
26639 space or ordinary hyphen. */);
26640 Vnobreak_char_display
= Qt
;
26642 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
26643 doc
: /* *The pointer shape to show in void text areas.
26644 A value of nil means to show the text pointer. Other options are `arrow',
26645 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
26646 Vvoid_text_area_pointer
= Qarrow
;
26648 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
26649 doc
: /* Non-nil means don't actually do any redisplay.
26650 This is used for internal purposes. */);
26651 Vinhibit_redisplay
= Qnil
;
26653 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
26654 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
26655 Vglobal_mode_string
= Qnil
;
26657 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
26658 doc
: /* Marker for where to display an arrow on top of the buffer text.
26659 This must be the beginning of a line in order to work.
26660 See also `overlay-arrow-string'. */);
26661 Voverlay_arrow_position
= Qnil
;
26663 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
26664 doc
: /* String to display as an arrow in non-window frames.
26665 See also `overlay-arrow-position'. */);
26666 Voverlay_arrow_string
= make_pure_c_string ("=>");
26668 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
26669 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
26670 The symbols on this list are examined during redisplay to determine
26671 where to display overlay arrows. */);
26672 Voverlay_arrow_variable_list
26673 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
26675 DEFVAR_INT ("scroll-step", &scroll_step
,
26676 doc
: /* *The number of lines to try scrolling a window by when point moves out.
26677 If that fails to bring point back on frame, point is centered instead.
26678 If this is zero, point is always centered after it moves off frame.
26679 If you want scrolling to always be a line at a time, you should set
26680 `scroll-conservatively' to a large value rather than set this to 1. */);
26682 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
26683 doc
: /* *Scroll up to this many lines, to bring point back on screen.
26684 If point moves off-screen, redisplay will scroll by up to
26685 `scroll-conservatively' lines in order to bring point just barely
26686 onto the screen again. If that cannot be done, then redisplay
26687 recenters point as usual.
26689 A value of zero means always recenter point if it moves off screen. */);
26690 scroll_conservatively
= 0;
26692 DEFVAR_INT ("scroll-margin", &scroll_margin
,
26693 doc
: /* *Number of lines of margin at the top and bottom of a window.
26694 Recenter the window whenever point gets within this many lines
26695 of the top or bottom of the window. */);
26698 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
26699 doc
: /* Pixels per inch value for non-window system displays.
26700 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
26701 Vdisplay_pixels_per_inch
= make_float (72.0);
26704 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
26707 DEFVAR_LISP ("truncate-partial-width-windows",
26708 &Vtruncate_partial_width_windows
,
26709 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
26710 For an integer value, truncate lines in each window narrower than the
26711 full frame width, provided the window width is less than that integer;
26712 otherwise, respect the value of `truncate-lines'.
26714 For any other non-nil value, truncate lines in all windows that do
26715 not span the full frame width.
26717 A value of nil means to respect the value of `truncate-lines'.
26719 If `word-wrap' is enabled, you might want to reduce this. */);
26720 Vtruncate_partial_width_windows
= make_number (50);
26722 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
26723 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
26724 Any other value means to use the appropriate face, `mode-line',
26725 `header-line', or `menu' respectively. */);
26726 mode_line_inverse_video
= 1;
26728 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
26729 doc
: /* *Maximum buffer size for which line number should be displayed.
26730 If the buffer is bigger than this, the line number does not appear
26731 in the mode line. A value of nil means no limit. */);
26732 Vline_number_display_limit
= Qnil
;
26734 DEFVAR_INT ("line-number-display-limit-width",
26735 &line_number_display_limit_width
,
26736 doc
: /* *Maximum line width (in characters) for line number display.
26737 If the average length of the lines near point is bigger than this, then the
26738 line number may be omitted from the mode line. */);
26739 line_number_display_limit_width
= 200;
26741 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
26742 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
26743 highlight_nonselected_windows
= 0;
26745 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
26746 doc
: /* Non-nil if more than one frame is visible on this display.
26747 Minibuffer-only frames don't count, but iconified frames do.
26748 This variable is not guaranteed to be accurate except while processing
26749 `frame-title-format' and `icon-title-format'. */);
26751 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
26752 doc
: /* Template for displaying the title bar of visible frames.
26753 \(Assuming the window manager supports this feature.)
26755 This variable has the same structure as `mode-line-format', except that
26756 the %c and %l constructs are ignored. It is used only on frames for
26757 which no explicit name has been set \(see `modify-frame-parameters'). */);
26759 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
26760 doc
: /* Template for displaying the title bar of an iconified frame.
26761 \(Assuming the window manager supports this feature.)
26762 This variable has the same structure as `mode-line-format' (which see),
26763 and is used only on frames for which no explicit name has been set
26764 \(see `modify-frame-parameters'). */);
26766 = Vframe_title_format
26767 = pure_cons (intern_c_string ("multiple-frames"),
26768 pure_cons (make_pure_c_string ("%b"),
26769 pure_cons (pure_cons (empty_unibyte_string
,
26770 pure_cons (intern_c_string ("invocation-name"),
26771 pure_cons (make_pure_c_string ("@"),
26772 pure_cons (intern_c_string ("system-name"),
26776 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
26777 doc
: /* Maximum number of lines to keep in the message log buffer.
26778 If nil, disable message logging. If t, log messages but don't truncate
26779 the buffer when it becomes large. */);
26780 Vmessage_log_max
= make_number (100);
26782 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
26783 doc
: /* Functions called before redisplay, if window sizes have changed.
26784 The value should be a list of functions that take one argument.
26785 Just before redisplay, for each frame, if any of its windows have changed
26786 size since the last redisplay, or have been split or deleted,
26787 all the functions in the list are called, with the frame as argument. */);
26788 Vwindow_size_change_functions
= Qnil
;
26790 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
26791 doc
: /* List of functions to call before redisplaying a window with scrolling.
26792 Each function is called with two arguments, the window and its new
26793 display-start position. Note that these functions are also called by
26794 `set-window-buffer'. Also note that the value of `window-end' is not
26795 valid when these functions are called. */);
26796 Vwindow_scroll_functions
= Qnil
;
26798 DEFVAR_LISP ("window-text-change-functions",
26799 &Vwindow_text_change_functions
,
26800 doc
: /* Functions to call in redisplay when text in the window might change. */);
26801 Vwindow_text_change_functions
= Qnil
;
26803 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
26804 doc
: /* Functions called when redisplay of a window reaches the end trigger.
26805 Each function is called with two arguments, the window and the end trigger value.
26806 See `set-window-redisplay-end-trigger'. */);
26807 Vredisplay_end_trigger_functions
= Qnil
;
26809 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
26810 doc
: /* *Non-nil means autoselect window with mouse pointer.
26811 If nil, do not autoselect windows.
26812 A positive number means delay autoselection by that many seconds: a
26813 window is autoselected only after the mouse has remained in that
26814 window for the duration of the delay.
26815 A negative number has a similar effect, but causes windows to be
26816 autoselected only after the mouse has stopped moving. \(Because of
26817 the way Emacs compares mouse events, you will occasionally wait twice
26818 that time before the window gets selected.\)
26819 Any other value means to autoselect window instantaneously when the
26820 mouse pointer enters it.
26822 Autoselection selects the minibuffer only if it is active, and never
26823 unselects the minibuffer if it is active.
26825 When customizing this variable make sure that the actual value of
26826 `focus-follows-mouse' matches the behavior of your window manager. */);
26827 Vmouse_autoselect_window
= Qnil
;
26829 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
26830 doc
: /* *Non-nil means automatically resize tool-bars.
26831 This dynamically changes the tool-bar's height to the minimum height
26832 that is needed to make all tool-bar items visible.
26833 If value is `grow-only', the tool-bar's height is only increased
26834 automatically; to decrease the tool-bar height, use \\[recenter]. */);
26835 Vauto_resize_tool_bars
= Qt
;
26837 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
26838 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
26839 auto_raise_tool_bar_buttons_p
= 1;
26841 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
26842 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
26843 make_cursor_line_fully_visible_p
= 1;
26845 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
26846 doc
: /* *Border below tool-bar in pixels.
26847 If an integer, use it as the height of the border.
26848 If it is one of `internal-border-width' or `border-width', use the
26849 value of the corresponding frame parameter.
26850 Otherwise, no border is added below the tool-bar. */);
26851 Vtool_bar_border
= Qinternal_border_width
;
26853 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
26854 doc
: /* *Margin around tool-bar buttons in pixels.
26855 If an integer, use that for both horizontal and vertical margins.
26856 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
26857 HORZ specifying the horizontal margin, and VERT specifying the
26858 vertical margin. */);
26859 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
26861 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
26862 doc
: /* *Relief thickness of tool-bar buttons. */);
26863 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
26865 DEFVAR_LISP ("tool-bar-style", &Vtool_bar_style
,
26866 doc
: /* *Tool bar style to use.
26868 image - show images only
26869 text - show text only
26870 both - show both, text below image
26871 both-horiz - show text to the right of the image
26872 text-image-horiz - show text to the left of the image
26873 any other - use system default or image if no system default. */);
26874 Vtool_bar_style
= Qnil
;
26876 DEFVAR_INT ("tool-bar-max-label-size", &tool_bar_max_label_size
,
26877 doc
: /* *Maximum number of characters a label can have to be shown.
26878 The tool bar style must also show labels for this to have any effect, see
26879 `tool-bar-style'. */);
26880 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
26882 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
26883 doc
: /* List of functions to call to fontify regions of text.
26884 Each function is called with one argument POS. Functions must
26885 fontify a region starting at POS in the current buffer, and give
26886 fontified regions the property `fontified'. */);
26887 Vfontification_functions
= Qnil
;
26888 Fmake_variable_buffer_local (Qfontification_functions
);
26890 DEFVAR_BOOL ("unibyte-display-via-language-environment",
26891 &unibyte_display_via_language_environment
,
26892 doc
: /* *Non-nil means display unibyte text according to language environment.
26893 Specifically, this means that raw bytes in the range 160-255 decimal
26894 are displayed by converting them to the equivalent multibyte characters
26895 according to the current language environment. As a result, they are
26896 displayed according to the current fontset.
26898 Note that this variable affects only how these bytes are displayed,
26899 but does not change the fact they are interpreted as raw bytes. */);
26900 unibyte_display_via_language_environment
= 0;
26902 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
26903 doc
: /* *Maximum height for resizing mini-windows.
26904 If a float, it specifies a fraction of the mini-window frame's height.
26905 If an integer, it specifies a number of lines. */);
26906 Vmax_mini_window_height
= make_float (0.25);
26908 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
26909 doc
: /* *How to resize mini-windows.
26910 A value of nil means don't automatically resize mini-windows.
26911 A value of t means resize them to fit the text displayed in them.
26912 A value of `grow-only', the default, means let mini-windows grow
26913 only, until their display becomes empty, at which point the windows
26914 go back to their normal size. */);
26915 Vresize_mini_windows
= Qgrow_only
;
26917 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
26918 doc
: /* Alist specifying how to blink the cursor off.
26919 Each element has the form (ON-STATE . OFF-STATE). Whenever the
26920 `cursor-type' frame-parameter or variable equals ON-STATE,
26921 comparing using `equal', Emacs uses OFF-STATE to specify
26922 how to blink it off. ON-STATE and OFF-STATE are values for
26923 the `cursor-type' frame parameter.
26925 If a frame's ON-STATE has no entry in this list,
26926 the frame's other specifications determine how to blink the cursor off. */);
26927 Vblink_cursor_alist
= Qnil
;
26929 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
26930 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
26931 If non-nil, windows are automatically scrolled horizontally to make
26932 point visible. */);
26933 automatic_hscrolling_p
= 1;
26934 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
26935 staticpro (&Qauto_hscroll_mode
);
26937 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
26938 doc
: /* *How many columns away from the window edge point is allowed to get
26939 before automatic hscrolling will horizontally scroll the window. */);
26940 hscroll_margin
= 5;
26942 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
26943 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
26944 When point is less than `hscroll-margin' columns from the window
26945 edge, automatic hscrolling will scroll the window by the amount of columns
26946 determined by this variable. If its value is a positive integer, scroll that
26947 many columns. If it's a positive floating-point number, it specifies the
26948 fraction of the window's width to scroll. If it's nil or zero, point will be
26949 centered horizontally after the scroll. Any other value, including negative
26950 numbers, are treated as if the value were zero.
26952 Automatic hscrolling always moves point outside the scroll margin, so if
26953 point was more than scroll step columns inside the margin, the window will
26954 scroll more than the value given by the scroll step.
26956 Note that the lower bound for automatic hscrolling specified by `scroll-left'
26957 and `scroll-right' overrides this variable's effect. */);
26958 Vhscroll_step
= make_number (0);
26960 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
26961 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
26962 Bind this around calls to `message' to let it take effect. */);
26963 message_truncate_lines
= 0;
26965 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
26966 doc
: /* Normal hook run to update the menu bar definitions.
26967 Redisplay runs this hook before it redisplays the menu bar.
26968 This is used to update submenus such as Buffers,
26969 whose contents depend on various data. */);
26970 Vmenu_bar_update_hook
= Qnil
;
26972 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
26973 doc
: /* Frame for which we are updating a menu.
26974 The enable predicate for a menu binding should check this variable. */);
26975 Vmenu_updating_frame
= Qnil
;
26977 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
26978 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
26979 inhibit_menubar_update
= 0;
26981 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
26982 doc
: /* Prefix prepended to all continuation lines at display time.
26983 The value may be a string, an image, or a stretch-glyph; it is
26984 interpreted in the same way as the value of a `display' text property.
26986 This variable is overridden by any `wrap-prefix' text or overlay
26989 To add a prefix to non-continuation lines, use `line-prefix'. */);
26990 Vwrap_prefix
= Qnil
;
26991 staticpro (&Qwrap_prefix
);
26992 Qwrap_prefix
= intern_c_string ("wrap-prefix");
26993 Fmake_variable_buffer_local (Qwrap_prefix
);
26995 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
26996 doc
: /* Prefix prepended to all non-continuation lines at display time.
26997 The value may be a string, an image, or a stretch-glyph; it is
26998 interpreted in the same way as the value of a `display' text property.
27000 This variable is overridden by any `line-prefix' text or overlay
27003 To add a prefix to continuation lines, use `wrap-prefix'. */);
27004 Vline_prefix
= Qnil
;
27005 staticpro (&Qline_prefix
);
27006 Qline_prefix
= intern_c_string ("line-prefix");
27007 Fmake_variable_buffer_local (Qline_prefix
);
27009 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
27010 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27011 inhibit_eval_during_redisplay
= 0;
27013 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
27014 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27015 inhibit_free_realized_faces
= 0;
27018 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
27019 doc
: /* Inhibit try_window_id display optimization. */);
27020 inhibit_try_window_id
= 0;
27022 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
27023 doc
: /* Inhibit try_window_reusing display optimization. */);
27024 inhibit_try_window_reusing
= 0;
27026 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
27027 doc
: /* Inhibit try_cursor_movement display optimization. */);
27028 inhibit_try_cursor_movement
= 0;
27029 #endif /* GLYPH_DEBUG */
27031 DEFVAR_INT ("overline-margin", &overline_margin
,
27032 doc
: /* *Space between overline and text, in pixels.
27033 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27034 margin to the caracter height. */);
27035 overline_margin
= 2;
27037 DEFVAR_INT ("underline-minimum-offset",
27038 &underline_minimum_offset
,
27039 doc
: /* Minimum distance between baseline and underline.
27040 This can improve legibility of underlined text at small font sizes,
27041 particularly when using variable `x-use-underline-position-properties'
27042 with fonts that specify an UNDERLINE_POSITION relatively close to the
27043 baseline. The default value is 1. */);
27044 underline_minimum_offset
= 1;
27046 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
27047 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27048 This feature only works when on a window system that can change
27049 cursor shapes. */);
27050 display_hourglass_p
= 1;
27052 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
27053 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27054 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27056 hourglass_atimer
= NULL
;
27057 hourglass_shown_p
= 0;
27059 DEFSYM (Qglyphless_char
, "glyphless-char");
27060 DEFSYM (Qhexa_code
, "hexa-code");
27061 DEFSYM (Qempty_box
, "empty-box");
27062 DEFSYM (Qthin_space
, "thin-space");
27063 DEFSYM (Qzero_width
, "zero-width");
27065 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27066 /* Intern this now in case it isn't already done.
27067 Setting this variable twice is harmless.
27068 But don't staticpro it here--that is done in alloc.c. */
27069 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27070 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27072 DEFVAR_LISP ("glyphless-char-display", &Vglyphless_char_display
,
27073 doc
: /* Char-table to control displaying of glyphless characters.
27074 Each element, if non-nil, is an ASCII acronym string (displayed in a box)
27075 or one of these symbols:
27076 hexa-code: display with hexadecimal character code in a box
27077 empty-box: display with an empty box
27078 thin-space: display with 1-pixel width space
27079 zero-width: don't display
27081 It has one extra slot to control the display of a character for which
27082 no font is found. The value of the slot is `hexa-code' or `empty-box'.
27083 The default is `empty-box'. */);
27084 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27085 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27090 /* Initialize this module when Emacs starts. */
27095 Lisp_Object root_window
;
27096 struct window
*mini_w
;
27098 current_header_line_height
= current_mode_line_height
= -1;
27100 CHARPOS (this_line_start_pos
) = 0;
27102 mini_w
= XWINDOW (minibuf_window
);
27103 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27105 if (!noninteractive
)
27107 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27110 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27111 set_window_height (root_window
,
27112 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27114 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27115 set_window_height (minibuf_window
, 1, 0);
27117 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27118 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27120 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27121 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27122 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27124 /* The default ellipsis glyphs `...'. */
27125 for (i
= 0; i
< 3; ++i
)
27126 default_invis_vector
[i
] = make_number ('.');
27130 /* Allocate the buffer for frame titles.
27131 Also used for `format-mode-line'. */
27133 mode_line_noprop_buf
= (char *) xmalloc (size
);
27134 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27135 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27136 mode_line_target
= MODE_LINE_DISPLAY
;
27139 help_echo_showing_p
= 0;
27142 /* Since w32 does not support atimers, it defines its own implementation of
27143 the following three functions in w32fns.c. */
27146 /* Platform-independent portion of hourglass implementation. */
27148 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27150 hourglass_started (void)
27152 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27155 /* Cancel a currently active hourglass timer, and start a new one. */
27157 start_hourglass (void)
27159 #if defined (HAVE_WINDOW_SYSTEM)
27161 int secs
, usecs
= 0;
27163 cancel_hourglass ();
27165 if (INTEGERP (Vhourglass_delay
)
27166 && XINT (Vhourglass_delay
) > 0)
27167 secs
= XFASTINT (Vhourglass_delay
);
27168 else if (FLOATP (Vhourglass_delay
)
27169 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27172 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27173 secs
= XFASTINT (tem
);
27174 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27177 secs
= DEFAULT_HOURGLASS_DELAY
;
27179 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27180 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27181 show_hourglass
, NULL
);
27186 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27189 cancel_hourglass (void)
27191 #if defined (HAVE_WINDOW_SYSTEM)
27192 if (hourglass_atimer
)
27194 cancel_atimer (hourglass_atimer
);
27195 hourglass_atimer
= NULL
;
27198 if (hourglass_shown_p
)
27202 #endif /* ! WINDOWSNT */