1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1994, 1995, 1996 Board of Trustees, University of Illinois.
3 Copyright (C) 1995 Free Software Foundation, Inc.
4 Copyright (C) 1995, 1996 Ben Wing.
5 Copyright (C) 1995 Sun Microsystems, Inc.
6 Copyright (C) 1996 Chuck Thompson.
8 This file is part of XEmacs.
10 XEmacs is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the
12 Free Software Foundation; either version 2, or (at your option) any
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with XEmacs; see the file COPYING. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* Synched up with: Not in FSF. */
27 /* Author: Chuck Thompson */
29 /* Fixed up by Ben Wing for Mule */
31 /* This file has been Mule-ized. */
33 /*****************************************************************************
34 The Golden Rules of Redisplay
36 First: It Is Better To Be Correct Than Fast
37 Second: Thou Shalt Not Run Elisp From Within Redisplay
38 Third: It Is Better To Be Fast Than Not To Be
39 ****************************************************************************/
59 #include "redisplay.h"
62 #include "line-number.h"
64 #include "file-coding.h"
68 #include "console-tty.h"
70 #include <unistd.h> /* for isatty() */
74 /* Note: We have to be careful throughout this code to properly handle
75 and differentiate between Bufbytes and Emchars.
77 Since strings are generally composed of Bufbytes, I've taken the tack
78 that any contiguous set of Bufbytes is called a "string", while
79 any contiguous set of Emchars is called an "array". */
81 /* Return value to indicate a failure by an add_*_rune routine to add
82 a rune, but no propagation information needs to be returned. */
83 #define ADD_FAILED (prop_block_dynarr *) 1
85 #define BEGIN_GLYPHS 0
88 #define RIGHT_GLYPHS 3
90 /* Set the vertical clip to 0 if we are currently updating the line
91 start cache. Otherwise for buffers of line height 1 it may fail to
92 be able to work properly because regenerate_window will not layout
94 #define VERTICAL_CLIP(w, display) \
95 (updating_line_start_cache \
97 : ((WINDOW_TTY_P (w) | (!display && scroll_on_clipped_lines)) \
101 /* The following structures are completely private to redisplay.c so
102 we put them here instead of in a header file, for modularity. */
104 /* NOTE: Bytinds not Bufpos's in this structure. */
106 typedef struct position_redisplay_data_type
108 /* This information is normally filled in by the create_*_block
109 routines and is used by the add_*_rune routines. */
111 /* if we are working with strings rather than buffers we need a
112 handle to the string */
115 struct display_block *db;
116 struct display_line *dl;
117 Emchar ch; /* Character that is to be added. This is
118 used to communicate this information to
119 add_emchar_rune(). */
120 Lisp_Object last_charset; /* The charset of the previous character.
121 Used to optimize some lookups -- we
122 only have to do some things when
123 the charset changes. */
124 face_index last_findex; /* The face index of the previous character.
125 Needed to ensure the validity of the
126 last_charset optimization. */
128 int last_char_width; /* The width of the previous character. */
129 int font_is_bogus; /* If true, it means we couldn't instantiate
130 the font for this charset, so we substitute
131 ~'s from the ASCII charset. */
136 int blank_width; /* Width of the blank that is to be added.
137 This is used to communicate this information
140 This is also used rather cheesily to
141 communicate the width of the eol-cursor-size
142 blank that exists at the end of the line.
143 add_emchar_rune() is called cheesily with
144 the non-printing char '\n', which is stuck
145 in the output routines with its width being
147 Bytind bi_cursor_bufpos;/* This stores the buffer position of the cursor. */
148 unsigned int cursor_type :3;
149 int cursor_x; /* rune block cursor is at */
150 int start_col; /* Number of character columns (each column has
151 a width of the default char width) that still
152 need to be skipped. This is used for horizontal
153 scrolling, where a certain number of columns
154 (those off the left side of the screen) need
155 to be skipped before anything is displayed. */
156 Bytind bi_start_col_enabled;
157 int start_col_xoffset; /* Number of pixels that still need to
158 be skipped. This is used for
159 horizontal scrolling of glyphs, where we want
160 to be able to scroll over part of the glyph. */
162 int hscroll_glyph_width_adjust; /* how much the width of the hscroll
163 glyph differs from space_width (w).
164 0 if no hscroll glyph was used,
165 i.e. the window is not scrolled
166 horizontally. Used in tab
169 /* Information about the face the text should be displayed in and
170 any begin-glyphs and end-glyphs. */
171 struct extent_fragment *ef;
174 /* The height of a pixmap may either be predetermined if the user
175 has set a baseline value, or it may be dependent on whatever the
176 line ascent and descent values end up being, based just on font
177 information. In the first case we can immediately update the
178 values, thus their inclusion here. In the last case we cannot
179 determine the actual contribution to the line height until we
180 have finished laying out all text on the line. Thus we propagate
181 the max height of such pixmaps and do a final calculation after
182 all text has been added to the line. */
185 int max_pixmap_height;
187 Lisp_Object result_str; /* String where we put the result of
188 generating a formatted string in the modeline. */
189 int is_modeline; /* Non-zero if we're generating the modeline. */
190 Charcount modeline_charpos; /* Number of chars used in result_str so far;
191 corresponds to bytepos. */
192 Bytecount bytepos; /* Number of bytes used in result_str so far.
193 We don't actually copy the bytes into result_str
194 until the end because we don't know how big the
195 string is going to be until then. */
206 /* Data that should be propagated to the next line. Either a single
207 Emchar or a string of Bufbyte's.
209 The actual data that is propagated ends up as a Dynarr of these
212 #### It's unclean that both Emchars and Bufbytes are here.
215 typedef struct prop_block prop_block;
225 Bytecount len; /* length of the string. */
231 Bytind bi_cursor_bufpos; /* NOTE: is in Bytinds */
232 unsigned int cursor_type :3;
245 Dynarr_declare (prop_block);
249 static void generate_formatted_string_db (Lisp_Object format_str,
250 Lisp_Object result_str,
252 struct display_line *dl,
253 struct display_block *db,
254 face_index findex, int min_pixpos,
255 int max_pixpos, int type);
256 static Charcount generate_fstring_runes (struct window *w, pos_data *data,
257 Charcount pos, Charcount min_pos,
258 Charcount max_pos, Lisp_Object elt,
259 int depth, int max_pixsize,
260 face_index findex, int type);
261 static prop_block_dynarr *add_glyph_rune (pos_data *data,
262 struct glyph_block *gb,
263 int pos_type, int allow_cursor,
264 struct glyph_cachel *cachel);
265 static Bytind create_text_block (struct window *w, struct display_line *dl,
266 Bytind bi_start_pos, prop_block_dynarr **prop,
268 static int create_overlay_glyph_block (struct window *w,
269 struct display_line *dl);
270 static void create_left_glyph_block (struct window *w,
271 struct display_line *dl,
273 static void create_right_glyph_block (struct window *w,
274 struct display_line *dl);
275 static void redisplay_windows (Lisp_Object window, int skip_selected);
276 static void decode_mode_spec (struct window *w, Emchar spec, int type);
277 static void free_display_line (struct display_line *dl);
278 static void update_line_start_cache (struct window *w, Bufpos from, Bufpos to,
279 Bufpos point, int no_regen);
280 static int point_visible (struct window *w, Bufpos point, int type);
282 /* This used to be 10 but 30 seems to give much better performance. */
283 #define INIT_MAX_PREEMPTS 30
284 static int max_preempts;
286 #define REDISPLAY_PREEMPTION_CHECK \
289 (!disable_preemption && \
290 ((preemption_count < max_preempts) || !NILP (Vexecuting_macro)) && \
291 (!INTERACTIVE || detect_input_pending ()))))
294 * Redisplay global variables.
297 /* We need a third set of display structures for the cursor motion
298 routines. We used to just give each window a third set. However,
299 we always fully regenerate the structures when needed so there
300 isn't any reason we need more than a single set. */
301 display_line_dynarr *cmotion_display_lines;
303 /* Used by generate_formatted_string. Global because they get used so
304 much that the dynamic allocation time adds up. */
305 static Emchar_dynarr *formatted_string_emchar_dynarr;
306 static struct display_line formatted_string_display_line;
307 /* We store the extents that we need to generate in a Dynarr and then
308 frob them all on at the end of generating the string. We do it
309 this way rather than adding them as we generate the string because
310 we don't store the text into the resulting string until we're done
311 (to avoid having to resize the string multiple times), and we don't
312 want to go around adding extents to a string when the extents might
313 stretch off the end of the string. */
314 static EXTENT_dynarr *formatted_string_extent_dynarr;
315 static Bytecount_dynarr *formatted_string_extent_start_dynarr;
316 static Bytecount_dynarr *formatted_string_extent_end_dynarr;
319 /* #### probably temporary */
320 int cache_adjustment;
322 /* This holds a string representing the text corresponding to a single
324 static Bufbyte_dynarr *mode_spec_bufbyte_string;
326 int in_display; /* 1 if in redisplay. */
328 int disable_preemption; /* Used for debugging redisplay and for
331 /* We only allow max_preempts preemptions before we force a redisplay. */
332 static int preemption_count;
334 /* Minimum pixel height of clipped bottom display line. */
337 /* Minimum visible pixel width of clipped glyphs at right margin. */
340 /* Set if currently inside update_line_start_cache. */
341 static int updating_line_start_cache;
343 /* Nonzero means reading single-character input with prompt
344 so put cursor on minibuffer after the prompt. */
345 int cursor_in_echo_area;
346 Lisp_Object Qcursor_in_echo_area;
348 /* Nonzero means truncate lines in all windows less wide than the frame */
349 int truncate_partial_width_windows;
351 /* non-nil if a buffer has changed since the last time redisplay completed */
353 int buffers_changed_set;
355 /* non-nil if hscroll has changed somewhere or a buffer has been
356 narrowed or widened */
358 int clip_changed_set;
360 /* non-nil if any extent has changed since the last time redisplay completed */
362 int extents_changed_set;
364 /* non-nil if any face has changed since the last time redisplay completed */
367 /* Nonzero means some frames have been marked as garbaged */
370 /* non-zero if any of the builtin display glyphs (continuation,
371 hscroll, control-arrow, etc) is in need of updating
374 int glyphs_changed_set;
376 /* non-zero if any displayed subwindow is in need of updating
378 int subwindows_changed;
379 int subwindows_changed_set;
381 /* non-zero if any displayed subwindow is in need of updating
383 int subwindows_state_changed;
384 int subwindows_state_changed_set;
386 /* This variable is 1 if the icon has to be updated.
387 It is set to 1 when `frame-icon-glyph' changes. */
389 int icon_changed_set;
391 /* This variable is 1 if the menubar widget has to be updated.
392 It is set to 1 by set-menubar-dirty-flag and cleared when the widget
395 int menubar_changed_set;
397 /* true iff we should redraw the modelines on the next redisplay */
398 int modeline_changed;
399 int modeline_changed_set;
401 /* non-nil if point has changed in some buffer since the last time
402 redisplay completed */
404 int point_changed_set;
406 /* non-nil if some frame has changed its size */
409 /* non-nil if some device has signaled that it wants to change size */
410 int asynch_device_change_pending;
412 /* non-nil if any toolbar has changed */
414 int toolbar_changed_set;
416 /* non-nil if any gutter has changed */
418 int gutter_changed_set;
420 /* non-nil if any window has changed since the last time redisplay completed */
423 /* non-nil if any frame's window structure has changed since the last
424 time redisplay completed */
425 int windows_structure_changed;
427 /* If non-nil, use vertical bar cursor. */
428 Lisp_Object Vbar_cursor;
429 Lisp_Object Qbar_cursor;
432 int visible_bell; /* If true and the terminal will support it
433 then the frame will flash instead of
434 beeping when an error occurs */
436 /* Nonzero means no need to redraw the entire frame on resuming
437 a suspended Emacs. This is useful on terminals with multiple pages,
438 where one page is used for Emacs and another for all else. */
439 int no_redraw_on_reenter;
441 Lisp_Object Vwindow_system; /* nil or a symbol naming the window system
442 under which emacs is running
443 ('x is the only current possibility) */
444 Lisp_Object Vinitial_window_system;
446 Lisp_Object Vglobal_mode_string;
448 /* The number of lines scroll a window by when point leaves the window; if
449 it is <=0 then point is centered in the window */
452 /* Scroll up to this many lines, to bring point back on screen. */
453 int scroll_conservatively;
455 /* Marker for where to display an arrow on top of the buffer text. */
456 Lisp_Object Voverlay_arrow_position;
457 /* String to display for the arrow. */
458 Lisp_Object Voverlay_arrow_string;
460 Lisp_Object Vwindow_size_change_functions;
461 Lisp_Object Vwindow_scroll_functions;
462 Lisp_Object Qredisplay_end_trigger_functions, Vredisplay_end_trigger_functions;
464 #define INHIBIT_REDISPLAY_HOOKS /* #### Until we've thought about
466 #ifndef INHIBIT_REDISPLAY_HOOKS
467 /* #### Chuck says: I think this needs more thought.
468 Think about this for 19.14. */
469 Lisp_Object Vpre_redisplay_hook, Vpost_redisplay_hook;
470 Lisp_Object Qpre_redisplay_hook, Qpost_redisplay_hook;
471 #endif /* INHIBIT_REDISPLAY_HOOKS */
473 static int last_display_warning_tick, display_warning_tick;
474 Lisp_Object Qdisplay_warning_buffer;
475 int inhibit_warning_display;
477 Lisp_Object Vleft_margin_width, Vright_margin_width;
478 Lisp_Object Vminimum_line_ascent, Vminimum_line_descent;
479 Lisp_Object Vuse_left_overflow, Vuse_right_overflow;
480 Lisp_Object Vtext_cursor_visible_p;
482 int column_number_start_at_one;
484 #define WINDOW_SCROLLED(w) \
485 (w->hscroll > 0 || w->left_xoffset)
488 /***************************************************************************/
490 /* low-level interfaces onto device routines */
492 /***************************************************************************/
495 redisplay_text_width_emchar_string (struct window *w, int findex,
496 Emchar *str, Charcount len)
498 unsigned char charsets[NUM_LEADING_BYTES];
501 find_charsets_in_emchar_string (charsets, str, len);
502 XSETWINDOW (window, w);
503 ensure_face_cachel_complete (WINDOW_FACE_CACHEL (w, findex), window,
505 return DEVMETH (XDEVICE (FRAME_DEVICE (XFRAME (WINDOW_FRAME (w)))),
506 text_width, (XFRAME (WINDOW_FRAME (w)),
507 WINDOW_FACE_CACHEL (w, findex), str, len));
510 static Emchar_dynarr *rtw_emchar_dynarr;
513 redisplay_text_width_string (struct window *w, int findex,
514 Bufbyte *nonreloc, Lisp_Object reloc,
515 Bytecount offset, Bytecount len)
517 if (!rtw_emchar_dynarr)
518 rtw_emchar_dynarr = Dynarr_new (Emchar);
519 Dynarr_reset (rtw_emchar_dynarr);
521 fixup_internal_substring (nonreloc, reloc, offset, &len);
523 nonreloc = XSTRING_DATA (reloc);
524 convert_bufbyte_string_into_emchar_dynarr (nonreloc, len, rtw_emchar_dynarr);
525 return redisplay_text_width_emchar_string
526 (w, findex, Dynarr_atp (rtw_emchar_dynarr, 0),
527 Dynarr_length (rtw_emchar_dynarr));
531 redisplay_frame_text_width_string (struct frame *f, Lisp_Object face,
532 Bufbyte *nonreloc, Lisp_Object reloc,
533 Bytecount offset, Bytecount len)
535 unsigned char charsets[NUM_LEADING_BYTES];
537 struct face_cachel cachel;
539 if (!rtw_emchar_dynarr)
540 rtw_emchar_dynarr = Dynarr_new (Emchar);
541 Dynarr_reset (rtw_emchar_dynarr);
543 fixup_internal_substring (nonreloc, reloc, offset, &len);
545 nonreloc = XSTRING_DATA (reloc);
546 convert_bufbyte_string_into_emchar_dynarr (nonreloc, len, rtw_emchar_dynarr);
547 find_charsets_in_bufbyte_string (charsets, nonreloc, len);
548 reset_face_cachel (&cachel);
550 XSETFRAME (frame, f);
551 ensure_face_cachel_complete (&cachel, frame, charsets);
552 return DEVMETH (XDEVICE (FRAME_DEVICE (f)),
553 text_width, (f, &cachel, Dynarr_atp (rtw_emchar_dynarr, 0),
554 Dynarr_length (rtw_emchar_dynarr)));
557 /* Return the display block from DL of the given TYPE. A display line
558 can have only one display block of each possible type. If DL does
559 not have a block of type TYPE, one will be created and added to DL. */
561 struct display_block *
562 get_display_block_from_line (struct display_line *dl, enum display_type type)
565 struct display_block db;
567 /* Check if this display line already has a block of the desired type and
569 if (dl->display_blocks)
571 for (elt = 0; elt < Dynarr_length (dl->display_blocks); elt++)
573 if (Dynarr_at (dl->display_blocks, elt).type == type)
574 return Dynarr_atp (dl->display_blocks, elt);
577 /* There isn't an active block of the desired type, but there
578 might still be allocated blocks we need to reuse. */
579 if (elt < Dynarr_largest (dl->display_blocks))
581 struct display_block *dbp = Dynarr_atp (dl->display_blocks, elt);
583 /* 'add' the block to the list */
584 Dynarr_increment (dl->display_blocks);
586 /* initialize and return */
593 /* This line doesn't have any display blocks, so initialize the display
595 dl->display_blocks = Dynarr_new (display_block);
598 /* The line doesn't have a block of the desired type so go ahead and create
599 one and add it to the line. */
602 db.runes = Dynarr_new (rune);
603 Dynarr_add (dl->display_blocks, db);
605 /* Return the newly added display block. */
606 elt = Dynarr_length (dl->display_blocks) - 1;
608 return Dynarr_atp (dl->display_blocks, elt);
612 tab_char_width (struct window *w)
614 struct buffer *b = XBUFFER (w->buffer);
615 int char_tab_width = XINT (b->tab_width);
617 if (char_tab_width <= 0 || char_tab_width > 1000) char_tab_width = 8;
619 return char_tab_width;
623 space_width (struct window *w)
625 /* While tabs are traditional composed of spaces, for variable-width
626 fonts the space character tends to give too narrow a value. So
627 we use 'n' instead. Except that we don't. We use the default
628 character width for the default face. If this is actually
629 defined by the font then it is probably the best thing to
630 actually use. If it isn't, we have assumed it is 'n' and have
631 already calculated its width. Thus we can avoid a call to
632 XTextWidth on X frames by just querying the default width. */
633 return XFONT_INSTANCE
634 (WINDOW_FACE_CACHEL_FONT (w, DEFAULT_INDEX, Vcharset_ascii))->width;
638 tab_pix_width (struct window *w)
640 return space_width (w) * tab_char_width (w);
643 /* Given a pixel position in a window, return the pixel location of
644 the next tabstop. Tabs are calculated from the left window edge in
645 terms of spaces displayed in the default face. Formerly the space
646 width was determined using the currently active face. That method
647 leads to tabstops which do not line up. */
650 next_tab_position (struct window *w, int start_pixpos, int left_pixpos)
652 int n_pos = left_pixpos;
653 int pix_tab_width = tab_pix_width (w);
655 /* Adjust n_pos for any hscrolling which has happened. */
656 if (WINDOW_SCROLLED (w))
657 n_pos -= space_width (w) * (w->hscroll - 1) + w->left_xoffset;
659 while (n_pos <= start_pixpos)
660 n_pos += pix_tab_width;
665 /* For the given window, calculate the outside and margin boundaries for a
666 display line. The whitespace boundaries must be calculated by the text
670 calculate_display_line_boundaries (struct window *w, int modeline)
672 layout_bounds bounds;
674 /* Set the outermost boundaries which are the boundaries of the
675 window itself minus the gutters (and minus the scrollbars if this
676 is for the modeline). */
679 bounds.left_out = WINDOW_TEXT_LEFT (w);
680 bounds.right_out = WINDOW_TEXT_RIGHT (w);
684 bounds.left_out = WINDOW_MODELINE_LEFT (w);
685 bounds.right_out = WINDOW_MODELINE_RIGHT (w);
688 /* The inner boundaries mark where the glyph margins are located. */
689 bounds.left_in = bounds.left_out + window_left_margin_width (w);
690 bounds.right_in = bounds.right_out - window_right_margin_width (w);
692 /* We cannot fully calculate the whitespace boundaries as they
693 depend on the contents of the line being displayed. */
694 bounds.left_white = bounds.left_in;
695 bounds.right_white = bounds.right_in;
700 /* Given a display line and a starting position, ensure that the
701 contents of the display line accurately represent the visual
702 representation of the buffer contents starting from the given
703 position when displayed in the given window. The display line ends
704 when the contents of the line reach the right boundary of the given
708 generate_display_line (struct window *w, struct display_line *dl, int bounds,
709 Bufpos start_pos, prop_block_dynarr **prop,
714 struct buffer *b = XBUFFER (WINDOW_BUFFER (w));
716 /* If our caller hasn't already set the boundaries, then do so now. */
718 dl->bounds = calculate_display_line_boundaries (w, 0);
720 /* Reset what this line is using. */
721 if (dl->display_blocks)
722 Dynarr_reset (dl->display_blocks);
725 Dynarr_free (dl->left_glyphs);
728 if (dl->right_glyphs)
730 Dynarr_free (dl->right_glyphs);
731 dl->right_glyphs = 0;
734 /* We aren't generating a modeline at the moment. */
737 /* Create a display block for the text region of the line. */
739 /* #### urk urk urk!!! Chuck fix this shit! */
740 Bytind hacked_up_bytind =
741 create_text_block (w, dl, bufpos_to_bytind (b, start_pos),
743 if (hacked_up_bytind > BI_BUF_ZV (b))
744 ret_bufpos = BUF_ZV (b) + 1;
746 ret_bufpos = bytind_to_bufpos (b, hacked_up_bytind);
748 dl->bufpos = start_pos;
749 if (dl->end_bufpos < dl->bufpos)
750 dl->end_bufpos = dl->bufpos;
752 if (MARKERP (Voverlay_arrow_position)
753 && EQ (w->buffer, Fmarker_buffer (Voverlay_arrow_position))
754 && start_pos == marker_position (Voverlay_arrow_position)
755 && (STRINGP (Voverlay_arrow_string)
756 || GLYPHP (Voverlay_arrow_string)))
758 overlay_width = create_overlay_glyph_block (w, dl);
763 /* If there are left glyphs associated with any character in the
764 text block, then create a display block to handle them. */
765 if (dl->left_glyphs != NULL && Dynarr_length (dl->left_glyphs))
766 create_left_glyph_block (w, dl, overlay_width);
768 /* If there are right glyphs associated with any character in the
769 text block, then create a display block to handle them. */
770 if (dl->right_glyphs != NULL && Dynarr_length (dl->right_glyphs))
771 create_right_glyph_block (w, dl);
773 /* In the future additional types of display blocks may be generated
776 w->last_redisplay_pos = ret_bufpos;
781 /* Adds an hscroll glyph to a display block. If this is called, then
782 the block had better be empty.
784 Yes, there are multiple places where this function is called but
785 that is the way it has to be. Each calling function has to deal
786 with bi_start_col_enabled a little differently depending on the
787 object being worked with. */
789 static prop_block_dynarr *
790 add_hscroll_rune (pos_data *data)
792 struct glyph_block gb;
793 prop_block_dynarr *retval;
794 Bytind bi_old_cursor_bufpos = data->bi_cursor_bufpos;
795 unsigned int old_cursor_type = data->cursor_type;
796 Bytind bi_old_bufpos = data->bi_bufpos;
798 if (data->cursor_type == CURSOR_ON
799 && data->bi_cursor_bufpos >= data->bi_start_col_enabled
800 && data->bi_cursor_bufpos <= data->bi_bufpos)
802 data->bi_cursor_bufpos = data->bi_start_col_enabled;
806 data->cursor_type = NO_CURSOR;
809 data->bi_endpos = data->bi_bufpos;
810 data->bi_bufpos = data->bi_start_col_enabled;
813 gb.glyph = Vhscroll_glyph;
815 int oldpixpos = data->pixpos;
816 retval = add_glyph_rune (data, &gb, BEGIN_GLYPHS, 1,
817 GLYPH_CACHEL (XWINDOW (data->window),
818 HSCROLL_GLYPH_INDEX));
819 data->hscroll_glyph_width_adjust =
820 data->pixpos - oldpixpos - space_width (XWINDOW (data->window));
823 data->bi_cursor_bufpos = bi_old_cursor_bufpos;
824 data->cursor_type = old_cursor_type;
825 data->bi_bufpos = bi_old_bufpos;
827 data->bi_start_col_enabled = 0;
831 /* Adds a character rune to a display block. If there is not enough
832 room to fit the rune on the display block (as determined by the
833 MAX_PIXPOS) then it adds nothing and returns ADD_FAILED. */
835 static prop_block_dynarr *
836 add_emchar_rune (pos_data *data)
838 struct rune rb, *crb;
849 if (data->bi_start_col_enabled)
851 return add_hscroll_rune (data);
854 if (data->ch == '\n')
856 data->font_is_bogus = 0;
857 /* Cheesy end-of-line pseudo-character. */
858 width = data->blank_width;
862 Lisp_Object charset = CHAR_CHARSET (data->ch);
863 if (!EQ (charset, data->last_charset) ||
864 data->findex != data->last_findex)
866 /* OK, we need to do things the hard way. */
867 struct window *w = XWINDOW (data->window);
868 struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, data->findex);
869 Lisp_Object font_instance =
870 ensure_face_cachel_contains_charset (cachel, data->window,
872 struct Lisp_Font_Instance *fi;
874 if (EQ (font_instance, Vthe_null_font_instance))
876 font_instance = FACE_CACHEL_FONT (cachel, Vcharset_ascii);
877 data->font_is_bogus = 1;
880 data->font_is_bogus = 0;
882 fi = XFONT_INSTANCE (font_instance);
883 if (!fi->proportional_p)
884 /* sweetness and light. */
885 data->last_char_width = fi->width;
887 data->last_char_width = -1;
888 data->new_ascent = max (data->new_ascent, (int) fi->ascent);
889 data->new_descent = max (data->new_descent, (int) fi->descent);
890 data->last_charset = charset;
891 data->last_findex = data->findex;
894 width = data->last_char_width;
897 /* bummer. Proportional fonts. */
898 width = redisplay_text_width_emchar_string (XWINDOW (data->window),
904 if (data->max_pixpos != -1 && (data->pixpos + width > data->max_pixpos))
909 if (Dynarr_length (data->db->runes) < Dynarr_largest (data->db->runes))
911 crb = Dynarr_atp (data->db->runes, Dynarr_length (data->db->runes));
920 crb->findex = data->findex;
921 crb->xpos = data->pixpos;
925 if (NILP (data->string))
927 bytind_to_bufpos (XBUFFER (WINDOW_BUFFER (XWINDOW (data->window))),
931 bytecount_to_charcount (XSTRING_DATA (data->string), data->bi_bufpos);
933 else if (data->is_modeline)
934 crb->bufpos = data->modeline_charpos;
936 /* fuckme if this shouldn't be an abort. */
937 /* abort (); fuckme harder, this abort gets tripped quite often,
938 in propagation and whatnot. #### fixme */
940 crb->type = RUNE_CHAR;
941 crb->object.chr.ch = data->font_is_bogus ? '~' : data->ch;
944 if (data->cursor_type == CURSOR_ON)
946 if (data->bi_bufpos == data->bi_cursor_bufpos)
948 crb->cursor_type = CURSOR_ON;
949 data->cursor_x = Dynarr_length (data->db->runes);
952 crb->cursor_type = CURSOR_OFF;
954 else if (data->cursor_type == NEXT_CURSOR)
956 crb->cursor_type = CURSOR_ON;
957 data->cursor_x = Dynarr_length (data->db->runes);
958 data->cursor_type = NO_CURSOR;
960 else if (data->cursor_type == IGNORE_CURSOR)
961 crb->cursor_type = IGNORE_CURSOR;
963 crb->cursor_type = CURSOR_OFF;
966 Dynarr_add (data->db->runes, *crb);
968 Dynarr_increment (data->db->runes);
970 data->pixpos += width;
975 /* Given a string C_STRING of length C_LENGTH, call add_emchar_rune
976 for each character in the string. Propagate any left-over data
977 unless NO_PROP is non-zero. */
979 static prop_block_dynarr *
980 add_bufbyte_string_runes (pos_data *data, Bufbyte *c_string,
981 Bytecount c_length, int no_prop)
983 Bufbyte *pos, *end = c_string + c_length;
984 prop_block_dynarr *prop;
986 /* #### This function is too simplistic. It needs to do the same
987 sort of character interpretation (display-table lookup,
988 ctl-arrow checking), etc. that create_text_block() does.
989 The functionality to do this in that routine needs to be
992 for (pos = c_string; pos < end;)
994 data->ch = charptr_emchar (pos);
996 prop = add_emchar_rune (data);
1004 struct prop_block pb;
1005 Bytecount len = end - pos;
1006 prop = Dynarr_new (prop_block);
1008 pb.type = PROP_STRING;
1009 pb.data.p_string.str = xnew_array (Bufbyte, len);
1010 strncpy ((char *) pb.data.p_string.str, (char *) pos, len);
1011 pb.data.p_string.len = len;
1013 Dynarr_add (prop, pb);
1018 assert (pos <= end);
1024 /* Add a single rune of the specified width. The area covered by this
1025 rune will be displayed in the foreground color of the associated
1028 static prop_block_dynarr *
1029 add_blank_rune (pos_data *data, struct window *w, int char_tab_width)
1033 /* If data->start_col is not 0 then this call to add_blank_rune must have
1034 been to add it as a tab. */
1035 if (data->start_col)
1037 /* assert (w != NULL) */
1038 prop_block_dynarr *retval;
1040 /* If we have still not fully scrolled horizontally, subtract
1041 the width of this tab and return. */
1042 if (char_tab_width < data->start_col)
1044 data->start_col -= char_tab_width;
1047 else if (char_tab_width == data->start_col)
1048 data->blank_width = 0;
1051 int spcwid = space_width (w);
1053 if (spcwid >= data->blank_width)
1054 data->blank_width = 0;
1056 data->blank_width -= spcwid;
1059 data->start_col = 0;
1060 retval = add_hscroll_rune (data);
1062 /* Could be caused by the handling of the hscroll rune. */
1063 if (retval != NULL || !data->blank_width)
1067 /* Blank runes are always calculated to fit. */
1068 assert (data->pixpos + data->blank_width <= data->max_pixpos);
1070 rb.findex = data->findex;
1071 rb.xpos = data->pixpos;
1072 rb.width = data->blank_width;
1073 if (data->bi_bufpos)
1075 bytind_to_bufpos (XBUFFER (WINDOW_BUFFER (XWINDOW (data->window))),
1078 /* #### and this is really correct too? */
1081 rb.type = RUNE_BLANK;
1083 if (data->cursor_type == CURSOR_ON)
1085 if (data->bi_bufpos == data->bi_cursor_bufpos)
1087 rb.cursor_type = CURSOR_ON;
1088 data->cursor_x = Dynarr_length (data->db->runes);
1091 rb.cursor_type = CURSOR_OFF;
1093 else if (data->cursor_type == NEXT_CURSOR)
1095 rb.cursor_type = CURSOR_ON;
1096 data->cursor_x = Dynarr_length (data->db->runes);
1097 data->cursor_type = NO_CURSOR;
1100 rb.cursor_type = CURSOR_OFF;
1102 Dynarr_add (data->db->runes, rb);
1103 data->pixpos += data->blank_width;
1108 /* Add runes representing a character in octal. */
1110 #define ADD_NEXT_OCTAL_RUNE_CHAR do \
1112 if (add_failed || (add_failed = add_emchar_rune (data))) \
1114 struct prop_block pb; \
1116 prop = Dynarr_new (prop_block); \
1118 pb.type = PROP_CHAR; \
1119 pb.data.p_char.ch = data->ch; \
1120 pb.data.p_char.cursor_type = data->cursor_type; \
1121 Dynarr_add (prop, pb); \
1125 static prop_block_dynarr *
1126 add_octal_runes (pos_data *data)
1128 prop_block_dynarr *prop, *add_failed;
1129 Emchar orig_char = data->ch;
1130 unsigned int orig_cursor_type = data->cursor_type;
1136 if (data->start_col)
1139 if (!data->start_col)
1141 if (data->bi_start_col_enabled)
1143 add_failed = add_hscroll_rune (data);
1147 struct glyph_block gb;
1148 struct window *w = XWINDOW (data->window);
1151 gb.glyph = Voctal_escape_glyph;
1153 add_glyph_rune (data, &gb, BEGIN_GLYPHS, 1,
1154 GLYPH_CACHEL (w, OCT_ESC_GLYPH_INDEX));
1158 /* We only propagate information if the glyph was partially
1163 data->cursor_type = IGNORE_CURSOR;
1165 if (data->ch >= 0x100)
1167 /* If the character is an extended Mule character, it could have
1168 up to 19 bits. For the moment, we treat it as a seven-digit
1169 octal number. This is not that pretty, but whatever. */
1170 data->ch = (7 & (orig_char >> 18)) + '0';
1171 ADD_NEXT_OCTAL_RUNE_CHAR;
1173 data->ch = (7 & (orig_char >> 15)) + '0';
1174 ADD_NEXT_OCTAL_RUNE_CHAR;
1176 data->ch = (7 & (orig_char >> 12)) + '0';
1177 ADD_NEXT_OCTAL_RUNE_CHAR;
1179 data->ch = (7 & (orig_char >> 9)) + '0';
1180 ADD_NEXT_OCTAL_RUNE_CHAR;
1183 data->ch = (7 & (orig_char >> 6)) + '0';
1184 ADD_NEXT_OCTAL_RUNE_CHAR;
1186 data->ch = (7 & (orig_char >> 3)) + '0';
1187 ADD_NEXT_OCTAL_RUNE_CHAR;
1189 data->ch = (7 & orig_char) + '0';
1190 ADD_NEXT_OCTAL_RUNE_CHAR;
1192 data->cursor_type = orig_cursor_type;
1196 #undef ADD_NEXT_OCTAL_RUNE_CHAR
1198 /* Add runes representing a control character to a display block. */
1200 static prop_block_dynarr *
1201 add_control_char_runes (pos_data *data, struct buffer *b)
1203 if (!NILP (b->ctl_arrow))
1205 prop_block_dynarr *prop;
1206 Emchar orig_char = data->ch;
1207 unsigned int old_cursor_type = data->cursor_type;
1212 if (data->start_col)
1215 if (!data->start_col)
1217 if (data->bi_start_col_enabled)
1219 prop_block_dynarr *retval;
1221 retval = add_hscroll_rune (data);
1227 struct glyph_block gb;
1228 struct window *w = XWINDOW (data->window);
1231 gb.glyph = Vcontrol_arrow_glyph;
1233 /* We only propagate information if the glyph was partially
1235 if (add_glyph_rune (data, &gb, BEGIN_GLYPHS, 1,
1236 GLYPH_CACHEL (w, CONTROL_GLYPH_INDEX)))
1241 if (orig_char == 0177)
1244 data->ch = orig_char ^ 0100;
1245 data->cursor_type = IGNORE_CURSOR;
1247 if (add_emchar_rune (data))
1249 struct prop_block pb;
1251 prop = Dynarr_new (prop_block);
1253 pb.type = PROP_CHAR;
1254 pb.data.p_char.ch = data->ch;
1255 pb.data.p_char.cursor_type = data->cursor_type;
1256 Dynarr_add (prop, pb);
1259 data->cursor_type = old_cursor_type;
1264 return add_octal_runes (data);
1268 static prop_block_dynarr *
1269 add_disp_table_entry_runes_1 (pos_data *data, Lisp_Object entry)
1271 prop_block_dynarr *prop = NULL;
1273 if (STRINGP (entry))
1275 prop = add_bufbyte_string_runes (data,
1276 XSTRING_DATA (entry),
1277 XSTRING_LENGTH (entry),
1280 else if (GLYPHP (entry))
1282 if (data->start_col)
1285 if (!data->start_col && data->bi_start_col_enabled)
1287 prop = add_hscroll_rune (data);
1291 struct glyph_block gb;
1295 prop = add_glyph_rune (data, &gb, BEGIN_GLYPHS, 0, 0);
1298 else if (CHAR_OR_CHAR_INTP (entry))
1300 data->ch = XCHAR_OR_CHAR_INT (entry);
1301 prop = add_emchar_rune (data);
1303 else if (CONSP (entry))
1305 if (EQ (XCAR (entry), Qformat)
1306 && CONSP (XCDR (entry))
1307 && STRINGP (XCAR (XCDR (entry))))
1309 Lisp_Object format = XCAR (XCDR (entry));
1310 Bytind len = XSTRING_LENGTH (format);
1311 Bufbyte *src = XSTRING_DATA (format), *end = src + len;
1312 Bufbyte *result = alloca_array (Bufbyte, len);
1313 Bufbyte *dst = result;
1317 Emchar c = charptr_emchar (src);
1319 if (c != '%' || src == end)
1320 dst += set_charptr_emchar (dst, c);
1323 c = charptr_emchar (src);
1328 dst += long_to_string_base ((char *)dst, data->ch, 16);
1331 dst += set_charptr_emchar (dst, '%');
1336 prop = add_bufbyte_string_runes (data, result, dst - result, 0);
1340 /* Else blow it off because someone added a bad entry and we don't
1341 have any safe way of signaling an error. */
1345 /* Given a display table entry, call the appropriate functions to
1346 display each element of the entry. */
1348 static prop_block_dynarr *
1349 add_disp_table_entry_runes (pos_data *data, Lisp_Object entry)
1351 prop_block_dynarr *prop = NULL;
1352 if (VECTORP (entry))
1354 struct Lisp_Vector *de = XVECTOR (entry);
1355 EMACS_INT len = vector_length (de);
1358 for (elt = 0; elt < len; elt++)
1360 if (NILP (vector_data (de)[elt]))
1363 prop = add_disp_table_entry_runes_1 (data, vector_data (de)[elt]);
1364 /* Else blow it off because someone added a bad entry and we
1365 don't have any safe way of signaling an error. Hey, this
1366 comment sounds familiar. */
1368 /* #### Still need to add any remaining elements to the
1369 propagation information. */
1375 prop = add_disp_table_entry_runes_1 (data, entry);
1379 /* Add runes which were propagated from the previous line. */
1381 static prop_block_dynarr *
1382 add_propagation_runes (prop_block_dynarr **prop, pos_data *data)
1384 /* #### Remember to handle start_col parameter of data when the rest of
1385 this is finished. */
1386 /* #### Chuck -- I've redone this function a bit. It looked like the
1387 case of not all the propagation blocks being added was not handled
1389 /* #### Chuck -- I also think the double indirection of PROP is kind
1390 of bogus. A cleaner solution is just to check for
1391 Dynarr_length (prop) > 0. */
1392 /* #### This function also doesn't even pay attention to ADD_FAILED!
1393 This is seriously fucked! Seven ####'s in 130 lines -- is that a
1396 prop_block_dynarr *add_failed;
1397 Bytind bi_old_cursor_bufpos = data->bi_cursor_bufpos;
1398 unsigned int old_cursor_type = data->cursor_type;
1400 for (elt = 0; elt < Dynarr_length (*prop); elt++)
1402 struct prop_block *pb = Dynarr_atp (*prop, elt);
1407 data->ch = pb->data.p_char.ch;
1408 data->bi_cursor_bufpos = pb->data.p_char.bi_cursor_bufpos;
1409 data->cursor_type = pb->data.p_char.cursor_type;
1410 add_failed = add_emchar_rune (data);
1413 goto oops_no_more_space;
1416 if (pb->data.p_string.str)
1417 xfree (pb->data.p_string.str);
1418 /* #### bogus bogus -- this doesn't do anything!
1419 Should probably call add_bufbyte_string_runes(),
1420 once that function is fixed. */
1422 case PROP_MINIBUF_PROMPT:
1424 face_index old_findex = data->findex;
1425 Bytind bi_old_bufpos = data->bi_bufpos;
1427 data->findex = DEFAULT_INDEX;
1428 data->bi_bufpos = 0;
1429 data->cursor_type = NO_CURSOR;
1431 while (pb->data.p_string.len > 0)
1433 data->ch = charptr_emchar (pb->data.p_string.str);
1434 add_failed = add_emchar_rune (data);
1438 data->findex = old_findex;
1439 data->bi_bufpos = bi_old_bufpos;
1440 goto oops_no_more_space;
1444 /* Complicated equivalent of ptr++, len-- */
1445 Bufbyte *oldpos = pb->data.p_string.str;
1446 INC_CHARPTR (pb->data.p_string.str);
1447 pb->data.p_string.len -= pb->data.p_string.str - oldpos;
1451 data->findex = old_findex;
1452 /* ##### FIXME FIXME FIXME -- Upon successful return from
1453 this function, data->bi_bufpos is automatically incremented.
1454 However, we don't want that to happen if we were adding
1455 the minibuffer prompt. */
1457 struct buffer *buf =
1458 XBUFFER (WINDOW_BUFFER (XWINDOW (data->window)));
1459 /* #### Chuck fix this shit or I'm gonna scream! */
1460 if (bi_old_bufpos > BI_BUF_BEGV (buf))
1461 data->bi_bufpos = prev_bytind (buf, bi_old_bufpos);
1463 /* #### is this correct? Does anyone know?
1464 Does anyone care? Is this a cheesy hack or what? */
1465 data->bi_bufpos = BI_BUF_BEGV (buf) - 1;
1471 /* #### I think it's unnecessary and misleading to preserve
1472 the blank_width, as it implies that the value carries
1473 over from one rune to the next, which is wrong. */
1474 int old_width = data->blank_width;
1475 face_index old_findex = data->findex;
1477 data->findex = pb->data.p_blank.findex;
1478 data->blank_width = pb->data.p_blank.width;
1479 data->bi_cursor_bufpos = 0;
1480 data->cursor_type = IGNORE_CURSOR;
1482 if (data->pixpos + data->blank_width > data->max_pixpos)
1483 data->blank_width = data->max_pixpos - data->pixpos;
1485 /* We pass a bogus value of char_tab_width. It shouldn't
1486 matter because unless something is really screwed up
1487 this call won't cause that arg to be used. */
1488 add_failed = add_blank_rune (data, XWINDOW (data->window), 0);
1490 /* This can happen in the case where we have a tab which
1491 is wider than the window. */
1492 if (data->blank_width != pb->data.p_blank.width)
1494 pb->data.p_blank.width -= data->blank_width;
1495 add_failed = ADD_FAILED;
1498 data->findex = old_findex;
1499 data->blank_width = old_width;
1502 goto oops_no_more_space;
1512 data->bi_cursor_bufpos = bi_old_cursor_bufpos;
1513 data->cursor_type = old_cursor_type;
1514 if (elt < Dynarr_length (*prop))
1516 Dynarr_delete_many (*prop, 0, elt);
1521 Dynarr_free (*prop);
1526 /* Add 'text layout glyphs at position POS_TYPE that are contained to
1527 the display block, but add all other types to the appropriate list
1528 of the display line. They will be added later by different
1531 static prop_block_dynarr *
1532 add_glyph_rune (pos_data *data, struct glyph_block *gb, int pos_type,
1533 int allow_cursor, struct glyph_cachel *cachel)
1535 struct window *w = XWINDOW (data->window);
1537 /* A nil extent indicates a special glyph (ex. truncator). */
1538 if (NILP (gb->extent)
1539 || (pos_type == BEGIN_GLYPHS &&
1540 extent_begin_glyph_layout (XEXTENT (gb->extent)) == GL_TEXT)
1541 || (pos_type == END_GLYPHS &&
1542 extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_TEXT))
1547 int ascent, descent;
1548 Lisp_Object baseline;
1552 width = cachel->width;
1554 width = glyph_width (gb->glyph, Qnil, data->findex, data->window);
1559 if (data->start_col || data->start_col_xoffset)
1561 prop_block_dynarr *retval;
1562 int glyph_char_width = width / space_width (w);
1564 /* If we still have not fully scrolled horizontally after
1565 taking into account the width of the glyph, subtract its
1566 width and return. */
1567 if (glyph_char_width < data->start_col)
1569 data->start_col -= glyph_char_width;
1572 else if (glyph_char_width == data->start_col)
1576 xoffset = space_width (w) * data->start_col;
1579 /* #### Can this happen? */
1584 data->start_col = 0;
1585 retval = add_hscroll_rune (data);
1587 /* Could be caused by the handling of the hscroll rune. */
1588 if (retval != NULL || !width)
1594 if (data->pixpos + width > data->max_pixpos)
1596 /* If this is the first object we are attempting to add to
1597 the line then we ignore the horizontal_clip threshold.
1598 Otherwise we will loop until the bottom of the window
1599 continually failing to add this glyph because it is wider
1600 than the window. We could alternatively just completely
1601 ignore the glyph and proceed from there but I think that
1602 this is a better solution. */
1603 if (Dynarr_length (data->db->runes)
1604 && data->max_pixpos - data->pixpos < horizontal_clip)
1607 width = data->max_pixpos - data->pixpos;
1612 ascent = cachel->ascent;
1613 descent = cachel->descent;
1617 ascent = glyph_ascent (gb->glyph, Qnil, data->findex, data->window);
1618 descent = glyph_descent (gb->glyph, Qnil, data->findex,
1622 baseline = glyph_baseline (gb->glyph, data->window);
1624 if (glyph_contrib_p (gb->glyph, data->window))
1626 /* A pixmap that has not had a baseline explicitly set. Its
1627 contribution will be determined later. */
1628 if (NILP (baseline))
1630 int height = ascent + descent;
1631 data->max_pixmap_height = max (data->max_pixmap_height, height);
1634 /* A string so determine contribution normally. */
1635 else if (EQ (baseline, Qt))
1637 data->new_ascent = max (data->new_ascent, ascent);
1638 data->new_descent = max (data->new_descent, descent);
1641 /* A pixmap with an explicitly set baseline. We determine the
1642 contribution here. */
1643 else if (INTP (baseline))
1645 int height = ascent + descent;
1646 int pix_ascent, pix_descent;
1648 pix_ascent = height * XINT (baseline) / 100;
1649 pix_descent = height - pix_ascent;
1651 data->new_ascent = max (data->new_ascent, pix_ascent);
1652 data->new_descent = max (data->new_descent, pix_descent);
1655 /* Otherwise something is screwed up. */
1660 face = glyph_face (gb->glyph, data->window);
1662 rb.findex = data->findex;
1664 rb.findex = get_builtin_face_cache_index (w, face);
1666 rb.xpos = data->pixpos;
1668 rb.bufpos = 0; /* glyphs are never "at" anywhere */
1669 if (data->bi_endpos)
1670 /* #### is this necessary at all? */
1671 rb.endpos = bytind_to_bufpos (XBUFFER (WINDOW_BUFFER (w)),
1675 rb.type = RUNE_DGLYPH;
1676 /* #### Ben sez: this is way bogus if the glyph is a string.
1677 You should not make the output routines have to cope with
1678 this. The string could contain Mule characters, or non-
1679 printable characters, or characters to be passed through
1680 the display table, or non-character objects (when this gets
1681 implemented), etc. Instead, this routine here should parse
1682 the string into a series of runes. */
1683 rb.object.dglyph.glyph = gb->glyph;
1684 rb.object.dglyph.extent = gb->extent;
1685 rb.object.dglyph.xoffset = xoffset;
1689 rb.bufpos = bytind_to_bufpos (XBUFFER (WINDOW_BUFFER (w)),
1692 if (data->cursor_type == CURSOR_ON)
1694 if (data->bi_bufpos == data->bi_cursor_bufpos)
1696 rb.cursor_type = CURSOR_ON;
1697 data->cursor_x = Dynarr_length (data->db->runes);
1700 rb.cursor_type = CURSOR_OFF;
1702 else if (data->cursor_type == NEXT_CURSOR)
1704 rb.cursor_type = CURSOR_ON;
1705 data->cursor_x = Dynarr_length (data->db->runes);
1706 data->cursor_type = NO_CURSOR;
1708 else if (data->cursor_type == IGNORE_CURSOR)
1709 rb.cursor_type = IGNORE_CURSOR;
1710 else if (data->cursor_type == NO_CURSOR)
1711 rb.cursor_type = NO_CURSOR;
1713 rb.cursor_type = CURSOR_OFF;
1716 rb.cursor_type = CURSOR_OFF;
1718 Dynarr_add (data->db->runes, rb);
1719 data->pixpos += width;
1725 if (!NILP (glyph_face (gb->glyph, data->window)))
1727 get_builtin_face_cache_index (w, glyph_face (gb->glyph,
1730 gb->findex = data->findex;
1732 if (pos_type == BEGIN_GLYPHS)
1734 if (!data->dl->left_glyphs)
1735 data->dl->left_glyphs = Dynarr_new (glyph_block);
1736 Dynarr_add (data->dl->left_glyphs, *gb);
1739 else if (pos_type == END_GLYPHS)
1741 if (!data->dl->right_glyphs)
1742 data->dl->right_glyphs = Dynarr_new (glyph_block);
1743 Dynarr_add (data->dl->right_glyphs, *gb);
1747 abort (); /* there are no unknown types */
1750 return NULL; /* shut up compiler */
1753 /* Add all glyphs at position POS_TYPE that are contained in the given
1756 static prop_block_dynarr *
1757 add_glyph_runes (pos_data *data, int pos_type)
1759 /* #### This still needs to handle the start_col parameter. Duh, Chuck,
1760 why didn't you just modify add_glyph_rune in the first place? */
1762 glyph_block_dynarr *glyph_arr = (pos_type == BEGIN_GLYPHS
1763 ? data->ef->begin_glyphs
1764 : data->ef->end_glyphs);
1765 prop_block_dynarr *prop;
1767 for (elt = 0; elt < Dynarr_length (glyph_arr); elt++)
1769 prop = add_glyph_rune (data, Dynarr_atp (glyph_arr, elt), pos_type, 0,
1774 /* #### Add some propagation information. */
1779 Dynarr_reset (glyph_arr);
1784 /* Given a position for a buffer in a window, ensure that the given
1785 display line DL accurately represents the text on a line starting
1786 at the given position.
1788 NOTE NOTE NOTE NOTE: This function works with and returns Bytinds.
1789 You must do appropriate conversion. */
1792 create_text_block (struct window *w, struct display_line *dl,
1793 Bytind bi_start_pos, prop_block_dynarr **prop,
1796 struct frame *f = XFRAME (w->frame);
1797 struct buffer *b = XBUFFER (w->buffer);
1798 struct device *d = XDEVICE (f->device);
1802 /* Don't display anything in the minibuffer if this window is not on
1803 a selected frame. We consider all other windows to be active
1804 minibuffers as it simplifies the coding. */
1805 int active_minibuffer = (!MINI_WINDOW_P (w) ||
1806 (f == device_selected_frame (d)) ||
1807 is_surrogate_for_selected_frame (f));
1809 int truncate_win = window_truncation_on (w);
1810 int end_glyph_width;
1812 /* If the buffer's value of selective_display is an integer then
1813 only lines that start with less than selective_display columns of
1814 space will be displayed. If selective_display is t then all text
1815 after a ^M is invisible. */
1816 int selective = (INTP (b->selective_display)
1817 ? XINT (b->selective_display)
1818 : (!NILP (b->selective_display) ? -1 : 0));
1820 /* The variable ctl-arrow allows the user to specify what characters
1821 can actually be displayed and which octal should be used for.
1822 #### This variable should probably have some rethought done to
1825 #### It would also be really nice if you could specify that
1826 the characters come out in hex instead of in octal. Mule
1827 does that by adding a ctl-hexa variable similar to ctl-arrow,
1828 but that's bogus -- we need a more general solution. I
1829 think you need to extend the concept of display tables
1830 into a more general conversion mechanism. Ideally you
1831 could specify a Lisp function that converts characters,
1832 but this violates the Second Golden Rule and besides would
1833 make things way way way way slow.
1835 So instead, we extend the display-table concept, which was
1836 historically limited to 256-byte vectors, to one of the
1839 a) A 256-entry vector, for backward compatibility;
1840 b) char-table, mapping characters to values;
1841 c) range-table, mapping ranges of characters to values;
1842 d) a list of the above.
1844 The (d) option allows you to specify multiple display tables
1845 instead of just one. Each display table can specify conversions
1846 for some characters and leave others unchanged. The way the
1847 character gets displayed is determined by the first display table
1848 with a binding for that character. This way, you could call a
1849 function `enable-hex-display' that adds a hex display-table to
1850 the list of display tables for the current buffer.
1852 #### ...not yet implemented... Also, we extend the concept of
1853 "mapping" to include a printf-like spec. Thus you can make all
1854 extended characters show up as hex with a display table like
1857 #s(range-table data ((256 524288) (format "%x")))
1859 Since more than one display table is possible, you have
1860 great flexibility in mapping ranges of characters. */
1861 Emchar printable_min = (CHAR_OR_CHAR_INTP (b->ctl_arrow)
1862 ? XCHAR_OR_CHAR_INT (b->ctl_arrow)
1863 : ((EQ (b->ctl_arrow, Qt) || EQ (b->ctl_arrow, Qnil))
1866 Lisp_Object face_dt, window_dt;
1868 /* The text display block for this display line. */
1869 struct display_block *db = get_display_block_from_line (dl, TEXT);
1871 /* The first time through the main loop we need to force the glyph
1872 data to be updated. */
1875 /* Apparently the new extent_fragment_update returns an end position
1876 equal to the position passed in if there are no more runs to be
1878 int no_more_frags = 0;
1880 Lisp_Object synch_minibuffers_value =
1881 symbol_value_in_buffer (Qsynchronize_minibuffers, w->buffer);
1883 dl->used_prop_data = 0;
1887 data.ef = extent_fragment_new (w->buffer, f);
1889 /* These values are used by all of the rune addition routines. We add
1890 them to this structure for ease of passing. */
1892 XSETWINDOW (data.window, w);
1897 data.bi_bufpos = bi_start_pos;
1898 data.pixpos = dl->bounds.left_in;
1899 data.last_charset = Qunbound;
1900 data.last_findex = DEFAULT_INDEX;
1901 data.result_str = Qnil;
1903 /* Set the right boundary adjusting it to take into account any end
1904 glyph. Save the width of the end glyph for later use. */
1905 data.max_pixpos = dl->bounds.right_in;
1907 end_glyph_width = GLYPH_CACHEL_WIDTH (w, TRUN_GLYPH_INDEX);
1909 end_glyph_width = GLYPH_CACHEL_WIDTH (w, CONT_GLYPH_INDEX);
1910 data.max_pixpos -= end_glyph_width;
1912 if (cursor_in_echo_area && MINI_WINDOW_P (w) && echo_area_active (f))
1914 data.bi_cursor_bufpos = BI_BUF_ZV (b);
1915 data.cursor_type = CURSOR_ON;
1917 else if (MINI_WINDOW_P (w) && !active_minibuffer)
1918 data.cursor_type = NO_CURSOR;
1919 else if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)) &&
1920 EQ(DEVICE_CONSOLE(d), Vselected_console) &&
1921 d == XDEVICE(CONSOLE_SELECTED_DEVICE(XCONSOLE(DEVICE_CONSOLE(d))))&&
1922 f == XFRAME(DEVICE_SELECTED_FRAME(d)))
1924 data.bi_cursor_bufpos = BI_BUF_PT (b);
1925 data.cursor_type = CURSOR_ON;
1927 else if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1929 data.bi_cursor_bufpos = bi_marker_position (w->pointm[type]);
1930 data.cursor_type = CURSOR_ON;
1933 data.cursor_type = NO_CURSOR;
1936 data.start_col = w->hscroll;
1937 data.start_col_xoffset = w->left_xoffset;
1938 data.bi_start_col_enabled = (w->hscroll ? bi_start_pos : 0);
1939 data.hscroll_glyph_width_adjust = 0;
1941 /* We regenerate the line from the very beginning. */
1942 Dynarr_reset (db->runes);
1944 /* Why is this less than or equal and not just less than? If the
1945 starting position is already equal to the maximum we can't add
1946 anything else, right? Wrong. We might still have a newline to
1947 add. A newline can use the room allocated for an end glyph since
1948 if we add it we know we aren't going to be adding any end
1951 /* #### Chuck -- I think this condition should be while (1).
1952 Otherwise if (e.g.) there is one begin-glyph and one end-glyph
1953 and the begin-glyph ends exactly at the end of the window, the
1954 end-glyph and text might not be displayed. while (1) ensures
1955 that the loop terminates only when either (a) there is
1956 propagation data or (b) the end-of-line or end-of-buffer is hit.
1958 #### Also I think you need to ensure that the operation
1959 "add begin glyphs; add end glyphs; add text" is atomic and
1960 can't get interrupted in the middle. If you run off the end
1961 of the line during that operation, then you keep accumulating
1962 propagation data until you're done. Otherwise, if the (e.g.)
1963 there's a begin glyph at a particular position and attempting
1964 to display that glyph results in window-end being hit and
1965 propagation data being generated, then the character at that
1966 position won't be displayed.
1968 #### See also the comment after the end of this loop, below.
1970 while (data.pixpos <= data.max_pixpos
1971 && (active_minibuffer || !NILP (synch_minibuffers_value)))
1973 /* #### This check probably should not be necessary. */
1974 if (data.bi_bufpos > BI_BUF_ZV (b))
1976 /* #### urk! More of this lossage! */
1981 /* If selective display was an integer and we aren't working on
1982 a continuation line then find the next line we are actually
1983 supposed to display. */
1985 && (data.bi_bufpos == BI_BUF_BEGV (b)
1986 || BUF_FETCH_CHAR (b, prev_bytind (b, data.bi_bufpos)) == '\n'))
1988 while (bi_spaces_at_point (b, data.bi_bufpos) >= selective)
1991 bi_find_next_newline_no_quit (b, data.bi_bufpos, 1);
1992 if (data.bi_bufpos >= BI_BUF_ZV (b))
1994 data.bi_bufpos = BI_BUF_ZV (b);
2000 /* Check for face changes. */
2001 if (initial || (!no_more_frags && data.bi_bufpos == data.ef->end))
2003 /* Now compute the face and begin/end-glyph information. */
2005 /* Remember that the extent-fragment routines deal in Bytind's. */
2006 extent_fragment_update (w, data.ef, data.bi_bufpos);
2008 get_display_tables (w, data.findex, &face_dt, &window_dt);
2010 if (data.bi_bufpos == data.ef->end)
2015 /* Determine what is next to be displayed. We first handle any
2016 glyphs returned by glyphs_at_bufpos. If there are no glyphs to
2017 display then we determine what to do based on the character at the
2018 current buffer position. */
2020 /* If the current position is covered by an invisible extent, do
2021 nothing (except maybe add some ellipses).
2023 #### The behavior of begin and end-glyphs at the edge of an
2024 invisible extent should be investigated further. This is
2025 fairly low priority though. */
2026 if (data.ef->invisible)
2028 /* #### Chuck, perhaps you could look at this code? I don't
2029 really know what I'm doing. */
2032 Dynarr_free (*prop);
2036 /* The extent fragment code only sets this when we should
2037 really display the ellipses. It makes sure the ellipses
2038 don't get displayed more than once in a row. */
2039 if (data.ef->invisible_ellipses)
2041 struct glyph_block gb;
2043 data.ef->invisible_ellipses_already_displayed = 1;
2044 data.ef->invisible_ellipses = 0;
2046 gb.glyph = Vinvisible_text_glyph;
2047 *prop = add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0,
2048 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX));
2049 /* Perhaps they shouldn't propagate if the very next thing
2050 is to display a newline (for compatibility with
2051 selective-display-ellipses)? Maybe that's too
2057 /* If point is in an invisible region we place it on the
2058 next visible character. */
2059 if (data.cursor_type == CURSOR_ON
2060 && data.bi_bufpos == data.bi_cursor_bufpos)
2062 data.cursor_type = NEXT_CURSOR;
2065 /* #### What if we we're dealing with a display table? */
2069 if (data.bi_bufpos == BI_BUF_ZV (b))
2072 INC_BYTIND (b, data.bi_bufpos);
2075 /* If there is propagation data, then it represents the current
2076 buffer position being displayed. Add them and advance the
2077 position counter. This might also add the minibuffer
2081 dl->used_prop_data = 1;
2082 *prop = add_propagation_runes (prop, &data);
2085 goto done; /* gee, a really narrow window */
2086 else if (data.bi_bufpos == BI_BUF_ZV (b))
2088 else if (data.bi_bufpos < BI_BUF_BEGV (b))
2089 /* #### urk urk urk! Aborts are not very fun! Fix this please! */
2090 data.bi_bufpos = BI_BUF_BEGV (b);
2092 INC_BYTIND (b, data.bi_bufpos);
2095 /* If there are end glyphs, add them to the line. These are
2096 the end glyphs for the previous run of text. We add them
2097 here rather than doing them at the end of handling the
2098 previous run so that glyphs at the beginning and end of
2099 a line are handled correctly. */
2100 else if (Dynarr_length (data.ef->end_glyphs) > 0)
2102 *prop = add_glyph_runes (&data, END_GLYPHS);
2107 /* If there are begin glyphs, add them to the line. */
2108 else if (Dynarr_length (data.ef->begin_glyphs) > 0)
2110 *prop = add_glyph_runes (&data, BEGIN_GLYPHS);
2115 /* If at end-of-buffer, we've already processed begin and
2116 end-glyphs at this point and there's no text to process,
2118 else if (data.bi_bufpos == BI_BUF_ZV (b))
2123 Lisp_Object entry = Qnil;
2124 /* Get the character at the current buffer position. */
2125 data.ch = BI_BUF_FETCH_CHAR (b, data.bi_bufpos);
2126 if (!NILP (face_dt) || !NILP (window_dt))
2127 entry = display_table_entry (data.ch, face_dt, window_dt);
2129 /* If there is a display table entry for it, hand it off to
2130 add_disp_table_entry_runes and let it worry about it. */
2131 if (!NILP (entry) && !EQ (entry, make_char (data.ch)))
2133 *prop = add_disp_table_entry_runes (&data, entry);
2139 /* Check if we have hit a newline character. If so, add a marker
2140 to the line and end this loop. */
2141 else if (data.ch == '\n')
2143 /* We aren't going to be adding an end glyph so give its
2144 space back in order to make sure that the cursor can
2146 data.max_pixpos += end_glyph_width;
2149 && (bi_spaces_at_point
2150 (b, next_bytind (b, data.bi_bufpos))
2153 if (!NILP (b->selective_display_ellipses))
2155 struct glyph_block gb;
2158 gb.glyph = Vinvisible_text_glyph;
2159 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0,
2160 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX));
2164 /* Cheesy, cheesy, cheesy. We mark the end of the
2165 line with a special "character rune" whose width
2166 is the EOL cursor width and whose character is
2167 the non-printing character '\n'. */
2168 data.blank_width = DEVMETH (d, eol_cursor_width, ());
2169 *prop = add_emchar_rune (&data);
2172 /* We need to set data.bi_bufpos to the start of the
2173 next visible region in order to make this line
2174 appear to contain all of the invisible area.
2175 Otherwise, the line cache won't work
2177 INC_BYTIND (b, data.bi_bufpos);
2178 while (bi_spaces_at_point (b, data.bi_bufpos) >= selective)
2181 bi_find_next_newline_no_quit (b, data.bi_bufpos, 1);
2182 if (data.bi_bufpos >= BI_BUF_ZV (b))
2184 data.bi_bufpos = BI_BUF_ZV (b);
2188 if (BI_BUF_FETCH_CHAR
2189 (b, prev_bytind (b, data.bi_bufpos)) == '\n')
2190 DEC_BYTIND (b, data.bi_bufpos);
2194 data.blank_width = DEVMETH (d, eol_cursor_width, ());
2195 *prop = add_emchar_rune (&data);
2201 /* If the current character is ^M, and selective display is
2202 enabled, then add the invisible-text-glyph if
2203 selective-display-ellipses is set. In any case, this
2205 else if (data.ch == (('M' & 037)) && selective == -1)
2207 Bytind bi_next_bufpos;
2209 /* Find the buffer position at the end of the line. */
2211 bi_find_next_newline_no_quit (b, data.bi_bufpos, 1);
2212 if (BI_BUF_FETCH_CHAR (b, prev_bytind (b, bi_next_bufpos))
2214 DEC_BYTIND (b, bi_next_bufpos);
2216 /* If the cursor is somewhere in the elided text make
2217 sure that the cursor gets drawn appropriately. */
2218 if (data.cursor_type == CURSOR_ON
2219 && (data.bi_cursor_bufpos >= data.bi_bufpos &&
2220 data.bi_cursor_bufpos < bi_next_bufpos))
2222 data.cursor_type = NEXT_CURSOR;
2225 /* We won't be adding a truncation or continuation glyph
2226 so give up the room allocated for them. */
2227 data.max_pixpos += end_glyph_width;
2229 if (!NILP (b->selective_display_ellipses))
2231 /* We don't propagate anything from the invisible
2232 text glyph if it fails to fit. This is
2234 struct glyph_block gb;
2237 gb.glyph = Vinvisible_text_glyph;
2238 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 1,
2239 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX));
2242 /* Set the buffer position to the end of the line. We
2243 need to do this before potentially adding a newline
2244 so that the cursor flag will get set correctly (if
2246 data.bi_bufpos = bi_next_bufpos;
2248 if (NILP (b->selective_display_ellipses)
2249 || data.bi_cursor_bufpos == bi_next_bufpos)
2251 /* We have to at least add a newline character so
2252 that the cursor shows up properly. */
2254 data.blank_width = DEVMETH (d, eol_cursor_width, ());
2255 data.findex = DEFAULT_INDEX;
2257 data.start_col_xoffset = 0;
2258 data.bi_start_col_enabled = 0;
2260 add_emchar_rune (&data);
2263 /* This had better be a newline but doing it this way
2264 we'll see obvious incorrect results if it isn't. No
2265 need to abort here. */
2266 data.ch = BI_BUF_FETCH_CHAR (b, data.bi_bufpos);
2271 /* If the current character is considered to be printable, then
2273 else if (data.ch >= printable_min)
2275 *prop = add_emchar_rune (&data);
2280 /* If the current character is a tab, determine the next tab
2281 starting position and add a blank rune which extends from the
2282 current pixel position to that starting position. */
2283 else if (data.ch == '\t')
2285 int tab_start_pixpos = data.pixpos;
2290 if (data.start_col > 1)
2291 tab_start_pixpos -= (space_width (w) * (data.start_col - 1))
2292 + data.start_col_xoffset;
2295 next_tab_position (w, tab_start_pixpos,
2296 dl->bounds.left_in +
2297 data.hscroll_glyph_width_adjust);
2298 if (next_tab_start > data.max_pixpos)
2300 prop_width = next_tab_start - data.max_pixpos;
2301 next_tab_start = data.max_pixpos;
2303 data.blank_width = next_tab_start - data.pixpos;
2305 (next_tab_start - tab_start_pixpos) / space_width (w);
2307 *prop = add_blank_rune (&data, w, char_tab_width);
2309 /* add_blank_rune is only supposed to be called with
2310 sizes guaranteed to fit in the available space. */
2315 struct prop_block pb;
2316 *prop = Dynarr_new (prop_block);
2318 pb.type = PROP_BLANK;
2319 pb.data.p_blank.width = prop_width;
2320 pb.data.p_blank.findex = data.findex;
2321 Dynarr_add (*prop, pb);
2327 /* If character is a control character, pass it off to
2328 add_control_char_runes.
2330 The is_*() routines have undefined results on
2331 arguments outside of the range [-1, 255]. (This
2332 often bites people who carelessly use `char' instead
2333 of `unsigned char'.)
2335 else if (data.ch < 0x100 && iscntrl ((Bufbyte) data.ch))
2337 *prop = add_control_char_runes (&data, b);
2343 /* If the character is above the ASCII range and we have not
2344 already handled it, then print it as an octal number. */
2345 else if (data.ch >= 0200)
2347 *prop = add_octal_runes (&data);
2353 /* Assume the current character is considered to be printable,
2354 then just add it. */
2357 *prop = add_emchar_rune (&data);
2362 INC_BYTIND (b, data.bi_bufpos);
2368 /* Determine the starting point of the next line if we did not hit the
2369 end of the buffer. */
2370 if (data.bi_bufpos < BI_BUF_ZV (b)
2371 && (active_minibuffer || !NILP (synch_minibuffers_value)))
2373 /* #### This check is not correct. If the line terminated
2374 due to a begin-glyph or end-glyph hitting window-end, then
2375 data.ch will not point to the character at data.bi_bufpos. If
2376 you make the two changes mentioned at the top of this loop,
2377 you should be able to say '(if (*prop))'. That should also
2378 make it possible to eliminate the data.bi_bufpos < BI_BUF_ZV (b)
2381 /* The common case is that the line ended because we hit a newline.
2382 In that case, the next character is just the next buffer
2384 if (data.ch == '\n')
2386 /* If data.start_col_enabled is still true, then the window is
2387 scrolled far enough so that nothing on this line is visible.
2388 We need to stick a truncation glyph at the beginning of the
2389 line in that case unless the line is completely blank. */
2390 if (data.bi_start_col_enabled)
2392 if (data.cursor_type == CURSOR_ON)
2394 if (data.bi_cursor_bufpos >= bi_start_pos
2395 && data.bi_cursor_bufpos <= data.bi_bufpos)
2396 data.bi_cursor_bufpos = data.bi_bufpos;
2398 data.findex = DEFAULT_INDEX;
2400 data.bi_start_col_enabled = 0;
2402 if (data.bi_bufpos != bi_start_pos)
2404 struct glyph_block gb;
2407 gb.glyph = Vhscroll_glyph;
2408 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0,
2409 GLYPH_CACHEL (w, HSCROLL_GLYPH_INDEX));
2413 /* This duplicates code down below to add a newline to
2414 the end of an otherwise empty line.*/
2416 data.blank_width = DEVMETH (d, eol_cursor_width, ());
2418 add_emchar_rune (&data);
2422 INC_BYTIND (b, data.bi_bufpos);
2425 /* Otherwise we have a buffer line which cannot fit on one display
2429 struct glyph_block gb;
2430 struct glyph_cachel *cachel;
2432 /* If the line is to be truncated then we actually have to look
2433 for the next newline. We also add the end-of-line glyph which
2434 we know will fit because we adjusted the right border before
2435 we starting laying out the line. */
2436 data.max_pixpos += end_glyph_width;
2437 data.findex = DEFAULT_INDEX;
2444 /* Now find the start of the next line. */
2445 bi_pos = bi_find_next_newline_no_quit (b, data.bi_bufpos, 1);
2447 /* If the cursor is past the truncation line then we
2448 make it appear on the truncation glyph. If we've hit
2449 the end of the buffer then we also make the cursor
2450 appear unless eob is immediately preceded by a
2451 newline. In that case the cursor should actually
2452 appear on the next line. */
2453 if (data.cursor_type == CURSOR_ON
2454 && data.bi_cursor_bufpos >= data.bi_bufpos
2455 && (data.bi_cursor_bufpos < bi_pos ||
2456 (bi_pos == BI_BUF_ZV (b)
2457 && (bi_pos == BI_BUF_BEGV (b)
2458 || (BI_BUF_FETCH_CHAR (b, prev_bytind (b, bi_pos))
2460 data.bi_cursor_bufpos = bi_pos;
2462 data.cursor_type = NO_CURSOR;
2464 data.bi_bufpos = bi_pos;
2465 gb.glyph = Vtruncation_glyph;
2466 cachel = GLYPH_CACHEL (w, TRUN_GLYPH_INDEX);
2470 /* The cursor can never be on the continuation glyph. */
2471 data.cursor_type = NO_CURSOR;
2473 /* data.bi_bufpos is already at the start of the next line. */
2475 gb.glyph = Vcontinuation_glyph;
2476 cachel = GLYPH_CACHEL (w, CONT_GLYPH_INDEX);
2479 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 1, cachel);
2481 if (truncate_win && data.bi_bufpos == BI_BUF_ZV (b)
2482 && BI_BUF_FETCH_CHAR (b, prev_bytind (b, BI_BUF_ZV (b))) != '\n')
2483 /* #### Damn this losing shit. */
2487 else if ((active_minibuffer || !NILP (synch_minibuffers_value))
2488 && (!echo_area_active (f) || data.bi_bufpos == BI_BUF_ZV (b)))
2490 /* We need to add a marker to the end of the line since there is no
2491 newline character in order for the cursor to get drawn. We label
2492 it as a newline so that it gets handled correctly by the
2493 whitespace routines below. */
2496 data.blank_width = DEVMETH (d, eol_cursor_width, ());
2497 data.findex = DEFAULT_INDEX;
2499 data.start_col_xoffset = 0;
2500 data.bi_start_col_enabled = 0;
2502 data.max_pixpos += data.blank_width;
2503 add_emchar_rune (&data);
2504 data.max_pixpos -= data.blank_width;
2506 /* #### urk! Chuck, this shit is bad news. Going around
2507 manipulating invalid positions is guaranteed to result in
2508 trouble sooner or later. */
2509 data.bi_bufpos = BI_BUF_ZV (b) + 1;
2512 /* Calculate left whitespace boundary. */
2516 /* Whitespace past a newline is considered right whitespace. */
2517 while (elt < Dynarr_length (db->runes))
2519 struct rune *rb = Dynarr_atp (db->runes, elt);
2521 if ((rb->type == RUNE_CHAR && rb->object.chr.ch == ' ')
2522 || rb->type == RUNE_BLANK)
2524 dl->bounds.left_white += rb->width;
2528 elt = Dynarr_length (db->runes);
2532 /* Calculate right whitespace boundary. */
2534 int elt = Dynarr_length (db->runes) - 1;
2537 while (!done && elt >= 0)
2539 struct rune *rb = Dynarr_atp (db->runes, elt);
2541 if (!(rb->type == RUNE_CHAR && rb->object.chr.ch < 0x100
2542 && isspace (rb->object.chr.ch))
2543 && !rb->type == RUNE_BLANK)
2545 dl->bounds.right_white = rb->xpos + rb->width;
2553 /* The line is blank so everything is considered to be right
2556 dl->bounds.right_white = dl->bounds.left_in;
2559 /* Set the display blocks bounds. */
2560 db->start_pos = dl->bounds.left_in;
2561 if (Dynarr_length (db->runes))
2563 struct rune *rb = Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
2565 db->end_pos = rb->xpos + rb->width;
2568 db->end_pos = dl->bounds.right_white;
2570 /* update line height parameters */
2571 if (!data.new_ascent && !data.new_descent)
2573 /* We've got a blank line so initialize these values from the default
2575 default_face_font_info (data.window, &data.new_ascent,
2576 &data.new_descent, 0, 0, 0);
2579 if (data.max_pixmap_height)
2581 int height = data.new_ascent + data.new_descent;
2582 int pix_ascent, pix_descent;
2584 pix_descent = data.max_pixmap_height * data.new_descent / height;
2585 pix_ascent = data.max_pixmap_height - pix_descent;
2587 data.new_ascent = max (data.new_ascent, pix_ascent);
2588 data.new_descent = max (data.new_descent, pix_descent);
2591 dl->ascent = data.new_ascent;
2592 dl->descent = data.new_descent;
2595 unsigned short ascent = (unsigned short) XINT (w->minimum_line_ascent);
2597 if (dl->ascent < ascent)
2598 dl->ascent = ascent;
2601 unsigned short descent = (unsigned short) XINT (w->minimum_line_descent);
2603 if (dl->descent < descent)
2604 dl->descent = descent;
2607 dl->cursor_elt = data.cursor_x;
2608 /* #### lossage lossage lossage! Fix this shit! */
2609 if (data.bi_bufpos > BI_BUF_ZV (b))
2610 dl->end_bufpos = BUF_ZV (b);
2612 dl->end_bufpos = bytind_to_bufpos (b, data.bi_bufpos) - 1;
2614 data.dl->num_chars = column_at_point (b, dl->end_bufpos, 0);
2616 /* This doesn't correctly take into account tabs and control
2617 characters but if the window isn't being truncated then this
2618 value isn't going to end up being used anyhow. */
2619 data.dl->num_chars = dl->end_bufpos - dl->bufpos;
2621 /* #### handle horizontally scrolled line with text none of which
2622 was actually laid out. */
2624 /* #### handle any remainder of overlay arrow */
2626 if (*prop == ADD_FAILED)
2629 if (truncate_win && *prop)
2631 Dynarr_free (*prop);
2635 extent_fragment_delete (data.ef);
2637 /* #### If we started at EOB, then make sure we return a value past
2638 it so that regenerate_window will exit properly. This is bogus.
2639 The main loop should get fixed so that it isn't necessary to call
2640 this function if we are already at EOB. */
2642 if (data.bi_bufpos == BI_BUF_ZV (b) && bi_start_pos == BI_BUF_ZV (b))
2643 return data.bi_bufpos + 1; /* Yuck! */
2645 return data.bi_bufpos;
2648 /* Display the overlay arrow at the beginning of the given line. */
2651 create_overlay_glyph_block (struct window *w, struct display_line *dl)
2653 struct frame *f = XFRAME (w->frame);
2654 struct device *d = XDEVICE (f->device);
2657 /* If Voverlay_arrow_string isn't valid then just fail silently. */
2658 if (!STRINGP (Voverlay_arrow_string) && !GLYPHP (Voverlay_arrow_string))
2664 XSETWINDOW (data.window, w);
2665 data.db = get_display_block_from_line (dl, OVERWRITE);
2667 data.pixpos = dl->bounds.left_in;
2668 data.max_pixpos = dl->bounds.right_in;
2669 data.cursor_type = NO_CURSOR;
2671 data.findex = DEFAULT_INDEX;
2672 data.last_charset = Qunbound;
2673 data.last_findex = DEFAULT_INDEX;
2674 data.result_str = Qnil;
2677 Dynarr_reset (data.db->runes);
2679 if (STRINGP (Voverlay_arrow_string))
2681 add_bufbyte_string_runes
2683 XSTRING_DATA (Voverlay_arrow_string),
2684 XSTRING_LENGTH (Voverlay_arrow_string),
2687 else if (GLYPHP (Voverlay_arrow_string))
2689 struct glyph_block gb;
2691 gb.glyph = Voverlay_arrow_string;
2693 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, 0);
2696 if (data.max_pixmap_height)
2698 int height = data.new_ascent + data.new_descent;
2699 int pix_ascent, pix_descent;
2701 pix_descent = data.max_pixmap_height * data.new_descent / height;
2702 pix_ascent = data.max_pixmap_height - pix_descent;
2704 data.new_ascent = max (data.new_ascent, pix_ascent);
2705 data.new_descent = max (data.new_descent, pix_descent);
2708 dl->ascent = data.new_ascent;
2709 dl->descent = data.new_descent;
2711 data.db->start_pos = dl->bounds.left_in;
2712 data.db->end_pos = data.pixpos;
2714 return data.pixpos - dl->bounds.left_in;
2717 /* Add a type of glyph to a margin display block. */
2720 add_margin_runes (struct display_line *dl, struct display_block *db, int start,
2721 int count, enum glyph_layout layout, int side, Lisp_Object window)
2723 glyph_block_dynarr *gbd = (side == LEFT_GLYPHS
2725 : dl->right_glyphs);
2730 if ((layout == GL_WHITESPACE && side == LEFT_GLYPHS)
2731 || (layout == GL_INSIDE_MARGIN && side == RIGHT_GLYPHS))
2734 elt = Dynarr_length (gbd) - 1;
2741 end = Dynarr_length (gbd);
2744 while (count && ((!reverse && elt < end) || (reverse && elt >= end)))
2746 struct glyph_block *gb = Dynarr_atp (gbd, elt);
2748 if (NILP (gb->extent))
2749 abort (); /* these should have been handled in add_glyph_rune */
2752 ((side == LEFT_GLYPHS &&
2753 extent_begin_glyph_layout (XEXTENT (gb->extent)) == layout)
2754 || (side == RIGHT_GLYPHS &&
2755 extent_end_glyph_layout (XEXTENT (gb->extent)) == layout)))
2759 rb.width = gb->width;
2760 rb.findex = gb->findex;
2764 rb.type = RUNE_DGLYPH;
2765 rb.object.dglyph.glyph = gb->glyph;
2766 rb.object.dglyph.extent = gb->extent;
2767 rb.object.dglyph.xoffset = 0;
2768 rb.cursor_type = CURSOR_OFF;
2770 Dynarr_add (db->runes, rb);
2775 if (glyph_contrib_p (gb->glyph, window))
2777 unsigned short ascent, descent;
2778 Lisp_Object baseline = glyph_baseline (gb->glyph, window);
2780 ascent = glyph_ascent (gb->glyph, Qnil, gb->findex, window);
2781 descent = glyph_descent (gb->glyph, Qnil, gb->findex, window);
2783 /* A pixmap that has not had a baseline explicitly set.
2784 We use the existing ascent / descent ratio of the
2786 if (NILP (baseline))
2788 int gheight = ascent + descent;
2789 int line_height = dl->ascent + dl->descent;
2790 int pix_ascent, pix_descent;
2792 pix_descent = (int) (gheight * dl->descent) / line_height;
2793 pix_ascent = gheight - pix_descent;
2795 dl->ascent = max ((int) dl->ascent, pix_ascent);
2796 dl->descent = max ((int) dl->descent, pix_descent);
2799 /* A string so determine contribution normally. */
2800 else if (EQ (baseline, Qt))
2802 dl->ascent = max (dl->ascent, ascent);
2803 dl->descent = max (dl->descent, descent);
2806 /* A pixmap with an explicitly set baseline. We determine the
2807 contribution here. */
2808 else if (INTP (baseline))
2810 int height = ascent + descent;
2811 int pix_ascent, pix_descent;
2813 pix_ascent = height * XINT (baseline) / 100;
2814 pix_descent = height - pix_ascent;
2816 dl->ascent = max ((int) dl->ascent, pix_ascent);
2817 dl->descent = max ((int) dl->descent, pix_descent);
2820 /* Otherwise something is screwed up. */
2826 (reverse ? elt-- : elt++);
2832 /* Add a blank to a margin display block. */
2835 add_margin_blank (struct display_line *dl, struct display_block *db,
2836 struct window *w, int xpos, int width, int side)
2840 rb.findex = (side == LEFT_GLYPHS
2841 ? get_builtin_face_cache_index (w, Vleft_margin_face)
2842 : get_builtin_face_cache_index (w, Vright_margin_face));
2847 rb.type = RUNE_BLANK;
2848 rb.cursor_type = CURSOR_OFF;
2850 Dynarr_add (db->runes, rb);
2853 /* Display glyphs in the left outside margin, left inside margin and
2854 left whitespace area. */
2857 create_left_glyph_block (struct window *w, struct display_line *dl,
2862 int use_overflow = (NILP (w->use_left_overflow) ? 0 : 1);
2864 int out_end, in_out_start, in_in_end, white_out_start, white_in_start;
2865 int out_cnt, in_out_cnt, in_in_cnt, white_out_cnt, white_in_cnt;
2866 int left_in_start = dl->bounds.left_in;
2867 int left_in_end = dl->bounds.left_in + overlay_width;
2869 struct display_block *odb, *idb;
2871 XSETWINDOW (window, w);
2873 /* We have to add the glyphs to the line in the order outside,
2874 inside, whitespace. However the precedence dictates that we
2875 determine how many will fit in the reverse order. */
2877 /* Determine how many whitespace glyphs we can display and where
2878 they should start. */
2879 white_in_start = dl->bounds.left_white;
2880 white_out_start = left_in_start;
2881 white_out_cnt = white_in_cnt = 0;
2884 while (elt < Dynarr_length (dl->left_glyphs))
2886 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt);
2888 if (NILP (gb->extent))
2889 abort (); /* these should have been handled in add_glyph_rune */
2891 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) == GL_WHITESPACE)
2895 width = glyph_width (gb->glyph, Qnil, gb->findex, window);
2897 if (white_in_start - width >= left_in_end)
2900 white_in_start -= width;
2904 else if (use_overflow
2905 && (white_out_start - width > dl->bounds.left_out))
2908 white_out_start -= width;
2919 /* Determine how many inside margin glyphs we can display and where
2920 they should start. The inside margin glyphs get whatever space
2921 is left after the whitespace glyphs have been displayed. These
2922 are tricky to calculate since if we decide to use the overflow
2923 area we basically have to start over. So for these we build up a
2924 list of just the inside margin glyphs and manipulate it to
2925 determine the needed info. */
2927 glyph_block_dynarr *ib;
2928 int avail_in, avail_out;
2931 int used_in, used_out;
2934 used_in = used_out = 0;
2935 ib = Dynarr_new (glyph_block);
2936 while (elt < Dynarr_length (dl->left_glyphs))
2938 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt);
2940 if (NILP (gb->extent))
2941 abort (); /* these should have been handled in add_glyph_rune */
2943 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) ==
2946 gb->width = glyph_width (gb->glyph, Qnil, gb->findex, window);
2947 used_in += gb->width;
2948 Dynarr_add (ib, *gb);
2958 avail_in = white_in_start - left_in_end;
2966 avail_out = white_out_start - dl->bounds.left_out;
2969 while (!done && marker < Dynarr_length (ib))
2971 int width = Dynarr_atp (ib, marker)->width;
2973 /* If everything now fits in the available inside margin
2974 space, we're done. */
2975 if (used_in <= avail_in)
2979 /* Otherwise see if we have room to move a glyph to the
2981 if (used_out + width <= avail_out)
2994 /* At this point we now know that everything from marker on goes in
2995 the inside margin and everything before it goes in the outside
2996 margin. The stuff going into the outside margin is guaranteed
2997 to fit, but we may have to trim some stuff from the inside. */
2999 in_in_end = left_in_end;
3000 in_out_start = white_out_start;
3001 in_out_cnt = in_in_cnt = 0;
3005 while (elt < Dynarr_length (dl->left_glyphs))
3007 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt);
3009 if (NILP (gb->extent))
3010 abort (); /* these should have been handled in add_glyph_rune */
3012 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) ==
3015 int width = glyph_width (gb->glyph, Qnil, gb->findex, window);
3020 in_out_start -= width;
3025 else if (in_in_end + width < white_in_start)
3040 /* Determine how many outside margin glyphs we can display. They
3041 always start at the left outside margin and can only use the
3042 outside margin space. */
3043 out_end = dl->bounds.left_out;
3047 while (elt < Dynarr_length (dl->left_glyphs))
3049 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt);
3051 if (NILP (gb->extent))
3052 abort (); /* these should have been handled in add_glyph_rune */
3054 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) ==
3057 int width = glyph_width (gb->glyph, Qnil, gb->findex, window);
3059 if (out_end + width <= in_out_start)
3073 /* Now that we know where everything goes, we add the glyphs as
3074 runes to the appropriate display blocks. */
3075 if (out_cnt || in_out_cnt || white_out_cnt)
3077 odb = get_display_block_from_line (dl, LEFT_OUTSIDE_MARGIN);
3078 odb->start_pos = dl->bounds.left_out;
3079 /* #### We should stop adding a blank to account for the space
3080 between the end of the glyphs and the margin and instead set
3081 this accordingly. */
3082 odb->end_pos = dl->bounds.left_in;
3083 Dynarr_reset (odb->runes);
3088 if (in_in_cnt || white_in_cnt)
3090 idb = get_display_block_from_line (dl, LEFT_INSIDE_MARGIN);
3091 idb->start_pos = dl->bounds.left_in;
3092 /* #### See above comment for odb->end_pos */
3093 idb->end_pos = dl->bounds.left_white;
3094 Dynarr_reset (idb->runes);
3099 /* First add the outside margin glyphs. */
3101 end_xpos = add_margin_runes (dl, odb, dl->bounds.left_out, out_cnt,
3102 GL_OUTSIDE_MARGIN, LEFT_GLYPHS, window);
3104 end_xpos = dl->bounds.left_out;
3106 /* There may be blank space between the outside margin glyphs and
3107 the inside margin glyphs. If so, add a blank. */
3108 if (in_out_cnt && (in_out_start - end_xpos))
3110 add_margin_blank (dl, odb, w, end_xpos, in_out_start - end_xpos,
3114 /* Next add the inside margin glyphs which are actually in the
3118 end_xpos = add_margin_runes (dl, odb, in_out_start, in_out_cnt,
3119 GL_INSIDE_MARGIN, LEFT_GLYPHS, window);
3122 /* If we didn't add any inside margin glyphs to the outside margin,
3123 but are adding whitespace glyphs, then we need to add a blank
3125 if (!in_out_cnt && white_out_cnt && (white_out_start - end_xpos))
3127 add_margin_blank (dl, odb, w, end_xpos, white_out_start - end_xpos,
3131 /* Next add the whitespace margin glyphs which are actually in the
3135 end_xpos = add_margin_runes (dl, odb, white_out_start, white_out_cnt,
3136 GL_WHITESPACE, LEFT_GLYPHS, window);
3139 /* We take care of clearing between the end of the glyphs and the
3140 start of the inside margin for lines which have glyphs. */
3141 if (odb && (left_in_start - end_xpos))
3143 add_margin_blank (dl, odb, w, end_xpos, left_in_start - end_xpos,
3147 /* Next add the inside margin glyphs which are actually in the
3151 end_xpos = add_margin_runes (dl, idb, left_in_end, in_in_cnt,
3152 GL_INSIDE_MARGIN, LEFT_GLYPHS, window);
3155 end_xpos = left_in_end;
3157 /* Make sure that the area between the end of the inside margin
3158 glyphs and the whitespace glyphs is cleared. */
3159 if (idb && (white_in_start - end_xpos > 0))
3161 add_margin_blank (dl, idb, w, end_xpos, white_in_start - end_xpos,
3165 /* Next add the whitespace margin glyphs which are actually in the
3169 add_margin_runes (dl, idb, white_in_start, white_in_cnt, GL_WHITESPACE,
3170 LEFT_GLYPHS, window);
3173 /* Whitespace glyphs always end right next to the text block so
3174 there is nothing we have to make sure is cleared after them. */
3177 /* Display glyphs in the right outside margin, right inside margin and
3178 right whitespace area. */
3181 create_right_glyph_block (struct window *w, struct display_line *dl)
3185 int use_overflow = (NILP (w->use_right_overflow) ? 0 : 1);
3187 int out_start, in_out_end, in_in_start, white_out_end, white_in_end;
3188 int out_cnt, in_out_cnt, in_in_cnt, white_out_cnt, white_in_cnt;
3190 struct display_block *odb, *idb;
3192 XSETWINDOW (window, w);
3194 /* We have to add the glyphs to the line in the order outside,
3195 inside, whitespace. However the precedence dictates that we
3196 determine how many will fit in the reverse order. */
3198 /* Determine how many whitespace glyphs we can display and where
3199 they should start. */
3200 white_in_end = dl->bounds.right_white;
3201 white_out_end = dl->bounds.right_in;
3202 white_out_cnt = white_in_cnt = 0;
3205 while (elt < Dynarr_length (dl->right_glyphs))
3207 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt);
3209 if (NILP (gb->extent))
3210 abort (); /* these should have been handled in add_glyph_rune */
3212 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_WHITESPACE)
3214 int width = glyph_width (gb->glyph, Qnil, gb->findex, window);
3216 if (white_in_end + width <= dl->bounds.right_in)
3219 white_in_end += width;
3223 else if (use_overflow
3224 && (white_out_end + width <= dl->bounds.right_out))
3227 white_out_end += width;
3238 /* Determine how many inside margin glyphs we can display and where
3239 they should start. The inside margin glyphs get whatever space
3240 is left after the whitespace glyphs have been displayed. These
3241 are tricky to calculate since if we decide to use the overflow
3242 area we basically have to start over. So for these we build up a
3243 list of just the inside margin glyphs and manipulate it to
3244 determine the needed info. */
3246 glyph_block_dynarr *ib;
3247 int avail_in, avail_out;
3250 int used_in, used_out;
3253 used_in = used_out = 0;
3254 ib = Dynarr_new (glyph_block);
3255 while (elt < Dynarr_length (dl->right_glyphs))
3257 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt);
3259 if (NILP (gb->extent))
3260 abort (); /* these should have been handled in add_glyph_rune */
3262 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_INSIDE_MARGIN)
3264 gb->width = glyph_width (gb->glyph, Qnil, gb->findex, window);
3265 used_in += gb->width;
3266 Dynarr_add (ib, *gb);
3275 avail_in = dl->bounds.right_in - white_in_end;
3280 avail_out = dl->bounds.right_out - white_out_end;
3283 while (!done && marker < Dynarr_length (ib))
3285 int width = Dynarr_atp (ib, marker)->width;
3287 /* If everything now fits in the available inside margin
3288 space, we're done. */
3289 if (used_in <= avail_in)
3293 /* Otherwise see if we have room to move a glyph to the
3295 if (used_out + width <= avail_out)
3308 /* At this point we now know that everything from marker on goes in
3309 the inside margin and everything before it goes in the outside
3310 margin. The stuff going into the outside margin is guaranteed
3311 to fit, but we may have to trim some stuff from the inside. */
3313 in_in_start = dl->bounds.right_in;
3314 in_out_end = dl->bounds.right_in;
3315 in_out_cnt = in_in_cnt = 0;
3319 while (elt < Dynarr_length (dl->right_glyphs))
3321 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt);
3323 if (NILP (gb->extent))
3324 abort (); /* these should have been handled in add_glyph_rune */
3326 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_INSIDE_MARGIN)
3328 int width = glyph_width (gb->glyph, Qnil, gb->findex, window);
3333 in_out_end += width;
3338 else if (in_in_start - width >= white_in_end)
3341 in_in_start -= width;
3353 /* Determine how many outside margin glyphs we can display. They
3354 always start at the right outside margin and can only use the
3355 outside margin space. */
3356 out_start = dl->bounds.right_out;
3360 while (elt < Dynarr_length (dl->right_glyphs))
3362 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt);
3364 if (NILP (gb->extent))
3365 abort (); /* these should have been handled in add_glyph_rune */
3367 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_OUTSIDE_MARGIN)
3369 int width = glyph_width (gb->glyph, Qnil, gb->findex, window);
3371 if (out_start - width >= in_out_end)
3385 /* Now that we now where everything goes, we add the glyphs as runes
3386 to the appropriate display blocks. */
3387 if (out_cnt || in_out_cnt || white_out_cnt)
3389 odb = get_display_block_from_line (dl, RIGHT_OUTSIDE_MARGIN);
3390 /* #### See comments before odb->start_pos init in
3391 create_left_glyph_block */
3392 odb->start_pos = dl->bounds.right_in;
3393 odb->end_pos = dl->bounds.right_out;
3394 Dynarr_reset (odb->runes);
3399 if (in_in_cnt || white_in_cnt)
3401 idb = get_display_block_from_line (dl, RIGHT_INSIDE_MARGIN);
3402 idb->start_pos = dl->bounds.right_white;
3403 /* #### See comments before odb->start_pos init in
3404 create_left_glyph_block */
3405 idb->end_pos = dl->bounds.right_in;
3406 Dynarr_reset (idb->runes);
3411 /* First add the whitespace margin glyphs which are actually in the
3415 end_xpos = add_margin_runes (dl, idb, dl->bounds.right_white,
3416 white_in_cnt, GL_WHITESPACE, RIGHT_GLYPHS,
3420 end_xpos = dl->bounds.right_white;
3422 /* Make sure that the area between the end of the whitespace glyphs
3423 and the inside margin glyphs is cleared. */
3424 if (in_in_cnt && (in_in_start - end_xpos))
3426 add_margin_blank (dl, idb, w, end_xpos, in_in_start - end_xpos,
3430 /* Next add the inside margin glyphs which are actually in the
3434 end_xpos = add_margin_runes (dl, idb, in_in_start, in_in_cnt,
3435 GL_INSIDE_MARGIN, RIGHT_GLYPHS, window);
3438 /* If we didn't add any inside margin glyphs then make sure the rest
3439 of the inside margin area gets cleared. */
3440 if (idb && (dl->bounds.right_in - end_xpos))
3442 add_margin_blank (dl, idb, w, end_xpos, dl->bounds.right_in - end_xpos,
3446 /* Next add any whitespace glyphs in the outside margin. */
3449 end_xpos = add_margin_runes (dl, odb, dl->bounds.right_in, white_out_cnt,
3450 GL_WHITESPACE, RIGHT_GLYPHS, window);
3453 end_xpos = dl->bounds.right_in;
3455 /* Next add any inside margin glyphs in the outside margin. */
3458 end_xpos = add_margin_runes (dl, odb, end_xpos, in_out_cnt,
3459 GL_INSIDE_MARGIN, RIGHT_GLYPHS, window);
3462 /* There may be space between any whitespace or inside margin glyphs
3463 in the outside margin and the actual outside margin glyphs. */
3464 if (odb && (out_start - end_xpos))
3466 add_margin_blank (dl, odb, w, end_xpos, out_start - end_xpos,
3470 /* Finally, add the outside margin glyphs. */
3473 add_margin_runes (dl, odb, out_start, out_cnt, GL_OUTSIDE_MARGIN,
3474 RIGHT_GLYPHS, window);
3479 /***************************************************************************/
3481 /* modeline routines */
3483 /***************************************************************************/
3485 /* Ensure that the given display line DL accurately represents the
3486 modeline for the given window. */
3489 generate_modeline (struct window *w, struct display_line *dl, int type)
3491 struct buffer *b = XBUFFER (w->buffer);
3492 struct frame *f = XFRAME (w->frame);
3493 struct device *d = XDEVICE (f->device);
3495 /* Unlike display line and rune pointers, this one can't change underneath
3497 struct display_block *db = get_display_block_from_line (dl, TEXT);
3498 int max_pixpos, min_pixpos, ypos_adj;
3499 Lisp_Object font_inst;
3501 /* This will actually determine incorrect inside boundaries for the
3502 modeline since it ignores the margins. However being aware of this fact
3503 we never use those values anywhere so it doesn't matter. */
3504 dl->bounds = calculate_display_line_boundaries (w, 1);
3506 /* We are generating a modeline. */
3508 dl->cursor_elt = -1;
3510 /* Reset the runes on the modeline. */
3511 Dynarr_reset (db->runes);
3513 if (!WINDOW_HAS_MODELINE_P (w))
3517 /* If there is a horizontal scrollbar, don't add anything. */
3518 if (window_scrollbar_height (w))
3521 dl->ascent = DEVMETH (d, divider_height, ());
3523 /* The modeline is at the bottom of the gutters. */
3524 dl->ypos = WINDOW_BOTTOM (w);
3526 /* adjust for the bottom gutter */
3527 if (window_is_lowest (w))
3528 dl->ypos -= FRAME_BOTTOM_GUTTER_BOUNDS (f);
3530 rb.findex = MODELINE_INDEX;
3531 rb.xpos = dl->bounds.left_out;
3532 rb.width = dl->bounds.right_out - dl->bounds.left_out;
3535 rb.type = RUNE_HLINE;
3536 rb.object.hline.thickness = 1;
3537 rb.object.hline.yoffset = 0;
3538 rb.cursor_type = NO_CURSOR;
3540 if (!EQ (Qzero, w->modeline_shadow_thickness)
3543 int shadow_thickness = MODELINE_SHADOW_THICKNESS (w);
3545 dl->ypos -= shadow_thickness;
3546 rb.xpos += shadow_thickness;
3547 rb.width -= 2 * shadow_thickness;
3550 Dynarr_add (db->runes, rb);
3554 /* !!#### not right; needs to compute the max height of
3556 font_inst = WINDOW_FACE_CACHEL_FONT (w, MODELINE_INDEX, Vcharset_ascii);
3558 dl->ascent = XFONT_INSTANCE (font_inst)->ascent;
3559 dl->descent = XFONT_INSTANCE (font_inst)->descent;
3561 min_pixpos = dl->bounds.left_out;
3562 max_pixpos = dl->bounds.right_out;
3564 if (!EQ (Qzero, w->modeline_shadow_thickness) && FRAME_WIN_P (f))
3566 int shadow_thickness = MODELINE_SHADOW_THICKNESS (w);
3568 ypos_adj = shadow_thickness;
3569 min_pixpos += shadow_thickness;
3570 max_pixpos -= shadow_thickness;
3575 generate_formatted_string_db (b->modeline_format,
3576 b->generated_modeline_string, w, dl, db,
3577 MODELINE_INDEX, min_pixpos, max_pixpos, type);
3579 /* The modeline is at the bottom of the gutters. We have to wait to
3580 set this until we've generated the modeline in order to account
3581 for any embedded faces. */
3582 dl->ypos = WINDOW_BOTTOM (w) - dl->descent - ypos_adj;
3583 /* adjust for the bottom gutter */
3584 if (window_is_lowest (w))
3585 dl->ypos -= FRAME_BOTTOM_GUTTER_BOUNDS (f);
3589 generate_formatted_string_db (Lisp_Object format_str, Lisp_Object result_str,
3590 struct window *w, struct display_line *dl,
3591 struct display_block *db, face_index findex,
3592 int min_pixpos, int max_pixpos, int type)
3594 struct frame *f = XFRAME (w->frame);
3595 struct device *d = XDEVICE (f->device);
3604 data.findex = findex;
3605 data.pixpos = min_pixpos;
3606 data.max_pixpos = max_pixpos;
3607 data.cursor_type = NO_CURSOR;
3608 data.last_charset = Qunbound;
3609 data.last_findex = DEFAULT_INDEX;
3610 data.result_str = result_str;
3611 data.is_modeline = 1;
3613 XSETWINDOW (data.window, w);
3615 Dynarr_reset (formatted_string_extent_dynarr);
3616 Dynarr_reset (formatted_string_extent_start_dynarr);
3617 Dynarr_reset (formatted_string_extent_end_dynarr);
3619 /* This recursively builds up the modeline. */
3620 generate_fstring_runes (w, &data, 0, 0, -1, format_str, 0,
3621 max_pixpos - min_pixpos, findex, type);
3623 if (Dynarr_length (db->runes))
3626 Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
3627 c_pixpos = rb->xpos + rb->width;
3630 c_pixpos = min_pixpos;
3632 /* If we don't reach the right side of the window, add a blank rune
3633 to make up the difference. This usually only occurs if the
3634 modeline face is using a proportional width font or a fixed width
3635 font of a different size from the default face font. */
3637 if (c_pixpos < max_pixpos)
3639 data.pixpos = c_pixpos;
3640 data.blank_width = max_pixpos - data.pixpos;
3642 add_blank_rune (&data, NULL, 0);
3645 /* Now create the result string and frob the extents into it. */
3646 if (!NILP (result_str))
3651 struct buffer *buf = XBUFFER (WINDOW_BUFFER (w));
3653 detach_all_extents (result_str);
3654 resize_string (XSTRING (result_str), -1,
3655 data.bytepos - XSTRING_LENGTH (result_str));
3657 strdata = XSTRING_DATA (result_str);
3659 for (elt = 0, len = 0; elt < Dynarr_length (db->runes); elt++)
3661 if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR)
3663 len += (set_charptr_emchar
3664 (strdata + len, Dynarr_atp (db->runes,
3665 elt)->object.chr.ch));
3669 for (elt = 0; elt < Dynarr_length (formatted_string_extent_dynarr);
3672 Lisp_Object extent = Qnil;
3675 XSETEXTENT (extent, Dynarr_at (formatted_string_extent_dynarr, elt));
3676 child = Fgethash (extent, buf->modeline_extent_table, Qnil);
3679 child = Fmake_extent (Qnil, Qnil, result_str);
3680 Fputhash (extent, child, buf->modeline_extent_table);
3682 Fset_extent_parent (child, extent);
3683 set_extent_endpoints
3685 Dynarr_at (formatted_string_extent_start_dynarr, elt),
3686 Dynarr_at (formatted_string_extent_end_dynarr, elt),
3693 add_string_to_fstring_db_runes (pos_data *data, CONST Bufbyte *str,
3694 Charcount pos, Charcount min_pos, Charcount max_pos)
3696 /* This function has been Mule-ized. */
3698 CONST Bufbyte *cur_pos = str;
3699 struct display_block *db = data->db;
3701 data->blank_width = space_width (XWINDOW (data->window));
3702 while (Dynarr_length (db->runes) < pos)
3703 add_blank_rune (data, NULL, 0);
3705 end = (Dynarr_length (db->runes) +
3706 bytecount_to_charcount (str, strlen ((CONST char *) str)));
3708 end = min (max_pos, end);
3710 while (pos < end && *cur_pos)
3712 CONST Bufbyte *old_cur_pos = cur_pos;
3715 data->ch = charptr_emchar (cur_pos);
3716 succeeded = (add_emchar_rune (data) != ADD_FAILED);
3717 INC_CHARPTR (cur_pos);
3721 data->modeline_charpos++;
3722 data->bytepos += cur_pos - old_cur_pos;
3726 while (Dynarr_length (db->runes) < min_pos &&
3727 (data->pixpos + data->blank_width <= data->max_pixpos))
3728 add_blank_rune (data, NULL, 0);
3730 return Dynarr_length (db->runes);
3733 /* #### Urk! Should also handle begin-glyphs and end-glyphs in
3734 modeline extents. */
3736 add_glyph_to_fstring_db_runes (pos_data *data, Lisp_Object glyph,
3737 Charcount pos, Charcount min_pos, Charcount max_pos)
3739 /* This function has been Mule-ized. */
3741 struct display_block *db = data->db;
3742 struct glyph_block gb;
3744 data->blank_width = space_width (XWINDOW (data->window));
3745 while (Dynarr_length (db->runes) < pos)
3746 add_blank_rune (data, NULL, 0);
3748 end = Dynarr_length (db->runes) + 1;
3750 end = min (max_pos, end);
3754 add_glyph_rune (data, &gb, BEGIN_GLYPHS, 0, 0);
3757 while (Dynarr_length (db->runes) < pos &&
3758 (data->pixpos + data->blank_width <= data->max_pixpos))
3759 add_blank_rune (data, NULL, 0);
3761 return Dynarr_length (db->runes);
3764 /* If max_pos is == -1, it is considered to be infinite. The same is
3765 true of max_pixsize. */
3766 #define SET_CURRENT_MODE_CHARS_PIXSIZE \
3767 if (Dynarr_length (data->db->runes)) \
3768 cur_pixsize = data->pixpos - Dynarr_atp (data->db->runes, 0)->xpos; \
3772 /* Note that this function does "positions" in terms of characters and
3773 not in terms of columns. This is necessary to make the formatting
3774 work correctly when proportional width fonts are used in the
3777 generate_fstring_runes (struct window *w, pos_data *data, Charcount pos,
3778 Charcount min_pos, Charcount max_pos,
3779 Lisp_Object elt, int depth, int max_pixsize,
3780 face_index findex, int type)
3782 /* This function has been Mule-ized. */
3783 /* #### The other losing things in this function are:
3785 -- C zero-terminated-string lossage.
3786 -- Non-printable characters should be converted into something
3787 appropriate (e.g. ^F) instead of blindly being printed anyway.
3798 /* A string. Add to the display line and check for %-constructs
3801 Bufbyte *this = XSTRING_DATA (elt);
3803 while ((pos < max_pos || max_pos == -1) && *this)
3805 Bufbyte *last = this;
3807 while (*this && *this != '%')
3812 /* The string is just a string. */
3814 bytecount_to_charcount (last, this - last) + pos;
3815 Charcount tmp_max = (max_pos == -1 ? size : min (size, max_pos));
3817 pos = add_string_to_fstring_db_runes (data, last, pos, pos,
3820 else /* *this == '%' */
3822 Charcount spec_width = 0;
3824 this++; /* skip over '%' */
3826 /* We can't allow -ve args due to the "%-" construct.
3827 * Argument specifies minwidth but not maxwidth
3828 * (maxwidth can be specified by
3829 * (<negative-number> . <stuff>) modeline elements)
3831 while (isdigit (*this))
3833 spec_width = spec_width * 10 + (*this - '0');
3840 pos = generate_fstring_runes (w, data, pos, spec_width,
3841 max_pos, Vglobal_mode_string,
3842 depth, max_pixsize, findex,
3845 else if (*this == '-')
3847 Charcount num_to_add;
3849 if (max_pixsize < 0)
3851 else if (max_pos != -1)
3852 num_to_add = max_pos - pos;
3858 SET_CURRENT_MODE_CHARS_PIXSIZE;
3861 redisplay_text_width_string (w, findex, &ch, Qnil, 0,
3864 num_to_add = (max_pixsize - cur_pixsize) / dash_pixsize;
3868 while (num_to_add--)
3869 pos = add_string_to_fstring_db_runes
3870 (data, (CONST Bufbyte *) "-", pos, pos, max_pos);
3872 else if (*this != 0)
3875 Emchar ch = charptr_emchar (this);
3876 decode_mode_spec (w, ch, type);
3878 str = Dynarr_atp (mode_spec_bufbyte_string, 0);
3879 pos = add_string_to_fstring_db_runes (data,str, pos, pos,
3883 /* NOT this++. There could be any sort of character at
3884 the current position. */
3888 if (max_pixsize > 0)
3891 SET_CURRENT_MODE_CHARS_PIXSIZE;
3893 if (cur_pixsize >= max_pixsize)
3898 else if (SYMBOLP (elt))
3900 /* A symbol: process the value of the symbol recursively
3901 as if it appeared here directly. */
3902 Lisp_Object tem = symbol_value_in_buffer (elt, w->buffer);
3904 if (!UNBOUNDP (tem))
3906 /* If value is a string, output that string literally:
3907 don't check for % within it. */
3911 add_string_to_fstring_db_runes
3912 (data, XSTRING_DATA (tem), pos, min_pos, max_pos);
3914 /* Give up right away for nil or t. */
3915 else if (!EQ (tem, elt))
3922 else if (GENERIC_SPECIFIERP (elt))
3924 Lisp_Object window, tem;
3925 XSETWINDOW (window, w);
3926 tem = specifier_instance_no_quit (elt, Qunbound, window,
3927 ERROR_ME_NOT, 0, Qzero);
3928 if (!UNBOUNDP (tem))
3934 else if (CONSP (elt))
3936 /* A cons cell: four distinct cases.
3937 * If first element is a string or a cons, process all the elements
3938 * and effectively concatenate them.
3939 * If first element is a negative number, truncate displaying cdr to
3940 * at most that many characters. If positive, pad (with spaces)
3941 * to at least that many characters.
3942 * If first element is a symbol, process the cadr or caddr recursively
3943 * according to whether the symbol's value is non-nil or nil.
3944 * If first element is a face, process the cdr recursively
3945 * without altering the depth.
3947 Lisp_Object car, tem;
3955 tem = symbol_value_in_buffer (car, w->buffer);
3956 /* elt is now the cdr, and we know it is a cons cell.
3957 Use its car if CAR has a non-nil value. */
3958 if (!UNBOUNDP (tem))
3966 /* Symbol's value is nil (or symbol is unbound)
3967 * Get the cddr of the original list
3968 * and if possible find the caddr and use that.
3973 else if (!CONSP (elt))
3981 else if (INTP (car))
3983 Charcount lim = XINT (car);
3989 /* Negative int means reduce maximum width.
3990 * DO NOT change MIN_PIXPOS here!
3991 * (20 -10 . foo) should truncate foo to 10 col
3992 * and then pad to 20.
3995 max_pos = pos - lim;
3997 max_pos = min (max_pos, pos - lim);
4001 /* Padding specified. Don't let it be more than
4005 if (max_pos != -1 && lim > max_pos)
4007 /* If that's more padding than already wanted, queue it.
4008 * But don't reduce padding already specified even if
4009 * that is beyond the current truncation point.
4016 else if (STRINGP (car) || CONSP (car))
4019 /* LIMIT is to protect against circular lists. */
4020 while (CONSP (elt) && --limit > 0
4021 && (pos < max_pos || max_pos == -1))
4023 pos = generate_fstring_runes (w, data, pos, pos, max_pos,
4025 max_pixsize, findex, type);
4029 else if (EXTENTP (car))
4031 struct extent *ext = XEXTENT (car);
4033 if (EXTENT_LIVE_P (ext))
4035 face_index old_findex = data->findex;
4037 Lisp_Object font_inst;
4038 face_index new_findex;
4039 Bytecount start = data->bytepos;
4041 face = extent_face (ext);
4044 /* #### needs to merge faces, sigh */
4045 /* #### needs to handle list of faces */
4046 new_findex = get_builtin_face_cache_index (w, face);
4047 /* !!#### not right; needs to compute the max height of
4049 font_inst = WINDOW_FACE_CACHEL_FONT (w, new_findex,
4052 data->dl->ascent = max (data->dl->ascent,
4053 XFONT_INSTANCE (font_inst)->ascent);
4054 data->dl->descent = max (data->dl->descent,
4055 XFONT_INSTANCE (font_inst)->
4059 new_findex = old_findex;
4061 data->findex = new_findex;
4062 pos = generate_fstring_runes (w, data, pos, pos, max_pos,
4063 XCDR (elt), depth - 1,
4064 max_pixsize, new_findex, type);
4065 data->findex = old_findex;
4066 Dynarr_add (formatted_string_extent_dynarr, ext);
4067 Dynarr_add (formatted_string_extent_start_dynarr, start);
4068 Dynarr_add (formatted_string_extent_end_dynarr, data->bytepos);
4072 else if (GLYPHP (elt))
4074 pos = add_glyph_to_fstring_db_runes (data, elt, pos, pos, max_pos);
4080 add_string_to_fstring_db_runes
4081 (data, (CONST Bufbyte *) GETTEXT ("*invalid*"), pos, min_pos,
4087 add_string_to_fstring_db_runes (data, (CONST Bufbyte *) "", pos, min_pos,
4094 /* The caller is responsible for freeing the returned string. */
4096 generate_formatted_string (struct window *w, Lisp_Object format_str,
4097 Lisp_Object result_str, face_index findex, int type)
4099 struct display_line *dl;
4100 struct display_block *db;
4103 dl = &formatted_string_display_line;
4104 db = get_display_block_from_line (dl, TEXT);
4105 Dynarr_reset (db->runes);
4107 generate_formatted_string_db (format_str, result_str, w, dl, db, findex, 0,
4110 Dynarr_reset (formatted_string_emchar_dynarr);
4111 while (elt < Dynarr_length (db->runes))
4113 if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR)
4114 Dynarr_add (formatted_string_emchar_dynarr,
4115 Dynarr_atp (db->runes, elt)->object.chr.ch);
4120 convert_emchar_string_into_malloced_string
4121 ( Dynarr_atp (formatted_string_emchar_dynarr, 0),
4122 Dynarr_length (formatted_string_emchar_dynarr), 0);
4125 /* Update just the modeline. Assumes the desired display structs. If
4126 they do not have a modeline block, it does nothing. */
4128 regenerate_modeline (struct window *w)
4130 display_line_dynarr *dla = window_display_lines (w, DESIRED_DISP);
4132 if (!Dynarr_length (dla) || !Dynarr_atp (dla, 0)->modeline)
4136 generate_modeline (w, Dynarr_atp (dla, 0), DESIRED_DISP);
4137 redisplay_update_line (w, 0, 0, 0);
4141 /* Make sure that modeline display line is present in the given
4142 display structs if the window has a modeline and update that
4143 line. Returns true if a modeline was needed. */
4145 ensure_modeline_generated (struct window *w, int type)
4149 /* minibuffer windows don't have modelines */
4150 if (MINI_WINDOW_P (w))
4152 /* windows which haven't had it turned off do */
4153 else if (WINDOW_HAS_MODELINE_P (w))
4155 /* windows which have it turned off don't have a divider if there is
4156 a horizontal scrollbar */
4157 else if (window_scrollbar_height (w))
4159 /* and in this case there is none */
4165 display_line_dynarr *dla;
4167 dla = window_display_lines (w, type);
4169 /* We don't care if there is a display line which is not
4170 currently a modeline because it is definitely going to become
4171 one if we have gotten to this point. */
4172 if (Dynarr_length (dla) == 0)
4174 if (Dynarr_largest (dla) > 0)
4176 struct display_line *mlp = Dynarr_atp (dla, 0);
4177 Dynarr_add (dla, *mlp);
4181 struct display_line modeline;
4183 Dynarr_add (dla, modeline);
4187 /* If we're adding a new place marker go ahead and generate the
4188 modeline so that it is available for use by
4189 window_modeline_height. */
4190 generate_modeline (w, Dynarr_atp (dla, 0), type);
4193 return need_modeline;
4196 /* #### Kludge or not a kludge. I tend towards the former. */
4198 real_current_modeline_height (struct window *w)
4200 Fset_marker (w->start[CMOTION_DISP], w->start[CURRENT_DISP], w->buffer);
4201 Fset_marker (w->pointm[CMOTION_DISP], w->pointm[CURRENT_DISP], w->buffer);
4203 if (ensure_modeline_generated (w, CMOTION_DISP))
4205 display_line_dynarr *dla = window_display_lines (w, CMOTION_DISP);
4207 if (Dynarr_length (dla))
4209 if (Dynarr_atp (dla, 0)->modeline)
4210 return (Dynarr_atp (dla, 0)->ascent +
4211 Dynarr_atp (dla, 0)->descent);
4218 /***************************************************************************/
4220 /* displayable string routines */
4222 /***************************************************************************/
4224 /* Given a position for a string in a window, ensure that the given
4225 display line DL accurately represents the text on a line starting
4226 at the given position.
4228 Yes, this is duplicating the code of create_text_block, but it
4229 looked just too hard to change create_text_block to handle strings
4230 *and* buffers. We already make a distinction between the two
4231 elsewhere in the code so I think unifying them would require a
4232 complete MULE rewrite. Besides, the other distinction is that these
4233 functions cover text that the user *cannot edit* so we can remove
4234 everything to do with cursors, minibuffers etc. Eventually the
4235 modeline routines should be modified to use this code as it copes
4236 with many more types of display situation. */
4239 create_string_text_block (struct window *w, Lisp_Object disp_string,
4240 struct display_line *dl,
4242 prop_block_dynarr **prop,
4243 face_index default_face)
4245 struct frame *f = XFRAME (w->frame);
4246 /* Note that a lot of the buffer controlled stuff has been left in
4247 because you might well want to make use of it (selective display
4248 etc), its just the buffer text that we do not use. However, it
4249 seems to be possible for buffer to be nil sometimes so protect
4250 against this case. */
4251 struct buffer *b = BUFFERP (w->buffer) ? XBUFFER (w->buffer) : 0;
4252 struct device *d = XDEVICE (f->device);
4253 struct Lisp_String* s = XSTRING (disp_string);
4255 /* we're working with these a lot so precalculate them */
4256 Bytecount slen = XSTRING_LENGTH (disp_string);
4257 Bytecount bi_string_zv = slen;
4258 Bytind bi_start_pos = charcount_to_bytecount (string_data (s), start_pos);
4262 int truncate_win = b ? window_truncation_on (w) : 0;
4263 int end_glyph_width = 0;
4265 /* we're going to ditch selective display for static text, its an
4266 FSF thing and invisble extents are the way to go
4267 here. Implementing it also relies on a number of buffer-specific
4268 functions that we don't have the luxury of being able to use
4271 /* The variable ctl-arrow allows the user to specify what characters
4272 can actually be displayed and which octal should be used for.
4273 #### This variable should probably have some rethought done to
4276 #### It would also be really nice if you could specify that
4277 the characters come out in hex instead of in octal. Mule
4278 does that by adding a ctl-hexa variable similar to ctl-arrow,
4279 but that's bogus -- we need a more general solution. I
4280 think you need to extend the concept of display tables
4281 into a more general conversion mechanism. Ideally you
4282 could specify a Lisp function that converts characters,
4283 but this violates the Second Golden Rule and besides would
4284 make things way way way way slow.
4286 So instead, we extend the display-table concept, which was
4287 historically limited to 256-byte vectors, to one of the
4290 a) A 256-entry vector, for backward compatibility;
4291 b) char-table, mapping characters to values;
4292 c) range-table, mapping ranges of characters to values;
4293 d) a list of the above.
4295 The (d) option allows you to specify multiple display tables
4296 instead of just one. Each display table can specify conversions
4297 for some characters and leave others unchanged. The way the
4298 character gets displayed is determined by the first display table
4299 with a binding for that character. This way, you could call a
4300 function `enable-hex-display' that adds a hex display-table to
4301 the list of display tables for the current buffer.
4303 #### ...not yet implemented... Also, we extend the concept of
4304 "mapping" to include a printf-like spec. Thus you can make all
4305 extended characters show up as hex with a display table like
4308 #s(range-table data ((256 524288) (format "%x")))
4310 Since more than one display table is possible, you have
4311 great flexibility in mapping ranges of characters. */
4312 Emchar printable_min = b ? (CHAR_OR_CHAR_INTP (b->ctl_arrow)
4313 ? XCHAR_OR_CHAR_INT (b->ctl_arrow)
4314 : ((EQ (b->ctl_arrow, Qt) || EQ (b->ctl_arrow, Qnil))
4315 ? 255 : 160)) : 255;
4317 Lisp_Object face_dt, window_dt;
4319 /* The text display block for this display line. */
4320 struct display_block *db = get_display_block_from_line (dl, TEXT);
4322 /* The first time through the main loop we need to force the glyph
4323 data to be updated. */
4326 /* Apparently the new extent_fragment_update returns an end position
4327 equal to the position passed in if there are no more runs to be
4329 int no_more_frags = 0;
4331 dl->used_prop_data = 0;
4334 /* set up faces to use for clearing areas, used by
4335 output_display_line */
4336 dl->default_findex = default_face;
4339 dl->left_margin_findex = default_face;
4340 dl->right_margin_findex = default_face;
4344 dl->left_margin_findex =
4345 get_builtin_face_cache_index (w, Vleft_margin_face);
4346 dl->right_margin_findex =
4347 get_builtin_face_cache_index (w, Vright_margin_face);
4351 data.ef = extent_fragment_new (disp_string, f);
4353 /* These values are used by all of the rune addition routines. We add
4354 them to this structure for ease of passing. */
4356 XSETWINDOW (data.window, w);
4360 data.bi_bufpos = bi_start_pos;
4361 data.pixpos = dl->bounds.left_in;
4362 data.last_charset = Qunbound;
4363 data.last_findex = default_face;
4364 data.result_str = Qnil;
4365 data.string = disp_string;
4367 /* Set the right boundary adjusting it to take into account any end
4368 glyph. Save the width of the end glyph for later use. */
4369 data.max_pixpos = dl->bounds.right_in;
4372 end_glyph_width = GLYPH_CACHEL_WIDTH (w, TRUN_GLYPH_INDEX);
4374 end_glyph_width = GLYPH_CACHEL_WIDTH (w, CONT_GLYPH_INDEX);
4376 data.max_pixpos -= end_glyph_width;
4378 data.cursor_type = NO_CURSOR;
4382 /* I don't think we want this, string areas should not scroll with
4384 data.start_col = w->hscroll;
4385 data.bi_start_col_enabled = (w->hscroll ? bi_start_pos : 0);
4387 data.bi_start_col_enabled = 0;
4388 data.hscroll_glyph_width_adjust = 0;
4390 /* We regenerate the line from the very beginning. */
4391 Dynarr_reset (db->runes);
4393 /* Why is this less than or equal and not just less than? If the
4394 starting position is already equal to the maximum we can't add
4395 anything else, right? Wrong. We might still have a newline to
4396 add. A newline can use the room allocated for an end glyph since
4397 if we add it we know we aren't going to be adding any end
4400 /* #### Chuck -- I think this condition should be while (1).
4401 Otherwise if (e.g.) there is one begin-glyph and one end-glyph
4402 and the begin-glyph ends exactly at the end of the window, the
4403 end-glyph and text might not be displayed. while (1) ensures
4404 that the loop terminates only when either (a) there is
4405 propagation data or (b) the end-of-line or end-of-buffer is hit.
4407 #### Also I think you need to ensure that the operation
4408 "add begin glyphs; add end glyphs; add text" is atomic and
4409 can't get interrupted in the middle. If you run off the end
4410 of the line during that operation, then you keep accumulating
4411 propagation data until you're done. Otherwise, if the (e.g.)
4412 there's a begin glyph at a particular position and attempting
4413 to display that glyph results in window-end being hit and
4414 propagation data being generated, then the character at that
4415 position won't be displayed.
4417 #### See also the comment after the end of this loop, below.
4419 while (data.pixpos <= data.max_pixpos)
4421 /* #### This check probably should not be necessary. */
4422 if (data.bi_bufpos > bi_string_zv)
4424 /* #### urk! More of this lossage! */
4429 /* Check for face changes. */
4430 if (initial || (!no_more_frags && data.bi_bufpos == data.ef->end))
4432 /* Now compute the face and begin/end-glyph information. */
4434 /* Remember that the extent-fragment routines deal in Bytind's. */
4435 extent_fragment_update (w, data.ef, data.bi_bufpos);
4436 /* This is somewhat cheesy but the alternative is to
4437 propagate default_face into extent_fragment_update. */
4438 if (data.findex == DEFAULT_INDEX)
4439 data.findex = default_face;
4441 get_display_tables (w, data.findex, &face_dt, &window_dt);
4443 if (data.bi_bufpos == data.ef->end)
4448 /* Determine what is next to be displayed. We first handle any
4449 glyphs returned by glyphs_at_bufpos. If there are no glyphs to
4450 display then we determine what to do based on the character at the
4451 current buffer position. */
4453 /* If the current position is covered by an invisible extent, do
4454 nothing (except maybe add some ellipses).
4456 #### The behavior of begin and end-glyphs at the edge of an
4457 invisible extent should be investigated further. This is
4458 fairly low priority though. */
4459 if (data.ef->invisible)
4461 /* #### Chuck, perhaps you could look at this code? I don't
4462 really know what I'm doing. */
4465 Dynarr_free (*prop);
4469 /* The extent fragment code only sets this when we should
4470 really display the ellipses. It makes sure the ellipses
4471 don't get displayed more than once in a row. */
4472 if (data.ef->invisible_ellipses)
4474 struct glyph_block gb;
4476 data.ef->invisible_ellipses_already_displayed = 1;
4477 data.ef->invisible_ellipses = 0;
4479 gb.glyph = Vinvisible_text_glyph;
4480 *prop = add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0,
4481 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX));
4482 /* Perhaps they shouldn't propagate if the very next thing
4483 is to display a newline (for compatibility with
4484 selective-display-ellipses)? Maybe that's too
4490 /* #### What if we we're dealing with a display table? */
4494 if (data.bi_bufpos == bi_string_zv)
4497 INC_CHARBYTIND (string_data (s), data.bi_bufpos);
4500 /* If there is propagation data, then it represents the current
4501 buffer position being displayed. Add them and advance the
4502 position counter. This might also add the minibuffer
4506 dl->used_prop_data = 1;
4507 *prop = add_propagation_runes (prop, &data);
4510 goto done; /* gee, a really narrow window */
4511 else if (data.bi_bufpos == bi_string_zv)
4513 else if (data.bi_bufpos < 0)
4514 /* #### urk urk urk! Aborts are not very fun! Fix this please! */
4517 INC_CHARBYTIND (string_data (s), data.bi_bufpos);
4520 /* If there are end glyphs, add them to the line. These are
4521 the end glyphs for the previous run of text. We add them
4522 here rather than doing them at the end of handling the
4523 previous run so that glyphs at the beginning and end of
4524 a line are handled correctly. */
4525 else if (Dynarr_length (data.ef->end_glyphs) > 0)
4527 *prop = add_glyph_runes (&data, END_GLYPHS);
4532 /* If there are begin glyphs, add them to the line. */
4533 else if (Dynarr_length (data.ef->begin_glyphs) > 0)
4535 *prop = add_glyph_runes (&data, BEGIN_GLYPHS);
4540 /* If at end-of-buffer, we've already processed begin and
4541 end-glyphs at this point and there's no text to process,
4543 else if (data.bi_bufpos == bi_string_zv)
4548 Lisp_Object entry = Qnil;
4549 /* Get the character at the current buffer position. */
4550 data.ch = string_char (s, data.bi_bufpos);
4551 if (!NILP (face_dt) || !NILP (window_dt))
4552 entry = display_table_entry (data.ch, face_dt, window_dt);
4554 /* If there is a display table entry for it, hand it off to
4555 add_disp_table_entry_runes and let it worry about it. */
4556 if (!NILP (entry) && !EQ (entry, make_char (data.ch)))
4558 *prop = add_disp_table_entry_runes (&data, entry);
4564 /* Check if we have hit a newline character. If so, add a marker
4565 to the line and end this loop. */
4566 else if (data.ch == '\n')
4568 /* We aren't going to be adding an end glyph so give its
4569 space back in order to make sure that the cursor can
4571 data.max_pixpos += end_glyph_width;
4575 /* If the current character is considered to be printable, then
4577 else if (data.ch >= printable_min)
4579 *prop = add_emchar_rune (&data);
4584 /* If the current character is a tab, determine the next tab
4585 starting position and add a blank rune which extends from the
4586 current pixel position to that starting position. */
4587 else if (data.ch == '\t')
4589 int tab_start_pixpos = data.pixpos;
4594 if (data.start_col > 1)
4595 tab_start_pixpos -= (space_width (w) * (data.start_col - 1));
4598 next_tab_position (w, tab_start_pixpos,
4599 dl->bounds.left_in +
4600 data.hscroll_glyph_width_adjust);
4601 if (next_tab_start > data.max_pixpos)
4603 prop_width = next_tab_start - data.max_pixpos;
4604 next_tab_start = data.max_pixpos;
4606 data.blank_width = next_tab_start - data.pixpos;
4608 (next_tab_start - tab_start_pixpos) / space_width (w);
4610 *prop = add_blank_rune (&data, w, char_tab_width);
4612 /* add_blank_rune is only supposed to be called with
4613 sizes guaranteed to fit in the available space. */
4618 struct prop_block pb;
4619 *prop = Dynarr_new (prop_block);
4621 pb.type = PROP_BLANK;
4622 pb.data.p_blank.width = prop_width;
4623 pb.data.p_blank.findex = data.findex;
4624 Dynarr_add (*prop, pb);
4630 /* If character is a control character, pass it off to
4631 add_control_char_runes.
4633 The is_*() routines have undefined results on
4634 arguments outside of the range [-1, 255]. (This
4635 often bites people who carelessly use `char' instead
4636 of `unsigned char'.)
4638 else if (data.ch < 0x100 && iscntrl ((Bufbyte) data.ch))
4640 *prop = add_control_char_runes (&data, b);
4646 /* If the character is above the ASCII range and we have not
4647 already handled it, then print it as an octal number. */
4648 else if (data.ch >= 0200)
4650 *prop = add_octal_runes (&data);
4656 /* Assume the current character is considered to be printable,
4657 then just add it. */
4660 *prop = add_emchar_rune (&data);
4665 INC_CHARBYTIND (string_data (s), data.bi_bufpos);
4671 /* Determine the starting point of the next line if we did not hit the
4672 end of the buffer. */
4673 if (data.bi_bufpos < bi_string_zv)
4675 /* #### This check is not correct. If the line terminated
4676 due to a begin-glyph or end-glyph hitting window-end, then
4677 data.ch will not point to the character at data.bi_bufpos. If
4678 you make the two changes mentioned at the top of this loop,
4679 you should be able to say '(if (*prop))'. That should also
4680 make it possible to eliminate the data.bi_bufpos < BI_BUF_ZV (b)
4683 /* The common case is that the line ended because we hit a newline.
4684 In that case, the next character is just the next buffer
4686 if (data.ch == '\n')
4688 INC_CHARBYTIND (string_data (s), data.bi_bufpos);
4691 /* Otherwise we have a buffer line which cannot fit on one display
4695 struct glyph_block gb;
4696 struct glyph_cachel *cachel;
4698 /* If the line is to be truncated then we actually have to look
4699 for the next newline. We also add the end-of-line glyph which
4700 we know will fit because we adjusted the right border before
4701 we starting laying out the line. */
4702 data.max_pixpos += end_glyph_width;
4703 data.findex = default_face;
4710 /* Now find the start of the next line. */
4711 bi_pos = bi_find_next_emchar_in_string (s, '\n', data.bi_bufpos, 1);
4713 data.cursor_type = NO_CURSOR;
4714 data.bi_bufpos = bi_pos;
4715 gb.glyph = Vtruncation_glyph;
4716 cachel = GLYPH_CACHEL (w, TRUN_GLYPH_INDEX);
4720 /* The cursor can never be on the continuation glyph. */
4721 data.cursor_type = NO_CURSOR;
4723 /* data.bi_bufpos is already at the start of the next line. */
4725 gb.glyph = Vcontinuation_glyph;
4726 cachel = GLYPH_CACHEL (w, CONT_GLYPH_INDEX);
4729 if (end_glyph_width)
4730 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, cachel);
4732 if (truncate_win && data.bi_bufpos == bi_string_zv)
4734 CONST Bufbyte* endb = charptr_n_addr (string_data (s), bi_string_zv);
4736 if (charptr_emchar (endb) != '\n')
4738 /* #### Damn this losing shit. */
4744 else if (data.bi_bufpos == bi_string_zv)
4746 /* create_text_block () adds a bogus \n marker here which screws
4747 up subwindow display. Since we never have a cursor in the
4748 gutter we can safely ignore it. */
4750 /* Calculate left whitespace boundary. */
4754 /* Whitespace past a newline is considered right whitespace. */
4755 while (elt < Dynarr_length (db->runes))
4757 struct rune *rb = Dynarr_atp (db->runes, elt);
4759 if ((rb->type == RUNE_CHAR && rb->object.chr.ch == ' ')
4760 || rb->type == RUNE_BLANK)
4762 dl->bounds.left_white += rb->width;
4766 elt = Dynarr_length (db->runes);
4770 /* Calculate right whitespace boundary. */
4772 int elt = Dynarr_length (db->runes) - 1;
4775 while (!done && elt >= 0)
4777 struct rune *rb = Dynarr_atp (db->runes, elt);
4779 if (!(rb->type == RUNE_CHAR && rb->object.chr.ch < 0x100
4780 && isspace (rb->object.chr.ch))
4781 && !rb->type == RUNE_BLANK)
4783 dl->bounds.right_white = rb->xpos + rb->width;
4791 /* The line is blank so everything is considered to be right
4794 dl->bounds.right_white = dl->bounds.left_in;
4797 /* Set the display blocks bounds. */
4798 db->start_pos = dl->bounds.left_in;
4799 if (Dynarr_length (db->runes))
4801 struct rune *rb = Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
4803 db->end_pos = rb->xpos + rb->width;
4806 db->end_pos = dl->bounds.right_white;
4808 /* update line height parameters */
4809 if (!data.new_ascent && !data.new_descent)
4811 /* We've got a blank line so initialize these values from the default
4813 default_face_font_info (data.window, &data.new_ascent,
4814 &data.new_descent, 0, 0, 0);
4817 if (data.max_pixmap_height)
4819 int height = data.new_ascent + data.new_descent;
4820 int pix_ascent, pix_descent;
4822 pix_descent = data.max_pixmap_height * data.new_descent / height;
4823 pix_ascent = data.max_pixmap_height - pix_descent;
4825 data.new_ascent = max (data.new_ascent, pix_ascent);
4826 data.new_descent = max (data.new_descent, pix_descent);
4829 dl->ascent = data.new_ascent;
4830 dl->descent = data.new_descent;
4833 unsigned short ascent = (unsigned short) XINT (w->minimum_line_ascent);
4835 if (dl->ascent < ascent)
4836 dl->ascent = ascent;
4839 unsigned short descent = (unsigned short) XINT (w->minimum_line_descent);
4841 if (dl->descent < descent)
4842 dl->descent = descent;
4845 dl->cursor_elt = data.cursor_x;
4846 /* #### lossage lossage lossage! Fix this shit! */
4847 if (data.bi_bufpos > bi_string_zv)
4848 dl->end_bufpos = buffer_or_string_bytind_to_bufpos (disp_string, bi_string_zv);
4850 dl->end_bufpos = buffer_or_string_bytind_to_bufpos (disp_string, data.bi_bufpos) - 1;
4852 data.dl->num_chars =
4853 string_column_at_point (s, dl->end_bufpos, b ? XINT (b->tab_width) : 8);
4855 /* This doesn't correctly take into account tabs and control
4856 characters but if the window isn't being truncated then this
4857 value isn't going to end up being used anyhow. */
4858 data.dl->num_chars = dl->end_bufpos - dl->bufpos;
4860 /* #### handle horizontally scrolled line with text none of which
4861 was actually laid out. */
4863 /* #### handle any remainder of overlay arrow */
4865 if (*prop == ADD_FAILED)
4868 if (truncate_win && *prop)
4870 Dynarr_free (*prop);
4874 extent_fragment_delete (data.ef);
4876 /* #### If we started at EOB, then make sure we return a value past
4877 it so that regenerate_window will exit properly. This is bogus.
4878 The main loop should get fixed so that it isn't necessary to call
4879 this function if we are already at EOB. */
4881 if (data.bi_bufpos == bi_string_zv && bi_start_pos == bi_string_zv)
4882 return bytecount_to_charcount (string_data (s), data.bi_bufpos) + 1; /* Yuck! */
4884 return bytecount_to_charcount (string_data (s), data.bi_bufpos);
4887 /* Given a display line and a starting position, ensure that the
4888 contents of the display line accurately represent the visual
4889 representation of the buffer contents starting from the given
4890 position when displayed in the given window. The display line ends
4891 when the contents of the line reach the right boundary of the given
4894 This is very similar to generate_display_line but with the same
4895 limitations as create_string_text_block. I have taken the liberty
4896 of fixing the bytind stuff though.*/
4899 generate_string_display_line (struct window *w, Lisp_Object disp_string,
4900 struct display_line *dl,
4902 prop_block_dynarr **prop,
4903 face_index default_face)
4907 /* you must set bounds before calling this. */
4909 /* Reset what this line is using. */
4910 if (dl->display_blocks)
4911 Dynarr_reset (dl->display_blocks);
4912 if (dl->left_glyphs)
4914 Dynarr_free (dl->left_glyphs);
4915 dl->left_glyphs = 0;
4917 if (dl->right_glyphs)
4919 Dynarr_free (dl->right_glyphs);
4920 dl->right_glyphs = 0;
4923 /* We aren't generating a modeline at the moment. */
4926 /* Create a display block for the text region of the line. */
4927 ret_bufpos = create_string_text_block (w, disp_string, dl, start_pos,
4928 prop, default_face);
4929 dl->bufpos = start_pos;
4930 if (dl->end_bufpos < dl->bufpos)
4931 dl->end_bufpos = dl->bufpos;
4933 /* If there are left glyphs associated with any character in the
4934 text block, then create a display block to handle them. */
4935 if (dl->left_glyphs != NULL && Dynarr_length (dl->left_glyphs))
4936 create_left_glyph_block (w, dl, 0);
4938 /* If there are right glyphs associated with any character in the
4939 text block, then create a display block to handle them. */
4940 if (dl->right_glyphs != NULL && Dynarr_length (dl->right_glyphs))
4941 create_right_glyph_block (w, dl);
4946 /* This is ripped off from regenerate_window. All we want to do is
4947 loop through elements in the string creating display lines until we
4948 have covered the provided area. Simple really. */
4950 generate_displayable_area (struct window *w, Lisp_Object disp_string,
4951 int xpos, int ypos, int width, int height,
4952 display_line_dynarr* dla,
4954 face_index default_face)
4956 int yend = ypos + height;
4959 prop_block_dynarr *prop = 0;
4960 layout_bounds bounds;
4964 /* if there's nothing to do then do nothing. code after this assumes
4965 there is something to do. */
4966 if (NILP (disp_string))
4969 s_zv = XSTRING_CHAR_LENGTH (disp_string);
4971 bounds.left_out = xpos;
4972 bounds.right_out = xpos + width;
4973 /* The inner boundaries mark where the glyph margins are located. */
4974 bounds.left_in = bounds.left_out + window_left_margin_width (w);
4975 bounds.right_in = bounds.right_out - window_right_margin_width (w);
4976 /* We cannot fully calculate the whitespace boundaries as they
4977 depend on the contents of the line being displayed. */
4978 bounds.left_white = bounds.left_in;
4979 bounds.right_white = bounds.right_in;
4983 struct display_line dl;
4984 struct display_line *dlp;
4988 if (Dynarr_length (dla) < Dynarr_largest (dla))
4990 dlp = Dynarr_atp (dla, Dynarr_length (dla));
5001 dlp->bounds = bounds;
5003 next_pos = generate_string_display_line (w, disp_string, dlp, start_pos,
5004 &prop, default_face);
5005 /* we need to make sure that we continue along the line if there
5006 is more left to display otherwise we just end up redisplaying
5007 the same chunk over and over again. */
5008 if (next_pos == start_pos && next_pos < s_zv)
5011 start_pos = next_pos;
5013 dlp->ypos = ypos + dlp->ascent;
5014 ypos = dlp->ypos + dlp->descent;
5018 int visible_height = dlp->ascent + dlp->descent;
5020 dlp->clip = (ypos - yend);
5021 visible_height -= dlp->clip;
5023 if (visible_height < VERTICAL_CLIP (w, 1))
5026 free_display_line (dlp);
5033 Dynarr_add (dla, *dlp);
5035 /* #### This type of check needs to be done down in the
5036 generate_display_line call. */
5037 if (start_pos >= s_zv)
5046 /***************************************************************************/
5048 /* window-regeneration routines */
5050 /***************************************************************************/
5052 /* For a given window and starting position in the buffer it contains,
5053 ensure that the TYPE display lines accurately represent the
5054 presentation of the window. We pass the buffer instead of getting
5055 it from the window since redisplay_window may have temporarily
5056 changed it to the echo area buffer. */
5059 regenerate_window (struct window *w, Bufpos start_pos, Bufpos point, int type)
5061 struct frame *f = XFRAME (w->frame);
5062 struct buffer *b = XBUFFER (w->buffer);
5063 int ypos = WINDOW_TEXT_TOP (w);
5064 int yend; /* set farther down */
5065 int yclip = WINDOW_TEXT_TOP_CLIP (w);
5067 prop_block_dynarr *prop;
5068 layout_bounds bounds;
5069 display_line_dynarr *dla;
5072 /* The lines had better exist by this point. */
5073 if (!(dla = window_display_lines (w, type)))
5076 w->max_line_len = 0;
5078 /* Normally these get updated in redisplay_window but it is possible
5079 for this function to get called from some other points where that
5080 update may not have occurred. This acts as a safety check. */
5081 if (!Dynarr_length (w->face_cachels))
5082 reset_face_cachels (w);
5083 if (!Dynarr_length (w->glyph_cachels))
5084 reset_glyph_cachels (w);
5086 Fset_marker (w->start[type], make_int (start_pos), w->buffer);
5087 Fset_marker (w->pointm[type], make_int (point), w->buffer);
5088 w->last_point_x[type] = -1;
5089 w->last_point_y[type] = -1;
5091 /* Make sure a modeline is in the structs if needed. */
5092 need_modeline = ensure_modeline_generated (w, type);
5094 /* Wait until here to set this so that the structs have a modeline
5095 generated in the case where one didn't exist. */
5096 yend = WINDOW_TEXT_BOTTOM (w);
5098 bounds = calculate_display_line_boundaries (w, 0);
5100 /* 97/3/14 jhod: stuff added here to support pre-prompts (used for input systems) */
5101 if (MINI_WINDOW_P (w)
5102 && (!NILP (Vminibuf_prompt) || !NILP (Vminibuf_preprompt))
5103 && !echo_area_active (f)
5104 && start_pos == BUF_BEGV (b))
5106 struct prop_block pb;
5108 prop = Dynarr_new (prop_block);
5110 string = concat2(Vminibuf_preprompt, Vminibuf_prompt);
5111 pb.type = PROP_MINIBUF_PROMPT;
5112 pb.data.p_string.str = XSTRING_DATA(string);
5113 pb.data.p_string.len = XSTRING_LENGTH(string);
5114 Dynarr_add (prop, pb);
5121 struct display_line dl;
5122 struct display_line *dlp;
5125 if (Dynarr_length (dla) < Dynarr_largest (dla))
5127 dlp = Dynarr_atp (dla, Dynarr_length (dla));
5138 dlp->bounds = bounds;
5140 start_pos = generate_display_line (w, dlp, 1, start_pos, &prop, type);
5142 if (yclip > dlp->ascent)
5144 /* this should never happen, but if it does just display the
5149 dlp->ypos = (ypos + dlp->ascent) - yclip;
5150 ypos = dlp->ypos + dlp->descent;
5152 /* See if we've been asked to start midway through a line, for
5153 partial display line scrolling. */
5156 dlp->top_clip = yclip;
5164 int visible_height = dlp->ascent + dlp->descent;
5166 dlp->clip = (ypos - yend);
5167 /* Although this seems strange we could have a single very
5168 tall line visible for which we need to account for both
5169 the top clip and the bottom clip. */
5170 visible_height -= (dlp->clip + dlp->top_clip);
5172 if (visible_height < VERTICAL_CLIP (w, 1))
5175 free_display_line (dlp);
5182 if (dlp->cursor_elt != -1)
5184 /* #### This check is steaming crap. Have to get things
5185 fixed so when create_text_block hits EOB, we're done,
5187 if (w->last_point_x[type] == -1)
5189 w->last_point_x[type] = dlp->cursor_elt;
5190 w->last_point_y[type] = Dynarr_length (dla);
5194 /* #### This means that we've added a cursor at EOB
5195 twice. Yuck oh yuck. */
5196 struct display_block *db =
5197 get_display_block_from_line (dlp, TEXT);
5199 Dynarr_atp (db->runes, dlp->cursor_elt)->cursor_type = NO_CURSOR;
5200 dlp->cursor_elt = -1;
5204 if (dlp->num_chars > w->max_line_len)
5205 w->max_line_len = dlp->num_chars;
5207 Dynarr_add (dla, *dlp);
5209 /* #### This isn't right, but it is close enough for now. */
5210 w->window_end_pos[type] = start_pos;
5212 /* #### This type of check needs to be done down in the
5213 generate_display_line call. */
5214 if (start_pos > BUF_ZV (b))
5221 /* #### More not quite right, but close enough. */
5222 /* #### Ben sez: apparently window_end_pos[] is measured
5223 as the number of characters between the window end and the
5224 end of the buffer? This seems rather weirdo. What's
5225 the justification for this? */
5226 w->window_end_pos[type] = BUF_Z (b) - w->window_end_pos[type];
5230 /* We know that this is the right thing to use because we put it
5231 there when we first started working in this function. */
5232 generate_modeline (w, Dynarr_atp (dla, 0), type);
5236 #define REGEN_INC_FIND_START_END \
5238 /* Determine start and end of lines. */ \
5239 if (!Dynarr_length (cdla)) \
5243 if (Dynarr_atp (cdla, 0)->modeline && Dynarr_atp (ddla, 0)->modeline) \
5247 else if (!Dynarr_atp (cdla, 0)->modeline \
5248 && !Dynarr_atp (ddla, 0)->modeline) \
5253 abort (); /* structs differ */ \
5255 dla_end = Dynarr_length (cdla) - 1; \
5258 start_pos = (Dynarr_atp (cdla, dla_start)->bufpos \
5259 + Dynarr_atp (cdla, dla_start)->offset); \
5260 /* If this isn't true, then startp has changed and we need to do a \
5262 if (startp != start_pos) \
5265 /* Point is outside the visible region so give up. */ \
5266 if (pointm < start_pos) \
5271 /* This attempts to incrementally update the display structures. It
5272 returns a boolean indicating success or failure. This function is
5273 very similar to regenerate_window_incrementally and is in fact only
5274 called from that function. However, because of the nature of the
5275 changes it deals with it sometimes makes different assumptions
5276 which can lead to success which are much more difficult to make
5277 when dealing with buffer changes. */
5280 regenerate_window_extents_only_changed (struct window *w, Bufpos startp,
5282 Charcount beg_unchanged,
5283 Charcount end_unchanged)
5285 struct buffer *b = XBUFFER (w->buffer);
5286 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
5287 display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP);
5291 int first_line, last_line;
5293 /* Don't define this in the loop where it is used because we
5294 definitely want its value to survive between passes. */
5295 prop_block_dynarr *prop = NULL;
5297 /* If we don't have any buffer change recorded but the modiff flag has
5298 been incremented, then fail. I'm not sure of the exact circumstances
5299 under which this can happen, but I believe that it is probably a
5300 reasonable happening. */
5301 if (!point_visible (w, pointm, CURRENT_DISP)
5302 || XINT (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b))
5305 /* If the cursor is moved we attempt to update it. If we succeed we
5306 go ahead and proceed with the optimization attempt. */
5307 if (!EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer)
5308 || pointm != marker_position (w->last_point[CURRENT_DISP]))
5310 struct frame *f = XFRAME (w->frame);
5311 struct device *d = XDEVICE (f->device);
5312 struct frame *sel_f = device_selected_frame (d);
5315 if (w->last_point_x[CURRENT_DISP] != -1
5316 && w->last_point_y[CURRENT_DISP] != -1)
5319 if (redisplay_move_cursor (w, pointm, WINDOW_TTY_P (w)))
5321 /* Always regenerate the modeline in case it is
5322 displaying the current line or column. */
5323 regenerate_modeline (w);
5327 else if (w != XWINDOW (FRAME_SELECTED_WINDOW (sel_f)))
5329 if (f->modeline_changed)
5330 regenerate_modeline (w);
5338 if (beg_unchanged == -1 && end_unchanged == -1)
5341 /* assert: There are no buffer modifications or they are all below the
5342 visible region. We assume that regenerate_window_incrementally has
5343 not called us unless this is true. */
5345 REGEN_INC_FIND_START_END;
5347 /* If the changed are starts before the visible area, give up. */
5348 if (beg_unchanged < startp)
5351 /* Find what display line the extent changes first affect. */
5353 while (line <= dla_end)
5355 struct display_line *dl = Dynarr_atp (cdla, line);
5356 Bufpos lstart = dl->bufpos + dl->offset;
5357 Bufpos lend = dl->end_bufpos + dl->offset;
5359 if (beg_unchanged >= lstart && beg_unchanged <= lend)
5365 /* If the changes are below the visible area then if point hasn't
5366 moved return success otherwise fail in order to be safe. */
5369 if (EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer)
5370 && pointm == marker_position (w->last_point[CURRENT_DISP]))
5376 /* At this point we know what line the changes first affect. We now
5377 begin redrawing lines as long as we are still in the affected
5378 region and the line's size and positioning don't change.
5379 Otherwise we fail. If we fail we will have altered the desired
5380 structs which could lead to an assertion failure. However, if we
5381 fail the next thing that is going to happen is a full regen so we
5382 will actually end up being safe. */
5383 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b));
5384 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b));
5385 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp), w->buffer);
5386 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm), w->buffer);
5388 first_line = last_line = line;
5389 while (line <= dla_end)
5391 Bufpos old_start, old_end, new_start;
5392 struct display_line *cdl = Dynarr_atp (cdla, line);
5393 struct display_line *ddl = Dynarr_atp (ddla, line);
5394 struct display_block *db;
5397 assert (cdl->bufpos == ddl->bufpos);
5398 assert (cdl->end_bufpos == ddl->end_bufpos);
5399 assert (cdl->offset == ddl->offset);
5401 db = get_display_block_from_line (ddl, TEXT);
5402 initial_size = Dynarr_length (db->runes);
5403 old_start = ddl->bufpos + ddl->offset;
5404 old_end = ddl->end_bufpos + ddl->offset;
5406 /* If this is the first line being updated and it used
5407 propagation data, fail. Otherwise we'll be okay because
5408 we'll have the necessary propagation data. */
5409 if (line == first_line && ddl->used_prop_data)
5412 new_start = generate_display_line (w, ddl, 0, ddl->bufpos + ddl->offset,
5413 &prop, DESIRED_DISP);
5416 /* #### If there is propagated stuff the fail. We could
5417 probably actually deal with this if the line had propagated
5418 information when originally created by a full
5426 /* If any line position parameters have changed or a
5427 cursor has disappeared or disappeared, fail. */
5428 db = get_display_block_from_line (ddl, TEXT);
5429 if (cdl->ypos != ddl->ypos
5430 || cdl->ascent != ddl->ascent
5431 || cdl->descent != ddl->descent
5432 || cdl->top_clip != ddl->top_clip
5433 || (cdl->cursor_elt != -1 && ddl->cursor_elt == -1)
5434 || (cdl->cursor_elt == -1 && ddl->cursor_elt != -1)
5435 || old_start != ddl->bufpos
5436 || old_end != ddl->end_bufpos
5437 || initial_size != Dynarr_length (db->runes))
5442 if (ddl->cursor_elt != -1)
5444 w->last_point_x[DESIRED_DISP] = ddl->cursor_elt;
5445 w->last_point_y[DESIRED_DISP] = line;
5450 /* If the extent changes end on the line we just updated then
5451 we're done. Otherwise go on to the next line. */
5452 if (end_unchanged <= ddl->end_bufpos)
5458 redisplay_update_line (w, first_line, last_line, 1);
5462 /* Attempt to update the display data structures based on knowledge of
5463 the changed region in the buffer. Returns a boolean indicating
5464 success or failure. If this function returns a failure then a
5465 regenerate_window _must_ be performed next in order to maintain
5466 invariants located here. */
5469 regenerate_window_incrementally (struct window *w, Bufpos startp,
5472 struct buffer *b = XBUFFER (w->buffer);
5473 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
5474 display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP);
5475 Charcount beg_unchanged, end_unchanged;
5476 Charcount extent_beg_unchanged, extent_end_unchanged;
5482 /* If this function is called, the current and desired structures
5483 had better be identical. If they are not, then that is a bug. */
5484 assert (Dynarr_length (cdla) == Dynarr_length (ddla));
5486 /* We don't handle minibuffer windows yet. The minibuffer prompt
5488 if (MINI_WINDOW_P (w))
5491 extent_beg_unchanged = BUF_EXTENT_BEGIN_UNCHANGED (b);
5492 extent_end_unchanged = (BUF_EXTENT_END_UNCHANGED (b) == -1
5494 : BUF_Z (b) - BUF_EXTENT_END_UNCHANGED (b));
5496 /* If nothing has changed in the buffer, then make sure point is ok
5498 if (BUF_BEGIN_UNCHANGED (b) == -1 && BUF_END_UNCHANGED (b) == -1)
5499 return regenerate_window_extents_only_changed (w, startp, pointm,
5500 extent_beg_unchanged,
5501 extent_end_unchanged);
5503 /* We can't deal with deleted newlines. */
5504 if (BUF_NEWLINE_WAS_DELETED (b))
5507 beg_unchanged = BUF_BEGIN_UNCHANGED (b);
5508 end_unchanged = (BUF_END_UNCHANGED (b) == -1
5510 : BUF_Z (b) - BUF_END_UNCHANGED (b));
5512 REGEN_INC_FIND_START_END;
5514 /* If the changed area starts before the visible area, give up. */
5515 if (beg_unchanged < startp)
5518 /* Find what display line the buffer changes first affect. */
5520 while (line <= dla_end)
5522 struct display_line *dl = Dynarr_atp (cdla, line);
5523 Bufpos lstart = dl->bufpos + dl->offset;
5524 Bufpos lend = dl->end_bufpos + dl->offset;
5526 if (beg_unchanged >= lstart && beg_unchanged <= lend)
5532 /* If the changes are below the visible area then if point hasn't
5533 moved return success otherwise fail in order to be safe. */
5535 return regenerate_window_extents_only_changed (w, startp, pointm,
5536 extent_beg_unchanged,
5537 extent_end_unchanged);
5539 /* At this point we know what line the changes first affect. We
5540 now redraw that line. If the changes are contained within it
5541 we are going to succeed and can update just that one line.
5542 Otherwise we fail. If we fail we will have altered the desired
5543 structs which could lead to an assertion failure. However, if
5544 we fail the next thing that is going to happen is a full regen
5545 so we will actually end up being safe. */
5548 prop_block_dynarr *prop = NULL;
5549 struct display_line *cdl = Dynarr_atp (cdla, line);
5550 struct display_line *ddl = Dynarr_atp (ddla, line);
5552 assert (cdl->bufpos == ddl->bufpos);
5553 assert (cdl->end_bufpos == ddl->end_bufpos);
5554 assert (cdl->offset == ddl->offset);
5556 /* If the last rune is already a continuation glyph, fail.
5557 #### We should be able to handle this better. */
5559 struct display_block *db = get_display_block_from_line (ddl, TEXT);
5560 if (Dynarr_length (db->runes))
5563 Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
5565 if (rb->type == RUNE_DGLYPH
5566 && EQ (rb->object.dglyph.glyph, Vcontinuation_glyph))
5571 /* If the line was generated using propagation data, fail. */
5572 if (ddl->used_prop_data)
5575 new_start = generate_display_line (w, ddl, 0, ddl->bufpos + ddl->offset,
5576 &prop, DESIRED_DISP);
5579 /* If there is propagated stuff then it is pretty much a
5580 guarantee that more than just the one line is affected. */
5587 /* If the last rune is now a continuation glyph, fail. */
5589 struct display_block *db = get_display_block_from_line (ddl, TEXT);
5590 if (Dynarr_length (db->runes))
5593 Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
5595 if (rb->type == RUNE_DGLYPH
5596 && EQ (rb->object.dglyph.glyph, Vcontinuation_glyph))
5601 /* If any line position parameters have changed or a
5602 cursor has disappeared or disappeared, fail. */
5603 if (cdl->ypos != ddl->ypos
5604 || cdl->ascent != ddl->ascent
5605 || cdl->descent != ddl->descent
5606 || cdl->top_clip != ddl->top_clip
5607 || (cdl->cursor_elt != -1 && ddl->cursor_elt == -1)
5608 || (cdl->cursor_elt == -1 && ddl->cursor_elt != -1))
5613 /* If the changed area also ends on this line, then we may be in
5614 business. Update everything and return success. */
5615 if (end_unchanged >= ddl->bufpos && end_unchanged <= ddl->end_bufpos)
5617 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b));
5618 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b));
5619 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp),
5621 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm),
5624 if (ddl->cursor_elt != -1)
5626 w->last_point_x[DESIRED_DISP] = ddl->cursor_elt;
5627 w->last_point_y[DESIRED_DISP] = line;
5630 redisplay_update_line (w, line, line, 1);
5631 regenerate_modeline (w);
5633 /* #### For now we just flush the cache until this has been
5634 tested. After that is done, this should correct the
5636 Dynarr_reset (w->line_start_cache);
5638 /* Adjust the extent changed boundaries to remove any
5639 overlap with the buffer changes since we've just
5640 successfully updated that area. */
5641 if (extent_beg_unchanged != -1
5642 && extent_beg_unchanged >= beg_unchanged
5643 && extent_beg_unchanged < end_unchanged)
5644 extent_beg_unchanged = end_unchanged;
5646 if (extent_end_unchanged != -1
5647 && extent_end_unchanged >= beg_unchanged
5648 && extent_end_unchanged < end_unchanged)
5649 extent_end_unchanged = beg_unchanged - 1;
5651 if (extent_end_unchanged <= extent_beg_unchanged)
5652 extent_beg_unchanged = extent_end_unchanged = -1;
5654 /* This could lead to odd results if it fails, but since the
5655 buffer changes update succeeded this probably will to.
5656 We already know that the extent changes start at or after
5657 the line because we checked before entering the loop. */
5658 if (extent_beg_unchanged != -1
5659 && extent_end_unchanged != -1
5660 && ((extent_beg_unchanged < ddl->bufpos)
5661 || (extent_end_unchanged > ddl->end_bufpos)))
5662 return regenerate_window_extents_only_changed (w, startp, pointm,
5663 extent_beg_unchanged,
5664 extent_end_unchanged);
5674 /* Given a window and a point, update the given display lines such
5675 that point is displayed in the middle of the window.
5676 Return the window's new start position. */
5679 regenerate_window_point_center (struct window *w, Bufpos point, int type)
5683 /* We need to make sure that the modeline is generated so that the
5684 window height can be calculated correctly. */
5685 ensure_modeline_generated (w, type);
5687 startp = start_with_line_at_pixpos (w, point, window_half_pixpos (w));
5688 regenerate_window (w, startp, point, type);
5689 Fset_marker (w->start[type], make_int (startp), w->buffer);
5694 /* Given a window and a set of display lines, return a boolean
5695 indicating whether the given point is contained within. */
5698 point_visible (struct window *w, Bufpos point, int type)
5700 struct buffer *b = XBUFFER (w->buffer);
5701 display_line_dynarr *dla = window_display_lines (w, type);
5704 if (Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
5709 if (Dynarr_length (dla) > first_line)
5712 struct display_line *dl = Dynarr_atp (dla, first_line);
5715 end = BUF_Z (b) - w->window_end_pos[type] - 1;
5717 if (point >= start && point <= end)
5719 if (!MINI_WINDOW_P (w) && scroll_on_clipped_lines)
5721 dl = Dynarr_atp (dla, Dynarr_length (dla) - 1);
5723 if (point >= (dl->bufpos + dl->offset)
5724 && point <= (dl->end_bufpos + dl->offset))
5739 /* Return pixel position the middle of the window, not including the
5740 modeline and any potential horizontal scrollbar. */
5743 window_half_pixpos (struct window *w)
5745 return WINDOW_TEXT_TOP (w) + (WINDOW_TEXT_HEIGHT (w) >> 1);
5748 /* Return the display line which is currently in the middle of the
5749 window W for display lines TYPE. */
5752 line_at_center (struct window *w, int type, Bufpos start, Bufpos point)
5754 display_line_dynarr *dla;
5757 int first_elt = (MINI_WINDOW_P (w) ? 0 : 1);
5759 if (type == CMOTION_DISP)
5760 regenerate_window (w, start, point, type);
5762 dla = window_display_lines (w, type);
5763 half = window_half_pixpos (w);
5765 for (elt = first_elt; elt < Dynarr_length (dla); elt++)
5767 struct display_line *dl = Dynarr_atp (dla, elt);
5768 int line_bot = dl->ypos + dl->descent;
5770 if (line_bot > half)
5774 /* We may not have a line at the middle if the end of the buffer is
5779 /* Return a value for point that would place it at the beginning of
5780 the line which is in the middle of the window. */
5783 point_at_center (struct window *w, int type, Bufpos start, Bufpos point)
5785 /* line_at_center will regenerate the display structures, if necessary. */
5786 int line = line_at_center (w, type, start, point);
5789 return BUF_ZV (XBUFFER (w->buffer));
5792 display_line_dynarr *dla = window_display_lines (w, type);
5793 struct display_line *dl = Dynarr_atp (dla, line);
5799 /* For a given window, ensure that the current visual representation
5803 redisplay_window (Lisp_Object window, int skip_selected)
5805 struct window *w = XWINDOW (window);
5806 struct frame *f = XFRAME (w->frame);
5807 struct device *d = XDEVICE (f->device);
5808 Lisp_Object old_buffer = w->buffer;
5809 Lisp_Object the_buffer = w->buffer;
5811 int echo_active = 0;
5816 int selected_in_its_frame;
5817 int selected_globally;
5818 int skip_output = 0;
5819 int truncation_changed;
5820 int inactive_minibuffer =
5821 (MINI_WINDOW_P (w) &&
5822 (f != device_selected_frame (d)) &&
5823 !is_surrogate_for_selected_frame (f));
5825 /* #### In the new world this function actually does a bunch of
5826 optimizations such as buffer-based scrolling, but none of that is
5829 /* If this is a combination window, do its children; that's all.
5830 The selected window is always a leaf so we don't check for
5831 skip_selected here. */
5832 if (!NILP (w->vchild))
5834 redisplay_windows (w->vchild, skip_selected);
5837 if (!NILP (w->hchild))
5839 redisplay_windows (w->hchild, skip_selected);
5843 /* Is this window the selected window on its frame? */
5844 selected_in_its_frame = (w == XWINDOW (FRAME_SELECTED_WINDOW (f)));
5846 selected_in_its_frame &&
5847 EQ(DEVICE_CONSOLE(d), Vselected_console) &&
5848 XDEVICE(CONSOLE_SELECTED_DEVICE(XCONSOLE(DEVICE_CONSOLE(d)))) == d &&
5849 XFRAME(DEVICE_SELECTED_FRAME(d)) == f;
5850 if (skip_selected && selected_in_its_frame)
5853 /* It is possible that the window is not fully initialized yet. */
5854 if (NILP (w->buffer))
5857 if (MINI_WINDOW_P (w) && echo_area_active (f))
5859 w->buffer = the_buffer = Vecho_area_buffer;
5863 b = XBUFFER (w->buffer);
5867 old_pointm = selected_globally
5869 : marker_position (w->pointm[CURRENT_DISP]);
5874 if (selected_globally)
5876 pointm = BUF_PT (b);
5880 pointm = marker_position (w->pointm[CURRENT_DISP]);
5882 if (pointm < BUF_BEGV (b))
5883 pointm = BUF_BEGV (b);
5884 else if (pointm > BUF_ZV (b))
5885 pointm = BUF_ZV (b);
5888 Fset_marker (w->pointm[DESIRED_DISP], make_int (pointm), the_buffer);
5890 /* If the buffer has changed we have to invalidate all of our face
5892 if ((!echo_active && b != window_display_buffer (w))
5893 || !Dynarr_length (w->face_cachels)
5894 || f->faces_changed)
5895 reset_face_cachels (w);
5897 mark_face_cachels_as_not_updated (w);
5899 /* Ditto the glyph cache elements, although we do *not* invalidate
5900 the cache purely because glyphs have changed - this is now
5901 handled by the dirty flag.*/
5902 if ((!echo_active && b != window_display_buffer (w))
5903 || !Dynarr_length (w->glyph_cachels))
5904 reset_glyph_cachels (w);
5906 mark_glyph_cachels_as_not_updated (w);
5908 /* If the marker's buffer is not the window's buffer, then we need
5909 to find a new starting position. */
5910 if (!MINI_WINDOW_P (w)
5911 && !EQ (Fmarker_buffer (w->start[CURRENT_DISP]), w->buffer))
5913 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP);
5915 goto regeneration_done;
5920 old_startp = marker_position (w->start[CURRENT_DISP]);
5925 startp = marker_position (w->start[CURRENT_DISP]);
5926 if (startp < BUF_BEGV (b))
5927 startp = BUF_BEGV (b);
5928 else if (startp > BUF_ZV (b))
5929 startp = BUF_ZV (b);
5931 Fset_marker (w->start[DESIRED_DISP], make_int (startp), the_buffer);
5933 truncation_changed = (find_window_mirror (w)->truncate_win !=
5934 window_truncation_on (w));
5936 /* If w->force_start is set, then some function set w->start and we
5937 should display from there and change point, if necessary, to
5938 ensure that it is visible. */
5939 if (w->force_start || inactive_minibuffer)
5942 w->last_modified[DESIRED_DISP] = Qzero;
5943 w->last_facechange[DESIRED_DISP] = Qzero;
5945 regenerate_window (w, startp, pointm, DESIRED_DISP);
5947 if (!point_visible (w, pointm, DESIRED_DISP) && !inactive_minibuffer)
5949 pointm = point_at_center (w, DESIRED_DISP, 0, 0);
5951 if (selected_globally)
5952 BUF_SET_PT (b, pointm);
5954 Fset_marker (w->pointm[DESIRED_DISP], make_int (pointm),
5957 /* #### BUFU amounts of overkill just to get the cursor
5958 location marked properly. FIX ME FIX ME FIX ME */
5959 regenerate_window (w, startp, pointm, DESIRED_DISP);
5962 goto regeneration_done;
5965 /* If nothing has changed since the last redisplay, then we just
5966 need to make sure that point is still visible. */
5967 if (XINT (w->last_modified[CURRENT_DISP]) >= BUF_MODIFF (b)
5968 && XINT (w->last_facechange[CURRENT_DISP]) >= BUF_FACECHANGE (b)
5970 /* This check is to make sure we restore the minibuffer after a
5971 temporary change to the echo area. */
5972 && !(MINI_WINDOW_P (w) && f->buffers_changed)
5973 && !f->frame_changed
5974 && !truncation_changed
5975 /* check whether start is really at the begining of a line GE */
5976 && (!w->start_at_line_beg || beginning_of_line_p (b, startp))
5979 /* Check if the cursor has actually moved. */
5980 if (EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer)
5981 && pointm == marker_position (w->last_point[CURRENT_DISP])
5982 && selected_globally
5983 && !w->windows_changed
5985 && !f->extents_changed
5986 && !f->faces_changed
5987 && !f->glyphs_changed
5988 && !f->subwindows_changed
5989 && !f->subwindows_state_changed
5990 && !f->point_changed
5991 && !f->windows_structure_changed)
5993 /* If not, we're done. */
5994 if (f->modeline_changed)
5995 regenerate_modeline (w);
5998 goto regeneration_done;
6002 /* If the new point is visible in the redisplay structures,
6003 then let the output update routines handle it, otherwise
6004 do things the hard way. */
6005 if (!w->windows_changed
6007 && !f->extents_changed
6008 && !f->faces_changed
6009 && !f->glyphs_changed
6010 && !f->subwindows_changed
6011 && !f->subwindows_state_changed
6012 && !f->windows_structure_changed)
6014 if (point_visible (w, pointm, CURRENT_DISP)
6015 && w->last_point_x[CURRENT_DISP] != -1
6016 && w->last_point_y[CURRENT_DISP] != -1)
6018 if (redisplay_move_cursor (w, pointm, FRAME_TTY_P (f)))
6020 /* Always regenerate in case it is displaying
6021 the current line or column. */
6022 regenerate_modeline (w);
6025 goto regeneration_done;
6028 else if (!selected_in_its_frame && !f->point_changed)
6030 if (f->modeline_changed)
6031 regenerate_modeline (w);
6034 goto regeneration_done;
6038 /* If we weren't able to take the shortcut method, then use
6039 the brute force method. */
6040 regenerate_window (w, startp, pointm, DESIRED_DISP);
6042 if (point_visible (w, pointm, DESIRED_DISP))
6043 goto regeneration_done;
6047 /* Check if the starting point is no longer at the beginning of a
6048 line, in which case find a new starting point. We also recenter
6049 if our start position is equal to point-max. Otherwise we'll end
6050 up with a blank window. */
6051 else if (((w->start_at_line_beg || MINI_WINDOW_P (w))
6052 && !(startp == BUF_BEGV (b)
6053 || BUF_FETCH_CHAR (b, startp - 1) == '\n'))
6054 || (pointm == startp &&
6055 EQ (Fmarker_buffer (w->last_start[CURRENT_DISP]), w->buffer) &&
6056 startp < marker_position (w->last_start[CURRENT_DISP]))
6057 || (startp == BUF_ZV (b)))
6059 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP);
6061 goto regeneration_done;
6063 /* See if we can update the data structures locally based on
6064 knowledge of what changed in the buffer. */
6065 else if (!w->windows_changed
6067 && !f->faces_changed
6068 && !f->glyphs_changed
6069 && !f->subwindows_changed
6070 && !f->subwindows_state_changed
6071 && !f->windows_structure_changed
6072 && !f->frame_changed
6073 && !truncation_changed
6075 && regenerate_window_incrementally (w, startp, pointm))
6077 if (f->modeline_changed
6078 || XINT (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b)
6079 || XINT (w->last_facechange[CURRENT_DISP]) < BUF_FACECHANGE (b))
6080 regenerate_modeline (w);
6083 goto regeneration_done;
6085 /* #### This is where a check for structure based scrolling would go. */
6086 /* If all else fails, try just regenerating and see what happens. */
6089 regenerate_window (w, startp, pointm, DESIRED_DISP);
6091 if (point_visible (w, pointm, DESIRED_DISP))
6092 goto regeneration_done;
6095 /* We still haven't gotten the window regenerated with point
6096 visible. Next we try scrolling a little and see if point comes
6097 back onto the screen. */
6098 if (scroll_step > 0)
6100 int scrolled = scroll_conservatively;
6101 for (; scrolled >= 0; scrolled -= scroll_step)
6103 startp = vmotion (w, startp,
6104 (pointm < startp) ? -scroll_step : scroll_step, 0);
6105 regenerate_window (w, startp, pointm, DESIRED_DISP);
6107 if (point_visible (w, pointm, DESIRED_DISP))
6108 goto regeneration_done;
6112 /* We still haven't managed to get the screen drawn with point on
6113 the screen, so just center it and be done with it. */
6114 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP);
6119 /* If the window's frame is changed then reset the current display
6120 lines in order to force a full repaint. */
6121 if (f->frame_changed)
6123 display_line_dynarr *cla = window_display_lines (w, CURRENT_DISP);
6128 /* Must do this before calling redisplay_output_window because it
6129 sets some markers on the window. */
6132 w->buffer = old_buffer;
6133 Fset_marker (w->pointm[DESIRED_DISP], make_int (old_pointm), old_buffer);
6134 Fset_marker (w->start[DESIRED_DISP], make_int (old_startp), old_buffer);
6137 /* These also have to be set before calling redisplay_output_window
6138 since it sets the CURRENT_DISP values based on them. */
6139 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b));
6140 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b));
6141 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp), w->buffer);
6142 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm), w->buffer);
6146 Bufpos start = marker_position (w->start[DESIRED_DISP]);
6147 Bufpos end = (w->window_end_pos[DESIRED_DISP] == -1
6149 : BUF_Z (b) - w->window_end_pos[DESIRED_DISP] - 1);
6150 /* Don't pollute the cache if not sure if we are correct */
6151 if (w->start_at_line_beg)
6152 update_line_start_cache (w, start, end, pointm, 1);
6153 redisplay_output_window (w);
6155 * If we just displayed the echo area, the line start cache is
6156 * no longer valid, because the minibuffer window is associated
6157 * with the window now.
6160 w->line_cache_last_updated = make_int (-1);
6163 /* #### This should be dependent on face changes and will need to be
6164 somewhere else once tty updates occur on a per-frame basis. */
6165 mark_face_cachels_as_clean (w);
6167 /* The glyph cachels only get dirty if someone changed something. */
6169 mark_glyph_cachels_as_clean (w);
6171 w->windows_changed = 0;
6174 /* Call buffer_reset_changes for all buffers present in any window
6175 currently visible in all frames on all devices. #### There has to
6176 be a better way to do this. */
6179 reset_buffer_changes_mapfun (struct window *w, void *ignored_closure)
6181 buffer_reset_changes (XBUFFER (w->buffer));
6186 reset_buffer_changes (void)
6188 Lisp_Object frmcons, devcons, concons;
6190 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
6192 struct frame *f = XFRAME (XCAR (frmcons));
6194 if (FRAME_REPAINT_P (f))
6195 map_windows (f, reset_buffer_changes_mapfun, 0);
6199 /* Ensure that all windows underneath the given window in the window
6200 hierarchy are correctly displayed. */
6203 redisplay_windows (Lisp_Object window, int skip_selected)
6205 for (; !NILP (window) ; window = XWINDOW (window)->next)
6207 redisplay_window (window, skip_selected);
6212 call_redisplay_end_triggers (struct window *w, void *closure)
6214 Bufpos lrpos = w->last_redisplay_pos;
6215 w->last_redisplay_pos = 0;
6216 if (!NILP (w->buffer)
6217 && !NILP (w->redisplay_end_trigger)
6222 if (MARKERP (w->redisplay_end_trigger)
6223 && XMARKER (w->redisplay_end_trigger)->buffer != 0)
6224 pos = marker_position (w->redisplay_end_trigger);
6225 else if (INTP (w->redisplay_end_trigger))
6226 pos = XINT (w->redisplay_end_trigger);
6229 w->redisplay_end_trigger = Qnil;
6236 XSETWINDOW (window, w);
6237 va_run_hook_with_args_in_buffer (XBUFFER (w->buffer),
6238 Qredisplay_end_trigger_functions,
6240 w->redisplay_end_trigger);
6241 w->redisplay_end_trigger = Qnil;
6248 /* Ensure that all windows on the given frame are correctly displayed. */
6251 redisplay_frame (struct frame *f, int preemption_check)
6253 struct device *d = XDEVICE (f->device);
6255 if (preemption_check)
6257 /* The preemption check itself takes a lot of time,
6258 so normally don't do it here. We do it if called
6259 from Lisp, though (`redisplay-frame'). */
6262 REDISPLAY_PREEMPTION_CHECK;
6267 /* Before we put a hold on frame size changes, attempt to process
6268 any which are already pending. */
6269 if (f->size_change_pending)
6270 change_frame_size (f, f->new_height, f->new_width, 0);
6272 /* If frame size might need to be changed, due to changed size
6273 of toolbars, scrollbars etc, change it now */
6274 if (f->size_slipped)
6276 adjust_frame_size (f);
6277 assert (!f->size_slipped);
6280 /* The menubar, toolbar, and icon updates must be done before
6281 hold_frame_size_changes is called and we are officially
6282 'in_display'. They may eval lisp code which may call Fsignal.
6283 If in_display is set Fsignal will abort. */
6285 #ifdef HAVE_MENUBARS
6286 /* Update the menubar. It is done first since it could change
6287 the menubar's visibility. This way we avoid having flashing
6288 caused by an Expose event generated by the visibility change
6290 update_frame_menubars (f);
6291 #endif /* HAVE_MENUBARS */
6292 /* widgets are similar to menus in that they can call lisp to
6293 determine activation etc. Therefore update them before we get
6294 into redisplay. This is primarily for connected widgets such as
6296 update_frame_subwindows (f);
6297 #ifdef HAVE_TOOLBARS
6298 /* Update the toolbars. */
6299 update_frame_toolbars (f);
6300 #endif /* HAVE_TOOLBARS */
6302 /* If we clear the frame we have to force its contents to be redrawn. */
6304 f->frame_changed = 1;
6306 /* invalidate the subwindow cache. We use subwindows_changed here to
6307 cause subwindows to get instantiated. This is because
6308 subwindows_state_changed is less strict - dealing with things
6309 like the clicked state of button. We have to do this before
6310 redisplaying the gutters as subwindows get unmapped in the
6312 if (!Dynarr_length (f->subwindow_cachels)
6313 || f->subwindows_changed
6315 || f->frame_changed)
6317 reset_subwindow_cachels (f);
6318 /* we have to do this so the gutter gets regenerated. */
6319 reset_gutter_display_lines (f);
6322 mark_subwindow_cachels_as_not_updated (f);
6323 /* We can now update the gutters, safe in the knowledge that our
6324 efforts won't get undone. */
6325 update_frame_gutters (f);
6327 hold_frame_size_changes ();
6329 /* ----------------- BEGIN CRITICAL REDISPLAY SECTION ---------------- */
6330 /* Within this section, we are defenseless and assume that the
6331 following cannot happen:
6333 1) garbage collection
6334 2) Lisp code evaluation
6335 3) frame size changes
6337 We ensure (3) by calling hold_frame_size_changes(), which
6338 will cause any pending frame size changes to get put on hold
6339 till after the end of the critical section. (1) follows
6340 automatically if (2) is met. #### Unfortunately, there are
6341 some places where Lisp code can be called within this section.
6342 We need to remove them.
6344 If Fsignal() is called during this critical section, we
6347 If garbage collection is called during this critical section,
6348 we simply return. #### We should abort instead.
6350 #### If a frame-size change does occur we should probably
6351 actually be preempting redisplay. */
6353 /* Erase the frame before outputting its contents. */
6356 DEVMETH (d, clear_frame, (f));
6359 /* Do the selected window first. */
6360 redisplay_window (FRAME_SELECTED_WINDOW (f), 0);
6362 /* Then do the rest. */
6363 redisplay_windows (f->root_window, 1);
6365 /* We now call the output_end routine for tty frames. We delay
6366 doing so in order to avoid cursor flicker. So much for 100%
6368 if (FRAME_TTY_P (f))
6369 DEVMETH (d, output_end, (d));
6371 update_frame_title (f);
6373 CLASS_RESET_CHANGED_FLAGS (f);
6374 f->window_face_cache_reset = 0;
6375 f->echo_area_garbaged = 0;
6378 if (!f->size_change_pending)
6379 f->size_changed = 0;
6381 /* ----------------- END CRITICAL REDISPLAY SECTION ---------------- */
6383 /* Allow frame size changes to occur again.
6385 #### what happens if changes to other frames happen? */
6386 unhold_one_frame_size_changes (f);
6388 map_windows (f, call_redisplay_end_triggers, 0);
6392 /* Ensure that all frames on the given device are correctly displayed. */
6395 redisplay_device (struct device *d)
6397 Lisp_Object frame, frmcons;
6399 int size_change_failed = 0;
6402 if (DEVICE_STREAM_P (d)) /* nothing to do */
6405 /* It is possible that redisplay has been called before the
6406 device is fully initialized. If so then continue with the
6408 if (NILP (DEVICE_SELECTED_FRAME (d)))
6411 REDISPLAY_PREEMPTION_CHECK;
6415 /* Always do the selected frame first. */
6416 frame = DEVICE_SELECTED_FRAME (d);
6420 if (f->icon_changed || f->windows_changed)
6421 update_frame_icon (f);
6423 if (FRAME_REPAINT_P (f))
6425 if (CLASS_REDISPLAY_FLAGS_CHANGEDP(f))
6427 preempted = redisplay_frame (f, 0);
6433 /* If the frame redisplay did not get preempted, then this flag
6434 should have gotten set to 0. It might be possible for that
6435 not to happen if a size change event were to occur at an odd
6436 time. To make sure we don't miss anything we simply don't
6437 reset the top level flags until the condition ends up being
6438 in the right state. */
6439 if (f->size_changed)
6440 size_change_failed = 1;
6443 DEVICE_FRAME_LOOP (frmcons, d)
6445 f = XFRAME (XCAR (frmcons));
6447 if (f == XFRAME (DEVICE_SELECTED_FRAME (d)))
6450 if (f->icon_changed || f->windows_changed)
6451 update_frame_icon (f);
6453 if (FRAME_REPAINT_P (f))
6455 if (CLASS_REDISPLAY_FLAGS_CHANGEDP (f))
6457 preempted = redisplay_frame (f, 0);
6463 if (f->size_change_pending)
6464 size_change_failed = 1;
6468 /* If we get here then we redisplayed all of our frames without
6469 getting preempted so mark ourselves as clean. */
6470 CLASS_RESET_CHANGED_FLAGS (d);
6472 if (!size_change_failed)
6473 d->size_changed = 0;
6479 restore_profiling_redisplay_flag (Lisp_Object val)
6481 profiling_redisplay_flag = XINT (val);
6485 /* Ensure that all windows on all frames on all devices are displaying
6486 the current contents of their respective buffers. */
6489 redisplay_without_hooks (void)
6491 Lisp_Object devcons, concons;
6492 int size_change_failed = 0;
6493 int count = specpdl_depth ();
6495 if (profiling_active)
6497 record_unwind_protect (restore_profiling_redisplay_flag,
6498 make_int (profiling_redisplay_flag));
6499 profiling_redisplay_flag = 1;
6502 if (asynch_device_change_pending)
6503 handle_asynch_device_change ();
6505 if (!GLOBAL_REDISPLAY_FLAGS_CHANGEDP &&
6506 !disable_preemption && preemption_count < max_preempts)
6509 DEVICE_LOOP_NO_BREAK (devcons, concons)
6511 struct device *d = XDEVICE (XCAR (devcons));
6514 if (CLASS_REDISPLAY_FLAGS_CHANGEDP (d))
6516 preempted = redisplay_device (d);
6521 RESET_CHANGED_SET_FLAGS;
6525 /* See comment in redisplay_device. */
6526 if (d->size_changed)
6527 size_change_failed = 1;
6530 preemption_count = 0;
6532 /* Mark redisplay as accurate */
6533 GLOBAL_RESET_CHANGED_FLAGS;
6534 RESET_CHANGED_SET_FLAGS;
6538 mark_all_faces_as_clean ();
6542 if (!size_change_failed)
6545 reset_buffer_changes ();
6548 unbind_to (count, Qnil);
6554 if (last_display_warning_tick != display_warning_tick &&
6555 !inhibit_warning_display)
6557 /* If an error occurs during this function, oh well.
6558 If we report another warning, we could get stuck in an
6559 infinite loop reporting warnings. */
6560 call0_trapping_errors (0, Qdisplay_warning_buffer);
6561 last_display_warning_tick = display_warning_tick;
6563 /* The run_hook_trapping_errors functions are smart enough not
6564 to do any evalling if the hook function is empty, so there
6565 should not be any significant time loss. All places in the
6566 C code that call redisplay() are prepared to handle GCing,
6567 so we should be OK. */
6568 #ifndef INHIBIT_REDISPLAY_HOOKS
6569 run_hook_trapping_errors ("Error in pre-redisplay-hook",
6570 Qpre_redisplay_hook);
6571 #endif /* INHIBIT_REDISPLAY_HOOKS */
6573 redisplay_without_hooks ();
6575 #ifndef INHIBIT_REDISPLAY_HOOKS
6576 run_hook_trapping_errors ("Error in post-redisplay-hook",
6577 Qpost_redisplay_hook);
6578 #endif /* INHIBIT_REDISPLAY_HOOKS */
6582 static char window_line_number_buf[32];
6584 /* Efficiently determine the window line number, and return a pointer
6585 to its printed representation. Do this regardless of whether
6586 line-number-mode is on. The first line in the buffer is counted as
6587 1. If narrowing is in effect, the lines are counted from the
6588 beginning of the visible portion of the buffer. */
6590 window_line_number (struct window *w, int type)
6592 struct device *d = XDEVICE (XFRAME (w->frame)->device);
6593 struct buffer *b = XBUFFER (w->buffer);
6594 /* Be careful in the order of these tests. The first clause will
6595 fail if DEVICE_SELECTED_FRAME == Qnil (since w->frame cannot be).
6596 This can occur when the frame title is computed really early */
6598 ((EQ(DEVICE_SELECTED_FRAME(d), w->frame) &&
6599 (w == XWINDOW (FRAME_SELECTED_WINDOW (device_selected_frame(d)))) &&
6600 EQ(DEVICE_CONSOLE(d), Vselected_console) &&
6601 XDEVICE(CONSOLE_SELECTED_DEVICE(XCONSOLE(DEVICE_CONSOLE(d)))) == d )
6603 : marker_position (w->pointm[type]));
6606 line = buffer_line_number (b, pos, 1);
6608 long_to_string (window_line_number_buf, line + 1);
6610 return window_line_number_buf;
6614 /* Given a character representing an object in a modeline
6615 specification, return a string (stored into the global array
6616 `mode_spec_bufbyte_string') with the information that object
6619 This function is largely unchanged from previous versions of the
6622 Warning! This code is also used for frame titles and can be called
6623 very early in the device/frame update process! JV
6627 decode_mode_spec (struct window *w, Emchar spec, int type)
6629 Lisp_Object obj = Qnil;
6630 CONST char *str = NULL;
6631 struct buffer *b = XBUFFER (w->buffer);
6633 Dynarr_reset (mode_spec_bufbyte_string);
6637 /* print buffer name */
6642 /* print visited file name */
6647 /* print the current column */
6650 Bufpos pt = (w == XWINDOW (Fselected_window (Qnil)))
6652 : marker_position (w->pointm[type]);
6653 int col = column_at_point (b, pt, 1) + !!column_number_start_at_one;
6656 long_to_string (buf, col);
6658 Dynarr_add_many (mode_spec_bufbyte_string,
6659 (CONST Bufbyte *) buf, strlen (buf));
6661 goto decode_mode_spec_done;
6663 /* print the file coding system */
6667 Lisp_Object codesys = b->buffer_file_coding_system;
6668 /* Be very careful here not to get an error. */
6669 if (NILP (codesys) || SYMBOLP (codesys) || CODING_SYSTEMP (codesys))
6671 codesys = Ffind_coding_system (codesys);
6672 if (CODING_SYSTEMP (codesys))
6673 obj = XCODING_SYSTEM_MNEMONIC (codesys);
6676 #endif /* FILE_CODING */
6679 /* print the current line number */
6681 str = window_line_number (w, type);
6684 /* print value of mode-name (obsolete) */
6689 /* print hyphen and frame number, if != 1 */
6693 struct frame *f = XFRAME (w->frame);
6694 if (FRAME_TTY_P (f) && f->order_count > 1 && f->order_count <= 99999999)
6696 /* Naughty, naughty */
6697 char * writable_str = alloca_array (char, 10);
6698 sprintf (writable_str, "-%d", f->order_count);
6702 #endif /* HAVE_TTY */
6705 /* print Narrow if appropriate */
6707 if (BUF_BEGV (b) > BUF_BEG (b)
6708 || BUF_ZV (b) < BUF_Z (b))
6712 /* print %, * or hyphen, if buffer is read-only, modified or neither */
6714 str = (!NILP (b->read_only)
6716 : ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
6721 /* print * or hyphen -- XEmacs change to allow a buffer to be
6722 read-only but still indicate whether it is modified. */
6724 str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
6726 : (!NILP (b->read_only)
6731 /* #### defined in 19.29 decode_mode_spec, but not in
6732 modeline-format doc string. */
6733 /* This differs from %* in that it ignores read-only-ness. */
6735 str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
6740 /* print process status */
6742 obj = Fget_buffer_process (w->buffer);
6744 str = GETTEXT ("no process");
6746 obj = Fsymbol_name (Fprocess_status (obj));
6749 /* Print name of selected frame. */
6751 obj = XFRAME (w->frame)->name;
6754 /* indicate TEXT or BINARY */
6756 /* #### NT does not use this any more. Now what? */
6760 /* print percent of buffer above top of window, or Top, Bot or All */
6763 Bufpos pos = marker_position (w->start[type]);
6765 /* This had better be while the desired lines are being done. */
6766 if (w->window_end_pos[type] <= BUF_Z (b) - BUF_ZV (b))
6768 if (pos <= BUF_BEGV (b))
6773 else if (pos <= BUF_BEGV (b))
6777 /* This hard limit is ok since the string it will hold has a
6778 fixed maximum length of 3. But just to be safe... */
6780 Charcount chars = pos - BUF_BEGV (b);
6781 Charcount total = BUF_ZV (b) - BUF_BEGV (b);
6783 /* Avoid overflow on big buffers */
6784 int percent = total > LONG_MAX/200 ?
6785 (chars + total/200) / (total / 100) :
6786 (chars * 100 + total/2) / total;
6788 /* We can't normally display a 3-digit number, so get us a
6789 2-digit number that is close. */
6793 sprintf (buf, "%d%%", percent);
6794 Dynarr_add_many (mode_spec_bufbyte_string, (Bufbyte *) buf,
6797 goto decode_mode_spec_done;
6802 /* print percent of buffer above bottom of window, perhaps plus
6803 Top, or print Bottom or All */
6806 Bufpos toppos = marker_position (w->start[type]);
6807 Bufpos botpos = BUF_Z (b) - w->window_end_pos[type];
6809 /* botpos is only accurate as of the last redisplay, so we can
6810 only treat it as a hint. In particular, after erase-buffer,
6811 botpos may be negative. */
6812 if (botpos < toppos)
6815 if (botpos >= BUF_ZV (b))
6817 if (toppos <= BUF_BEGV (b))
6824 /* This hard limit is ok since the string it will hold has a
6825 fixed maximum length of around 6. But just to be safe... */
6827 Charcount chars = botpos - BUF_BEGV (b);
6828 Charcount total = BUF_ZV (b) - BUF_BEGV (b);
6830 /* Avoid overflow on big buffers */
6831 int percent = total > LONG_MAX/200 ?
6832 (chars + total/200) / (total / 100) :
6833 (chars * 100 + total/2) / max (total, 1);
6835 /* We can't normally display a 3-digit number, so get us a
6836 2-digit number that is close. */
6840 if (toppos <= BUF_BEGV (b))
6841 sprintf (buf, "Top%d%%", percent);
6843 sprintf (buf, "%d%%", percent);
6845 Dynarr_add_many (mode_spec_bufbyte_string, (Bufbyte *) buf,
6848 goto decode_mode_spec_done;
6858 /* print one [ for each recursive editing level. */
6863 if (command_loop_level > 5)
6869 for (i = 0; i < command_loop_level; i++)
6870 Dynarr_add (mode_spec_bufbyte_string, '[');
6872 goto decode_mode_spec_done;
6875 /* print one ] for each recursive editing level. */
6880 if (command_loop_level > 5)
6886 for (i = 0; i < command_loop_level; i++)
6887 Dynarr_add (mode_spec_bufbyte_string, ']');
6889 goto decode_mode_spec_done;
6892 /* print infinitely many dashes -- handle at top level now */
6899 Dynarr_add_many (mode_spec_bufbyte_string,
6901 XSTRING_LENGTH (obj));
6903 Dynarr_add_many (mode_spec_bufbyte_string, (Bufbyte *) str, strlen (str));
6905 decode_mode_spec_done:
6906 Dynarr_add (mode_spec_bufbyte_string, '\0');
6909 /* Given a display line, free all of its data structures. */
6912 free_display_line (struct display_line *dl)
6916 if (dl->display_blocks)
6918 for (block = 0; block < Dynarr_largest (dl->display_blocks); block++)
6920 struct display_block *db = Dynarr_atp (dl->display_blocks, block);
6922 Dynarr_free (db->runes);
6925 Dynarr_free (dl->display_blocks);
6926 dl->display_blocks = NULL;
6929 if (dl->left_glyphs)
6931 Dynarr_free (dl->left_glyphs);
6932 dl->left_glyphs = NULL;
6935 if (dl->right_glyphs)
6937 Dynarr_free (dl->right_glyphs);
6938 dl->right_glyphs = NULL;
6943 /* Given an array of display lines, free them and all data structures
6944 contained within them. */
6947 free_display_lines (display_line_dynarr *dla)
6951 for (line = 0; line < Dynarr_largest (dla); line++)
6953 free_display_line (Dynarr_atp (dla, line));
6959 /* Call internal free routine for each set of display lines. */
6962 free_display_structs (struct window_mirror *mir)
6964 if (mir->current_display_lines)
6966 free_display_lines (mir->current_display_lines);
6967 mir->current_display_lines = 0;
6970 if (mir->desired_display_lines)
6972 free_display_lines (mir->desired_display_lines);
6973 mir->desired_display_lines = 0;
6979 mark_glyph_block_dynarr (glyph_block_dynarr *gba)
6983 glyph_block *gb = Dynarr_atp (gba, 0);
6984 glyph_block *gb_last = Dynarr_atp (gba, Dynarr_length (gba));
6986 for (; gb < gb_last; gb++)
6988 if (!NILP (gb->glyph))
6989 mark_object (gb->glyph);
6990 if (!NILP (gb->extent))
6991 mark_object (gb->extent);
6997 mark_redisplay_structs (display_line_dynarr *dla)
6999 display_line *dl = Dynarr_atp (dla, 0);
7000 display_line *dl_last = Dynarr_atp (dla, Dynarr_length (dla));
7002 for (; dl < dl_last; dl++)
7004 display_block_dynarr *dba = dl->display_blocks;
7005 display_block *db = Dynarr_atp (dba, 0);
7006 display_block *db_last = Dynarr_atp (dba, Dynarr_length (dba));
7008 for (; db < db_last; db++)
7010 rune_dynarr *ra = db->runes;
7011 rune *r = Dynarr_atp (ra, 0);
7012 rune *r_last = Dynarr_atp (ra, Dynarr_length (ra));
7014 for (; r < r_last; r++)
7016 if (r->type == RUNE_DGLYPH)
7018 if (!NILP (r->object.dglyph.glyph))
7019 mark_object (r->object.dglyph.glyph);
7020 if (!NILP (r->object.dglyph.extent))
7021 mark_object (r->object.dglyph.extent);
7026 mark_glyph_block_dynarr (dl->left_glyphs);
7027 mark_glyph_block_dynarr (dl->right_glyphs);
7032 mark_window_mirror (struct window_mirror *mir)
7034 mark_redisplay_structs (mir->current_display_lines);
7035 mark_redisplay_structs (mir->desired_display_lines);
7038 mark_window_mirror (mir->next);
7041 mark_window_mirror (mir->hchild);
7042 else if (mir->vchild)
7043 mark_window_mirror (mir->vchild);
7047 mark_redisplay (void)
7049 Lisp_Object frmcons, devcons, concons;
7051 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
7053 struct frame *f = XFRAME (XCAR (frmcons));
7054 update_frame_window_mirror (f);
7055 mark_window_mirror (f->root_mirror);
7059 /*****************************************************************************
7060 Line Start Cache Description and Rationale
7062 The traditional scrolling code in Emacs breaks in a variable height world.
7063 It depends on the key assumption that the number of lines that can be
7064 displayed at any given time is fixed. This led to a complete separation
7065 of the scrolling code from the redisplay code. In order to fully support
7066 variable height lines, the scrolling code must actually be tightly
7067 integrated with redisplay. Only redisplay can determine how many lines
7068 will be displayed on a screen for any given starting point.
7070 What is ideally wanted is a complete list of the starting buffer position
7071 for every possible display line of a buffer along with the height of that
7072 display line. Maintaining such a full list would be very expensive. We
7073 settle for having it include information for all areas which we happen to
7074 generate anyhow (i.e. the region currently being displayed) and for those
7075 areas we need to work with.
7077 In order to ensure that the cache accurately represents what redisplay
7078 would actually show, it is necessary to invalidate it in many situations.
7079 If the buffer changes, the starting positions may no longer be correct.
7080 If a face or an extent has changed then the line heights may have altered.
7081 These events happen frequently enough that the cache can end up being
7082 constantly disabled. With this potentially constant invalidation when is
7083 the cache ever useful?
7085 Even if the cache is invalidated before every single usage, it is
7086 necessary. Scrolling often requires knowledge about display lines which
7087 are actually above or below the visible region. The cache provides a
7088 convenient light-weight method of storing this information for multiple
7089 display regions. This knowledge is necessary for the scrolling code to
7090 always obey the First Golden Rule of Redisplay.
7092 If the cache already contains all of the information that the scrolling
7093 routines happen to need so that it doesn't have to go generate it, then we
7094 are able to obey the Third Golden Rule of Redisplay. The first thing we
7095 do to help out the cache is to always add the displayed region. This
7096 region had to be generated anyway, so the cache ends up getting the
7097 information basically for free. In those cases where a user is simply
7098 scrolling around viewing a buffer there is a high probability that this is
7099 sufficient to always provide the needed information. The second thing we
7100 can do is be smart about invalidating the cache.
7102 TODO -- Be smart about invalidating the cache. Potential places:
7104 + Insertions at end-of-line which don't cause line-wraps do not alter the
7105 starting positions of any display lines. These types of buffer
7106 modifications should not invalidate the cache. This is actually a large
7107 optimization for redisplay speed as well.
7109 + Buffer modifications frequently only affect the display of lines at and
7110 below where they occur. In these situations we should only invalidate
7111 the part of the cache starting at where the modification occurs.
7113 In case you're wondering, the Second Golden Rule of Redisplay is not
7115 ****************************************************************************/
7117 /* This will get used quite a bit so we don't want to be constantly
7118 allocating and freeing it. */
7119 static line_start_cache_dynarr *internal_cache;
7121 /* Makes internal_cache represent the TYPE display structs and only
7122 the TYPE display structs. */
7125 update_internal_cache_list (struct window *w, int type)
7128 display_line_dynarr *dla = window_display_lines (w, type);
7130 Dynarr_reset (internal_cache);
7131 for (line = 0; line < Dynarr_length (dla); line++)
7133 struct display_line *dl = Dynarr_atp (dla, line);
7139 struct line_start_cache lsc;
7141 lsc.start = dl->bufpos;
7142 lsc.end = dl->end_bufpos;
7143 lsc.height = dl->ascent + dl->descent;
7145 Dynarr_add (internal_cache, lsc);
7150 /* Reset the line cache if necessary. This should be run at the
7151 beginning of any function which access the cache. */
7154 validate_line_start_cache (struct window *w)
7156 struct buffer *b = XBUFFER (w->buffer);
7157 struct frame *f = XFRAME (w->frame);
7159 if (!w->line_cache_validation_override)
7161 /* f->extents_changed used to be in here because extent face and
7162 size changes can cause text shifting. However, the extent
7163 covering the region is constantly having its face set and
7164 priority altered by the mouse code. This means that the line
7165 start cache is constantly being invalidated. This is bad
7166 since the mouse code also triggers heavy usage of the cache.
7167 Since it is an unlikely that f->extents being changed
7168 indicates that the cache really needs to be updated and if it
7169 does redisplay will catch it pretty quickly we no longer
7170 invalidate the cache if it is set. This greatly speeds up
7171 dragging out regions with the mouse. */
7172 if (XINT (w->line_cache_last_updated) < BUF_MODIFF (b)
7176 Dynarr_reset (w->line_start_cache);
7181 /* Return the very first buffer position contained in the given
7182 window's cache, or -1 if the cache is empty. Assumes that the
7186 line_start_cache_start (struct window *w)
7188 line_start_cache_dynarr *cache = w->line_start_cache;
7190 if (!Dynarr_length (cache))
7193 return Dynarr_atp (cache, 0)->start;
7196 /* Return the very last buffer position contained in the given
7197 window's cache, or -1 if the cache is empty. Assumes that the
7201 line_start_cache_end (struct window *w)
7203 line_start_cache_dynarr *cache = w->line_start_cache;
7205 if (!Dynarr_length (cache))
7208 return Dynarr_atp (cache, Dynarr_length (cache) - 1)->end;
7211 /* Return the index of the line POINT is contained within in window
7212 W's line start cache. It will enlarge the cache or move the cache
7213 window in order to have POINT be present in the cache. MIN_PAST is
7214 a guarantee of the number of entries in the cache present on either
7215 side of POINT (unless a buffer boundary is hit). If MIN_PAST is -1
7216 then it will be treated as 0, but the cache window will not be
7217 allowed to shift. Returns -1 if POINT cannot be found in the cache
7221 point_in_line_start_cache (struct window *w, Bufpos point, int min_past)
7223 struct buffer *b = XBUFFER (w->buffer);
7224 line_start_cache_dynarr *cache = w->line_start_cache;
7225 unsigned int top, bottom, pos;
7227 validate_line_start_cache (w);
7228 w->line_cache_validation_override++;
7230 /* Let functions pass in negative values, but we still treat -1
7232 /* #### bogosity alert */
7233 if (min_past < 0 && min_past != -1)
7234 min_past = -min_past;
7236 if (!Dynarr_length (cache) || line_start_cache_start (w) > point
7237 || line_start_cache_end (w) < point)
7240 int win_char_height = window_char_height (w, 1);
7242 /* Occasionally we get here with a 0 height
7243 window. find_next_newline_no_quit will abort if we pass it a
7244 count of 0 so handle that case. */
7245 if (!win_char_height)
7246 win_char_height = 1;
7248 if (!Dynarr_length (cache))
7250 Bufpos from = find_next_newline_no_quit (b, point, -1);
7251 Bufpos to = find_next_newline_no_quit (b, from, win_char_height);
7253 update_line_start_cache (w, from, to, point, 0);
7255 if (!Dynarr_length (cache))
7257 w->line_cache_validation_override--;
7262 assert (Dynarr_length (cache));
7265 while (line_start_cache_start (w) > point
7266 && (loop < cache_adjustment || min_past == -1))
7270 from = line_start_cache_start (w);
7271 if (from <= BUF_BEGV (b))
7274 from = find_next_newline_no_quit (b, from, -win_char_height);
7275 to = line_start_cache_end (w);
7277 update_line_start_cache (w, from, to, point, 0);
7281 if (line_start_cache_start (w) > point)
7285 from = find_next_newline_no_quit (b, point, -1);
7286 if (from >= BUF_ZV (b))
7288 to = find_next_newline_no_quit (b, from, -win_char_height);
7293 to = find_next_newline_no_quit (b, from, win_char_height);
7295 update_line_start_cache (w, from, to, point, 0);
7299 while (line_start_cache_end (w) < point
7300 && (loop < cache_adjustment || min_past == -1))
7304 to = line_start_cache_end (w);
7305 if (to >= BUF_ZV (b))
7308 from = line_start_cache_end (w);
7309 to = find_next_newline_no_quit (b, from, win_char_height);
7311 update_line_start_cache (w, from, to, point, 0);
7315 if (line_start_cache_end (w) < point)
7319 from = find_next_newline_no_quit (b, point, -1);
7320 if (from >= BUF_ZV (b))
7322 to = find_next_newline_no_quit (b, from, -win_char_height);
7327 to = find_next_newline_no_quit (b, from, win_char_height);
7329 update_line_start_cache (w, from, to, point, 0);
7333 assert (Dynarr_length (cache));
7338 /* This could happen if the buffer is narrowed. */
7339 if (line_start_cache_start (w) > point
7340 || line_start_cache_end (w) < point)
7342 w->line_cache_validation_override--;
7348 top = Dynarr_length (cache) - 1;
7353 unsigned int new_pos;
7356 pos = (bottom + top + 1) >> 1;
7357 start = Dynarr_atp (cache, pos)->start;
7358 end = Dynarr_atp (cache, pos)->end;
7360 if (point >= start && point <= end)
7362 if (pos < min_past && line_start_cache_start (w) > BUF_BEGV (b))
7365 find_next_newline_no_quit (b, line_start_cache_start (w),
7367 Bufpos to = line_start_cache_end (w);
7369 update_line_start_cache (w, from, to, point, 0);
7370 goto find_point_loop;
7372 else if ((Dynarr_length (cache) - pos - 1) < min_past
7373 && line_start_cache_end (w) < BUF_ZV (b))
7375 Bufpos from = line_start_cache_end (w);
7376 Bufpos to = find_next_newline_no_quit (b, from,
7381 update_line_start_cache (w, from, to, point, 0);
7382 goto find_point_loop;
7386 w->line_cache_validation_override--;
7390 else if (point > end)
7392 else if (point < start)
7397 new_pos = (bottom + top + 1) >> 1;
7400 w->line_cache_validation_override--;
7406 /* Return a boolean indicating if POINT would be visible in window W
7407 if display of the window was to begin at STARTP. */
7410 point_would_be_visible (struct window *w, Bufpos startp, Bufpos point)
7412 struct buffer *b = XBUFFER (w->buffer);
7413 int pixpos = -WINDOW_TEXT_TOP_CLIP(w);
7414 int bottom = WINDOW_TEXT_HEIGHT (w);
7417 /* If point is before the intended start it obviously can't be visible. */
7421 /* If point or start are not in the accessible buffer range, then
7423 if (startp < BUF_BEGV (b) || startp > BUF_ZV (b)
7424 || point < BUF_BEGV (b) || point > BUF_ZV (b))
7427 validate_line_start_cache (w);
7428 w->line_cache_validation_override++;
7430 start_elt = point_in_line_start_cache (w, startp, 0);
7431 if (start_elt == -1)
7433 w->line_cache_validation_override--;
7437 assert (line_start_cache_start (w) <= startp
7438 && line_start_cache_end (w) >= startp);
7444 /* Expand the cache if necessary. */
7445 if (start_elt == Dynarr_length (w->line_start_cache))
7448 Dynarr_atp (w->line_start_cache, start_elt - 1)->start;
7450 start_elt = point_in_line_start_cache (w, old_startp,
7451 window_char_height (w, 0));
7453 /* We've already actually processed old_startp, so increment
7457 /* If this happens we didn't add any extra elements. Bummer. */
7458 if (start_elt == Dynarr_length (w->line_start_cache))
7460 w->line_cache_validation_override--;
7465 height = Dynarr_atp (w->line_start_cache, start_elt)->height;
7467 if (pixpos + height > bottom)
7469 if (bottom - pixpos < VERTICAL_CLIP (w, 0))
7471 w->line_cache_validation_override--;
7477 if (point <= Dynarr_atp (w->line_start_cache, start_elt)->end)
7479 w->line_cache_validation_override--;
7487 /* For the given window W, if display starts at STARTP, what will be
7488 the buffer position at the beginning or end of the last line
7489 displayed. The end of the last line is also know as the window end
7492 #### With a little work this could probably be reworked as just a
7493 call to start_with_line_at_pixpos. */
7496 start_end_of_last_line (struct window *w, Bufpos startp, int end)
7498 struct buffer *b = XBUFFER (w->buffer);
7499 line_start_cache_dynarr *cache = w->line_start_cache;
7501 int bottom = WINDOW_TEXT_HEIGHT (w);
7505 validate_line_start_cache (w);
7506 w->line_cache_validation_override++;
7508 if (startp < BUF_BEGV (b))
7509 startp = BUF_BEGV (b);
7510 else if (startp > BUF_ZV (b))
7511 startp = BUF_ZV (b);
7514 start_elt = point_in_line_start_cache (w, cur_start, 0);
7515 if (start_elt == -1)
7516 abort (); /* this had better never happen */
7520 int height = Dynarr_atp (cache, start_elt)->height;
7522 cur_start = Dynarr_atp (cache, start_elt)->start;
7524 if (pixpos + height > bottom)
7526 /* Adjust for any possible clip. */
7527 if (bottom - pixpos < VERTICAL_CLIP (w, 0))
7532 w->line_cache_validation_override--;
7536 return BUF_BEGV (b);
7540 w->line_cache_validation_override--;
7542 return Dynarr_atp (cache, start_elt)->end;
7544 return Dynarr_atp (cache, start_elt)->start;
7550 if (start_elt == Dynarr_length (cache))
7552 Bufpos from = line_start_cache_end (w);
7553 int win_char_height = window_char_height (w, 0);
7554 Bufpos to = find_next_newline_no_quit (b, from,
7559 /* We've hit the end of the bottom so that's what it is. */
7560 if (from >= BUF_ZV (b))
7562 w->line_cache_validation_override--;
7566 update_line_start_cache (w, from, to, BUF_PT (b), 0);
7568 /* Updating the cache invalidates any current indexes. */
7569 start_elt = point_in_line_start_cache (w, cur_start, -1) + 1;
7574 /* For the given window W, if display starts at STARTP, what will be
7575 the buffer position at the beginning of the last line displayed. */
7578 start_of_last_line (struct window *w, Bufpos startp)
7580 return start_end_of_last_line (w, startp, 0);
7583 /* For the given window W, if display starts at STARTP, what will be
7584 the buffer position at the end of the last line displayed. This is
7585 also know as the window end position. */
7588 end_of_last_line (struct window *w, Bufpos startp)
7590 return start_end_of_last_line (w, startp, 1);
7593 /* For window W, what does the starting position have to be so that
7594 the line containing POINT will cover pixel position PIXPOS. */
7597 start_with_line_at_pixpos (struct window *w, Bufpos point, int pixpos)
7599 struct buffer *b = XBUFFER (w->buffer);
7601 Bufpos cur_pos, prev_pos = point;
7602 int point_line_height;
7603 int pixheight = pixpos - WINDOW_TEXT_TOP (w);
7605 validate_line_start_cache (w);
7606 w->line_cache_validation_override++;
7608 cur_elt = point_in_line_start_cache (w, point, 0);
7609 /* #### See comment in update_line_start_cache about big minibuffers. */
7612 w->line_cache_validation_override--;
7616 point_line_height = Dynarr_atp (w->line_start_cache, cur_elt)->height;
7620 cur_pos = Dynarr_atp (w->line_start_cache, cur_elt)->start;
7622 pixheight -= Dynarr_atp (w->line_start_cache, cur_elt)->height;
7624 /* Do not take into account the value of vertical_clip here.
7625 That is the responsibility of the calling functions. */
7628 w->line_cache_validation_override--;
7629 if (-pixheight > point_line_height)
7630 /* We can't make the target line cover pixpos, so put it
7631 above pixpos. That way it will at least be visible. */
7641 int win_char_height;
7643 if (cur_pos <= BUF_BEGV (b))
7645 w->line_cache_validation_override--;
7646 return BUF_BEGV (b);
7649 win_char_height = window_char_height (w, 0);
7650 if (!win_char_height)
7651 win_char_height = 1;
7653 from = find_next_newline_no_quit (b, cur_pos, -win_char_height);
7654 to = line_start_cache_end (w);
7655 update_line_start_cache (w, from, to, point, 0);
7657 cur_elt = point_in_line_start_cache (w, cur_pos, 2) - 1;
7658 assert (cur_elt >= -1);
7659 /* This used to be cur_elt>=0 under the assumption that if
7660 point is in the top line and not at BUF_BEGV, then
7661 setting the window_start to a newline before the start of
7662 the first line will always cause scrolling.
7664 However in my (jv) opinion this is wrong. That new line
7665 can be hidden in various ways: invisible extents, an
7666 explicit window-start not at a newline character etc.
7667 The existence of those are indeed known to create crashes
7668 on that assert. So we have no option but to continue the
7669 search if we found point at the top of the line_start_cache
7671 cur_pos = Dynarr_atp (w->line_start_cache,0)->start;
7677 /* For window W, what does the starting position have to be so that
7678 the line containing point is on display line LINE. If LINE is
7679 positive it is considered to be the number of lines from the top of
7680 the window (0 is the top line). If it is negative the number is
7681 considered to be the number of lines from the bottom (-1 is the
7685 start_with_point_on_display_line (struct window *w, Bufpos point, int line)
7687 validate_line_start_cache (w);
7688 w->line_cache_validation_override++;
7692 int cur_elt = point_in_line_start_cache (w, point, line);
7694 if (cur_elt - line < 0)
7695 cur_elt = 0; /* Hit the top */
7699 w->line_cache_validation_override--;
7700 return Dynarr_atp (w->line_start_cache, cur_elt)->start;
7704 /* The calculated value of pixpos is correct for the bottom line
7705 or what we want when line is -1. Therefore we subtract one
7706 because we have already handled one line. */
7707 int new_line = -line - 1;
7708 int cur_elt = point_in_line_start_cache (w, point, new_line);
7709 int pixpos = WINDOW_TEXT_BOTTOM (w);
7710 Bufpos retval, search_point;
7712 /* If scroll_on_clipped_lines is false, the last "visible" line of
7713 the window covers the pixel at WINDOW_TEXT_BOTTOM (w) - 1.
7714 If s_o_c_l is true, then we don't want to count a clipped
7715 line, so back up from the bottom by the height of the line
7716 containing point. */
7717 if (scroll_on_clipped_lines)
7718 pixpos -= Dynarr_atp (w->line_start_cache, cur_elt)->height;
7722 if (cur_elt + new_line >= Dynarr_length (w->line_start_cache))
7724 /* Hit the bottom of the buffer. */
7726 (cur_elt + new_line) - Dynarr_length (w->line_start_cache) + 1;
7730 XSETWINDOW (window, w);
7731 default_face_height_and_width (window, &defheight, 0);
7733 cur_elt = Dynarr_length (w->line_start_cache) - 1;
7735 pixpos -= (adjustment * defheight);
7736 if (pixpos < WINDOW_TEXT_TOP (w))
7737 pixpos = WINDOW_TEXT_TOP (w);
7740 cur_elt = cur_elt + new_line;
7742 search_point = Dynarr_atp (w->line_start_cache, cur_elt)->start;
7744 retval = start_with_line_at_pixpos (w, search_point, pixpos);
7745 w->line_cache_validation_override--;
7750 /* This is used to speed up vertical scrolling by caching the known
7751 buffer starting positions for display lines. This allows the
7752 scrolling routines to avoid costly calls to regenerate_window. If
7753 NO_REGEN is true then it will only add the values in the DESIRED
7754 display structs which are in the given range.
7756 Note also that the FROM/TO values are minimums. It is possible
7757 that this function will actually add information outside of the
7758 lines containing those positions. This can't hurt but it could
7761 #### We currently force the cache to have only 1 contiguous region.
7762 It might help to make the cache a dynarr of caches so that we can
7763 cover more areas. This might, however, turn out to be a lot of
7764 overhead for too little gain. */
7767 update_line_start_cache (struct window *w, Bufpos from, Bufpos to,
7768 Bufpos point, int no_regen)
7770 struct buffer *b = XBUFFER (w->buffer);
7771 line_start_cache_dynarr *cache = w->line_start_cache;
7772 Bufpos low_bound, high_bound;
7774 validate_line_start_cache (w);
7775 w->line_cache_validation_override++;
7776 updating_line_start_cache = 1;
7778 if (from < BUF_BEGV (b))
7779 from = BUF_BEGV (b);
7780 if (to > BUF_ZV (b))
7785 updating_line_start_cache = 0;
7786 w->line_cache_validation_override--;
7790 if (Dynarr_length (cache))
7792 low_bound = line_start_cache_start (w);
7793 high_bound = line_start_cache_end (w);
7795 /* Check to see if the desired range is already in the cache. */
7796 if (from >= low_bound && to <= high_bound)
7798 updating_line_start_cache = 0;
7799 w->line_cache_validation_override--;
7803 /* Check to make sure that the desired range is adjacent to the
7804 current cache. If not, invalidate the cache. */
7805 if (to < low_bound || from > high_bound)
7807 Dynarr_reset (cache);
7808 low_bound = high_bound = -1;
7813 low_bound = high_bound = -1;
7816 w->line_cache_last_updated = make_int (BUF_MODIFF (b));
7818 /* This could be integrated into the next two sections, but it is easier
7819 to follow what's going on by having it separate. */
7824 update_internal_cache_list (w, DESIRED_DISP);
7825 if (!Dynarr_length (internal_cache))
7827 updating_line_start_cache = 0;
7828 w->line_cache_validation_override--;
7832 start = Dynarr_atp (internal_cache, 0)->start;
7834 Dynarr_atp (internal_cache, Dynarr_length (internal_cache) - 1)->end;
7836 /* We aren't allowed to generate additional information to fill in
7837 gaps, so if the DESIRED structs don't overlap the cache, reset the
7839 if (Dynarr_length (cache))
7841 if (end < low_bound || start > high_bound)
7842 Dynarr_reset (cache);
7844 /* #### What should really happen if what we are doing is
7845 extending a line (the last line)? */
7846 if (Dynarr_length (cache) == 1
7847 && Dynarr_length (internal_cache) == 1)
7848 Dynarr_reset (cache);
7851 if (!Dynarr_length (cache))
7853 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
7854 Dynarr_length (internal_cache));
7855 updating_line_start_cache = 0;
7856 w->line_cache_validation_override--;
7860 /* An extra check just in case the calling function didn't pass in
7861 the bounds of the DESIRED structs in the first place. */
7862 if (start >= low_bound && end <= high_bound)
7864 updating_line_start_cache = 0;
7865 w->line_cache_validation_override--;
7869 /* At this point we know that the internal cache partially overlaps
7871 if (start < low_bound)
7873 int ic_elt = Dynarr_length (internal_cache) - 1;
7876 if (Dynarr_atp (internal_cache, ic_elt)->start < low_bound)
7884 Dynarr_reset (cache);
7885 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
7886 Dynarr_length (internal_cache));
7887 updating_line_start_cache = 0;
7888 w->line_cache_validation_override--;
7892 Dynarr_insert_many_at_start (cache, Dynarr_atp (internal_cache, 0),
7896 if (end > high_bound)
7900 while (ic_elt < Dynarr_length (internal_cache))
7902 if (Dynarr_atp (internal_cache, ic_elt)->start > high_bound)
7908 if (!(ic_elt < Dynarr_length (internal_cache)))
7910 Dynarr_reset (cache);
7911 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
7912 Dynarr_length (internal_cache));
7913 updating_line_start_cache = 0;
7914 w->line_cache_validation_override--;
7918 Dynarr_add_many (cache, Dynarr_atp (internal_cache, ic_elt),
7919 Dynarr_length (internal_cache) - ic_elt);
7922 updating_line_start_cache = 0;
7923 w->line_cache_validation_override--;
7927 if (!Dynarr_length (cache) || from < low_bound)
7929 Bufpos startp = find_next_newline_no_quit (b, from, -1);
7931 int old_lb = low_bound;
7933 while (startp < old_lb || low_bound == -1)
7938 regenerate_window (w, startp, point, CMOTION_DISP);
7939 update_internal_cache_list (w, CMOTION_DISP);
7941 /* If this assert is triggered then regenerate_window failed
7942 to layout a single line. That is not supposed to be
7943 possible because we impose a minimum height on the buffer
7944 and override vertical clip when we are in here. */
7945 /* #### Ah, but it is because the window may temporarily
7946 exist but not have any lines at all if the minibuffer is
7947 real big. Look into that situation better. */
7948 if (!Dynarr_length (internal_cache))
7950 if (old_lb == -1 && low_bound == -1)
7952 updating_line_start_cache = 0;
7953 w->line_cache_validation_override--;
7957 assert (Dynarr_length (internal_cache));
7959 assert (startp == Dynarr_atp (internal_cache, 0)->start);
7961 ic_elt = Dynarr_length (internal_cache) - 1;
7962 if (low_bound != -1)
7966 if (Dynarr_atp (internal_cache, ic_elt)->start < old_lb)
7972 assert (ic_elt >= 0);
7974 new_startp = Dynarr_atp (internal_cache, ic_elt)->end + 1;
7977 * Handle invisible text properly:
7978 * If the last line we're inserting has the same end as the
7979 * line before which it will be added, merge the two lines.
7981 if (Dynarr_length (cache) &&
7982 Dynarr_atp (internal_cache, ic_elt)->end ==
7983 Dynarr_atp (cache, marker)->end)
7985 Dynarr_atp (cache, marker)->start
7986 = Dynarr_atp (internal_cache, ic_elt)->start;
7987 Dynarr_atp (cache, marker)->height
7988 = Dynarr_atp (internal_cache, ic_elt)->height;
7992 if (ic_elt >= 0) /* we still have lines to add.. */
7994 Dynarr_insert_many (cache, Dynarr_atp (internal_cache, 0),
7995 ic_elt + 1, marker);
7996 marker += (ic_elt + 1);
7999 if (startp < low_bound || low_bound == -1)
8001 startp = new_startp;
8002 if (startp > BUF_ZV (b))
8004 updating_line_start_cache = 0;
8005 w->line_cache_validation_override--;
8011 assert (Dynarr_length (cache));
8012 assert (from >= low_bound);
8014 /* Readjust the high_bound to account for any changes made while
8015 correcting the low_bound. */
8016 high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end;
8018 if (to > high_bound)
8020 Bufpos startp = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end + 1;
8024 regenerate_window (w, startp, point, CMOTION_DISP);
8025 update_internal_cache_list (w, CMOTION_DISP);
8027 /* See comment above about regenerate_window failing. */
8028 assert (Dynarr_length (internal_cache));
8030 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
8031 Dynarr_length (internal_cache));
8032 high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end;
8033 startp = high_bound + 1;
8035 while (to > high_bound);
8038 updating_line_start_cache = 0;
8039 w->line_cache_validation_override--;
8040 assert (to <= high_bound);
8044 /* Given x and y coordinates in characters, relative to a window,
8045 return the pixel location corresponding to those coordinates. The
8046 pixel location returned is the center of the given character
8047 position. The pixel values are generated relative to the window,
8050 The modeline is considered to be part of the window. */
8053 glyph_to_pixel_translation (struct window *w, int char_x, int char_y,
8054 int *pix_x, int *pix_y)
8056 display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP);
8057 int num_disp_lines, modeline;
8059 int defheight, defwidth;
8061 XSETWINDOW (window, w);
8062 default_face_height_and_width (window, &defheight, &defwidth);
8064 /* If we get a bogus value indicating somewhere above or to the left of
8065 the window, use the first window line or character position
8072 num_disp_lines = Dynarr_length (dla);
8076 if (Dynarr_atp (dla, 0)->modeline)
8083 /* First check if the y position intersects the display lines. */
8084 if (char_y < num_disp_lines)
8086 struct display_line *dl = Dynarr_atp (dla, char_y + modeline);
8087 struct display_block *db = get_display_block_from_line (dl, TEXT);
8089 *pix_y = (dl->ypos - dl->ascent +
8090 ((unsigned int) (dl->ascent + dl->descent - dl->clip) >> 1));
8092 if (char_x < Dynarr_length (db->runes))
8094 struct rune *rb = Dynarr_atp (db->runes, char_x);
8096 *pix_x = rb->xpos + (rb->width >> 1);
8100 int last_rune = Dynarr_length (db->runes) - 1;
8101 struct rune *rb = Dynarr_atp (db->runes, last_rune);
8103 char_x -= last_rune;
8105 *pix_x = rb->xpos + rb->width;
8106 *pix_x += ((char_x - 1) * defwidth);
8107 *pix_x += (defwidth >> 1);
8112 /* It didn't intersect, so extrapolate. #### For now, we include the
8113 modeline in this since we don't have true character positions in
8116 if (!Dynarr_length (w->face_cachels))
8117 reset_face_cachels (w);
8119 char_y -= num_disp_lines;
8121 if (Dynarr_length (dla))
8123 struct display_line *dl = Dynarr_atp (dla, Dynarr_length (dla) - 1);
8124 *pix_y = dl->ypos + dl->descent - dl->clip;
8127 *pix_y = WINDOW_TEXT_TOP (w);
8129 *pix_y += (char_y * defheight);
8130 *pix_y += (defheight >> 1);
8132 *pix_x = WINDOW_TEXT_LEFT (w);
8133 /* Don't adjust by one because this is still the unadjusted value. */
8134 *pix_x += (char_x * defwidth);
8135 *pix_x += (defwidth >> 1);
8138 if (*pix_x > w->pixel_left + w->pixel_width)
8139 *pix_x = w->pixel_left + w->pixel_width;
8140 if (*pix_y > w->pixel_top + w->pixel_height)
8141 *pix_y = w->pixel_top + w->pixel_height;
8143 *pix_x -= w->pixel_left;
8144 *pix_y -= w->pixel_top;
8147 /* Given a display line and a position, determine if there is a glyph
8148 there and return information about it if there is. */
8151 get_position_object (struct display_line *dl, Lisp_Object *obj1,
8152 Lisp_Object *obj2, int x_coord, int *low_x_coord,
8155 struct display_block *db;
8158 get_next_display_block (dl->bounds, dl->display_blocks, x_coord, 0);
8160 /* We use get_next_display_block to get the actual display block
8161 that would be displayed at x_coord. */
8163 if (block == NO_BLOCK)
8166 db = Dynarr_atp (dl->display_blocks, block);
8168 for (elt = 0; elt < Dynarr_length (db->runes); elt++)
8170 struct rune *rb = Dynarr_atp (db->runes, elt);
8172 if (rb->xpos <= x_coord && x_coord < (rb->xpos + rb->width))
8174 if (rb->type == RUNE_DGLYPH)
8176 *obj1 = rb->object.dglyph.glyph;
8177 *obj2 = rb->object.dglyph.extent;
8186 *low_x_coord = rb->xpos;
8188 *high_x_coord = rb->xpos + rb->width;
8195 #define UPDATE_CACHE_RETURN \
8197 d->pixel_to_glyph_cache.valid = 1; \
8198 d->pixel_to_glyph_cache.low_x_coord = low_x_coord; \
8199 d->pixel_to_glyph_cache.high_x_coord = high_x_coord; \
8200 d->pixel_to_glyph_cache.low_y_coord = low_y_coord; \
8201 d->pixel_to_glyph_cache.high_y_coord = high_y_coord; \
8202 d->pixel_to_glyph_cache.frame = f; \
8203 d->pixel_to_glyph_cache.col = *col; \
8204 d->pixel_to_glyph_cache.row = *row; \
8205 d->pixel_to_glyph_cache.obj_x = *obj_x; \
8206 d->pixel_to_glyph_cache.obj_y = *obj_y; \
8207 d->pixel_to_glyph_cache.w = *w; \
8208 d->pixel_to_glyph_cache.bufpos = *bufpos; \
8209 d->pixel_to_glyph_cache.closest = *closest; \
8210 d->pixel_to_glyph_cache.modeline_closest = *modeline_closest; \
8211 d->pixel_to_glyph_cache.obj1 = *obj1; \
8212 d->pixel_to_glyph_cache.obj2 = *obj2; \
8213 d->pixel_to_glyph_cache.retval = position; \
8214 RETURN_SANS_WARNINGS position; \
8217 /* Given x and y coordinates in pixels relative to a frame, return
8218 information about what is located under those coordinates.
8220 The return value will be one of:
8222 OVER_TOOLBAR: over one of the 4 frame toolbars
8223 OVER_MODELINE: over a modeline
8224 OVER_BORDER: over an internal border
8225 OVER_NOTHING: over the text area, but not over text
8226 OVER_OUTSIDE: outside of the frame border
8227 OVER_TEXT: over text in the text area
8233 -- nil if the coordinates are not over a glyph or a toolbar button.
8237 -- an extent, if the coordinates are over a glyph in the text area
8240 If the coordinates are over a glyph, OBJ_X and OBJ_Y give the
8241 equivalent coordinates relative to the upper-left corner of the glyph.
8243 If the coordinates are over a character, OBJ_X and OBJ_Y give the
8244 equivalent coordinates relative to the upper-left corner of the character.
8246 Otherwise, OBJ_X and OBJ_Y are undefined.
8250 pixel_to_glyph_translation (struct frame *f, int x_coord, int y_coord,
8251 int *col, int *row, int *obj_x, int *obj_y,
8252 struct window **w, Bufpos *bufpos,
8253 Bufpos *closest, Charcount *modeline_closest,
8254 Lisp_Object *obj1, Lisp_Object *obj2)
8257 struct pixel_to_glyph_translation_cache *cache;
8259 int frm_left, frm_right, frm_top, frm_bottom;
8260 int low_x_coord, high_x_coord, low_y_coord, high_y_coord;
8261 int position = OVER_NOTHING;
8262 int device_check_failed = 0;
8263 display_line_dynarr *dla;
8265 /* This is a safety valve in case this got called with a frame in
8266 the middle of being deleted. */
8267 if (!DEVICEP (f->device) || !DEVICE_LIVE_P (XDEVICE (f->device)))
8269 device_check_failed = 1;
8270 d = NULL, cache = NULL; /* Warning suppression */
8274 d = XDEVICE (f->device);
8275 cache = &d->pixel_to_glyph_cache;
8278 if (!device_check_failed
8280 && cache->frame == f
8281 && cache->low_x_coord <= x_coord
8282 && cache->high_x_coord > x_coord
8283 && cache->low_y_coord <= y_coord
8284 && cache->high_y_coord > y_coord)
8288 *obj_x = cache->obj_x;
8289 *obj_y = cache->obj_y;
8291 *bufpos = cache->bufpos;
8292 *closest = cache->closest;
8293 *modeline_closest = cache->modeline_closest;
8294 *obj1 = cache->obj1;
8295 *obj2 = cache->obj2;
8297 return cache->retval;
8308 *modeline_closest = -1;
8312 low_x_coord = x_coord;
8313 high_x_coord = x_coord + 1;
8314 low_y_coord = y_coord;
8315 high_y_coord = y_coord + 1;
8318 if (device_check_failed)
8319 return OVER_NOTHING;
8321 frm_left = FRAME_LEFT_BORDER_END (f);
8322 frm_right = FRAME_RIGHT_BORDER_START (f);
8323 frm_top = FRAME_TOP_BORDER_END (f);
8324 frm_bottom = FRAME_BOTTOM_BORDER_START (f);
8326 /* Check if the mouse is outside of the text area actually used by
8328 if (y_coord < frm_top)
8330 if (y_coord >= FRAME_TOP_BORDER_START (f))
8332 low_y_coord = FRAME_TOP_BORDER_START (f);
8333 high_y_coord = frm_top;
8334 position = OVER_BORDER;
8336 else if (y_coord >= 0)
8339 high_y_coord = FRAME_TOP_BORDER_START (f);
8340 position = OVER_TOOLBAR;
8344 low_y_coord = y_coord;
8346 position = OVER_OUTSIDE;
8349 else if (y_coord >= frm_bottom)
8351 if (y_coord < FRAME_BOTTOM_BORDER_END (f))
8353 low_y_coord = frm_bottom;
8354 high_y_coord = FRAME_BOTTOM_BORDER_END (f);
8355 position = OVER_BORDER;
8357 else if (y_coord < FRAME_PIXHEIGHT (f))
8359 low_y_coord = FRAME_BOTTOM_BORDER_END (f);
8360 high_y_coord = FRAME_PIXHEIGHT (f);
8361 position = OVER_TOOLBAR;
8365 low_y_coord = FRAME_PIXHEIGHT (f);
8366 high_y_coord = y_coord;
8367 position = OVER_OUTSIDE;
8371 if (position != OVER_TOOLBAR && position != OVER_BORDER)
8373 if (x_coord < frm_left)
8375 if (x_coord >= FRAME_LEFT_BORDER_START (f))
8377 low_x_coord = FRAME_LEFT_BORDER_START (f);
8378 high_x_coord = frm_left;
8379 position = OVER_BORDER;
8381 else if (x_coord >= 0)
8384 high_x_coord = FRAME_LEFT_BORDER_START (f);
8385 position = OVER_TOOLBAR;
8389 low_x_coord = x_coord;
8391 position = OVER_OUTSIDE;
8394 else if (x_coord >= frm_right)
8396 if (x_coord < FRAME_RIGHT_BORDER_END (f))
8398 low_x_coord = frm_right;
8399 high_x_coord = FRAME_RIGHT_BORDER_END (f);
8400 position = OVER_BORDER;
8402 else if (x_coord < FRAME_PIXWIDTH (f))
8404 low_x_coord = FRAME_RIGHT_BORDER_END (f);
8405 high_x_coord = FRAME_PIXWIDTH (f);
8406 position = OVER_TOOLBAR;
8410 low_x_coord = FRAME_PIXWIDTH (f);
8411 high_x_coord = x_coord;
8412 position = OVER_OUTSIDE;
8417 #ifdef HAVE_TOOLBARS
8418 if (position == OVER_TOOLBAR)
8420 *obj1 = toolbar_button_at_pixpos (f, x_coord, y_coord);
8423 UPDATE_CACHE_RETURN;
8425 #endif /* HAVE_TOOLBARS */
8427 /* We still have to return the window the pointer is next to and its
8428 relative y position even if it is outside the x boundary. */
8429 if (x_coord < frm_left)
8431 else if (x_coord > frm_right)
8432 x_coord = frm_right;
8434 /* Same in reverse. */
8435 if (y_coord < frm_top)
8437 else if (y_coord > frm_bottom)
8438 y_coord = frm_bottom;
8440 /* Find what window the given coordinates are actually in. */
8441 window = f->root_window;
8442 *w = find_window_by_pixel_pos (x_coord, y_coord, window);
8444 /* If we didn't find a window, we're done. */
8447 UPDATE_CACHE_RETURN;
8449 else if (position != OVER_NOTHING)
8452 *modeline_closest = -1;
8454 if (high_y_coord <= frm_top || high_y_coord >= frm_bottom)
8457 UPDATE_CACHE_RETURN;
8461 /* Check if the window is a minibuffer but isn't active. */
8462 if (MINI_WINDOW_P (*w) && !minibuf_level)
8464 /* Must reset the window value since some callers will ignore
8465 the return value if it is set. */
8467 UPDATE_CACHE_RETURN;
8470 /* See if the point is over window vertical divider */
8471 if (window_needs_vertical_divider (*w))
8473 int div_x_high = WINDOW_RIGHT (*w);
8474 int div_x_low = div_x_high - window_divider_width (*w);
8475 int div_y_high = WINDOW_BOTTOM (*w);
8476 int div_y_low = WINDOW_TOP (*w);
8478 if (div_x_low < x_coord && x_coord <= div_x_high &&
8479 div_y_low < y_coord && y_coord <= div_y_high)
8481 low_x_coord = div_x_low;
8482 high_x_coord = div_x_high;
8483 low_y_coord = div_y_low;
8484 high_y_coord = div_y_high;
8485 position = OVER_V_DIVIDER;
8486 UPDATE_CACHE_RETURN;
8490 dla = window_display_lines (*w, CURRENT_DISP);
8492 for (*row = 0; *row < Dynarr_length (dla); (*row)++)
8494 int really_over_nothing = 0;
8495 struct display_line *dl = Dynarr_atp (dla, *row);
8497 if ((int) (dl->ypos - dl->ascent) <= y_coord
8498 && y_coord <= (int) (dl->ypos + dl->descent))
8500 int check_margin_glyphs = 0;
8501 struct display_block *db = get_display_block_from_line (dl, TEXT);
8502 struct rune *rb = 0;
8504 if (x_coord < dl->bounds.left_white
8505 || x_coord >= dl->bounds.right_white)
8506 check_margin_glyphs = 1;
8508 low_y_coord = dl->ypos - dl->ascent;
8509 high_y_coord = dl->ypos + dl->descent + 1;
8511 if (position == OVER_BORDER
8512 || position == OVER_OUTSIDE
8513 || check_margin_glyphs)
8515 int x_check, left_bound;
8517 if (check_margin_glyphs)
8520 left_bound = dl->bounds.left_white;
8524 x_check = high_x_coord;
8525 left_bound = frm_left;
8528 if (Dynarr_length (db->runes))
8530 if (x_check <= left_bound)
8533 *modeline_closest = Dynarr_atp (db->runes, 0)->bufpos;
8535 *closest = Dynarr_atp (db->runes, 0)->bufpos;
8541 Dynarr_atp (db->runes,
8542 Dynarr_length (db->runes) - 1)->bufpos;
8545 Dynarr_atp (db->runes,
8546 Dynarr_length (db->runes) - 1)->bufpos;
8550 *modeline_closest += dl->offset;
8552 *closest += dl->offset;
8556 /* #### What should be here. */
8558 *modeline_closest = 0;
8563 if (check_margin_glyphs)
8565 if (x_coord < dl->bounds.left_in
8566 || x_coord >= dl->bounds.right_in)
8568 /* If we are over the outside margins then we
8569 know the loop over the text block isn't going
8570 to accomplish anything. So we go ahead and
8571 set what information we can right here and
8574 *obj_y = y_coord - (dl->ypos - dl->ascent);
8575 get_position_object (dl, obj1, obj2, x_coord,
8576 &low_x_coord, &high_x_coord);
8578 UPDATE_CACHE_RETURN;
8582 UPDATE_CACHE_RETURN;
8585 for (*col = 0; *col <= Dynarr_length (db->runes); (*col)++)
8587 int past_end = (*col == Dynarr_length (db->runes));
8590 rb = Dynarr_atp (db->runes, *col);
8593 (rb->xpos <= x_coord && x_coord < rb->xpos + rb->width))
8598 rb = Dynarr_atp (db->runes, *col);
8601 *bufpos = rb->bufpos + dl->offset;
8602 low_x_coord = rb->xpos;
8603 high_x_coord = rb->xpos + rb->width;
8605 if (rb->type == RUNE_DGLYPH)
8609 /* Find the first character after the glyph. */
8610 while (elt < Dynarr_length (db->runes))
8612 if (Dynarr_atp (db->runes, elt)->type != RUNE_DGLYPH)
8616 (Dynarr_atp (db->runes, elt)->bufpos +
8620 (Dynarr_atp (db->runes, elt)->bufpos +
8628 /* In this case we failed to find a non-glyph
8629 character so we return the last position
8630 displayed on the line. */
8631 if (elt == Dynarr_length (db->runes))
8634 *modeline_closest = dl->end_bufpos + dl->offset;
8636 *closest = dl->end_bufpos + dl->offset;
8637 really_over_nothing = 1;
8643 *modeline_closest = rb->bufpos + dl->offset;
8645 *closest = rb->bufpos + dl->offset;
8650 *row = window_displayed_height (*w);
8652 if (position == OVER_NOTHING)
8653 position = OVER_MODELINE;
8655 if (rb->type == RUNE_DGLYPH)
8657 *obj1 = rb->object.dglyph.glyph;
8658 *obj2 = rb->object.dglyph.extent;
8660 else if (rb->type == RUNE_CHAR)
8671 UPDATE_CACHE_RETURN;
8674 || (rb->type == RUNE_CHAR
8675 && rb->object.chr.ch == '\n'))
8678 /* At this point we may have glyphs in the right
8680 if (check_margin_glyphs)
8681 get_position_object (dl, obj1, obj2, x_coord,
8682 &low_x_coord, &high_x_coord);
8683 UPDATE_CACHE_RETURN;
8688 if (rb->type == RUNE_DGLYPH)
8690 *obj1 = rb->object.dglyph.glyph;
8691 *obj2 = rb->object.dglyph.extent;
8693 else if (rb->type == RUNE_CHAR)
8704 *obj_x = x_coord - rb->xpos;
8705 *obj_y = y_coord - (dl->ypos - dl->ascent);
8707 /* At this point we may have glyphs in the left
8709 if (check_margin_glyphs)
8710 get_position_object (dl, obj1, obj2, x_coord, 0, 0);
8712 if (position == OVER_NOTHING && !really_over_nothing)
8713 position = OVER_TEXT;
8715 UPDATE_CACHE_RETURN;
8722 *row = Dynarr_length (dla) - 1;
8723 if (FRAME_WIN_P (f))
8725 int bot_elt = Dynarr_length (dla) - 1;
8729 struct display_line *dl = Dynarr_atp (dla, bot_elt);
8730 int adj_area = y_coord - (dl->ypos + dl->descent);
8734 XSETWINDOW (lwin, *w);
8735 default_face_height_and_width (lwin, 0, &defheight);
8737 *row += (adj_area / defheight);
8741 /* #### This should be checked out some more to determine what
8742 should really be going on. */
8743 if (!MARKERP ((*w)->start[CURRENT_DISP]))
8746 *closest = end_of_last_line (*w,
8747 marker_position ((*w)->start[CURRENT_DISP]));
8749 UPDATE_CACHE_RETURN;
8751 #undef UPDATE_CACHE_RETURN
8754 /***************************************************************************/
8756 /* Lisp functions */
8758 /***************************************************************************/
8760 DEFUN ("redisplay-echo-area", Fredisplay_echo_area, 0, 0, 0, /*
8761 Ensure that all minibuffers are correctly showing the echo area.
8765 Lisp_Object devcons, concons;
8767 DEVICE_LOOP_NO_BREAK (devcons, concons)
8769 struct device *d = XDEVICE (XCAR (devcons));
8770 Lisp_Object frmcons;
8772 DEVICE_FRAME_LOOP (frmcons, d)
8774 struct frame *f = XFRAME (XCAR (frmcons));
8776 if (FRAME_REPAINT_P (f) && FRAME_HAS_MINIBUF_P (f))
8778 Lisp_Object window = FRAME_MINIBUF_WINDOW (f);
8780 * If the frame size has changed, there may be random
8781 * chud on the screen left from previous messages
8782 * because redisplay_frame hasn't been called yet.
8783 * Clear the screen to get rid of the potential mess.
8785 if (f->echo_area_garbaged)
8787 DEVMETH (d, clear_frame, (f));
8788 f->echo_area_garbaged = 0;
8790 redisplay_window (window, 0);
8791 call_redisplay_end_triggers (XWINDOW (window), 0);
8795 /* We now call the output_end routine for tty frames. We delay
8796 doing so in order to avoid cursor flicker. So much for 100%
8798 if (DEVICE_TTY_P (d))
8799 DEVMETH (d, output_end, (d));
8806 restore_disable_preemption_value (Lisp_Object value)
8808 disable_preemption = XINT (value);
8812 DEFUN ("redraw-frame", Fredraw_frame, 0, 2, 0, /*
8813 Clear frame FRAME and output again what is supposed to appear on it.
8814 FRAME defaults to the selected frame if omitted.
8815 Normally, redisplay is preempted as normal if input arrives. However,
8816 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
8817 input and is guaranteed to proceed to completion.
8819 (frame, no_preempt))
8821 struct frame *f = decode_frame (frame);
8822 int count = specpdl_depth ();
8824 if (!NILP (no_preempt))
8826 record_unwind_protect (restore_disable_preemption_value,
8827 make_int (disable_preemption));
8828 disable_preemption++;
8832 redisplay_frame (f, 1);
8834 return unbind_to (count, Qnil);
8837 DEFUN ("redisplay-frame", Fredisplay_frame, 0, 2, 0, /*
8838 Ensure that FRAME's contents are correctly displayed.
8839 This differs from `redraw-frame' in that it only redraws what needs to
8840 be updated, as opposed to unconditionally clearing and redrawing
8842 FRAME defaults to the selected frame if omitted.
8843 Normally, redisplay is preempted as normal if input arrives. However,
8844 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
8845 input and is guaranteed to proceed to completion.
8847 (frame, no_preempt))
8849 struct frame *f = decode_frame (frame);
8850 int count = specpdl_depth ();
8852 if (!NILP (no_preempt))
8854 record_unwind_protect (restore_disable_preemption_value,
8855 make_int (disable_preemption));
8856 disable_preemption++;
8859 redisplay_frame (f, 1);
8861 return unbind_to (count, Qnil);
8864 DEFUN ("redraw-device", Fredraw_device, 0, 2, 0, /*
8865 Clear device DEVICE and output again what is supposed to appear on it.
8866 DEVICE defaults to the selected device if omitted.
8867 Normally, redisplay is preempted as normal if input arrives. However,
8868 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
8869 input and is guaranteed to proceed to completion.
8871 (device, no_preempt))
8873 struct device *d = decode_device (device);
8874 Lisp_Object frmcons;
8875 int count = specpdl_depth ();
8877 if (!NILP (no_preempt))
8879 record_unwind_protect (restore_disable_preemption_value,
8880 make_int (disable_preemption));
8881 disable_preemption++;
8884 DEVICE_FRAME_LOOP (frmcons, d)
8886 XFRAME (XCAR (frmcons))->clear = 1;
8888 redisplay_device (d);
8890 return unbind_to (count, Qnil);
8893 DEFUN ("redisplay-device", Fredisplay_device, 0, 2, 0, /*
8894 Ensure that DEVICE's contents are correctly displayed.
8895 This differs from `redraw-device' in that it only redraws what needs to
8896 be updated, as opposed to unconditionally clearing and redrawing
8898 DEVICE defaults to the selected device if omitted.
8899 Normally, redisplay is preempted as normal if input arrives. However,
8900 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
8901 input and is guaranteed to proceed to completion.
8903 (device, no_preempt))
8905 struct device *d = decode_device (device);
8906 int count = specpdl_depth ();
8908 if (!NILP (no_preempt))
8910 record_unwind_protect (restore_disable_preemption_value,
8911 make_int (disable_preemption));
8912 disable_preemption++;
8915 redisplay_device (d);
8917 return unbind_to (count, Qnil);
8920 /* Big lie. Big lie. This will force all modelines to be updated
8921 regardless if the all flag is set or not. It remains in existence
8922 solely for backwards compatibility. */
8923 DEFUN ("redraw-modeline", Fredraw_modeline, 0, 1, 0, /*
8924 Force the modeline of the current buffer to be redisplayed.
8925 With optional non-nil ALL, force redisplay of all modelines.
8929 MARK_MODELINE_CHANGED;
8933 DEFUN ("force-cursor-redisplay", Fforce_cursor_redisplay, 0, 1, 0, /*
8934 Force an immediate update of the cursor on FRAME.
8935 FRAME defaults to the selected frame if omitted.
8939 redisplay_redraw_cursor (decode_frame (frame), 1);
8944 /***************************************************************************/
8946 /* Lisp-variable change triggers */
8948 /***************************************************************************/
8951 margin_width_changed_in_frame (Lisp_Object specifier, struct frame *f,
8954 /* Nothing to be done? */
8958 redisplay_variable_changed (Lisp_Object sym, Lisp_Object *val,
8959 Lisp_Object in_object, int flags)
8961 /* #### clip_changed should really be renamed something like
8962 global_redisplay_change. */
8967 /* This is called if the built-in glyphs have their properties
8970 redisplay_glyph_changed (Lisp_Object glyph, Lisp_Object property,
8973 if (WINDOWP (locale))
8975 MARK_FRAME_GLYPHS_CHANGED (XFRAME (WINDOW_FRAME (XWINDOW (locale))));
8977 else if (FRAMEP (locale))
8979 MARK_FRAME_GLYPHS_CHANGED (XFRAME (locale));
8981 else if (DEVICEP (locale))
8983 Lisp_Object frmcons;
8984 DEVICE_FRAME_LOOP (frmcons, XDEVICE (locale))
8985 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons)));
8987 else if (CONSOLEP (locale))
8989 Lisp_Object frmcons, devcons;
8990 CONSOLE_FRAME_LOOP_NO_BREAK (frmcons, devcons, XCONSOLE (locale))
8991 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons)));
8993 else /* global or buffer */
8995 Lisp_Object frmcons, devcons, concons;
8996 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
8997 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons)));
9002 text_cursor_visible_p_changed (Lisp_Object specifier, struct window *w,
9005 if (XFRAME (w->frame)->init_finished)
9006 Fforce_cursor_redisplay (w->frame);
9009 #ifdef MEMORY_USAGE_STATS
9012 /***************************************************************************/
9014 /* memory usage computation */
9016 /***************************************************************************/
9019 compute_rune_dynarr_usage (rune_dynarr *dyn, struct overhead_stats *ovstats)
9021 return dyn ? Dynarr_memory_usage (dyn, ovstats) : 0;
9025 compute_display_block_dynarr_usage (display_block_dynarr *dyn,
9026 struct overhead_stats *ovstats)
9033 total = Dynarr_memory_usage (dyn, ovstats);
9034 for (i = 0; i < Dynarr_largest (dyn); i++)
9035 total += compute_rune_dynarr_usage (Dynarr_at (dyn, i).runes, ovstats);
9041 compute_glyph_block_dynarr_usage (glyph_block_dynarr *dyn,
9042 struct overhead_stats *ovstats)
9044 return dyn ? Dynarr_memory_usage (dyn, ovstats) : 0;
9048 compute_display_line_dynarr_usage (display_line_dynarr *dyn,
9049 struct overhead_stats *ovstats)
9056 total = Dynarr_memory_usage (dyn, ovstats);
9057 for (i = 0; i < Dynarr_largest (dyn); i++)
9059 struct display_line *dl = &Dynarr_at (dyn, i);
9060 total += compute_display_block_dynarr_usage(dl->display_blocks, ovstats);
9061 total += compute_glyph_block_dynarr_usage (dl->left_glyphs, ovstats);
9062 total += compute_glyph_block_dynarr_usage (dl->right_glyphs, ovstats);
9069 compute_line_start_cache_dynarr_usage (line_start_cache_dynarr *dyn,
9070 struct overhead_stats *ovstats)
9072 return dyn ? Dynarr_memory_usage (dyn, ovstats) : 0;
9075 #endif /* MEMORY_USAGE_STATS */
9078 /***************************************************************************/
9080 /* initialization */
9082 /***************************************************************************/
9085 init_redisplay (void)
9087 disable_preemption = 0;
9088 preemption_count = 0;
9089 max_preempts = INIT_MAX_PREEMPTS;
9095 cmotion_display_lines = Dynarr_new (display_line);
9096 mode_spec_bufbyte_string = Dynarr_new (Bufbyte);
9097 formatted_string_emchar_dynarr = Dynarr_new (Emchar);
9098 formatted_string_extent_dynarr = Dynarr_new (EXTENT);
9099 formatted_string_extent_start_dynarr = Dynarr_new (Bytecount);
9100 formatted_string_extent_end_dynarr = Dynarr_new (Bytecount);
9101 internal_cache = Dynarr_new (line_start_cache);
9102 xzero (formatted_string_display_line);
9105 /* window system is nil when in -batch mode */
9106 if (!initialized || noninteractive)
9109 /* If the user wants to use a window system, we shouldn't bother
9110 initializing the terminal. This is especially important when the
9111 terminal is so dumb that emacs gives up before and doesn't bother
9112 using the window system.
9114 If the DISPLAY environment variable is set, try to use X, and die
9115 with an error message if that doesn't work. */
9117 #ifdef HAVE_X_WINDOWS
9118 if (!strcmp (display_use, "x"))
9120 /* Some stuff checks this way early. */
9121 Vwindow_system = Qx;
9122 Vinitial_window_system = Qx;
9125 #endif /* HAVE_X_WINDOWS */
9127 #ifdef HAVE_MS_WINDOWS
9128 if (!strcmp (display_use, "mswindows"))
9130 /* Some stuff checks this way early. */
9131 Vwindow_system = Qmswindows;
9132 Vinitial_window_system = Qmswindows;
9135 #endif /* HAVE_MS_WINDOWS */
9138 /* If no window system has been specified, try to use the terminal. */
9141 stderr_out ("XEmacs: standard input is not a tty\n");
9145 /* Look at the TERM variable */
9146 if (!getenv ("TERM"))
9148 stderr_out ("Please set the environment variable TERM; see tset(1).\n");
9152 Vinitial_window_system = Qtty;
9154 #else /* not HAVE_TTY */
9155 /* No DISPLAY specified, and no TTY support. */
9156 stderr_out ("XEmacs: Cannot open display.\n\
9157 Please set the environmental variable DISPLAY to an appropriate value.\n");
9164 syms_of_redisplay (void)
9166 defsymbol (&Qcursor_in_echo_area, "cursor-in-echo-area");
9167 #ifndef INHIBIT_REDISPLAY_HOOKS
9168 defsymbol (&Qpre_redisplay_hook, "pre-redisplay-hook");
9169 defsymbol (&Qpost_redisplay_hook, "post-redisplay-hook");
9170 #endif /* INHIBIT_REDISPLAY_HOOKS */
9171 defsymbol (&Qdisplay_warning_buffer, "display-warning-buffer");
9172 defsymbol (&Qbar_cursor, "bar-cursor");
9173 defsymbol (&Qredisplay_end_trigger_functions,
9174 "redisplay-end-trigger-functions");
9176 DEFSUBR (Fredisplay_echo_area);
9177 DEFSUBR (Fredraw_frame);
9178 DEFSUBR (Fredisplay_frame);
9179 DEFSUBR (Fredraw_device);
9180 DEFSUBR (Fredisplay_device);
9181 DEFSUBR (Fredraw_modeline);
9182 DEFSUBR (Fforce_cursor_redisplay);
9186 reinit_vars_of_redisplay (void)
9188 updating_line_start_cache = 0;
9192 vars_of_redisplay (void)
9194 reinit_vars_of_redisplay ();
9197 staticpro (&last_arrow_position);
9198 staticpro (&last_arrow_string);
9199 last_arrow_position = Qnil;
9200 last_arrow_string = Qnil;
9203 /* #### Probably temporary */
9204 DEFVAR_INT ("redisplay-cache-adjustment", &cache_adjustment /*
9205 \(Temporary) Setting this will impact the performance of the internal
9208 cache_adjustment = 2;
9210 DEFVAR_INT_MAGIC ("pixel-vertical-clip-threshold", &vertical_clip /*
9211 Minimum pixel height for clipped bottom display line.
9212 A clipped line shorter than this won't be displayed.
9214 redisplay_variable_changed);
9217 DEFVAR_INT_MAGIC ("pixel-horizontal-clip-threshold", &horizontal_clip /*
9218 Minimum visible area for clipped glyphs at right boundary.
9219 Clipped glyphs shorter than this won't be displayed.
9220 Only pixmap glyph instances are currently allowed to be clipped.
9222 redisplay_variable_changed);
9223 horizontal_clip = 5;
9225 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string /*
9226 String displayed by modeline-format's "%m" specification.
9228 Vglobal_mode_string = Qnil;
9230 DEFVAR_LISP_MAGIC ("overlay-arrow-position", &Voverlay_arrow_position /*
9231 Marker for where to display an arrow on top of the buffer text.
9232 This must be the beginning of a line in order to work.
9233 See also `overlay-arrow-string'.
9235 redisplay_variable_changed);
9236 Voverlay_arrow_position = Qnil;
9238 DEFVAR_LISP_MAGIC ("overlay-arrow-string", &Voverlay_arrow_string /*
9239 String to display as an arrow. See also `overlay-arrow-position'.
9241 redisplay_variable_changed);
9242 Voverlay_arrow_string = Qnil;
9244 DEFVAR_INT ("scroll-step", &scroll_step /*
9245 *The number of lines to try scrolling a window by when point moves out.
9246 If that fails to bring point back on frame, point is centered instead.
9247 If this is zero, point is always centered after it moves off screen.
9251 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively /*
9252 *Scroll up to this many lines, to bring point back on screen.
9254 scroll_conservatively = 0;
9256 DEFVAR_BOOL_MAGIC ("truncate-partial-width-windows",
9257 &truncate_partial_width_windows /*
9258 *Non-nil means truncate lines in all windows less than full frame wide.
9260 redisplay_variable_changed);
9261 truncate_partial_width_windows = 1;
9263 DEFVAR_BOOL ("visible-bell", &visible_bell /*
9264 *Non-nil means try to flash the frame to represent a bell.
9268 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter /*
9269 *Non-nil means no need to redraw entire frame after suspending.
9270 A non-nil value is useful if the terminal can automatically preserve
9271 Emacs's frame display when you reenter Emacs.
9272 It is up to you to set this variable if your terminal can do that.
9274 no_redraw_on_reenter = 0;
9276 DEFVAR_LISP ("window-system", &Vwindow_system /*
9277 A symbol naming the window-system under which Emacs is running,
9278 such as `x', or nil if emacs is running on an ordinary terminal.
9280 Do not use this variable, except for GNU Emacs compatibility, as it
9281 gives wrong values in a multi-device environment. Use `console-type'
9284 Vwindow_system = Qnil;
9286 /* #### Temporary shit until window-system is eliminated. */
9287 DEFVAR_CONST_LISP ("initial-window-system", &Vinitial_window_system /*
9290 Vinitial_window_system = Qnil;
9292 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area /*
9293 Non-nil means put cursor in minibuffer, at end of any message there.
9295 cursor_in_echo_area = 0;
9297 /* #### Shouldn't this be generalized as follows:
9299 if nil, use block cursor.
9300 if a number, use a bar cursor of that width.
9301 Otherwise, use a 1-pixel bar cursor.
9303 #### Or better yet, this variable should be trashed entirely
9304 (use a Lisp-magic variable to maintain compatibility)
9305 and a specifier `cursor-shape' added, which allows a block
9306 cursor, a bar cursor, a flashing block or bar cursor,
9307 maybe a caret cursor, etc. */
9309 DEFVAR_LISP ("bar-cursor", &Vbar_cursor /*
9310 Use vertical bar cursor if non-nil. If t width is 1 pixel, otherwise 2.
9314 #ifndef INHIBIT_REDISPLAY_HOOKS
9315 xxDEFVAR_LISP ("pre-redisplay-hook", &Vpre_redisplay_hook /*
9316 Function or functions to run before every redisplay.
9317 Functions on this hook must be careful to avoid signalling errors!
9319 Vpre_redisplay_hook = Qnil;
9321 xxDEFVAR_LISP ("post-redisplay-hook", &Vpost_redisplay_hook /*
9322 Function or functions to run after every redisplay.
9323 Functions on this hook must be careful to avoid signalling errors!
9325 Vpost_redisplay_hook = Qnil;
9326 #endif /* INHIBIT_REDISPLAY_HOOKS */
9328 DEFVAR_INT ("display-warning-tick", &display_warning_tick /*
9329 Bump this to tell the C code to call `display-warning-buffer'
9330 at next redisplay. You should not normally change this; the function
9331 `display-warning' automatically does this at appropriate times.
9333 display_warning_tick = 0;
9335 DEFVAR_BOOL ("inhibit-warning-display", &inhibit_warning_display /*
9336 Non-nil means inhibit display of warning messages.
9337 You should *bind* this, not set it. Any pending warning messages
9338 will be displayed when the binding no longer applies.
9340 /* reset to 0 by startup.el after the splash screen has displayed.
9341 This way, the warnings don't obliterate the splash screen. */
9342 inhibit_warning_display = 1;
9344 DEFVAR_LISP ("window-size-change-functions",
9345 &Vwindow_size_change_functions /*
9346 Not currently implemented.
9347 Functions called before redisplay, if window sizes have changed.
9348 The value should be a list of functions that take one argument.
9349 Just before redisplay, for each frame, if any of its windows have changed
9350 size since the last redisplay, or have been split or deleted,
9351 all the functions in the list are called, with the frame as argument.
9353 Vwindow_size_change_functions = Qnil;
9355 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions /*
9356 Not currently implemented.
9357 Functions to call before redisplaying a window with scrolling.
9358 Each function is called with two arguments, the window
9359 and its new display-start position. Note that the value of `window-end'
9360 is not valid when these functions are called.
9362 Vwindow_scroll_functions = Qnil;
9364 DEFVAR_LISP ("redisplay-end-trigger-functions",
9365 &Vredisplay_end_trigger_functions /*
9366 See `set-window-redisplay-end-trigger'.
9368 Vredisplay_end_trigger_functions = Qnil;
9370 DEFVAR_BOOL ("column-number-start-at-one", &column_number_start_at_one /*
9371 *Non-nil means column display number starts at 1.
9373 column_number_start_at_one = 0;
9377 specifier_vars_of_redisplay (void)
9379 DEFVAR_SPECIFIER ("left-margin-width", &Vleft_margin_width /*
9380 *Width of left margin.
9381 This is a specifier; use `set-specifier' to change it.
9383 Vleft_margin_width = Fmake_specifier (Qnatnum);
9384 set_specifier_fallback (Vleft_margin_width, list1 (Fcons (Qnil, Qzero)));
9385 set_specifier_caching (Vleft_margin_width,
9386 slot_offset (struct window, left_margin_width),
9387 some_window_value_changed,
9388 slot_offset (struct frame, left_margin_width),
9389 margin_width_changed_in_frame);
9391 DEFVAR_SPECIFIER ("right-margin-width", &Vright_margin_width /*
9392 *Width of right margin.
9393 This is a specifier; use `set-specifier' to change it.
9395 Vright_margin_width = Fmake_specifier (Qnatnum);
9396 set_specifier_fallback (Vright_margin_width, list1 (Fcons (Qnil, Qzero)));
9397 set_specifier_caching (Vright_margin_width,
9398 slot_offset (struct window, right_margin_width),
9399 some_window_value_changed,
9400 slot_offset (struct frame, right_margin_width),
9401 margin_width_changed_in_frame);
9403 DEFVAR_SPECIFIER ("minimum-line-ascent", &Vminimum_line_ascent /*
9404 *Minimum ascent height of lines.
9405 This is a specifier; use `set-specifier' to change it.
9407 Vminimum_line_ascent = Fmake_specifier (Qnatnum);
9408 set_specifier_fallback (Vminimum_line_ascent, list1 (Fcons (Qnil, Qzero)));
9409 set_specifier_caching (Vminimum_line_ascent,
9410 slot_offset (struct window, minimum_line_ascent),
9411 some_window_value_changed,
9414 DEFVAR_SPECIFIER ("minimum-line-descent", &Vminimum_line_descent /*
9415 *Minimum descent height of lines.
9416 This is a specifier; use `set-specifier' to change it.
9418 Vminimum_line_descent = Fmake_specifier (Qnatnum);
9419 set_specifier_fallback (Vminimum_line_descent, list1 (Fcons (Qnil, Qzero)));
9420 set_specifier_caching (Vminimum_line_descent,
9421 slot_offset (struct window, minimum_line_descent),
9422 some_window_value_changed,
9425 DEFVAR_SPECIFIER ("use-left-overflow", &Vuse_left_overflow /*
9426 *Non-nil means use the left outside margin as extra whitespace when
9427 displaying 'whitespace or 'inside-margin glyphs.
9428 This is a specifier; use `set-specifier' to change it.
9430 Vuse_left_overflow = Fmake_specifier (Qboolean);
9431 set_specifier_fallback (Vuse_left_overflow, list1 (Fcons (Qnil, Qnil)));
9432 set_specifier_caching (Vuse_left_overflow,
9433 slot_offset (struct window, use_left_overflow),
9434 some_window_value_changed,
9437 DEFVAR_SPECIFIER ("use-right-overflow", &Vuse_right_overflow /*
9438 *Non-nil means use the right outside margin as extra whitespace when
9439 displaying 'whitespace or 'inside-margin glyphs.
9440 This is a specifier; use `set-specifier' to change it.
9442 Vuse_right_overflow = Fmake_specifier (Qboolean);
9443 set_specifier_fallback (Vuse_right_overflow, list1 (Fcons (Qnil, Qnil)));
9444 set_specifier_caching (Vuse_right_overflow,
9445 slot_offset (struct window, use_right_overflow),
9446 some_window_value_changed,
9449 DEFVAR_SPECIFIER ("text-cursor-visible-p", &Vtext_cursor_visible_p /*
9450 *Non-nil means the text cursor is visible (this is usually the case).
9451 This is a specifier; use `set-specifier' to change it.
9453 Vtext_cursor_visible_p = Fmake_specifier (Qboolean);
9454 set_specifier_fallback (Vtext_cursor_visible_p, list1 (Fcons (Qnil, Qt)));
9455 set_specifier_caching (Vtext_cursor_visible_p,
9456 slot_offset (struct window, text_cursor_visible_p),
9457 text_cursor_visible_p_changed,