428
|
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.
|
3025
|
4 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2003, 2005 Ben Wing.
|
428
|
5 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
6 Copyright (C) 1996 Chuck Thompson.
|
|
7
|
|
8 This file is part of XEmacs.
|
|
9
|
|
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
|
|
13 later version.
|
|
14
|
|
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
|
|
18 for more details.
|
|
19
|
|
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. */
|
|
24
|
|
25 /* Synched up with: Not in FSF. */
|
|
26
|
|
27 /* Author: Chuck Thompson */
|
|
28
|
|
29 /* Fixed up by Ben Wing for Mule */
|
|
30
|
|
31 /* This file has been Mule-ized. */
|
|
32
|
|
33 /*****************************************************************************
|
|
34 The Golden Rules of Redisplay
|
|
35
|
853
|
36 First: It Is Better To Be Correct Than Fast
|
|
37 Second: Thou Shalt Use Due Caution When Running Elisp From Within Redisplay
|
|
38 Third: It Is Better To Be Fast Than Not To Be
|
428
|
39 ****************************************************************************/
|
|
40
|
1318
|
41 /* Note: The second rule used to prohibit running Elisp from within
|
|
42 redisplay, but that's not correct any more -- use
|
|
43 call*_trapping_problems() or call_with_suspended_errors() instead.
|
853
|
44
|
|
45 --ben
|
|
46 */
|
|
47
|
428
|
48 #include <config.h>
|
|
49 #include "lisp.h"
|
|
50
|
|
51 #include "buffer.h"
|
|
52 #include "commands.h"
|
|
53 #include "debug.h"
|
872
|
54 #include "device-impl.h"
|
428
|
55 #include "elhash.h"
|
853
|
56 #include "events.h"
|
872
|
57 #include "extents-impl.h"
|
428
|
58 #include "faces.h"
|
872
|
59 #include "frame-impl.h"
|
428
|
60 #include "glyphs.h"
|
|
61 #include "gutter.h"
|
|
62 #include "insdel.h"
|
|
63 #include "menubar.h"
|
872
|
64 #include "objects-impl.h"
|
1318
|
65 #include "opaque.h"
|
428
|
66 #include "process.h"
|
1292
|
67 #include "profile.h"
|
428
|
68 #include "redisplay.h"
|
|
69 #include "toolbar.h"
|
872
|
70 #include "window-impl.h"
|
428
|
71 #include "line-number.h"
|
|
72 #include "file-coding.h"
|
|
73
|
442
|
74 #include "sysfile.h"
|
|
75
|
428
|
76 #ifdef HAVE_TTY
|
|
77 #include "console-tty.h"
|
|
78 #endif /* HAVE_TTY */
|
|
79
|
|
80 /* Note: We have to be careful throughout this code to properly handle
|
867
|
81 and differentiate between Ibytes and Ichars.
|
|
82
|
|
83 Since strings are generally composed of Ibytes, I've taken the tack
|
|
84 that any contiguous set of Ibytes is called a "string", while
|
|
85 any contiguous set of Ichars is called an "array". */
|
428
|
86
|
|
87 /* Return value to indicate a failure by an add_*_rune routine to add
|
|
88 a rune, but no propagation information needs to be returned. */
|
|
89 #define ADD_FAILED (prop_block_dynarr *) 1
|
|
90
|
|
91 #define BEGIN_GLYPHS 0
|
|
92 #define END_GLYPHS 1
|
|
93 #define LEFT_GLYPHS 2
|
|
94 #define RIGHT_GLYPHS 3
|
|
95
|
|
96 #define VERTICAL_CLIP(w, display) \
|
442
|
97 ((WINDOW_TTY_P (w) | (!display && scroll_on_clipped_lines)) \
|
428
|
98 ? INT_MAX \
|
442
|
99 : vertical_clip)
|
428
|
100
|
|
101 /* The following structures are completely private to redisplay.c so
|
|
102 we put them here instead of in a header file, for modularity. */
|
|
103
|
826
|
104 /* NOTE: Bytexpos's not Charxpos's in this structure. */
|
428
|
105
|
|
106 typedef struct position_redisplay_data_type
|
|
107 {
|
|
108 /* This information is normally filled in by the create_*_block
|
|
109 routines and is used by the add_*_rune routines. */
|
|
110 Lisp_Object window;
|
|
111 /* if we are working with strings rather than buffers we need a
|
|
112 handle to the string */
|
|
113 Lisp_Object string;
|
|
114 struct device *d;
|
|
115 struct display_block *db;
|
|
116 struct display_line *dl;
|
867
|
117 Ichar ch; /* Character that is to be added. This is
|
428
|
118 used to communicate this information to
|
867
|
119 add_ichar_rune(). */
|
428
|
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. */
|
|
127
|
|
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. */
|
826
|
132 Bytexpos byte_charpos; /* Position of character we are processing. This
|
|
133 is a Bytexpos, meaning it refers to bytes (not
|
|
134 chars) and can refer to either buffers (1-based)
|
|
135 or strings (0-based). We need to be careful
|
|
136 when doing anything that references the text in
|
|
137 the buffer or string. */
|
|
138 Bytexpos byte_endpos; /* ????? Unknown, under-used. */
|
428
|
139 int pixpos;
|
|
140 int max_pixpos;
|
|
141 int blank_width; /* Width of the blank that is to be added.
|
|
142 This is used to communicate this information
|
|
143 to add_blank_rune().
|
|
144
|
|
145 This is also used rather cheesily to
|
|
146 communicate the width of the eol-cursor-size
|
|
147 blank that exists at the end of the line.
|
867
|
148 add_ichar_rune() is called cheesily with
|
428
|
149 the non-printing char '\n', which is stuck
|
|
150 in the output routines with its width being
|
|
151 BLANK_WIDTH. */
|
826
|
152 Bytexpos byte_cursor_charpos; /* This stores the buffer position of the
|
|
153 cursor. */
|
428
|
154 unsigned int cursor_type :3;
|
|
155 int cursor_x; /* rune block cursor is at */
|
|
156 int start_col; /* Number of character columns (each column has
|
|
157 a width of the default char width) that still
|
|
158 need to be skipped. This is used for horizontal
|
|
159 scrolling, where a certain number of columns
|
|
160 (those off the left side of the screen) need
|
|
161 to be skipped before anything is displayed. */
|
826
|
162 Bytexpos byte_start_col_enabled;
|
428
|
163 int start_col_xoffset; /* Number of pixels that still need to
|
819
|
164 be skipped. This is used for
|
|
165 horizontal scrolling of glyphs, where we want
|
|
166 to be able to scroll over part of the glyph. */
|
428
|
167
|
|
168 int hscroll_glyph_width_adjust; /* how much the width of the hscroll
|
|
169 glyph differs from space_width (w).
|
|
170 0 if no hscroll glyph was used,
|
|
171 i.e. the window is not scrolled
|
|
172 horizontally. Used in tab
|
|
173 calculations. */
|
|
174
|
|
175 /* Information about the face the text should be displayed in and
|
|
176 any begin-glyphs and end-glyphs. */
|
|
177 struct extent_fragment *ef;
|
|
178 face_index findex;
|
|
179
|
819
|
180 /* The height of a pixmap may either be predetermined if the user has set a
|
|
181 baseline value, or it may be dependent on whatever the line ascent and
|
|
182 descent values end up being, based just on font and pixmap-ascent
|
|
183 information. In the first case we can immediately update the values, thus
|
|
184 their inclusion here. In the last case we cannot determine the actual
|
|
185 contribution to the line height until we have finished laying out all text
|
|
186 on the line. Thus we propagate the max height of such pixmaps and do a
|
|
187 final calculation (in calculate_baseline()) after all text has been added
|
|
188 to the line. */
|
428
|
189 int new_ascent;
|
|
190 int new_descent;
|
|
191 int max_pixmap_height;
|
819
|
192 int need_baseline_computation;
|
|
193 int end_glyph_width; /* Well, it is the kitchen sink after all ... */
|
428
|
194
|
|
195 Lisp_Object result_str; /* String where we put the result of
|
|
196 generating a formatted string in the modeline. */
|
|
197 int is_modeline; /* Non-zero if we're generating the modeline. */
|
|
198 Charcount modeline_charpos; /* Number of chars used in result_str so far;
|
|
199 corresponds to bytepos. */
|
|
200 Bytecount bytepos; /* Number of bytes used in result_str so far.
|
|
201 We don't actually copy the bytes into result_str
|
|
202 until the end because we don't know how big the
|
|
203 string is going to be until then. */
|
|
204 } pos_data;
|
|
205
|
|
206 enum prop_type
|
|
207 {
|
|
208 PROP_STRING,
|
|
209 PROP_CHAR,
|
|
210 PROP_MINIBUF_PROMPT,
|
819
|
211 PROP_BLANK,
|
|
212 PROP_GLYPH
|
428
|
213 };
|
|
214
|
|
215 /* Data that should be propagated to the next line. Either a single
|
867
|
216 Ichar, a string of Ibyte's or a glyph.
|
428
|
217
|
|
218 The actual data that is propagated ends up as a Dynarr of these
|
|
219 blocks.
|
|
220
|
819
|
221 prop_blocks are used to indicate that data that was supposed to go
|
|
222 on the previous line couldn't actually be displayed. Generally this
|
|
223 shouldn't happen if we are clipping the end of lines. If we are
|
|
224 wrapping then we need to display the propagation data before moving
|
|
225 on. Its questionable whether we should wrap or clip glyphs in this
|
|
226 instance. Most e-lisp relies on clipping so we preserve this
|
|
227 behavior.
|
|
228
|
867
|
229 #### It's unclean that both Ichars and Ibytes are here.
|
428
|
230 */
|
|
231
|
|
232 typedef struct prop_block prop_block;
|
|
233 struct prop_block
|
|
234 {
|
|
235 enum prop_type type;
|
|
236
|
|
237 union data
|
|
238 {
|
|
239 struct
|
|
240 {
|
867
|
241 Ibyte *str;
|
428
|
242 Bytecount len; /* length of the string. */
|
|
243 } p_string;
|
|
244
|
|
245 struct
|
|
246 {
|
867
|
247 Ichar ch;
|
826
|
248 Bytebpos byte_cursor_charpos; /* NOTE: is in Bytebpos's */
|
428
|
249 unsigned int cursor_type :3;
|
|
250 } p_char;
|
|
251
|
|
252 struct
|
|
253 {
|
|
254 int width;
|
|
255 face_index findex;
|
|
256 } p_blank;
|
819
|
257
|
|
258 struct
|
|
259 {
|
|
260 /* Not used as yet, but could be used to wrap rather than clip glyphs. */
|
|
261 int width;
|
|
262 Lisp_Object glyph;
|
|
263 } p_glyph;
|
|
264
|
428
|
265 } data;
|
|
266 };
|
|
267
|
|
268 typedef struct
|
|
269 {
|
|
270 Dynarr_declare (prop_block);
|
|
271 } prop_block_dynarr;
|
|
272
|
|
273
|
|
274 static Charcount generate_fstring_runes (struct window *w, pos_data *data,
|
|
275 Charcount pos, Charcount min_pos,
|
|
276 Charcount max_pos, Lisp_Object elt,
|
|
277 int depth, int max_pixsize,
|
438
|
278 face_index findex, int type,
|
|
279 Charcount *offset,
|
|
280 Lisp_Object cur_ext);
|
428
|
281 static prop_block_dynarr *add_glyph_rune (pos_data *data,
|
|
282 struct glyph_block *gb,
|
|
283 int pos_type, int allow_cursor,
|
|
284 struct glyph_cachel *cachel);
|
665
|
285 static Bytebpos create_text_block (struct window *w, struct display_line *dl,
|
826
|
286 Bytebpos byte_start_pos,
|
|
287 prop_block_dynarr **prop,
|
|
288 int type);
|
428
|
289 static int create_overlay_glyph_block (struct window *w,
|
|
290 struct display_line *dl);
|
|
291 static void create_left_glyph_block (struct window *w,
|
|
292 struct display_line *dl,
|
|
293 int overlay_width);
|
|
294 static void create_right_glyph_block (struct window *w,
|
|
295 struct display_line *dl);
|
|
296 static void redisplay_windows (Lisp_Object window, int skip_selected);
|
867
|
297 static void decode_mode_spec (struct window *w, Ichar spec, int type);
|
428
|
298 static void free_display_line (struct display_line *dl);
|
826
|
299 static void update_line_start_cache (struct window *w, Charbpos from,
|
|
300 Charbpos to, Charbpos point,
|
|
301 int no_regen);
|
665
|
302 static int point_visible (struct window *w, Charbpos point, int type);
|
819
|
303 static void calculate_yoffset (struct display_line *dl,
|
|
304 struct display_block *fixup);
|
|
305 static void calculate_baseline (pos_data *data);
|
428
|
306
|
1204
|
307 #ifdef ERROR_CHECK_DISPLAY
|
800
|
308 static void sledgehammer_check_redisplay_structs (void);
|
1204
|
309 #endif /* ERROR_CHECK_DISPLAY */
|
800
|
310
|
428
|
311 /* This used to be 10 but 30 seems to give much better performance. */
|
|
312 #define INIT_MAX_PREEMPTS 30
|
1268
|
313 static Fixnum max_preempts;
|
|
314
|
|
315 #define QUEUED_EVENTS_REQUIRED_FOR_PREEMPTION 4
|
428
|
316
|
1318
|
317 /* Note that doing this can call Lisp. */
|
428
|
318 #define REDISPLAY_PREEMPTION_CHECK \
|
|
319 ((void) \
|
|
320 (preempted = \
|
|
321 (!disable_preemption && \
|
|
322 ((preemption_count < max_preempts) || !NILP (Vexecuting_macro)) && \
|
1268
|
323 (!INTERACTIVE || \
|
|
324 detect_input_pending (QUEUED_EVENTS_REQUIRED_FOR_PREEMPTION)))))
|
428
|
325
|
|
326 /*
|
|
327 * Redisplay global variables.
|
|
328 */
|
|
329
|
|
330 /* We need a third set of display structures for the cursor motion
|
|
331 routines. We used to just give each window a third set. However,
|
|
332 we always fully regenerate the structures when needed so there
|
|
333 isn't any reason we need more than a single set. */
|
|
334 display_line_dynarr *cmotion_display_lines;
|
|
335
|
|
336 /* We store the extents that we need to generate in a Dynarr and then
|
|
337 frob them all on at the end of generating the string. We do it
|
|
338 this way rather than adding them as we generate the string because
|
|
339 we don't store the text into the resulting string until we're done
|
|
340 (to avoid having to resize the string multiple times), and we don't
|
|
341 want to go around adding extents to a string when the extents might
|
|
342 stretch off the end of the string. */
|
|
343 static EXTENT_dynarr *formatted_string_extent_dynarr;
|
|
344 static Bytecount_dynarr *formatted_string_extent_start_dynarr;
|
|
345 static Bytecount_dynarr *formatted_string_extent_end_dynarr;
|
|
346
|
|
347
|
|
348 /* #### probably temporary */
|
458
|
349 Fixnum cache_adjustment;
|
428
|
350
|
|
351 /* This holds a string representing the text corresponding to a single
|
|
352 modeline % spec. */
|
867
|
353 static Ibyte_dynarr *mode_spec_ibyte_string;
|
428
|
354
|
|
355 int in_display; /* 1 if in redisplay. */
|
|
356
|
1318
|
357 /* Whether we should delay size changes. Broken out of
|
|
358 enter_redisplay_critical_section(). */
|
|
359 int hold_frame_size_changes;
|
|
360
|
428
|
361 int disable_preemption; /* Used for debugging redisplay and for
|
|
362 force-redisplay. */
|
|
363
|
|
364 /* We only allow max_preempts preemptions before we force a redisplay. */
|
|
365 static int preemption_count;
|
|
366
|
|
367 /* Minimum pixel height of clipped bottom display line. */
|
458
|
368 Fixnum vertical_clip;
|
428
|
369
|
|
370 /* Minimum visible pixel width of clipped glyphs at right margin. */
|
458
|
371 Fixnum horizontal_clip;
|
428
|
372
|
|
373 /* Nonzero means reading single-character input with prompt
|
|
374 so put cursor on minibuffer after the prompt. */
|
|
375 int cursor_in_echo_area;
|
|
376 Lisp_Object Qcursor_in_echo_area;
|
|
377
|
|
378 /* Nonzero means truncate lines in all windows less wide than the frame */
|
|
379 int truncate_partial_width_windows;
|
|
380
|
|
381 /* non-nil if a buffer has changed since the last time redisplay completed */
|
|
382 int buffers_changed;
|
|
383 int buffers_changed_set;
|
|
384
|
|
385 /* non-nil if hscroll has changed somewhere or a buffer has been
|
|
386 narrowed or widened */
|
|
387 int clip_changed;
|
|
388 int clip_changed_set;
|
|
389
|
|
390 /* non-nil if any extent has changed since the last time redisplay completed */
|
|
391 int extents_changed;
|
|
392 int extents_changed_set;
|
|
393
|
|
394 /* non-nil if any face has changed since the last time redisplay completed */
|
|
395 int faces_changed;
|
|
396
|
|
397 /* Nonzero means some frames have been marked as garbaged */
|
|
398 int frame_changed;
|
|
399
|
|
400 /* non-zero if any of the builtin display glyphs (continuation,
|
|
401 hscroll, control-arrow, etc) is in need of updating
|
|
402 somewhere. */
|
|
403 int glyphs_changed;
|
|
404 int glyphs_changed_set;
|
|
405
|
442
|
406 /* non-zero if any subwindow has been deleted. */
|
428
|
407 int subwindows_changed;
|
|
408 int subwindows_changed_set;
|
|
409
|
|
410 /* non-zero if any displayed subwindow is in need of updating
|
|
411 somewhere. */
|
|
412 int subwindows_state_changed;
|
|
413 int subwindows_state_changed_set;
|
|
414
|
|
415 /* This variable is 1 if the icon has to be updated.
|
|
416 It is set to 1 when `frame-icon-glyph' changes. */
|
|
417 int icon_changed;
|
|
418 int icon_changed_set;
|
|
419
|
|
420 /* This variable is 1 if the menubar widget has to be updated.
|
|
421 It is set to 1 by set-menubar-dirty-flag and cleared when the widget
|
|
422 has been updated. */
|
|
423 int menubar_changed;
|
|
424 int menubar_changed_set;
|
|
425
|
|
426 /* true iff we should redraw the modelines on the next redisplay */
|
|
427 int modeline_changed;
|
|
428 int modeline_changed_set;
|
|
429
|
|
430 /* non-nil if point has changed in some buffer since the last time
|
|
431 redisplay completed */
|
|
432 int point_changed;
|
|
433 int point_changed_set;
|
|
434
|
|
435 /* non-nil if some frame has changed its size */
|
|
436 int size_changed;
|
|
437
|
|
438 /* non-nil if some device has signaled that it wants to change size */
|
|
439 int asynch_device_change_pending;
|
|
440
|
|
441 /* non-nil if any toolbar has changed */
|
|
442 int toolbar_changed;
|
|
443 int toolbar_changed_set;
|
|
444
|
905
|
445 /* Nonzero if some frame has changed the layout of internal elements
|
|
446 (gutters or toolbars). */
|
|
447 int frame_layout_changed;
|
|
448
|
428
|
449 /* non-nil if any gutter has changed */
|
|
450 int gutter_changed;
|
|
451 int gutter_changed_set;
|
|
452
|
|
453 /* non-nil if any window has changed since the last time redisplay completed */
|
|
454 int windows_changed;
|
|
455
|
|
456 /* non-nil if any frame's window structure has changed since the last
|
|
457 time redisplay completed */
|
|
458 int windows_structure_changed;
|
|
459
|
|
460 /* If non-nil, use vertical bar cursor. */
|
|
461 Lisp_Object Vbar_cursor;
|
|
462 Lisp_Object Qbar_cursor;
|
|
463
|
442
|
464 Lisp_Object Vvisible_bell; /* If true and the terminal will support it
|
|
465 then the frame will flash instead of
|
|
466 beeping when an error occurs */
|
428
|
467
|
|
468 /* Nonzero means no need to redraw the entire frame on resuming
|
|
469 a suspended Emacs. This is useful on terminals with multiple pages,
|
|
470 where one page is used for Emacs and another for all else. */
|
|
471 int no_redraw_on_reenter;
|
|
472
|
|
473 Lisp_Object Vwindow_system; /* nil or a symbol naming the window system
|
|
474 under which emacs is running
|
3025
|
475 (`x' is the only current possibility) */
|
428
|
476 Lisp_Object Vinitial_window_system;
|
|
477
|
|
478 Lisp_Object Vglobal_mode_string;
|
|
479
|
|
480 /* The number of lines scroll a window by when point leaves the window; if
|
|
481 it is <=0 then point is centered in the window */
|
458
|
482 Fixnum scroll_step;
|
428
|
483
|
|
484 /* Scroll up to this many lines, to bring point back on screen. */
|
458
|
485 Fixnum scroll_conservatively;
|
428
|
486
|
|
487 /* Marker for where to display an arrow on top of the buffer text. */
|
|
488 Lisp_Object Voverlay_arrow_position;
|
|
489 /* String to display for the arrow. */
|
|
490 Lisp_Object Voverlay_arrow_string;
|
|
491
|
442
|
492 Lisp_Object Qbuffer_list_changed_hook, Vbuffer_list_changed_hook;
|
|
493
|
458
|
494 static Fixnum last_display_warning_tick;
|
|
495 static Fixnum display_warning_tick;
|
428
|
496 Lisp_Object Qdisplay_warning_buffer;
|
|
497 int inhibit_warning_display;
|
|
498
|
|
499 Lisp_Object Vleft_margin_width, Vright_margin_width;
|
|
500 Lisp_Object Vminimum_line_ascent, Vminimum_line_descent;
|
|
501 Lisp_Object Vuse_left_overflow, Vuse_right_overflow;
|
|
502 Lisp_Object Vtext_cursor_visible_p;
|
|
503
|
1292
|
504 static Lisp_Object QSin_redisplay;
|
|
505
|
1318
|
506 static Lisp_Object Vpost_redisplay_actions;
|
|
507
|
428
|
508 int column_number_start_at_one;
|
|
509
|
442
|
510 Lisp_Object Qtop_bottom;
|
|
511
|
444
|
512 #define WINDOW_SCROLLED(w) ((w)->hscroll > 0 || (w)->left_xoffset)
|
428
|
513
|
1204
|
514 static const struct memory_description rune_dglyph_description_1[] = {
|
|
515 { XD_LISP_OBJECT, offsetof (struct rune_dglyph, glyph) },
|
|
516 { XD_LISP_OBJECT, offsetof (struct rune_dglyph, extent) },
|
|
517 { XD_END }
|
|
518 };
|
|
519
|
|
520 static const struct sized_memory_description rune_dglyph_description = {
|
|
521 sizeof (struct rune_dglyph), rune_dglyph_description_1
|
|
522 };
|
|
523
|
|
524 static const struct memory_description rune_object_description_1[] = {
|
2551
|
525 { XD_BLOCK_ARRAY, RUNE_DGLYPH, 1, { &rune_dglyph_description } },
|
1204
|
526 { XD_END }
|
|
527 };
|
|
528
|
|
529 static const struct sized_memory_description rune_object_description = {
|
|
530 0, rune_object_description_1
|
|
531 };
|
|
532
|
|
533 static const struct memory_description rune_description_1[] = {
|
|
534 { XD_INT, offsetof (rune, type) },
|
|
535 { XD_UNION, offsetof (rune, object),
|
2551
|
536 XD_INDIRECT (0, 0), { &rune_object_description } },
|
1204
|
537 { XD_END }
|
|
538 };
|
|
539
|
|
540 static const struct sized_memory_description rune_description = {
|
|
541 sizeof (rune),
|
|
542 rune_description_1
|
|
543 };
|
|
544
|
|
545 static const struct memory_description rune_dynarr_description_1[] = {
|
|
546 XD_DYNARR_DESC (rune_dynarr, &rune_description),
|
|
547 { XD_END }
|
|
548 };
|
|
549
|
|
550 static const struct sized_memory_description rune_dynarr_description = {
|
|
551 sizeof (rune_dynarr),
|
|
552 rune_dynarr_description_1
|
|
553 };
|
|
554
|
|
555 static const struct memory_description display_block_description_1[] = {
|
2367
|
556 { XD_BLOCK_PTR, offsetof (display_block, runes),
|
2551
|
557 1, { &rune_dynarr_description } },
|
1204
|
558 { XD_END }
|
|
559 };
|
|
560
|
|
561 static const struct sized_memory_description display_block_description = {
|
|
562 sizeof (display_block),
|
|
563 display_block_description_1
|
|
564 };
|
|
565
|
|
566 static const struct memory_description display_block_dynarr_description_1[] = {
|
|
567 XD_DYNARR_DESC (display_block_dynarr, &display_block_description),
|
|
568 { XD_END }
|
|
569 };
|
|
570
|
|
571 static const struct sized_memory_description display_block_dynarr_description = {
|
|
572 sizeof (display_block_dynarr),
|
|
573 display_block_dynarr_description_1
|
|
574 };
|
|
575
|
|
576 static const struct memory_description glyph_block_description_1[] = {
|
|
577 { XD_LISP_OBJECT, offsetof (glyph_block, glyph) },
|
|
578 { XD_LISP_OBJECT, offsetof (glyph_block, extent) },
|
|
579 { XD_END }
|
|
580 };
|
|
581
|
|
582 static const struct sized_memory_description glyph_block_description = {
|
|
583 sizeof (glyph_block),
|
|
584 glyph_block_description_1
|
|
585 };
|
|
586
|
|
587 static const struct memory_description glyph_block_dynarr_description_1[] = {
|
|
588 XD_DYNARR_DESC (glyph_block_dynarr, &glyph_block_description),
|
|
589 { XD_END }
|
|
590 };
|
|
591
|
|
592 static const struct sized_memory_description glyph_block_dynarr_description = {
|
|
593 sizeof (glyph_block_dynarr),
|
|
594 glyph_block_dynarr_description_1
|
|
595 };
|
|
596
|
|
597 static const struct memory_description display_line_description_1[] = {
|
2367
|
598 { XD_BLOCK_PTR, offsetof (display_line, display_blocks),
|
2551
|
599 1, { &display_block_dynarr_description } },
|
2367
|
600 { XD_BLOCK_PTR, offsetof (display_line, left_glyphs),
|
2551
|
601 1, { &glyph_block_dynarr_description } },
|
2367
|
602 { XD_BLOCK_PTR, offsetof (display_line, right_glyphs),
|
2551
|
603 1, { &glyph_block_dynarr_description } },
|
1204
|
604 { XD_END }
|
|
605 };
|
|
606
|
|
607 static const struct sized_memory_description display_line_description = {
|
|
608 sizeof (display_line),
|
|
609 display_line_description_1
|
|
610 };
|
|
611
|
|
612 static const struct memory_description display_line_dynarr_description_1[] = {
|
|
613 XD_DYNARR_DESC (display_line_dynarr, &display_line_description),
|
|
614 { XD_END }
|
|
615 };
|
|
616
|
|
617 const struct sized_memory_description display_line_dynarr_description = {
|
|
618 sizeof (display_line_dynarr),
|
|
619 display_line_dynarr_description_1
|
|
620 };
|
|
621
|
428
|
622
|
|
623 /***************************************************************************/
|
|
624 /* */
|
|
625 /* low-level interfaces onto device routines */
|
|
626 /* */
|
|
627 /***************************************************************************/
|
|
628
|
|
629 static int
|
867
|
630 redisplay_text_width_ichar_string (struct window *w, int findex,
|
|
631 Ichar *str, Charcount len)
|
428
|
632 {
|
|
633 unsigned char charsets[NUM_LEADING_BYTES];
|
|
634 Lisp_Object window;
|
|
635
|
867
|
636 find_charsets_in_ichar_string (charsets, str, len);
|
793
|
637 window = wrap_window (w);
|
428
|
638 ensure_face_cachel_complete (WINDOW_FACE_CACHEL (w, findex), window,
|
|
639 charsets);
|
|
640 return DEVMETH (XDEVICE (FRAME_DEVICE (XFRAME (WINDOW_FRAME (w)))),
|
|
641 text_width, (XFRAME (WINDOW_FRAME (w)),
|
|
642 WINDOW_FACE_CACHEL (w, findex), str, len));
|
|
643 }
|
|
644
|
867
|
645 static Ichar_dynarr *rtw_ichar_dynarr;
|
428
|
646
|
|
647 int
|
|
648 redisplay_text_width_string (struct window *w, int findex,
|
867
|
649 Ibyte *nonreloc, Lisp_Object reloc,
|
428
|
650 Bytecount offset, Bytecount len)
|
|
651 {
|
867
|
652 if (!rtw_ichar_dynarr)
|
|
653 rtw_ichar_dynarr = Dynarr_new (Ichar);
|
|
654 Dynarr_reset (rtw_ichar_dynarr);
|
428
|
655
|
|
656 fixup_internal_substring (nonreloc, reloc, offset, &len);
|
|
657 if (STRINGP (reloc))
|
|
658 nonreloc = XSTRING_DATA (reloc);
|
867
|
659 convert_ibyte_string_into_ichar_dynarr (nonreloc, len, rtw_ichar_dynarr);
|
|
660 return redisplay_text_width_ichar_string
|
|
661 (w, findex, Dynarr_atp (rtw_ichar_dynarr, 0),
|
|
662 Dynarr_length (rtw_ichar_dynarr));
|
428
|
663 }
|
|
664
|
|
665 int
|
|
666 redisplay_frame_text_width_string (struct frame *f, Lisp_Object face,
|
867
|
667 Ibyte *nonreloc, Lisp_Object reloc,
|
428
|
668 Bytecount offset, Bytecount len)
|
|
669 {
|
|
670 unsigned char charsets[NUM_LEADING_BYTES];
|
|
671 Lisp_Object frame;
|
|
672 struct face_cachel cachel;
|
|
673
|
867
|
674 if (!rtw_ichar_dynarr)
|
|
675 rtw_ichar_dynarr = Dynarr_new (Ichar);
|
|
676 Dynarr_reset (rtw_ichar_dynarr);
|
428
|
677
|
|
678 fixup_internal_substring (nonreloc, reloc, offset, &len);
|
|
679 if (STRINGP (reloc))
|
|
680 nonreloc = XSTRING_DATA (reloc);
|
867
|
681 convert_ibyte_string_into_ichar_dynarr (nonreloc, len, rtw_ichar_dynarr);
|
|
682 find_charsets_in_ibyte_string (charsets, nonreloc, len);
|
428
|
683 reset_face_cachel (&cachel);
|
|
684 cachel.face = face;
|
793
|
685 frame = wrap_frame (f);
|
428
|
686 ensure_face_cachel_complete (&cachel, frame, charsets);
|
|
687 return DEVMETH (XDEVICE (FRAME_DEVICE (f)),
|
867
|
688 text_width, (f, &cachel, Dynarr_atp (rtw_ichar_dynarr, 0),
|
|
689 Dynarr_length (rtw_ichar_dynarr)));
|
428
|
690 }
|
|
691
|
|
692 /* Return the display block from DL of the given TYPE. A display line
|
|
693 can have only one display block of each possible type. If DL does
|
|
694 not have a block of type TYPE, one will be created and added to DL. */
|
|
695
|
|
696 struct display_block *
|
|
697 get_display_block_from_line (struct display_line *dl, enum display_type type)
|
|
698 {
|
|
699 int elt;
|
|
700 struct display_block db;
|
|
701
|
|
702 /* Check if this display line already has a block of the desired type and
|
|
703 if so, return it. */
|
|
704 if (dl->display_blocks)
|
|
705 {
|
|
706 for (elt = 0; elt < Dynarr_length (dl->display_blocks); elt++)
|
|
707 {
|
|
708 if (Dynarr_at (dl->display_blocks, elt).type == type)
|
|
709 return Dynarr_atp (dl->display_blocks, elt);
|
|
710 }
|
|
711
|
|
712 /* There isn't an active block of the desired type, but there
|
|
713 might still be allocated blocks we need to reuse. */
|
|
714 if (elt < Dynarr_largest (dl->display_blocks))
|
|
715 {
|
|
716 struct display_block *dbp = Dynarr_atp (dl->display_blocks, elt);
|
|
717
|
3025
|
718 /* "add" the block to the list */
|
428
|
719 Dynarr_increment (dl->display_blocks);
|
|
720
|
|
721 /* initialize and return */
|
|
722 dbp->type = type;
|
|
723 return dbp;
|
|
724 }
|
|
725 }
|
|
726 else
|
|
727 {
|
|
728 /* This line doesn't have any display blocks, so initialize the display
|
|
729 bock array. */
|
|
730 dl->display_blocks = Dynarr_new (display_block);
|
|
731 }
|
|
732
|
|
733 /* The line doesn't have a block of the desired type so go ahead and create
|
|
734 one and add it to the line. */
|
|
735 xzero (db);
|
|
736 db.type = type;
|
|
737 db.runes = Dynarr_new (rune);
|
|
738 Dynarr_add (dl->display_blocks, db);
|
|
739
|
|
740 /* Return the newly added display block. */
|
|
741 elt = Dynarr_length (dl->display_blocks) - 1;
|
|
742
|
|
743 return Dynarr_atp (dl->display_blocks, elt);
|
|
744 }
|
|
745
|
|
746 static int
|
|
747 tab_char_width (struct window *w)
|
|
748 {
|
|
749 struct buffer *b = XBUFFER (w->buffer);
|
|
750 int char_tab_width = XINT (b->tab_width);
|
|
751
|
|
752 if (char_tab_width <= 0 || char_tab_width > 1000) char_tab_width = 8;
|
|
753
|
|
754 return char_tab_width;
|
|
755 }
|
|
756
|
|
757 static int
|
|
758 space_width (struct window *w)
|
|
759 {
|
|
760 /* While tabs are traditional composed of spaces, for variable-width
|
|
761 fonts the space character tends to give too narrow a value. So
|
|
762 we use 'n' instead. Except that we don't. We use the default
|
|
763 character width for the default face. If this is actually
|
|
764 defined by the font then it is probably the best thing to
|
|
765 actually use. If it isn't, we have assumed it is 'n' and have
|
|
766 already calculated its width. Thus we can avoid a call to
|
|
767 XTextWidth on X frames by just querying the default width. */
|
|
768 return XFONT_INSTANCE
|
|
769 (WINDOW_FACE_CACHEL_FONT (w, DEFAULT_INDEX, Vcharset_ascii))->width;
|
|
770 }
|
|
771
|
|
772 static int
|
|
773 tab_pix_width (struct window *w)
|
|
774 {
|
|
775 return space_width (w) * tab_char_width (w);
|
|
776 }
|
|
777
|
|
778 /* Given a pixel position in a window, return the pixel location of
|
|
779 the next tabstop. Tabs are calculated from the left window edge in
|
|
780 terms of spaces displayed in the default face. Formerly the space
|
|
781 width was determined using the currently active face. That method
|
|
782 leads to tabstops which do not line up. */
|
|
783
|
|
784 static int
|
|
785 next_tab_position (struct window *w, int start_pixpos, int left_pixpos)
|
|
786 {
|
|
787 int n_pos = left_pixpos;
|
|
788 int pix_tab_width = tab_pix_width (w);
|
|
789
|
|
790 /* Adjust n_pos for any hscrolling which has happened. */
|
|
791 if (WINDOW_SCROLLED (w))
|
|
792 n_pos -= space_width (w) * (w->hscroll - 1) + w->left_xoffset;
|
|
793
|
|
794 while (n_pos <= start_pixpos)
|
|
795 n_pos += pix_tab_width;
|
|
796
|
|
797 return n_pos;
|
|
798 }
|
|
799
|
|
800 /* For the given window, calculate the outside and margin boundaries for a
|
|
801 display line. The whitespace boundaries must be calculated by the text
|
|
802 layout routines. */
|
|
803
|
|
804 layout_bounds
|
|
805 calculate_display_line_boundaries (struct window *w, int modeline)
|
|
806 {
|
|
807 layout_bounds bounds;
|
|
808
|
|
809 /* Set the outermost boundaries which are the boundaries of the
|
|
810 window itself minus the gutters (and minus the scrollbars if this
|
|
811 is for the modeline). */
|
|
812 if (!modeline)
|
|
813 {
|
|
814 bounds.left_out = WINDOW_TEXT_LEFT (w);
|
|
815 bounds.right_out = WINDOW_TEXT_RIGHT (w);
|
|
816 }
|
|
817 else
|
|
818 {
|
|
819 bounds.left_out = WINDOW_MODELINE_LEFT (w);
|
|
820 bounds.right_out = WINDOW_MODELINE_RIGHT (w);
|
|
821 }
|
|
822
|
|
823 /* The inner boundaries mark where the glyph margins are located. */
|
|
824 bounds.left_in = bounds.left_out + window_left_margin_width (w);
|
|
825 bounds.right_in = bounds.right_out - window_right_margin_width (w);
|
|
826
|
|
827 /* We cannot fully calculate the whitespace boundaries as they
|
|
828 depend on the contents of the line being displayed. */
|
|
829 bounds.left_white = bounds.left_in;
|
|
830 bounds.right_white = bounds.right_in;
|
|
831
|
|
832 return bounds;
|
|
833 }
|
|
834
|
819
|
835 /* This takes a display_block and its containing line and corrects the yoffset
|
|
836 of each glyph in the block to cater for the ascent of the line as a
|
|
837 whole. Must be called *after* the line-ascent is known! */
|
|
838
|
|
839 static void
|
|
840 calculate_yoffset (struct display_line *dl, struct display_block *fixup)
|
|
841 {
|
|
842 int i;
|
|
843 for (i=0; i<Dynarr_length (fixup->runes); i++)
|
|
844 {
|
|
845 struct rune *r = Dynarr_atp (fixup->runes,i);
|
|
846 if (r->type == RUNE_DGLYPH)
|
|
847 {
|
|
848 if (r->object.dglyph.ascent < dl->ascent)
|
|
849 r->object.dglyph.yoffset = dl->ascent - r->object.dglyph.ascent +
|
|
850 r->object.dglyph.descent;
|
|
851 }
|
|
852 }
|
|
853 }
|
|
854
|
|
855 /* Calculate the textual baseline (the ascent and descent values for the
|
|
856 display_line as a whole).
|
|
857
|
|
858 If the baseline is completely blank, or contains no manually positioned
|
|
859 glyphs, then the textual baseline is simply the baseline of the default font.
|
|
860 (The `contains no manually positioned glyphs' part is actually done for
|
867
|
861 us by `add_ichar_rune'.)
|
819
|
862
|
|
863 If the baseline contains pixmaps, and they're all manually positioned, then
|
|
864 the textual baseline location is constrained that way, and we need do no
|
|
865 work.
|
|
866
|
|
867 If the baseline contains pixmaps, and at least one is automatically
|
|
868 positioned, then the textual ascent is the largest ascent on the line, and
|
|
869 the textual descent is the largest descent (which is how things are set up at
|
|
870 entry to this function anyway): except that if the max_ascent + max_descent
|
|
871 is too small for the height of the line (say you've adjusted the baseline of
|
|
872 a short glyph, and there's a tall one next to it), then take the ascent and
|
|
873 descent for the line individually from the largest of the explicitly set
|
|
874 ascent/descent, and the rescaled ascent/descent of the default font, scaled
|
|
875 such that the largest glyph will fit.
|
|
876
|
|
877 This means that if you have a short glyph (but taller than the default
|
|
878 font's descent) forced right under the baseline, and a really tall
|
|
879 automatically positioned glyph, that the descent for the line is just big
|
|
880 enough for the manually positioned short glyph, and the tall one uses as
|
|
881 much of that space as the default font would were it as tall as the tall
|
|
882 glyph; but that the ascent is big enough for the tall glyph to fit.
|
|
883
|
|
884 This behaviour means that under no circumstances will changing the baseline
|
|
885 of a short glyph cause a tall glyph to move around; nor will it move the
|
|
886 textual baseline more than necessary. (Changing a tall glyph's baseline
|
|
887 might move the text's baseline arbitrarily, of course.) */
|
|
888
|
|
889 static void
|
|
890 calculate_baseline (pos_data *data)
|
|
891 {
|
|
892 /* Blank line: baseline is default font's baseline. */
|
|
893
|
|
894 if (!data->new_ascent && !data->new_descent)
|
|
895 {
|
|
896 /* We've got a blank line so initialize these values from the default
|
|
897 face. */
|
|
898 default_face_font_info (data->window, &data->new_ascent,
|
|
899 &data->new_descent, 0, 0, 0);
|
|
900 }
|
|
901
|
|
902 /* No automatically positioned glyphs? Return at once. */
|
|
903 if (!data->need_baseline_computation)
|
|
904 return;
|
|
905
|
|
906 /* Is the tallest glyph on the line automatically positioned?
|
|
907 If it's manually positioned, or it's automatically positioned
|
|
908 and there's enough room for it anyway, we need do no more work. */
|
|
909 if (data->max_pixmap_height > data->new_ascent + data->new_descent)
|
|
910 {
|
|
911 int default_font_ascent, default_font_descent, default_font_height;
|
|
912 int scaled_default_font_ascent, scaled_default_font_descent;
|
|
913
|
|
914 default_face_font_info (data->window, &default_font_ascent,
|
|
915 &default_font_descent, &default_font_height,
|
|
916 0, 0);
|
|
917
|
|
918 scaled_default_font_ascent = data->max_pixmap_height *
|
|
919 default_font_ascent / default_font_height;
|
|
920
|
|
921 data->new_ascent = max (data->new_ascent, scaled_default_font_ascent);
|
|
922
|
|
923 /* The ascent may have expanded now. Do we still need to grow the descent,
|
|
924 or are things big enough?
|
|
925
|
|
926 The +1 caters for the baseline row itself. */
|
|
927 if (data->max_pixmap_height > data->new_ascent + data->new_descent)
|
|
928 {
|
|
929 scaled_default_font_descent = (data->max_pixmap_height *
|
|
930 default_font_descent / default_font_height) + 1;
|
|
931
|
|
932 data->new_descent = max (data->new_descent, scaled_default_font_descent);
|
|
933 }
|
|
934 }
|
|
935 }
|
|
936
|
428
|
937 /* Given a display line and a starting position, ensure that the
|
|
938 contents of the display line accurately represent the visual
|
|
939 representation of the buffer contents starting from the given
|
|
940 position when displayed in the given window. The display line ends
|
|
941 when the contents of the line reach the right boundary of the given
|
|
942 window. */
|
|
943
|
665
|
944 static Charbpos
|
428
|
945 generate_display_line (struct window *w, struct display_line *dl, int bounds,
|
665
|
946 Charbpos start_pos, prop_block_dynarr **prop,
|
428
|
947 int type)
|
|
948 {
|
826
|
949 Charbpos ret_charpos;
|
428
|
950 int overlay_width;
|
|
951 struct buffer *b = XBUFFER (WINDOW_BUFFER (w));
|
|
952
|
|
953 /* If our caller hasn't already set the boundaries, then do so now. */
|
|
954 if (!bounds)
|
|
955 dl->bounds = calculate_display_line_boundaries (w, 0);
|
|
956
|
|
957 /* Reset what this line is using. */
|
|
958 if (dl->display_blocks)
|
|
959 Dynarr_reset (dl->display_blocks);
|
|
960 if (dl->left_glyphs)
|
|
961 {
|
|
962 Dynarr_free (dl->left_glyphs);
|
|
963 dl->left_glyphs = 0;
|
|
964 }
|
|
965 if (dl->right_glyphs)
|
|
966 {
|
|
967 Dynarr_free (dl->right_glyphs);
|
|
968 dl->right_glyphs = 0;
|
|
969 }
|
|
970
|
|
971 /* We aren't generating a modeline at the moment. */
|
|
972 dl->modeline = 0;
|
|
973
|
|
974 /* Create a display block for the text region of the line. */
|
|
975 {
|
|
976 /* #### urk urk urk!!! Chuck fix this shit! */
|
665
|
977 Bytebpos hacked_up_bytebpos =
|
|
978 create_text_block (w, dl, charbpos_to_bytebpos (b, start_pos),
|
428
|
979 prop, type);
|
826
|
980 if (hacked_up_bytebpos > BYTE_BUF_ZV (b))
|
|
981 ret_charpos = BUF_ZV (b) + 1;
|
428
|
982 else
|
826
|
983 ret_charpos = bytebpos_to_charbpos (b, hacked_up_bytebpos);
|
428
|
984 }
|
826
|
985 dl->charpos = start_pos;
|
|
986 if (dl->end_charpos < dl->charpos)
|
|
987 dl->end_charpos = dl->charpos;
|
428
|
988
|
|
989 if (MARKERP (Voverlay_arrow_position)
|
|
990 && EQ (w->buffer, Fmarker_buffer (Voverlay_arrow_position))
|
|
991 && start_pos == marker_position (Voverlay_arrow_position)
|
|
992 && (STRINGP (Voverlay_arrow_string)
|
|
993 || GLYPHP (Voverlay_arrow_string)))
|
|
994 {
|
|
995 overlay_width = create_overlay_glyph_block (w, dl);
|
|
996 }
|
|
997 else
|
|
998 overlay_width = 0;
|
|
999
|
|
1000 /* If there are left glyphs associated with any character in the
|
|
1001 text block, then create a display block to handle them. */
|
|
1002 if (dl->left_glyphs != NULL && Dynarr_length (dl->left_glyphs))
|
|
1003 create_left_glyph_block (w, dl, overlay_width);
|
|
1004
|
|
1005 /* If there are right glyphs associated with any character in the
|
|
1006 text block, then create a display block to handle them. */
|
|
1007 if (dl->right_glyphs != NULL && Dynarr_length (dl->right_glyphs))
|
|
1008 create_right_glyph_block (w, dl);
|
|
1009
|
|
1010 /* In the future additional types of display blocks may be generated
|
|
1011 here. */
|
|
1012
|
826
|
1013 w->last_redisplay_pos = ret_charpos;
|
|
1014
|
|
1015 return ret_charpos;
|
428
|
1016 }
|
|
1017
|
|
1018 /* Adds an hscroll glyph to a display block. If this is called, then
|
|
1019 the block had better be empty.
|
|
1020
|
|
1021 Yes, there are multiple places where this function is called but
|
|
1022 that is the way it has to be. Each calling function has to deal
|
826
|
1023 with byte_start_col_enabled a little differently depending on the
|
428
|
1024 object being worked with. */
|
|
1025
|
|
1026 static prop_block_dynarr *
|
|
1027 add_hscroll_rune (pos_data *data)
|
|
1028 {
|
|
1029 struct glyph_block gb;
|
|
1030 prop_block_dynarr *retval;
|
826
|
1031 Bytebpos byte_old_cursor_charpos = data->byte_cursor_charpos;
|
647
|
1032 int old_cursor_type = data->cursor_type;
|
826
|
1033 Bytebpos byte_old_charpos = data->byte_charpos;
|
428
|
1034
|
|
1035 if (data->cursor_type == CURSOR_ON
|
826
|
1036 && data->byte_cursor_charpos >= data->byte_start_col_enabled
|
|
1037 && data->byte_cursor_charpos <= data->byte_charpos)
|
|
1038 {
|
|
1039 data->byte_cursor_charpos = data->byte_start_col_enabled;
|
428
|
1040 }
|
|
1041 else
|
|
1042 {
|
|
1043 data->cursor_type = NO_CURSOR;
|
|
1044 }
|
|
1045
|
826
|
1046 data->byte_endpos = data->byte_charpos;
|
|
1047 data->byte_charpos = data->byte_start_col_enabled;
|
428
|
1048
|
|
1049 gb.extent = Qnil;
|
|
1050 gb.glyph = Vhscroll_glyph;
|
|
1051 {
|
|
1052 int oldpixpos = data->pixpos;
|
442
|
1053 retval = add_glyph_rune (data, &gb, BEGIN_GLYPHS, 0,
|
428
|
1054 GLYPH_CACHEL (XWINDOW (data->window),
|
|
1055 HSCROLL_GLYPH_INDEX));
|
|
1056 data->hscroll_glyph_width_adjust =
|
|
1057 data->pixpos - oldpixpos - space_width (XWINDOW (data->window));
|
|
1058 }
|
826
|
1059 data->byte_endpos = 0;
|
|
1060 data->byte_cursor_charpos = byte_old_cursor_charpos;
|
428
|
1061 data->cursor_type = old_cursor_type;
|
826
|
1062 data->byte_charpos = byte_old_charpos;
|
|
1063
|
|
1064 data->byte_start_col_enabled = 0;
|
428
|
1065 return retval;
|
|
1066 }
|
|
1067
|
793
|
1068 /* Adds a character rune to a display block. If there is not enough room
|
|
1069 to fit the rune on the display block (as determined by the MAX_PIXPOS)
|
|
1070 then it adds nothing and returns ADD_FAILED. If
|
|
1071 NO_CONTRIBUTE_TO_LINE_HEIGHT is non-zero, don't allow the char's height
|
867
|
1072 to affect the total line height. (See add_ibyte_string_runes()). */
|
428
|
1073
|
|
1074 static prop_block_dynarr *
|
867
|
1075 add_ichar_rune_1 (pos_data *data, int no_contribute_to_line_height)
|
428
|
1076 {
|
|
1077 struct rune rb, *crb;
|
|
1078 int width, local;
|
|
1079
|
|
1080 if (data->start_col)
|
|
1081 {
|
|
1082 data->start_col--;
|
|
1083
|
|
1084 if (data->start_col)
|
|
1085 return NULL;
|
|
1086 }
|
|
1087
|
826
|
1088 if (data->byte_start_col_enabled)
|
428
|
1089 {
|
|
1090 return add_hscroll_rune (data);
|
|
1091 }
|
|
1092
|
|
1093 if (data->ch == '\n')
|
|
1094 {
|
|
1095 data->font_is_bogus = 0;
|
|
1096 /* Cheesy end-of-line pseudo-character. */
|
|
1097 width = data->blank_width;
|
|
1098 }
|
|
1099 else
|
|
1100 {
|
867
|
1101 Lisp_Object charset = ichar_charset (data->ch);
|
428
|
1102 if (!EQ (charset, data->last_charset) ||
|
|
1103 data->findex != data->last_findex)
|
|
1104 {
|
|
1105 /* OK, we need to do things the hard way. */
|
|
1106 struct window *w = XWINDOW (data->window);
|
|
1107 struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, data->findex);
|
|
1108 Lisp_Object font_instance =
|
|
1109 ensure_face_cachel_contains_charset (cachel, data->window,
|
|
1110 charset);
|
440
|
1111 Lisp_Font_Instance *fi;
|
428
|
1112
|
|
1113 if (EQ (font_instance, Vthe_null_font_instance))
|
|
1114 {
|
|
1115 font_instance = FACE_CACHEL_FONT (cachel, Vcharset_ascii);
|
|
1116 data->font_is_bogus = 1;
|
|
1117 }
|
|
1118 else
|
|
1119 data->font_is_bogus = 0;
|
|
1120
|
|
1121 fi = XFONT_INSTANCE (font_instance);
|
771
|
1122 if (!fi->proportional_p || data->font_is_bogus)
|
|
1123 {
|
867
|
1124 Ichar ch = data->font_is_bogus ? '~' : data->ch;
|
771
|
1125
|
|
1126 data->last_char_width =
|
867
|
1127 redisplay_text_width_ichar_string (XWINDOW (data->window),
|
771
|
1128 data->findex, &ch, 1);
|
|
1129 }
|
428
|
1130 else
|
|
1131 data->last_char_width = -1;
|
819
|
1132
|
793
|
1133 if (!no_contribute_to_line_height)
|
|
1134 {
|
|
1135 data->new_ascent = max (data->new_ascent, (int) fi->ascent);
|
|
1136 data->new_descent = max (data->new_descent, (int) fi->descent);
|
|
1137 }
|
819
|
1138
|
428
|
1139 data->last_charset = charset;
|
|
1140 data->last_findex = data->findex;
|
|
1141 }
|
|
1142
|
|
1143 width = data->last_char_width;
|
771
|
1144 if (width < 0) /* proportional fonts */
|
867
|
1145 width = redisplay_text_width_ichar_string (XWINDOW (data->window),
|
771
|
1146 data->findex,
|
|
1147 &data->ch, 1);
|
428
|
1148 }
|
|
1149
|
|
1150 if (data->max_pixpos != -1 && (data->pixpos + width > data->max_pixpos))
|
|
1151 {
|
|
1152 return ADD_FAILED;
|
|
1153 }
|
|
1154
|
|
1155 if (Dynarr_length (data->db->runes) < Dynarr_largest (data->db->runes))
|
|
1156 {
|
|
1157 crb = Dynarr_atp (data->db->runes, Dynarr_length (data->db->runes));
|
|
1158 local = 0;
|
|
1159 }
|
|
1160 else
|
|
1161 {
|
|
1162 crb = &rb;
|
|
1163 local = 1;
|
|
1164 }
|
|
1165
|
|
1166 crb->findex = data->findex;
|
|
1167 crb->xpos = data->pixpos;
|
|
1168 crb->width = width;
|
826
|
1169 if (data->byte_charpos)
|
428
|
1170 {
|
|
1171 if (NILP (data->string))
|
826
|
1172 crb->charpos =
|
793
|
1173 bytebpos_to_charbpos (XBUFFER (WINDOW_BUFFER
|
|
1174 (XWINDOW (data->window))),
|
826
|
1175 data->byte_charpos);
|
428
|
1176 else
|
826
|
1177 crb->charpos =
|
|
1178 string_index_byte_to_char (data->string, data->byte_charpos);
|
428
|
1179 }
|
|
1180 else if (data->is_modeline)
|
826
|
1181 crb->charpos = data->modeline_charpos;
|
428
|
1182 else
|
442
|
1183 /* Text but not in buffer */
|
826
|
1184 crb->charpos = 0;
|
428
|
1185 crb->type = RUNE_CHAR;
|
|
1186 crb->object.chr.ch = data->font_is_bogus ? '~' : data->ch;
|
|
1187 crb->endpos = 0;
|
|
1188
|
|
1189 if (data->cursor_type == CURSOR_ON)
|
|
1190 {
|
826
|
1191 if (data->byte_charpos == data->byte_cursor_charpos)
|
428
|
1192 {
|
|
1193 crb->cursor_type = CURSOR_ON;
|
|
1194 data->cursor_x = Dynarr_length (data->db->runes);
|
|
1195 }
|
|
1196 else
|
|
1197 crb->cursor_type = CURSOR_OFF;
|
|
1198 }
|
|
1199 else if (data->cursor_type == NEXT_CURSOR)
|
|
1200 {
|
|
1201 crb->cursor_type = CURSOR_ON;
|
|
1202 data->cursor_x = Dynarr_length (data->db->runes);
|
|
1203 data->cursor_type = NO_CURSOR;
|
|
1204 }
|
|
1205 else if (data->cursor_type == IGNORE_CURSOR)
|
|
1206 crb->cursor_type = IGNORE_CURSOR;
|
|
1207 else
|
|
1208 crb->cursor_type = CURSOR_OFF;
|
|
1209
|
|
1210 if (local)
|
|
1211 Dynarr_add (data->db->runes, *crb);
|
|
1212 else
|
|
1213 Dynarr_increment (data->db->runes);
|
|
1214
|
|
1215 data->pixpos += width;
|
|
1216
|
|
1217 return NULL;
|
|
1218 }
|
|
1219
|
793
|
1220 static prop_block_dynarr *
|
867
|
1221 add_ichar_rune (pos_data *data)
|
|
1222 {
|
|
1223 return add_ichar_rune_1 (data, 0);
|
|
1224 }
|
|
1225
|
|
1226 /* Given a string C_STRING of length C_LENGTH, call add_ichar_rune for
|
793
|
1227 each character in the string. Propagate any left-over data unless
|
|
1228 NO_PROP is non-zero. If NO_CONTRIBUTE_TO_LINE_HEIGHT is non-zero, don't
|
|
1229 allow this character to increase the total height of the line. (This is
|
|
1230 used when the character is part of a text glyph. In that case, the
|
|
1231 glyph code itself adjusts the line height as necessary, depending on
|
|
1232 whether glyph-contrib-p is true.) */
|
428
|
1233
|
|
1234 static prop_block_dynarr *
|
867
|
1235 add_ibyte_string_runes (pos_data *data, Ibyte *c_string,
|
793
|
1236 Bytecount c_length, int no_prop,
|
|
1237 int no_contribute_to_line_height)
|
428
|
1238 {
|
867
|
1239 Ibyte *pos, *end = c_string + c_length;
|
428
|
1240 prop_block_dynarr *prop;
|
|
1241
|
|
1242 /* #### This function is too simplistic. It needs to do the same
|
|
1243 sort of character interpretation (display-table lookup,
|
|
1244 ctl-arrow checking), etc. that create_text_block() does.
|
|
1245 The functionality to do this in that routine needs to be
|
|
1246 modularized. */
|
|
1247
|
|
1248 for (pos = c_string; pos < end;)
|
|
1249 {
|
867
|
1250 Ibyte *old_pos = pos;
|
|
1251
|
|
1252 data->ch = itext_ichar (pos);
|
|
1253
|
|
1254 prop = add_ichar_rune_1 (data, no_contribute_to_line_height);
|
428
|
1255
|
|
1256 if (prop)
|
|
1257 {
|
|
1258 if (no_prop)
|
|
1259 return ADD_FAILED;
|
|
1260 else
|
|
1261 {
|
|
1262 struct prop_block pb;
|
|
1263 Bytecount len = end - pos;
|
|
1264 prop = Dynarr_new (prop_block);
|
|
1265
|
|
1266 pb.type = PROP_STRING;
|
867
|
1267 pb.data.p_string.str = xnew_array (Ibyte, len);
|
428
|
1268 strncpy ((char *) pb.data.p_string.str, (char *) pos, len);
|
|
1269 pb.data.p_string.len = len;
|
|
1270
|
|
1271 Dynarr_add (prop, pb);
|
|
1272 return prop;
|
|
1273 }
|
|
1274 }
|
867
|
1275 INC_IBYTEPTR (pos);
|
428
|
1276 assert (pos <= end);
|
464
|
1277 /* #### Duplicate code from add_string_to_fstring_db_runes
|
|
1278 should we do more?*/
|
|
1279 data->bytepos += pos - old_pos;
|
428
|
1280 }
|
|
1281
|
|
1282 return NULL;
|
|
1283 }
|
|
1284
|
|
1285 /* Add a single rune of the specified width. The area covered by this
|
|
1286 rune will be displayed in the foreground color of the associated
|
|
1287 face. */
|
|
1288
|
|
1289 static prop_block_dynarr *
|
|
1290 add_blank_rune (pos_data *data, struct window *w, int char_tab_width)
|
|
1291 {
|
|
1292 struct rune rb;
|
|
1293
|
|
1294 /* If data->start_col is not 0 then this call to add_blank_rune must have
|
|
1295 been to add it as a tab. */
|
|
1296 if (data->start_col)
|
|
1297 {
|
|
1298 /* assert (w != NULL) */
|
|
1299 prop_block_dynarr *retval;
|
|
1300
|
|
1301 /* If we have still not fully scrolled horizontally, subtract
|
|
1302 the width of this tab and return. */
|
|
1303 if (char_tab_width < data->start_col)
|
|
1304 {
|
|
1305 data->start_col -= char_tab_width;
|
|
1306 return NULL;
|
|
1307 }
|
|
1308 else if (char_tab_width == data->start_col)
|
|
1309 data->blank_width = 0;
|
|
1310 else
|
|
1311 {
|
|
1312 int spcwid = space_width (w);
|
|
1313
|
|
1314 if (spcwid >= data->blank_width)
|
|
1315 data->blank_width = 0;
|
|
1316 else
|
|
1317 data->blank_width -= spcwid;
|
|
1318 }
|
|
1319
|
|
1320 data->start_col = 0;
|
|
1321 retval = add_hscroll_rune (data);
|
|
1322
|
|
1323 /* Could be caused by the handling of the hscroll rune. */
|
|
1324 if (retval != NULL || !data->blank_width)
|
|
1325 return retval;
|
|
1326 }
|
|
1327
|
|
1328 /* Blank runes are always calculated to fit. */
|
|
1329 assert (data->pixpos + data->blank_width <= data->max_pixpos);
|
|
1330
|
|
1331 rb.findex = data->findex;
|
|
1332 rb.xpos = data->pixpos;
|
|
1333 rb.width = data->blank_width;
|
826
|
1334 if (data->byte_charpos)
|
|
1335 rb.charpos =
|
665
|
1336 bytebpos_to_charbpos (XBUFFER (WINDOW_BUFFER (XWINDOW (data->window))),
|
826
|
1337 data->byte_charpos);
|
428
|
1338 else
|
|
1339 /* #### and this is really correct too? */
|
826
|
1340 rb.charpos = 0;
|
428
|
1341 rb.endpos = 0;
|
|
1342 rb.type = RUNE_BLANK;
|
|
1343
|
|
1344 if (data->cursor_type == CURSOR_ON)
|
|
1345 {
|
826
|
1346 if (data->byte_charpos == data->byte_cursor_charpos)
|
428
|
1347 {
|
|
1348 rb.cursor_type = CURSOR_ON;
|
|
1349 data->cursor_x = Dynarr_length (data->db->runes);
|
|
1350 }
|
|
1351 else
|
|
1352 rb.cursor_type = CURSOR_OFF;
|
|
1353 }
|
|
1354 else if (data->cursor_type == NEXT_CURSOR)
|
|
1355 {
|
|
1356 rb.cursor_type = CURSOR_ON;
|
|
1357 data->cursor_x = Dynarr_length (data->db->runes);
|
|
1358 data->cursor_type = NO_CURSOR;
|
|
1359 }
|
|
1360 else
|
|
1361 rb.cursor_type = CURSOR_OFF;
|
|
1362
|
|
1363 Dynarr_add (data->db->runes, rb);
|
|
1364 data->pixpos += data->blank_width;
|
|
1365
|
|
1366 return NULL;
|
|
1367 }
|
|
1368
|
|
1369 /* Add runes representing a character in octal. */
|
|
1370
|
|
1371 #define ADD_NEXT_OCTAL_RUNE_CHAR do \
|
|
1372 { \
|
867
|
1373 if (add_failed || (add_failed = add_ichar_rune (data))) \
|
428
|
1374 { \
|
|
1375 struct prop_block pb; \
|
|
1376 if (!prop) \
|
|
1377 prop = Dynarr_new (prop_block); \
|
|
1378 \
|
|
1379 pb.type = PROP_CHAR; \
|
|
1380 pb.data.p_char.ch = data->ch; \
|
|
1381 pb.data.p_char.cursor_type = data->cursor_type; \
|
|
1382 Dynarr_add (prop, pb); \
|
|
1383 } \
|
|
1384 } while (0)
|
|
1385
|
|
1386 static prop_block_dynarr *
|
|
1387 add_octal_runes (pos_data *data)
|
|
1388 {
|
819
|
1389 prop_block_dynarr *add_failed, *prop = 0;
|
867
|
1390 Ichar orig_char = data->ch;
|
647
|
1391 int orig_cursor_type = data->cursor_type;
|
428
|
1392
|
|
1393 /* Initialize */
|
|
1394 add_failed = NULL;
|
|
1395
|
|
1396 if (data->start_col)
|
|
1397 data->start_col--;
|
|
1398
|
|
1399 if (!data->start_col)
|
|
1400 {
|
826
|
1401 if (data->byte_start_col_enabled)
|
428
|
1402 {
|
|
1403 add_failed = add_hscroll_rune (data);
|
|
1404 }
|
|
1405 else
|
|
1406 {
|
|
1407 struct glyph_block gb;
|
|
1408 struct window *w = XWINDOW (data->window);
|
|
1409
|
|
1410 gb.extent = Qnil;
|
|
1411 gb.glyph = Voctal_escape_glyph;
|
|
1412 add_failed =
|
|
1413 add_glyph_rune (data, &gb, BEGIN_GLYPHS, 1,
|
|
1414 GLYPH_CACHEL (w, OCT_ESC_GLYPH_INDEX));
|
|
1415 }
|
|
1416 }
|
|
1417
|
|
1418 /* We only propagate information if the glyph was partially
|
|
1419 added. */
|
|
1420 if (add_failed)
|
|
1421 return add_failed;
|
|
1422
|
|
1423 data->cursor_type = IGNORE_CURSOR;
|
|
1424
|
|
1425 if (data->ch >= 0x100)
|
|
1426 {
|
|
1427 /* If the character is an extended Mule character, it could have
|
|
1428 up to 19 bits. For the moment, we treat it as a seven-digit
|
|
1429 octal number. This is not that pretty, but whatever. */
|
|
1430 data->ch = (7 & (orig_char >> 18)) + '0';
|
|
1431 ADD_NEXT_OCTAL_RUNE_CHAR;
|
|
1432
|
|
1433 data->ch = (7 & (orig_char >> 15)) + '0';
|
|
1434 ADD_NEXT_OCTAL_RUNE_CHAR;
|
|
1435
|
|
1436 data->ch = (7 & (orig_char >> 12)) + '0';
|
|
1437 ADD_NEXT_OCTAL_RUNE_CHAR;
|
|
1438
|
|
1439 data->ch = (7 & (orig_char >> 9)) + '0';
|
|
1440 ADD_NEXT_OCTAL_RUNE_CHAR;
|
|
1441 }
|
|
1442
|
|
1443 data->ch = (7 & (orig_char >> 6)) + '0';
|
|
1444 ADD_NEXT_OCTAL_RUNE_CHAR;
|
|
1445
|
|
1446 data->ch = (7 & (orig_char >> 3)) + '0';
|
|
1447 ADD_NEXT_OCTAL_RUNE_CHAR;
|
|
1448
|
|
1449 data->ch = (7 & orig_char) + '0';
|
|
1450 ADD_NEXT_OCTAL_RUNE_CHAR;
|
|
1451
|
|
1452 data->cursor_type = orig_cursor_type;
|
819
|
1453 return NULL;
|
428
|
1454 }
|
|
1455
|
|
1456 #undef ADD_NEXT_OCTAL_RUNE_CHAR
|
|
1457
|
|
1458 /* Add runes representing a control character to a display block. */
|
|
1459
|
|
1460 static prop_block_dynarr *
|
|
1461 add_control_char_runes (pos_data *data, struct buffer *b)
|
|
1462 {
|
|
1463 if (!NILP (b->ctl_arrow))
|
|
1464 {
|
|
1465 prop_block_dynarr *prop;
|
867
|
1466 Ichar orig_char = data->ch;
|
647
|
1467 int old_cursor_type = data->cursor_type;
|
428
|
1468
|
|
1469 /* Initialize */
|
|
1470 prop = NULL;
|
|
1471
|
|
1472 if (data->start_col)
|
|
1473 data->start_col--;
|
|
1474
|
|
1475 if (!data->start_col)
|
|
1476 {
|
826
|
1477 if (data->byte_start_col_enabled)
|
428
|
1478 {
|
|
1479 prop_block_dynarr *retval;
|
|
1480
|
|
1481 retval = add_hscroll_rune (data);
|
|
1482 if (retval)
|
|
1483 return retval;
|
|
1484 }
|
|
1485 else
|
|
1486 {
|
|
1487 struct glyph_block gb;
|
|
1488 struct window *w = XWINDOW (data->window);
|
|
1489
|
|
1490 gb.extent = Qnil;
|
|
1491 gb.glyph = Vcontrol_arrow_glyph;
|
|
1492
|
|
1493 /* We only propagate information if the glyph was partially
|
|
1494 added. */
|
|
1495 if (add_glyph_rune (data, &gb, BEGIN_GLYPHS, 1,
|
|
1496 GLYPH_CACHEL (w, CONTROL_GLYPH_INDEX)))
|
|
1497 return ADD_FAILED;
|
|
1498 }
|
|
1499 }
|
|
1500
|
|
1501 if (orig_char == 0177)
|
|
1502 data->ch = '?';
|
|
1503 else
|
|
1504 data->ch = orig_char ^ 0100;
|
|
1505 data->cursor_type = IGNORE_CURSOR;
|
|
1506
|
867
|
1507 if (add_ichar_rune (data))
|
428
|
1508 {
|
|
1509 struct prop_block pb;
|
|
1510 if (!prop)
|
|
1511 prop = Dynarr_new (prop_block);
|
|
1512
|
|
1513 pb.type = PROP_CHAR;
|
|
1514 pb.data.p_char.ch = data->ch;
|
|
1515 pb.data.p_char.cursor_type = data->cursor_type;
|
|
1516 Dynarr_add (prop, pb);
|
|
1517 }
|
|
1518
|
|
1519 data->cursor_type = old_cursor_type;
|
|
1520 return prop;
|
|
1521 }
|
|
1522 else
|
|
1523 {
|
|
1524 return add_octal_runes (data);
|
|
1525 }
|
|
1526 }
|
|
1527
|
|
1528 static prop_block_dynarr *
|
|
1529 add_disp_table_entry_runes_1 (pos_data *data, Lisp_Object entry)
|
|
1530 {
|
|
1531 prop_block_dynarr *prop = NULL;
|
|
1532
|
|
1533 if (STRINGP (entry))
|
|
1534 {
|
867
|
1535 prop = add_ibyte_string_runes (data,
|
428
|
1536 XSTRING_DATA (entry),
|
|
1537 XSTRING_LENGTH (entry),
|
793
|
1538 0, 0);
|
428
|
1539 }
|
|
1540 else if (GLYPHP (entry))
|
|
1541 {
|
|
1542 if (data->start_col)
|
|
1543 data->start_col--;
|
|
1544
|
826
|
1545 if (!data->start_col && data->byte_start_col_enabled)
|
428
|
1546 {
|
|
1547 prop = add_hscroll_rune (data);
|
|
1548 }
|
|
1549 else
|
|
1550 {
|
|
1551 struct glyph_block gb;
|
|
1552
|
|
1553 gb.glyph = entry;
|
|
1554 gb.extent = Qnil;
|
|
1555 prop = add_glyph_rune (data, &gb, BEGIN_GLYPHS, 0, 0);
|
|
1556 }
|
|
1557 }
|
|
1558 else if (CHAR_OR_CHAR_INTP (entry))
|
|
1559 {
|
|
1560 data->ch = XCHAR_OR_CHAR_INT (entry);
|
867
|
1561 prop = add_ichar_rune (data);
|
428
|
1562 }
|
|
1563 else if (CONSP (entry))
|
|
1564 {
|
|
1565 if (EQ (XCAR (entry), Qformat)
|
|
1566 && CONSP (XCDR (entry))
|
|
1567 && STRINGP (XCAR (XCDR (entry))))
|
|
1568 {
|
|
1569 Lisp_Object format = XCAR (XCDR (entry));
|
665
|
1570 Bytebpos len = XSTRING_LENGTH (format);
|
867
|
1571 Ibyte *src = XSTRING_DATA (format), *end = src + len;
|
2367
|
1572 Ibyte *result = alloca_ibytes (len);
|
867
|
1573 Ibyte *dst = result;
|
428
|
1574
|
|
1575 while (src < end)
|
|
1576 {
|
867
|
1577 Ichar c = itext_ichar (src);
|
|
1578 INC_IBYTEPTR (src);
|
428
|
1579 if (c != '%' || src == end)
|
867
|
1580 dst += set_itext_ichar (dst, c);
|
428
|
1581 else
|
|
1582 {
|
867
|
1583 c = itext_ichar (src);
|
|
1584 INC_IBYTEPTR (src);
|
428
|
1585 switch (c)
|
|
1586 {
|
|
1587 /*case 'x':
|
|
1588 dst += long_to_string_base ((char *)dst, data->ch, 16);
|
|
1589 break;*/
|
|
1590 case '%':
|
867
|
1591 dst += set_itext_ichar (dst, '%');
|
428
|
1592 break;
|
442
|
1593 /* #### unimplemented */
|
428
|
1594 }
|
|
1595 }
|
|
1596 }
|
867
|
1597 prop = add_ibyte_string_runes (data, result, dst - result, 0, 0);
|
428
|
1598 }
|
|
1599 }
|
|
1600
|
|
1601 /* Else blow it off because someone added a bad entry and we don't
|
|
1602 have any safe way of signaling an error. */
|
|
1603 return prop;
|
|
1604 }
|
|
1605
|
|
1606 /* Given a display table entry, call the appropriate functions to
|
|
1607 display each element of the entry. */
|
|
1608
|
|
1609 static prop_block_dynarr *
|
|
1610 add_disp_table_entry_runes (pos_data *data, Lisp_Object entry)
|
|
1611 {
|
|
1612 prop_block_dynarr *prop = NULL;
|
|
1613 if (VECTORP (entry))
|
|
1614 {
|
440
|
1615 Lisp_Vector *de = XVECTOR (entry);
|
428
|
1616 EMACS_INT len = vector_length (de);
|
|
1617 int elt;
|
|
1618
|
|
1619 for (elt = 0; elt < len; elt++)
|
|
1620 {
|
|
1621 if (NILP (vector_data (de)[elt]))
|
|
1622 continue;
|
|
1623 else
|
|
1624 prop = add_disp_table_entry_runes_1 (data, vector_data (de)[elt]);
|
|
1625 /* Else blow it off because someone added a bad entry and we
|
|
1626 don't have any safe way of signaling an error. Hey, this
|
|
1627 comment sounds familiar. */
|
|
1628
|
|
1629 /* #### Still need to add any remaining elements to the
|
|
1630 propagation information. */
|
|
1631 if (prop)
|
|
1632 return prop;
|
|
1633 }
|
|
1634 }
|
|
1635 else
|
|
1636 prop = add_disp_table_entry_runes_1 (data, entry);
|
|
1637 return prop;
|
|
1638 }
|
|
1639
|
|
1640 /* Add runes which were propagated from the previous line. */
|
|
1641
|
|
1642 static prop_block_dynarr *
|
|
1643 add_propagation_runes (prop_block_dynarr **prop, pos_data *data)
|
|
1644 {
|
|
1645 /* #### Remember to handle start_col parameter of data when the rest of
|
|
1646 this is finished. */
|
|
1647 /* #### Chuck -- I've redone this function a bit. It looked like the
|
|
1648 case of not all the propagation blocks being added was not handled
|
|
1649 well. */
|
|
1650 /* #### Chuck -- I also think the double indirection of PROP is kind
|
|
1651 of bogus. A cleaner solution is just to check for
|
|
1652 Dynarr_length (prop) > 0. */
|
|
1653 /* #### This function also doesn't even pay attention to ADD_FAILED!
|
|
1654 This is seriously fucked! Seven ####'s in 130 lines -- is that a
|
|
1655 record? */
|
|
1656 int elt;
|
|
1657 prop_block_dynarr *add_failed;
|
826
|
1658 Bytebpos byte_old_cursor_charpos = data->byte_cursor_charpos;
|
647
|
1659 int old_cursor_type = data->cursor_type;
|
428
|
1660
|
|
1661 for (elt = 0; elt < Dynarr_length (*prop); elt++)
|
|
1662 {
|
|
1663 struct prop_block *pb = Dynarr_atp (*prop, elt);
|
|
1664
|
|
1665 switch (pb->type)
|
|
1666 {
|
|
1667 case PROP_CHAR:
|
|
1668 data->ch = pb->data.p_char.ch;
|
826
|
1669 data->byte_cursor_charpos = pb->data.p_char.byte_cursor_charpos;
|
428
|
1670 data->cursor_type = pb->data.p_char.cursor_type;
|
867
|
1671 add_failed = add_ichar_rune (data);
|
428
|
1672
|
|
1673 if (add_failed)
|
|
1674 goto oops_no_more_space;
|
|
1675 break;
|
|
1676 case PROP_STRING:
|
|
1677 if (pb->data.p_string.str)
|
1726
|
1678 xfree (pb->data.p_string.str, Ibyte *);
|
428
|
1679 /* #### bogus bogus -- this doesn't do anything!
|
867
|
1680 Should probably call add_ibyte_string_runes(),
|
428
|
1681 once that function is fixed. */
|
|
1682 break;
|
|
1683 case PROP_MINIBUF_PROMPT:
|
|
1684 {
|
|
1685 face_index old_findex = data->findex;
|
826
|
1686 Bytebpos byte_old_charpos = data->byte_charpos;
|
428
|
1687
|
|
1688 data->findex = DEFAULT_INDEX;
|
826
|
1689 data->byte_charpos = 0;
|
428
|
1690 data->cursor_type = NO_CURSOR;
|
|
1691
|
|
1692 while (pb->data.p_string.len > 0)
|
|
1693 {
|
867
|
1694 data->ch = itext_ichar (pb->data.p_string.str);
|
|
1695 add_failed = add_ichar_rune (data);
|
428
|
1696
|
|
1697 if (add_failed)
|
|
1698 {
|
|
1699 data->findex = old_findex;
|
826
|
1700 data->byte_charpos = byte_old_charpos;
|
428
|
1701 goto oops_no_more_space;
|
|
1702 }
|
|
1703 else
|
|
1704 {
|
|
1705 /* Complicated equivalent of ptr++, len-- */
|
867
|
1706 Ibyte *oldpos = pb->data.p_string.str;
|
|
1707 INC_IBYTEPTR (pb->data.p_string.str);
|
428
|
1708 pb->data.p_string.len -= pb->data.p_string.str - oldpos;
|
|
1709 }
|
|
1710 }
|
|
1711
|
|
1712 data->findex = old_findex;
|
|
1713 /* ##### FIXME FIXME FIXME -- Upon successful return from
|
826
|
1714 this function, data->byte_charpos is automatically incremented.
|
428
|
1715 However, we don't want that to happen if we were adding
|
|
1716 the minibuffer prompt. */
|
|
1717 {
|
|
1718 struct buffer *buf =
|
|
1719 XBUFFER (WINDOW_BUFFER (XWINDOW (data->window)));
|
|
1720 /* #### Chuck fix this shit or I'm gonna scream! */
|
826
|
1721 if (byte_old_charpos > BYTE_BUF_BEGV (buf))
|
|
1722 data->byte_charpos = prev_bytebpos (buf, byte_old_charpos);
|
428
|
1723 else
|
|
1724 /* #### is this correct? Does anyone know?
|
|
1725 Does anyone care? Is this a cheesy hack or what? */
|
826
|
1726 data->byte_charpos = BYTE_BUF_BEGV (buf) - 1;
|
428
|
1727 }
|
|
1728 }
|
|
1729 break;
|
|
1730 case PROP_BLANK:
|
|
1731 {
|
|
1732 /* #### I think it's unnecessary and misleading to preserve
|
|
1733 the blank_width, as it implies that the value carries
|
|
1734 over from one rune to the next, which is wrong. */
|
|
1735 int old_width = data->blank_width;
|
|
1736 face_index old_findex = data->findex;
|
|
1737
|
|
1738 data->findex = pb->data.p_blank.findex;
|
|
1739 data->blank_width = pb->data.p_blank.width;
|
826
|
1740 data->byte_cursor_charpos = 0;
|
428
|
1741 data->cursor_type = IGNORE_CURSOR;
|
|
1742
|
|
1743 if (data->pixpos + data->blank_width > data->max_pixpos)
|
|
1744 data->blank_width = data->max_pixpos - data->pixpos;
|
|
1745
|
|
1746 /* We pass a bogus value of char_tab_width. It shouldn't
|
|
1747 matter because unless something is really screwed up
|
|
1748 this call won't cause that arg to be used. */
|
|
1749 add_failed = add_blank_rune (data, XWINDOW (data->window), 0);
|
|
1750
|
|
1751 /* This can happen in the case where we have a tab which
|
|
1752 is wider than the window. */
|
|
1753 if (data->blank_width != pb->data.p_blank.width)
|
|
1754 {
|
|
1755 pb->data.p_blank.width -= data->blank_width;
|
|
1756 add_failed = ADD_FAILED;
|
|
1757 }
|
|
1758
|
|
1759 data->findex = old_findex;
|
|
1760 data->blank_width = old_width;
|
|
1761
|
|
1762 if (add_failed)
|
|
1763 goto oops_no_more_space;
|
|
1764 }
|
|
1765 break;
|
|
1766 default:
|
2500
|
1767 ABORT ();
|
428
|
1768 }
|
|
1769 }
|
|
1770
|
|
1771 oops_no_more_space:
|
|
1772
|
826
|
1773 data->byte_cursor_charpos = byte_old_cursor_charpos;
|
428
|
1774 data->cursor_type = old_cursor_type;
|
|
1775 if (elt < Dynarr_length (*prop))
|
|
1776 {
|
|
1777 Dynarr_delete_many (*prop, 0, elt);
|
|
1778 return *prop;
|
|
1779 }
|
|
1780 else
|
|
1781 {
|
|
1782 Dynarr_free (*prop);
|
|
1783 return NULL;
|
|
1784 }
|
|
1785 }
|
|
1786
|
3025
|
1787 /* Add `text' layout glyphs at position POS_TYPE that are contained to
|
428
|
1788 the display block, but add all other types to the appropriate list
|
|
1789 of the display line. They will be added later by different
|
|
1790 routines. */
|
|
1791
|
|
1792 static prop_block_dynarr *
|
|
1793 add_glyph_rune (pos_data *data, struct glyph_block *gb, int pos_type,
|
|
1794 int allow_cursor, struct glyph_cachel *cachel)
|
|
1795 {
|
|
1796 struct window *w = XWINDOW (data->window);
|
|
1797
|
440
|
1798 /* If window faces changed, and glyph instance is text, then
|
|
1799 glyph sizes might have changed too */
|
|
1800 invalidate_glyph_geometry_maybe (gb->glyph, w);
|
|
1801
|
442
|
1802 /* This makes sure the glyph is in the cachels.
|
|
1803
|
|
1804 #### We do this to make sure the glyph is in the glyph cachels,
|
|
1805 so that the dirty flag can be reset after redisplay has
|
|
1806 finished. We should do this some other way, maybe by iterating
|
|
1807 over the window cache of subwindows. */
|
|
1808 get_glyph_cachel_index (w, gb->glyph);
|
|
1809
|
428
|
1810 /* A nil extent indicates a special glyph (ex. truncator). */
|
|
1811 if (NILP (gb->extent)
|
|
1812 || (pos_type == BEGIN_GLYPHS &&
|
|
1813 extent_begin_glyph_layout (XEXTENT (gb->extent)) == GL_TEXT)
|
|
1814 || (pos_type == END_GLYPHS &&
|
442
|
1815 extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_TEXT)
|
|
1816 || pos_type == LEFT_GLYPHS || pos_type == RIGHT_GLYPHS)
|
428
|
1817 {
|
|
1818 struct rune rb;
|
|
1819 int width;
|
|
1820 int xoffset = 0;
|
|
1821 int ascent, descent;
|
|
1822 Lisp_Object baseline;
|
|
1823 Lisp_Object face;
|
442
|
1824 Lisp_Object instance;
|
|
1825 face_index findex;
|
819
|
1826 prop_block_dynarr *retval = 0;
|
428
|
1827
|
|
1828 if (cachel)
|
|
1829 width = cachel->width;
|
|
1830 else
|
438
|
1831 width = glyph_width (gb->glyph, data->window);
|
428
|
1832
|
|
1833 if (!width)
|
|
1834 return NULL;
|
|
1835
|
|
1836 if (data->start_col || data->start_col_xoffset)
|
|
1837 {
|
|
1838 int glyph_char_width = width / space_width (w);
|
|
1839
|
|
1840 /* If we still have not fully scrolled horizontally after
|
|
1841 taking into account the width of the glyph, subtract its
|
|
1842 width and return. */
|
|
1843 if (glyph_char_width < data->start_col)
|
|
1844 {
|
|
1845 data->start_col -= glyph_char_width;
|
|
1846 return NULL;
|
|
1847 }
|
|
1848 else if (glyph_char_width == data->start_col)
|
|
1849 width = 0;
|
|
1850 else
|
|
1851 {
|
|
1852 xoffset = space_width (w) * data->start_col;
|
|
1853 width -= xoffset;
|
|
1854
|
|
1855 /* #### Can this happen? */
|
|
1856 if (width < 0)
|
|
1857 width = 0;
|
|
1858 }
|
|
1859
|
|
1860 data->start_col = 0;
|
|
1861 retval = add_hscroll_rune (data);
|
|
1862
|
|
1863 /* Could be caused by the handling of the hscroll rune. */
|
|
1864 if (retval != NULL || !width)
|
|
1865 return retval;
|
|
1866 }
|
|
1867 else
|
|
1868 xoffset = 0;
|
|
1869
|
|
1870 if (data->pixpos + width > data->max_pixpos)
|
|
1871 {
|
|
1872 /* If this is the first object we are attempting to add to
|
819
|
1873 the line then we ignore the horizontal_clip threshold.
|
|
1874 Otherwise we will loop until the bottom of the window
|
|
1875 continually failing to add this glyph because it is wider
|
|
1876 than the window. We could alternatively just completely
|
|
1877 ignore the glyph and proceed from there but I think that
|
|
1878 this is a better solution.
|
|
1879
|
|
1880 This does, however, create a different problem in that we
|
|
1881 can end up adding the object to every single line, never
|
|
1882 getting any further - for instance an extent with a long
|
|
1883 start-glyph that covers multitple following
|
|
1884 characters. */
|
428
|
1885 if (Dynarr_length (data->db->runes)
|
|
1886 && data->max_pixpos - data->pixpos < horizontal_clip)
|
|
1887 return ADD_FAILED;
|
819
|
1888 else {
|
|
1889 struct prop_block pb;
|
|
1890
|
|
1891 /* We need to account for the width of the end-of-line
|
|
1892 glyph if there is nothing more in the line to display,
|
|
1893 since we will not display it in this instance. It seems
|
|
1894 kind of gross doing it here, but otherwise we have to
|
|
1895 search the runes in create_text_block(). */
|
|
1896 if (data->ch == '\n')
|
|
1897 data->max_pixpos += data->end_glyph_width;
|
428
|
1898 width = data->max_pixpos - data->pixpos;
|
819
|
1899 /* Add the glyph we are displaying, but clipping, to the
|
|
1900 propagation data so that we don't try and do it
|
|
1901 again. */
|
|
1902 retval = Dynarr_new (prop_block);
|
|
1903 pb.type = PROP_GLYPH;
|
|
1904 pb.data.p_glyph.glyph = gb->glyph;
|
|
1905 pb.data.p_glyph.width = width;
|
|
1906 Dynarr_add (retval, pb);
|
|
1907 }
|
428
|
1908 }
|
|
1909
|
|
1910 if (cachel)
|
|
1911 {
|
|
1912 ascent = cachel->ascent;
|
|
1913 descent = cachel->descent;
|
|
1914 }
|
|
1915 else
|
|
1916 {
|
438
|
1917 ascent = glyph_ascent (gb->glyph, data->window);
|
|
1918 descent = glyph_descent (gb->glyph, data->window);
|
428
|
1919 }
|
|
1920
|
|
1921 baseline = glyph_baseline (gb->glyph, data->window);
|
|
1922
|
819
|
1923 rb.object.dglyph.descent = 0; /* Gets reset lower down, if it is known. */
|
|
1924
|
428
|
1925 if (glyph_contrib_p (gb->glyph, data->window))
|
|
1926 {
|
|
1927 /* A pixmap that has not had a baseline explicitly set. Its
|
|
1928 contribution will be determined later. */
|
|
1929 if (NILP (baseline))
|
|
1930 {
|
|
1931 int height = ascent + descent;
|
819
|
1932 data->need_baseline_computation = 1;
|
428
|
1933 data->max_pixmap_height = max (data->max_pixmap_height, height);
|
|
1934 }
|
|
1935
|
|
1936 /* A string so determine contribution normally. */
|
|
1937 else if (EQ (baseline, Qt))
|
|
1938 {
|
|
1939 data->new_ascent = max (data->new_ascent, ascent);
|
|
1940 data->new_descent = max (data->new_descent, descent);
|
|
1941 }
|
|
1942
|
|
1943 /* A pixmap with an explicitly set baseline. We determine the
|
|
1944 contribution here. */
|
|
1945 else if (INTP (baseline))
|
|
1946 {
|
|
1947 int height = ascent + descent;
|
|
1948 int pix_ascent, pix_descent;
|
|
1949
|
|
1950 pix_ascent = height * XINT (baseline) / 100;
|
|
1951 pix_descent = height - pix_ascent;
|
|
1952
|
|
1953 data->new_ascent = max (data->new_ascent, pix_ascent);
|
|
1954 data->new_descent = max (data->new_descent, pix_descent);
|
819
|
1955 data->max_pixmap_height = max (data->max_pixmap_height, height);
|
|
1956
|
|
1957 rb.object.dglyph.descent = pix_descent;
|
428
|
1958 }
|
|
1959
|
|
1960 /* Otherwise something is screwed up. */
|
|
1961 else
|
2500
|
1962 ABORT ();
|
428
|
1963 }
|
|
1964
|
|
1965 face = glyph_face (gb->glyph, data->window);
|
|
1966 if (NILP (face))
|
442
|
1967 findex = data->findex;
|
428
|
1968 else
|
442
|
1969 findex = get_builtin_face_cache_index (w, face);
|
|
1970
|
|
1971 instance = glyph_image_instance (gb->glyph, data->window,
|
793
|
1972 ERROR_ME_DEBUG_WARN, 1);
|
442
|
1973 if (TEXT_IMAGE_INSTANCEP (instance))
|
|
1974 {
|
|
1975 Lisp_Object string = XIMAGE_INSTANCE_TEXT_STRING (instance);
|
|
1976 face_index orig_findex = data->findex;
|
826
|
1977 Bytebpos orig_charpos = data->byte_charpos;
|
|
1978 Bytebpos orig_start_col_enabled = data->byte_start_col_enabled;
|
442
|
1979
|
|
1980 data->findex = findex;
|
826
|
1981 data->byte_start_col_enabled = 0;
|
442
|
1982 if (!allow_cursor)
|
826
|
1983 data->byte_charpos = 0;
|
867
|
1984 add_ibyte_string_runes (data, XSTRING_DATA (string),
|
793
|
1985 XSTRING_LENGTH (string), 0, 1);
|
442
|
1986 data->findex = orig_findex;
|
826
|
1987 data->byte_charpos = orig_charpos;
|
|
1988 data->byte_start_col_enabled = orig_start_col_enabled;
|
819
|
1989 return retval;
|
442
|
1990 }
|
|
1991
|
|
1992 rb.findex = findex;
|
428
|
1993 rb.xpos = data->pixpos;
|
|
1994 rb.width = width;
|
826
|
1995 rb.charpos = 0; /* glyphs are never "at" anywhere */
|
|
1996 if (data->byte_endpos)
|
428
|
1997 /* #### is this necessary at all? */
|
665
|
1998 rb.endpos = bytebpos_to_charbpos (XBUFFER (WINDOW_BUFFER (w)),
|
826
|
1999 data->byte_endpos);
|
428
|
2000 else
|
|
2001 rb.endpos = 0;
|
|
2002 rb.type = RUNE_DGLYPH;
|
|
2003 rb.object.dglyph.glyph = gb->glyph;
|
|
2004 rb.object.dglyph.extent = gb->extent;
|
|
2005 rb.object.dglyph.xoffset = xoffset;
|
819
|
2006 rb.object.dglyph.ascent = ascent;
|
|
2007 rb.object.dglyph.yoffset = 0; /* Until we know better, assume that it has
|
|
2008 a normal (textual) baseline. */
|
428
|
2009
|
|
2010 if (allow_cursor)
|
|
2011 {
|
826
|
2012 rb.charpos = bytebpos_to_charbpos (XBUFFER (WINDOW_BUFFER (w)),
|
|
2013 data->byte_charpos);
|
428
|
2014
|
|
2015 if (data->cursor_type == CURSOR_ON)
|
|
2016 {
|
826
|
2017 if (data->byte_charpos == data->byte_cursor_charpos)
|
428
|
2018 {
|
|
2019 rb.cursor_type = CURSOR_ON;
|
|
2020 data->cursor_x = Dynarr_length (data->db->runes);
|
|
2021 }
|
|
2022 else
|
|
2023 rb.cursor_type = CURSOR_OFF;
|
|
2024 }
|
|
2025 else if (data->cursor_type == NEXT_CURSOR)
|
|
2026 {
|
|
2027 rb.cursor_type = CURSOR_ON;
|
|
2028 data->cursor_x = Dynarr_length (data->db->runes);
|
|
2029 data->cursor_type = NO_CURSOR;
|
|
2030 }
|
|
2031 else if (data->cursor_type == IGNORE_CURSOR)
|
|
2032 rb.cursor_type = IGNORE_CURSOR;
|
|
2033 else if (data->cursor_type == NO_CURSOR)
|
|
2034 rb.cursor_type = NO_CURSOR;
|
|
2035 else
|
|
2036 rb.cursor_type = CURSOR_OFF;
|
|
2037 }
|
|
2038 else
|
|
2039 rb.cursor_type = CURSOR_OFF;
|
|
2040
|
|
2041 Dynarr_add (data->db->runes, rb);
|
|
2042 data->pixpos += width;
|
|
2043
|
819
|
2044 return retval;
|
428
|
2045 }
|
|
2046 else
|
|
2047 {
|
|
2048 if (!NILP (glyph_face (gb->glyph, data->window)))
|
|
2049 gb->findex =
|
|
2050 get_builtin_face_cache_index (w, glyph_face (gb->glyph,
|
|
2051 data->window));
|
|
2052 else
|
|
2053 gb->findex = data->findex;
|
|
2054
|
|
2055 if (pos_type == BEGIN_GLYPHS)
|
|
2056 {
|
|
2057 if (!data->dl->left_glyphs)
|
|
2058 data->dl->left_glyphs = Dynarr_new (glyph_block);
|
|
2059 Dynarr_add (data->dl->left_glyphs, *gb);
|
|
2060 return NULL;
|
|
2061 }
|
|
2062 else if (pos_type == END_GLYPHS)
|
|
2063 {
|
|
2064 if (!data->dl->right_glyphs)
|
|
2065 data->dl->right_glyphs = Dynarr_new (glyph_block);
|
|
2066 Dynarr_add (data->dl->right_glyphs, *gb);
|
|
2067 return NULL;
|
|
2068 }
|
|
2069 else
|
2500
|
2070 ABORT (); /* there are no unknown types */
|
428
|
2071 }
|
|
2072
|
819
|
2073 return NULL;
|
428
|
2074 }
|
|
2075
|
|
2076 /* Add all glyphs at position POS_TYPE that are contained in the given
|
|
2077 data. */
|
|
2078
|
|
2079 static prop_block_dynarr *
|
|
2080 add_glyph_runes (pos_data *data, int pos_type)
|
|
2081 {
|
|
2082 /* #### This still needs to handle the start_col parameter. Duh, Chuck,
|
|
2083 why didn't you just modify add_glyph_rune in the first place? */
|
|
2084 int elt;
|
|
2085 glyph_block_dynarr *glyph_arr = (pos_type == BEGIN_GLYPHS
|
|
2086 ? data->ef->begin_glyphs
|
|
2087 : data->ef->end_glyphs);
|
|
2088 prop_block_dynarr *prop;
|
|
2089
|
|
2090 for (elt = 0; elt < Dynarr_length (glyph_arr); elt++)
|
|
2091 {
|
|
2092 prop = add_glyph_rune (data, Dynarr_atp (glyph_arr, elt), pos_type, 0,
|
|
2093 0);
|
|
2094
|
|
2095 if (prop)
|
|
2096 {
|
|
2097 /* #### Add some propagation information. */
|
|
2098 return prop;
|
|
2099 }
|
|
2100 }
|
|
2101
|
|
2102 Dynarr_reset (glyph_arr);
|
|
2103
|
|
2104 return NULL;
|
|
2105 }
|
|
2106
|
|
2107 /* Given a position for a buffer in a window, ensure that the given
|
|
2108 display line DL accurately represents the text on a line starting
|
|
2109 at the given position.
|
|
2110
|
826
|
2111 NOTE NOTE NOTE NOTE: This function works with and returns Bytebpos's.
|
428
|
2112 You must do appropriate conversion. */
|
|
2113
|
665
|
2114 static Bytebpos
|
428
|
2115 create_text_block (struct window *w, struct display_line *dl,
|
826
|
2116 Bytebpos byte_start_pos, prop_block_dynarr **prop,
|
428
|
2117 int type)
|
|
2118 {
|
|
2119 struct frame *f = XFRAME (w->frame);
|
|
2120 struct buffer *b = XBUFFER (w->buffer);
|
|
2121 struct device *d = XDEVICE (f->device);
|
|
2122
|
|
2123 pos_data data;
|
|
2124
|
|
2125 /* Don't display anything in the minibuffer if this window is not on
|
|
2126 a selected frame. We consider all other windows to be active
|
|
2127 minibuffers as it simplifies the coding. */
|
|
2128 int active_minibuffer = (!MINI_WINDOW_P (w) ||
|
|
2129 (f == device_selected_frame (d)) ||
|
|
2130 is_surrogate_for_selected_frame (f));
|
|
2131
|
|
2132 int truncate_win = window_truncation_on (w);
|
|
2133
|
|
2134 /* If the buffer's value of selective_display is an integer then
|
|
2135 only lines that start with less than selective_display columns of
|
|
2136 space will be displayed. If selective_display is t then all text
|
|
2137 after a ^M is invisible. */
|
|
2138 int selective = (INTP (b->selective_display)
|
|
2139 ? XINT (b->selective_display)
|
434
|
2140 : (!NILP (b->selective_display) ? -1 : 0));
|
428
|
2141
|
|
2142 /* The variable ctl-arrow allows the user to specify what characters
|
|
2143 can actually be displayed and which octal should be used for.
|
|
2144 #### This variable should probably have some rethought done to
|
|
2145 it.
|
|
2146
|
2367
|
2147 See also
|
|
2148
|
|
2149 (Info-goto-node "(internals)Future Work -- Display Tables")
|
|
2150
|
|
2151 */
|
867
|
2152 Ichar printable_min = (CHAR_OR_CHAR_INTP (b->ctl_arrow)
|
428
|
2153 ? XCHAR_OR_CHAR_INT (b->ctl_arrow)
|
|
2154 : ((EQ (b->ctl_arrow, Qt) || EQ (b->ctl_arrow, Qnil))
|
|
2155 ? 255 : 160));
|
|
2156
|
|
2157 Lisp_Object face_dt, window_dt;
|
|
2158
|
|
2159 /* The text display block for this display line. */
|
|
2160 struct display_block *db = get_display_block_from_line (dl, TEXT);
|
|
2161
|
|
2162 /* The first time through the main loop we need to force the glyph
|
|
2163 data to be updated. */
|
|
2164 int initial = 1;
|
|
2165
|
|
2166 /* Apparently the new extent_fragment_update returns an end position
|
|
2167 equal to the position passed in if there are no more runs to be
|
|
2168 displayed. */
|
|
2169 int no_more_frags = 0;
|
|
2170
|
|
2171 Lisp_Object synch_minibuffers_value =
|
|
2172 symbol_value_in_buffer (Qsynchronize_minibuffers, w->buffer);
|
|
2173
|
|
2174 dl->used_prop_data = 0;
|
|
2175 dl->num_chars = 0;
|
442
|
2176 dl->line_continuation = 0;
|
428
|
2177
|
|
2178 xzero (data);
|
|
2179 data.ef = extent_fragment_new (w->buffer, f);
|
|
2180
|
|
2181 /* These values are used by all of the rune addition routines. We add
|
|
2182 them to this structure for ease of passing. */
|
|
2183 data.d = d;
|
793
|
2184 data.window = wrap_window (w);
|
428
|
2185 data.string = Qnil;
|
|
2186 data.db = db;
|
|
2187 data.dl = dl;
|
|
2188
|
826
|
2189 data.byte_charpos = byte_start_pos;
|
428
|
2190 data.pixpos = dl->bounds.left_in;
|
|
2191 data.last_charset = Qunbound;
|
|
2192 data.last_findex = DEFAULT_INDEX;
|
|
2193 data.result_str = Qnil;
|
|
2194
|
|
2195 /* Set the right boundary adjusting it to take into account any end
|
|
2196 glyph. Save the width of the end glyph for later use. */
|
|
2197 data.max_pixpos = dl->bounds.right_in;
|
|
2198 if (truncate_win)
|
819
|
2199 data.end_glyph_width = GLYPH_CACHEL_WIDTH (w, TRUN_GLYPH_INDEX);
|
428
|
2200 else
|
819
|
2201 data.end_glyph_width = GLYPH_CACHEL_WIDTH (w, CONT_GLYPH_INDEX);
|
|
2202 data.max_pixpos -= data.end_glyph_width;
|
428
|
2203
|
|
2204 if (cursor_in_echo_area && MINI_WINDOW_P (w) && echo_area_active (f))
|
|
2205 {
|
826
|
2206 data.byte_cursor_charpos = BYTE_BUF_ZV (b);
|
428
|
2207 data.cursor_type = CURSOR_ON;
|
|
2208 }
|
|
2209 else if (MINI_WINDOW_P (w) && !active_minibuffer)
|
|
2210 data.cursor_type = NO_CURSOR;
|
|
2211 else if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)) &&
|
|
2212 EQ(DEVICE_CONSOLE(d), Vselected_console) &&
|
|
2213 d == XDEVICE(CONSOLE_SELECTED_DEVICE(XCONSOLE(DEVICE_CONSOLE(d))))&&
|
|
2214 f == XFRAME(DEVICE_SELECTED_FRAME(d)))
|
|
2215 {
|
826
|
2216 data.byte_cursor_charpos = BYTE_BUF_PT (b);
|
428
|
2217 data.cursor_type = CURSOR_ON;
|
|
2218 }
|
|
2219 else if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
|
|
2220 {
|
826
|
2221 data.byte_cursor_charpos = byte_marker_position (w->pointm[type]);
|
428
|
2222 data.cursor_type = CURSOR_ON;
|
|
2223 }
|
|
2224 else
|
|
2225 data.cursor_type = NO_CURSOR;
|
|
2226 data.cursor_x = -1;
|
|
2227
|
|
2228 data.start_col = w->hscroll;
|
|
2229 data.start_col_xoffset = w->left_xoffset;
|
826
|
2230 data.byte_start_col_enabled = (w->hscroll ? byte_start_pos : 0);
|
428
|
2231 data.hscroll_glyph_width_adjust = 0;
|
|
2232
|
|
2233 /* We regenerate the line from the very beginning. */
|
|
2234 Dynarr_reset (db->runes);
|
|
2235
|
|
2236 /* Why is this less than or equal and not just less than? If the
|
|
2237 starting position is already equal to the maximum we can't add
|
|
2238 anything else, right? Wrong. We might still have a newline to
|
|
2239 add. A newline can use the room allocated for an end glyph since
|
|
2240 if we add it we know we aren't going to be adding any end
|
|
2241 glyph. */
|
|
2242
|
|
2243 /* #### Chuck -- I think this condition should be while (1).
|
|
2244 Otherwise if (e.g.) there is one begin-glyph and one end-glyph
|
|
2245 and the begin-glyph ends exactly at the end of the window, the
|
|
2246 end-glyph and text might not be displayed. while (1) ensures
|
|
2247 that the loop terminates only when either (a) there is
|
|
2248 propagation data or (b) the end-of-line or end-of-buffer is hit.
|
|
2249
|
|
2250 #### Also I think you need to ensure that the operation
|
|
2251 "add begin glyphs; add end glyphs; add text" is atomic and
|
|
2252 can't get interrupted in the middle. If you run off the end
|
|
2253 of the line during that operation, then you keep accumulating
|
|
2254 propagation data until you're done. Otherwise, if the (e.g.)
|
|
2255 there's a begin glyph at a particular position and attempting
|
|
2256 to display that glyph results in window-end being hit and
|
|
2257 propagation data being generated, then the character at that
|
|
2258 position won't be displayed.
|
|
2259
|
|
2260 #### See also the comment after the end of this loop, below.
|
|
2261 */
|
|
2262 while (data.pixpos <= data.max_pixpos
|
|
2263 && (active_minibuffer || !NILP (synch_minibuffers_value)))
|
|
2264 {
|
|
2265 /* #### This check probably should not be necessary. */
|
826
|
2266 if (data.byte_charpos > BYTE_BUF_ZV (b))
|
428
|
2267 {
|
|
2268 /* #### urk! More of this lossage! */
|
826
|
2269 data.byte_charpos--;
|
428
|
2270 goto done;
|
|
2271 }
|
|
2272
|
|
2273 /* If selective display was an integer and we aren't working on
|
|
2274 a continuation line then find the next line we are actually
|
|
2275 supposed to display. */
|
|
2276 if (selective > 0
|
826
|
2277 && (data.byte_charpos == BYTE_BUF_BEGV (b)
|
|
2278 || BUF_FETCH_CHAR (b, prev_bytebpos (b, data.byte_charpos)) == '\n'))
|
|
2279 {
|
|
2280 while (byte_spaces_at_point (b, data.byte_charpos) >= selective)
|
428
|
2281 {
|
826
|
2282 data.byte_charpos =
|
|
2283 byte_find_next_newline_no_quit (b, data.byte_charpos, 1);
|
|
2284 if (data.byte_charpos >= BYTE_BUF_ZV (b))
|
428
|
2285 {
|
826
|
2286 data.byte_charpos = BYTE_BUF_ZV (b);
|
428
|
2287 goto done;
|
|
2288 }
|
|
2289 }
|
|
2290 }
|
|
2291
|
|
2292 /* Check for face changes. */
|
826
|
2293 if (initial || (!no_more_frags && data.byte_charpos == data.ef->end))
|
428
|
2294 {
|
819
|
2295 Lisp_Object last_glyph = Qnil;
|
|
2296
|
|
2297 /* Deal with glyphs that we have already displayed. The
|
|
2298 theory is that if we end up with a PROP_GLYPH in the
|
|
2299 propagation data then we are clipping the glyph and there
|
|
2300 can be no propagation data before that point. The theory
|
|
2301 works because we always recalculate the extent-fragments
|
|
2302 for propagated data, we never actually propagate the
|
|
2303 fragments that still need to be displayed. */
|
|
2304 if (*prop && Dynarr_atp (*prop, 0)->type == PROP_GLYPH)
|
|
2305 {
|
|
2306 last_glyph = Dynarr_atp (*prop, 0)->data.p_glyph.glyph;
|
|
2307 Dynarr_free (*prop);
|
|
2308 *prop = 0;
|
|
2309 }
|
428
|
2310 /* Now compute the face and begin/end-glyph information. */
|
|
2311 data.findex =
|
665
|
2312 /* Remember that the extent-fragment routines deal in Bytebpos's. */
|
826
|
2313 extent_fragment_update (w, data.ef, data.byte_charpos, last_glyph);
|
428
|
2314
|
|
2315 get_display_tables (w, data.findex, &face_dt, &window_dt);
|
|
2316
|
826
|
2317 if (data.byte_charpos == data.ef->end)
|
428
|
2318 no_more_frags = 1;
|
|
2319 }
|
|
2320 initial = 0;
|
|
2321
|
|
2322 /* Determine what is next to be displayed. We first handle any
|
665
|
2323 glyphs returned by glyphs_at_charbpos. If there are no glyphs to
|
428
|
2324 display then we determine what to do based on the character at the
|
|
2325 current buffer position. */
|
|
2326
|
|
2327 /* If the current position is covered by an invisible extent, do
|
|
2328 nothing (except maybe add some ellipses).
|
|
2329
|
|
2330 #### The behavior of begin and end-glyphs at the edge of an
|
|
2331 invisible extent should be investigated further. This is
|
|
2332 fairly low priority though. */
|
|
2333 if (data.ef->invisible)
|
|
2334 {
|
|
2335 /* #### Chuck, perhaps you could look at this code? I don't
|
|
2336 really know what I'm doing. */
|
|
2337 if (*prop)
|
|
2338 {
|
|
2339 Dynarr_free (*prop);
|
|
2340 *prop = 0;
|
|
2341 }
|
|
2342
|
|
2343 /* The extent fragment code only sets this when we should
|
|
2344 really display the ellipses. It makes sure the ellipses
|
|
2345 don't get displayed more than once in a row. */
|
|
2346 if (data.ef->invisible_ellipses)
|
|
2347 {
|
|
2348 struct glyph_block gb;
|
|
2349
|
|
2350 data.ef->invisible_ellipses_already_displayed = 1;
|
|
2351 data.ef->invisible_ellipses = 0;
|
|
2352 gb.extent = Qnil;
|
|
2353 gb.glyph = Vinvisible_text_glyph;
|
|
2354 *prop = add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0,
|
|
2355 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX));
|
|
2356 /* Perhaps they shouldn't propagate if the very next thing
|
|
2357 is to display a newline (for compatibility with
|
|
2358 selective-display-ellipses)? Maybe that's too
|
|
2359 abstruse. */
|
|
2360 if (*prop)
|
|
2361 goto done;
|
|
2362 }
|
|
2363
|
|
2364 /* If point is in an invisible region we place it on the
|
|
2365 next visible character. */
|
|
2366 if (data.cursor_type == CURSOR_ON
|
826
|
2367 && data.byte_charpos == data.byte_cursor_charpos)
|
428
|
2368 {
|
|
2369 data.cursor_type = NEXT_CURSOR;
|
|
2370 }
|
|
2371
|
|
2372 /* #### What if we we're dealing with a display table? */
|
|
2373 if (data.start_col)
|
|
2374 data.start_col--;
|
|
2375
|
826
|
2376 if (data.byte_charpos == BYTE_BUF_ZV (b))
|
428
|
2377 goto done;
|
|
2378 else
|
826
|
2379 INC_BYTEBPOS (b, data.byte_charpos);
|
428
|
2380 }
|
|
2381
|
|
2382 /* If there is propagation data, then it represents the current
|
819
|
2383 buffer position being displayed. Add them and advance the
|
|
2384 position counter. This might also add the minibuffer
|
|
2385 prompt. */
|
428
|
2386 else if (*prop)
|
|
2387 {
|
|
2388 dl->used_prop_data = 1;
|
|
2389 *prop = add_propagation_runes (prop, &data);
|
|
2390
|
|
2391 if (*prop)
|
|
2392 goto done; /* gee, a really narrow window */
|
826
|
2393 else if (data.byte_charpos == BYTE_BUF_ZV (b))
|
428
|
2394 goto done;
|
826
|
2395 else if (data.byte_charpos < BYTE_BUF_BEGV (b))
|
428
|
2396 /* #### urk urk urk! Aborts are not very fun! Fix this please! */
|
826
|
2397 data.byte_charpos = BYTE_BUF_BEGV (b);
|
428
|
2398 else
|
826
|
2399 INC_BYTEBPOS (b, data.byte_charpos);
|
428
|
2400 }
|
|
2401
|
|
2402 /* If there are end glyphs, add them to the line. These are
|
|
2403 the end glyphs for the previous run of text. We add them
|
|
2404 here rather than doing them at the end of handling the
|
|
2405 previous run so that glyphs at the beginning and end of
|
|
2406 a line are handled correctly. */
|
819
|
2407 else if (Dynarr_length (data.ef->end_glyphs) > 0
|
|
2408 || Dynarr_length (data.ef->begin_glyphs) > 0)
|
|
2409 {
|
|
2410 glyph_block_dynarr* tmpglyphs = 0;
|
|
2411 /* #### I think this is safe, but could be wrong. */
|
826
|
2412 data.ch = BYTE_BUF_FETCH_CHAR (b, data.byte_charpos);
|
819
|
2413
|
|
2414 if (Dynarr_length (data.ef->end_glyphs) > 0)
|
|
2415 {
|
|
2416 *prop = add_glyph_runes (&data, END_GLYPHS);
|
|
2417 tmpglyphs = data.ef->end_glyphs;
|
|
2418 }
|
|
2419
|
|
2420 /* If there are begin glyphs, add them to the line. */
|
|
2421 if (!*prop && Dynarr_length (data.ef->begin_glyphs) > 0)
|
|
2422 {
|
|
2423 *prop = add_glyph_runes (&data, BEGIN_GLYPHS);
|
|
2424 tmpglyphs = data.ef->begin_glyphs;
|
|
2425 }
|
|
2426
|
|
2427 if (*prop)
|
|
2428 {
|
|
2429 /* If we just clipped a glyph and we are at the end of a
|
|
2430 line and there are more glyphs to display then do
|
|
2431 appropriate processing to not get a continuation
|
|
2432 glyph. */
|
|
2433 if (*prop != ADD_FAILED
|
|
2434 && Dynarr_atp (*prop, 0)->type == PROP_GLYPH
|
|
2435 && data.ch == '\n')
|
|
2436 {
|
|
2437 /* If there are no more glyphs then do the normal
|
|
2438 processing.
|
|
2439
|
|
2440 #### This doesn't actually work if the same glyph is
|
|
2441 present more than once in the block. To solve
|
|
2442 this we would have to carry the index around
|
|
2443 which might be problematic since the fragment is
|
|
2444 recalculated for each line. */
|
|
2445 if (EQ (Dynarr_end (tmpglyphs)->glyph,
|
|
2446 Dynarr_atp (*prop, 0)->data.p_glyph.glyph))
|
|
2447 {
|
|
2448 Dynarr_free (*prop);
|
|
2449 *prop = 0;
|
|
2450 }
|
|
2451 else {
|
|
2452 data.blank_width = DEVMETH (d, eol_cursor_width, ());
|
867
|
2453 add_ichar_rune (&data); /* discard prop data. */
|
819
|
2454 goto done;
|
|
2455 }
|
|
2456 }
|
|
2457 else
|
|
2458 goto done;
|
|
2459 }
|
428
|
2460 }
|
|
2461
|
|
2462 /* If at end-of-buffer, we've already processed begin and
|
|
2463 end-glyphs at this point and there's no text to process,
|
|
2464 so we're done. */
|
826
|
2465 else if (data.byte_charpos == BYTE_BUF_ZV (b))
|
428
|
2466 goto done;
|
|
2467
|
|
2468 else
|
|
2469 {
|
|
2470 Lisp_Object entry = Qnil;
|
|
2471 /* Get the character at the current buffer position. */
|
826
|
2472 data.ch = BYTE_BUF_FETCH_CHAR (b, data.byte_charpos);
|
428
|
2473 if (!NILP (face_dt) || !NILP (window_dt))
|
|
2474 entry = display_table_entry (data.ch, face_dt, window_dt);
|
|
2475
|
|
2476 /* If there is a display table entry for it, hand it off to
|
|
2477 add_disp_table_entry_runes and let it worry about it. */
|
|
2478 if (!NILP (entry) && !EQ (entry, make_char (data.ch)))
|
|
2479 {
|
|
2480 *prop = add_disp_table_entry_runes (&data, entry);
|
|
2481
|
|
2482 if (*prop)
|
|
2483 goto done;
|
|
2484 }
|
|
2485
|
|
2486 /* Check if we have hit a newline character. If so, add a marker
|
|
2487 to the line and end this loop. */
|
|
2488 else if (data.ch == '\n')
|
|
2489 {
|
|
2490 /* We aren't going to be adding an end glyph so give its
|
|
2491 space back in order to make sure that the cursor can
|
|
2492 fit. */
|
819
|
2493 data.max_pixpos += data.end_glyph_width;
|
428
|
2494
|
|
2495 if (selective > 0
|
826
|
2496 && (byte_spaces_at_point
|
|
2497 (b, next_bytebpos (b, data.byte_charpos))
|
428
|
2498 >= selective))
|
|
2499 {
|
|
2500 if (!NILP (b->selective_display_ellipses))
|
|
2501 {
|
|
2502 struct glyph_block gb;
|
|
2503
|
|
2504 gb.extent = Qnil;
|
|
2505 gb.glyph = Vinvisible_text_glyph;
|
|
2506 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0,
|
|
2507 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX));
|
|
2508 }
|
|
2509 else
|
|
2510 {
|
|
2511 /* Cheesy, cheesy, cheesy. We mark the end of the
|
|
2512 line with a special "character rune" whose width
|
|
2513 is the EOL cursor width and whose character is
|
|
2514 the non-printing character '\n'. */
|
|
2515 data.blank_width = DEVMETH (d, eol_cursor_width, ());
|
867
|
2516 *prop = add_ichar_rune (&data);
|
428
|
2517 }
|
|
2518
|
826
|
2519 /* We need to set data.byte_charpos to the start of the
|
428
|
2520 next visible region in order to make this line
|
|
2521 appear to contain all of the invisible area.
|
|
2522 Otherwise, the line cache won't work
|
|
2523 correctly. */
|
826
|
2524 INC_BYTEBPOS (b, data.byte_charpos);
|
|
2525 while (byte_spaces_at_point (b, data.byte_charpos) >= selective)
|
428
|
2526 {
|
826
|
2527 data.byte_charpos =
|
|
2528 byte_find_next_newline_no_quit (b, data.byte_charpos, 1);
|
|
2529 if (data.byte_charpos >= BYTE_BUF_ZV (b))
|
428
|
2530 {
|
826
|
2531 data.byte_charpos = BYTE_BUF_ZV (b);
|
428
|
2532 break;
|
|
2533 }
|
|
2534 }
|
826
|
2535 if (BYTE_BUF_FETCH_CHAR
|
|
2536 (b, prev_bytebpos (b, data.byte_charpos)) == '\n')
|
|
2537 DEC_BYTEBPOS (b, data.byte_charpos);
|
428
|
2538 }
|
|
2539 else
|
|
2540 {
|
|
2541 data.blank_width = DEVMETH (d, eol_cursor_width, ());
|
867
|
2542 *prop = add_ichar_rune (&data);
|
428
|
2543 }
|
|
2544
|
|
2545 goto done;
|
|
2546 }
|
|
2547
|
|
2548 /* If the current character is ^M, and selective display is
|
|
2549 enabled, then add the invisible-text-glyph if
|
|
2550 selective-display-ellipses is set. In any case, this
|
|
2551 line is done. */
|
|
2552 else if (data.ch == (('M' & 037)) && selective == -1)
|
|
2553 {
|
826
|
2554 Bytebpos byte_next_charpos;
|
428
|
2555
|
|
2556 /* Find the buffer position at the end of the line. */
|
826
|
2557 byte_next_charpos =
|
|
2558 byte_find_next_newline_no_quit (b, data.byte_charpos, 1);
|
|
2559 if (BYTE_BUF_FETCH_CHAR (b, prev_bytebpos (b, byte_next_charpos))
|
428
|
2560 == '\n')
|
826
|
2561 DEC_BYTEBPOS (b, byte_next_charpos);
|
428
|
2562
|
|
2563 /* If the cursor is somewhere in the elided text make
|
|
2564 sure that the cursor gets drawn appropriately. */
|
|
2565 if (data.cursor_type == CURSOR_ON
|
826
|
2566 && (data.byte_cursor_charpos >= data.byte_charpos &&
|
|
2567 data.byte_cursor_charpos < byte_next_charpos))
|
428
|
2568 {
|
|
2569 data.cursor_type = NEXT_CURSOR;
|
|
2570 }
|
|
2571
|
|
2572 /* We won't be adding a truncation or continuation glyph
|
|
2573 so give up the room allocated for them. */
|
819
|
2574 data.max_pixpos += data.end_glyph_width;
|
428
|
2575
|
|
2576 if (!NILP (b->selective_display_ellipses))
|
|
2577 {
|
|
2578 /* We don't propagate anything from the invisible
|
|
2579 text glyph if it fails to fit. This is
|
|
2580 intentional. */
|
|
2581 struct glyph_block gb;
|
|
2582
|
|
2583 gb.extent = Qnil;
|
|
2584 gb.glyph = Vinvisible_text_glyph;
|
|
2585 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 1,
|
|
2586 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX));
|
|
2587 }
|
|
2588
|
|
2589 /* Set the buffer position to the end of the line. We
|
|
2590 need to do this before potentially adding a newline
|
|
2591 so that the cursor flag will get set correctly (if
|
|
2592 needed). */
|
826
|
2593 data.byte_charpos = byte_next_charpos;
|
428
|
2594
|
|
2595 if (NILP (b->selective_display_ellipses)
|
826
|
2596 || data.byte_cursor_charpos == byte_next_charpos)
|
428
|
2597 {
|
|
2598 /* We have to at least add a newline character so
|
|
2599 that the cursor shows up properly. */
|
|
2600 data.ch = '\n';
|
|
2601 data.blank_width = DEVMETH (d, eol_cursor_width, ());
|
|
2602 data.findex = DEFAULT_INDEX;
|
|
2603 data.start_col = 0;
|
|
2604 data.start_col_xoffset = 0;
|
826
|
2605 data.byte_start_col_enabled = 0;
|
428
|
2606
|
867
|
2607 add_ichar_rune (&data);
|
428
|
2608 }
|
|
2609
|
|
2610 /* This had better be a newline but doing it this way
|
|
2611 we'll see obvious incorrect results if it isn't. No
|
|
2612 need to abort here. */
|
826
|
2613 data.ch = BYTE_BUF_FETCH_CHAR (b, data.byte_charpos);
|
428
|
2614
|
|
2615 goto done;
|
|
2616 }
|
|
2617
|
|
2618 /* If the current character is considered to be printable, then
|
|
2619 just add it. */
|
|
2620 else if (data.ch >= printable_min)
|
|
2621 {
|
867
|
2622 *prop = add_ichar_rune (&data);
|
428
|
2623 if (*prop)
|
|
2624 goto done;
|
|
2625 }
|
|
2626
|
|
2627 /* If the current character is a tab, determine the next tab
|
|
2628 starting position and add a blank rune which extends from the
|
|
2629 current pixel position to that starting position. */
|
|
2630 else if (data.ch == '\t')
|
|
2631 {
|
|
2632 int tab_start_pixpos = data.pixpos;
|
|
2633 int next_tab_start;
|
|
2634 int char_tab_width;
|
|
2635 int prop_width = 0;
|
|
2636
|
|
2637 if (data.start_col > 1)
|
434
|
2638 tab_start_pixpos -= (space_width (w) * (data.start_col - 1))
|
428
|
2639 + data.start_col_xoffset;
|
|
2640
|
|
2641 next_tab_start =
|
|
2642 next_tab_position (w, tab_start_pixpos,
|
|
2643 dl->bounds.left_in +
|
|
2644 data.hscroll_glyph_width_adjust);
|
|
2645 if (next_tab_start > data.max_pixpos)
|
|
2646 {
|
|
2647 prop_width = next_tab_start - data.max_pixpos;
|
|
2648 next_tab_start = data.max_pixpos;
|
|
2649 }
|
|
2650 data.blank_width = next_tab_start - data.pixpos;
|
|
2651 char_tab_width =
|
|
2652 (next_tab_start - tab_start_pixpos) / space_width (w);
|
|
2653
|
|
2654 *prop = add_blank_rune (&data, w, char_tab_width);
|
|
2655
|
|
2656 /* add_blank_rune is only supposed to be called with
|
|
2657 sizes guaranteed to fit in the available space. */
|
|
2658 assert (!(*prop));
|
|
2659
|
|
2660 if (prop_width)
|
|
2661 {
|
|
2662 struct prop_block pb;
|
|
2663 *prop = Dynarr_new (prop_block);
|
|
2664
|
|
2665 pb.type = PROP_BLANK;
|
|
2666 pb.data.p_blank.width = prop_width;
|
|
2667 pb.data.p_blank.findex = data.findex;
|
|
2668 Dynarr_add (*prop, pb);
|
|
2669
|
|
2670 goto done;
|
|
2671 }
|
|
2672 }
|
|
2673
|
|
2674 /* If character is a control character, pass it off to
|
|
2675 add_control_char_runes.
|
|
2676
|
|
2677 The is_*() routines have undefined results on
|
|
2678 arguments outside of the range [-1, 255]. (This
|
|
2679 often bites people who carelessly use `char' instead
|
|
2680 of `unsigned char'.)
|
|
2681 */
|
867
|
2682 else if (data.ch < 0x100 && iscntrl ((Ibyte) data.ch))
|
428
|
2683 {
|
|
2684 *prop = add_control_char_runes (&data, b);
|
|
2685
|
|
2686 if (*prop)
|
|
2687 goto done;
|
|
2688 }
|
|
2689
|
|
2690 /* If the character is above the ASCII range and we have not
|
|
2691 already handled it, then print it as an octal number. */
|
|
2692 else if (data.ch >= 0200)
|
|
2693 {
|
|
2694 *prop = add_octal_runes (&data);
|
|
2695
|
|
2696 if (*prop)
|
|
2697 goto done;
|
|
2698 }
|
|
2699
|
|
2700 /* Assume the current character is considered to be printable,
|
|
2701 then just add it. */
|
|
2702 else
|
|
2703 {
|
867
|
2704 *prop = add_ichar_rune (&data);
|
428
|
2705 if (*prop)
|
|
2706 goto done;
|
|
2707 }
|
|
2708
|
826
|
2709 INC_BYTEBPOS (b, data.byte_charpos);
|
428
|
2710 }
|
|
2711 }
|
|
2712
|
|
2713 done:
|
|
2714
|
|
2715 /* Determine the starting point of the next line if we did not hit the
|
|
2716 end of the buffer. */
|
826
|
2717 if (data.byte_charpos < BYTE_BUF_ZV (b)
|
428
|
2718 && (active_minibuffer || !NILP (synch_minibuffers_value)))
|
|
2719 {
|
|
2720 /* #### This check is not correct. If the line terminated
|
|
2721 due to a begin-glyph or end-glyph hitting window-end, then
|
826
|
2722 data.ch will not point to the character at data.byte_charpos. If
|
428
|
2723 you make the two changes mentioned at the top of this loop,
|
|
2724 you should be able to say '(if (*prop))'. That should also
|
826
|
2725 make it possible to eliminate the data.byte_charpos < BYTE_BUF_ZV (b)
|
428
|
2726 check. */
|
|
2727
|
|
2728 /* The common case is that the line ended because we hit a newline.
|
|
2729 In that case, the next character is just the next buffer
|
|
2730 position. */
|
|
2731 if (data.ch == '\n')
|
|
2732 {
|
|
2733 /* If data.start_col_enabled is still true, then the window is
|
|
2734 scrolled far enough so that nothing on this line is visible.
|
|
2735 We need to stick a truncation glyph at the beginning of the
|
|
2736 line in that case unless the line is completely blank. */
|
826
|
2737 if (data.byte_start_col_enabled)
|
428
|
2738 {
|
|
2739 if (data.cursor_type == CURSOR_ON)
|
|
2740 {
|
826
|
2741 if (data.byte_cursor_charpos >= byte_start_pos
|
|
2742 && data.byte_cursor_charpos <= data.byte_charpos)
|
|
2743 data.byte_cursor_charpos = data.byte_charpos;
|
428
|
2744 }
|
|
2745 data.findex = DEFAULT_INDEX;
|
|
2746 data.start_col = 0;
|
826
|
2747 data.byte_start_col_enabled = 0;
|
|
2748
|
|
2749 if (data.byte_charpos != byte_start_pos)
|
428
|
2750 {
|
|
2751 struct glyph_block gb;
|
|
2752
|
|
2753 gb.extent = Qnil;
|
|
2754 gb.glyph = Vhscroll_glyph;
|
|
2755 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0,
|
|
2756 GLYPH_CACHEL (w, HSCROLL_GLYPH_INDEX));
|
|
2757 }
|
|
2758 else
|
|
2759 {
|
|
2760 /* This duplicates code down below to add a newline to
|
|
2761 the end of an otherwise empty line.*/
|
|
2762 data.ch = '\n';
|
|
2763 data.blank_width = DEVMETH (d, eol_cursor_width, ());
|
|
2764
|
867
|
2765 add_ichar_rune (&data);
|
428
|
2766 }
|
|
2767 }
|
|
2768
|
826
|
2769 INC_BYTEBPOS (b, data.byte_charpos);
|
428
|
2770 }
|
|
2771
|
|
2772 /* Otherwise we have a buffer line which cannot fit on one display
|
|
2773 line. */
|
|
2774 else
|
|
2775 {
|
|
2776 struct glyph_block gb;
|
|
2777 struct glyph_cachel *cachel;
|
|
2778
|
|
2779 /* If the line is to be truncated then we actually have to look
|
|
2780 for the next newline. We also add the end-of-line glyph which
|
|
2781 we know will fit because we adjusted the right border before
|
|
2782 we starting laying out the line. */
|
819
|
2783 data.max_pixpos += data.end_glyph_width;
|
428
|
2784 data.findex = DEFAULT_INDEX;
|
|
2785 gb.extent = Qnil;
|
|
2786
|
|
2787 if (truncate_win)
|
|
2788 {
|
826
|
2789 Bytebpos byte_pos;
|
428
|
2790
|
|
2791 /* Now find the start of the next line. */
|
826
|
2792 byte_pos = byte_find_next_newline_no_quit (b, data.byte_charpos, 1);
|
428
|
2793
|
|
2794 /* If the cursor is past the truncation line then we
|
|
2795 make it appear on the truncation glyph. If we've hit
|
|
2796 the end of the buffer then we also make the cursor
|
|
2797 appear unless eob is immediately preceded by a
|
|
2798 newline. In that case the cursor should actually
|
|
2799 appear on the next line. */
|
|
2800 if (data.cursor_type == CURSOR_ON
|
826
|
2801 && data.byte_cursor_charpos >= data.byte_charpos
|
|
2802 && (data.byte_cursor_charpos < byte_pos ||
|
|
2803 (byte_pos == BYTE_BUF_ZV (b)
|
|
2804 && (byte_pos == BYTE_BUF_BEGV (b)
|
|
2805 || (BYTE_BUF_FETCH_CHAR (b, prev_bytebpos (b, byte_pos))
|
428
|
2806 != '\n')))))
|
826
|
2807 data.byte_cursor_charpos = byte_pos;
|
428
|
2808 else
|
|
2809 data.cursor_type = NO_CURSOR;
|
|
2810
|
826
|
2811 data.byte_charpos = byte_pos;
|
428
|
2812 gb.glyph = Vtruncation_glyph;
|
|
2813 cachel = GLYPH_CACHEL (w, TRUN_GLYPH_INDEX);
|
|
2814 }
|
|
2815 else
|
|
2816 {
|
|
2817 /* The cursor can never be on the continuation glyph. */
|
|
2818 data.cursor_type = NO_CURSOR;
|
|
2819
|
826
|
2820 /* data.byte_charpos is already at the start of the next line. */
|
428
|
2821
|
442
|
2822 dl->line_continuation = 1;
|
428
|
2823 gb.glyph = Vcontinuation_glyph;
|
|
2824 cachel = GLYPH_CACHEL (w, CONT_GLYPH_INDEX);
|
|
2825 }
|
|
2826
|
442
|
2827 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, cachel);
|
428
|
2828
|
826
|
2829 if (truncate_win && data.byte_charpos == BYTE_BUF_ZV (b)
|
|
2830 && BYTE_BUF_FETCH_CHAR (b, prev_bytebpos (b, BYTE_BUF_ZV (b))) != '\n')
|
428
|
2831 /* #### Damn this losing shit. */
|
826
|
2832 data.byte_charpos++;
|
428
|
2833 }
|
|
2834 }
|
|
2835 else if ((active_minibuffer || !NILP (synch_minibuffers_value))
|
826
|
2836 && (!echo_area_active (f) || data.byte_charpos == BYTE_BUF_ZV (b)))
|
428
|
2837 {
|
|
2838 /* We need to add a marker to the end of the line since there is no
|
|
2839 newline character in order for the cursor to get drawn. We label
|
|
2840 it as a newline so that it gets handled correctly by the
|
|
2841 whitespace routines below. */
|
|
2842
|
|
2843 data.ch = '\n';
|
|
2844 data.blank_width = DEVMETH (d, eol_cursor_width, ());
|
|
2845 data.findex = DEFAULT_INDEX;
|
|
2846 data.start_col = 0;
|
|
2847 data.start_col_xoffset = 0;
|
826
|
2848 data.byte_start_col_enabled = 0;
|
428
|
2849
|
|
2850 data.max_pixpos += data.blank_width;
|
867
|
2851 add_ichar_rune (&data);
|
428
|
2852 data.max_pixpos -= data.blank_width;
|
|
2853
|
|
2854 /* #### urk! Chuck, this shit is bad news. Going around
|
|
2855 manipulating invalid positions is guaranteed to result in
|
|
2856 trouble sooner or later. */
|
826
|
2857 data.byte_charpos = BYTE_BUF_ZV (b) + 1;
|
428
|
2858 }
|
|
2859
|
|
2860 /* Calculate left whitespace boundary. */
|
|
2861 {
|
|
2862 int elt = 0;
|
|
2863
|
|
2864 /* Whitespace past a newline is considered right whitespace. */
|
|
2865 while (elt < Dynarr_length (db->runes))
|
|
2866 {
|
|
2867 struct rune *rb = Dynarr_atp (db->runes, elt);
|
|
2868
|
|
2869 if ((rb->type == RUNE_CHAR && rb->object.chr.ch == ' ')
|
|
2870 || rb->type == RUNE_BLANK)
|
|
2871 {
|
|
2872 dl->bounds.left_white += rb->width;
|
|
2873 elt++;
|
|
2874 }
|
|
2875 else
|
|
2876 elt = Dynarr_length (db->runes);
|
|
2877 }
|
|
2878 }
|
|
2879
|
|
2880 /* Calculate right whitespace boundary. */
|
|
2881 {
|
|
2882 int elt = Dynarr_length (db->runes) - 1;
|
|
2883 int done = 0;
|
|
2884
|
|
2885 while (!done && elt >= 0)
|
|
2886 {
|
|
2887 struct rune *rb = Dynarr_atp (db->runes, elt);
|
|
2888
|
|
2889 if (!(rb->type == RUNE_CHAR && rb->object.chr.ch < 0x100
|
|
2890 && isspace (rb->object.chr.ch))
|
|
2891 && !rb->type == RUNE_BLANK)
|
|
2892 {
|
|
2893 dl->bounds.right_white = rb->xpos + rb->width;
|
|
2894 done = 1;
|
|
2895 }
|
|
2896
|
|
2897 elt--;
|
|
2898
|
|
2899 }
|
|
2900
|
|
2901 /* The line is blank so everything is considered to be right
|
|
2902 whitespace. */
|
|
2903 if (!done)
|
|
2904 dl->bounds.right_white = dl->bounds.left_in;
|
|
2905 }
|
|
2906
|
|
2907 /* Set the display blocks bounds. */
|
|
2908 db->start_pos = dl->bounds.left_in;
|
|
2909 if (Dynarr_length (db->runes))
|
|
2910 {
|
|
2911 struct rune *rb = Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
|
|
2912
|
|
2913 db->end_pos = rb->xpos + rb->width;
|
|
2914 }
|
|
2915 else
|
|
2916 db->end_pos = dl->bounds.right_white;
|
|
2917
|
819
|
2918 calculate_baseline (&data);
|
428
|
2919
|
|
2920 dl->ascent = data.new_ascent;
|
|
2921 dl->descent = data.new_descent;
|
|
2922
|
|
2923 {
|
|
2924 unsigned short ascent = (unsigned short) XINT (w->minimum_line_ascent);
|
|
2925
|
|
2926 if (dl->ascent < ascent)
|
|
2927 dl->ascent = ascent;
|
|
2928 }
|
|
2929 {
|
|
2930 unsigned short descent = (unsigned short) XINT (w->minimum_line_descent);
|
|
2931
|
|
2932 if (dl->descent < descent)
|
|
2933 dl->descent = descent;
|
|
2934 }
|
|
2935
|
819
|
2936 calculate_yoffset (dl, db);
|
|
2937
|
428
|
2938 dl->cursor_elt = data.cursor_x;
|
|
2939 /* #### lossage lossage lossage! Fix this shit! */
|
826
|
2940 if (data.byte_charpos > BYTE_BUF_ZV (b))
|
|
2941 dl->end_charpos = BUF_ZV (b);
|
428
|
2942 else
|
826
|
2943 dl->end_charpos = bytebpos_to_charbpos (b, data.byte_charpos) - 1;
|
428
|
2944 if (truncate_win)
|
826
|
2945 data.dl->num_chars = column_at_point (b, dl->end_charpos, 0);
|
428
|
2946 else
|
|
2947 /* This doesn't correctly take into account tabs and control
|
|
2948 characters but if the window isn't being truncated then this
|
|
2949 value isn't going to end up being used anyhow. */
|
826
|
2950 data.dl->num_chars = dl->end_charpos - dl->charpos;
|
428
|
2951
|
|
2952 /* #### handle horizontally scrolled line with text none of which
|
|
2953 was actually laid out. */
|
|
2954
|
|
2955 /* #### handle any remainder of overlay arrow */
|
|
2956
|
|
2957 if (*prop == ADD_FAILED)
|
|
2958 *prop = NULL;
|
|
2959
|
|
2960 if (truncate_win && *prop)
|
|
2961 {
|
|
2962 Dynarr_free (*prop);
|
|
2963 *prop = NULL;
|
|
2964 }
|
|
2965
|
|
2966 extent_fragment_delete (data.ef);
|
|
2967
|
|
2968 /* #### If we started at EOB, then make sure we return a value past
|
|
2969 it so that regenerate_window will exit properly. This is bogus.
|
|
2970 The main loop should get fixed so that it isn't necessary to call
|
|
2971 this function if we are already at EOB. */
|
|
2972
|
826
|
2973 if (data.byte_charpos == BYTE_BUF_ZV (b) && byte_start_pos == BYTE_BUF_ZV (b))
|
|
2974 return data.byte_charpos + 1; /* Yuck! */
|
428
|
2975 else
|
826
|
2976 return data.byte_charpos;
|
428
|
2977 }
|
|
2978
|
|
2979 /* Display the overlay arrow at the beginning of the given line. */
|
|
2980
|
|
2981 static int
|
|
2982 create_overlay_glyph_block (struct window *w, struct display_line *dl)
|
|
2983 {
|
|
2984 struct frame *f = XFRAME (w->frame);
|
|
2985 struct device *d = XDEVICE (f->device);
|
|
2986 pos_data data;
|
|
2987
|
|
2988 /* If Voverlay_arrow_string isn't valid then just fail silently. */
|
|
2989 if (!STRINGP (Voverlay_arrow_string) && !GLYPHP (Voverlay_arrow_string))
|
|
2990 return 0;
|
|
2991
|
|
2992 xzero (data);
|
|
2993 data.ef = NULL;
|
|
2994 data.d = d;
|
793
|
2995 data.window = wrap_window (w);
|
428
|
2996 data.db = get_display_block_from_line (dl, OVERWRITE);
|
|
2997 data.dl = dl;
|
|
2998 data.pixpos = dl->bounds.left_in;
|
|
2999 data.max_pixpos = dl->bounds.right_in;
|
|
3000 data.cursor_type = NO_CURSOR;
|
|
3001 data.cursor_x = -1;
|
|
3002 data.findex = DEFAULT_INDEX;
|
|
3003 data.last_charset = Qunbound;
|
|
3004 data.last_findex = DEFAULT_INDEX;
|
|
3005 data.result_str = Qnil;
|
|
3006 data.string = Qnil;
|
|
3007
|
|
3008 Dynarr_reset (data.db->runes);
|
|
3009
|
|
3010 if (STRINGP (Voverlay_arrow_string))
|
|
3011 {
|
867
|
3012 add_ibyte_string_runes
|
428
|
3013 (&data,
|
|
3014 XSTRING_DATA (Voverlay_arrow_string),
|
|
3015 XSTRING_LENGTH (Voverlay_arrow_string),
|
793
|
3016 1, 0);
|
428
|
3017 }
|
|
3018 else if (GLYPHP (Voverlay_arrow_string))
|
|
3019 {
|
|
3020 struct glyph_block gb;
|
|
3021
|
|
3022 gb.glyph = Voverlay_arrow_string;
|
|
3023 gb.extent = Qnil;
|
|
3024 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, 0);
|
|
3025 }
|
819
|
3026
|
428
|
3027 if (data.max_pixmap_height)
|
|
3028 {
|
|
3029 int height = data.new_ascent + data.new_descent;
|
|
3030 int pix_ascent, pix_descent;
|
819
|
3031
|
428
|
3032 pix_descent = data.max_pixmap_height * data.new_descent / height;
|
|
3033 pix_ascent = data.max_pixmap_height - pix_descent;
|
819
|
3034 calculate_baseline (&data);
|
428
|
3035
|
|
3036 data.new_ascent = max (data.new_ascent, pix_ascent);
|
|
3037 data.new_descent = max (data.new_descent, pix_descent);
|
|
3038 }
|
|
3039
|
|
3040 dl->ascent = data.new_ascent;
|
|
3041 dl->descent = data.new_descent;
|
|
3042
|
|
3043 data.db->start_pos = dl->bounds.left_in;
|
|
3044 data.db->end_pos = data.pixpos;
|
|
3045
|
819
|
3046 calculate_yoffset (dl, data.db);
|
|
3047
|
428
|
3048 return data.pixpos - dl->bounds.left_in;
|
|
3049 }
|
|
3050
|
|
3051 /* Add a type of glyph to a margin display block. */
|
|
3052
|
|
3053 static int
|
|
3054 add_margin_runes (struct display_line *dl, struct display_block *db, int start,
|
|
3055 int count, enum glyph_layout layout, int side, Lisp_Object window)
|
|
3056 {
|
|
3057 glyph_block_dynarr *gbd = (side == LEFT_GLYPHS
|
|
3058 ? dl->left_glyphs
|
|
3059 : dl->right_glyphs);
|
|
3060 int elt, end;
|
|
3061 int reverse;
|
442
|
3062 struct window *w = XWINDOW (window);
|
|
3063 struct frame *f = XFRAME (w->frame);
|
|
3064 struct device *d = XDEVICE (f->device);
|
|
3065 pos_data data;
|
|
3066
|
|
3067 xzero (data);
|
|
3068 data.d = d;
|
|
3069 data.window = window;
|
|
3070 data.db = db;
|
|
3071 data.dl = dl;
|
|
3072 data.pixpos = start;
|
|
3073 data.cursor_type = NO_CURSOR;
|
|
3074 data.cursor_x = -1;
|
|
3075 data.last_charset = Qunbound;
|
|
3076 data.last_findex = DEFAULT_INDEX;
|
|
3077 data.result_str = Qnil;
|
|
3078 data.string = Qnil;
|
|
3079 data.new_ascent = dl->ascent;
|
|
3080 data.new_descent = dl->descent;
|
428
|
3081
|
|
3082 if ((layout == GL_WHITESPACE && side == LEFT_GLYPHS)
|
|
3083 || (layout == GL_INSIDE_MARGIN && side == RIGHT_GLYPHS))
|
|
3084 {
|
|
3085 reverse = 1;
|
|
3086 elt = Dynarr_length (gbd) - 1;
|
|
3087 end = 0;
|
|
3088 }
|
|
3089 else
|
|
3090 {
|
|
3091 reverse = 0;
|
|
3092 elt = 0;
|
|
3093 end = Dynarr_length (gbd);
|
|
3094 }
|
|
3095
|
|
3096 while (count && ((!reverse && elt < end) || (reverse && elt >= end)))
|
|
3097 {
|
|
3098 struct glyph_block *gb = Dynarr_atp (gbd, elt);
|
|
3099
|
|
3100 if (NILP (gb->extent))
|
2500
|
3101 ABORT (); /* these should have been handled in add_glyph_rune */
|
428
|
3102
|
|
3103 if (gb->active &&
|
|
3104 ((side == LEFT_GLYPHS &&
|
|
3105 extent_begin_glyph_layout (XEXTENT (gb->extent)) == layout)
|
|
3106 || (side == RIGHT_GLYPHS &&
|
|
3107 extent_end_glyph_layout (XEXTENT (gb->extent)) == layout)))
|
|
3108 {
|
442
|
3109 data.findex = gb->findex;
|
|
3110 data.max_pixpos = data.pixpos + gb->width;
|
|
3111 add_glyph_rune (&data, gb, side, 0, NULL);
|
428
|
3112 count--;
|
|
3113 gb->active = 0;
|
|
3114 }
|
|
3115
|
|
3116 (reverse ? elt-- : elt++);
|
|
3117 }
|
|
3118
|
819
|
3119 calculate_baseline (&data);
|
442
|
3120
|
|
3121 dl->ascent = data.new_ascent;
|
|
3122 dl->descent = data.new_descent;
|
|
3123
|
819
|
3124 calculate_yoffset (dl, data.db);
|
|
3125
|
442
|
3126 return data.pixpos;
|
428
|
3127 }
|
|
3128
|
|
3129 /* Add a blank to a margin display block. */
|
|
3130
|
|
3131 static void
|
2286
|
3132 add_margin_blank (struct display_line *UNUSED (dl), struct display_block *db,
|
428
|
3133 struct window *w, int xpos, int width, int side)
|
|
3134 {
|
|
3135 struct rune rb;
|
|
3136
|
|
3137 rb.findex = (side == LEFT_GLYPHS
|
|
3138 ? get_builtin_face_cache_index (w, Vleft_margin_face)
|
|
3139 : get_builtin_face_cache_index (w, Vright_margin_face));
|
|
3140 rb.xpos = xpos;
|
|
3141 rb.width = width;
|
826
|
3142 rb.charpos = -1;
|
428
|
3143 rb.endpos = 0;
|
|
3144 rb.type = RUNE_BLANK;
|
|
3145 rb.cursor_type = CURSOR_OFF;
|
|
3146
|
|
3147 Dynarr_add (db->runes, rb);
|
|
3148 }
|
|
3149
|
|
3150 /* Display glyphs in the left outside margin, left inside margin and
|
|
3151 left whitespace area. */
|
|
3152
|
|
3153 static void
|
|
3154 create_left_glyph_block (struct window *w, struct display_line *dl,
|
|
3155 int overlay_width)
|
|
3156 {
|
|
3157 Lisp_Object window;
|
|
3158
|
|
3159 int use_overflow = (NILP (w->use_left_overflow) ? 0 : 1);
|
|
3160 int elt, end_xpos;
|
|
3161 int out_end, in_out_start, in_in_end, white_out_start, white_in_start;
|
|
3162 int out_cnt, in_out_cnt, in_in_cnt, white_out_cnt, white_in_cnt;
|
|
3163 int left_in_start = dl->bounds.left_in;
|
|
3164 int left_in_end = dl->bounds.left_in + overlay_width;
|
|
3165
|
|
3166 struct display_block *odb, *idb;
|
|
3167
|
793
|
3168 window = wrap_window (w);
|
428
|
3169
|
|
3170 /* We have to add the glyphs to the line in the order outside,
|
|
3171 inside, whitespace. However the precedence dictates that we
|
|
3172 determine how many will fit in the reverse order. */
|
|
3173
|
|
3174 /* Determine how many whitespace glyphs we can display and where
|
|
3175 they should start. */
|
|
3176 white_in_start = dl->bounds.left_white;
|
|
3177 white_out_start = left_in_start;
|
|
3178 white_out_cnt = white_in_cnt = 0;
|
|
3179 elt = 0;
|
|
3180
|
|
3181 while (elt < Dynarr_length (dl->left_glyphs))
|
|
3182 {
|
|
3183 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt);
|
|
3184
|
|
3185 if (NILP (gb->extent))
|
2500
|
3186 ABORT (); /* these should have been handled in add_glyph_rune */
|
428
|
3187
|
|
3188 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) == GL_WHITESPACE)
|
|
3189 {
|
|
3190 int width;
|
|
3191
|
438
|
3192 width = glyph_width (gb->glyph, window);
|
428
|
3193
|
|
3194 if (white_in_start - width >= left_in_end)
|
|
3195 {
|
|
3196 white_in_cnt++;
|
|
3197 white_in_start -= width;
|
|
3198 gb->width = width;
|
|
3199 gb->active = 1;
|
|
3200 }
|
|
3201 else if (use_overflow
|
|
3202 && (white_out_start - width > dl->bounds.left_out))
|
|
3203 {
|
|
3204 white_out_cnt++;
|
|
3205 white_out_start -= width;
|
|
3206 gb->width = width;
|
|
3207 gb->active = 1;
|
|
3208 }
|
|
3209 else
|
|
3210 gb->active = 0;
|
|
3211 }
|
|
3212
|
|
3213 elt++;
|
|
3214 }
|
|
3215
|
|
3216 /* Determine how many inside margin glyphs we can display and where
|
|
3217 they should start. The inside margin glyphs get whatever space
|
|
3218 is left after the whitespace glyphs have been displayed. These
|
|
3219 are tricky to calculate since if we decide to use the overflow
|
|
3220 area we basically have to start over. So for these we build up a
|
|
3221 list of just the inside margin glyphs and manipulate it to
|
|
3222 determine the needed info. */
|
|
3223 {
|
|
3224 glyph_block_dynarr *ib;
|
|
3225 int avail_in, avail_out;
|
|
3226 int done = 0;
|
|
3227 int marker = 0;
|
|
3228 int used_in, used_out;
|
|
3229
|
|
3230 elt = 0;
|
|
3231 used_in = used_out = 0;
|
|
3232 ib = Dynarr_new (glyph_block);
|
|
3233 while (elt < Dynarr_length (dl->left_glyphs))
|
|
3234 {
|
|
3235 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt);
|
|
3236
|
|
3237 if (NILP (gb->extent))
|
2500
|
3238 ABORT (); /* these should have been handled in add_glyph_rune */
|
428
|
3239
|
|
3240 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) ==
|
|
3241 GL_INSIDE_MARGIN)
|
|
3242 {
|
438
|
3243 gb->width = glyph_width (gb->glyph, window);
|
428
|
3244 used_in += gb->width;
|
|
3245 Dynarr_add (ib, *gb);
|
|
3246 }
|
|
3247
|
|
3248 elt++;
|
|
3249 }
|
|
3250
|
|
3251 if (white_out_cnt)
|
|
3252 avail_in = 0;
|
|
3253 else
|
|
3254 {
|
|
3255 avail_in = white_in_start - left_in_end;
|
|
3256 if (avail_in < 0)
|
|
3257 avail_in = 0;
|
|
3258 }
|
|
3259
|
|
3260 if (!use_overflow)
|
|
3261 avail_out = 0;
|
|
3262 else
|
|
3263 avail_out = white_out_start - dl->bounds.left_out;
|
|
3264
|
|
3265 marker = 0;
|
|
3266 while (!done && marker < Dynarr_length (ib))
|
|
3267 {
|
|
3268 int width = Dynarr_atp (ib, marker)->width;
|
|
3269
|
|
3270 /* If everything now fits in the available inside margin
|
|
3271 space, we're done. */
|
|
3272 if (used_in <= avail_in)
|
|
3273 done = 1;
|
|
3274 else
|
|
3275 {
|
|
3276 /* Otherwise see if we have room to move a glyph to the
|
|
3277 outside. */
|
|
3278 if (used_out + width <= avail_out)
|
|
3279 {
|
|
3280 used_out += width;
|
|
3281 used_in -= width;
|
|
3282 }
|
|
3283 else
|
|
3284 done = 1;
|
|
3285 }
|
|
3286
|
|
3287 if (!done)
|
|
3288 marker++;
|
|
3289 }
|
|
3290
|
|
3291 /* At this point we now know that everything from marker on goes in
|
|
3292 the inside margin and everything before it goes in the outside
|
|
3293 margin. The stuff going into the outside margin is guaranteed
|
|
3294 to fit, but we may have to trim some stuff from the inside. */
|
|
3295
|
|
3296 in_in_end = left_in_end;
|
|
3297 in_out_start = white_out_start;
|
|
3298 in_out_cnt = in_in_cnt = 0;
|
|
3299
|
|
3300 Dynarr_free (ib);
|
|
3301 elt = 0;
|
|
3302 while (elt < Dynarr_length (dl->left_glyphs))
|
|
3303 {
|
|
3304 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt);
|
|
3305
|
|
3306 if (NILP (gb->extent))
|
2500
|
3307 ABORT (); /* these should have been handled in add_glyph_rune */
|
428
|
3308
|
|
3309 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) ==
|
|
3310 GL_INSIDE_MARGIN)
|
|
3311 {
|
438
|
3312 int width = glyph_width (gb->glyph, window);
|
428
|
3313
|
|
3314 if (used_out)
|
|
3315 {
|
|
3316 in_out_cnt++;
|
|
3317 in_out_start -= width;
|
|
3318 gb->width = width;
|
|
3319 gb->active = 1;
|
|
3320 used_out -= width;
|
|
3321 }
|
|
3322 else if (in_in_end + width < white_in_start)
|
|
3323 {
|
|
3324 in_in_cnt++;
|
|
3325 in_in_end += width;
|
|
3326 gb->width = width;
|
|
3327 gb->active = 1;
|
|
3328 }
|
|
3329 else
|
|
3330 gb->active = 0;
|
|
3331 }
|
|
3332
|
|
3333 elt++;
|
|
3334 }
|
|
3335 }
|
|
3336
|
|
3337 /* Determine how many outside margin glyphs we can display. They
|
|
3338 always start at the left outside margin and can only use the
|
|
3339 outside margin space. */
|
|
3340 out_end = dl->bounds.left_out;
|
|
3341 out_cnt = 0;
|
|
3342 elt = 0;
|
|
3343
|
|
3344 while (elt < Dynarr_length (dl->left_glyphs))
|
|
3345 {
|
|
3346 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt);
|
|
3347
|
|
3348 if (NILP (gb->extent))
|
2500
|
3349 ABORT (); /* these should have been handled in add_glyph_rune */
|
428
|
3350
|
|
3351 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) ==
|
|
3352 GL_OUTSIDE_MARGIN)
|
|
3353 {
|
438
|
3354 int width = glyph_width (gb->glyph, window);
|
428
|
3355
|
|
3356 if (out_end + width <= in_out_start)
|
|
3357 {
|
|
3358 out_cnt++;
|
|
3359 out_end += width;
|
|
3360 gb->width = width;
|
|
3361 gb->active = 1;
|
|
3362 }
|
|
3363 else
|
|
3364 gb->active = 0;
|
|
3365 }
|
|
3366
|
|
3367 elt++;
|
|
3368 }
|
|
3369
|
|
3370 /* Now that we know where everything goes, we add the glyphs as
|
|
3371 runes to the appropriate display blocks. */
|
|
3372 if (out_cnt || in_out_cnt || white_out_cnt)
|
|
3373 {
|
|
3374 odb = get_display_block_from_line (dl, LEFT_OUTSIDE_MARGIN);
|
|
3375 odb->start_pos = dl->bounds.left_out;
|
|
3376 /* #### We should stop adding a blank to account for the space
|
|
3377 between the end of the glyphs and the margin and instead set
|
|
3378 this accordingly. */
|
|
3379 odb->end_pos = dl->bounds.left_in;
|
|
3380 Dynarr_reset (odb->runes);
|
|
3381 }
|
|
3382 else
|
|
3383 odb = 0;
|
|
3384
|
|
3385 if (in_in_cnt || white_in_cnt)
|
|
3386 {
|
|
3387 idb = get_display_block_from_line (dl, LEFT_INSIDE_MARGIN);
|
|
3388 idb->start_pos = dl->bounds.left_in;
|
|
3389 /* #### See above comment for odb->end_pos */
|
|
3390 idb->end_pos = dl->bounds.left_white;
|
|
3391 Dynarr_reset (idb->runes);
|
|
3392 }
|
|
3393 else
|
|
3394 idb = 0;
|
|
3395
|
|
3396 /* First add the outside margin glyphs. */
|
|
3397 if (out_cnt)
|
|
3398 end_xpos = add_margin_runes (dl, odb, dl->bounds.left_out, out_cnt,
|
|
3399 GL_OUTSIDE_MARGIN, LEFT_GLYPHS, window);
|
|
3400 else
|
|
3401 end_xpos = dl->bounds.left_out;
|
|
3402
|
|
3403 /* There may be blank space between the outside margin glyphs and
|
|
3404 the inside margin glyphs. If so, add a blank. */
|
|
3405 if (in_out_cnt && (in_out_start - end_xpos))
|
|
3406 {
|
|
3407 add_margin_blank (dl, odb, w, end_xpos, in_out_start - end_xpos,
|
|
3408 LEFT_GLYPHS);
|
|
3409 }
|
|
3410
|
|
3411 /* Next add the inside margin glyphs which are actually in the
|
|
3412 outside margin. */
|
|
3413 if (in_out_cnt)
|
|
3414 {
|
|
3415 end_xpos = add_margin_runes (dl, odb, in_out_start, in_out_cnt,
|
|
3416 GL_INSIDE_MARGIN, LEFT_GLYPHS, window);
|
|
3417 }
|
|
3418
|
|
3419 /* If we didn't add any inside margin glyphs to the outside margin,
|
|
3420 but are adding whitespace glyphs, then we need to add a blank
|
|
3421 here. */
|
|
3422 if (!in_out_cnt && white_out_cnt && (white_out_start - end_xpos))
|
|
3423 {
|
|
3424 add_margin_blank (dl, odb, w, end_xpos, white_out_start - end_xpos,
|
|
3425 LEFT_GLYPHS);
|
|
3426 }
|
|
3427
|
|
3428 /* Next add the whitespace margin glyphs which are actually in the
|
|
3429 outside margin. */
|
|
3430 if (white_out_cnt)
|
|
3431 {
|
|
3432 end_xpos = add_margin_runes (dl, odb, white_out_start, white_out_cnt,
|
|
3433 GL_WHITESPACE, LEFT_GLYPHS, window);
|
|
3434 }
|
|
3435
|
|
3436 /* We take care of clearing between the end of the glyphs and the
|
|
3437 start of the inside margin for lines which have glyphs. */
|
|
3438 if (odb && (left_in_start - end_xpos))
|
|
3439 {
|
|
3440 add_margin_blank (dl, odb, w, end_xpos, left_in_start - end_xpos,
|
|
3441 LEFT_GLYPHS);
|
|
3442 }
|
|
3443
|
|
3444 /* Next add the inside margin glyphs which are actually in the
|
|
3445 inside margin. */
|
|
3446 if (in_in_cnt)
|
|
3447 {
|
|
3448 end_xpos = add_margin_runes (dl, idb, left_in_end, in_in_cnt,
|
|
3449 GL_INSIDE_MARGIN, LEFT_GLYPHS, window);
|
|
3450 }
|
|
3451 else
|
|
3452 end_xpos = left_in_end;
|
|
3453
|
|
3454 /* Make sure that the area between the end of the inside margin
|
|
3455 glyphs and the whitespace glyphs is cleared. */
|
|
3456 if (idb && (white_in_start - end_xpos > 0))
|
|
3457 {
|
|
3458 add_margin_blank (dl, idb, w, end_xpos, white_in_start - end_xpos,
|
|
3459 LEFT_GLYPHS);
|
|
3460 }
|
|
3461
|
|
3462 /* Next add the whitespace margin glyphs which are actually in the
|
|
3463 inside margin. */
|
|
3464 if (white_in_cnt)
|
|
3465 {
|
|
3466 add_margin_runes (dl, idb, white_in_start, white_in_cnt, GL_WHITESPACE,
|
|
3467 LEFT_GLYPHS, window);
|
|
3468 }
|
|
3469
|
|
3470 /* Whitespace glyphs always end right next to the text block so
|
|
3471 there is nothing we have to make sure is cleared after them. */
|
|
3472 }
|
|
3473
|
|
3474 /* Display glyphs in the right outside margin, right inside margin and
|
|
3475 right whitespace area. */
|
|
3476
|
|
3477 static void
|
|
3478 create_right_glyph_block (struct window *w, struct display_line *dl)
|
|
3479 {
|
|
3480 Lisp_Object window;
|
|
3481
|
|
3482 int use_overflow = (NILP (w->use_right_overflow) ? 0 : 1);
|
|
3483 int elt, end_xpos;
|
|
3484 int out_start, in_out_end, in_in_start, white_out_end, white_in_end;
|
|
3485 int out_cnt, in_out_cnt, in_in_cnt, white_out_cnt, white_in_cnt;
|
|
3486
|
|
3487 struct display_block *odb, *idb;
|
|
3488
|
793
|
3489 window = wrap_window (w);
|
428
|
3490
|
|
3491 /* We have to add the glyphs to the line in the order outside,
|
|
3492 inside, whitespace. However the precedence dictates that we
|
|
3493 determine how many will fit in the reverse order. */
|
|
3494
|
|
3495 /* Determine how many whitespace glyphs we can display and where
|
|
3496 they should start. */
|
|
3497 white_in_end = dl->bounds.right_white;
|
|
3498 white_out_end = dl->bounds.right_in;
|
|
3499 white_out_cnt = white_in_cnt = 0;
|
|
3500 elt = 0;
|
|
3501
|
|
3502 while (elt < Dynarr_length (dl->right_glyphs))
|
|
3503 {
|
|
3504 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt);
|
|
3505
|
|
3506 if (NILP (gb->extent))
|
2500
|
3507 ABORT (); /* these should have been handled in add_glyph_rune */
|
428
|
3508
|
|
3509 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_WHITESPACE)
|
|
3510 {
|
438
|
3511 int width = glyph_width (gb->glyph, window);
|
428
|
3512
|
|
3513 if (white_in_end + width <= dl->bounds.right_in)
|
|
3514 {
|
|
3515 white_in_cnt++;
|
|
3516 white_in_end += width;
|
|
3517 gb->width = width;
|
|
3518 gb->active = 1;
|
|
3519 }
|
|
3520 else if (use_overflow
|
|
3521 && (white_out_end + width <= dl->bounds.right_out))
|
|
3522 {
|
|
3523 white_out_cnt++;
|
|
3524 white_out_end += width;
|
|
3525 gb->width = width;
|
|
3526 gb->active = 1;
|
|
3527 }
|
|
3528 else
|
|
3529 gb->active = 0;
|
|
3530 }
|
|
3531
|
|
3532 elt++;
|
|
3533 }
|
|
3534
|
|
3535 /* Determine how many inside margin glyphs we can display and where
|
|
3536 they should start. The inside margin glyphs get whatever space
|
|
3537 is left after the whitespace glyphs have been displayed. These
|
|
3538 are tricky to calculate since if we decide to use the overflow
|
|
3539 area we basically have to start over. So for these we build up a
|
|
3540 list of just the inside margin glyphs and manipulate it to
|
|
3541 determine the needed info. */
|
|
3542 {
|
|
3543 glyph_block_dynarr *ib;
|
|
3544 int avail_in, avail_out;
|
|
3545 int done = 0;
|
|
3546 int marker = 0;
|
|
3547 int used_in, used_out;
|
|
3548
|
|
3549 elt = 0;
|
|
3550 used_in = used_out = 0;
|
|
3551 ib = Dynarr_new (glyph_block);
|
|
3552 while (elt < Dynarr_length (dl->right_glyphs))
|
|
3553 {
|
|
3554 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt);
|
|
3555
|
|
3556 if (NILP (gb->extent))
|
2500
|
3557 ABORT (); /* these should have been handled in add_glyph_rune */
|
428
|
3558
|
|
3559 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_INSIDE_MARGIN)
|
|
3560 {
|
438
|
3561 gb->width = glyph_width (gb->glyph, window);
|
428
|
3562 used_in += gb->width;
|
|
3563 Dynarr_add (ib, *gb);
|
|
3564 }
|
|
3565
|
|
3566 elt++;
|
|
3567 }
|
|
3568
|
|
3569 if (white_out_cnt)
|
|
3570 avail_in = 0;
|
|
3571 else
|
|
3572 avail_in = dl->bounds.right_in - white_in_end;
|
|
3573
|
|
3574 if (!use_overflow)
|
|
3575 avail_out = 0;
|
|
3576 else
|
|
3577 avail_out = dl->bounds.right_out - white_out_end;
|
|
3578
|
|
3579 marker = 0;
|
|
3580 while (!done && marker < Dynarr_length (ib))
|
|
3581 {
|
|
3582 int width = Dynarr_atp (ib, marker)->width;
|
|
3583
|
|
3584 /* If everything now fits in the available inside margin
|
|
3585 space, we're done. */
|
|
3586 if (used_in <= avail_in)
|
|
3587 done = 1;
|
|
3588 else
|
|
3589 {
|
|
3590 /* Otherwise see if we have room to move a glyph to the
|
|
3591 outside. */
|
|
3592 if (used_out + width <= avail_out)
|
|
3593 {
|
|
3594 used_out += width;
|
|
3595 used_in -= width;
|
|
3596 }
|
|
3597 else
|
|
3598 done = 1;
|
|
3599 }
|
|
3600
|
|
3601 if (!done)
|
|
3602 marker++;
|
|
3603 }
|
|
3604
|
|
3605 /* At this point we now know that everything from marker on goes in
|
|
3606 the inside margin and everything before it goes in the outside
|
|
3607 margin. The stuff going into the outside margin is guaranteed
|
|
3608 to fit, but we may have to trim some stuff from the inside. */
|
|
3609
|
|
3610 in_in_start = dl->bounds.right_in;
|
|
3611 in_out_end = dl->bounds.right_in;
|
|
3612 in_out_cnt = in_in_cnt = 0;
|
|
3613
|
|
3614 Dynarr_free (ib);
|
|
3615 elt = 0;
|
|
3616 while (elt < Dynarr_length (dl->right_glyphs))
|
|
3617 {
|
|
3618 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt);
|
|
3619
|
|
3620 if (NILP (gb->extent))
|
2500
|
3621 ABORT (); /* these should have been handled in add_glyph_rune */
|
428
|
3622
|
|
3623 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_INSIDE_MARGIN)
|
|
3624 {
|
438
|
3625 int width = glyph_width (gb->glyph, window);
|
428
|
3626
|
|
3627 if (used_out)
|
|
3628 {
|
|
3629 in_out_cnt++;
|
|
3630 in_out_end += width;
|
|
3631 gb->width = width;
|
|
3632 gb->active = 1;
|
|
3633 used_out -= width;
|
|
3634 }
|
|
3635 else if (in_in_start - width >= white_in_end)
|
|
3636 {
|
|
3637 in_in_cnt++;
|
|
3638 in_in_start -= width;
|
|
3639 gb->width = width;
|
|
3640 gb->active = 1;
|
|
3641 }
|
|
3642 else
|
|
3643 gb->active = 0;
|
|
3644 }
|
|
3645
|
|
3646 elt++;
|
|
3647 }
|
|
3648 }
|
|
3649
|
|
3650 /* Determine how many outside margin glyphs we can display. They
|
|
3651 always start at the right outside margin and can only use the
|
|
3652 outside margin space. */
|
|
3653 out_start = dl->bounds.right_out;
|
|
3654 out_cnt = 0;
|
|
3655 elt = 0;
|
|
3656
|
|
3657 while (elt < Dynarr_length (dl->right_glyphs))
|
|
3658 {
|
|
3659 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt);
|
|
3660
|
|
3661 if (NILP (gb->extent))
|
2500
|
3662 ABORT (); /* these should have been handled in add_glyph_rune */
|
428
|
3663
|
|
3664 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_OUTSIDE_MARGIN)
|
|
3665 {
|
438
|
3666 int width = glyph_width (gb->glyph, window);
|
428
|
3667
|
|
3668 if (out_start - width >= in_out_end)
|
|
3669 {
|
|
3670 out_cnt++;
|
|
3671 out_start -= width;
|
|
3672 gb->width = width;
|
|
3673 gb->active = 1;
|
|
3674 }
|
|
3675 else
|
|
3676 gb->active = 0;
|
|
3677 }
|
|
3678
|
|
3679 elt++;
|
|
3680 }
|
|
3681
|
|
3682 /* Now that we now where everything goes, we add the glyphs as runes
|
|
3683 to the appropriate display blocks. */
|
|
3684 if (out_cnt || in_out_cnt || white_out_cnt)
|
|
3685 {
|
|
3686 odb = get_display_block_from_line (dl, RIGHT_OUTSIDE_MARGIN);
|
|
3687 /* #### See comments before odb->start_pos init in
|
|
3688 create_left_glyph_block */
|
|
3689 odb->start_pos = dl->bounds.right_in;
|
|
3690 odb->end_pos = dl->bounds.right_out;
|
|
3691 Dynarr_reset (odb->runes);
|
|
3692 }
|
|
3693 else
|
|
3694 odb = 0;
|
|
3695
|
|
3696 if (in_in_cnt || white_in_cnt)
|
|
3697 {
|
|
3698 idb = get_display_block_from_line (dl, RIGHT_INSIDE_MARGIN);
|
|
3699 idb->start_pos = dl->bounds.right_white;
|
|
3700 /* #### See comments before odb->start_pos init in
|
|
3701 create_left_glyph_block */
|
|
3702 idb->end_pos = dl->bounds.right_in;
|
|
3703 Dynarr_reset (idb->runes);
|
|
3704 }
|
|
3705 else
|
|
3706 idb = 0;
|
|
3707
|
|
3708 /* First add the whitespace margin glyphs which are actually in the
|
|
3709 inside margin. */
|
|
3710 if (white_in_cnt)
|
|
3711 {
|
|
3712 end_xpos = add_margin_runes (dl, idb, dl->bounds.right_white,
|
|
3713 white_in_cnt, GL_WHITESPACE, RIGHT_GLYPHS,
|
|
3714 window);
|
|
3715 }
|
|
3716 else
|
|
3717 end_xpos = dl->bounds.right_white;
|
|
3718
|
|
3719 /* Make sure that the area between the end of the whitespace glyphs
|
|
3720 and the inside margin glyphs is cleared. */
|
|
3721 if (in_in_cnt && (in_in_start - end_xpos))
|
|
3722 {
|
|
3723 add_margin_blank (dl, idb, w, end_xpos, in_in_start - end_xpos,
|
|
3724 RIGHT_GLYPHS);
|
|
3725 }
|
|
3726
|
|
3727 /* Next add the inside margin glyphs which are actually in the
|
|
3728 inside margin. */
|
|
3729 if (in_in_cnt)
|
|
3730 {
|
|
3731 end_xpos = add_margin_runes (dl, idb, in_in_start, in_in_cnt,
|
|
3732 GL_INSIDE_MARGIN, RIGHT_GLYPHS, window);
|
|
3733 }
|
|
3734
|
|
3735 /* If we didn't add any inside margin glyphs then make sure the rest
|
|
3736 of the inside margin area gets cleared. */
|
|
3737 if (idb && (dl->bounds.right_in - end_xpos))
|
|
3738 {
|
|
3739 add_margin_blank (dl, idb, w, end_xpos, dl->bounds.right_in - end_xpos,
|
|
3740 RIGHT_GLYPHS);
|
|
3741 }
|
|
3742
|
|
3743 /* Next add any whitespace glyphs in the outside margin. */
|
|
3744 if (white_out_cnt)
|
|
3745 {
|
|
3746 end_xpos = add_margin_runes (dl, odb, dl->bounds.right_in, white_out_cnt,
|
|
3747 GL_WHITESPACE, RIGHT_GLYPHS, window);
|
|
3748 }
|
|
3749 else
|
|
3750 end_xpos = dl->bounds.right_in;
|
|
3751
|
|
3752 /* Next add any inside margin glyphs in the outside margin. */
|
|
3753 if (in_out_cnt)
|
|
3754 {
|
|
3755 end_xpos = add_margin_runes (dl, odb, end_xpos, in_out_cnt,
|
|
3756 GL_INSIDE_MARGIN, RIGHT_GLYPHS, window);
|
|
3757 }
|
|
3758
|
|
3759 /* There may be space between any whitespace or inside margin glyphs
|
|
3760 in the outside margin and the actual outside margin glyphs. */
|
|
3761 if (odb && (out_start - end_xpos))
|
|
3762 {
|
|
3763 add_margin_blank (dl, odb, w, end_xpos, out_start - end_xpos,
|
|
3764 RIGHT_GLYPHS);
|
|
3765 }
|
|
3766
|
|
3767 /* Finally, add the outside margin glyphs. */
|
|
3768 if (out_cnt)
|
|
3769 {
|
|
3770 add_margin_runes (dl, odb, out_start, out_cnt, GL_OUTSIDE_MARGIN,
|
|
3771 RIGHT_GLYPHS, window);
|
|
3772 }
|
|
3773 }
|
|
3774
|
|
3775
|
|
3776 /***************************************************************************/
|
|
3777 /* */
|
|
3778 /* modeline routines */
|
|
3779 /* */
|
|
3780 /***************************************************************************/
|
|
3781
|
438
|
3782 /* This function is also used in frame.c by `generate_title_string' */
|
|
3783 void
|
|
3784 generate_formatted_string_db (Lisp_Object format_str, Lisp_Object result_str,
|
|
3785 struct window *w, struct display_line *dl,
|
|
3786 struct display_block *db, face_index findex,
|
|
3787 int min_pixpos, int max_pixpos, int type)
|
|
3788 {
|
|
3789 struct frame *f = XFRAME (w->frame);
|
|
3790 struct device *d = XDEVICE (f->device);
|
|
3791
|
|
3792 pos_data data;
|
|
3793 int c_pixpos;
|
|
3794 Charcount offset = 0;
|
|
3795
|
|
3796 xzero (data);
|
|
3797 data.d = d;
|
|
3798 data.db = db;
|
|
3799 data.dl = dl;
|
|
3800 data.findex = findex;
|
|
3801 data.pixpos = min_pixpos;
|
|
3802 data.max_pixpos = max_pixpos;
|
|
3803 data.cursor_type = NO_CURSOR;
|
|
3804 data.last_charset = Qunbound;
|
|
3805 data.last_findex = DEFAULT_INDEX;
|
|
3806 data.result_str = result_str;
|
|
3807 data.is_modeline = 1;
|
|
3808 data.string = Qnil;
|
793
|
3809 data.window = wrap_window (w);
|
438
|
3810
|
|
3811 Dynarr_reset (formatted_string_extent_dynarr);
|
|
3812 Dynarr_reset (formatted_string_extent_start_dynarr);
|
|
3813 Dynarr_reset (formatted_string_extent_end_dynarr);
|
|
3814
|
|
3815 /* result_str is nil when we're building a frame or icon title. Otherwise,
|
|
3816 we're building a modeline, so the offset starts at the modeline
|
442
|
3817 horizontal scrolling amount */
|
438
|
3818 if (! NILP (result_str))
|
|
3819 offset = w->modeline_hscroll;
|
|
3820 generate_fstring_runes (w, &data, 0, 0, -1, format_str, 0,
|
|
3821 max_pixpos - min_pixpos, findex, type, &offset,
|
|
3822 Qnil);
|
|
3823
|
|
3824 if (Dynarr_length (db->runes))
|
|
3825 {
|
|
3826 struct rune *rb =
|
|
3827 Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
|
|
3828 c_pixpos = rb->xpos + rb->width;
|
|
3829 }
|
|
3830 else
|
|
3831 c_pixpos = min_pixpos;
|
|
3832
|
|
3833 /* If we don't reach the right side of the window, add a blank rune
|
|
3834 to make up the difference. This usually only occurs if the
|
|
3835 modeline face is using a proportional width font or a fixed width
|
|
3836 font of a different size from the default face font. */
|
|
3837
|
|
3838 if (c_pixpos < max_pixpos)
|
|
3839 {
|
|
3840 data.pixpos = c_pixpos;
|
|
3841 data.blank_width = max_pixpos - data.pixpos;
|
|
3842
|
|
3843 add_blank_rune (&data, NULL, 0);
|
|
3844 }
|
|
3845
|
|
3846 /* Now create the result string and frob the extents into it. */
|
|
3847 if (!NILP (result_str))
|
|
3848 {
|
|
3849 int elt;
|
|
3850 Bytecount len;
|
867
|
3851 Ibyte *strdata;
|
438
|
3852 struct buffer *buf = XBUFFER (WINDOW_BUFFER (w));
|
|
3853
|
442
|
3854 in_modeline_generation = 1;
|
|
3855
|
771
|
3856 sledgehammer_check_ascii_begin (result_str);
|
438
|
3857 detach_all_extents (result_str);
|
793
|
3858 resize_string (result_str, -1,
|
438
|
3859 data.bytepos - XSTRING_LENGTH (result_str));
|
|
3860
|
|
3861 strdata = XSTRING_DATA (result_str);
|
|
3862
|
|
3863 for (elt = 0, len = 0; elt < Dynarr_length (db->runes); elt++)
|
|
3864 {
|
|
3865 if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR)
|
|
3866 {
|
867
|
3867 len += (set_itext_ichar
|
438
|
3868 (strdata + len, Dynarr_atp (db->runes,
|
|
3869 elt)->object.chr.ch));
|
|
3870 }
|
|
3871 }
|
|
3872
|
771
|
3873 init_string_ascii_begin (result_str);
|
|
3874 bump_string_modiff (result_str);
|
|
3875 sledgehammer_check_ascii_begin (result_str);
|
|
3876
|
438
|
3877 for (elt = 0; elt < Dynarr_length (formatted_string_extent_dynarr);
|
|
3878 elt++)
|
|
3879 {
|
|
3880 Lisp_Object extent = Qnil;
|
|
3881 Lisp_Object child;
|
|
3882
|
793
|
3883 extent = wrap_extent (Dynarr_at (formatted_string_extent_dynarr, elt));
|
438
|
3884 child = Fgethash (extent, buf->modeline_extent_table, Qnil);
|
|
3885 if (NILP (child))
|
|
3886 {
|
|
3887 child = Fmake_extent (Qnil, Qnil, result_str);
|
|
3888 Fputhash (extent, child, buf->modeline_extent_table);
|
|
3889 }
|
|
3890 Fset_extent_parent (child, extent);
|
|
3891 set_extent_endpoints
|
|
3892 (XEXTENT (child),
|
|
3893 Dynarr_at (formatted_string_extent_start_dynarr, elt),
|
|
3894 Dynarr_at (formatted_string_extent_end_dynarr, elt),
|
|
3895 result_str);
|
|
3896 }
|
442
|
3897
|
|
3898 in_modeline_generation = 0;
|
438
|
3899 }
|
|
3900 }
|
|
3901
|
428
|
3902 /* Ensure that the given display line DL accurately represents the
|
|
3903 modeline for the given window. */
|
|
3904 static void
|
|
3905 generate_modeline (struct window *w, struct display_line *dl, int type)
|
|
3906 {
|
|
3907 struct buffer *b = XBUFFER (w->buffer);
|
|
3908 struct frame *f = XFRAME (w->frame);
|
|
3909 struct device *d = XDEVICE (f->device);
|
|
3910
|
|
3911 /* Unlike display line and rune pointers, this one can't change underneath
|
|
3912 our feet. */
|
|
3913 struct display_block *db = get_display_block_from_line (dl, TEXT);
|
|
3914 int max_pixpos, min_pixpos, ypos_adj;
|
|
3915 Lisp_Object font_inst;
|
|
3916
|
|
3917 /* This will actually determine incorrect inside boundaries for the
|
|
3918 modeline since it ignores the margins. However being aware of this fact
|
|
3919 we never use those values anywhere so it doesn't matter. */
|
|
3920 dl->bounds = calculate_display_line_boundaries (w, 1);
|
|
3921
|
|
3922 /* We are generating a modeline. */
|
|
3923 dl->modeline = 1;
|
|
3924 dl->cursor_elt = -1;
|
|
3925
|
|
3926 /* Reset the runes on the modeline. */
|
|
3927 Dynarr_reset (db->runes);
|
|
3928
|
|
3929 if (!WINDOW_HAS_MODELINE_P (w))
|
|
3930 {
|
|
3931 struct rune rb;
|
|
3932
|
|
3933 /* If there is a horizontal scrollbar, don't add anything. */
|
|
3934 if (window_scrollbar_height (w))
|
|
3935 return;
|
|
3936
|
|
3937 dl->ascent = DEVMETH (d, divider_height, ());
|
|
3938 dl->descent = 0;
|
|
3939 /* The modeline is at the bottom of the gutters. */
|
|
3940 dl->ypos = WINDOW_BOTTOM (w);
|
|
3941
|
|
3942 rb.findex = MODELINE_INDEX;
|
|
3943 rb.xpos = dl->bounds.left_out;
|
|
3944 rb.width = dl->bounds.right_out - dl->bounds.left_out;
|
826
|
3945 rb.charpos = 0;
|
428
|
3946 rb.endpos = 0;
|
|
3947 rb.type = RUNE_HLINE;
|
|
3948 rb.object.hline.thickness = 1;
|
|
3949 rb.object.hline.yoffset = 0;
|
|
3950 rb.cursor_type = NO_CURSOR;
|
|
3951
|
|
3952 if (!EQ (Qzero, w->modeline_shadow_thickness)
|
|
3953 && FRAME_WIN_P (f))
|
|
3954 {
|
|
3955 int shadow_thickness = MODELINE_SHADOW_THICKNESS (w);
|
|
3956
|
|
3957 dl->ypos -= shadow_thickness;
|
|
3958 rb.xpos += shadow_thickness;
|
|
3959 rb.width -= 2 * shadow_thickness;
|
|
3960 }
|
|
3961
|
|
3962 Dynarr_add (db->runes, rb);
|
|
3963 return;
|
|
3964 }
|
|
3965
|
|
3966 /* !!#### not right; needs to compute the max height of
|
|
3967 all the charsets */
|
|
3968 font_inst = WINDOW_FACE_CACHEL_FONT (w, MODELINE_INDEX, Vcharset_ascii);
|
|
3969
|
|
3970 dl->ascent = XFONT_INSTANCE (font_inst)->ascent;
|
|
3971 dl->descent = XFONT_INSTANCE (font_inst)->descent;
|
|
3972
|
|
3973 min_pixpos = dl->bounds.left_out;
|
|
3974 max_pixpos = dl->bounds.right_out;
|
|
3975
|
|
3976 if (!EQ (Qzero, w->modeline_shadow_thickness) && FRAME_WIN_P (f))
|
|
3977 {
|
|
3978 int shadow_thickness = MODELINE_SHADOW_THICKNESS (w);
|
|
3979
|
|
3980 ypos_adj = shadow_thickness;
|
|
3981 min_pixpos += shadow_thickness;
|
|
3982 max_pixpos -= shadow_thickness;
|
|
3983 }
|
|
3984 else
|
|
3985 ypos_adj = 0;
|
|
3986
|
|
3987 generate_formatted_string_db (b->modeline_format,
|
|
3988 b->generated_modeline_string, w, dl, db,
|
|
3989 MODELINE_INDEX, min_pixpos, max_pixpos, type);
|
|
3990
|
|
3991 /* The modeline is at the bottom of the gutters. We have to wait to
|
|
3992 set this until we've generated the modeline in order to account
|
|
3993 for any embedded faces. */
|
|
3994 dl->ypos = WINDOW_BOTTOM (w) - dl->descent - ypos_adj;
|
|
3995 }
|
|
3996
|
|
3997 static Charcount
|
867
|
3998 add_string_to_fstring_db_runes (pos_data *data, const Ibyte *str,
|
771
|
3999 Charcount pos, Charcount min_pos,
|
|
4000 Charcount max_pos)
|
428
|
4001 {
|
|
4002 /* This function has been Mule-ized. */
|
|
4003 Charcount end;
|
867
|
4004 const Ibyte *cur_pos = str;
|
428
|
4005 struct display_block *db = data->db;
|
|
4006
|
|
4007 data->blank_width = space_width (XWINDOW (data->window));
|
|
4008 while (Dynarr_length (db->runes) < pos)
|
|
4009 add_blank_rune (data, NULL, 0);
|
|
4010
|
|
4011 end = (Dynarr_length (db->runes) +
|
442
|
4012 bytecount_to_charcount (str, strlen ((const char *) str)));
|
428
|
4013 if (max_pos != -1)
|
|
4014 end = min (max_pos, end);
|
|
4015
|
|
4016 while (pos < end && *cur_pos)
|
|
4017 {
|
867
|
4018 const Ibyte *old_cur_pos = cur_pos;
|
428
|
4019 int succeeded;
|
|
4020
|
867
|
4021 data->ch = itext_ichar (cur_pos);
|
|
4022 succeeded = (add_ichar_rune (data) != ADD_FAILED);
|
|
4023 INC_IBYTEPTR (cur_pos);
|
428
|
4024 if (succeeded)
|
|
4025 {
|
|
4026 pos++;
|
|
4027 data->modeline_charpos++;
|
|
4028 data->bytepos += cur_pos - old_cur_pos;
|
|
4029 }
|
|
4030 }
|
|
4031
|
|
4032 while (Dynarr_length (db->runes) < min_pos &&
|
|
4033 (data->pixpos + data->blank_width <= data->max_pixpos))
|
|
4034 add_blank_rune (data, NULL, 0);
|
|
4035
|
|
4036 return Dynarr_length (db->runes);
|
|
4037 }
|
|
4038
|
|
4039 /* #### Urk! Should also handle begin-glyphs and end-glyphs in
|
|
4040 modeline extents. */
|
|
4041 static Charcount
|
|
4042 add_glyph_to_fstring_db_runes (pos_data *data, Lisp_Object glyph,
|
2286
|
4043 Charcount pos, Charcount UNUSED (min_pos),
|
438
|
4044 Charcount max_pos, Lisp_Object extent)
|
428
|
4045 {
|
|
4046 /* This function has been Mule-ized. */
|
|
4047 Charcount end;
|
|
4048 struct display_block *db = data->db;
|
|
4049 struct glyph_block gb;
|
|
4050
|
|
4051 data->blank_width = space_width (XWINDOW (data->window));
|
|
4052 while (Dynarr_length (db->runes) < pos)
|
|
4053 add_blank_rune (data, NULL, 0);
|
|
4054
|
|
4055 end = Dynarr_length (db->runes) + 1;
|
|
4056 if (max_pos != -1)
|
|
4057 end = min (max_pos, end);
|
|
4058
|
|
4059 gb.glyph = glyph;
|
438
|
4060 gb.extent = extent;
|
428
|
4061 add_glyph_rune (data, &gb, BEGIN_GLYPHS, 0, 0);
|
|
4062 pos++;
|
|
4063
|
|
4064 while (Dynarr_length (db->runes) < pos &&
|
|
4065 (data->pixpos + data->blank_width <= data->max_pixpos))
|
|
4066 add_blank_rune (data, NULL, 0);
|
|
4067
|
|
4068 return Dynarr_length (db->runes);
|
|
4069 }
|
|
4070
|
|
4071 /* If max_pos is == -1, it is considered to be infinite. The same is
|
|
4072 true of max_pixsize. */
|
|
4073 #define SET_CURRENT_MODE_CHARS_PIXSIZE \
|
|
4074 if (Dynarr_length (data->db->runes)) \
|
|
4075 cur_pixsize = data->pixpos - Dynarr_atp (data->db->runes, 0)->xpos; \
|
|
4076 else \
|
|
4077 cur_pixsize = 0;
|
|
4078
|
|
4079 /* Note that this function does "positions" in terms of characters and
|
|
4080 not in terms of columns. This is necessary to make the formatting
|
|
4081 work correctly when proportional width fonts are used in the
|
|
4082 modeline. */
|
|
4083 static Charcount
|
|
4084 generate_fstring_runes (struct window *w, pos_data *data, Charcount pos,
|
|
4085 Charcount min_pos, Charcount max_pos,
|
|
4086 Lisp_Object elt, int depth, int max_pixsize,
|
438
|
4087 face_index findex, int type, Charcount *offset,
|
|
4088 Lisp_Object cur_ext)
|
428
|
4089 {
|
|
4090 /* This function has been Mule-ized. */
|
|
4091 /* #### The other losing things in this function are:
|
|
4092
|
|
4093 -- C zero-terminated-string lossage.
|
|
4094 -- Non-printable characters should be converted into something
|
|
4095 appropriate (e.g. ^F) instead of blindly being printed anyway.
|
|
4096 */
|
|
4097
|
|
4098 tail_recurse:
|
|
4099 if (depth > 10)
|
|
4100 goto invalid;
|
|
4101
|
|
4102 depth++;
|
|
4103
|
|
4104 if (STRINGP (elt))
|
|
4105 {
|
|
4106 /* A string. Add to the display line and check for %-constructs
|
|
4107 within it. */
|
|
4108
|
2552
|
4109 Ibyte *this_str = XSTRING_DATA (elt);
|
|
4110
|
|
4111 while ((pos < max_pos || max_pos == -1) && *this_str)
|
428
|
4112 {
|
2552
|
4113 Ibyte *last = this_str;
|
|
4114
|
|
4115 while (*this_str && *this_str != '%')
|
|
4116 this_str++;
|
|
4117
|
|
4118 if (this_str != last)
|
428
|
4119 {
|
438
|
4120 /* No %-construct */
|
428
|
4121 Charcount size =
|
2552
|
4122 bytecount_to_charcount (last, this_str - last);
|
438
|
4123
|
|
4124 if (size <= *offset)
|
|
4125 *offset -= size;
|
|
4126 else
|
|
4127 {
|
|
4128 Charcount tmp_max = (max_pos == -1 ? pos + size - *offset :
|
|
4129 min (pos + size - *offset, max_pos));
|
867
|
4130 const Ibyte *tmp_last = itext_n_addr (last, *offset);
|
438
|
4131
|
|
4132 pos = add_string_to_fstring_db_runes (data, tmp_last,
|
|
4133 pos, pos, tmp_max);
|
|
4134 *offset = 0;
|
|
4135 }
|
428
|
4136 }
|
2552
|
4137 else /* *this_str == '%' */
|
428
|
4138 {
|
|
4139 Charcount spec_width = 0;
|
|
4140
|
2552
|
4141 this_str++; /* skip over '%' */
|
428
|
4142
|
|
4143 /* We can't allow -ve args due to the "%-" construct.
|
|
4144 * Argument specifies minwidth but not maxwidth
|
|
4145 * (maxwidth can be specified by
|
|
4146 * (<negative-number> . <stuff>) modeline elements)
|
|
4147 */
|
2552
|
4148 while (isdigit (*this_str))
|
428
|
4149 {
|
2552
|
4150 spec_width = spec_width * 10 + (*this_str - '0');
|
|
4151 this_str++;
|
428
|
4152 }
|
|
4153 spec_width += pos;
|
|
4154
|
2552
|
4155 if (*this_str == 'M')
|
428
|
4156 {
|
|
4157 pos = generate_fstring_runes (w, data, pos, spec_width,
|
|
4158 max_pos, Vglobal_mode_string,
|
|
4159 depth, max_pixsize, findex,
|
438
|
4160 type, offset, cur_ext);
|
428
|
4161 }
|
2552
|
4162 else if (*this_str == '-')
|
428
|
4163 {
|
|
4164 Charcount num_to_add;
|
|
4165
|
|
4166 if (max_pixsize < 0)
|
|
4167 num_to_add = 0;
|
|
4168 else if (max_pos != -1)
|
|
4169 num_to_add = max_pos - pos;
|
|
4170 else
|
|
4171 {
|
|
4172 int cur_pixsize;
|
|
4173 int dash_pixsize;
|
867
|
4174 Ibyte ch = '-';
|
428
|
4175 SET_CURRENT_MODE_CHARS_PIXSIZE;
|
|
4176
|
|
4177 dash_pixsize =
|
|
4178 redisplay_text_width_string (w, findex, &ch, Qnil, 0,
|
|
4179 1);
|
|
4180
|
|
4181 num_to_add = (max_pixsize - cur_pixsize) / dash_pixsize;
|
|
4182 num_to_add++;
|
|
4183 }
|
|
4184
|
|
4185 while (num_to_add--)
|
|
4186 pos = add_string_to_fstring_db_runes
|
867
|
4187 (data, (const Ibyte *) "-", pos, pos, max_pos);
|
428
|
4188 }
|
2552
|
4189 else if (*this_str != 0)
|
428
|
4190 {
|
2552
|
4191 Ichar ch = itext_ichar (this_str);
|
867
|
4192 Ibyte *str;
|
438
|
4193 Charcount size;
|
|
4194
|
428
|
4195 decode_mode_spec (w, ch, type);
|
|
4196
|
867
|
4197 str = Dynarr_atp (mode_spec_ibyte_string, 0);
|
438
|
4198 size = bytecount_to_charcount
|
|
4199 /* Skip the null character added by `decode_mode_spec' */
|
867
|
4200 (str, Dynarr_length (mode_spec_ibyte_string)) - 1;
|
438
|
4201
|
|
4202 if (size <= *offset)
|
|
4203 *offset -= size;
|
|
4204 else
|
|
4205 {
|
867
|
4206 const Ibyte *tmp_str = itext_n_addr (str, *offset);
|
438
|
4207
|
440
|
4208 /* #### NOTE: I don't understand why a tmp_max is not
|
438
|
4209 computed and used here as in the plain string case
|
|
4210 above. -- dv */
|
|
4211 pos = add_string_to_fstring_db_runes (data, tmp_str,
|
|
4212 pos, pos,
|
|
4213 max_pos);
|
|
4214 *offset = 0;
|
|
4215 }
|
428
|
4216 }
|
|
4217
|
2552
|
4218 /* NOT this_str++. There could be any sort of character at
|
428
|
4219 the current position. */
|
2552
|
4220 INC_IBYTEPTR (this_str);
|
428
|
4221 }
|
|
4222
|
|
4223 if (max_pixsize > 0)
|
|
4224 {
|
|
4225 int cur_pixsize;
|
|
4226 SET_CURRENT_MODE_CHARS_PIXSIZE;
|
|
4227
|
|
4228 if (cur_pixsize >= max_pixsize)
|
|
4229 break;
|
|
4230 }
|
|
4231 }
|
|
4232 }
|
|
4233 else if (SYMBOLP (elt))
|
|
4234 {
|
|
4235 /* A symbol: process the value of the symbol recursively
|
|
4236 as if it appeared here directly. */
|
|
4237 Lisp_Object tem = symbol_value_in_buffer (elt, w->buffer);
|
|
4238
|
|
4239 if (!UNBOUNDP (tem))
|
|
4240 {
|
438
|
4241 /* If value is a string, output that string literally:
|
428
|
4242 don't check for % within it. */
|
|
4243 if (STRINGP (tem))
|
|
4244 {
|
867
|
4245 Ibyte *str = XSTRING_DATA (tem);
|
826
|
4246 Charcount size = string_char_length (tem);
|
438
|
4247
|
|
4248 if (size <= *offset)
|
|
4249 *offset -= size;
|
|
4250 else
|
|
4251 {
|
867
|
4252 const Ibyte *tmp_str = itext_n_addr (str, *offset);
|
438
|
4253
|
440
|
4254 /* #### NOTE: I don't understand why a tmp_max is not
|
438
|
4255 computed and used here as in the plain string case
|
|
4256 above. -- dv */
|
|
4257 pos = add_string_to_fstring_db_runes (data, tmp_str, pos,
|
|
4258 min_pos, max_pos);
|
|
4259 *offset = 0;
|
|
4260 }
|
428
|
4261 }
|
|
4262 /* Give up right away for nil or t. */
|
|
4263 else if (!EQ (tem, elt))
|
|
4264 {
|
|
4265 elt = tem;
|
|
4266 goto tail_recurse;
|
|
4267 }
|
|
4268 }
|
|
4269 }
|
|
4270 else if (GENERIC_SPECIFIERP (elt))
|
|
4271 {
|
|
4272 Lisp_Object window, tem;
|
793
|
4273 window = wrap_window (w);
|
428
|
4274 tem = specifier_instance_no_quit (elt, Qunbound, window,
|
793
|
4275 ERROR_ME_DEBUG_WARN, 0, Qzero);
|
428
|
4276 if (!UNBOUNDP (tem))
|
|
4277 {
|
|
4278 elt = tem;
|
|
4279 goto tail_recurse;
|
|
4280 }
|
|
4281 }
|
|
4282 else if (CONSP (elt))
|
|
4283 {
|
|
4284 /* A cons cell: four distinct cases.
|
438
|
4285 * - If first element is a string or a cons, process all the elements
|
|
4286 * and effectively concatenate them.
|
|
4287 * - If first element is a negative number, truncate displaying cdr to
|
|
4288 * at most that many characters. If positive, pad (with spaces)
|
|
4289 * to at least that many characters.
|
771
|
4290 * - If first element is another symbol or a boolean specifier, process
|
|
4291 * the cadr or caddr recursively according to whether the symbol's
|
|
4292 * value or specifier's instance is non-nil or nil.
|
|
4293 * - If first element is , process the cadr or caddr
|
|
4294 * recursively according to whether the instance of the specifier in
|
|
4295 * the modeline's window is non-nil or nil.
|
442
|
4296 * - If first element is an extent, process the cdr recursively
|
|
4297 * and handle the extent's face.
|
428
|
4298 */
|
438
|
4299
|
428
|
4300 Lisp_Object car, tem;
|
|
4301
|
|
4302 car = XCAR (elt);
|
771
|
4303 if (SYMBOLP (car) || BOOLEAN_SPECIFIERP (car))
|
438
|
4304 {
|
|
4305 elt = XCDR (elt);
|
|
4306 if (!CONSP (elt))
|
|
4307 goto invalid;
|
|
4308
|
771
|
4309 if (SYMBOLP (car))
|
|
4310 tem = symbol_value_in_buffer (car, w->buffer);
|
|
4311 else
|
|
4312 tem = specifier_instance_no_quit (car, Qunbound, wrap_window (w),
|
793
|
4313 ERROR_ME_DEBUG_WARN, 0, Qzero);
|
438
|
4314 /* elt is now the cdr, and we know it is a cons cell.
|
|
4315 Use its car if CAR has a non-nil value. */
|
771
|
4316 if (!UNBOUNDP (tem) && !NILP (tem))
|
438
|
4317 {
|
771
|
4318 elt = XCAR (elt);
|
|
4319 goto tail_recurse;
|
438
|
4320 }
|
771
|
4321 /* Symbol's value or specifier's instance is nil or unbound
|
438
|
4322 * Get the cddr of the original list
|
|
4323 * and if possible find the caddr and use that.
|
|
4324 */
|
|
4325 elt = XCDR (elt);
|
|
4326 if (NILP (elt))
|
|
4327 ;
|
|
4328 else if (!CONSP (elt))
|
|
4329 goto invalid;
|
|
4330 else
|
|
4331 {
|
|
4332 elt = XCAR (elt);
|
|
4333 goto tail_recurse;
|
|
4334 }
|
|
4335 }
|
428
|
4336 else if (INTP (car))
|
|
4337 {
|
|
4338 Charcount lim = XINT (car);
|
|
4339
|
|
4340 elt = XCDR (elt);
|
|
4341
|
|
4342 if (lim < 0)
|
|
4343 {
|
|
4344 /* Negative int means reduce maximum width.
|
|
4345 * DO NOT change MIN_PIXPOS here!
|
|
4346 * (20 -10 . foo) should truncate foo to 10 col
|
|
4347 * and then pad to 20.
|
|
4348 */
|
|
4349 if (max_pos == -1)
|
|
4350 max_pos = pos - lim;
|
|
4351 else
|
|
4352 max_pos = min (max_pos, pos - lim);
|
|
4353 }
|
|
4354 else if (lim > 0)
|
|
4355 {
|
|
4356 /* Padding specified. Don't let it be more than
|
|
4357 * current maximum.
|
|
4358 */
|
|
4359 lim += pos;
|
|
4360 if (max_pos != -1 && lim > max_pos)
|
|
4361 lim = max_pos;
|
|
4362 /* If that's more padding than already wanted, queue it.
|
|
4363 * But don't reduce padding already specified even if
|
|
4364 * that is beyond the current truncation point.
|
|
4365 */
|
|
4366 if (lim > min_pos)
|
|
4367 min_pos = lim;
|
|
4368 }
|
|
4369 goto tail_recurse;
|
|
4370 }
|
|
4371 else if (STRINGP (car) || CONSP (car))
|
|
4372 {
|
|
4373 int limit = 50;
|
438
|
4374
|
428
|
4375 /* LIMIT is to protect against circular lists. */
|
|
4376 while (CONSP (elt) && --limit > 0
|
|
4377 && (pos < max_pos || max_pos == -1))
|
|
4378 {
|
|
4379 pos = generate_fstring_runes (w, data, pos, pos, max_pos,
|
438
|
4380 XCAR (elt), depth, max_pixsize,
|
|
4381 findex, type, offset, cur_ext);
|
428
|
4382 elt = XCDR (elt);
|
|
4383 }
|
|
4384 }
|
|
4385 else if (EXTENTP (car))
|
|
4386 {
|
|
4387 struct extent *ext = XEXTENT (car);
|
|
4388
|
|
4389 if (EXTENT_LIVE_P (ext))
|
|
4390 {
|
|
4391 face_index old_findex = data->findex;
|
|
4392 Lisp_Object face;
|
|
4393 Lisp_Object font_inst;
|
|
4394 face_index new_findex;
|
|
4395 Bytecount start = data->bytepos;
|
|
4396
|
|
4397 face = extent_face (ext);
|
|
4398 if (FACEP (face))
|
|
4399 {
|
|
4400 /* #### needs to merge faces, sigh */
|
|
4401 /* #### needs to handle list of faces */
|
|
4402 new_findex = get_builtin_face_cache_index (w, face);
|
|
4403 /* !!#### not right; needs to compute the max height of
|
|
4404 all the charsets */
|
|
4405 font_inst = WINDOW_FACE_CACHEL_FONT (w, new_findex,
|
|
4406 Vcharset_ascii);
|
|
4407
|
|
4408 data->dl->ascent = max (data->dl->ascent,
|
|
4409 XFONT_INSTANCE (font_inst)->ascent);
|
|
4410 data->dl->descent = max (data->dl->descent,
|
|
4411 XFONT_INSTANCE (font_inst)->
|
|
4412 descent);
|
|
4413 }
|
|
4414 else
|
|
4415 new_findex = old_findex;
|
|
4416
|
|
4417 data->findex = new_findex;
|
|
4418 pos = generate_fstring_runes (w, data, pos, pos, max_pos,
|
|
4419 XCDR (elt), depth - 1,
|
438
|
4420 max_pixsize, new_findex, type,
|
|
4421 offset, car);
|
428
|
4422 data->findex = old_findex;
|
|
4423 Dynarr_add (formatted_string_extent_dynarr, ext);
|
|
4424 Dynarr_add (formatted_string_extent_start_dynarr, start);
|
|
4425 Dynarr_add (formatted_string_extent_end_dynarr, data->bytepos);
|
|
4426 }
|
|
4427 }
|
|
4428 }
|
|
4429 else if (GLYPHP (elt))
|
|
4430 {
|
438
|
4431 /* Glyphs are considered as one character with respect to the modeline
|
|
4432 horizontal scrolling facility. -- dv */
|
|
4433 if (*offset > 0)
|
|
4434 *offset -= 1;
|
|
4435 else
|
|
4436 pos = add_glyph_to_fstring_db_runes (data, elt, pos, pos, max_pos,
|
|
4437 cur_ext);
|
428
|
4438 }
|
|
4439 else
|
|
4440 {
|
|
4441 invalid:
|
438
|
4442 {
|
|
4443 char *str = GETTEXT ("*invalid*");
|
|
4444 Charcount size = (Charcount) strlen (str); /* is this ok ?? -- dv */
|
|
4445
|
|
4446 if (size <= *offset)
|
|
4447 *offset -= size;
|
|
4448 else
|
|
4449 {
|
867
|
4450 const Ibyte *tmp_str =
|
|
4451 itext_n_addr ((const Ibyte *) str, *offset);
|
438
|
4452
|
440
|
4453 /* #### NOTE: I don't understand why a tmp_max is not computed and
|
438
|
4454 used here as in the plain string case above. -- dv */
|
|
4455 pos = add_string_to_fstring_db_runes (data, tmp_str, pos,
|
|
4456 min_pos, max_pos);
|
|
4457 *offset = 0;
|
|
4458 }
|
|
4459 }
|
428
|
4460 }
|
|
4461
|
|
4462 if (min_pos > pos)
|
|
4463 {
|
867
|
4464 add_string_to_fstring_db_runes (data, (const Ibyte *) "", pos,
|
438
|
4465 min_pos, -1);
|
428
|
4466 }
|
|
4467
|
|
4468 return pos;
|
|
4469 }
|
|
4470
|
|
4471 /* Update just the modeline. Assumes the desired display structs. If
|
|
4472 they do not have a modeline block, it does nothing. */
|
|
4473 static void
|
|
4474 regenerate_modeline (struct window *w)
|
|
4475 {
|
|
4476 display_line_dynarr *dla = window_display_lines (w, DESIRED_DISP);
|
|
4477
|
|
4478 if (!Dynarr_length (dla) || !Dynarr_atp (dla, 0)->modeline)
|
|
4479 return;
|
|
4480 else
|
|
4481 {
|
|
4482 generate_modeline (w, Dynarr_atp (dla, 0), DESIRED_DISP);
|
|
4483 redisplay_update_line (w, 0, 0, 0);
|
|
4484 }
|
|
4485 }
|
|
4486
|
|
4487 /* Make sure that modeline display line is present in the given
|
|
4488 display structs if the window has a modeline and update that
|
|
4489 line. Returns true if a modeline was needed. */
|
|
4490 static int
|
|
4491 ensure_modeline_generated (struct window *w, int type)
|
|
4492 {
|
|
4493 int need_modeline;
|
|
4494
|
|
4495 /* minibuffer windows don't have modelines */
|
|
4496 if (MINI_WINDOW_P (w))
|
|
4497 need_modeline = 0;
|
|
4498 /* windows which haven't had it turned off do */
|
|
4499 else if (WINDOW_HAS_MODELINE_P (w))
|
|
4500 need_modeline = 1;
|
|
4501 /* windows which have it turned off don't have a divider if there is
|
|
4502 a horizontal scrollbar */
|
|
4503 else if (window_scrollbar_height (w))
|
|
4504 need_modeline = 0;
|
|
4505 /* and in this case there is none */
|
|
4506 else
|
|
4507 need_modeline = 1;
|
|
4508
|
|
4509 if (need_modeline)
|
|
4510 {
|
|
4511 display_line_dynarr *dla;
|
|
4512
|
|
4513 dla = window_display_lines (w, type);
|
|
4514
|
|
4515 /* We don't care if there is a display line which is not
|
|
4516 currently a modeline because it is definitely going to become
|
|
4517 one if we have gotten to this point. */
|
|
4518 if (Dynarr_length (dla) == 0)
|
|
4519 {
|
|
4520 if (Dynarr_largest (dla) > 0)
|
800
|
4521 Dynarr_increment (dla);
|
428
|
4522 else
|
|
4523 {
|
|
4524 struct display_line modeline;
|
|
4525 xzero (modeline);
|
|
4526 Dynarr_add (dla, modeline);
|
|
4527 }
|
|
4528 }
|
|
4529
|
|
4530 /* If we're adding a new place marker go ahead and generate the
|
|
4531 modeline so that it is available for use by
|
|
4532 window_modeline_height. */
|
|
4533 generate_modeline (w, Dynarr_atp (dla, 0), type);
|
|
4534 }
|
|
4535
|
|
4536 return need_modeline;
|
|
4537 }
|
|
4538
|
|
4539 /* #### Kludge or not a kludge. I tend towards the former. */
|
|
4540 int
|
|
4541 real_current_modeline_height (struct window *w)
|
|
4542 {
|
|
4543 Fset_marker (w->start[CMOTION_DISP], w->start[CURRENT_DISP], w->buffer);
|
|
4544 Fset_marker (w->pointm[CMOTION_DISP], w->pointm[CURRENT_DISP], w->buffer);
|
|
4545
|
|
4546 if (ensure_modeline_generated (w, CMOTION_DISP))
|
|
4547 {
|
|
4548 display_line_dynarr *dla = window_display_lines (w, CMOTION_DISP);
|
|
4549
|
|
4550 if (Dynarr_length (dla))
|
|
4551 {
|
|
4552 if (Dynarr_atp (dla, 0)->modeline)
|
|
4553 return (Dynarr_atp (dla, 0)->ascent +
|
|
4554 Dynarr_atp (dla, 0)->descent);
|
|
4555 }
|
|
4556 }
|
|
4557 return 0;
|
|
4558 }
|
|
4559
|
|
4560
|
|
4561 /***************************************************************************/
|
819
|
4562 /* */
|
826
|
4563 /* displayable string routines */
|
819
|
4564 /* */
|
428
|
4565 /***************************************************************************/
|
|
4566
|
|
4567 /* Given a position for a string in a window, ensure that the given
|
|
4568 display line DL accurately represents the text on a line starting
|
|
4569 at the given position.
|
|
4570
|
|
4571 Yes, this is duplicating the code of create_text_block, but it
|
|
4572 looked just too hard to change create_text_block to handle strings
|
|
4573 *and* buffers. We already make a distinction between the two
|
|
4574 elsewhere in the code so I think unifying them would require a
|
|
4575 complete MULE rewrite. Besides, the other distinction is that these
|
|
4576 functions cover text that the user *cannot edit* so we can remove
|
|
4577 everything to do with cursors, minibuffers etc. Eventually the
|
|
4578 modeline routines should be modified to use this code as it copes
|
|
4579 with many more types of display situation. */
|
|
4580
|
665
|
4581 static Charbpos
|
428
|
4582 create_string_text_block (struct window *w, Lisp_Object disp_string,
|
|
4583 struct display_line *dl,
|
826
|
4584 Charcount start_pos,
|
428
|
4585 prop_block_dynarr **prop,
|
|
4586 face_index default_face)
|
|
4587 {
|
|
4588 struct frame *f = XFRAME (w->frame);
|
|
4589 /* Note that a lot of the buffer controlled stuff has been left in
|
|
4590 because you might well want to make use of it (selective display
|
|
4591 etc), its just the buffer text that we do not use. However, it
|
|
4592 seems to be possible for buffer to be nil sometimes so protect
|
|
4593 against this case. */
|
|
4594 struct buffer *b = BUFFERP (w->buffer) ? XBUFFER (w->buffer) : 0;
|
|
4595 struct device *d = XDEVICE (f->device);
|
|
4596
|
|
4597 /* we're working with these a lot so precalculate them */
|
|
4598 Bytecount slen = XSTRING_LENGTH (disp_string);
|
826
|
4599 Bytecount byte_string_zv = slen;
|
|
4600 Bytecount byte_start_pos = string_index_char_to_byte (disp_string, start_pos);
|
428
|
4601
|
|
4602 pos_data data;
|
|
4603
|
|
4604 int truncate_win = b ? window_truncation_on (w) : 0;
|
|
4605
|
442
|
4606 /* We're going to ditch selective display for static text, it's an
|
|
4607 FSF thing and invisible extents are the way to go here.
|
|
4608 Implementing it also relies on a number of buffer-specific
|
428
|
4609 functions that we don't have the luxury of being able to use
|
|
4610 here. */
|
|
4611
|
|
4612 /* The variable ctl-arrow allows the user to specify what characters
|
|
4613 can actually be displayed and which octal should be used for.
|
|
4614 #### This variable should probably have some rethought done to
|
|
4615 it.
|
|
4616
|
|
4617 #### It would also be really nice if you could specify that
|
|
4618 the characters come out in hex instead of in octal. Mule
|
|
4619 does that by adding a ctl-hexa variable similar to ctl-arrow,
|
|
4620 but that's bogus -- we need a more general solution. I
|
|
4621 think you need to extend the concept of display tables
|
|
4622 into a more general conversion mechanism. Ideally you
|
|
4623 could specify a Lisp function that converts characters,
|
|
4624 but this violates the Second Golden Rule and besides would
|
|
4625 make things way way way way slow.
|
|
4626
|
|
4627 So instead, we extend the display-table concept, which was
|
|
4628 historically limited to 256-byte vectors, to one of the
|
|
4629 following:
|
|
4630
|
|
4631 a) A 256-entry vector, for backward compatibility;
|
|
4632 b) char-table, mapping characters to values;
|
|
4633 c) range-table, mapping ranges of characters to values;
|
|
4634 d) a list of the above.
|
|
4635
|
|
4636 The (d) option allows you to specify multiple display tables
|
|
4637 instead of just one. Each display table can specify conversions
|
|
4638 for some characters and leave others unchanged. The way the
|
|
4639 character gets displayed is determined by the first display table
|
|
4640 with a binding for that character. This way, you could call a
|
|
4641 function `enable-hex-display' that adds a hex display-table to
|
|
4642 the list of display tables for the current buffer.
|
|
4643
|
|
4644 #### ...not yet implemented... Also, we extend the concept of
|
|
4645 "mapping" to include a printf-like spec. Thus you can make all
|
|
4646 extended characters show up as hex with a display table like
|
|
4647 this:
|
|
4648
|
|
4649 #s(range-table data ((256 524288) (format "%x")))
|
|
4650
|
|
4651 Since more than one display table is possible, you have
|
|
4652 great flexibility in mapping ranges of characters. */
|
867
|
4653 Ichar printable_min = b ? (CHAR_OR_CHAR_INTP (b->ctl_arrow)
|
428
|
4654 ? XCHAR_OR_CHAR_INT (b->ctl_arrow)
|
|
4655 : ((EQ (b->ctl_arrow, Qt) || EQ (b->ctl_arrow, Qnil))
|
|
4656 ? 255 : 160)) : 255;
|
|
4657
|
|
4658 Lisp_Object face_dt, window_dt;
|
|
4659
|
|
4660 /* The text display block for this display line. */
|
|
4661 struct display_block *db = get_display_block_from_line (dl, TEXT);
|
|
4662
|
|
4663 /* The first time through the main loop we need to force the glyph
|
|
4664 data to be updated. */
|
|
4665 int initial = 1;
|
|
4666
|
|
4667 /* Apparently the new extent_fragment_update returns an end position
|
|
4668 equal to the position passed in if there are no more runs to be
|
|
4669 displayed. */
|
|
4670 int no_more_frags = 0;
|
|
4671
|
|
4672 dl->used_prop_data = 0;
|
|
4673 dl->num_chars = 0;
|
442
|
4674 dl->line_continuation = 0;
|
428
|
4675
|
|
4676 /* set up faces to use for clearing areas, used by
|
|
4677 output_display_line */
|
|
4678 dl->default_findex = default_face;
|
|
4679 if (default_face)
|
|
4680 {
|
|
4681 dl->left_margin_findex = default_face;
|
|
4682 dl->right_margin_findex = default_face;
|
|
4683 }
|
|
4684 else
|
|
4685 {
|
434
|
4686 dl->left_margin_findex =
|
428
|
4687 get_builtin_face_cache_index (w, Vleft_margin_face);
|
434
|
4688 dl->right_margin_findex =
|
428
|
4689 get_builtin_face_cache_index (w, Vright_margin_face);
|
|
4690 }
|
|
4691
|
|
4692 xzero (data);
|
|
4693 data.ef = extent_fragment_new (disp_string, f);
|
|
4694
|
|
4695 /* These values are used by all of the rune addition routines. We add
|
|
4696 them to this structure for ease of passing. */
|
|
4697 data.d = d;
|
793
|
4698 data.window = wrap_window (w);
|
428
|
4699 data.db = db;
|
|
4700 data.dl = dl;
|
|
4701
|
826
|
4702 data.byte_charpos = byte_start_pos;
|
428
|
4703 data.pixpos = dl->bounds.left_in;
|
|
4704 data.last_charset = Qunbound;
|
|
4705 data.last_findex = default_face;
|
|
4706 data.result_str = Qnil;
|
|
4707 data.string = disp_string;
|
|
4708
|
|
4709 /* Set the right boundary adjusting it to take into account any end
|
|
4710 glyph. Save the width of the end glyph for later use. */
|
|
4711 data.max_pixpos = dl->bounds.right_in;
|
819
|
4712 data.max_pixpos -= data.end_glyph_width;
|
428
|
4713
|
|
4714 data.cursor_type = NO_CURSOR;
|
|
4715 data.cursor_x = -1;
|
|
4716
|
|
4717 data.start_col = 0;
|
|
4718 /* I don't think we want this, string areas should not scroll with
|
434
|
4719 the window
|
428
|
4720 data.start_col = w->hscroll;
|
826
|
4721 data.byte_start_col_enabled = (w->hscroll ? byte_start_pos : 0);
|
428
|
4722 */
|
826
|
4723 data.byte_start_col_enabled = 0;
|
428
|
4724 data.hscroll_glyph_width_adjust = 0;
|
|
4725
|
|
4726 /* We regenerate the line from the very beginning. */
|
|
4727 Dynarr_reset (db->runes);
|
|
4728
|
|
4729 /* Why is this less than or equal and not just less than? If the
|
|
4730 starting position is already equal to the maximum we can't add
|
|
4731 anything else, right? Wrong. We might still have a newline to
|
|
4732 add. A newline can use the room allocated for an end glyph since
|
|
4733 if we add it we know we aren't going to be adding any end
|
|
4734 glyph. */
|
|
4735
|
|
4736 /* #### Chuck -- I think this condition should be while (1).
|
|
4737 Otherwise if (e.g.) there is one begin-glyph and one end-glyph
|
|
4738 and the begin-glyph ends exactly at the end of the window, the
|
|
4739 end-glyph and text might not be displayed. while (1) ensures
|
|
4740 that the loop terminates only when either (a) there is
|
|
4741 propagation data or (b) the end-of-line or end-of-buffer is hit.
|
|
4742
|
|
4743 #### Also I think you need to ensure that the operation
|
|
4744 "add begin glyphs; add end glyphs; add text" is atomic and
|
|
4745 can't get interrupted in the middle. If you run off the end
|
|
4746 of the line during that operation, then you keep accumulating
|
|
4747 propagation data until you're done. Otherwise, if the (e.g.)
|
|
4748 there's a begin glyph at a particular position and attempting
|
|
4749 to display that glyph results in window-end being hit and
|
|
4750 propagation data being generated, then the character at that
|
|
4751 position won't be displayed.
|
|
4752
|
|
4753 #### See also the comment after the end of this loop, below.
|
|
4754 */
|
|
4755 while (data.pixpos <= data.max_pixpos)
|
|
4756 {
|
|
4757 /* #### This check probably should not be necessary. */
|
826
|
4758 if (data.byte_charpos > byte_string_zv)
|
428
|
4759 {
|
|
4760 /* #### urk! More of this lossage! */
|
826
|
4761 data.byte_charpos--;
|
428
|
4762 goto done;
|
|
4763 }
|
|
4764
|
|
4765 /* Check for face changes. */
|
826
|
4766 if (initial || (!no_more_frags && data.byte_charpos == data.ef->end))
|
428
|
4767 {
|
819
|
4768 Lisp_Object last_glyph = Qnil;
|
|
4769 /* Deal with clipped glyphs that we have already displayed. */
|
|
4770 if (*prop && Dynarr_atp (*prop, 0)->type == PROP_GLYPH)
|
|
4771 {
|
|
4772 last_glyph = Dynarr_atp (*prop, 0)->data.p_glyph.glyph;
|
|
4773 Dynarr_free (*prop);
|
|
4774 *prop = 0;
|
|
4775 }
|
428
|
4776 /* Now compute the face and begin/end-glyph information. */
|
|
4777 data.findex =
|
793
|
4778 /* Remember that the extent-fragment routines deal in
|
826
|
4779 Bytexpos's. */
|
|
4780 extent_fragment_update (w, data.ef, data.byte_charpos, last_glyph);
|
428
|
4781 /* This is somewhat cheesy but the alternative is to
|
|
4782 propagate default_face into extent_fragment_update. */
|
|
4783 if (data.findex == DEFAULT_INDEX)
|
|
4784 data.findex = default_face;
|
|
4785
|
|
4786 get_display_tables (w, data.findex, &face_dt, &window_dt);
|
|
4787
|
826
|
4788 if (data.byte_charpos == data.ef->end)
|
428
|
4789 no_more_frags = 1;
|
|
4790 }
|
|
4791 initial = 0;
|
|
4792
|
|
4793 /* Determine what is next to be displayed. We first handle any
|
665
|
4794 glyphs returned by glyphs_at_charbpos. If there are no glyphs to
|
428
|
4795 display then we determine what to do based on the character at the
|
|
4796 current buffer position. */
|
|
4797
|
|
4798 /* If the current position is covered by an invisible extent, do
|
|
4799 nothing (except maybe add some ellipses).
|
|
4800
|
|
4801 #### The behavior of begin and end-glyphs at the edge of an
|
|
4802 invisible extent should be investigated further. This is
|
|
4803 fairly low priority though. */
|
|
4804 if (data.ef->invisible)
|
|
4805 {
|
|
4806 /* #### Chuck, perhaps you could look at this code? I don't
|
|
4807 really know what I'm doing. */
|
|
4808 if (*prop)
|
|
4809 {
|
|
4810 Dynarr_free (*prop);
|
|
4811 *prop = 0;
|
|
4812 }
|
|
4813
|
|
4814 /* The extent fragment code only sets this when we should
|
|
4815 really display the ellipses. It makes sure the ellipses
|
|
4816 don't get displayed more than once in a row. */
|
|
4817 if (data.ef->invisible_ellipses)
|
|
4818 {
|
|
4819 struct glyph_block gb;
|
|
4820
|
|
4821 data.ef->invisible_ellipses_already_displayed = 1;
|
|
4822 data.ef->invisible_ellipses = 0;
|
|
4823 gb.extent = Qnil;
|
|
4824 gb.glyph = Vinvisible_text_glyph;
|
|
4825 *prop = add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0,
|
|
4826 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX));
|
|
4827 /* Perhaps they shouldn't propagate if the very next thing
|
|
4828 is to display a newline (for compatibility with
|
|
4829 selective-display-ellipses)? Maybe that's too
|
|
4830 abstruse. */
|
|
4831 if (*prop)
|
|
4832 goto done;
|
|
4833 }
|
|
4834
|
638
|
4835 /* #### What if we're dealing with a display table? */
|
428
|
4836 if (data.start_col)
|
|
4837 data.start_col--;
|
|
4838
|
826
|
4839 if (data.byte_charpos == byte_string_zv)
|
428
|
4840 goto done;
|
|
4841 else
|
826
|
4842 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos);
|
428
|
4843 }
|
|
4844
|
|
4845 /* If there is propagation data, then it represents the current
|
|
4846 buffer position being displayed. Add them and advance the
|
|
4847 position counter. This might also add the minibuffer
|
|
4848 prompt. */
|
|
4849 else if (*prop)
|
|
4850 {
|
|
4851 dl->used_prop_data = 1;
|
|
4852 *prop = add_propagation_runes (prop, &data);
|
|
4853
|
|
4854 if (*prop)
|
|
4855 goto done; /* gee, a really narrow window */
|
826
|
4856 else if (data.byte_charpos == byte_string_zv)
|
428
|
4857 goto done;
|
826
|
4858 else if (data.byte_charpos < 0)
|
428
|
4859 /* #### urk urk urk! Aborts are not very fun! Fix this please! */
|
826
|
4860 data.byte_charpos = 0;
|
428
|
4861 else
|
826
|
4862 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos);
|
428
|
4863 }
|
|
4864
|
|
4865 /* If there are end glyphs, add them to the line. These are
|
|
4866 the end glyphs for the previous run of text. We add them
|
|
4867 here rather than doing them at the end of handling the
|
|
4868 previous run so that glyphs at the beginning and end of
|
|
4869 a line are handled correctly. */
|
|
4870 else if (Dynarr_length (data.ef->end_glyphs) > 0)
|
|
4871 {
|
867
|
4872 data.ch = string_ichar (disp_string, data.byte_charpos);
|
428
|
4873 *prop = add_glyph_runes (&data, END_GLYPHS);
|
819
|
4874
|
|
4875 if (*prop) {
|
428
|
4876 goto done;
|
819
|
4877 }
|
428
|
4878 }
|
|
4879
|
|
4880 /* If there are begin glyphs, add them to the line. */
|
|
4881 else if (Dynarr_length (data.ef->begin_glyphs) > 0)
|
|
4882 {
|
867
|
4883 data.ch = string_ichar (disp_string, data.byte_charpos);
|
428
|
4884 *prop = add_glyph_runes (&data, BEGIN_GLYPHS);
|
819
|
4885
|
|
4886 if (*prop) {
|
428
|
4887 goto done;
|
819
|
4888 }
|
428
|
4889 }
|
|
4890
|
|
4891 /* If at end-of-buffer, we've already processed begin and
|
|
4892 end-glyphs at this point and there's no text to process,
|
|
4893 so we're done. */
|
826
|
4894 else if (data.byte_charpos == byte_string_zv)
|
428
|
4895 goto done;
|
|
4896
|
|
4897 else
|
|
4898 {
|
|
4899 Lisp_Object entry = Qnil;
|
|
4900 /* Get the character at the current buffer position. */
|
867
|
4901 data.ch = string_ichar (disp_string, data.byte_charpos);
|
428
|
4902 if (!NILP (face_dt) || !NILP (window_dt))
|
|
4903 entry = display_table_entry (data.ch, face_dt, window_dt);
|
|
4904
|
|
4905 /* If there is a display table entry for it, hand it off to
|
|
4906 add_disp_table_entry_runes and let it worry about it. */
|
|
4907 if (!NILP (entry) && !EQ (entry, make_char (data.ch)))
|
|
4908 {
|
|
4909 *prop = add_disp_table_entry_runes (&data, entry);
|
|
4910
|
|
4911 if (*prop)
|
|
4912 goto done;
|
|
4913 }
|
|
4914
|
|
4915 /* Check if we have hit a newline character. If so, add a marker
|
|
4916 to the line and end this loop. */
|
|
4917 else if (data.ch == '\n')
|
|
4918 {
|
|
4919 /* We aren't going to be adding an end glyph so give its
|
|
4920 space back in order to make sure that the cursor can
|
|
4921 fit. */
|
819
|
4922 data.max_pixpos += data.end_glyph_width;
|
428
|
4923 goto done;
|
|
4924 }
|
|
4925
|
|
4926 /* If the current character is considered to be printable, then
|
|
4927 just add it. */
|
|
4928 else if (data.ch >= printable_min)
|
|
4929 {
|
867
|
4930 *prop = add_ichar_rune (&data);
|
428
|
4931 if (*prop)
|
|
4932 goto done;
|
|
4933 }
|
|
4934
|
|
4935 /* If the current character is a tab, determine the next tab
|
|
4936 starting position and add a blank rune which extends from the
|
|
4937 current pixel position to that starting position. */
|
|
4938 else if (data.ch == '\t')
|
|
4939 {
|
|
4940 int tab_start_pixpos = data.pixpos;
|
|
4941 int next_tab_start;
|
|
4942 int char_tab_width;
|
|
4943 int prop_width = 0;
|
|
4944
|
|
4945 if (data.start_col > 1)
|
|
4946 tab_start_pixpos -= (space_width (w) * (data.start_col - 1));
|
|
4947
|
|
4948 next_tab_start =
|
|
4949 next_tab_position (w, tab_start_pixpos,
|
|
4950 dl->bounds.left_in +
|
|
4951 data.hscroll_glyph_width_adjust);
|
|
4952 if (next_tab_start > data.max_pixpos)
|
|
4953 {
|
|
4954 prop_width = next_tab_start - data.max_pixpos;
|
|
4955 next_tab_start = data.max_pixpos;
|
|
4956 }
|
|
4957 data.blank_width = next_tab_start - data.pixpos;
|
|
4958 char_tab_width =
|
|
4959 (next_tab_start - tab_start_pixpos) / space_width (w);
|
|
4960
|
|
4961 *prop = add_blank_rune (&data, w, char_tab_width);
|
|
4962
|
|
4963 /* add_blank_rune is only supposed to be called with
|
819
|
4964 sizes guaranteed to fit in the available space. */
|
428
|
4965 assert (!(*prop));
|
|
4966
|
|
4967 if (prop_width)
|
|
4968 {
|
|
4969 struct prop_block pb;
|
|
4970 *prop = Dynarr_new (prop_block);
|
|
4971
|
|
4972 pb.type = PROP_BLANK;
|
|
4973 pb.data.p_blank.width = prop_width;
|
|
4974 pb.data.p_blank.findex = data.findex;
|
|
4975 Dynarr_add (*prop, pb);
|
|
4976
|
|
4977 goto done;
|
|
4978 }
|
|
4979 }
|
|
4980
|
|
4981 /* If character is a control character, pass it off to
|
|
4982 add_control_char_runes.
|
|
4983
|
|
4984 The is_*() routines have undefined results on
|
|
4985 arguments outside of the range [-1, 255]. (This
|
|
4986 often bites people who carelessly use `char' instead
|
|
4987 of `unsigned char'.)
|
|
4988 */
|
867
|
4989 else if (data.ch < 0x100 && iscntrl ((Ibyte) data.ch))
|
428
|
4990 {
|
|
4991 *prop = add_control_char_runes (&data, b);
|
|
4992
|
|
4993 if (*prop)
|
|
4994 goto done;
|
|
4995 }
|
|
4996
|
|
4997 /* If the character is above the ASCII range and we have not
|
|
4998 already handled it, then print it as an octal number. */
|
|
4999 else if (data.ch >= 0200)
|
|
5000 {
|
|
5001 *prop = add_octal_runes (&data);
|
|
5002
|
|
5003 if (*prop)
|
|
5004 goto done;
|
|
5005 }
|
|
5006
|
|
5007 /* Assume the current character is considered to be printable,
|
|
5008 then just add it. */
|
|
5009 else
|
|
5010 {
|
867
|
5011 *prop = add_ichar_rune (&data);
|
428
|
5012 if (*prop)
|
|
5013 goto done;
|
|
5014 }
|
|
5015
|
826
|
5016 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos);
|
428
|
5017 }
|
|
5018 }
|
|
5019
|
819
|
5020 done:
|
428
|
5021
|
|
5022 /* Determine the starting point of the next line if we did not hit the
|
|
5023 end of the buffer. */
|
826
|
5024 if (data.byte_charpos < byte_string_zv)
|
428
|
5025 {
|
|
5026 /* #### This check is not correct. If the line terminated
|
|
5027 due to a begin-glyph or end-glyph hitting window-end, then
|
826
|
5028 data.ch will not point to the character at data.byte_charpos. If
|
428
|
5029 you make the two changes mentioned at the top of this loop,
|
|
5030 you should be able to say '(if (*prop))'. That should also
|
826
|
5031 make it possible to eliminate the data.byte_charpos < BYTE_BUF_ZV (b)
|
428
|
5032 check. */
|
|
5033
|
|
5034 /* The common case is that the line ended because we hit a newline.
|
|
5035 In that case, the next character is just the next buffer
|
|
5036 position. */
|
|
5037 if (data.ch == '\n')
|
|
5038 {
|
826
|
5039 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos);
|
428
|
5040 }
|
|
5041
|
|
5042 /* Otherwise we have a buffer line which cannot fit on one display
|
|
5043 line. */
|
|
5044 else
|
|
5045 {
|
|
5046 struct glyph_block gb;
|
|
5047 struct glyph_cachel *cachel;
|
|
5048
|
|
5049 /* If the line is to be truncated then we actually have to look
|
|
5050 for the next newline. We also add the end-of-line glyph which
|
|
5051 we know will fit because we adjusted the right border before
|
|
5052 we starting laying out the line. */
|
819
|
5053 data.max_pixpos += data.end_glyph_width;
|
428
|
5054 data.findex = default_face;
|
|
5055 gb.extent = Qnil;
|
|
5056
|
|
5057 if (truncate_win)
|
|
5058 {
|
826
|
5059 Bytecount byte_pos;
|
428
|
5060
|
|
5061 /* Now find the start of the next line. */
|
867
|
5062 byte_pos = byte_find_next_ichar_in_string (disp_string, '\n',
|
826
|
5063 data.byte_charpos, 1);
|
428
|
5064
|
|
5065 data.cursor_type = NO_CURSOR;
|
826
|
5066 data.byte_charpos = byte_pos;
|
428
|
5067 gb.glyph = Vtruncation_glyph;
|
|
5068 cachel = GLYPH_CACHEL (w, TRUN_GLYPH_INDEX);
|
|
5069 }
|
|
5070 else
|
|
5071 {
|
|
5072 /* The cursor can never be on the continuation glyph. */
|
|
5073 data.cursor_type = NO_CURSOR;
|
|
5074
|
826
|
5075 /* data.byte_charpos is already at the start of the next line. */
|
428
|
5076
|
442
|
5077 dl->line_continuation = 1;
|
428
|
5078 gb.glyph = Vcontinuation_glyph;
|
|
5079 cachel = GLYPH_CACHEL (w, CONT_GLYPH_INDEX);
|
|
5080 }
|
|
5081
|
819
|
5082 if (data.end_glyph_width)
|
428
|
5083 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, cachel);
|
|
5084
|
826
|
5085 if (truncate_win && data.byte_charpos == byte_string_zv)
|
428
|
5086 {
|
867
|
5087 const Ibyte *endb = itext_n_addr (XSTRING_DATA (disp_string),
|
826
|
5088 byte_string_zv);
|
867
|
5089 DEC_IBYTEPTR (endb);
|
|
5090 if (itext_ichar (endb) != '\n')
|
428
|
5091 {
|
|
5092 /* #### Damn this losing shit. */
|
826
|
5093 data.byte_charpos++;
|
428
|
5094 }
|
|
5095 }
|
|
5096 }
|
|
5097 }
|
826
|
5098 else if (data.byte_charpos == byte_string_zv)
|
428
|
5099 {
|
|
5100 /* create_text_block () adds a bogus \n marker here which screws
|
|
5101 up subwindow display. Since we never have a cursor in the
|
|
5102 gutter we can safely ignore it. */
|
|
5103 }
|
|
5104 /* Calculate left whitespace boundary. */
|
|
5105 {
|
|
5106 int elt = 0;
|
|
5107
|
|
5108 /* Whitespace past a newline is considered right whitespace. */
|
|
5109 while (elt < Dynarr_length (db->runes))
|
|
5110 {
|
|
5111 struct rune *rb = Dynarr_atp (db->runes, elt);
|
|
5112
|
|
5113 if ((rb->type == RUNE_CHAR && rb->object.chr.ch == ' ')
|
|
5114 || rb->type == RUNE_BLANK)
|
|
5115 {
|
|
5116 dl->bounds.left_white += rb->width;
|
|
5117 elt++;
|
|
5118 }
|
|
5119 else
|
|
5120 elt = Dynarr_length (db->runes);
|
|
5121 }
|
|
5122 }
|
|
5123
|
|
5124 /* Calculate right whitespace boundary. */
|
|
5125 {
|
|
5126 int elt = Dynarr_length (db->runes) - 1;
|
|
5127 int done = 0;
|
|
5128
|
|
5129 while (!done && elt >= 0)
|
|
5130 {
|
|
5131 struct rune *rb = Dynarr_atp (db->runes, elt);
|
|
5132
|
|
5133 if (!(rb->type == RUNE_CHAR && rb->object.chr.ch < 0x100
|
|
5134 && isspace (rb->object.chr.ch))
|
|
5135 && !rb->type == RUNE_BLANK)
|
|
5136 {
|
|
5137 dl->bounds.right_white = rb->xpos + rb->width;
|
|
5138 done = 1;
|
|
5139 }
|
|
5140
|
|
5141 elt--;
|
|
5142
|
|
5143 }
|
|
5144
|
|
5145 /* The line is blank so everything is considered to be right
|
|
5146 whitespace. */
|
|
5147 if (!done)
|
|
5148 dl->bounds.right_white = dl->bounds.left_in;
|
|
5149 }
|
|
5150
|
|
5151 /* Set the display blocks bounds. */
|
|
5152 db->start_pos = dl->bounds.left_in;
|
|
5153 if (Dynarr_length (db->runes))
|
|
5154 {
|
|
5155 struct rune *rb = Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
|
|
5156
|
|
5157 db->end_pos = rb->xpos + rb->width;
|
|
5158 }
|
|
5159 else
|
|
5160 db->end_pos = dl->bounds.right_white;
|
|
5161
|
819
|
5162 calculate_baseline (&data);
|
428
|
5163
|
|
5164 dl->ascent = data.new_ascent;
|
|
5165 dl->descent = data.new_descent;
|
|
5166
|
|
5167 {
|
|
5168 unsigned short ascent = (unsigned short) XINT (w->minimum_line_ascent);
|
|
5169
|
|
5170 if (dl->ascent < ascent)
|
|
5171 dl->ascent = ascent;
|
|
5172 }
|
|
5173 {
|
|
5174 unsigned short descent = (unsigned short) XINT (w->minimum_line_descent);
|
|
5175
|
|
5176 if (dl->descent < descent)
|
|
5177 dl->descent = descent;
|
|
5178 }
|
|
5179
|
819
|
5180 calculate_yoffset (dl, db);
|
|
5181
|
428
|
5182 dl->cursor_elt = data.cursor_x;
|
|
5183 /* #### lossage lossage lossage! Fix this shit! */
|
826
|
5184 if (data.byte_charpos > byte_string_zv)
|
|
5185 dl->end_charpos = buffer_or_string_bytexpos_to_charxpos (disp_string,
|
|
5186 byte_string_zv);
|
428
|
5187 else
|
826
|
5188 dl->end_charpos =
|
|
5189 buffer_or_string_bytexpos_to_charxpos (disp_string,
|
|
5190 data.byte_charpos) - 1;
|
428
|
5191 if (truncate_win)
|
434
|
5192 data.dl->num_chars =
|
826
|
5193 string_column_at_point (disp_string, dl->end_charpos,
|
793
|
5194 b ? XINT (b->tab_width) : 8);
|
428
|
5195 else
|
|
5196 /* This doesn't correctly take into account tabs and control
|
|
5197 characters but if the window isn't being truncated then this
|
|
5198 value isn't going to end up being used anyhow. */
|
826
|
5199 data.dl->num_chars = dl->end_charpos - dl->charpos;
|
428
|
5200
|
|
5201 /* #### handle horizontally scrolled line with text none of which
|
|
5202 was actually laid out. */
|
|
5203
|
|
5204 /* #### handle any remainder of overlay arrow */
|
|
5205
|
|
5206 if (*prop == ADD_FAILED)
|
|
5207 *prop = NULL;
|
|
5208
|
|
5209 if (truncate_win && *prop)
|
|
5210 {
|
|
5211 Dynarr_free (*prop);
|
|
5212 *prop = NULL;
|
|
5213 }
|
|
5214
|
|
5215 extent_fragment_delete (data.ef);
|
|
5216
|
|
5217 /* #### If we started at EOB, then make sure we return a value past
|
|
5218 it so that regenerate_window will exit properly. This is bogus.
|
|
5219 The main loop should get fixed so that it isn't necessary to call
|
|
5220 this function if we are already at EOB. */
|
|
5221
|
826
|
5222 if (data.byte_charpos == byte_string_zv && byte_start_pos == byte_string_zv)
|
793
|
5223 return string_index_byte_to_char (disp_string,
|
826
|
5224 data.byte_charpos) + 1; /* Yuck! */
|
428
|
5225 else
|
826
|
5226 return string_index_byte_to_char (disp_string, data.byte_charpos);
|
428
|
5227 }
|
|
5228
|
|
5229 /* Given a display line and a starting position, ensure that the
|
|
5230 contents of the display line accurately represent the visual
|
|
5231 representation of the buffer contents starting from the given
|
|
5232 position when displayed in the given window. The display line ends
|
|
5233 when the contents of the line reach the right boundary of the given
|
434
|
5234 window.
|
|
5235
|
428
|
5236 This is very similar to generate_display_line but with the same
|
|
5237 limitations as create_string_text_block. I have taken the liberty
|
665
|
5238 of fixing the bytebpos stuff though.*/
|
|
5239
|
|
5240 static Charbpos
|
428
|
5241 generate_string_display_line (struct window *w, Lisp_Object disp_string,
|
|
5242 struct display_line *dl,
|
826
|
5243 Charcount start_pos,
|
428
|
5244 prop_block_dynarr **prop,
|
|
5245 face_index default_face)
|
|
5246 {
|
826
|
5247 Charcount ret_charcount;
|
428
|
5248
|
|
5249 /* you must set bounds before calling this. */
|
434
|
5250
|
428
|
5251 /* Reset what this line is using. */
|
|
5252 if (dl->display_blocks)
|
|
5253 Dynarr_reset (dl->display_blocks);
|
|
5254 if (dl->left_glyphs)
|
|
5255 {
|
|
5256 Dynarr_free (dl->left_glyphs);
|
|
5257 dl->left_glyphs = 0;
|
|
5258 }
|
|
5259 if (dl->right_glyphs)
|
|
5260 {
|
|
5261 Dynarr_free (dl->right_glyphs);
|
|
5262 dl->right_glyphs = 0;
|
|
5263 }
|
|
5264
|
|
5265 /* We aren't generating a modeline at the moment. */
|
|
5266 dl->modeline = 0;
|
|
5267
|
|
5268 /* Create a display block for the text region of the line. */
|
826
|
5269 ret_charcount = create_string_text_block (w, disp_string, dl, start_pos,
|
|
5270 prop, default_face);
|
|
5271 dl->charpos = start_pos;
|
|
5272 if (dl->end_charpos < dl->charpos)
|
|
5273 dl->end_charpos = dl->charpos;
|
428
|
5274
|
|
5275 /* If there are left glyphs associated with any character in the
|
|
5276 text block, then create a display block to handle them. */
|
|
5277 if (dl->left_glyphs != NULL && Dynarr_length (dl->left_glyphs))
|
|
5278 create_left_glyph_block (w, dl, 0);
|
|
5279
|
|
5280 /* If there are right glyphs associated with any character in the
|
|
5281 text block, then create a display block to handle them. */
|
|
5282 if (dl->right_glyphs != NULL && Dynarr_length (dl->right_glyphs))
|
|
5283 create_right_glyph_block (w, dl);
|
|
5284
|
826
|
5285 return ret_charcount;
|
428
|
5286 }
|
|
5287
|
2518
|
5288 /*
|
|
5289
|
|
5290 Info on Re-entrancy crashes, with backtraces given:
|
|
5291
|
|
5292 (Info-goto-node "(internals)Nasty Bugs due to Reentrancy in Redisplay Structures handling QUIT")
|
1318
|
5293 */
|
|
5294
|
|
5295
|
428
|
5296 /* This is ripped off from regenerate_window. All we want to do is
|
|
5297 loop through elements in the string creating display lines until we
|
|
5298 have covered the provided area. Simple really. */
|
|
5299 void
|
|
5300 generate_displayable_area (struct window *w, Lisp_Object disp_string,
|
|
5301 int xpos, int ypos, int width, int height,
|
|
5302 display_line_dynarr* dla,
|
826
|
5303 Charcount start_pos,
|
428
|
5304 face_index default_face)
|
|
5305 {
|
|
5306 int yend = ypos + height;
|
|
5307 Charcount s_zv;
|
|
5308 prop_block_dynarr *prop = 0;
|
|
5309 layout_bounds bounds;
|
2518
|
5310 int depth = -1;
|
|
5311
|
428
|
5312 /* if there's nothing to do then do nothing. code after this assumes
|
|
5313 there is something to do. */
|
|
5314 if (NILP (disp_string))
|
|
5315 return;
|
|
5316
|
2518
|
5317 /* See comment in regenerate_window() */
|
|
5318 if (!in_display)
|
|
5319 depth = enter_redisplay_critical_section ();
|
|
5320
|
|
5321 assert (dla);
|
|
5322 Dynarr_reset (dla);
|
|
5323
|
826
|
5324 s_zv = string_char_length (disp_string);
|
428
|
5325
|
|
5326 bounds.left_out = xpos;
|
|
5327 bounds.right_out = xpos + width;
|
|
5328 /* The inner boundaries mark where the glyph margins are located. */
|
|
5329 bounds.left_in = bounds.left_out + window_left_margin_width (w);
|
|
5330 bounds.right_in = bounds.right_out - window_right_margin_width (w);
|
|
5331 /* We cannot fully calculate the whitespace boundaries as they
|
|
5332 depend on the contents of the line being displayed. */
|
|
5333 bounds.left_white = bounds.left_in;
|
|
5334 bounds.right_white = bounds.right_in;
|
|
5335
|
|
5336 while (ypos < yend)
|
|
5337 {
|
|
5338 struct display_line dl;
|
|
5339 struct display_line *dlp;
|
826
|
5340 Charcount next_pos;
|
428
|
5341 int local;
|
851
|
5342 int pos_of_dlp = -1;
|
428
|
5343
|
|
5344 if (Dynarr_length (dla) < Dynarr_largest (dla))
|
|
5345 {
|
851
|
5346 pos_of_dlp = Dynarr_length (dla);
|
|
5347 dlp = Dynarr_atp (dla, pos_of_dlp);
|
428
|
5348 local = 0;
|
|
5349 }
|
|
5350 else
|
|
5351 {
|
|
5352
|
|
5353 xzero (dl);
|
|
5354 dlp = &dl;
|
|
5355 local = 1;
|
|
5356 }
|
|
5357
|
|
5358 dlp->bounds = bounds;
|
|
5359 dlp->offset = 0;
|
1318
|
5360 Dynarr_lock (dla);
|
428
|
5361 next_pos = generate_string_display_line (w, disp_string, dlp, start_pos,
|
|
5362 &prop, default_face);
|
1318
|
5363 Dynarr_unlock (dla);
|
428
|
5364 /* we need to make sure that we continue along the line if there
|
|
5365 is more left to display otherwise we just end up redisplaying
|
|
5366 the same chunk over and over again. */
|
|
5367 if (next_pos == start_pos && next_pos < s_zv)
|
|
5368 start_pos++;
|
|
5369 else
|
|
5370 start_pos = next_pos;
|
|
5371
|
|
5372 dlp->ypos = ypos + dlp->ascent;
|
|
5373 ypos = dlp->ypos + dlp->descent;
|
|
5374
|
|
5375 if (ypos > yend)
|
|
5376 {
|
|
5377 int visible_height = dlp->ascent + dlp->descent;
|
|
5378
|
|
5379 dlp->clip = (ypos - yend);
|
|
5380 visible_height -= dlp->clip;
|
|
5381
|
|
5382 if (visible_height < VERTICAL_CLIP (w, 1))
|
|
5383 {
|
|
5384 if (local)
|
|
5385 free_display_line (dlp);
|
|
5386 break;
|
|
5387 }
|
|
5388 }
|
|
5389 else
|
|
5390 dlp->clip = 0;
|
|
5391
|
851
|
5392 assert (pos_of_dlp < 0 || pos_of_dlp == Dynarr_length (dla));
|
428
|
5393 Dynarr_add (dla, *dlp);
|
|
5394
|
|
5395 /* #### This type of check needs to be done down in the
|
|
5396 generate_display_line call. */
|
|
5397 if (start_pos >= s_zv)
|
|
5398 break;
|
|
5399 }
|
|
5400
|
|
5401 if (prop)
|
|
5402 Dynarr_free (prop);
|
2518
|
5403
|
|
5404 if (depth >= 0)
|
|
5405 exit_redisplay_critical_section (depth);
|
428
|
5406 }
|
|
5407
|
|
5408
|
|
5409 /***************************************************************************/
|
|
5410 /* */
|
|
5411 /* window-regeneration routines */
|
|
5412 /* */
|
|
5413 /***************************************************************************/
|
|
5414
|
|
5415 /* For a given window and starting position in the buffer it contains,
|
|
5416 ensure that the TYPE display lines accurately represent the
|
|
5417 presentation of the window. We pass the buffer instead of getting
|
|
5418 it from the window since redisplay_window may have temporarily
|
|
5419 changed it to the echo area buffer. */
|
|
5420
|
|
5421 static void
|
2518
|
5422 regenerate_window (struct window *w, Charbpos start_pos, Charbpos point,
|
|
5423 int type)
|
428
|
5424 {
|
|
5425 struct frame *f = XFRAME (w->frame);
|
|
5426 struct buffer *b = XBUFFER (w->buffer);
|
|
5427 int ypos = WINDOW_TEXT_TOP (w);
|
|
5428 int yend; /* set farther down */
|
|
5429 int yclip = WINDOW_TEXT_TOP_CLIP (w);
|
442
|
5430 int force;
|
2518
|
5431 int depth = -1;
|
428
|
5432
|
|
5433 prop_block_dynarr *prop;
|
|
5434 layout_bounds bounds;
|
|
5435 display_line_dynarr *dla;
|
|
5436 int need_modeline;
|
|
5437
|
|
5438 /* The lines had better exist by this point. */
|
|
5439 if (!(dla = window_display_lines (w, type)))
|
2500
|
5440 ABORT ();
|
2518
|
5441
|
|
5442 if (!in_display)
|
|
5443 depth = enter_redisplay_critical_section ();
|
|
5444
|
|
5445 /* This is one spot where a re-entrancy crash will occur, due to a check
|
|
5446 in the dynarr to make sure it isn't "locked" */
|
|
5447 /*
|
|
5448
|
|
5449 Info on Re-entrancy crashes, with backtraces given:
|
|
5450
|
|
5451 (Info-goto-node "(internals)Nasty Bugs due to Reentrancy in Redisplay Structures handling QUIT")
|
|
5452 */
|
|
5453
|
428
|
5454 Dynarr_reset (dla);
|
|
5455 w->max_line_len = 0;
|
|
5456
|
|
5457 /* Normally these get updated in redisplay_window but it is possible
|
|
5458 for this function to get called from some other points where that
|
|
5459 update may not have occurred. This acts as a safety check. */
|
|
5460 if (!Dynarr_length (w->face_cachels))
|
|
5461 reset_face_cachels (w);
|
|
5462 if (!Dynarr_length (w->glyph_cachels))
|
|
5463 reset_glyph_cachels (w);
|
|
5464
|
|
5465 Fset_marker (w->start[type], make_int (start_pos), w->buffer);
|
|
5466 Fset_marker (w->pointm[type], make_int (point), w->buffer);
|
|
5467 w->last_point_x[type] = -1;
|
|
5468 w->last_point_y[type] = -1;
|
|
5469
|
|
5470 /* Make sure a modeline is in the structs if needed. */
|
|
5471 need_modeline = ensure_modeline_generated (w, type);
|
|
5472
|
|
5473 /* Wait until here to set this so that the structs have a modeline
|
|
5474 generated in the case where one didn't exist. */
|
|
5475 yend = WINDOW_TEXT_BOTTOM (w);
|
|
5476
|
|
5477 bounds = calculate_display_line_boundaries (w, 0);
|
|
5478
|
|
5479 /* 97/3/14 jhod: stuff added here to support pre-prompts (used for input systems) */
|
|
5480 if (MINI_WINDOW_P (w)
|
|
5481 && (!NILP (Vminibuf_prompt) || !NILP (Vminibuf_preprompt))
|
|
5482 && !echo_area_active (f)
|
|
5483 && start_pos == BUF_BEGV (b))
|
|
5484 {
|
|
5485 struct prop_block pb;
|
|
5486 Lisp_Object string;
|
|
5487 prop = Dynarr_new (prop_block);
|
|
5488
|
|
5489 string = concat2(Vminibuf_preprompt, Vminibuf_prompt);
|
|
5490 pb.type = PROP_MINIBUF_PROMPT;
|
|
5491 pb.data.p_string.str = XSTRING_DATA(string);
|
|
5492 pb.data.p_string.len = XSTRING_LENGTH(string);
|
|
5493 Dynarr_add (prop, pb);
|
|
5494 }
|
|
5495 else
|
|
5496 prop = 0;
|
|
5497
|
442
|
5498 /* When we are computing things for scrolling purposes, make
|
|
5499 sure at least one line is always generated */
|
|
5500 force = (type == CMOTION_DISP);
|
|
5501
|
|
5502 /* Make sure this is set always */
|
|
5503 /* Note the conversion at end */
|
|
5504 w->window_end_pos[type] = start_pos;
|
|
5505 while (ypos < yend || force)
|
428
|
5506 {
|
|
5507 struct display_line dl;
|
|
5508 struct display_line *dlp;
|
|
5509 int local;
|
851
|
5510 int pos_of_dlp = -1;
|
428
|
5511
|
|
5512 if (Dynarr_length (dla) < Dynarr_largest (dla))
|
|
5513 {
|
851
|
5514 pos_of_dlp = Dynarr_length (dla);
|
|
5515 dlp = Dynarr_atp (dla, pos_of_dlp);
|
428
|
5516 local = 0;
|
|
5517 }
|
|
5518 else
|
|
5519 {
|
|
5520
|
|
5521 xzero (dl);
|
|
5522 dlp = &dl;
|
|
5523 local = 1;
|
|
5524 }
|
|
5525
|
|
5526 dlp->bounds = bounds;
|
|
5527 dlp->offset = 0;
|
1318
|
5528 Dynarr_lock (dla);
|
428
|
5529 start_pos = generate_display_line (w, dlp, 1, start_pos, &prop, type);
|
1318
|
5530 Dynarr_unlock (dla);
|
428
|
5531
|
|
5532 if (yclip > dlp->ascent)
|
|
5533 {
|
|
5534 /* this should never happen, but if it does just display the
|
|
5535 whole line */
|
|
5536 yclip = 0;
|
|
5537 }
|
|
5538
|
|
5539 dlp->ypos = (ypos + dlp->ascent) - yclip;
|
|
5540 ypos = dlp->ypos + dlp->descent;
|
|
5541
|
|
5542 /* See if we've been asked to start midway through a line, for
|
|
5543 partial display line scrolling. */
|
434
|
5544 if (yclip)
|
428
|
5545 {
|
|
5546 dlp->top_clip = yclip;
|
|
5547 yclip = 0;
|
|
5548 }
|
|
5549 else
|
|
5550 dlp->top_clip = 0;
|
|
5551
|
|
5552 if (ypos > yend)
|
|
5553 {
|
|
5554 int visible_height = dlp->ascent + dlp->descent;
|
|
5555
|
|
5556 dlp->clip = (ypos - yend);
|
|
5557 /* Although this seems strange we could have a single very
|
|
5558 tall line visible for which we need to account for both
|
|
5559 the top clip and the bottom clip. */
|
|
5560 visible_height -= (dlp->clip + dlp->top_clip);
|
|
5561
|
442
|
5562 if (visible_height < VERTICAL_CLIP (w, 1) && !force)
|
428
|
5563 {
|
|
5564 if (local)
|
|
5565 free_display_line (dlp);
|
|
5566 break;
|
|
5567 }
|
|
5568 }
|
|
5569 else
|
|
5570 dlp->clip = 0;
|
|
5571
|
|
5572 if (dlp->cursor_elt != -1)
|
|
5573 {
|
|
5574 /* #### This check is steaming crap. Have to get things
|
|
5575 fixed so when create_text_block hits EOB, we're done,
|
|
5576 period. */
|
|
5577 if (w->last_point_x[type] == -1)
|
|
5578 {
|
|
5579 w->last_point_x[type] = dlp->cursor_elt;
|
|
5580 w->last_point_y[type] = Dynarr_length (dla);
|
|
5581 }
|
|
5582 else
|
|
5583 {
|
|
5584 /* #### This means that we've added a cursor at EOB
|
|
5585 twice. Yuck oh yuck. */
|
1318
|
5586 struct display_block *db;
|
|
5587
|
|
5588 Dynarr_lock (dla);
|
|
5589 db = get_display_block_from_line (dlp, TEXT);
|
|
5590 Dynarr_unlock (dla);
|
428
|
5591
|
|
5592 Dynarr_atp (db->runes, dlp->cursor_elt)->cursor_type = NO_CURSOR;
|
|
5593 dlp->cursor_elt = -1;
|
|
5594 }
|
|
5595 }
|
|
5596
|
|
5597 if (dlp->num_chars > w->max_line_len)
|
|
5598 w->max_line_len = dlp->num_chars;
|
|
5599
|
851
|
5600 assert (pos_of_dlp < 0 || pos_of_dlp == Dynarr_length (dla));
|
428
|
5601 Dynarr_add (dla, *dlp);
|
|
5602
|
|
5603 /* #### This isn't right, but it is close enough for now. */
|
|
5604 w->window_end_pos[type] = start_pos;
|
|
5605
|
|
5606 /* #### This type of check needs to be done down in the
|
|
5607 generate_display_line call. */
|
|
5608 if (start_pos > BUF_ZV (b))
|
|
5609 break;
|
442
|
5610
|
|
5611 force = 0;
|
428
|
5612 }
|
|
5613
|
|
5614 if (prop)
|
|
5615 Dynarr_free (prop);
|
|
5616
|
|
5617 /* #### More not quite right, but close enough. */
|
442
|
5618 /* Ben sez: apparently window_end_pos[] is measured
|
428
|
5619 as the number of characters between the window end and the
|
|
5620 end of the buffer? This seems rather weirdo. What's
|
442
|
5621 the justification for this?
|
|
5622
|
|
5623 JV sez: Because BUF_Z (b) would be a good initial value, however
|
|
5624 that can change. This representation allows initalizing with 0.
|
|
5625 */
|
428
|
5626 w->window_end_pos[type] = BUF_Z (b) - w->window_end_pos[type];
|
|
5627
|
|
5628 if (need_modeline)
|
|
5629 {
|
|
5630 /* We know that this is the right thing to use because we put it
|
|
5631 there when we first started working in this function. */
|
|
5632 generate_modeline (w, Dynarr_atp (dla, 0), type);
|
|
5633 }
|
2518
|
5634
|
|
5635 if (depth >= 0)
|
|
5636 exit_redisplay_critical_section (depth);
|
428
|
5637 }
|
|
5638
|
826
|
5639 #define REGEN_INC_FIND_START_END \
|
|
5640 do { \
|
|
5641 /* Determine start and end of lines. */ \
|
|
5642 if (!Dynarr_length (cdla)) \
|
|
5643 return 0; \
|
|
5644 else \
|
|
5645 { \
|
428
|
5646 if (Dynarr_atp (cdla, 0)->modeline && Dynarr_atp (ddla, 0)->modeline) \
|
826
|
5647 { \
|
|
5648 dla_start = 1; \
|
|
5649 } \
|
|
5650 else if (!Dynarr_atp (cdla, 0)->modeline \
|
|
5651 && !Dynarr_atp (ddla, 0)->modeline) \
|
|
5652 { \
|
|
5653 dla_start = 0; \
|
|
5654 } \
|
|
5655 else \
|
2500
|
5656 ABORT (); /* structs differ */ \
|
826
|
5657 \
|
|
5658 dla_end = Dynarr_length (cdla) - 1; \
|
|
5659 } \
|
|
5660 \
|
|
5661 start_pos = (Dynarr_atp (cdla, dla_start)->charpos \
|
|
5662 + Dynarr_atp (cdla, dla_start)->offset); \
|
|
5663 /* If this isn't true, then startp has changed and we need to do a \
|
|
5664 full regen. */ \
|
|
5665 if (startp != start_pos) \
|
|
5666 return 0; \
|
|
5667 \
|
|
5668 /* Point is outside the visible region so give up. */ \
|
|
5669 if (pointm < start_pos) \
|
|
5670 return 0; \
|
|
5671 \
|
428
|
5672 } while (0)
|
|
5673
|
|
5674 /* This attempts to incrementally update the display structures. It
|
|
5675 returns a boolean indicating success or failure. This function is
|
|
5676 very similar to regenerate_window_incrementally and is in fact only
|
|
5677 called from that function. However, because of the nature of the
|
|
5678 changes it deals with it sometimes makes different assumptions
|
|
5679 which can lead to success which are much more difficult to make
|
|
5680 when dealing with buffer changes. */
|
|
5681
|
|
5682 static int
|
665
|
5683 regenerate_window_extents_only_changed (struct window *w, Charbpos startp,
|
|
5684 Charbpos pointm,
|
428
|
5685 Charcount beg_unchanged,
|
|
5686 Charcount end_unchanged)
|
|
5687 {
|
|
5688 struct buffer *b = XBUFFER (w->buffer);
|
|
5689 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
|
|
5690 display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP);
|
|
5691
|
|
5692 int dla_start = 0;
|
|
5693 int dla_end, line;
|
|
5694 int first_line, last_line;
|
665
|
5695 Charbpos start_pos;
|
428
|
5696 /* Don't define this in the loop where it is used because we
|
|
5697 definitely want its value to survive between passes. */
|
|
5698 prop_block_dynarr *prop = NULL;
|
|
5699
|
|
5700 /* If we don't have any buffer change recorded but the modiff flag has
|
|
5701 been incremented, then fail. I'm not sure of the exact circumstances
|
|
5702 under which this can happen, but I believe that it is probably a
|
|
5703 reasonable happening. */
|
|
5704 if (!point_visible (w, pointm, CURRENT_DISP)
|
|
5705 || XINT (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b))
|
|
5706 return 0;
|
|
5707
|
|
5708 /* If the cursor is moved we attempt to update it. If we succeed we
|
|
5709 go ahead and proceed with the optimization attempt. */
|
|
5710 if (!EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer)
|
|
5711 || pointm != marker_position (w->last_point[CURRENT_DISP]))
|
|
5712 {
|
|
5713 struct frame *f = XFRAME (w->frame);
|
|
5714 struct device *d = XDEVICE (f->device);
|
|
5715 struct frame *sel_f = device_selected_frame (d);
|
|
5716 int success = 0;
|
|
5717
|
|
5718 if (w->last_point_x[CURRENT_DISP] != -1
|
|
5719 && w->last_point_y[CURRENT_DISP] != -1)
|
|
5720 {
|
|
5721
|
|
5722 if (redisplay_move_cursor (w, pointm, WINDOW_TTY_P (w)))
|
|
5723 {
|
|
5724 /* Always regenerate the modeline in case it is
|
|
5725 displaying the current line or column. */
|
|
5726 regenerate_modeline (w);
|
|
5727 success = 1;
|
|
5728 }
|
|
5729 }
|
|
5730 else if (w != XWINDOW (FRAME_SELECTED_WINDOW (sel_f)))
|
|
5731 {
|
|
5732 if (f->modeline_changed)
|
|
5733 regenerate_modeline (w);
|
|
5734 success = 1;
|
|
5735 }
|
|
5736
|
|
5737 if (!success)
|
|
5738 return 0;
|
|
5739 }
|
|
5740
|
|
5741 if (beg_unchanged == -1 && end_unchanged == -1)
|
|
5742 return 1;
|
|
5743
|
|
5744 /* assert: There are no buffer modifications or they are all below the
|
|
5745 visible region. We assume that regenerate_window_incrementally has
|
|
5746 not called us unless this is true. */
|
|
5747
|
|
5748 REGEN_INC_FIND_START_END;
|
|
5749
|
|
5750 /* If the changed are starts before the visible area, give up. */
|
|
5751 if (beg_unchanged < startp)
|
|
5752 return 0;
|
|
5753
|
|
5754 /* Find what display line the extent changes first affect. */
|
|
5755 line = dla_start;
|
|
5756 while (line <= dla_end)
|
|
5757 {
|
|
5758 struct display_line *dl = Dynarr_atp (cdla, line);
|
826
|
5759 Charbpos lstart = dl->charpos + dl->offset;
|
|
5760 Charbpos lend = dl->end_charpos + dl->offset;
|
428
|
5761
|
|
5762 if (beg_unchanged >= lstart && beg_unchanged <= lend)
|
|
5763 break;
|
|
5764
|
|
5765 line++;
|
|
5766 }
|
|
5767
|
|
5768 /* If the changes are below the visible area then if point hasn't
|
|
5769 moved return success otherwise fail in order to be safe. */
|
|
5770 if (line > dla_end)
|
|
5771 {
|
|
5772 if (EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer)
|
|
5773 && pointm == marker_position (w->last_point[CURRENT_DISP]))
|
|
5774 return 1;
|
|
5775 else
|
|
5776 return 0;
|
|
5777 }
|
|
5778
|
|
5779 /* At this point we know what line the changes first affect. We now
|
|
5780 begin redrawing lines as long as we are still in the affected
|
|
5781 region and the line's size and positioning don't change.
|
|
5782 Otherwise we fail. If we fail we will have altered the desired
|
|
5783 structs which could lead to an assertion failure. However, if we
|
|
5784 fail the next thing that is going to happen is a full regen so we
|
|
5785 will actually end up being safe. */
|
|
5786 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b));
|
|
5787 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b));
|
|
5788 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp), w->buffer);
|
|
5789 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm), w->buffer);
|
|
5790
|
|
5791 first_line = last_line = line;
|
|
5792 while (line <= dla_end)
|
|
5793 {
|
2286
|
5794 Charbpos old_start, old_end;
|
428
|
5795 struct display_line *cdl = Dynarr_atp (cdla, line);
|
|
5796 struct display_line *ddl = Dynarr_atp (ddla, line);
|
|
5797 struct display_block *db;
|
|
5798 int initial_size;
|
|
5799
|
826
|
5800 assert (cdl->charpos == ddl->charpos);
|
|
5801 assert (cdl->end_charpos == ddl->end_charpos);
|
428
|
5802 assert (cdl->offset == ddl->offset);
|
|
5803
|
|
5804 db = get_display_block_from_line (ddl, TEXT);
|
|
5805 initial_size = Dynarr_length (db->runes);
|
826
|
5806 old_start = ddl->charpos + ddl->offset;
|
|
5807 old_end = ddl->end_charpos + ddl->offset;
|
428
|
5808
|
|
5809 /* If this is the first line being updated and it used
|
|
5810 propagation data, fail. Otherwise we'll be okay because
|
|
5811 we'll have the necessary propagation data. */
|
|
5812 if (line == first_line && ddl->used_prop_data)
|
|
5813 return 0;
|
|
5814
|
2286
|
5815 generate_display_line (w, ddl, 0, ddl->charpos + ddl->offset,
|
|
5816 &prop, DESIRED_DISP);
|
428
|
5817 ddl->offset = 0;
|
|
5818
|
|
5819 /* #### If there is propagated stuff the fail. We could
|
|
5820 probably actually deal with this if the line had propagated
|
|
5821 information when originally created by a full
|
|
5822 regeneration. */
|
|
5823 if (prop)
|
|
5824 {
|
|
5825 Dynarr_free (prop);
|
|
5826 return 0;
|
|
5827 }
|
|
5828
|
|
5829 /* If any line position parameters have changed or a
|
|
5830 cursor has disappeared or disappeared, fail. */
|
|
5831 db = get_display_block_from_line (ddl, TEXT);
|
|
5832 if (cdl->ypos != ddl->ypos
|
|
5833 || cdl->ascent != ddl->ascent
|
|
5834 || cdl->descent != ddl->descent
|
|
5835 || cdl->top_clip != ddl->top_clip
|
|
5836 || (cdl->cursor_elt != -1 && ddl->cursor_elt == -1)
|
|
5837 || (cdl->cursor_elt == -1 && ddl->cursor_elt != -1)
|
826
|
5838 || old_start != ddl->charpos
|
|
5839 || old_end != ddl->end_charpos
|
428
|
5840 || initial_size != Dynarr_length (db->runes))
|
|
5841 {
|
|
5842 return 0;
|
|
5843 }
|
|
5844
|
|
5845 if (ddl->cursor_elt != -1)
|
|
5846 {
|
|
5847 w->last_point_x[DESIRED_DISP] = ddl->cursor_elt;
|
|
5848 w->last_point_y[DESIRED_DISP] = line;
|
|
5849 }
|
|
5850
|
|
5851 last_line = line;
|
|
5852
|
|
5853 /* If the extent changes end on the line we just updated then
|
|
5854 we're done. Otherwise go on to the next line. */
|
826
|
5855 if (end_unchanged <= ddl->end_charpos)
|
428
|
5856 break;
|
|
5857 else
|
|
5858 line++;
|
|
5859 }
|
|
5860
|
|
5861 redisplay_update_line (w, first_line, last_line, 1);
|
|
5862 return 1;
|
|
5863 }
|
|
5864
|
|
5865 /* Attempt to update the display data structures based on knowledge of
|
|
5866 the changed region in the buffer. Returns a boolean indicating
|
|
5867 success or failure. If this function returns a failure then a
|
|
5868 regenerate_window _must_ be performed next in order to maintain
|
|
5869 invariants located here. */
|
|
5870
|
|
5871 static int
|
665
|
5872 regenerate_window_incrementally (struct window *w, Charbpos startp,
|
|
5873 Charbpos pointm)
|
428
|
5874 {
|
|
5875 struct buffer *b = XBUFFER (w->buffer);
|
|
5876 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
|
|
5877 display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP);
|
|
5878 Charcount beg_unchanged, end_unchanged;
|
|
5879 Charcount extent_beg_unchanged, extent_end_unchanged;
|
|
5880
|
|
5881 int dla_start = 0;
|
|
5882 int dla_end, line;
|
665
|
5883 Charbpos start_pos;
|
428
|
5884
|
|
5885 /* If this function is called, the current and desired structures
|
|
5886 had better be identical. If they are not, then that is a bug. */
|
|
5887 assert (Dynarr_length (cdla) == Dynarr_length (ddla));
|
|
5888
|
|
5889 /* We don't handle minibuffer windows yet. The minibuffer prompt
|
|
5890 screws us up. */
|
|
5891 if (MINI_WINDOW_P (w))
|
|
5892 return 0;
|
|
5893
|
|
5894 extent_beg_unchanged = BUF_EXTENT_BEGIN_UNCHANGED (b);
|
|
5895 extent_end_unchanged = (BUF_EXTENT_END_UNCHANGED (b) == -1
|
|
5896 ? -1
|
|
5897 : BUF_Z (b) - BUF_EXTENT_END_UNCHANGED (b));
|
|
5898
|
|
5899 /* If nothing has changed in the buffer, then make sure point is ok
|
|
5900 and succeed. */
|
|
5901 if (BUF_BEGIN_UNCHANGED (b) == -1 && BUF_END_UNCHANGED (b) == -1)
|
|
5902 return regenerate_window_extents_only_changed (w, startp, pointm,
|
|
5903 extent_beg_unchanged,
|
|
5904 extent_end_unchanged);
|
|
5905
|
|
5906 /* We can't deal with deleted newlines. */
|
|
5907 if (BUF_NEWLINE_WAS_DELETED (b))
|
|
5908 return 0;
|
|
5909
|
|
5910 beg_unchanged = BUF_BEGIN_UNCHANGED (b);
|
|
5911 end_unchanged = (BUF_END_UNCHANGED (b) == -1
|
|
5912 ? -1
|
|
5913 : BUF_Z (b) - BUF_END_UNCHANGED (b));
|
|
5914
|
|
5915 REGEN_INC_FIND_START_END;
|
|
5916
|
|
5917 /* If the changed area starts before the visible area, give up. */
|
|
5918 if (beg_unchanged < startp)
|
|
5919 return 0;
|
|
5920
|
|
5921 /* Find what display line the buffer changes first affect. */
|
|
5922 line = dla_start;
|
|
5923 while (line <= dla_end)
|
|
5924 {
|
|
5925 struct display_line *dl = Dynarr_atp (cdla, line);
|
826
|
5926 Charbpos lstart = dl->charpos + dl->offset;
|
|
5927 Charbpos lend = dl->end_charpos + dl->offset;
|
428
|
5928
|
|
5929 if (beg_unchanged >= lstart && beg_unchanged <= lend)
|
|
5930 break;
|
|
5931
|
|
5932 line++;
|
|
5933 }
|
|
5934
|
|
5935 /* If the changes are below the visible area then if point hasn't
|
|
5936 moved return success otherwise fail in order to be safe. */
|
|
5937 if (line > dla_end)
|
|
5938 return regenerate_window_extents_only_changed (w, startp, pointm,
|
|
5939 extent_beg_unchanged,
|
|
5940 extent_end_unchanged);
|
|
5941 else
|
|
5942 /* At this point we know what line the changes first affect. We
|
|
5943 now redraw that line. If the changes are contained within it
|
|
5944 we are going to succeed and can update just that one line.
|
|
5945 Otherwise we fail. If we fail we will have altered the desired
|
|
5946 structs which could lead to an assertion failure. However, if
|
|
5947 we fail the next thing that is going to happen is a full regen
|
|
5948 so we will actually end up being safe. */
|
|
5949 {
|
|
5950 prop_block_dynarr *prop = NULL;
|
|
5951 struct display_line *cdl = Dynarr_atp (cdla, line);
|
|
5952 struct display_line *ddl = Dynarr_atp (ddla, line);
|
|
5953
|
826
|
5954 assert (cdl->charpos == ddl->charpos);
|
|
5955 assert (cdl->end_charpos == ddl->end_charpos);
|
428
|
5956 assert (cdl->offset == ddl->offset);
|
|
5957
|
442
|
5958 /* If the line continues to next display line, fail. */
|
|
5959 if (ddl->line_continuation)
|
|
5960 return 0;
|
428
|
5961
|
|
5962 /* If the line was generated using propagation data, fail. */
|
|
5963 if (ddl->used_prop_data)
|
|
5964 return 0;
|
|
5965
|
2286
|
5966 generate_display_line (w, ddl, 0, ddl->charpos + ddl->offset,
|
|
5967 &prop, DESIRED_DISP);
|
428
|
5968 ddl->offset = 0;
|
|
5969
|
|
5970 /* If there is propagated stuff then it is pretty much a
|
|
5971 guarantee that more than just the one line is affected. */
|
|
5972 if (prop)
|
|
5973 {
|
|
5974 Dynarr_free (prop);
|
|
5975 return 0;
|
|
5976 }
|
|
5977
|
442
|
5978 /* If the line continues to next display line, fail. */
|
|
5979 if (ddl->line_continuation)
|
|
5980 return 0;
|
428
|
5981
|
|
5982 /* If any line position parameters have changed or a
|
|
5983 cursor has disappeared or disappeared, fail. */
|
|
5984 if (cdl->ypos != ddl->ypos
|
|
5985 || cdl->ascent != ddl->ascent
|
|
5986 || cdl->descent != ddl->descent
|
|
5987 || cdl->top_clip != ddl->top_clip
|
|
5988 || (cdl->cursor_elt != -1 && ddl->cursor_elt == -1)
|
|
5989 || (cdl->cursor_elt == -1 && ddl->cursor_elt != -1))
|
|
5990 {
|
|
5991 return 0;
|
|
5992 }
|
|
5993
|
|
5994 /* If the changed area also ends on this line, then we may be in
|
|
5995 business. Update everything and return success. */
|
826
|
5996 if (end_unchanged >= ddl->charpos && end_unchanged <= ddl->end_charpos)
|
428
|
5997 {
|
|
5998 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b));
|
|
5999 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b));
|
|
6000 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp),
|
|
6001 w->buffer);
|
|
6002 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm),
|
|
6003 w->buffer);
|
|
6004
|
|
6005 if (ddl->cursor_elt != -1)
|
|
6006 {
|
|
6007 w->last_point_x[DESIRED_DISP] = ddl->cursor_elt;
|
|
6008 w->last_point_y[DESIRED_DISP] = line;
|
|
6009 }
|
|
6010
|
|
6011 redisplay_update_line (w, line, line, 1);
|
|
6012 regenerate_modeline (w);
|
|
6013
|
|
6014 /* #### For now we just flush the cache until this has been
|
|
6015 tested. After that is done, this should correct the
|
|
6016 cache directly. */
|
|
6017 Dynarr_reset (w->line_start_cache);
|
|
6018
|
|
6019 /* Adjust the extent changed boundaries to remove any
|
|
6020 overlap with the buffer changes since we've just
|
|
6021 successfully updated that area. */
|
|
6022 if (extent_beg_unchanged != -1
|
|
6023 && extent_beg_unchanged >= beg_unchanged
|
|
6024 && extent_beg_unchanged < end_unchanged)
|
|
6025 extent_beg_unchanged = end_unchanged;
|
|
6026
|
|
6027 if (extent_end_unchanged != -1
|
|
6028 && extent_end_unchanged >= beg_unchanged
|
|
6029 && extent_end_unchanged < end_unchanged)
|
|
6030 extent_end_unchanged = beg_unchanged - 1;
|
|
6031
|
|
6032 if (extent_end_unchanged <= extent_beg_unchanged)
|
|
6033 extent_beg_unchanged = extent_end_unchanged = -1;
|
|
6034
|
|
6035 /* This could lead to odd results if it fails, but since the
|
|
6036 buffer changes update succeeded this probably will to.
|
|
6037 We already know that the extent changes start at or after
|
|
6038 the line because we checked before entering the loop. */
|
|
6039 if (extent_beg_unchanged != -1
|
|
6040 && extent_end_unchanged != -1
|
826
|
6041 && ((extent_beg_unchanged < ddl->charpos)
|
|
6042 || (extent_end_unchanged > ddl->end_charpos)))
|
428
|
6043 return regenerate_window_extents_only_changed (w, startp, pointm,
|
|
6044 extent_beg_unchanged,
|
|
6045 extent_end_unchanged);
|
|
6046 else
|
|
6047 return 1;
|
|
6048 }
|
|
6049 }
|
|
6050
|
|
6051 /* Oh, well. */
|
|
6052 return 0;
|
|
6053 }
|
|
6054
|
|
6055 /* Given a window and a point, update the given display lines such
|
|
6056 that point is displayed in the middle of the window.
|
|
6057 Return the window's new start position. */
|
|
6058
|
665
|
6059 static Charbpos
|
|
6060 regenerate_window_point_center (struct window *w, Charbpos point, int type)
|
428
|
6061 {
|
665
|
6062 Charbpos startp;
|
428
|
6063
|
|
6064 /* We need to make sure that the modeline is generated so that the
|
|
6065 window height can be calculated correctly. */
|
|
6066 ensure_modeline_generated (w, type);
|
|
6067
|
|
6068 startp = start_with_line_at_pixpos (w, point, window_half_pixpos (w));
|
|
6069 regenerate_window (w, startp, point, type);
|
|
6070 Fset_marker (w->start[type], make_int (startp), w->buffer);
|
|
6071
|
|
6072 return startp;
|
|
6073 }
|
|
6074
|
|
6075 /* Given a window and a set of display lines, return a boolean
|
|
6076 indicating whether the given point is contained within. */
|
|
6077
|
|
6078 static int
|
665
|
6079 point_visible (struct window *w, Charbpos point, int type)
|
428
|
6080 {
|
|
6081 struct buffer *b = XBUFFER (w->buffer);
|
|
6082 display_line_dynarr *dla = window_display_lines (w, type);
|
|
6083 int first_line;
|
|
6084
|
|
6085 if (Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
|
|
6086 first_line = 1;
|
|
6087 else
|
|
6088 first_line = 0;
|
|
6089
|
|
6090 if (Dynarr_length (dla) > first_line)
|
|
6091 {
|
665
|
6092 Charbpos start, end;
|
428
|
6093 struct display_line *dl = Dynarr_atp (dla, first_line);
|
|
6094
|
826
|
6095 start = dl->charpos;
|
428
|
6096 end = BUF_Z (b) - w->window_end_pos[type] - 1;
|
|
6097
|
|
6098 if (point >= start && point <= end)
|
|
6099 {
|
|
6100 if (!MINI_WINDOW_P (w) && scroll_on_clipped_lines)
|
|
6101 {
|
|
6102 dl = Dynarr_atp (dla, Dynarr_length (dla) - 1);
|
|
6103
|
826
|
6104 if (point >= (dl->charpos + dl->offset)
|
|
6105 && point <= (dl->end_charpos + dl->offset))
|
428
|
6106 return !dl->clip;
|
|
6107 else
|
|
6108 return 1;
|
|
6109 }
|
|
6110 else
|
|
6111 return 1;
|
|
6112 }
|
|
6113 else
|
|
6114 return 0;
|
|
6115 }
|
|
6116 else
|
|
6117 return 0;
|
|
6118 }
|
|
6119
|
|
6120 /* Return pixel position the middle of the window, not including the
|
|
6121 modeline and any potential horizontal scrollbar. */
|
|
6122
|
|
6123 int
|
|
6124 window_half_pixpos (struct window *w)
|
|
6125 {
|
|
6126 return WINDOW_TEXT_TOP (w) + (WINDOW_TEXT_HEIGHT (w) >> 1);
|
|
6127 }
|
|
6128
|
|
6129 /* Return the display line which is currently in the middle of the
|
|
6130 window W for display lines TYPE. */
|
|
6131
|
|
6132 int
|
665
|
6133 line_at_center (struct window *w, int type, Charbpos start, Charbpos point)
|
428
|
6134 {
|
|
6135 display_line_dynarr *dla;
|
|
6136 int half;
|
|
6137 int elt;
|
|
6138 int first_elt = (MINI_WINDOW_P (w) ? 0 : 1);
|
|
6139
|
|
6140 if (type == CMOTION_DISP)
|
|
6141 regenerate_window (w, start, point, type);
|
|
6142
|
|
6143 dla = window_display_lines (w, type);
|
|
6144 half = window_half_pixpos (w);
|
|
6145
|
|
6146 for (elt = first_elt; elt < Dynarr_length (dla); elt++)
|
|
6147 {
|
|
6148 struct display_line *dl = Dynarr_atp (dla, elt);
|
|
6149 int line_bot = dl->ypos + dl->descent;
|
|
6150
|
|
6151 if (line_bot > half)
|
|
6152 return elt;
|
|
6153 }
|
|
6154
|
|
6155 /* We may not have a line at the middle if the end of the buffer is
|
|
6156 being displayed. */
|
|
6157 return -1;
|
|
6158 }
|
|
6159
|
|
6160 /* Return a value for point that would place it at the beginning of
|
|
6161 the line which is in the middle of the window. */
|
|
6162
|
665
|
6163 Charbpos
|
|
6164 point_at_center (struct window *w, int type, Charbpos start, Charbpos point)
|
428
|
6165 {
|
|
6166 /* line_at_center will regenerate the display structures, if necessary. */
|
|
6167 int line = line_at_center (w, type, start, point);
|
|
6168
|
|
6169 if (line == -1)
|
|
6170 return BUF_ZV (XBUFFER (w->buffer));
|
|
6171 else
|
|
6172 {
|
|
6173 display_line_dynarr *dla = window_display_lines (w, type);
|
|
6174 struct display_line *dl = Dynarr_atp (dla, line);
|
|
6175
|
826
|
6176 return dl->charpos;
|
428
|
6177 }
|
|
6178 }
|
|
6179
|
|
6180 /* For a given window, ensure that the current visual representation
|
|
6181 is accurate. */
|
|
6182
|
|
6183 static void
|
|
6184 redisplay_window (Lisp_Object window, int skip_selected)
|
|
6185 {
|
|
6186 struct window *w = XWINDOW (window);
|
|
6187 struct frame *f = XFRAME (w->frame);
|
|
6188 struct device *d = XDEVICE (f->device);
|
|
6189 Lisp_Object old_buffer = w->buffer;
|
|
6190 Lisp_Object the_buffer = w->buffer;
|
|
6191 struct buffer *b;
|
|
6192 int echo_active = 0;
|
|
6193 int startp = 1;
|
|
6194 int pointm;
|
|
6195 int old_startp = 1;
|
|
6196 int old_pointm = 1;
|
|
6197 int selected_in_its_frame;
|
|
6198 int selected_globally;
|
|
6199 int skip_output = 0;
|
|
6200 int truncation_changed;
|
|
6201 int inactive_minibuffer =
|
|
6202 (MINI_WINDOW_P (w) &&
|
|
6203 (f != device_selected_frame (d)) &&
|
|
6204 !is_surrogate_for_selected_frame (f));
|
|
6205
|
|
6206 /* #### In the new world this function actually does a bunch of
|
|
6207 optimizations such as buffer-based scrolling, but none of that is
|
|
6208 implemented yet. */
|
|
6209
|
|
6210 /* If this is a combination window, do its children; that's all.
|
|
6211 The selected window is always a leaf so we don't check for
|
|
6212 skip_selected here. */
|
|
6213 if (!NILP (w->vchild))
|
|
6214 {
|
|
6215 redisplay_windows (w->vchild, skip_selected);
|
|
6216 return;
|
|
6217 }
|
|
6218 if (!NILP (w->hchild))
|
|
6219 {
|
|
6220 redisplay_windows (w->hchild, skip_selected);
|
|
6221 return;
|
|
6222 }
|
|
6223
|
|
6224 /* Is this window the selected window on its frame? */
|
|
6225 selected_in_its_frame = (w == XWINDOW (FRAME_SELECTED_WINDOW (f)));
|
|
6226 selected_globally =
|
|
6227 selected_in_its_frame &&
|
|
6228 EQ(DEVICE_CONSOLE(d), Vselected_console) &&
|
|
6229 XDEVICE(CONSOLE_SELECTED_DEVICE(XCONSOLE(DEVICE_CONSOLE(d)))) == d &&
|
|
6230 XFRAME(DEVICE_SELECTED_FRAME(d)) == f;
|
|
6231 if (skip_selected && selected_in_its_frame)
|
|
6232 return;
|
|
6233
|
|
6234 /* It is possible that the window is not fully initialized yet. */
|
|
6235 if (NILP (w->buffer))
|
|
6236 return;
|
|
6237
|
|
6238 if (MINI_WINDOW_P (w) && echo_area_active (f))
|
|
6239 {
|
|
6240 w->buffer = the_buffer = Vecho_area_buffer;
|
|
6241 echo_active = 1;
|
|
6242 }
|
|
6243
|
|
6244 b = XBUFFER (w->buffer);
|
|
6245
|
|
6246 if (echo_active)
|
|
6247 {
|
|
6248 old_pointm = selected_globally
|
|
6249 ? BUF_PT (b)
|
|
6250 : marker_position (w->pointm[CURRENT_DISP]);
|
|
6251 pointm = 1;
|
|
6252 }
|
|
6253 else
|
|
6254 {
|
|
6255 if (selected_globally)
|
|
6256 {
|
|
6257 pointm = BUF_PT (b);
|
|
6258 }
|
|
6259 else
|
|
6260 {
|
|
6261 pointm = marker_position (w->pointm[CURRENT_DISP]);
|
|
6262
|
|
6263 if (pointm < BUF_BEGV (b))
|
|
6264 pointm = BUF_BEGV (b);
|
|
6265 else if (pointm > BUF_ZV (b))
|
|
6266 pointm = BUF_ZV (b);
|
|
6267 }
|
|
6268 }
|
|
6269 Fset_marker (w->pointm[DESIRED_DISP], make_int (pointm), the_buffer);
|
|
6270
|
|
6271 /* If the buffer has changed we have to invalidate all of our face
|
|
6272 cache elements. */
|
|
6273 if ((!echo_active && b != window_display_buffer (w))
|
|
6274 || !Dynarr_length (w->face_cachels)
|
|
6275 || f->faces_changed)
|
|
6276 reset_face_cachels (w);
|
|
6277 else
|
|
6278 mark_face_cachels_as_not_updated (w);
|
|
6279
|
|
6280 /* Ditto the glyph cache elements, although we do *not* invalidate
|
|
6281 the cache purely because glyphs have changed - this is now
|
|
6282 handled by the dirty flag.*/
|
|
6283 if ((!echo_active && b != window_display_buffer (w))
|
440
|
6284 || !Dynarr_length (w->glyph_cachels) || f->faces_changed)
|
428
|
6285 reset_glyph_cachels (w);
|
|
6286 else
|
|
6287 mark_glyph_cachels_as_not_updated (w);
|
|
6288
|
|
6289 /* If the marker's buffer is not the window's buffer, then we need
|
|
6290 to find a new starting position. */
|
|
6291 if (!MINI_WINDOW_P (w)
|
|
6292 && !EQ (Fmarker_buffer (w->start[CURRENT_DISP]), w->buffer))
|
|
6293 {
|
|
6294 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP);
|
|
6295
|
|
6296 goto regeneration_done;
|
|
6297 }
|
|
6298
|
|
6299 if (echo_active)
|
|
6300 {
|
|
6301 old_startp = marker_position (w->start[CURRENT_DISP]);
|
|
6302 startp = 1;
|
|
6303 }
|
|
6304 else
|
|
6305 {
|
|
6306 startp = marker_position (w->start[CURRENT_DISP]);
|
|
6307 if (startp < BUF_BEGV (b))
|
|
6308 startp = BUF_BEGV (b);
|
|
6309 else if (startp > BUF_ZV (b))
|
|
6310 startp = BUF_ZV (b);
|
|
6311 }
|
|
6312 Fset_marker (w->start[DESIRED_DISP], make_int (startp), the_buffer);
|
|
6313
|
|
6314 truncation_changed = (find_window_mirror (w)->truncate_win !=
|
647
|
6315 (unsigned int) window_truncation_on (w));
|
428
|
6316
|
|
6317 /* If w->force_start is set, then some function set w->start and we
|
|
6318 should display from there and change point, if necessary, to
|
|
6319 ensure that it is visible. */
|
|
6320 if (w->force_start || inactive_minibuffer)
|
|
6321 {
|
|
6322 w->force_start = 0;
|
|
6323 w->last_modified[DESIRED_DISP] = Qzero;
|
|
6324 w->last_facechange[DESIRED_DISP] = Qzero;
|
|
6325
|
|
6326 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6327
|
|
6328 if (!point_visible (w, pointm, DESIRED_DISP) && !inactive_minibuffer)
|
|
6329 {
|
|
6330 pointm = point_at_center (w, DESIRED_DISP, 0, 0);
|
|
6331
|
|
6332 if (selected_globally)
|
|
6333 BUF_SET_PT (b, pointm);
|
|
6334
|
|
6335 Fset_marker (w->pointm[DESIRED_DISP], make_int (pointm),
|
|
6336 the_buffer);
|
|
6337
|
|
6338 /* #### BUFU amounts of overkill just to get the cursor
|
|
6339 location marked properly. FIX ME FIX ME FIX ME */
|
|
6340 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6341 }
|
|
6342
|
|
6343 goto regeneration_done;
|
|
6344 }
|
|
6345
|
|
6346 /* If nothing has changed since the last redisplay, then we just
|
|
6347 need to make sure that point is still visible. */
|
|
6348 if (XINT (w->last_modified[CURRENT_DISP]) >= BUF_MODIFF (b)
|
|
6349 && XINT (w->last_facechange[CURRENT_DISP]) >= BUF_FACECHANGE (b)
|
|
6350 && pointm >= startp
|
|
6351 /* This check is to make sure we restore the minibuffer after a
|
|
6352 temporary change to the echo area. */
|
|
6353 && !(MINI_WINDOW_P (w) && f->buffers_changed)
|
|
6354 && !f->frame_changed
|
|
6355 && !truncation_changed
|
442
|
6356 /* check whether start is really at the beginning of a line GE */
|
428
|
6357 && (!w->start_at_line_beg || beginning_of_line_p (b, startp))
|
|
6358 )
|
|
6359 {
|
|
6360 /* Check if the cursor has actually moved. */
|
|
6361 if (EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer)
|
|
6362 && pointm == marker_position (w->last_point[CURRENT_DISP])
|
|
6363 && selected_globally
|
|
6364 && !w->windows_changed
|
|
6365 && !f->clip_changed
|
|
6366 && !f->extents_changed
|
|
6367 && !f->faces_changed
|
|
6368 && !f->glyphs_changed
|
|
6369 && !f->subwindows_changed
|
442
|
6370 /* && !f->subwindows_state_changed*/
|
428
|
6371 && !f->point_changed
|
|
6372 && !f->windows_structure_changed)
|
|
6373 {
|
|
6374 /* If not, we're done. */
|
|
6375 if (f->modeline_changed)
|
|
6376 regenerate_modeline (w);
|
|
6377
|
|
6378 skip_output = 1;
|
|
6379 goto regeneration_done;
|
|
6380 }
|
|
6381 else
|
|
6382 {
|
|
6383 /* If the new point is visible in the redisplay structures,
|
|
6384 then let the output update routines handle it, otherwise
|
|
6385 do things the hard way. */
|
|
6386 if (!w->windows_changed
|
|
6387 && !f->clip_changed
|
|
6388 && !f->extents_changed
|
|
6389 && !f->faces_changed
|
|
6390 && !f->glyphs_changed
|
|
6391 && !f->subwindows_changed
|
442
|
6392 /* && !f->subwindows_state_changed*/
|
428
|
6393 && !f->windows_structure_changed)
|
|
6394 {
|
|
6395 if (point_visible (w, pointm, CURRENT_DISP)
|
|
6396 && w->last_point_x[CURRENT_DISP] != -1
|
|
6397 && w->last_point_y[CURRENT_DISP] != -1)
|
|
6398 {
|
|
6399 if (redisplay_move_cursor (w, pointm, FRAME_TTY_P (f)))
|
|
6400 {
|
|
6401 /* Always regenerate in case it is displaying
|
|
6402 the current line or column. */
|
|
6403 regenerate_modeline (w);
|
|
6404
|
|
6405 skip_output = 1;
|
|
6406 goto regeneration_done;
|
|
6407 }
|
|
6408 }
|
|
6409 else if (!selected_in_its_frame && !f->point_changed)
|
|
6410 {
|
|
6411 if (f->modeline_changed)
|
|
6412 regenerate_modeline (w);
|
|
6413
|
|
6414 skip_output = 1;
|
|
6415 goto regeneration_done;
|
|
6416 }
|
|
6417 }
|
|
6418
|
|
6419 /* If we weren't able to take the shortcut method, then use
|
|
6420 the brute force method. */
|
|
6421 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6422
|
|
6423 if (point_visible (w, pointm, DESIRED_DISP))
|
|
6424 goto regeneration_done;
|
|
6425 }
|
|
6426 }
|
|
6427
|
|
6428 /* Check if the starting point is no longer at the beginning of a
|
|
6429 line, in which case find a new starting point. We also recenter
|
|
6430 if our start position is equal to point-max. Otherwise we'll end
|
|
6431 up with a blank window. */
|
|
6432 else if (((w->start_at_line_beg || MINI_WINDOW_P (w))
|
|
6433 && !(startp == BUF_BEGV (b)
|
|
6434 || BUF_FETCH_CHAR (b, startp - 1) == '\n'))
|
|
6435 || (pointm == startp &&
|
|
6436 EQ (Fmarker_buffer (w->last_start[CURRENT_DISP]), w->buffer) &&
|
|
6437 startp < marker_position (w->last_start[CURRENT_DISP]))
|
|
6438 || (startp == BUF_ZV (b)))
|
|
6439 {
|
|
6440 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP);
|
|
6441
|
|
6442 goto regeneration_done;
|
|
6443 }
|
|
6444 /* See if we can update the data structures locally based on
|
|
6445 knowledge of what changed in the buffer. */
|
|
6446 else if (!w->windows_changed
|
|
6447 && !f->clip_changed
|
|
6448 && !f->faces_changed
|
|
6449 && !f->glyphs_changed
|
|
6450 && !f->subwindows_changed
|
442
|
6451 /* && !f->subwindows_state_changed*/
|
428
|
6452 && !f->windows_structure_changed
|
|
6453 && !f->frame_changed
|
|
6454 && !truncation_changed
|
|
6455 && pointm >= startp
|
|
6456 && regenerate_window_incrementally (w, startp, pointm))
|
|
6457 {
|
|
6458 if (f->modeline_changed
|
|
6459 || XINT (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b)
|
|
6460 || XINT (w->last_facechange[CURRENT_DISP]) < BUF_FACECHANGE (b))
|
|
6461 regenerate_modeline (w);
|
|
6462
|
|
6463 skip_output = 1;
|
|
6464 goto regeneration_done;
|
|
6465 }
|
|
6466 /* #### This is where a check for structure based scrolling would go. */
|
|
6467 /* If all else fails, try just regenerating and see what happens. */
|
|
6468 else
|
|
6469 {
|
|
6470 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6471
|
|
6472 if (point_visible (w, pointm, DESIRED_DISP))
|
|
6473 goto regeneration_done;
|
|
6474 }
|
|
6475
|
|
6476 /* We still haven't gotten the window regenerated with point
|
|
6477 visible. Next we try scrolling a little and see if point comes
|
|
6478 back onto the screen. */
|
|
6479 if (scroll_step > 0)
|
|
6480 {
|
|
6481 int scrolled = scroll_conservatively;
|
|
6482 for (; scrolled >= 0; scrolled -= scroll_step)
|
|
6483 {
|
|
6484 startp = vmotion (w, startp,
|
|
6485 (pointm < startp) ? -scroll_step : scroll_step, 0);
|
|
6486 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6487
|
|
6488 if (point_visible (w, pointm, DESIRED_DISP))
|
|
6489 goto regeneration_done;
|
|
6490 }
|
|
6491 }
|
|
6492
|
|
6493 /* We still haven't managed to get the screen drawn with point on
|
|
6494 the screen, so just center it and be done with it. */
|
|
6495 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP);
|
|
6496
|
|
6497
|
|
6498 regeneration_done:
|
|
6499
|
|
6500 /* If the window's frame is changed then reset the current display
|
|
6501 lines in order to force a full repaint. */
|
|
6502 if (f->frame_changed)
|
|
6503 {
|
|
6504 display_line_dynarr *cla = window_display_lines (w, CURRENT_DISP);
|
|
6505
|
|
6506 Dynarr_reset (cla);
|
|
6507 }
|
|
6508
|
|
6509 /* Must do this before calling redisplay_output_window because it
|
|
6510 sets some markers on the window. */
|
|
6511 if (echo_active)
|
|
6512 {
|
|
6513 w->buffer = old_buffer;
|
|
6514 Fset_marker (w->pointm[DESIRED_DISP], make_int (old_pointm), old_buffer);
|
|
6515 Fset_marker (w->start[DESIRED_DISP], make_int (old_startp), old_buffer);
|
|
6516 }
|
|
6517
|
|
6518 /* These also have to be set before calling redisplay_output_window
|
|
6519 since it sets the CURRENT_DISP values based on them. */
|
|
6520 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b));
|
|
6521 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b));
|
|
6522 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp), w->buffer);
|
|
6523 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm), w->buffer);
|
|
6524
|
|
6525 if (!skip_output)
|
|
6526 {
|
665
|
6527 Charbpos start = marker_position (w->start[DESIRED_DISP]);
|
|
6528 Charbpos end = (w->window_end_pos[DESIRED_DISP] == -1
|
428
|
6529 ? BUF_ZV (b)
|
|
6530 : BUF_Z (b) - w->window_end_pos[DESIRED_DISP] - 1);
|
|
6531 /* Don't pollute the cache if not sure if we are correct */
|
|
6532 if (w->start_at_line_beg)
|
|
6533 update_line_start_cache (w, start, end, pointm, 1);
|
|
6534 redisplay_output_window (w);
|
|
6535 /*
|
|
6536 * If we just displayed the echo area, the line start cache is
|
|
6537 * no longer valid, because the minibuffer window is associated
|
|
6538 * with the window now.
|
|
6539 */
|
|
6540 if (echo_active)
|
|
6541 w->line_cache_last_updated = make_int (-1);
|
|
6542 }
|
|
6543
|
|
6544 /* #### This should be dependent on face changes and will need to be
|
|
6545 somewhere else once tty updates occur on a per-frame basis. */
|
|
6546 mark_face_cachels_as_clean (w);
|
|
6547
|
438
|
6548 /* The glyph cachels only get dirty if someone changed something.
|
|
6549 Since redisplay has now effectively ended we can reset the dirty
|
|
6550 flag since everything must be up-to-date. */
|
428
|
6551 if (glyphs_changed)
|
|
6552 mark_glyph_cachels_as_clean (w);
|
|
6553
|
|
6554 w->windows_changed = 0;
|
|
6555 }
|
|
6556
|
|
6557 /* Call buffer_reset_changes for all buffers present in any window
|
|
6558 currently visible in all frames on all devices. #### There has to
|
|
6559 be a better way to do this. */
|
|
6560
|
|
6561 static int
|
2286
|
6562 reset_buffer_changes_mapfun (struct window *w, void *UNUSED (closure))
|
428
|
6563 {
|
|
6564 buffer_reset_changes (XBUFFER (w->buffer));
|
|
6565 return 0;
|
|
6566 }
|
|
6567
|
|
6568 static void
|
|
6569 reset_buffer_changes (void)
|
|
6570 {
|
|
6571 Lisp_Object frmcons, devcons, concons;
|
|
6572
|
|
6573 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
6574 {
|
|
6575 struct frame *f = XFRAME (XCAR (frmcons));
|
|
6576
|
|
6577 if (FRAME_REPAINT_P (f))
|
|
6578 map_windows (f, reset_buffer_changes_mapfun, 0);
|
|
6579 }
|
|
6580 }
|
|
6581
|
|
6582 /* Ensure that all windows underneath the given window in the window
|
|
6583 hierarchy are correctly displayed. */
|
|
6584
|
|
6585 static void
|
|
6586 redisplay_windows (Lisp_Object window, int skip_selected)
|
|
6587 {
|
|
6588 for (; !NILP (window) ; window = XWINDOW (window)->next)
|
|
6589 {
|
|
6590 redisplay_window (window, skip_selected);
|
|
6591 }
|
|
6592 }
|
|
6593
|
1318
|
6594 /* Register an action to be called at the end of redisplay.
|
|
6595 in_display is 0 when this is called.
|
|
6596 This is used when it is discovered that an action needs to be taken,
|
|
6597 but it's during redisplay, so it's not safe. (Typically, it's an action
|
|
6598 that needs to enter redisplay, which can't happen reentrantly.)
|
|
6599
|
|
6600 NEVER signal an error in these functions.
|
|
6601 */
|
|
6602
|
|
6603 void
|
|
6604 register_post_redisplay_action (void (*fun) (Lisp_Object), Lisp_Object arg)
|
|
6605 {
|
|
6606 Vpost_redisplay_actions = nconc2 (Vpost_redisplay_actions,
|
|
6607 list1 (Fcons (make_opaque_ptr
|
|
6608 ((void *) fun), arg)));
|
|
6609 }
|
|
6610
|
1320
|
6611 static int running_post_redisplay_actions;
|
|
6612
|
1318
|
6613 static void
|
|
6614 run_post_redisplay_actions (void)
|
|
6615 {
|
1320
|
6616 int depth;
|
|
6617
|
|
6618 if (running_post_redisplay_actions)
|
|
6619 return;
|
|
6620
|
|
6621 depth = internal_bind_int (&running_post_redisplay_actions, 1);
|
|
6622 /* If the function pushes further actions, they will be tacked onto
|
|
6623 the end of the list, and we'll run them when we're done with the
|
|
6624 current ones. */
|
1318
|
6625 while (!NILP (Vpost_redisplay_actions))
|
|
6626 {
|
|
6627 Lisp_Object car = XCAR (Vpost_redisplay_actions);
|
|
6628 void (*fun) (Lisp_Object) =
|
|
6629 (void (*)(Lisp_Object)) get_opaque_ptr (XCAR (car));
|
|
6630 (*fun) (XCDR (car));
|
|
6631 free_opaque_ptr (XCAR (car));
|
|
6632 free_cons (car);
|
|
6633 Vpost_redisplay_actions = XCDR (Vpost_redisplay_actions);
|
|
6634 }
|
1320
|
6635 unbind_to (depth);
|
1318
|
6636 }
|
|
6637
|
|
6638 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS
|
|
6639
|
|
6640 static Lisp_Object
|
2286
|
6641 commit_ritual_suicide (Lisp_Object UNUSED (ceci_nest_pas_une_pipe))
|
1318
|
6642 {
|
|
6643 assert (!in_display);
|
|
6644 return Qnil;
|
|
6645 }
|
|
6646
|
|
6647 #endif
|
|
6648
|
|
6649 /* Within the guts of redisplay, we are defenseless and cannot allow any of
|
|
6650 the following to happen:
|
|
6651
|
|
6652 1) garbage collection
|
|
6653 2) QUIT
|
|
6654 3) any non-local exits
|
|
6655 4) frame size changes
|
|
6656 5) deletion of any buffers, windows, frames, etc.
|
|
6657 6) modification of buffer text
|
|
6658 7) reentrant entry of redisplay (see the stack trace above
|
|
6659 generate_displayable_area())
|
|
6660
|
|
6661 The general reason is that the redisplay code is written to assume that
|
|
6662 it is the only code running, and thus (a) cannot tolerate structures
|
|
6663 changed out from under it (hence 1, 4, 5, 6, 7) and (b) at various points
|
|
6664 within redisplay the redisplay structures may be in an inconsistent
|
|
6665 state and there are no unwind-protects to clean the structures up in
|
|
6666 case of non-local exit (hence 2, 3). Fixing redisplay to address these
|
|
6667 issues is hard and perhaps not worth it (and might slow things down a
|
|
6668 fair amount). We address 1, 4, 5 and 6 ourselves inside of
|
|
6669 enter_redisplay_critical_section() by simply inhibiting them, but we
|
|
6670 cannot handle 2 and 3, which must be handled at the actual point where
|
|
6671 they may occur (especially, internal_equal() or any place that may call
|
|
6672 Lisp), by wrapping the code in call_trapping_problems() or
|
|
6673 call_with_suspended_errors(). [[ NOTE: We could address QUIT by inhibiting
|
|
6674 it but this would be anti-social because it would prevent the user from
|
|
6675 interrupting any Lisp code called within the critical section. With the
|
|
6676 call_*() wrapping, C-g will interrupt the Lisp code and throw back to
|
|
6677 the innermost wrapping. ]] In fact we do turn off QUIT handling, since
|
|
6678 it's just too dangerous otherwise. See below.
|
|
6679
|
|
6680 Code calling enter_redisplay_critical_section() must check for reentrancy
|
|
6681 (#7) and take appropriate corrective action.
|
|
6682
|
|
6683 To help debug potential problems, we arrange (when
|
|
6684 ERROR_CHECK_TRAPPING_PROBLEMS is set) to crash automatically every time
|
|
6685 we execute QUIT or call Lisp code unless proper wrapping is in place, as
|
|
6686 well as further checks when we actually Fsignal(), Fthrow(),
|
|
6687 garbage_collect_1().
|
|
6688
|
|
6689 #### If a frame-size change does occur we should probably actually be
|
|
6690 preempting redisplay. */
|
|
6691
|
|
6692 /* Count of number of recursive times we call
|
|
6693 enter_redisplay_critical_section() or
|
|
6694 enter_redisplay_critical_section_maybe().
|
|
6695 enter_redisplay_critical_section() cannot occur reentrantly but we have
|
|
6696 to know in the *maybe() version whether to exit the section when we're
|
|
6697 done. */
|
|
6698 static int in_display_nesting;
|
|
6699
|
|
6700 static Lisp_Object
|
2286
|
6701 end_hold_frame_size_changes (Lisp_Object UNUSED (obj))
|
1318
|
6702 {
|
|
6703 if (!hold_frame_size_changes)
|
|
6704 {
|
|
6705 /* we used to have a function to do this for only one frame, and
|
|
6706 it was typical to call it at the end of a critical section
|
|
6707 (which occurs once per frame); but what then happens if multiple
|
|
6708 frames have frame changes held up?
|
|
6709
|
|
6710 This means we are O(N^2) over frames. I seriously doubt it matters.
|
|
6711 --ben */
|
|
6712 Lisp_Object frmcons, devcons, concons;
|
|
6713
|
|
6714 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
6715 {
|
|
6716 struct frame *f = XFRAME (XCAR (frmcons));
|
|
6717 if (f->size_change_pending)
|
|
6718 change_frame_size (f, f->new_height, f->new_width, 0);
|
|
6719 }
|
|
6720 }
|
|
6721 return Qnil;
|
|
6722 }
|
|
6723
|
|
6724 /* Call this to temporarily prevent frame-size changes from being processed.
|
|
6725 To undo, use unbind_to(), passing it the value returned by this function.
|
|
6726 */
|
|
6727
|
|
6728 int
|
|
6729 begin_hold_frame_size_changes (void)
|
|
6730 {
|
|
6731 int depth = specpdl_depth ();
|
|
6732 record_unwind_protect (end_hold_frame_size_changes, Qnil);
|
|
6733 internal_bind_int (&hold_frame_size_changes, 1 + hold_frame_size_changes);
|
|
6734 return depth;
|
|
6735 }
|
|
6736
|
|
6737 int
|
|
6738 enter_redisplay_critical_section (void)
|
|
6739 {
|
|
6740 int depth = specpdl_depth ();
|
|
6741
|
|
6742 /* Reentrant entry is deadly. The calling function must check for this. */
|
|
6743 assert (!in_display);
|
|
6744 begin_hold_frame_size_changes ();
|
|
6745 /* Make sure in_display gets reset, but don't set it yet so that
|
|
6746 commit_ritual_suicide() can be used. */
|
|
6747 internal_bind_int (&in_display, 0);
|
|
6748 internal_bind_int (&in_display_nesting, 1 + in_display_nesting);
|
|
6749 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS
|
|
6750 /* Force every call to QUIT to check for in_displayness. This will
|
|
6751 verify proper wrapping, as in the previous comment, aborting if not. */
|
|
6752 something_happened++;
|
|
6753 /* Verify that no nonlocal exits blow past us. */
|
|
6754 record_unwind_protect (commit_ritual_suicide, Qnil);
|
|
6755 #endif
|
|
6756 in_display++;
|
|
6757
|
|
6758 set_trapping_problems_flags (INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY);
|
|
6759 /* Even checking for QUIT can cause arbitrary Lisp code to be executed,
|
|
6760 e.g. through a menu handler. We really don't want that happening
|
|
6761 inside of redisplay. Code that we `eval' is at least written with the
|
|
6762 expectation that it's inside of redisplay, and shouldn't try anything
|
|
6763 weird; but that's not the case for menu code (e.g. custom loads huge
|
|
6764 amounts of LISP FILES from a menu handler! FMH!). Safest just to turn
|
|
6765 this off. We could turn it on using UNINHIBIT_QUIT or
|
|
6766 begin_do_check_for_quit() in certain places if we want, if we know
|
|
6767 it's not in an especially tricky place. */
|
|
6768 begin_dont_check_for_quit ();
|
|
6769 return depth;
|
|
6770 }
|
|
6771
|
|
6772 void
|
|
6773 exit_redisplay_critical_section (int depth)
|
|
6774 {
|
|
6775 in_display--;
|
|
6776 assert (!in_display);
|
|
6777 unbind_to (depth);
|
|
6778
|
|
6779 run_post_redisplay_actions ();
|
|
6780 }
|
|
6781
|
|
6782 /* Enter the redisplay critical section if we're not already in it. This
|
|
6783 is for code that needs frame changes held up and other protections from
|
|
6784 being inside, but doesn't modify the redisplay structures, and doesn't
|
|
6785 look at them in a way that they will be confused by inconsistencies. */
|
|
6786
|
|
6787 int
|
|
6788 enter_redisplay_critical_section_maybe (void)
|
|
6789 {
|
|
6790 if (!in_display)
|
|
6791 return enter_redisplay_critical_section ();
|
|
6792 else
|
|
6793 return internal_bind_int (&in_display_nesting, 1 + in_display_nesting);
|
|
6794 }
|
|
6795
|
|
6796 void
|
|
6797 exit_redisplay_critical_section_maybe (int depth)
|
|
6798 {
|
|
6799 if (in_display_nesting == 1)
|
|
6800 exit_redisplay_critical_section (depth);
|
|
6801 else
|
|
6802 unbind_to (depth);
|
|
6803 }
|
|
6804
|
1279
|
6805 /* Ensure that all windows on the given frame are correctly displayed.
|
|
6806 Return non-zero if pre-empted. */
|
428
|
6807
|
442
|
6808 int
|
428
|
6809 redisplay_frame (struct frame *f, int preemption_check)
|
|
6810 {
|
|
6811 struct device *d = XDEVICE (f->device);
|
853
|
6812 int depth;
|
428
|
6813
|
1279
|
6814 assert (f->init_finished);
|
|
6815
|
1318
|
6816 /* NOTE: Without sufficient checks for stream frames, we got weird
|
|
6817 crashes in pdump. These came and went very easily -- adding the
|
|
6818 critical-section code for redisplay was enough to trigger them.
|
|
6819 Perhaps I should have debugged them but there didn't seem to be any
|
|
6820 point. --ben */
|
1279
|
6821 if (FRAME_STREAM_P (f)) /* nothing to do */
|
|
6822 return 0;
|
|
6823
|
1318
|
6824 /* Reentrancy into redisplay can be deadly. See stack trace above
|
|
6825 generate_displayable_area(). */
|
|
6826 if (in_display)
|
|
6827 return 1;
|
|
6828
|
545
|
6829 if (preemption_check
|
|
6830 && !DEVICE_IMPL_FLAG (d, XDEVIMPF_DONT_PREEMPT_REDISPLAY))
|
428
|
6831 {
|
|
6832 /* The preemption check itself takes a lot of time,
|
|
6833 so normally don't do it here. We do it if called
|
|
6834 from Lisp, though (`redisplay-frame'). */
|
|
6835 int preempted;
|
|
6836
|
|
6837 REDISPLAY_PREEMPTION_CHECK;
|
|
6838 if (preempted)
|
|
6839 return 1;
|
|
6840 }
|
|
6841
|
442
|
6842 if (!internal_equal (f->old_buffer_alist, f->buffer_alist, 0))
|
|
6843 {
|
|
6844 Lisp_Object frame;
|
|
6845
|
|
6846 f->old_buffer_alist = Freplace_list (f->old_buffer_alist,
|
|
6847 f->buffer_alist);
|
793
|
6848 frame = wrap_frame (f);
|
442
|
6849 va_run_hook_with_args (Qbuffer_list_changed_hook, 1, frame);
|
|
6850 }
|
|
6851
|
428
|
6852 /* Before we put a hold on frame size changes, attempt to process
|
|
6853 any which are already pending. */
|
|
6854 if (f->size_change_pending)
|
|
6855 change_frame_size (f, f->new_height, f->new_width, 0);
|
|
6856
|
|
6857 /* If frame size might need to be changed, due to changed size
|
|
6858 of toolbars, scrollbars etc, change it now */
|
|
6859 if (f->size_slipped)
|
|
6860 {
|
|
6861 adjust_frame_size (f);
|
|
6862 assert (!f->size_slipped);
|
|
6863 }
|
|
6864
|
1318
|
6865 /* The menubar, toolbar, and icon updates should be done before
|
853
|
6866 enter_redisplay_critical_section is called and we are officially
|
3025
|
6867 `in_display'. They is because they tend to eval Lisp code, which
|
1318
|
6868 needs to be carefully wrapped within the critical section (and hence
|
|
6869 is difficult to debug). */
|
428
|
6870
|
|
6871 #ifdef HAVE_MENUBARS
|
|
6872 /* Update the menubar. It is done first since it could change
|
|
6873 the menubar's visibility. This way we avoid having flashing
|
|
6874 caused by an Expose event generated by the visibility change
|
|
6875 being handled. */
|
|
6876 update_frame_menubars (f);
|
|
6877 #endif /* HAVE_MENUBARS */
|
|
6878 #ifdef HAVE_TOOLBARS
|
905
|
6879 /* Update the toolbars geometry. We don't update the toolbars
|
|
6880 themselves at this point since the space they are trying to
|
|
6881 occupy may currently by occupied by gutter elements. Instead we
|
|
6882 update the geometry, then update the gutter geometry, then update
|
|
6883 the gutters - which will cause mapped windows to be repositioned
|
|
6884 - and finally update the toolbars. */
|
|
6885 update_frame_toolbars_geometry (f);
|
428
|
6886 #endif /* HAVE_TOOLBARS */
|
442
|
6887 /* Gutter update proper has to be done inside display when no frame
|
|
6888 size changes can occur, thus we separately update the gutter
|
|
6889 geometry here if it needs it. */
|
|
6890 update_frame_gutter_geometry (f);
|
428
|
6891
|
|
6892 /* If we clear the frame we have to force its contents to be redrawn. */
|
|
6893 if (f->clear)
|
|
6894 f->frame_changed = 1;
|
|
6895
|
442
|
6896 /* Invalidate the subwindow caches. We use subwindows_changed here
|
|
6897 to cause subwindows to get instantiated. This is because
|
428
|
6898 subwindows_state_changed is less strict - dealing with things
|
|
6899 like the clicked state of button. We have to do this before
|
|
6900 redisplaying the gutters as subwindows get unmapped in the
|
|
6901 process.*/
|
442
|
6902 if (f->frame_changed)
|
|
6903 reset_frame_subwindow_instance_cache (f);
|
|
6904
|
|
6905 if (f->frame_changed || f->subwindows_changed)
|
|
6906 {
|
428
|
6907 /* we have to do this so the gutter gets regenerated. */
|
|
6908 reset_gutter_display_lines (f);
|
|
6909 }
|
|
6910
|
853
|
6911 depth = enter_redisplay_critical_section ();
|
428
|
6912
|
|
6913 /* ----------------- BEGIN CRITICAL REDISPLAY SECTION ---------------- */
|
1318
|
6914
|
|
6915 /* See comments in enter_redisplay_critical_section() */
|
428
|
6916
|
442
|
6917 MAYBE_DEVMETH (d, frame_output_begin, (f));
|
|
6918
|
|
6919 /* We can now update the gutters, safe in the knowledge that our
|
|
6920 efforts won't get undone. */
|
|
6921
|
|
6922 /* This can call lisp, but redisplay is protected by binding
|
|
6923 inhibit_quit. More importantly the code involving display lines
|
|
6924 *assumes* that GC will not happen and so does not GCPRO
|
|
6925 anything. Since we use this code the whole time with the gutters
|
1318
|
6926 we cannot allow GC to happen when manipulating the gutters.
|
|
6927
|
|
6928 This must be inside of the critical section for various reasons.
|
|
6929 For example, it messes with display structures, which be left in
|
|
6930 an inconsistent state. */
|
442
|
6931 update_frame_gutters (f);
|
|
6932
|
428
|
6933 /* Erase the frame before outputting its contents. */
|
|
6934 if (f->clear)
|
|
6935 {
|
442
|
6936 MAYBE_DEVMETH (d, clear_frame, (f));
|
428
|
6937 }
|
|
6938
|
|
6939 /* Do the selected window first. */
|
|
6940 redisplay_window (FRAME_SELECTED_WINDOW (f), 0);
|
|
6941
|
|
6942 /* Then do the rest. */
|
|
6943 redisplay_windows (f->root_window, 1);
|
|
6944
|
442
|
6945 MAYBE_DEVMETH (d, frame_output_end, (f));
|
428
|
6946
|
|
6947 update_frame_title (f);
|
|
6948
|
905
|
6949 #ifdef HAVE_TOOLBARS
|
|
6950 /* Finally update the toolbars. It seems its possible to get in a
|
|
6951 cycle between updating the gutter and the toolbars. Basically we
|
|
6952 want to end up with both being up-to-date and this doesn't seem
|
|
6953 possible in a single pass. */
|
|
6954 update_frame_toolbars (f);
|
|
6955 #endif /* HAVE_TOOLBARS */
|
|
6956
|
428
|
6957 CLASS_RESET_CHANGED_FLAGS (f);
|
|
6958 f->window_face_cache_reset = 0;
|
|
6959 f->echo_area_garbaged = 0;
|
|
6960 f->clear = 0;
|
|
6961
|
|
6962 if (!f->size_change_pending)
|
|
6963 f->size_changed = 0;
|
|
6964
|
|
6965 /* ----------------- END CRITICAL REDISPLAY SECTION ---------------- */
|
|
6966
|
853
|
6967 /* Allow frame size changes to occur again. */
|
|
6968 exit_redisplay_critical_section (depth);
|
428
|
6969
|
|
6970 return 0;
|
|
6971 }
|
|
6972
|
440
|
6973 /* Ensure that all frames on the given device are correctly displayed.
|
|
6974 If AUTOMATIC is non-zero, and the device implementation indicates
|
|
6975 no automatic redisplay, as printers do, then the device is not
|
|
6976 redisplayed. AUTOMATIC is set to zero when called from lisp
|
|
6977 functions (redraw-device) and (redisplay-device), and to non-zero
|
|
6978 when called from "lazy" redisplay();
|
|
6979 */
|
428
|
6980
|
|
6981 static int
|
440
|
6982 redisplay_device (struct device *d, int automatic)
|
428
|
6983 {
|
|
6984 Lisp_Object frame, frmcons;
|
|
6985 int size_change_failed = 0;
|
|
6986 struct frame *f;
|
|
6987
|
545
|
6988 if (automatic && DEVICE_IMPL_FLAG (d, XDEVIMPF_NO_AUTO_REDISPLAY))
|
440
|
6989 return 0;
|
|
6990
|
428
|
6991 if (DEVICE_STREAM_P (d)) /* nothing to do */
|
|
6992 return 0;
|
|
6993
|
|
6994 /* It is possible that redisplay has been called before the
|
545
|
6995 device is fully initialized, or that the console implementation
|
|
6996 allows frameless devices. If so then continue with the next
|
|
6997 device. */
|
428
|
6998 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
6999 return 0;
|
|
7000
|
545
|
7001 if (!DEVICE_IMPL_FLAG (d, XDEVIMPF_DONT_PREEMPT_REDISPLAY))
|
|
7002 {
|
|
7003 int preempted;
|
|
7004 REDISPLAY_PREEMPTION_CHECK;
|
|
7005 if (preempted)
|
|
7006 return 1;
|
|
7007 }
|
428
|
7008
|
|
7009 /* Always do the selected frame first. */
|
|
7010 frame = DEVICE_SELECTED_FRAME (d);
|
|
7011
|
|
7012 f = XFRAME (frame);
|
|
7013
|
|
7014 if (f->icon_changed || f->windows_changed)
|
|
7015 update_frame_icon (f);
|
|
7016
|
|
7017 if (FRAME_REPAINT_P (f))
|
|
7018 {
|
|
7019 if (CLASS_REDISPLAY_FLAGS_CHANGEDP(f))
|
|
7020 {
|
588
|
7021 int preempted = redisplay_frame (f, 1);
|
545
|
7022 if (preempted)
|
|
7023 return 1;
|
|
7024 }
|
428
|
7025
|
|
7026 /* If the frame redisplay did not get preempted, then this flag
|
|
7027 should have gotten set to 0. It might be possible for that
|
|
7028 not to happen if a size change event were to occur at an odd
|
|
7029 time. To make sure we don't miss anything we simply don't
|
|
7030 reset the top level flags until the condition ends up being
|
|
7031 in the right state. */
|
|
7032 if (f->size_changed)
|
|
7033 size_change_failed = 1;
|
|
7034 }
|
|
7035
|
|
7036 DEVICE_FRAME_LOOP (frmcons, d)
|
|
7037 {
|
|
7038 f = XFRAME (XCAR (frmcons));
|
|
7039
|
|
7040 if (f == XFRAME (DEVICE_SELECTED_FRAME (d)))
|
|
7041 continue;
|
|
7042
|
|
7043 if (f->icon_changed || f->windows_changed)
|
|
7044 update_frame_icon (f);
|
|
7045
|
|
7046 if (FRAME_REPAINT_P (f))
|
|
7047 {
|
430
|
7048 if (CLASS_REDISPLAY_FLAGS_CHANGEDP (f))
|
428
|
7049 {
|
588
|
7050 int preempted = redisplay_frame (f, 1);
|
545
|
7051 if (preempted)
|
|
7052 return 1;
|
428
|
7053 }
|
|
7054
|
|
7055 if (f->size_change_pending)
|
|
7056 size_change_failed = 1;
|
|
7057 }
|
|
7058 }
|
|
7059
|
|
7060 /* If we get here then we redisplayed all of our frames without
|
|
7061 getting preempted so mark ourselves as clean. */
|
|
7062 CLASS_RESET_CHANGED_FLAGS (d);
|
|
7063
|
|
7064 if (!size_change_failed)
|
|
7065 d->size_changed = 0;
|
|
7066
|
|
7067 return 0;
|
|
7068 }
|
|
7069
|
|
7070 /* Ensure that all windows on all frames on all devices are displaying
|
|
7071 the current contents of their respective buffers. */
|
|
7072
|
|
7073 static void
|
|
7074 redisplay_without_hooks (void)
|
|
7075 {
|
|
7076 Lisp_Object devcons, concons;
|
|
7077 int size_change_failed = 0;
|
1292
|
7078 PROFILE_DECLARE ();
|
|
7079
|
|
7080 PROFILE_RECORD_ENTERING_SECTION (QSin_redisplay);
|
428
|
7081
|
|
7082 if (asynch_device_change_pending)
|
|
7083 handle_asynch_device_change ();
|
|
7084
|
|
7085 if (!GLOBAL_REDISPLAY_FLAGS_CHANGEDP &&
|
430
|
7086 !disable_preemption && preemption_count < max_preempts)
|
428
|
7087 goto done;
|
|
7088
|
|
7089 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
7090 {
|
|
7091 struct device *d = XDEVICE (XCAR (devcons));
|
|
7092 int preempted;
|
|
7093
|
430
|
7094 if (CLASS_REDISPLAY_FLAGS_CHANGEDP (d))
|
428
|
7095 {
|
440
|
7096 preempted = redisplay_device (d, 1);
|
428
|
7097
|
|
7098 if (preempted)
|
|
7099 {
|
|
7100 preemption_count++;
|
|
7101 RESET_CHANGED_SET_FLAGS;
|
|
7102 goto done;
|
|
7103 }
|
|
7104
|
|
7105 /* See comment in redisplay_device. */
|
|
7106 if (d->size_changed)
|
|
7107 size_change_failed = 1;
|
|
7108 }
|
|
7109 }
|
|
7110 preemption_count = 0;
|
|
7111
|
|
7112 /* Mark redisplay as accurate */
|
|
7113 GLOBAL_RESET_CHANGED_FLAGS;
|
|
7114 RESET_CHANGED_SET_FLAGS;
|
|
7115
|
|
7116 if (faces_changed)
|
|
7117 {
|
|
7118 mark_all_faces_as_clean ();
|
|
7119 faces_changed = 0;
|
|
7120 }
|
|
7121
|
|
7122 if (!size_change_failed)
|
|
7123 size_changed = 0;
|
|
7124
|
|
7125 reset_buffer_changes ();
|
|
7126
|
|
7127 done:
|
800
|
7128 #ifdef ERROR_CHECK_DISPLAY
|
|
7129 sledgehammer_check_redisplay_structs ();
|
|
7130 #endif /* ERROR_CHECK_DISPLAY */
|
1292
|
7131
|
|
7132 PROFILE_RECORD_EXITING_SECTION (QSin_redisplay);
|
428
|
7133 }
|
|
7134
|
1318
|
7135 /* Note: All places in the C code that call redisplay() are prepared to
|
|
7136 handle GCing, which can happen from run_pre_idle_hook(). However, we
|
|
7137 can't currently handle GC inside the guts of redisplay; see
|
|
7138 enter_redisplay_critical_section().
|
853
|
7139
|
|
7140 (#### What about other external entry points to the redisplay code?
|
|
7141 Someone should go through and make sure that all callers can handle
|
|
7142 GC there, too.)
|
|
7143 */
|
|
7144
|
428
|
7145 void
|
|
7146 redisplay (void)
|
|
7147 {
|
853
|
7148 run_pre_idle_hook ();
|
|
7149 redisplay_no_pre_idle_hook ();
|
|
7150 }
|
|
7151
|
|
7152 void
|
|
7153 redisplay_no_pre_idle_hook (void)
|
|
7154 {
|
428
|
7155 if (last_display_warning_tick != display_warning_tick &&
|
|
7156 !inhibit_warning_display)
|
|
7157 {
|
|
7158 /* If an error occurs during this function, oh well.
|
|
7159 If we report another warning, we could get stuck in an
|
|
7160 infinite loop reporting warnings. */
|
853
|
7161 call0_trapping_problems
|
|
7162 (0, Qdisplay_warning_buffer,
|
|
7163 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION);
|
428
|
7164 last_display_warning_tick = display_warning_tick;
|
|
7165 }
|
|
7166
|
|
7167 redisplay_without_hooks ();
|
|
7168 }
|
|
7169
|
853
|
7170 Lisp_Object
|
|
7171 eval_within_redisplay (Lisp_Object dont_trust_this_damn_sucker)
|
|
7172 {
|
|
7173 return
|
|
7174 eval_in_buffer_trapping_problems
|
|
7175 ("Error calling function within redisplay", current_buffer,
|
1318
|
7176 dont_trust_this_damn_sucker, 0);
|
853
|
7177 }
|
428
|
7178
|
|
7179 /* Efficiently determine the window line number, and return a pointer
|
|
7180 to its printed representation. Do this regardless of whether
|
|
7181 line-number-mode is on. The first line in the buffer is counted as
|
|
7182 1. If narrowing is in effect, the lines are counted from the
|
|
7183 beginning of the visible portion of the buffer. */
|
|
7184 static char *
|
|
7185 window_line_number (struct window *w, int type)
|
|
7186 {
|
|
7187 struct device *d = XDEVICE (XFRAME (w->frame)->device);
|
|
7188 struct buffer *b = XBUFFER (w->buffer);
|
|
7189 /* Be careful in the order of these tests. The first clause will
|
|
7190 fail if DEVICE_SELECTED_FRAME == Qnil (since w->frame cannot be).
|
|
7191 This can occur when the frame title is computed really early */
|
665
|
7192 Charbpos pos =
|
428
|
7193 ((EQ(DEVICE_SELECTED_FRAME(d), w->frame) &&
|
|
7194 (w == XWINDOW (FRAME_SELECTED_WINDOW (device_selected_frame(d)))) &&
|
|
7195 EQ(DEVICE_CONSOLE(d), Vselected_console) &&
|
|
7196 XDEVICE(CONSOLE_SELECTED_DEVICE(XCONSOLE(DEVICE_CONSOLE(d)))) == d )
|
|
7197 ? BUF_PT (b)
|
|
7198 : marker_position (w->pointm[type]));
|
|
7199 EMACS_INT line;
|
|
7200
|
|
7201 line = buffer_line_number (b, pos, 1);
|
|
7202
|
603
|
7203 {
|
|
7204 static char window_line_number_buf[DECIMAL_PRINT_SIZE (long)];
|
|
7205
|
|
7206 long_to_string (window_line_number_buf, line + 1);
|
|
7207
|
|
7208 return window_line_number_buf;
|
|
7209 }
|
428
|
7210 }
|
|
7211
|
|
7212
|
|
7213 /* Given a character representing an object in a modeline
|
|
7214 specification, return a string (stored into the global array
|
867
|
7215 `mode_spec_ibyte_string') with the information that object
|
428
|
7216 represents.
|
|
7217
|
|
7218 This function is largely unchanged from previous versions of the
|
|
7219 redisplay engine.
|
|
7220
|
|
7221 Warning! This code is also used for frame titles and can be called
|
|
7222 very early in the device/frame update process! JV
|
|
7223 */
|
|
7224
|
|
7225 static void
|
867
|
7226 decode_mode_spec (struct window *w, Ichar spec, int type)
|
428
|
7227 {
|
|
7228 Lisp_Object obj = Qnil;
|
442
|
7229 const char *str = NULL;
|
428
|
7230 struct buffer *b = XBUFFER (w->buffer);
|
|
7231
|
867
|
7232 Dynarr_reset (mode_spec_ibyte_string);
|
428
|
7233
|
|
7234 switch (spec)
|
|
7235 {
|
|
7236 /* print buffer name */
|
|
7237 case 'b':
|
|
7238 obj = b->name;
|
|
7239 break;
|
|
7240
|
|
7241 /* print visited file name */
|
|
7242 case 'f':
|
|
7243 obj = b->filename;
|
|
7244 break;
|
|
7245
|
|
7246 /* print the current column */
|
|
7247 case 'c':
|
|
7248 {
|
665
|
7249 Charbpos pt = (w == XWINDOW (Fselected_window (Qnil)))
|
428
|
7250 ? BUF_PT (b)
|
|
7251 : marker_position (w->pointm[type]);
|
|
7252 int col = column_at_point (b, pt, 1) + !!column_number_start_at_one;
|
603
|
7253 char buf[DECIMAL_PRINT_SIZE (long)];
|
428
|
7254
|
|
7255 long_to_string (buf, col);
|
|
7256
|
867
|
7257 Dynarr_add_many (mode_spec_ibyte_string,
|
|
7258 (const Ibyte *) buf, strlen (buf));
|
428
|
7259
|
|
7260 goto decode_mode_spec_done;
|
|
7261 }
|
|
7262 /* print the file coding system */
|
|
7263 case 'C':
|
|
7264 {
|
|
7265 Lisp_Object codesys = b->buffer_file_coding_system;
|
|
7266 /* Be very careful here not to get an error. */
|
|
7267 if (NILP (codesys) || SYMBOLP (codesys) || CODING_SYSTEMP (codesys))
|
|
7268 {
|
771
|
7269 codesys = find_coding_system_for_text_file (codesys, 0);
|
428
|
7270 if (CODING_SYSTEMP (codesys))
|
|
7271 obj = XCODING_SYSTEM_MNEMONIC (codesys);
|
|
7272 }
|
|
7273 }
|
|
7274 break;
|
|
7275
|
|
7276 /* print the current line number */
|
|
7277 case 'l':
|
|
7278 str = window_line_number (w, type);
|
|
7279 break;
|
|
7280
|
|
7281 /* print value of mode-name (obsolete) */
|
|
7282 case 'm':
|
|
7283 obj = b->mode_name;
|
|
7284 break;
|
|
7285
|
|
7286 /* print hyphen and frame number, if != 1 */
|
|
7287 case 'N':
|
|
7288 #ifdef HAVE_TTY
|
|
7289 {
|
|
7290 struct frame *f = XFRAME (w->frame);
|
|
7291 if (FRAME_TTY_P (f) && f->order_count > 1 && f->order_count <= 99999999)
|
|
7292 {
|
|
7293 /* Naughty, naughty */
|
|
7294 char * writable_str = alloca_array (char, 10);
|
|
7295 sprintf (writable_str, "-%d", f->order_count);
|
|
7296 str = writable_str;
|
|
7297 }
|
|
7298 }
|
|
7299 #endif /* HAVE_TTY */
|
|
7300 break;
|
|
7301
|
|
7302 /* print Narrow if appropriate */
|
|
7303 case 'n':
|
|
7304 if (BUF_BEGV (b) > BUF_BEG (b)
|
|
7305 || BUF_ZV (b) < BUF_Z (b))
|
|
7306 str = " Narrow";
|
|
7307 break;
|
|
7308
|
|
7309 /* print %, * or hyphen, if buffer is read-only, modified or neither */
|
|
7310 case '*':
|
|
7311 str = (!NILP (b->read_only)
|
|
7312 ? "%"
|
|
7313 : ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
|
|
7314 ? "*"
|
|
7315 : "-"));
|
|
7316 break;
|
|
7317
|
|
7318 /* print * or hyphen -- XEmacs change to allow a buffer to be
|
|
7319 read-only but still indicate whether it is modified. */
|
|
7320 case '+':
|
|
7321 str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
|
|
7322 ? "*"
|
|
7323 : (!NILP (b->read_only)
|
|
7324 ? "%"
|
|
7325 : "-"));
|
|
7326 break;
|
|
7327
|
|
7328 /* #### defined in 19.29 decode_mode_spec, but not in
|
|
7329 modeline-format doc string. */
|
|
7330 /* This differs from %* in that it ignores read-only-ness. */
|
|
7331 case '&':
|
|
7332 str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
|
|
7333 ? "*"
|
|
7334 : "-");
|
|
7335 break;
|
|
7336
|
|
7337 /* print process status */
|
|
7338 case 's':
|
|
7339 obj = Fget_buffer_process (w->buffer);
|
|
7340 if (NILP (obj))
|
|
7341 str = GETTEXT ("no process");
|
|
7342 else
|
|
7343 obj = Fsymbol_name (Fprocess_status (obj));
|
|
7344 break;
|
|
7345
|
|
7346 /* Print name of selected frame. */
|
|
7347 case 'S':
|
|
7348 obj = XFRAME (w->frame)->name;
|
|
7349 break;
|
|
7350
|
|
7351 /* indicate TEXT or BINARY */
|
|
7352 case 't':
|
|
7353 /* #### NT does not use this any more. Now what? */
|
|
7354 str = "T";
|
|
7355 break;
|
|
7356
|
|
7357 /* print percent of buffer above top of window, or Top, Bot or All */
|
|
7358 case 'p':
|
|
7359 {
|
665
|
7360 Charbpos pos = marker_position (w->start[type]);
|
428
|
7361
|
|
7362 /* This had better be while the desired lines are being done. */
|
|
7363 if (w->window_end_pos[type] <= BUF_Z (b) - BUF_ZV (b))
|
|
7364 {
|
|
7365 if (pos <= BUF_BEGV (b))
|
|
7366 str = "All";
|
|
7367 else
|
|
7368 str = "Bottom";
|
|
7369 }
|
|
7370 else if (pos <= BUF_BEGV (b))
|
|
7371 str = "Top";
|
|
7372 else
|
|
7373 {
|
|
7374 /* This hard limit is ok since the string it will hold has a
|
|
7375 fixed maximum length of 3. But just to be safe... */
|
|
7376 char buf[10];
|
|
7377 Charcount chars = pos - BUF_BEGV (b);
|
|
7378 Charcount total = BUF_ZV (b) - BUF_BEGV (b);
|
|
7379
|
|
7380 /* Avoid overflow on big buffers */
|
|
7381 int percent = total > LONG_MAX/200 ?
|
|
7382 (chars + total/200) / (total / 100) :
|
|
7383 (chars * 100 + total/2) / total;
|
|
7384
|
|
7385 /* We can't normally display a 3-digit number, so get us a
|
|
7386 2-digit number that is close. */
|
|
7387 if (percent == 100)
|
|
7388 percent = 99;
|
|
7389
|
|
7390 sprintf (buf, "%d%%", percent);
|
867
|
7391 Dynarr_add_many (mode_spec_ibyte_string, (Ibyte *) buf,
|
428
|
7392 strlen (buf));
|
|
7393
|
|
7394 goto decode_mode_spec_done;
|
|
7395 }
|
|
7396 break;
|
|
7397 }
|
|
7398
|
|
7399 /* print percent of buffer above bottom of window, perhaps plus
|
|
7400 Top, or print Bottom or All */
|
|
7401 case 'P':
|
|
7402 {
|
665
|
7403 Charbpos toppos = marker_position (w->start[type]);
|
|
7404 Charbpos botpos = BUF_Z (b) - w->window_end_pos[type];
|
428
|
7405
|
|
7406 /* botpos is only accurate as of the last redisplay, so we can
|
|
7407 only treat it as a hint. In particular, after erase-buffer,
|
|
7408 botpos may be negative. */
|
|
7409 if (botpos < toppos)
|
|
7410 botpos = toppos;
|
|
7411
|
|
7412 if (botpos >= BUF_ZV (b))
|
|
7413 {
|
|
7414 if (toppos <= BUF_BEGV (b))
|
|
7415 str = "All";
|
|
7416 else
|
|
7417 str = "Bottom";
|
|
7418 }
|
|
7419 else
|
|
7420 {
|
|
7421 /* This hard limit is ok since the string it will hold has a
|
|
7422 fixed maximum length of around 6. But just to be safe... */
|
|
7423 char buf[10];
|
|
7424 Charcount chars = botpos - BUF_BEGV (b);
|
|
7425 Charcount total = BUF_ZV (b) - BUF_BEGV (b);
|
|
7426
|
|
7427 /* Avoid overflow on big buffers */
|
|
7428 int percent = total > LONG_MAX/200 ?
|
|
7429 (chars + total/200) / (total / 100) :
|
|
7430 (chars * 100 + total/2) / max (total, 1);
|
|
7431
|
|
7432 /* We can't normally display a 3-digit number, so get us a
|
|
7433 2-digit number that is close. */
|
|
7434 if (percent == 100)
|
|
7435 percent = 99;
|
|
7436
|
|
7437 if (toppos <= BUF_BEGV (b))
|
|
7438 sprintf (buf, "Top%d%%", percent);
|
|
7439 else
|
|
7440 sprintf (buf, "%d%%", percent);
|
|
7441
|
867
|
7442 Dynarr_add_many (mode_spec_ibyte_string, (Ibyte *) buf,
|
428
|
7443 strlen (buf));
|
|
7444
|
|
7445 goto decode_mode_spec_done;
|
|
7446 }
|
|
7447 break;
|
|
7448 }
|
|
7449
|
|
7450 /* print % */
|
|
7451 case '%':
|
|
7452 str = "%";
|
|
7453 break;
|
|
7454
|
|
7455 /* print one [ for each recursive editing level. */
|
|
7456 case '[':
|
|
7457 {
|
|
7458 int i;
|
|
7459
|
|
7460 if (command_loop_level > 5)
|
|
7461 {
|
|
7462 str = "[[[... ";
|
|
7463 break;
|
|
7464 }
|
|
7465
|
|
7466 for (i = 0; i < command_loop_level; i++)
|
867
|
7467 Dynarr_add (mode_spec_ibyte_string, '[');
|
428
|
7468
|
|
7469 goto decode_mode_spec_done;
|
|
7470 }
|
|
7471
|
|
7472 /* print one ] for each recursive editing level. */
|
|
7473 case ']':
|
|
7474 {
|
|
7475 int i;
|
|
7476
|
|
7477 if (command_loop_level > 5)
|
|
7478 {
|
|
7479 str = "...]]]";
|
|
7480 break;
|
|
7481 }
|
|
7482
|
|
7483 for (i = 0; i < command_loop_level; i++)
|
867
|
7484 Dynarr_add (mode_spec_ibyte_string, ']');
|
428
|
7485
|
|
7486 goto decode_mode_spec_done;
|
|
7487 }
|
|
7488
|
|
7489 /* print infinitely many dashes -- handle at top level now */
|
|
7490 case '-':
|
|
7491 break;
|
|
7492
|
|
7493 }
|
|
7494
|
|
7495 if (STRINGP (obj))
|
867
|
7496 Dynarr_add_many (mode_spec_ibyte_string,
|
428
|
7497 XSTRING_DATA (obj),
|
|
7498 XSTRING_LENGTH (obj));
|
|
7499 else if (str)
|
867
|
7500 Dynarr_add_many (mode_spec_ibyte_string, (Ibyte *) str, strlen (str));
|
428
|
7501
|
|
7502 decode_mode_spec_done:
|
867
|
7503 Dynarr_add (mode_spec_ibyte_string, '\0');
|
428
|
7504 }
|
|
7505
|
|
7506 /* Given a display line, free all of its data structures. */
|
|
7507
|
|
7508 static void
|
|
7509 free_display_line (struct display_line *dl)
|
|
7510 {
|
|
7511 int block;
|
|
7512
|
|
7513 if (dl->display_blocks)
|
|
7514 {
|
|
7515 for (block = 0; block < Dynarr_largest (dl->display_blocks); block++)
|
1318
|
7516 {
|
428
|
7517 struct display_block *db = Dynarr_atp (dl->display_blocks, block);
|
|
7518
|
|
7519 Dynarr_free (db->runes);
|
|
7520 }
|
|
7521
|
|
7522 Dynarr_free (dl->display_blocks);
|
|
7523 dl->display_blocks = NULL;
|
|
7524 }
|
|
7525
|
|
7526 if (dl->left_glyphs)
|
|
7527 {
|
|
7528 Dynarr_free (dl->left_glyphs);
|
|
7529 dl->left_glyphs = NULL;
|
|
7530 }
|
|
7531
|
|
7532 if (dl->right_glyphs)
|
|
7533 {
|
|
7534 Dynarr_free (dl->right_glyphs);
|
|
7535 dl->right_glyphs = NULL;
|
|
7536 }
|
|
7537 }
|
|
7538
|
|
7539
|
|
7540 /* Given an array of display lines, free them and all data structures
|
|
7541 contained within them. */
|
|
7542
|
|
7543 void
|
|
7544 free_display_lines (display_line_dynarr *dla)
|
|
7545 {
|
|
7546 int line;
|
|
7547
|
|
7548 for (line = 0; line < Dynarr_largest (dla); line++)
|
|
7549 {
|
|
7550 free_display_line (Dynarr_atp (dla, line));
|
|
7551 }
|
|
7552
|
|
7553 Dynarr_free (dla);
|
|
7554 }
|
|
7555
|
|
7556 /* Call internal free routine for each set of display lines. */
|
|
7557
|
|
7558 void
|
|
7559 free_display_structs (struct window_mirror *mir)
|
|
7560 {
|
|
7561 if (mir->current_display_lines)
|
|
7562 {
|
|
7563 free_display_lines (mir->current_display_lines);
|
|
7564 mir->current_display_lines = 0;
|
|
7565 }
|
|
7566
|
|
7567 if (mir->desired_display_lines)
|
|
7568 {
|
|
7569 free_display_lines (mir->desired_display_lines);
|
|
7570 mir->desired_display_lines = 0;
|
|
7571 }
|
|
7572 }
|
|
7573
|
|
7574
|
|
7575 static void
|
|
7576 mark_glyph_block_dynarr (glyph_block_dynarr *gba)
|
|
7577 {
|
|
7578 if (gba)
|
|
7579 {
|
|
7580 glyph_block *gb = Dynarr_atp (gba, 0);
|
|
7581 glyph_block *gb_last = Dynarr_atp (gba, Dynarr_length (gba));
|
|
7582
|
|
7583 for (; gb < gb_last; gb++)
|
|
7584 {
|
|
7585 if (!NILP (gb->glyph))
|
|
7586 mark_object (gb->glyph);
|
|
7587 if (!NILP (gb->extent))
|
|
7588 mark_object (gb->extent);
|
|
7589 }
|
|
7590 }
|
|
7591 }
|
|
7592
|
442
|
7593 /* See the comment in image_instantiate_cache_result as to why marking
|
|
7594 the glyph will also mark the image_instance. */
|
|
7595 void
|
428
|
7596 mark_redisplay_structs (display_line_dynarr *dla)
|
|
7597 {
|
|
7598 display_line *dl = Dynarr_atp (dla, 0);
|
|
7599 display_line *dl_last = Dynarr_atp (dla, Dynarr_length (dla));
|
|
7600
|
|
7601 for (; dl < dl_last; dl++)
|
|
7602 {
|
|
7603 display_block_dynarr *dba = dl->display_blocks;
|
|
7604 display_block *db = Dynarr_atp (dba, 0);
|
|
7605 display_block *db_last = Dynarr_atp (dba, Dynarr_length (dba));
|
|
7606
|
|
7607 for (; db < db_last; db++)
|
|
7608 {
|
|
7609 rune_dynarr *ra = db->runes;
|
|
7610 rune *r = Dynarr_atp (ra, 0);
|
|
7611 rune *r_last = Dynarr_atp (ra, Dynarr_length (ra));
|
|
7612
|
|
7613 for (; r < r_last; r++)
|
|
7614 {
|
|
7615 if (r->type == RUNE_DGLYPH)
|
|
7616 {
|
|
7617 if (!NILP (r->object.dglyph.glyph))
|
|
7618 mark_object (r->object.dglyph.glyph);
|
|
7619 if (!NILP (r->object.dglyph.extent))
|
|
7620 mark_object (r->object.dglyph.extent);
|
|
7621 }
|
|
7622 }
|
|
7623 }
|
|
7624
|
|
7625 mark_glyph_block_dynarr (dl->left_glyphs);
|
|
7626 mark_glyph_block_dynarr (dl->right_glyphs);
|
|
7627 }
|
|
7628 }
|
|
7629
|
|
7630
|
2367
|
7631
|
|
7632 /*
|
|
7633
|
|
7634 Info on line-start cache:
|
|
7635
|
|
7636 (Info-goto-node "(internals)Line Start Cache")
|
|
7637 */
|
428
|
7638
|
|
7639 /* This will get used quite a bit so we don't want to be constantly
|
|
7640 allocating and freeing it. */
|
|
7641 static line_start_cache_dynarr *internal_cache;
|
|
7642
|
|
7643 /* Makes internal_cache represent the TYPE display structs and only
|
|
7644 the TYPE display structs. */
|
|
7645
|
|
7646 static void
|
|
7647 update_internal_cache_list (struct window *w, int type)
|
|
7648 {
|
|
7649 int line;
|
|
7650 display_line_dynarr *dla = window_display_lines (w, type);
|
|
7651
|
|
7652 Dynarr_reset (internal_cache);
|
|
7653 for (line = 0; line < Dynarr_length (dla); line++)
|
|
7654 {
|
|
7655 struct display_line *dl = Dynarr_atp (dla, line);
|
|
7656
|
|
7657 if (dl->modeline)
|
|
7658 continue;
|
|
7659 else
|
|
7660 {
|
|
7661 struct line_start_cache lsc;
|
434
|
7662
|
826
|
7663 lsc.start = dl->charpos;
|
|
7664 lsc.end = dl->end_charpos;
|
428
|
7665 lsc.height = dl->ascent + dl->descent;
|
|
7666
|
|
7667 Dynarr_add (internal_cache, lsc);
|
|
7668 }
|
|
7669 }
|
|
7670 }
|
|
7671
|
|
7672 /* Reset the line cache if necessary. This should be run at the
|
|
7673 beginning of any function which access the cache. */
|
|
7674
|
|
7675 static void
|
|
7676 validate_line_start_cache (struct window *w)
|
|
7677 {
|
|
7678 struct buffer *b = XBUFFER (w->buffer);
|
|
7679 struct frame *f = XFRAME (w->frame);
|
|
7680
|
|
7681 if (!w->line_cache_validation_override)
|
|
7682 {
|
|
7683 /* f->extents_changed used to be in here because extent face and
|
|
7684 size changes can cause text shifting. However, the extent
|
|
7685 covering the region is constantly having its face set and
|
|
7686 priority altered by the mouse code. This means that the line
|
|
7687 start cache is constantly being invalidated. This is bad
|
|
7688 since the mouse code also triggers heavy usage of the cache.
|
|
7689 Since it is an unlikely that f->extents being changed
|
|
7690 indicates that the cache really needs to be updated and if it
|
|
7691 does redisplay will catch it pretty quickly we no longer
|
|
7692 invalidate the cache if it is set. This greatly speeds up
|
|
7693 dragging out regions with the mouse. */
|
|
7694 if (XINT (w->line_cache_last_updated) < BUF_MODIFF (b)
|
|
7695 || f->faces_changed
|
|
7696 || f->clip_changed)
|
|
7697 {
|
|
7698 Dynarr_reset (w->line_start_cache);
|
|
7699 }
|
|
7700 }
|
|
7701 }
|
|
7702
|
|
7703 /* Return the very first buffer position contained in the given
|
|
7704 window's cache, or -1 if the cache is empty. Assumes that the
|
|
7705 cache is valid. */
|
|
7706
|
665
|
7707 static Charbpos
|
428
|
7708 line_start_cache_start (struct window *w)
|
|
7709 {
|
|
7710 line_start_cache_dynarr *cache = w->line_start_cache;
|
|
7711
|
|
7712 if (!Dynarr_length (cache))
|
|
7713 return -1;
|
|
7714 else
|
|
7715 return Dynarr_atp (cache, 0)->start;
|
|
7716 }
|
|
7717
|
|
7718 /* Return the very last buffer position contained in the given
|
|
7719 window's cache, or -1 if the cache is empty. Assumes that the
|
|
7720 cache is valid. */
|
|
7721
|
665
|
7722 static Charbpos
|
428
|
7723 line_start_cache_end (struct window *w)
|
|
7724 {
|
|
7725 line_start_cache_dynarr *cache = w->line_start_cache;
|
|
7726
|
|
7727 if (!Dynarr_length (cache))
|
|
7728 return -1;
|
|
7729 else
|
|
7730 return Dynarr_atp (cache, Dynarr_length (cache) - 1)->end;
|
|
7731 }
|
|
7732
|
|
7733 /* Return the index of the line POINT is contained within in window
|
|
7734 W's line start cache. It will enlarge the cache or move the cache
|
|
7735 window in order to have POINT be present in the cache. MIN_PAST is
|
|
7736 a guarantee of the number of entries in the cache present on either
|
|
7737 side of POINT (unless a buffer boundary is hit). If MIN_PAST is -1
|
|
7738 then it will be treated as 0, but the cache window will not be
|
|
7739 allowed to shift. Returns -1 if POINT cannot be found in the cache
|
|
7740 for any reason. */
|
|
7741
|
|
7742 int
|
665
|
7743 point_in_line_start_cache (struct window *w, Charbpos point, int min_past)
|
428
|
7744 {
|
|
7745 struct buffer *b = XBUFFER (w->buffer);
|
|
7746 line_start_cache_dynarr *cache = w->line_start_cache;
|
647
|
7747 int top, bottom, pos;
|
428
|
7748
|
|
7749 validate_line_start_cache (w);
|
|
7750 w->line_cache_validation_override++;
|
|
7751
|
|
7752 /* Let functions pass in negative values, but we still treat -1
|
|
7753 specially. */
|
|
7754 /* #### bogosity alert */
|
|
7755 if (min_past < 0 && min_past != -1)
|
|
7756 min_past = -min_past;
|
|
7757
|
|
7758 if (!Dynarr_length (cache) || line_start_cache_start (w) > point
|
|
7759 || line_start_cache_end (w) < point)
|
|
7760 {
|
|
7761 int loop;
|
|
7762 int win_char_height = window_char_height (w, 1);
|
|
7763
|
|
7764 /* Occasionally we get here with a 0 height
|
|
7765 window. find_next_newline_no_quit will abort if we pass it a
|
|
7766 count of 0 so handle that case. */
|
|
7767 if (!win_char_height)
|
|
7768 win_char_height = 1;
|
|
7769
|
|
7770 if (!Dynarr_length (cache))
|
|
7771 {
|
665
|
7772 Charbpos from = find_next_newline_no_quit (b, point, -1);
|
|
7773 Charbpos to = find_next_newline_no_quit (b, from, win_char_height);
|
428
|
7774
|
|
7775 update_line_start_cache (w, from, to, point, 0);
|
|
7776
|
|
7777 if (!Dynarr_length (cache))
|
|
7778 {
|
|
7779 w->line_cache_validation_override--;
|
|
7780 return -1;
|
|
7781 }
|
|
7782 }
|
|
7783
|
|
7784 assert (Dynarr_length (cache));
|
|
7785
|
|
7786 loop = 0;
|
|
7787 while (line_start_cache_start (w) > point
|
|
7788 && (loop < cache_adjustment || min_past == -1))
|
|
7789 {
|
665
|
7790 Charbpos from, to;
|
428
|
7791
|
|
7792 from = line_start_cache_start (w);
|
|
7793 if (from <= BUF_BEGV (b))
|
|
7794 break;
|
|
7795
|
|
7796 from = find_next_newline_no_quit (b, from, -win_char_height);
|
|
7797 to = line_start_cache_end (w);
|
|
7798
|
|
7799 update_line_start_cache (w, from, to, point, 0);
|
|
7800 loop++;
|
|
7801 }
|
|
7802
|
|
7803 if (line_start_cache_start (w) > point)
|
|
7804 {
|
665
|
7805 Charbpos from, to;
|
428
|
7806
|
|
7807 from = find_next_newline_no_quit (b, point, -1);
|
|
7808 if (from >= BUF_ZV (b))
|
|
7809 {
|
|
7810 to = find_next_newline_no_quit (b, from, -win_char_height);
|
|
7811 from = to;
|
|
7812 to = BUF_ZV (b);
|
|
7813 }
|
|
7814 else
|
|
7815 to = find_next_newline_no_quit (b, from, win_char_height);
|
|
7816
|
|
7817 update_line_start_cache (w, from, to, point, 0);
|
|
7818 }
|
|
7819
|
|
7820 loop = 0;
|
|
7821 while (line_start_cache_end (w) < point
|
|
7822 && (loop < cache_adjustment || min_past == -1))
|
|
7823 {
|
665
|
7824 Charbpos from, to;
|
428
|
7825
|
|
7826 to = line_start_cache_end (w);
|
|
7827 if (to >= BUF_ZV (b))
|
|
7828 break;
|
|
7829
|
|
7830 from = line_start_cache_end (w);
|
|
7831 to = find_next_newline_no_quit (b, from, win_char_height);
|
|
7832
|
|
7833 update_line_start_cache (w, from, to, point, 0);
|
|
7834 loop++;
|
|
7835 }
|
|
7836
|
|
7837 if (line_start_cache_end (w) < point)
|
|
7838 {
|
665
|
7839 Charbpos from, to;
|
428
|
7840
|
|
7841 from = find_next_newline_no_quit (b, point, -1);
|
|
7842 if (from >= BUF_ZV (b))
|
|
7843 {
|
|
7844 to = find_next_newline_no_quit (b, from, -win_char_height);
|
|
7845 from = to;
|
|
7846 to = BUF_ZV (b);
|
|
7847 }
|
|
7848 else
|
|
7849 to = find_next_newline_no_quit (b, from, win_char_height);
|
|
7850
|
|
7851 update_line_start_cache (w, from, to, point, 0);
|
|
7852 }
|
|
7853 }
|
|
7854
|
|
7855 assert (Dynarr_length (cache));
|
|
7856
|
|
7857 if (min_past == -1)
|
|
7858 min_past = 0;
|
|
7859
|
|
7860 /* This could happen if the buffer is narrowed. */
|
|
7861 if (line_start_cache_start (w) > point
|
|
7862 || line_start_cache_end (w) < point)
|
|
7863 {
|
|
7864 w->line_cache_validation_override--;
|
|
7865 return -1;
|
|
7866 }
|
|
7867
|
|
7868 find_point_loop:
|
|
7869
|
|
7870 top = Dynarr_length (cache) - 1;
|
|
7871 bottom = 0;
|
|
7872
|
|
7873 while (1)
|
|
7874 {
|
647
|
7875 int new_pos;
|
665
|
7876 Charbpos start, end;
|
428
|
7877
|
|
7878 pos = (bottom + top + 1) >> 1;
|
|
7879 start = Dynarr_atp (cache, pos)->start;
|
|
7880 end = Dynarr_atp (cache, pos)->end;
|
|
7881
|
|
7882 if (point >= start && point <= end)
|
|
7883 {
|
|
7884 if (pos < min_past && line_start_cache_start (w) > BUF_BEGV (b))
|
|
7885 {
|
665
|
7886 Charbpos from =
|
428
|
7887 find_next_newline_no_quit (b, line_start_cache_start (w),
|
|
7888 -min_past - 1);
|
665
|
7889 Charbpos to = line_start_cache_end (w);
|
428
|
7890
|
|
7891 update_line_start_cache (w, from, to, point, 0);
|
|
7892 goto find_point_loop;
|
|
7893 }
|
|
7894 else if ((Dynarr_length (cache) - pos - 1) < min_past
|
|
7895 && line_start_cache_end (w) < BUF_ZV (b))
|
|
7896 {
|
665
|
7897 Charbpos from = line_start_cache_end (w);
|
|
7898 Charbpos to = find_next_newline_no_quit (b, from,
|
428
|
7899 (min_past
|
|
7900 ? min_past
|
|
7901 : 1));
|
|
7902
|
|
7903 update_line_start_cache (w, from, to, point, 0);
|
|
7904 goto find_point_loop;
|
|
7905 }
|
|
7906 else
|
|
7907 {
|
|
7908 w->line_cache_validation_override--;
|
|
7909 return pos;
|
|
7910 }
|
|
7911 }
|
|
7912 else if (point > end)
|
|
7913 bottom = pos + 1;
|
|
7914 else if (point < start)
|
|
7915 top = pos - 1;
|
|
7916 else
|
2500
|
7917 ABORT ();
|
428
|
7918
|
|
7919 new_pos = (bottom + top + 1) >> 1;
|
|
7920 if (pos == new_pos)
|
|
7921 {
|
|
7922 w->line_cache_validation_override--;
|
|
7923 return -1;
|
|
7924 }
|
|
7925 }
|
|
7926 }
|
|
7927
|
|
7928 /* Return a boolean indicating if POINT would be visible in window W
|
1708
|
7929 if display of the window was to begin at STARTP. If PARTIALLY is
|
|
7930 zero, then if POINT has fewer visible pixels than the window clip,
|
|
7931 0 is returned; otherwise, 1 is returned if POINT has any visible
|
|
7932 pixels. */
|
428
|
7933 int
|
1708
|
7934 point_would_be_visible (struct window *w, Charbpos startp, Charbpos point,
|
|
7935 int partially)
|
428
|
7936 {
|
|
7937 struct buffer *b = XBUFFER (w->buffer);
|
430
|
7938 int pixpos = -WINDOW_TEXT_TOP_CLIP(w);
|
428
|
7939 int bottom = WINDOW_TEXT_HEIGHT (w);
|
|
7940 int start_elt;
|
|
7941
|
|
7942 /* If point is before the intended start it obviously can't be visible. */
|
|
7943 if (point < startp)
|
|
7944 return 0;
|
|
7945
|
|
7946 /* If point or start are not in the accessible buffer range, then
|
|
7947 fail. */
|
|
7948 if (startp < BUF_BEGV (b) || startp > BUF_ZV (b)
|
|
7949 || point < BUF_BEGV (b) || point > BUF_ZV (b))
|
|
7950 return 0;
|
|
7951
|
|
7952 validate_line_start_cache (w);
|
|
7953 w->line_cache_validation_override++;
|
|
7954
|
|
7955 start_elt = point_in_line_start_cache (w, startp, 0);
|
|
7956 if (start_elt == -1)
|
|
7957 {
|
|
7958 w->line_cache_validation_override--;
|
|
7959 return 0;
|
|
7960 }
|
|
7961
|
|
7962 assert (line_start_cache_start (w) <= startp
|
|
7963 && line_start_cache_end (w) >= startp);
|
|
7964
|
|
7965 while (1)
|
|
7966 {
|
|
7967 int height;
|
|
7968
|
|
7969 /* Expand the cache if necessary. */
|
|
7970 if (start_elt == Dynarr_length (w->line_start_cache))
|
|
7971 {
|
665
|
7972 Charbpos old_startp =
|
428
|
7973 Dynarr_atp (w->line_start_cache, start_elt - 1)->start;
|
|
7974
|
|
7975 start_elt = point_in_line_start_cache (w, old_startp,
|
|
7976 window_char_height (w, 0));
|
|
7977
|
|
7978 /* We've already actually processed old_startp, so increment
|
|
7979 immediately. */
|
|
7980 start_elt++;
|
|
7981
|
|
7982 /* If this happens we didn't add any extra elements. Bummer. */
|
|
7983 if (start_elt == Dynarr_length (w->line_start_cache))
|
|
7984 {
|
|
7985 w->line_cache_validation_override--;
|
|
7986 return 0;
|
|
7987 }
|
|
7988 }
|
|
7989
|
|
7990 height = Dynarr_atp (w->line_start_cache, start_elt)->height;
|
|
7991
|
|
7992 if (pixpos + height > bottom)
|
|
7993 {
|
1708
|
7994 if (bottom - pixpos < (partially ? 0 : VERTICAL_CLIP (w, 0)))
|
428
|
7995 {
|
|
7996 w->line_cache_validation_override--;
|
|
7997 return 0;
|
|
7998 }
|
|
7999 }
|
|
8000
|
|
8001 pixpos += height;
|
|
8002 if (point <= Dynarr_atp (w->line_start_cache, start_elt)->end)
|
|
8003 {
|
|
8004 w->line_cache_validation_override--;
|
|
8005 return 1;
|
|
8006 }
|
|
8007
|
|
8008 start_elt++;
|
|
8009 }
|
|
8010 }
|
|
8011
|
|
8012 /* For the given window W, if display starts at STARTP, what will be
|
|
8013 the buffer position at the beginning or end of the last line
|
|
8014 displayed. The end of the last line is also know as the window end
|
|
8015 position.
|
|
8016
|
442
|
8017 WARNING: It is possible that redisplay failed to layout any lines for the
|
|
8018 windows. Under normal circumstances this is rare. However it seems that it
|
|
8019 does occur in the following situation: A mouse event has come in and we
|
|
8020 need to compute its location in a window. That code (in
|
|
8021 pixel_to_glyph_translation) already can handle 0 as an error return value.
|
|
8022
|
428
|
8023 #### With a little work this could probably be reworked as just a
|
|
8024 call to start_with_line_at_pixpos. */
|
|
8025
|
665
|
8026 static Charbpos
|
|
8027 start_end_of_last_line (struct window *w, Charbpos startp, int end,
|
442
|
8028 int may_error)
|
428
|
8029 {
|
|
8030 struct buffer *b = XBUFFER (w->buffer);
|
|
8031 line_start_cache_dynarr *cache = w->line_start_cache;
|
|
8032 int pixpos = 0;
|
|
8033 int bottom = WINDOW_TEXT_HEIGHT (w);
|
665
|
8034 Charbpos cur_start;
|
428
|
8035 int start_elt;
|
|
8036
|
|
8037 validate_line_start_cache (w);
|
|
8038 w->line_cache_validation_override++;
|
|
8039
|
|
8040 if (startp < BUF_BEGV (b))
|
|
8041 startp = BUF_BEGV (b);
|
|
8042 else if (startp > BUF_ZV (b))
|
|
8043 startp = BUF_ZV (b);
|
|
8044 cur_start = startp;
|
|
8045
|
|
8046 start_elt = point_in_line_start_cache (w, cur_start, 0);
|
|
8047 if (start_elt == -1)
|
442
|
8048 return may_error ? 0 : startp;
|
428
|
8049
|
|
8050 while (1)
|
|
8051 {
|
|
8052 int height = Dynarr_atp (cache, start_elt)->height;
|
|
8053
|
|
8054 cur_start = Dynarr_atp (cache, start_elt)->start;
|
|
8055
|
|
8056 if (pixpos + height > bottom)
|
|
8057 {
|
|
8058 /* Adjust for any possible clip. */
|
|
8059 if (bottom - pixpos < VERTICAL_CLIP (w, 0))
|
|
8060 start_elt--;
|
|
8061
|
|
8062 if (start_elt < 0)
|
|
8063 {
|
|
8064 w->line_cache_validation_override--;
|
|
8065 if (end)
|
|
8066 return BUF_ZV (b);
|
|
8067 else
|
|
8068 return BUF_BEGV (b);
|
|
8069 }
|
|
8070 else
|
|
8071 {
|
|
8072 w->line_cache_validation_override--;
|
|
8073 if (end)
|
|
8074 return Dynarr_atp (cache, start_elt)->end;
|
|
8075 else
|
|
8076 return Dynarr_atp (cache, start_elt)->start;
|
|
8077 }
|
|
8078 }
|
|
8079
|
|
8080 pixpos += height;
|
|
8081 start_elt++;
|
|
8082 if (start_elt == Dynarr_length (cache))
|
|
8083 {
|
665
|
8084 Charbpos from = line_start_cache_end (w);
|
428
|
8085 int win_char_height = window_char_height (w, 0);
|
665
|
8086 Charbpos to = find_next_newline_no_quit (b, from,
|
428
|
8087 (win_char_height
|
|
8088 ? win_char_height
|
|
8089 : 1));
|
|
8090
|
|
8091 /* We've hit the end of the bottom so that's what it is. */
|
|
8092 if (from >= BUF_ZV (b))
|
|
8093 {
|
|
8094 w->line_cache_validation_override--;
|
|
8095 return BUF_ZV (b);
|
|
8096 }
|
|
8097
|
|
8098 update_line_start_cache (w, from, to, BUF_PT (b), 0);
|
|
8099
|
|
8100 /* Updating the cache invalidates any current indexes. */
|
|
8101 start_elt = point_in_line_start_cache (w, cur_start, -1) + 1;
|
|
8102 }
|
|
8103 }
|
|
8104 }
|
|
8105
|
|
8106 /* For the given window W, if display starts at STARTP, what will be
|
|
8107 the buffer position at the beginning of the last line displayed. */
|
|
8108
|
665
|
8109 Charbpos
|
|
8110 start_of_last_line (struct window *w, Charbpos startp)
|
428
|
8111 {
|
442
|
8112 return start_end_of_last_line (w, startp, 0 , 0);
|
428
|
8113 }
|
|
8114
|
|
8115 /* For the given window W, if display starts at STARTP, what will be
|
|
8116 the buffer position at the end of the last line displayed. This is
|
|
8117 also know as the window end position. */
|
|
8118
|
665
|
8119 Charbpos
|
|
8120 end_of_last_line (struct window *w, Charbpos startp)
|
428
|
8121 {
|
442
|
8122 return start_end_of_last_line (w, startp, 1, 0);
|
428
|
8123 }
|
|
8124
|
665
|
8125 static Charbpos
|
|
8126 end_of_last_line_may_error (struct window *w, Charbpos startp)
|
442
|
8127 {
|
|
8128 return start_end_of_last_line (w, startp, 1, 1);
|
|
8129 }
|
|
8130
|
|
8131
|
428
|
8132 /* For window W, what does the starting position have to be so that
|
|
8133 the line containing POINT will cover pixel position PIXPOS. */
|
|
8134
|
665
|
8135 Charbpos
|
|
8136 start_with_line_at_pixpos (struct window *w, Charbpos point, int pixpos)
|
428
|
8137 {
|
|
8138 struct buffer *b = XBUFFER (w->buffer);
|
|
8139 int cur_elt;
|
665
|
8140 Charbpos cur_pos, prev_pos = point;
|
428
|
8141 int point_line_height;
|
|
8142 int pixheight = pixpos - WINDOW_TEXT_TOP (w);
|
|
8143
|
|
8144 validate_line_start_cache (w);
|
|
8145 w->line_cache_validation_override++;
|
|
8146
|
|
8147 cur_elt = point_in_line_start_cache (w, point, 0);
|
|
8148 /* #### See comment in update_line_start_cache about big minibuffers. */
|
|
8149 if (cur_elt < 0)
|
|
8150 {
|
|
8151 w->line_cache_validation_override--;
|
|
8152 return point;
|
|
8153 }
|
|
8154
|
|
8155 point_line_height = Dynarr_atp (w->line_start_cache, cur_elt)->height;
|
|
8156
|
|
8157 while (1)
|
|
8158 {
|
|
8159 cur_pos = Dynarr_atp (w->line_start_cache, cur_elt)->start;
|
|
8160
|
|
8161 pixheight -= Dynarr_atp (w->line_start_cache, cur_elt)->height;
|
|
8162
|
|
8163 /* Do not take into account the value of vertical_clip here.
|
|
8164 That is the responsibility of the calling functions. */
|
|
8165 if (pixheight < 0)
|
|
8166 {
|
|
8167 w->line_cache_validation_override--;
|
|
8168 if (-pixheight > point_line_height)
|
|
8169 /* We can't make the target line cover pixpos, so put it
|
|
8170 above pixpos. That way it will at least be visible. */
|
|
8171 return prev_pos;
|
|
8172 else
|
|
8173 return cur_pos;
|
|
8174 }
|
|
8175
|
|
8176 cur_elt--;
|
|
8177 while (cur_elt < 0)
|
|
8178 {
|
665
|
8179 Charbpos from, to;
|
428
|
8180 int win_char_height;
|
|
8181
|
|
8182 if (cur_pos <= BUF_BEGV (b))
|
|
8183 {
|
|
8184 w->line_cache_validation_override--;
|
|
8185 return BUF_BEGV (b);
|
|
8186 }
|
|
8187
|
|
8188 win_char_height = window_char_height (w, 0);
|
|
8189 if (!win_char_height)
|
|
8190 win_char_height = 1;
|
|
8191
|
|
8192 from = find_next_newline_no_quit (b, cur_pos, -win_char_height);
|
|
8193 to = line_start_cache_end (w);
|
|
8194 update_line_start_cache (w, from, to, point, 0);
|
|
8195
|
|
8196 cur_elt = point_in_line_start_cache (w, cur_pos, 2) - 1;
|
|
8197 assert (cur_elt >= -1);
|
|
8198 /* This used to be cur_elt>=0 under the assumption that if
|
|
8199 point is in the top line and not at BUF_BEGV, then
|
434
|
8200 setting the window_start to a newline before the start of
|
428
|
8201 the first line will always cause scrolling.
|
|
8202
|
|
8203 However in my (jv) opinion this is wrong. That new line
|
|
8204 can be hidden in various ways: invisible extents, an
|
|
8205 explicit window-start not at a newline character etc.
|
|
8206 The existence of those are indeed known to create crashes
|
|
8207 on that assert. So we have no option but to continue the
|
|
8208 search if we found point at the top of the line_start_cache
|
|
8209 again. */
|
434
|
8210 cur_pos = Dynarr_atp (w->line_start_cache,0)->start;
|
428
|
8211 }
|
|
8212 prev_pos = cur_pos;
|
|
8213 }
|
|
8214 }
|
|
8215
|
|
8216 /* For window W, what does the starting position have to be so that
|
|
8217 the line containing point is on display line LINE. If LINE is
|
|
8218 positive it is considered to be the number of lines from the top of
|
|
8219 the window (0 is the top line). If it is negative the number is
|
|
8220 considered to be the number of lines from the bottom (-1 is the
|
|
8221 bottom line). */
|
|
8222
|
665
|
8223 Charbpos
|
|
8224 start_with_point_on_display_line (struct window *w, Charbpos point, int line)
|
428
|
8225 {
|
|
8226 validate_line_start_cache (w);
|
|
8227 w->line_cache_validation_override++;
|
|
8228
|
|
8229 if (line >= 0)
|
|
8230 {
|
|
8231 int cur_elt = point_in_line_start_cache (w, point, line);
|
|
8232
|
|
8233 if (cur_elt - line < 0)
|
|
8234 cur_elt = 0; /* Hit the top */
|
|
8235 else
|
|
8236 cur_elt -= line;
|
|
8237
|
|
8238 w->line_cache_validation_override--;
|
|
8239 return Dynarr_atp (w->line_start_cache, cur_elt)->start;
|
|
8240 }
|
|
8241 else
|
|
8242 {
|
|
8243 /* The calculated value of pixpos is correct for the bottom line
|
|
8244 or what we want when line is -1. Therefore we subtract one
|
|
8245 because we have already handled one line. */
|
|
8246 int new_line = -line - 1;
|
|
8247 int cur_elt = point_in_line_start_cache (w, point, new_line);
|
|
8248 int pixpos = WINDOW_TEXT_BOTTOM (w);
|
665
|
8249 Charbpos retval, search_point;
|
428
|
8250
|
|
8251 /* If scroll_on_clipped_lines is false, the last "visible" line of
|
|
8252 the window covers the pixel at WINDOW_TEXT_BOTTOM (w) - 1.
|
|
8253 If s_o_c_l is true, then we don't want to count a clipped
|
|
8254 line, so back up from the bottom by the height of the line
|
|
8255 containing point. */
|
|
8256 if (scroll_on_clipped_lines)
|
|
8257 pixpos -= Dynarr_atp (w->line_start_cache, cur_elt)->height;
|
|
8258 else
|
|
8259 pixpos -= 1;
|
|
8260
|
|
8261 if (cur_elt + new_line >= Dynarr_length (w->line_start_cache))
|
|
8262 {
|
|
8263 /* Hit the bottom of the buffer. */
|
|
8264 int adjustment =
|
|
8265 (cur_elt + new_line) - Dynarr_length (w->line_start_cache) + 1;
|
|
8266 Lisp_Object window;
|
|
8267 int defheight;
|
|
8268
|
793
|
8269 window = wrap_window (w);
|
428
|
8270 default_face_height_and_width (window, &defheight, 0);
|
|
8271
|
|
8272 cur_elt = Dynarr_length (w->line_start_cache) - 1;
|
|
8273
|
|
8274 pixpos -= (adjustment * defheight);
|
|
8275 if (pixpos < WINDOW_TEXT_TOP (w))
|
|
8276 pixpos = WINDOW_TEXT_TOP (w);
|
|
8277 }
|
|
8278 else
|
|
8279 cur_elt = cur_elt + new_line;
|
|
8280
|
|
8281 search_point = Dynarr_atp (w->line_start_cache, cur_elt)->start;
|
|
8282
|
|
8283 retval = start_with_line_at_pixpos (w, search_point, pixpos);
|
|
8284 w->line_cache_validation_override--;
|
|
8285 return retval;
|
|
8286 }
|
|
8287 }
|
|
8288
|
|
8289 /* This is used to speed up vertical scrolling by caching the known
|
|
8290 buffer starting positions for display lines. This allows the
|
|
8291 scrolling routines to avoid costly calls to regenerate_window. If
|
|
8292 NO_REGEN is true then it will only add the values in the DESIRED
|
|
8293 display structs which are in the given range.
|
|
8294
|
|
8295 Note also that the FROM/TO values are minimums. It is possible
|
|
8296 that this function will actually add information outside of the
|
|
8297 lines containing those positions. This can't hurt but it could
|
|
8298 possibly help.
|
|
8299
|
|
8300 #### We currently force the cache to have only 1 contiguous region.
|
|
8301 It might help to make the cache a dynarr of caches so that we can
|
|
8302 cover more areas. This might, however, turn out to be a lot of
|
|
8303 overhead for too little gain. */
|
|
8304
|
|
8305 static void
|
665
|
8306 update_line_start_cache (struct window *w, Charbpos from, Charbpos to,
|
|
8307 Charbpos point, int no_regen)
|
428
|
8308 {
|
|
8309 struct buffer *b = XBUFFER (w->buffer);
|
|
8310 line_start_cache_dynarr *cache = w->line_start_cache;
|
665
|
8311 Charbpos low_bound, high_bound;
|
428
|
8312
|
|
8313 validate_line_start_cache (w);
|
|
8314 w->line_cache_validation_override++;
|
|
8315
|
|
8316 if (from < BUF_BEGV (b))
|
|
8317 from = BUF_BEGV (b);
|
|
8318 if (to > BUF_ZV (b))
|
|
8319 to = BUF_ZV (b);
|
|
8320
|
|
8321 if (from > to)
|
|
8322 {
|
|
8323 w->line_cache_validation_override--;
|
|
8324 return;
|
|
8325 }
|
|
8326
|
|
8327 if (Dynarr_length (cache))
|
|
8328 {
|
|
8329 low_bound = line_start_cache_start (w);
|
|
8330 high_bound = line_start_cache_end (w);
|
|
8331
|
|
8332 /* Check to see if the desired range is already in the cache. */
|
|
8333 if (from >= low_bound && to <= high_bound)
|
|
8334 {
|
|
8335 w->line_cache_validation_override--;
|
|
8336 return;
|
|
8337 }
|
|
8338
|
|
8339 /* Check to make sure that the desired range is adjacent to the
|
|
8340 current cache. If not, invalidate the cache. */
|
|
8341 if (to < low_bound || from > high_bound)
|
|
8342 {
|
|
8343 Dynarr_reset (cache);
|
|
8344 low_bound = high_bound = -1;
|
|
8345 }
|
|
8346 }
|
|
8347 else
|
|
8348 {
|
|
8349 low_bound = high_bound = -1;
|
|
8350 }
|
|
8351
|
|
8352 w->line_cache_last_updated = make_int (BUF_MODIFF (b));
|
|
8353
|
|
8354 /* This could be integrated into the next two sections, but it is easier
|
|
8355 to follow what's going on by having it separate. */
|
|
8356 if (no_regen)
|
|
8357 {
|
665
|
8358 Charbpos start, end;
|
428
|
8359
|
|
8360 update_internal_cache_list (w, DESIRED_DISP);
|
|
8361 if (!Dynarr_length (internal_cache))
|
|
8362 {
|
|
8363 w->line_cache_validation_override--;
|
|
8364 return;
|
|
8365 }
|
|
8366
|
|
8367 start = Dynarr_atp (internal_cache, 0)->start;
|
|
8368 end =
|
|
8369 Dynarr_atp (internal_cache, Dynarr_length (internal_cache) - 1)->end;
|
|
8370
|
|
8371 /* We aren't allowed to generate additional information to fill in
|
|
8372 gaps, so if the DESIRED structs don't overlap the cache, reset the
|
|
8373 cache. */
|
|
8374 if (Dynarr_length (cache))
|
|
8375 {
|
|
8376 if (end < low_bound || start > high_bound)
|
|
8377 Dynarr_reset (cache);
|
|
8378
|
|
8379 /* #### What should really happen if what we are doing is
|
|
8380 extending a line (the last line)? */
|
|
8381 if (Dynarr_length (cache) == 1
|
|
8382 && Dynarr_length (internal_cache) == 1)
|
|
8383 Dynarr_reset (cache);
|
|
8384 }
|
|
8385
|
|
8386 if (!Dynarr_length (cache))
|
|
8387 {
|
|
8388 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8389 Dynarr_length (internal_cache));
|
|
8390 w->line_cache_validation_override--;
|
|
8391 return;
|
|
8392 }
|
|
8393
|
|
8394 /* An extra check just in case the calling function didn't pass in
|
|
8395 the bounds of the DESIRED structs in the first place. */
|
|
8396 if (start >= low_bound && end <= high_bound)
|
|
8397 {
|
|
8398 w->line_cache_validation_override--;
|
|
8399 return;
|
|
8400 }
|
|
8401
|
|
8402 /* At this point we know that the internal cache partially overlaps
|
|
8403 the main cache. */
|
|
8404 if (start < low_bound)
|
|
8405 {
|
|
8406 int ic_elt = Dynarr_length (internal_cache) - 1;
|
|
8407 while (ic_elt >= 0)
|
|
8408 {
|
|
8409 if (Dynarr_atp (internal_cache, ic_elt)->start < low_bound)
|
|
8410 break;
|
|
8411 else
|
|
8412 ic_elt--;
|
|
8413 }
|
|
8414
|
|
8415 if (!(ic_elt >= 0))
|
|
8416 {
|
|
8417 Dynarr_reset (cache);
|
|
8418 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8419 Dynarr_length (internal_cache));
|
|
8420 w->line_cache_validation_override--;
|
|
8421 return;
|
|
8422 }
|
|
8423
|
|
8424 Dynarr_insert_many_at_start (cache, Dynarr_atp (internal_cache, 0),
|
|
8425 ic_elt + 1);
|
|
8426 }
|
|
8427
|
|
8428 if (end > high_bound)
|
|
8429 {
|
|
8430 int ic_elt = 0;
|
|
8431
|
|
8432 while (ic_elt < Dynarr_length (internal_cache))
|
|
8433 {
|
|
8434 if (Dynarr_atp (internal_cache, ic_elt)->start > high_bound)
|
|
8435 break;
|
|
8436 else
|
|
8437 ic_elt++;
|
|
8438 }
|
|
8439
|
|
8440 if (!(ic_elt < Dynarr_length (internal_cache)))
|
|
8441 {
|
|
8442 Dynarr_reset (cache);
|
|
8443 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8444 Dynarr_length (internal_cache));
|
|
8445 w->line_cache_validation_override--;
|
|
8446 return;
|
|
8447 }
|
|
8448
|
|
8449 Dynarr_add_many (cache, Dynarr_atp (internal_cache, ic_elt),
|
|
8450 Dynarr_length (internal_cache) - ic_elt);
|
|
8451 }
|
|
8452
|
|
8453 w->line_cache_validation_override--;
|
|
8454 return;
|
|
8455 }
|
|
8456
|
|
8457 if (!Dynarr_length (cache) || from < low_bound)
|
|
8458 {
|
665
|
8459 Charbpos startp = find_next_newline_no_quit (b, from, -1);
|
428
|
8460 int marker = 0;
|
|
8461 int old_lb = low_bound;
|
|
8462
|
|
8463 while (startp < old_lb || low_bound == -1)
|
|
8464 {
|
|
8465 int ic_elt;
|
665
|
8466 Charbpos new_startp;
|
428
|
8467
|
|
8468 regenerate_window (w, startp, point, CMOTION_DISP);
|
|
8469 update_internal_cache_list (w, CMOTION_DISP);
|
|
8470
|
|
8471 /* If this assert is triggered then regenerate_window failed
|
442
|
8472 to layout a single line. This is not possible since we
|
|
8473 force at least a single line to be layout for CMOTION_DISP */
|
|
8474 assert (Dynarr_length (internal_cache));
|
428
|
8475 assert (startp == Dynarr_atp (internal_cache, 0)->start);
|
|
8476
|
|
8477 ic_elt = Dynarr_length (internal_cache) - 1;
|
|
8478 if (low_bound != -1)
|
|
8479 {
|
|
8480 while (ic_elt >= 0)
|
|
8481 {
|
|
8482 if (Dynarr_atp (internal_cache, ic_elt)->start < old_lb)
|
|
8483 break;
|
|
8484 else
|
|
8485 ic_elt--;
|
|
8486 }
|
|
8487 }
|
|
8488 assert (ic_elt >= 0);
|
|
8489
|
|
8490 new_startp = Dynarr_atp (internal_cache, ic_elt)->end + 1;
|
|
8491
|
|
8492 /*
|
|
8493 * Handle invisible text properly:
|
|
8494 * If the last line we're inserting has the same end as the
|
|
8495 * line before which it will be added, merge the two lines.
|
|
8496 */
|
|
8497 if (Dynarr_length (cache) &&
|
|
8498 Dynarr_atp (internal_cache, ic_elt)->end ==
|
|
8499 Dynarr_atp (cache, marker)->end)
|
|
8500 {
|
|
8501 Dynarr_atp (cache, marker)->start
|
|
8502 = Dynarr_atp (internal_cache, ic_elt)->start;
|
|
8503 Dynarr_atp (cache, marker)->height
|
|
8504 = Dynarr_atp (internal_cache, ic_elt)->height;
|
|
8505 ic_elt--;
|
|
8506 }
|
|
8507
|
|
8508 if (ic_elt >= 0) /* we still have lines to add.. */
|
|
8509 {
|
|
8510 Dynarr_insert_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8511 ic_elt + 1, marker);
|
|
8512 marker += (ic_elt + 1);
|
|
8513 }
|
|
8514
|
|
8515 if (startp < low_bound || low_bound == -1)
|
|
8516 low_bound = startp;
|
|
8517 startp = new_startp;
|
|
8518 if (startp > BUF_ZV (b))
|
|
8519 {
|
|
8520 w->line_cache_validation_override--;
|
|
8521 return;
|
|
8522 }
|
|
8523 }
|
|
8524 }
|
|
8525
|
|
8526 assert (Dynarr_length (cache));
|
|
8527 assert (from >= low_bound);
|
|
8528
|
|
8529 /* Readjust the high_bound to account for any changes made while
|
|
8530 correcting the low_bound. */
|
|
8531 high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end;
|
|
8532
|
|
8533 if (to > high_bound)
|
|
8534 {
|
665
|
8535 Charbpos startp = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end + 1;
|
428
|
8536
|
|
8537 do
|
|
8538 {
|
|
8539 regenerate_window (w, startp, point, CMOTION_DISP);
|
|
8540 update_internal_cache_list (w, CMOTION_DISP);
|
|
8541
|
|
8542 /* See comment above about regenerate_window failing. */
|
|
8543 assert (Dynarr_length (internal_cache));
|
|
8544
|
|
8545 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8546 Dynarr_length (internal_cache));
|
|
8547 high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end;
|
|
8548 startp = high_bound + 1;
|
|
8549 }
|
|
8550 while (to > high_bound);
|
|
8551 }
|
|
8552
|
|
8553 w->line_cache_validation_override--;
|
|
8554 assert (to <= high_bound);
|
|
8555 }
|
|
8556
|
|
8557
|
|
8558 /* Given x and y coordinates in characters, relative to a window,
|
|
8559 return the pixel location corresponding to those coordinates. The
|
|
8560 pixel location returned is the center of the given character
|
|
8561 position. The pixel values are generated relative to the window,
|
|
8562 not the frame.
|
|
8563
|
|
8564 The modeline is considered to be part of the window. */
|
|
8565
|
|
8566 void
|
|
8567 glyph_to_pixel_translation (struct window *w, int char_x, int char_y,
|
|
8568 int *pix_x, int *pix_y)
|
|
8569 {
|
|
8570 display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP);
|
|
8571 int num_disp_lines, modeline;
|
|
8572 Lisp_Object window;
|
|
8573 int defheight, defwidth;
|
|
8574
|
793
|
8575 window = wrap_window (w);
|
428
|
8576 default_face_height_and_width (window, &defheight, &defwidth);
|
|
8577
|
|
8578 /* If we get a bogus value indicating somewhere above or to the left of
|
|
8579 the window, use the first window line or character position
|
|
8580 instead. */
|
|
8581 if (char_y < 0)
|
|
8582 char_y = 0;
|
|
8583 if (char_x < 0)
|
|
8584 char_x = 0;
|
|
8585
|
|
8586 num_disp_lines = Dynarr_length (dla);
|
|
8587 modeline = 0;
|
|
8588 if (num_disp_lines)
|
|
8589 {
|
|
8590 if (Dynarr_atp (dla, 0)->modeline)
|
|
8591 {
|
|
8592 num_disp_lines--;
|
|
8593 modeline = 1;
|
|
8594 }
|
|
8595 }
|
|
8596
|
|
8597 /* First check if the y position intersects the display lines. */
|
|
8598 if (char_y < num_disp_lines)
|
|
8599 {
|
|
8600 struct display_line *dl = Dynarr_atp (dla, char_y + modeline);
|
|
8601 struct display_block *db = get_display_block_from_line (dl, TEXT);
|
|
8602
|
|
8603 *pix_y = (dl->ypos - dl->ascent +
|
647
|
8604 ((dl->ascent + dl->descent - dl->clip) >> 1));
|
428
|
8605
|
|
8606 if (char_x < Dynarr_length (db->runes))
|
|
8607 {
|
|
8608 struct rune *rb = Dynarr_atp (db->runes, char_x);
|
|
8609
|
|
8610 *pix_x = rb->xpos + (rb->width >> 1);
|
|
8611 }
|
|
8612 else
|
|
8613 {
|
|
8614 int last_rune = Dynarr_length (db->runes) - 1;
|
|
8615 struct rune *rb = Dynarr_atp (db->runes, last_rune);
|
|
8616
|
|
8617 char_x -= last_rune;
|
|
8618
|
|
8619 *pix_x = rb->xpos + rb->width;
|
|
8620 *pix_x += ((char_x - 1) * defwidth);
|
|
8621 *pix_x += (defwidth >> 1);
|
|
8622 }
|
|
8623 }
|
|
8624 else
|
|
8625 {
|
|
8626 /* It didn't intersect, so extrapolate. #### For now, we include the
|
|
8627 modeline in this since we don't have true character positions in
|
|
8628 it. */
|
|
8629
|
|
8630 if (!Dynarr_length (w->face_cachels))
|
|
8631 reset_face_cachels (w);
|
|
8632
|
|
8633 char_y -= num_disp_lines;
|
|
8634
|
|
8635 if (Dynarr_length (dla))
|
|
8636 {
|
|
8637 struct display_line *dl = Dynarr_atp (dla, Dynarr_length (dla) - 1);
|
|
8638 *pix_y = dl->ypos + dl->descent - dl->clip;
|
|
8639 }
|
|
8640 else
|
|
8641 *pix_y = WINDOW_TEXT_TOP (w);
|
|
8642
|
|
8643 *pix_y += (char_y * defheight);
|
|
8644 *pix_y += (defheight >> 1);
|
|
8645
|
|
8646 *pix_x = WINDOW_TEXT_LEFT (w);
|
|
8647 /* Don't adjust by one because this is still the unadjusted value. */
|
|
8648 *pix_x += (char_x * defwidth);
|
|
8649 *pix_x += (defwidth >> 1);
|
|
8650 }
|
|
8651
|
|
8652 if (*pix_x > w->pixel_left + w->pixel_width)
|
|
8653 *pix_x = w->pixel_left + w->pixel_width;
|
|
8654 if (*pix_y > w->pixel_top + w->pixel_height)
|
|
8655 *pix_y = w->pixel_top + w->pixel_height;
|
|
8656
|
|
8657 *pix_x -= w->pixel_left;
|
|
8658 *pix_y -= w->pixel_top;
|
|
8659 }
|
|
8660
|
|
8661 /* Given a display line and a position, determine if there is a glyph
|
|
8662 there and return information about it if there is. */
|
|
8663
|
|
8664 static void
|
|
8665 get_position_object (struct display_line *dl, Lisp_Object *obj1,
|
|
8666 Lisp_Object *obj2, int x_coord, int *low_x_coord,
|
|
8667 int *high_x_coord)
|
|
8668 {
|
|
8669 struct display_block *db;
|
|
8670 int elt;
|
|
8671 int block =
|
|
8672 get_next_display_block (dl->bounds, dl->display_blocks, x_coord, 0);
|
|
8673
|
|
8674 /* We use get_next_display_block to get the actual display block
|
|
8675 that would be displayed at x_coord. */
|
|
8676
|
|
8677 if (block == NO_BLOCK)
|
|
8678 return;
|
|
8679 else
|
|
8680 db = Dynarr_atp (dl->display_blocks, block);
|
|
8681
|
|
8682 for (elt = 0; elt < Dynarr_length (db->runes); elt++)
|
|
8683 {
|
|
8684 struct rune *rb = Dynarr_atp (db->runes, elt);
|
|
8685
|
|
8686 if (rb->xpos <= x_coord && x_coord < (rb->xpos + rb->width))
|
|
8687 {
|
|
8688 if (rb->type == RUNE_DGLYPH)
|
|
8689 {
|
|
8690 *obj1 = rb->object.dglyph.glyph;
|
|
8691 *obj2 = rb->object.dglyph.extent;
|
|
8692 }
|
|
8693 else
|
|
8694 {
|
|
8695 *obj1 = Qnil;
|
|
8696 *obj2 = Qnil;
|
|
8697 }
|
|
8698
|
|
8699 if (low_x_coord)
|
|
8700 *low_x_coord = rb->xpos;
|
|
8701 if (high_x_coord)
|
|
8702 *high_x_coord = rb->xpos + rb->width;
|
|
8703
|
|
8704 return;
|
|
8705 }
|
|
8706 }
|
|
8707 }
|
|
8708
|
|
8709 #define UPDATE_CACHE_RETURN \
|
|
8710 do { \
|
|
8711 d->pixel_to_glyph_cache.valid = 1; \
|
|
8712 d->pixel_to_glyph_cache.low_x_coord = low_x_coord; \
|
|
8713 d->pixel_to_glyph_cache.high_x_coord = high_x_coord; \
|
|
8714 d->pixel_to_glyph_cache.low_y_coord = low_y_coord; \
|
|
8715 d->pixel_to_glyph_cache.high_y_coord = high_y_coord; \
|
|
8716 d->pixel_to_glyph_cache.frame = f; \
|
|
8717 d->pixel_to_glyph_cache.col = *col; \
|
|
8718 d->pixel_to_glyph_cache.row = *row; \
|
|
8719 d->pixel_to_glyph_cache.obj_x = *obj_x; \
|
|
8720 d->pixel_to_glyph_cache.obj_y = *obj_y; \
|
|
8721 d->pixel_to_glyph_cache.w = *w; \
|
826
|
8722 d->pixel_to_glyph_cache.charpos = *charpos; \
|
428
|
8723 d->pixel_to_glyph_cache.closest = *closest; \
|
|
8724 d->pixel_to_glyph_cache.modeline_closest = *modeline_closest; \
|
|
8725 d->pixel_to_glyph_cache.obj1 = *obj1; \
|
|
8726 d->pixel_to_glyph_cache.obj2 = *obj2; \
|
|
8727 d->pixel_to_glyph_cache.retval = position; \
|
|
8728 RETURN_SANS_WARNINGS position; \
|
|
8729 } while (0)
|
|
8730
|
|
8731 /* Given x and y coordinates in pixels relative to a frame, return
|
|
8732 information about what is located under those coordinates.
|
|
8733
|
|
8734 The return value will be one of:
|
|
8735
|
|
8736 OVER_TOOLBAR: over one of the 4 frame toolbars
|
|
8737 OVER_MODELINE: over a modeline
|
|
8738 OVER_BORDER: over an internal border
|
|
8739 OVER_NOTHING: over the text area, but not over text
|
|
8740 OVER_OUTSIDE: outside of the frame border
|
|
8741 OVER_TEXT: over text in the text area
|
|
8742
|
|
8743 OBJ1 is one of
|
|
8744
|
|
8745 -- a toolbar button
|
|
8746 -- a glyph
|
|
8747 -- nil if the coordinates are not over a glyph or a toolbar button.
|
|
8748
|
|
8749 OBJ2 is one of
|
|
8750
|
|
8751 -- an extent, if the coordinates are over a glyph in the text area
|
|
8752 -- nil otherwise.
|
|
8753
|
|
8754 If the coordinates are over a glyph, OBJ_X and OBJ_Y give the
|
|
8755 equivalent coordinates relative to the upper-left corner of the glyph.
|
|
8756
|
|
8757 If the coordinates are over a character, OBJ_X and OBJ_Y give the
|
|
8758 equivalent coordinates relative to the upper-left corner of the character.
|
|
8759
|
|
8760 Otherwise, OBJ_X and OBJ_Y are undefined.
|
|
8761 */
|
|
8762
|
|
8763 int
|
|
8764 pixel_to_glyph_translation (struct frame *f, int x_coord, int y_coord,
|
|
8765 int *col, int *row, int *obj_x, int *obj_y,
|
826
|
8766 struct window **w, Charbpos *charpos,
|
665
|
8767 Charbpos *closest, Charcount *modeline_closest,
|
428
|
8768 Lisp_Object *obj1, Lisp_Object *obj2)
|
|
8769 {
|
|
8770 struct device *d;
|
|
8771 struct pixel_to_glyph_translation_cache *cache;
|
|
8772 Lisp_Object window;
|
|
8773 int frm_left, frm_right, frm_top, frm_bottom;
|
|
8774 int low_x_coord, high_x_coord, low_y_coord, high_y_coord;
|
|
8775 int position = OVER_NOTHING;
|
|
8776 int device_check_failed = 0;
|
|
8777 display_line_dynarr *dla;
|
|
8778
|
|
8779 /* This is a safety valve in case this got called with a frame in
|
|
8780 the middle of being deleted. */
|
|
8781 if (!DEVICEP (f->device) || !DEVICE_LIVE_P (XDEVICE (f->device)))
|
|
8782 {
|
|
8783 device_check_failed = 1;
|
|
8784 d = NULL, cache = NULL; /* Warning suppression */
|
|
8785 }
|
|
8786 else
|
|
8787 {
|
|
8788 d = XDEVICE (f->device);
|
|
8789 cache = &d->pixel_to_glyph_cache;
|
|
8790 }
|
|
8791
|
|
8792 if (!device_check_failed
|
|
8793 && cache->valid
|
|
8794 && cache->frame == f
|
|
8795 && cache->low_x_coord <= x_coord
|
|
8796 && cache->high_x_coord > x_coord
|
|
8797 && cache->low_y_coord <= y_coord
|
|
8798 && cache->high_y_coord > y_coord)
|
|
8799 {
|
|
8800 *col = cache->col;
|
|
8801 *row = cache->row;
|
|
8802 *obj_x = cache->obj_x;
|
|
8803 *obj_y = cache->obj_y;
|
|
8804 *w = cache->w;
|
826
|
8805 *charpos = cache->charpos;
|
428
|
8806 *closest = cache->closest;
|
|
8807 *modeline_closest = cache->modeline_closest;
|
|
8808 *obj1 = cache->obj1;
|
|
8809 *obj2 = cache->obj2;
|
|
8810
|
|
8811 return cache->retval;
|
|
8812 }
|
|
8813 else
|
|
8814 {
|
|
8815 *col = 0;
|
|
8816 *row = 0;
|
|
8817 *obj_x = 0;
|
|
8818 *obj_y = 0;
|
|
8819 *w = 0;
|
826
|
8820 *charpos = 0;
|
428
|
8821 *closest = 0;
|
|
8822 *modeline_closest = -1;
|
|
8823 *obj1 = Qnil;
|
|
8824 *obj2 = Qnil;
|
|
8825
|
|
8826 low_x_coord = x_coord;
|
|
8827 high_x_coord = x_coord + 1;
|
|
8828 low_y_coord = y_coord;
|
|
8829 high_y_coord = y_coord + 1;
|
|
8830 }
|
|
8831
|
|
8832 if (device_check_failed)
|
|
8833 return OVER_NOTHING;
|
|
8834
|
|
8835 frm_left = FRAME_LEFT_BORDER_END (f);
|
|
8836 frm_right = FRAME_RIGHT_BORDER_START (f);
|
|
8837 frm_top = FRAME_TOP_BORDER_END (f);
|
|
8838 frm_bottom = FRAME_BOTTOM_BORDER_START (f);
|
|
8839
|
|
8840 /* Check if the mouse is outside of the text area actually used by
|
|
8841 redisplay. */
|
|
8842 if (y_coord < frm_top)
|
|
8843 {
|
|
8844 if (y_coord >= FRAME_TOP_BORDER_START (f))
|
|
8845 {
|
|
8846 low_y_coord = FRAME_TOP_BORDER_START (f);
|
|
8847 high_y_coord = frm_top;
|
|
8848 position = OVER_BORDER;
|
|
8849 }
|
|
8850 else if (y_coord >= 0)
|
|
8851 {
|
|
8852 low_y_coord = 0;
|
|
8853 high_y_coord = FRAME_TOP_BORDER_START (f);
|
|
8854 position = OVER_TOOLBAR;
|
|
8855 }
|
|
8856 else
|
|
8857 {
|
|
8858 low_y_coord = y_coord;
|
|
8859 high_y_coord = 0;
|
|
8860 position = OVER_OUTSIDE;
|
|
8861 }
|
|
8862 }
|
|
8863 else if (y_coord >= frm_bottom)
|
|
8864 {
|
|
8865 if (y_coord < FRAME_BOTTOM_BORDER_END (f))
|
|
8866 {
|
|
8867 low_y_coord = frm_bottom;
|
|
8868 high_y_coord = FRAME_BOTTOM_BORDER_END (f);
|
|
8869 position = OVER_BORDER;
|
|
8870 }
|
|
8871 else if (y_coord < FRAME_PIXHEIGHT (f))
|
|
8872 {
|
|
8873 low_y_coord = FRAME_BOTTOM_BORDER_END (f);
|
|
8874 high_y_coord = FRAME_PIXHEIGHT (f);
|
|
8875 position = OVER_TOOLBAR;
|
|
8876 }
|
|
8877 else
|
|
8878 {
|
|
8879 low_y_coord = FRAME_PIXHEIGHT (f);
|
|
8880 high_y_coord = y_coord;
|
|
8881 position = OVER_OUTSIDE;
|
|
8882 }
|
|
8883 }
|
|
8884
|
|
8885 if (position != OVER_TOOLBAR && position != OVER_BORDER)
|
|
8886 {
|
|
8887 if (x_coord < frm_left)
|
|
8888 {
|
|
8889 if (x_coord >= FRAME_LEFT_BORDER_START (f))
|
|
8890 {
|
|
8891 low_x_coord = FRAME_LEFT_BORDER_START (f);
|
|
8892 high_x_coord = frm_left;
|
|
8893 position = OVER_BORDER;
|
|
8894 }
|
|
8895 else if (x_coord >= 0)
|
|
8896 {
|
|
8897 low_x_coord = 0;
|
|
8898 high_x_coord = FRAME_LEFT_BORDER_START (f);
|
|
8899 position = OVER_TOOLBAR;
|
|
8900 }
|
|
8901 else
|
|
8902 {
|
|
8903 low_x_coord = x_coord;
|
|
8904 high_x_coord = 0;
|
|
8905 position = OVER_OUTSIDE;
|
|
8906 }
|
|
8907 }
|
|
8908 else if (x_coord >= frm_right)
|
|
8909 {
|
|
8910 if (x_coord < FRAME_RIGHT_BORDER_END (f))
|
|
8911 {
|
|
8912 low_x_coord = frm_right;
|
|
8913 high_x_coord = FRAME_RIGHT_BORDER_END (f);
|
|
8914 position = OVER_BORDER;
|
|
8915 }
|
|
8916 else if (x_coord < FRAME_PIXWIDTH (f))
|
|
8917 {
|
|
8918 low_x_coord = FRAME_RIGHT_BORDER_END (f);
|
|
8919 high_x_coord = FRAME_PIXWIDTH (f);
|
|
8920 position = OVER_TOOLBAR;
|
|
8921 }
|
|
8922 else
|
|
8923 {
|
|
8924 low_x_coord = FRAME_PIXWIDTH (f);
|
|
8925 high_x_coord = x_coord;
|
|
8926 position = OVER_OUTSIDE;
|
|
8927 }
|
|
8928 }
|
|
8929 }
|
|
8930
|
|
8931 #ifdef HAVE_TOOLBARS
|
|
8932 if (position == OVER_TOOLBAR)
|
|
8933 {
|
|
8934 *obj1 = toolbar_button_at_pixpos (f, x_coord, y_coord);
|
|
8935 *obj2 = Qnil;
|
|
8936 *w = 0;
|
|
8937 UPDATE_CACHE_RETURN;
|
|
8938 }
|
|
8939 #endif /* HAVE_TOOLBARS */
|
|
8940
|
|
8941 /* We still have to return the window the pointer is next to and its
|
|
8942 relative y position even if it is outside the x boundary. */
|
|
8943 if (x_coord < frm_left)
|
|
8944 x_coord = frm_left;
|
|
8945 else if (x_coord > frm_right)
|
|
8946 x_coord = frm_right;
|
|
8947
|
|
8948 /* Same in reverse. */
|
|
8949 if (y_coord < frm_top)
|
|
8950 y_coord = frm_top;
|
|
8951 else if (y_coord > frm_bottom)
|
|
8952 y_coord = frm_bottom;
|
|
8953
|
|
8954 /* Find what window the given coordinates are actually in. */
|
|
8955 window = f->root_window;
|
|
8956 *w = find_window_by_pixel_pos (x_coord, y_coord, window);
|
|
8957
|
|
8958 /* If we didn't find a window, we're done. */
|
|
8959 if (!*w)
|
|
8960 {
|
|
8961 UPDATE_CACHE_RETURN;
|
|
8962 }
|
|
8963 else if (position != OVER_NOTHING)
|
|
8964 {
|
|
8965 *closest = 0;
|
|
8966 *modeline_closest = -1;
|
|
8967
|
|
8968 if (high_y_coord <= frm_top || high_y_coord >= frm_bottom)
|
|
8969 {
|
|
8970 *w = 0;
|
|
8971 UPDATE_CACHE_RETURN;
|
|
8972 }
|
|
8973 }
|
|
8974
|
|
8975 /* Check if the window is a minibuffer but isn't active. */
|
|
8976 if (MINI_WINDOW_P (*w) && !minibuf_level)
|
|
8977 {
|
|
8978 /* Must reset the window value since some callers will ignore
|
|
8979 the return value if it is set. */
|
|
8980 *w = 0;
|
|
8981 UPDATE_CACHE_RETURN;
|
|
8982 }
|
|
8983
|
|
8984 /* See if the point is over window vertical divider */
|
|
8985 if (window_needs_vertical_divider (*w))
|
|
8986 {
|
|
8987 int div_x_high = WINDOW_RIGHT (*w);
|
|
8988 int div_x_low = div_x_high - window_divider_width (*w);
|
|
8989 int div_y_high = WINDOW_BOTTOM (*w);
|
|
8990 int div_y_low = WINDOW_TOP (*w);
|
|
8991
|
|
8992 if (div_x_low < x_coord && x_coord <= div_x_high &&
|
|
8993 div_y_low < y_coord && y_coord <= div_y_high)
|
|
8994 {
|
|
8995 low_x_coord = div_x_low;
|
|
8996 high_x_coord = div_x_high;
|
|
8997 low_y_coord = div_y_low;
|
|
8998 high_y_coord = div_y_high;
|
|
8999 position = OVER_V_DIVIDER;
|
|
9000 UPDATE_CACHE_RETURN;
|
|
9001 }
|
|
9002 }
|
|
9003
|
|
9004 dla = window_display_lines (*w, CURRENT_DISP);
|
|
9005
|
|
9006 for (*row = 0; *row < Dynarr_length (dla); (*row)++)
|
|
9007 {
|
|
9008 int really_over_nothing = 0;
|
|
9009 struct display_line *dl = Dynarr_atp (dla, *row);
|
|
9010
|
|
9011 if ((int) (dl->ypos - dl->ascent) <= y_coord
|
|
9012 && y_coord <= (int) (dl->ypos + dl->descent))
|
|
9013 {
|
|
9014 int check_margin_glyphs = 0;
|
|
9015 struct display_block *db = get_display_block_from_line (dl, TEXT);
|
|
9016 struct rune *rb = 0;
|
|
9017
|
|
9018 if (x_coord < dl->bounds.left_white
|
|
9019 || x_coord >= dl->bounds.right_white)
|
|
9020 check_margin_glyphs = 1;
|
|
9021
|
|
9022 low_y_coord = dl->ypos - dl->ascent;
|
|
9023 high_y_coord = dl->ypos + dl->descent + 1;
|
|
9024
|
|
9025 if (position == OVER_BORDER
|
|
9026 || position == OVER_OUTSIDE
|
|
9027 || check_margin_glyphs)
|
|
9028 {
|
|
9029 int x_check, left_bound;
|
|
9030
|
|
9031 if (check_margin_glyphs)
|
|
9032 {
|
|
9033 x_check = x_coord;
|
|
9034 left_bound = dl->bounds.left_white;
|
|
9035 }
|
|
9036 else
|
|
9037 {
|
|
9038 x_check = high_x_coord;
|
|
9039 left_bound = frm_left;
|
|
9040 }
|
|
9041
|
|
9042 if (Dynarr_length (db->runes))
|
|
9043 {
|
|
9044 if (x_check <= left_bound)
|
|
9045 {
|
|
9046 if (dl->modeline)
|
826
|
9047 *modeline_closest = Dynarr_atp (db->runes, 0)->charpos;
|
428
|
9048 else
|
826
|
9049 *closest = Dynarr_atp (db->runes, 0)->charpos;
|
428
|
9050 }
|
|
9051 else
|
|
9052 {
|
|
9053 if (dl->modeline)
|
|
9054 *modeline_closest =
|
|
9055 Dynarr_atp (db->runes,
|
826
|
9056 Dynarr_length (db->runes) - 1)->charpos;
|
428
|
9057 else
|
|
9058 *closest =
|
|
9059 Dynarr_atp (db->runes,
|
826
|
9060 Dynarr_length (db->runes) - 1)->charpos;
|
428
|
9061 }
|
|
9062
|
|
9063 if (dl->modeline)
|
|
9064 *modeline_closest += dl->offset;
|
|
9065 else
|
|
9066 *closest += dl->offset;
|
|
9067 }
|
|
9068 else
|
|
9069 {
|
|
9070 /* #### What should be here. */
|
|
9071 if (dl->modeline)
|
|
9072 *modeline_closest = 0;
|
|
9073 else
|
|
9074 *closest = 0;
|
|
9075 }
|
|
9076
|
|
9077 if (check_margin_glyphs)
|
|
9078 {
|
|
9079 if (x_coord < dl->bounds.left_in
|
|
9080 || x_coord >= dl->bounds.right_in)
|
|
9081 {
|
|
9082 /* If we are over the outside margins then we
|
|
9083 know the loop over the text block isn't going
|
|
9084 to accomplish anything. So we go ahead and
|
|
9085 set what information we can right here and
|
|
9086 return. */
|
|
9087 (*row)--;
|
|
9088 *obj_y = y_coord - (dl->ypos - dl->ascent);
|
|
9089 get_position_object (dl, obj1, obj2, x_coord,
|
|
9090 &low_x_coord, &high_x_coord);
|
|
9091
|
|
9092 UPDATE_CACHE_RETURN;
|
|
9093 }
|
|
9094 }
|
|
9095 else
|
|
9096 UPDATE_CACHE_RETURN;
|
|
9097 }
|
|
9098
|
|
9099 for (*col = 0; *col <= Dynarr_length (db->runes); (*col)++)
|
|
9100 {
|
|
9101 int past_end = (*col == Dynarr_length (db->runes));
|
|
9102
|
|
9103 if (!past_end)
|
|
9104 rb = Dynarr_atp (db->runes, *col);
|
|
9105
|
|
9106 if (past_end ||
|
|
9107 (rb->xpos <= x_coord && x_coord < rb->xpos + rb->width))
|
|
9108 {
|
|
9109 if (past_end)
|
|
9110 {
|
|
9111 (*col)--;
|
|
9112 rb = Dynarr_atp (db->runes, *col);
|
|
9113 }
|
|
9114
|
826
|
9115 *charpos = rb->charpos + dl->offset;
|
428
|
9116 low_x_coord = rb->xpos;
|
|
9117 high_x_coord = rb->xpos + rb->width;
|
|
9118
|
|
9119 if (rb->type == RUNE_DGLYPH)
|
|
9120 {
|
|
9121 int elt = *col + 1;
|
|
9122
|
|
9123 /* Find the first character after the glyph. */
|
|
9124 while (elt < Dynarr_length (db->runes))
|
|
9125 {
|
|
9126 if (Dynarr_atp (db->runes, elt)->type != RUNE_DGLYPH)
|
|
9127 {
|
|
9128 if (dl->modeline)
|
|
9129 *modeline_closest =
|
826
|
9130 (Dynarr_atp (db->runes, elt)->charpos +
|
428
|
9131 dl->offset);
|
|
9132 else
|
|
9133 *closest =
|
826
|
9134 (Dynarr_atp (db->runes, elt)->charpos +
|
428
|
9135 dl->offset);
|
|
9136 break;
|
|
9137 }
|
|
9138
|
|
9139 elt++;
|
|
9140 }
|
|
9141
|
|
9142 /* In this case we failed to find a non-glyph
|
|
9143 character so we return the last position
|
|
9144 displayed on the line. */
|
|
9145 if (elt == Dynarr_length (db->runes))
|
|
9146 {
|
|
9147 if (dl->modeline)
|
826
|
9148 *modeline_closest = dl->end_charpos + dl->offset;
|
428
|
9149 else
|
826
|
9150 *closest = dl->end_charpos + dl->offset;
|
428
|
9151 really_over_nothing = 1;
|
|
9152 }
|
|
9153 }
|
|
9154 else
|
|
9155 {
|
|
9156 if (dl->modeline)
|
826
|
9157 *modeline_closest = rb->charpos + dl->offset;
|
428
|
9158 else
|
826
|
9159 *closest = rb->charpos + dl->offset;
|
428
|
9160 }
|
|
9161
|
|
9162 if (dl->modeline)
|
|
9163 {
|
|
9164 *row = window_displayed_height (*w);
|
|
9165
|
|
9166 if (position == OVER_NOTHING)
|
|
9167 position = OVER_MODELINE;
|
|
9168
|
|
9169 if (rb->type == RUNE_DGLYPH)
|
|
9170 {
|
|
9171 *obj1 = rb->object.dglyph.glyph;
|
|
9172 *obj2 = rb->object.dglyph.extent;
|
|
9173 }
|
|
9174 else if (rb->type == RUNE_CHAR)
|
|
9175 {
|
|
9176 *obj1 = Qnil;
|
|
9177 *obj2 = Qnil;
|
|
9178 }
|
|
9179 else
|
|
9180 {
|
|
9181 *obj1 = Qnil;
|
|
9182 *obj2 = Qnil;
|
|
9183 }
|
|
9184
|
|
9185 UPDATE_CACHE_RETURN;
|
|
9186 }
|
|
9187 else if (past_end
|
|
9188 || (rb->type == RUNE_CHAR
|
|
9189 && rb->object.chr.ch == '\n'))
|
|
9190 {
|
|
9191 (*row)--;
|
|
9192 /* At this point we may have glyphs in the right
|
|
9193 inside margin. */
|
|
9194 if (check_margin_glyphs)
|
|
9195 get_position_object (dl, obj1, obj2, x_coord,
|
|
9196 &low_x_coord, &high_x_coord);
|
|
9197 UPDATE_CACHE_RETURN;
|
|
9198 }
|
|
9199 else
|
|
9200 {
|
|
9201 (*row)--;
|
|
9202 if (rb->type == RUNE_DGLYPH)
|
|
9203 {
|
|
9204 *obj1 = rb->object.dglyph.glyph;
|
|
9205 *obj2 = rb->object.dglyph.extent;
|
|
9206 }
|
|
9207 else if (rb->type == RUNE_CHAR)
|
|
9208 {
|
|
9209 *obj1 = Qnil;
|
|
9210 *obj2 = Qnil;
|
|
9211 }
|
|
9212 else
|
|
9213 {
|
|
9214 *obj1 = Qnil;
|
|
9215 *obj2 = Qnil;
|
|
9216 }
|
|
9217
|
|
9218 *obj_x = x_coord - rb->xpos;
|
|
9219 *obj_y = y_coord - (dl->ypos - dl->ascent);
|
|
9220
|
|
9221 /* At this point we may have glyphs in the left
|
|
9222 inside margin. */
|
|
9223 if (check_margin_glyphs)
|
|
9224 get_position_object (dl, obj1, obj2, x_coord, 0, 0);
|
|
9225
|
|
9226 if (position == OVER_NOTHING && !really_over_nothing)
|
|
9227 position = OVER_TEXT;
|
|
9228
|
|
9229 UPDATE_CACHE_RETURN;
|
|
9230 }
|
|
9231 }
|
|
9232 }
|
|
9233 }
|
|
9234 }
|
|
9235
|
|
9236 *row = Dynarr_length (dla) - 1;
|
|
9237 if (FRAME_WIN_P (f))
|
|
9238 {
|
|
9239 int bot_elt = Dynarr_length (dla) - 1;
|
|
9240
|
|
9241 if (bot_elt >= 0)
|
|
9242 {
|
|
9243 struct display_line *dl = Dynarr_atp (dla, bot_elt);
|
|
9244 int adj_area = y_coord - (dl->ypos + dl->descent);
|
|
9245 Lisp_Object lwin;
|
|
9246 int defheight;
|
|
9247
|
793
|
9248 lwin = wrap_window (*w);
|
428
|
9249 default_face_height_and_width (lwin, 0, &defheight);
|
|
9250
|
|
9251 *row += (adj_area / defheight);
|
|
9252 }
|
|
9253 }
|
|
9254
|
|
9255 /* #### This should be checked out some more to determine what
|
|
9256 should really be going on. */
|
|
9257 if (!MARKERP ((*w)->start[CURRENT_DISP]))
|
|
9258 *closest = 0;
|
|
9259 else
|
442
|
9260 *closest = end_of_last_line_may_error (*w,
|
428
|
9261 marker_position ((*w)->start[CURRENT_DISP]));
|
|
9262 *col = 0;
|
|
9263 UPDATE_CACHE_RETURN;
|
|
9264 }
|
|
9265 #undef UPDATE_CACHE_RETURN
|
|
9266
|
|
9267
|
|
9268 /***************************************************************************/
|
|
9269 /* */
|
|
9270 /* Lisp functions */
|
|
9271 /* */
|
|
9272 /***************************************************************************/
|
|
9273
|
|
9274 DEFUN ("redisplay-echo-area", Fredisplay_echo_area, 0, 0, 0, /*
|
|
9275 Ensure that all minibuffers are correctly showing the echo area.
|
|
9276 */
|
|
9277 ())
|
|
9278 {
|
|
9279 Lisp_Object devcons, concons;
|
|
9280
|
1318
|
9281 if (in_display)
|
|
9282 return Qnil;
|
|
9283
|
428
|
9284 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
9285 {
|
|
9286 struct device *d = XDEVICE (XCAR (devcons));
|
|
9287 Lisp_Object frmcons;
|
|
9288
|
1279
|
9289 if (DEVICE_STREAM_P (d))
|
|
9290 continue;
|
|
9291
|
428
|
9292 DEVICE_FRAME_LOOP (frmcons, d)
|
|
9293 {
|
|
9294 struct frame *f = XFRAME (XCAR (frmcons));
|
853
|
9295 int depth;
|
428
|
9296
|
|
9297 if (FRAME_REPAINT_P (f) && FRAME_HAS_MINIBUF_P (f))
|
|
9298 {
|
|
9299 Lisp_Object window = FRAME_MINIBUF_WINDOW (f);
|
442
|
9300
|
|
9301 MAYBE_DEVMETH (d, frame_output_begin, (f));
|
|
9302
|
428
|
9303 /*
|
|
9304 * If the frame size has changed, there may be random
|
|
9305 * chud on the screen left from previous messages
|
|
9306 * because redisplay_frame hasn't been called yet.
|
|
9307 * Clear the screen to get rid of the potential mess.
|
|
9308 */
|
|
9309 if (f->echo_area_garbaged)
|
|
9310 {
|
442
|
9311 MAYBE_DEVMETH (d, clear_frame, (f));
|
428
|
9312 f->echo_area_garbaged = 0;
|
|
9313 }
|
853
|
9314 depth = enter_redisplay_critical_section ();
|
428
|
9315 redisplay_window (window, 0);
|
853
|
9316 exit_redisplay_critical_section (depth);
|
442
|
9317 MAYBE_DEVMETH (d, frame_output_end, (f));
|
428
|
9318 }
|
|
9319 }
|
|
9320 }
|
|
9321
|
|
9322 return Qnil;
|
|
9323 }
|
|
9324
|
|
9325 DEFUN ("redraw-frame", Fredraw_frame, 0, 2, 0, /*
|
|
9326 Clear frame FRAME and output again what is supposed to appear on it.
|
|
9327 FRAME defaults to the selected frame if omitted.
|
|
9328 Normally, redisplay is preempted as normal if input arrives. However,
|
|
9329 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
|
|
9330 input and is guaranteed to proceed to completion.
|
|
9331 */
|
|
9332 (frame, no_preempt))
|
|
9333 {
|
|
9334 struct frame *f = decode_frame (frame);
|
|
9335 int count = specpdl_depth ();
|
|
9336
|
|
9337 if (!NILP (no_preempt))
|
853
|
9338 internal_bind_int (&disable_preemption, 1 + disable_preemption);
|
428
|
9339
|
|
9340 f->clear = 1;
|
|
9341 redisplay_frame (f, 1);
|
|
9342
|
442
|
9343 /* See the comment in Fredisplay_frame. */
|
|
9344 RESET_CHANGED_SET_FLAGS;
|
|
9345
|
771
|
9346 return unbind_to (count);
|
428
|
9347 }
|
|
9348
|
|
9349 DEFUN ("redisplay-frame", Fredisplay_frame, 0, 2, 0, /*
|
|
9350 Ensure that FRAME's contents are correctly displayed.
|
|
9351 This differs from `redraw-frame' in that it only redraws what needs to
|
|
9352 be updated, as opposed to unconditionally clearing and redrawing
|
|
9353 the frame.
|
|
9354 FRAME defaults to the selected frame if omitted.
|
|
9355 Normally, redisplay is preempted as normal if input arrives. However,
|
|
9356 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
|
|
9357 input and is guaranteed to proceed to completion.
|
|
9358 */
|
|
9359 (frame, no_preempt))
|
|
9360 {
|
|
9361 struct frame *f = decode_frame (frame);
|
|
9362 int count = specpdl_depth ();
|
|
9363
|
|
9364 if (!NILP (no_preempt))
|
853
|
9365 internal_bind_int (&disable_preemption, 1 + disable_preemption);
|
428
|
9366
|
|
9367 redisplay_frame (f, 1);
|
|
9368
|
442
|
9369 /* If we don't reset the global redisplay flags here, subsequent
|
|
9370 changes to the display will not get registered by redisplay
|
|
9371 because it thinks it already has registered changes. If you
|
|
9372 really knew what you were doing you could confuse redisplay by
|
|
9373 calling Fredisplay_frame while updating another frame. We assume
|
|
9374 that if you know what you are doing you will not be that
|
|
9375 stupid. */
|
|
9376 RESET_CHANGED_SET_FLAGS;
|
|
9377
|
771
|
9378 return unbind_to (count);
|
428
|
9379 }
|
|
9380
|
|
9381 DEFUN ("redraw-device", Fredraw_device, 0, 2, 0, /*
|
|
9382 Clear device DEVICE and output again what is supposed to appear on it.
|
|
9383 DEVICE defaults to the selected device if omitted.
|
|
9384 Normally, redisplay is preempted as normal if input arrives. However,
|
|
9385 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
|
|
9386 input and is guaranteed to proceed to completion.
|
|
9387 */
|
|
9388 (device, no_preempt))
|
|
9389 {
|
|
9390 struct device *d = decode_device (device);
|
|
9391 Lisp_Object frmcons;
|
|
9392 int count = specpdl_depth ();
|
|
9393
|
|
9394 if (!NILP (no_preempt))
|
853
|
9395 internal_bind_int (&disable_preemption, 1 + disable_preemption);
|
428
|
9396
|
|
9397 DEVICE_FRAME_LOOP (frmcons, d)
|
|
9398 {
|
|
9399 XFRAME (XCAR (frmcons))->clear = 1;
|
|
9400 }
|
440
|
9401 redisplay_device (d, 0);
|
428
|
9402
|
442
|
9403 /* See the comment in Fredisplay_frame. */
|
|
9404 RESET_CHANGED_SET_FLAGS;
|
|
9405
|
771
|
9406 return unbind_to (count);
|
428
|
9407 }
|
|
9408
|
|
9409 DEFUN ("redisplay-device", Fredisplay_device, 0, 2, 0, /*
|
|
9410 Ensure that DEVICE's contents are correctly displayed.
|
|
9411 This differs from `redraw-device' in that it only redraws what needs to
|
|
9412 be updated, as opposed to unconditionally clearing and redrawing
|
|
9413 the device.
|
|
9414 DEVICE defaults to the selected device if omitted.
|
|
9415 Normally, redisplay is preempted as normal if input arrives. However,
|
|
9416 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
|
|
9417 input and is guaranteed to proceed to completion.
|
853
|
9418
|
|
9419 Note: If you simply want everything redisplayed, the current idiom is
|
|
9420 `(sit-for 0)'.
|
428
|
9421 */
|
|
9422 (device, no_preempt))
|
|
9423 {
|
|
9424 struct device *d = decode_device (device);
|
|
9425 int count = specpdl_depth ();
|
|
9426
|
|
9427 if (!NILP (no_preempt))
|
853
|
9428 internal_bind_int (&disable_preemption, 1 + disable_preemption);
|
428
|
9429
|
440
|
9430 redisplay_device (d, 0);
|
428
|
9431
|
442
|
9432 /* See the comment in Fredisplay_frame. */
|
|
9433 RESET_CHANGED_SET_FLAGS;
|
|
9434
|
771
|
9435 return unbind_to (count);
|
428
|
9436 }
|
|
9437
|
|
9438 /* Big lie. Big lie. This will force all modelines to be updated
|
|
9439 regardless if the all flag is set or not. It remains in existence
|
|
9440 solely for backwards compatibility. */
|
|
9441 DEFUN ("redraw-modeline", Fredraw_modeline, 0, 1, 0, /*
|
|
9442 Force the modeline of the current buffer to be redisplayed.
|
|
9443 With optional non-nil ALL, force redisplay of all modelines.
|
|
9444 */
|
2286
|
9445 (UNUSED (all)))
|
428
|
9446 {
|
|
9447 MARK_MODELINE_CHANGED;
|
|
9448 return Qnil;
|
|
9449 }
|
|
9450
|
|
9451 DEFUN ("force-cursor-redisplay", Fforce_cursor_redisplay, 0, 1, 0, /*
|
|
9452 Force an immediate update of the cursor on FRAME.
|
|
9453 FRAME defaults to the selected frame if omitted.
|
|
9454 */
|
|
9455 (frame))
|
|
9456 {
|
1279
|
9457 struct frame *f = decode_frame (frame);
|
|
9458
|
|
9459 if (!FRAME_STREAM_P (f))
|
|
9460 redisplay_redraw_cursor (f, 1);
|
428
|
9461 return Qnil;
|
|
9462 }
|
|
9463
|
|
9464
|
|
9465 /***************************************************************************/
|
|
9466 /* */
|
872
|
9467 /* Change flags */
|
428
|
9468 /* */
|
|
9469 /***************************************************************************/
|
|
9470
|
|
9471 static void
|
2286
|
9472 margin_width_changed_in_frame (Lisp_Object UNUSED (specifier),
|
|
9473 struct frame *UNUSED (f),
|
|
9474 Lisp_Object UNUSED (oldval))
|
428
|
9475 {
|
|
9476 /* Nothing to be done? */
|
|
9477 }
|
|
9478
|
|
9479 int
|
2286
|
9480 redisplay_variable_changed (Lisp_Object UNUSED (sym),
|
|
9481 Lisp_Object *UNUSED (val),
|
|
9482 Lisp_Object UNUSED (in_object),
|
|
9483 int UNUSED (flags))
|
428
|
9484 {
|
|
9485 /* #### clip_changed should really be renamed something like
|
|
9486 global_redisplay_change. */
|
|
9487 MARK_CLIP_CHANGED;
|
|
9488 return 0;
|
|
9489 }
|
|
9490
|
|
9491 /* This is called if the built-in glyphs have their properties
|
|
9492 changed. */
|
|
9493 void
|
2286
|
9494 redisplay_glyph_changed (Lisp_Object UNUSED (glyph),
|
|
9495 Lisp_Object UNUSED (property), Lisp_Object locale)
|
428
|
9496 {
|
|
9497 if (WINDOWP (locale))
|
|
9498 {
|
|
9499 MARK_FRAME_GLYPHS_CHANGED (XFRAME (WINDOW_FRAME (XWINDOW (locale))));
|
|
9500 }
|
|
9501 else if (FRAMEP (locale))
|
|
9502 {
|
|
9503 MARK_FRAME_GLYPHS_CHANGED (XFRAME (locale));
|
|
9504 }
|
|
9505 else if (DEVICEP (locale))
|
|
9506 {
|
|
9507 Lisp_Object frmcons;
|
|
9508 DEVICE_FRAME_LOOP (frmcons, XDEVICE (locale))
|
|
9509 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons)));
|
|
9510 }
|
|
9511 else if (CONSOLEP (locale))
|
|
9512 {
|
|
9513 Lisp_Object frmcons, devcons;
|
|
9514 CONSOLE_FRAME_LOOP_NO_BREAK (frmcons, devcons, XCONSOLE (locale))
|
|
9515 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons)));
|
|
9516 }
|
|
9517 else /* global or buffer */
|
|
9518 {
|
|
9519 Lisp_Object frmcons, devcons, concons;
|
|
9520 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
9521 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons)));
|
|
9522 }
|
|
9523 }
|
|
9524
|
|
9525 static void
|
2286
|
9526 text_cursor_visible_p_changed (Lisp_Object UNUSED (specifier),
|
|
9527 struct window *w, Lisp_Object UNUSED (oldval))
|
428
|
9528 {
|
|
9529 if (XFRAME (w->frame)->init_finished)
|
|
9530 Fforce_cursor_redisplay (w->frame);
|
|
9531 }
|
|
9532
|
872
|
9533 void
|
|
9534 mark_buffers_changed (void)
|
|
9535 {
|
|
9536 MARK_TYPE_CHANGED (buffers);
|
|
9537 }
|
|
9538
|
|
9539 void
|
|
9540 mark_clip_changed (void)
|
|
9541 {
|
|
9542 MARK_TYPE_CHANGED (clip);
|
|
9543 }
|
|
9544
|
|
9545 void
|
|
9546 mark_extents_changed (void)
|
|
9547 {
|
|
9548 MARK_TYPE_CHANGED (extents);
|
|
9549 }
|
|
9550
|
|
9551 void
|
|
9552 mark_icon_changed (void)
|
|
9553 {
|
|
9554 MARK_TYPE_CHANGED (icon);
|
|
9555 }
|
|
9556
|
|
9557 void
|
|
9558 mark_menubar_changed (void)
|
|
9559 {
|
|
9560 MARK_TYPE_CHANGED (menubar);
|
|
9561 }
|
|
9562
|
|
9563 void
|
|
9564 mark_modeline_changed (void)
|
|
9565 {
|
|
9566 MARK_TYPE_CHANGED (modeline);
|
|
9567 }
|
|
9568
|
|
9569 void
|
|
9570 mark_point_changed (void)
|
|
9571 {
|
|
9572 MARK_TYPE_CHANGED (point);
|
|
9573 }
|
|
9574
|
|
9575 void
|
|
9576 mark_toolbar_changed (void)
|
|
9577 {
|
|
9578 MARK_TYPE_CHANGED (toolbar);
|
|
9579 }
|
|
9580
|
|
9581 void
|
|
9582 mark_gutter_changed (void)
|
|
9583 {
|
|
9584 MARK_TYPE_CHANGED (gutter);
|
|
9585 }
|
|
9586
|
|
9587 void
|
|
9588 mark_glyphs_changed (void)
|
|
9589 {
|
|
9590 MARK_TYPE_CHANGED (glyphs);
|
|
9591 }
|
|
9592
|
|
9593 void
|
|
9594 mark_subwindows_changed (void)
|
|
9595 {
|
|
9596 MARK_TYPE_CHANGED (subwindows);
|
|
9597 }
|
|
9598
|
|
9599 void
|
|
9600 mark_subwindows_state_changed (void)
|
|
9601 {
|
|
9602 MARK_TYPE_CHANGED (subwindows_state);
|
|
9603 }
|
|
9604
|
428
|
9605 #ifdef MEMORY_USAGE_STATS
|
|
9606
|
|
9607
|
|
9608 /***************************************************************************/
|
|
9609 /* */
|
|
9610 /* memory usage computation */
|
|
9611 /* */
|
|
9612 /***************************************************************************/
|
|
9613
|
|
9614 static int
|
|
9615 compute_rune_dynarr_usage (rune_dynarr *dyn, struct overhead_stats *ovstats)
|
|
9616 {
|
|
9617 return dyn ? Dynarr_memory_usage (dyn, ovstats) : 0;
|
|
9618 }
|
|
9619
|
|
9620 static int
|
|
9621 compute_display_block_dynarr_usage (display_block_dynarr *dyn,
|
|
9622 struct overhead_stats *ovstats)
|
|
9623 {
|
|
9624 int total, i;
|
|
9625
|
|
9626 if (!dyn)
|
|
9627 return 0;
|
|
9628
|
|
9629 total = Dynarr_memory_usage (dyn, ovstats);
|
|
9630 for (i = 0; i < Dynarr_largest (dyn); i++)
|
|
9631 total += compute_rune_dynarr_usage (Dynarr_at (dyn, i).runes, ovstats);
|
|
9632
|
|
9633 return total;
|
|
9634 }
|
|
9635
|
|
9636 static int
|
|
9637 compute_glyph_block_dynarr_usage (glyph_block_dynarr *dyn,
|
|
9638 struct overhead_stats *ovstats)
|
|
9639 {
|
|
9640 return dyn ? Dynarr_memory_usage (dyn, ovstats) : 0;
|
|
9641 }
|
|
9642
|
|
9643 int
|
|
9644 compute_display_line_dynarr_usage (display_line_dynarr *dyn,
|
|
9645 struct overhead_stats *ovstats)
|
|
9646 {
|
|
9647 int total, i;
|
|
9648
|
|
9649 if (!dyn)
|
|
9650 return 0;
|
|
9651
|
|
9652 total = Dynarr_memory_usage (dyn, ovstats);
|
|
9653 for (i = 0; i < Dynarr_largest (dyn); i++)
|
|
9654 {
|
|
9655 struct display_line *dl = &Dynarr_at (dyn, i);
|
|
9656 total += compute_display_block_dynarr_usage(dl->display_blocks, ovstats);
|
|
9657 total += compute_glyph_block_dynarr_usage (dl->left_glyphs, ovstats);
|
|
9658 total += compute_glyph_block_dynarr_usage (dl->right_glyphs, ovstats);
|
|
9659 }
|
|
9660
|
|
9661 return total;
|
|
9662 }
|
|
9663
|
|
9664 int
|
|
9665 compute_line_start_cache_dynarr_usage (line_start_cache_dynarr *dyn,
|
|
9666 struct overhead_stats *ovstats)
|
|
9667 {
|
|
9668 return dyn ? Dynarr_memory_usage (dyn, ovstats) : 0;
|
|
9669 }
|
|
9670
|
|
9671 #endif /* MEMORY_USAGE_STATS */
|
|
9672
|
1204
|
9673 #ifdef ERROR_CHECK_DISPLAY
|
|
9674
|
800
|
9675 static int
|
2286
|
9676 sledgehammer_check_redisplay_structs_1 (struct window *w,
|
|
9677 void *UNUSED (closure))
|
800
|
9678 {
|
|
9679 int i, j;
|
|
9680 display_line_dynarr *dl;
|
|
9681
|
|
9682 dl = window_display_lines (w, CURRENT_DISP);
|
|
9683
|
|
9684 for (i = 0; i < Dynarr_largest (dl); i++)
|
|
9685 for (j = i + 1; j < Dynarr_largest (dl); j++)
|
|
9686 assert (Dynarr_atp (dl, i)->display_blocks !=
|
|
9687 Dynarr_atp (dl, j)->display_blocks);
|
|
9688
|
|
9689 dl = window_display_lines (w, DESIRED_DISP);
|
|
9690
|
|
9691 for (i = 0; i < Dynarr_largest (dl); i++)
|
|
9692 for (j = i + 1; j < Dynarr_largest (dl); j++)
|
|
9693 assert (Dynarr_atp (dl, i)->display_blocks !=
|
|
9694 Dynarr_atp (dl, j)->display_blocks);
|
|
9695
|
|
9696 return 0;
|
|
9697 }
|
|
9698
|
|
9699 static void
|
|
9700 sledgehammer_check_redisplay_structs (void)
|
|
9701 {
|
|
9702 map_windows (0, sledgehammer_check_redisplay_structs_1, NULL);
|
|
9703 }
|
|
9704
|
1204
|
9705 #endif /* ERROR_CHECK_DISPLAY */
|
|
9706
|
428
|
9707
|
|
9708 /***************************************************************************/
|
|
9709 /* */
|
|
9710 /* initialization */
|
|
9711 /* */
|
|
9712 /***************************************************************************/
|
|
9713
|
|
9714 void
|
|
9715 init_redisplay (void)
|
|
9716 {
|
|
9717 disable_preemption = 0;
|
|
9718 preemption_count = 0;
|
|
9719
|
|
9720 #ifndef PDUMP
|
|
9721 if (!initialized)
|
|
9722 #endif
|
|
9723 {
|
440
|
9724 if (!cmotion_display_lines)
|
|
9725 cmotion_display_lines = Dynarr_new (display_line);
|
867
|
9726 if (!mode_spec_ibyte_string)
|
|
9727 mode_spec_ibyte_string = Dynarr_new (Ibyte);
|
440
|
9728 if (!formatted_string_extent_dynarr)
|
|
9729 formatted_string_extent_dynarr = Dynarr_new (EXTENT);
|
|
9730 if (!formatted_string_extent_start_dynarr)
|
|
9731 formatted_string_extent_start_dynarr = Dynarr_new (Bytecount);
|
|
9732 if (!formatted_string_extent_end_dynarr)
|
|
9733 formatted_string_extent_end_dynarr = Dynarr_new (Bytecount);
|
|
9734 if (!internal_cache)
|
|
9735 internal_cache = Dynarr_new (line_start_cache);
|
428
|
9736 }
|
|
9737
|
|
9738 /* window system is nil when in -batch mode */
|
|
9739 if (!initialized || noninteractive)
|
|
9740 return;
|
|
9741
|
|
9742 /* If the user wants to use a window system, we shouldn't bother
|
|
9743 initializing the terminal. This is especially important when the
|
|
9744 terminal is so dumb that emacs gives up before and doesn't bother
|
|
9745 using the window system.
|
|
9746
|
|
9747 If the DISPLAY environment variable is set, try to use X, and die
|
|
9748 with an error message if that doesn't work. */
|
|
9749
|
|
9750 #ifdef HAVE_X_WINDOWS
|
|
9751 if (!strcmp (display_use, "x"))
|
|
9752 {
|
|
9753 /* Some stuff checks this way early. */
|
|
9754 Vwindow_system = Qx;
|
|
9755 Vinitial_window_system = Qx;
|
|
9756 return;
|
|
9757 }
|
|
9758 #endif /* HAVE_X_WINDOWS */
|
|
9759
|
462
|
9760 #ifdef HAVE_GTK
|
|
9761 if (!strcmp (display_use, "gtk"))
|
|
9762 {
|
|
9763 Vwindow_system = Qgtk;
|
|
9764 Vinitial_window_system = Qgtk;
|
|
9765 return;
|
|
9766 }
|
|
9767 #endif
|
|
9768
|
428
|
9769 #ifdef HAVE_MS_WINDOWS
|
|
9770 if (!strcmp (display_use, "mswindows"))
|
|
9771 {
|
|
9772 /* Some stuff checks this way early. */
|
|
9773 Vwindow_system = Qmswindows;
|
|
9774 Vinitial_window_system = Qmswindows;
|
|
9775 return;
|
|
9776 }
|
|
9777 #endif /* HAVE_MS_WINDOWS */
|
|
9778
|
|
9779 #ifdef HAVE_TTY
|
|
9780 /* If no window system has been specified, try to use the terminal. */
|
|
9781 if (!isatty (0))
|
|
9782 {
|
|
9783 stderr_out ("XEmacs: standard input is not a tty\n");
|
|
9784 exit (1);
|
|
9785 }
|
|
9786
|
|
9787 /* Look at the TERM variable */
|
771
|
9788 if (!egetenv ("TERM"))
|
428
|
9789 {
|
|
9790 stderr_out ("Please set the environment variable TERM; see tset(1).\n");
|
|
9791 exit (1);
|
|
9792 }
|
|
9793
|
|
9794 Vinitial_window_system = Qtty;
|
|
9795 return;
|
|
9796 #else /* not HAVE_TTY */
|
|
9797 /* No DISPLAY specified, and no TTY support. */
|
|
9798 stderr_out ("XEmacs: Cannot open display.\n\
|
|
9799 Please set the environmental variable DISPLAY to an appropriate value.\n");
|
|
9800 exit (1);
|
|
9801 #endif
|
|
9802 /* Unreached. */
|
|
9803 }
|
|
9804
|
|
9805 void
|
|
9806 syms_of_redisplay (void)
|
|
9807 {
|
563
|
9808 DEFSYMBOL (Qcursor_in_echo_area);
|
|
9809 DEFSYMBOL (Qdisplay_warning_buffer);
|
|
9810 DEFSYMBOL (Qbar_cursor);
|
|
9811 DEFSYMBOL (Qtop_bottom);
|
|
9812 DEFSYMBOL (Qbuffer_list_changed_hook);
|
428
|
9813
|
|
9814 DEFSUBR (Fredisplay_echo_area);
|
|
9815 DEFSUBR (Fredraw_frame);
|
|
9816 DEFSUBR (Fredisplay_frame);
|
|
9817 DEFSUBR (Fredraw_device);
|
|
9818 DEFSUBR (Fredisplay_device);
|
|
9819 DEFSUBR (Fredraw_modeline);
|
|
9820 DEFSUBR (Fforce_cursor_redisplay);
|
|
9821 }
|
|
9822
|
|
9823 void
|
|
9824 vars_of_redisplay (void)
|
|
9825 {
|
1292
|
9826 QSin_redisplay = build_msg_string ("(in redisplay)");
|
|
9827 staticpro (&QSin_redisplay);
|
428
|
9828
|
1318
|
9829 Vpost_redisplay_actions = Qnil;
|
|
9830 staticpro (&Vpost_redisplay_actions);
|
|
9831
|
428
|
9832 #if 0
|
|
9833 staticpro (&last_arrow_position);
|
|
9834 staticpro (&last_arrow_string);
|
|
9835 last_arrow_position = Qnil;
|
|
9836 last_arrow_string = Qnil;
|
|
9837 #endif /* 0 */
|
|
9838
|
|
9839 /* #### Probably temporary */
|
|
9840 DEFVAR_INT ("redisplay-cache-adjustment", &cache_adjustment /*
|
|
9841 \(Temporary) Setting this will impact the performance of the internal
|
|
9842 line start cache.
|
|
9843 */ );
|
|
9844 cache_adjustment = 2;
|
|
9845
|
1268
|
9846 DEFVAR_INT ("maximum-preempts", &max_preempts /*
|
|
9847 Maximum number of times redisplay can be preempted by user input.
|
|
9848 */ );
|
|
9849 max_preempts = INIT_MAX_PREEMPTS;
|
|
9850
|
428
|
9851 DEFVAR_INT_MAGIC ("pixel-vertical-clip-threshold", &vertical_clip /*
|
|
9852 Minimum pixel height for clipped bottom display line.
|
|
9853 A clipped line shorter than this won't be displayed.
|
|
9854 */ ,
|
|
9855 redisplay_variable_changed);
|
|
9856 vertical_clip = 5;
|
|
9857
|
|
9858 DEFVAR_INT_MAGIC ("pixel-horizontal-clip-threshold", &horizontal_clip /*
|
|
9859 Minimum visible area for clipped glyphs at right boundary.
|
|
9860 Clipped glyphs shorter than this won't be displayed.
|
|
9861 Only pixmap glyph instances are currently allowed to be clipped.
|
|
9862 */ ,
|
|
9863 redisplay_variable_changed);
|
|
9864 horizontal_clip = 5;
|
|
9865
|
|
9866 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string /*
|
|
9867 String displayed by modeline-format's "%m" specification.
|
|
9868 */ );
|
|
9869 Vglobal_mode_string = Qnil;
|
|
9870
|
|
9871 DEFVAR_LISP_MAGIC ("overlay-arrow-position", &Voverlay_arrow_position /*
|
|
9872 Marker for where to display an arrow on top of the buffer text.
|
|
9873 This must be the beginning of a line in order to work.
|
|
9874 See also `overlay-arrow-string'.
|
|
9875 */ ,
|
|
9876 redisplay_variable_changed);
|
|
9877 Voverlay_arrow_position = Qnil;
|
|
9878
|
|
9879 DEFVAR_LISP_MAGIC ("overlay-arrow-string", &Voverlay_arrow_string /*
|
442
|
9880 String or glyph to display as an arrow. See also `overlay-arrow-position'.
|
444
|
9881 \(Note that despite the name of this variable, it can be set to a glyph as
|
442
|
9882 well as a string.)
|
428
|
9883 */ ,
|
|
9884 redisplay_variable_changed);
|
|
9885 Voverlay_arrow_string = Qnil;
|
|
9886
|
|
9887 DEFVAR_INT ("scroll-step", &scroll_step /*
|
|
9888 *The number of lines to try scrolling a window by when point moves out.
|
|
9889 If that fails to bring point back on frame, point is centered instead.
|
|
9890 If this is zero, point is always centered after it moves off screen.
|
|
9891 */ );
|
|
9892 scroll_step = 0;
|
|
9893
|
|
9894 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively /*
|
|
9895 *Scroll up to this many lines, to bring point back on screen.
|
|
9896 */ );
|
|
9897 scroll_conservatively = 0;
|
|
9898
|
|
9899 DEFVAR_BOOL_MAGIC ("truncate-partial-width-windows",
|
|
9900 &truncate_partial_width_windows /*
|
|
9901 *Non-nil means truncate lines in all windows less than full frame wide.
|
|
9902 */ ,
|
|
9903 redisplay_variable_changed);
|
|
9904 truncate_partial_width_windows = 1;
|
|
9905
|
442
|
9906 DEFVAR_LISP ("visible-bell", &Vvisible_bell /*
|
|
9907 *Non-nil substitutes a visual signal for the audible bell.
|
|
9908
|
|
9909 Default behavior is to flash the whole screen. On some platforms,
|
|
9910 special effects are available using the following values:
|
|
9911
|
3025
|
9912 `display' Flash the whole screen (ie, the default behavior).
|
|
9913 `top-bottom' Flash only the top and bottom lines of the selected frame.
|
442
|
9914
|
|
9915 When effects are unavailable on a platform, the visual bell is the
|
|
9916 default, whole screen. (Currently only X supports any special effects.)
|
428
|
9917 */ );
|
442
|
9918 Vvisible_bell = Qnil;
|
428
|
9919
|
|
9920 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter /*
|
|
9921 *Non-nil means no need to redraw entire frame after suspending.
|
|
9922 A non-nil value is useful if the terminal can automatically preserve
|
|
9923 Emacs's frame display when you reenter Emacs.
|
|
9924 It is up to you to set this variable if your terminal can do that.
|
|
9925 */ );
|
|
9926 no_redraw_on_reenter = 0;
|
|
9927
|
|
9928 DEFVAR_LISP ("window-system", &Vwindow_system /*
|
|
9929 A symbol naming the window-system under which Emacs is running,
|
|
9930 such as `x', or nil if emacs is running on an ordinary terminal.
|
|
9931
|
|
9932 Do not use this variable, except for GNU Emacs compatibility, as it
|
|
9933 gives wrong values in a multi-device environment. Use `console-type'
|
|
9934 instead.
|
|
9935 */ );
|
|
9936 Vwindow_system = Qnil;
|
|
9937
|
|
9938 /* #### Temporary shit until window-system is eliminated. */
|
|
9939 DEFVAR_CONST_LISP ("initial-window-system", &Vinitial_window_system /*
|
|
9940 DON'T TOUCH
|
|
9941 */ );
|
|
9942 Vinitial_window_system = Qnil;
|
|
9943
|
|
9944 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area /*
|
|
9945 Non-nil means put cursor in minibuffer, at end of any message there.
|
|
9946 */ );
|
|
9947 cursor_in_echo_area = 0;
|
|
9948
|
|
9949 /* #### Shouldn't this be generalized as follows:
|
|
9950
|
|
9951 if nil, use block cursor.
|
|
9952 if a number, use a bar cursor of that width.
|
|
9953 Otherwise, use a 1-pixel bar cursor.
|
|
9954
|
|
9955 #### Or better yet, this variable should be trashed entirely
|
|
9956 (use a Lisp-magic variable to maintain compatibility)
|
|
9957 and a specifier `cursor-shape' added, which allows a block
|
|
9958 cursor, a bar cursor, a flashing block or bar cursor,
|
|
9959 maybe a caret cursor, etc. */
|
|
9960
|
|
9961 DEFVAR_LISP ("bar-cursor", &Vbar_cursor /*
|
448
|
9962 *Use vertical bar cursor if non-nil. If t width is 1 pixel, otherwise 2.
|
428
|
9963 */ );
|
|
9964 Vbar_cursor = Qnil;
|
|
9965
|
442
|
9966 DEFVAR_LISP ("buffer-list-changed-hook", &Vbuffer_list_changed_hook /*
|
|
9967 Function or functions to call when a frame's buffer list has changed.
|
|
9968 This is called during redisplay, before redisplaying each frame.
|
|
9969 Functions on this hook are called with one argument, the frame.
|
|
9970 */ );
|
|
9971 Vbuffer_list_changed_hook = Qnil;
|
|
9972
|
428
|
9973 DEFVAR_INT ("display-warning-tick", &display_warning_tick /*
|
|
9974 Bump this to tell the C code to call `display-warning-buffer'
|
|
9975 at next redisplay. You should not normally change this; the function
|
|
9976 `display-warning' automatically does this at appropriate times.
|
|
9977 */ );
|
|
9978 display_warning_tick = 0;
|
|
9979
|
|
9980 DEFVAR_BOOL ("inhibit-warning-display", &inhibit_warning_display /*
|
|
9981 Non-nil means inhibit display of warning messages.
|
|
9982 You should *bind* this, not set it. Any pending warning messages
|
|
9983 will be displayed when the binding no longer applies.
|
|
9984 */ );
|
|
9985 /* reset to 0 by startup.el after the splash screen has displayed.
|
|
9986 This way, the warnings don't obliterate the splash screen. */
|
|
9987 inhibit_warning_display = 1;
|
|
9988
|
|
9989 DEFVAR_BOOL ("column-number-start-at-one", &column_number_start_at_one /*
|
|
9990 *Non-nil means column display number starts at 1.
|
|
9991 */ );
|
|
9992 column_number_start_at_one = 0;
|
|
9993 }
|
|
9994
|
|
9995 void
|
|
9996 specifier_vars_of_redisplay (void)
|
|
9997 {
|
|
9998 DEFVAR_SPECIFIER ("left-margin-width", &Vleft_margin_width /*
|
|
9999 *Width of left margin.
|
|
10000 This is a specifier; use `set-specifier' to change it.
|
|
10001 */ );
|
|
10002 Vleft_margin_width = Fmake_specifier (Qnatnum);
|
|
10003 set_specifier_fallback (Vleft_margin_width, list1 (Fcons (Qnil, Qzero)));
|
|
10004 set_specifier_caching (Vleft_margin_width,
|
438
|
10005 offsetof (struct window, left_margin_width),
|
428
|
10006 some_window_value_changed,
|
438
|
10007 offsetof (struct frame, left_margin_width),
|
444
|
10008 margin_width_changed_in_frame, 0);
|
428
|
10009
|
|
10010 DEFVAR_SPECIFIER ("right-margin-width", &Vright_margin_width /*
|
|
10011 *Width of right margin.
|
|
10012 This is a specifier; use `set-specifier' to change it.
|
|
10013 */ );
|
|
10014 Vright_margin_width = Fmake_specifier (Qnatnum);
|
|
10015 set_specifier_fallback (Vright_margin_width, list1 (Fcons (Qnil, Qzero)));
|
|
10016 set_specifier_caching (Vright_margin_width,
|
438
|
10017 offsetof (struct window, right_margin_width),
|
428
|
10018 some_window_value_changed,
|
438
|
10019 offsetof (struct frame, right_margin_width),
|
444
|
10020 margin_width_changed_in_frame, 0);
|
428
|
10021
|
|
10022 DEFVAR_SPECIFIER ("minimum-line-ascent", &Vminimum_line_ascent /*
|
|
10023 *Minimum ascent height of lines.
|
|
10024 This is a specifier; use `set-specifier' to change it.
|
|
10025 */ );
|
|
10026 Vminimum_line_ascent = Fmake_specifier (Qnatnum);
|
|
10027 set_specifier_fallback (Vminimum_line_ascent, list1 (Fcons (Qnil, Qzero)));
|
|
10028 set_specifier_caching (Vminimum_line_ascent,
|
438
|
10029 offsetof (struct window, minimum_line_ascent),
|
428
|
10030 some_window_value_changed,
|
444
|
10031 0, 0, 0);
|
428
|
10032
|
|
10033 DEFVAR_SPECIFIER ("minimum-line-descent", &Vminimum_line_descent /*
|
|
10034 *Minimum descent height of lines.
|
|
10035 This is a specifier; use `set-specifier' to change it.
|
|
10036 */ );
|
|
10037 Vminimum_line_descent = Fmake_specifier (Qnatnum);
|
|
10038 set_specifier_fallback (Vminimum_line_descent, list1 (Fcons (Qnil, Qzero)));
|
|
10039 set_specifier_caching (Vminimum_line_descent,
|
438
|
10040 offsetof (struct window, minimum_line_descent),
|
428
|
10041 some_window_value_changed,
|
444
|
10042 0, 0, 0);
|
428
|
10043
|
|
10044 DEFVAR_SPECIFIER ("use-left-overflow", &Vuse_left_overflow /*
|
|
10045 *Non-nil means use the left outside margin as extra whitespace when
|
3025
|
10046 displaying `whitespace' or `inside-margin' glyphs.
|
428
|
10047 This is a specifier; use `set-specifier' to change it.
|
|
10048 */ );
|
|
10049 Vuse_left_overflow = Fmake_specifier (Qboolean);
|
|
10050 set_specifier_fallback (Vuse_left_overflow, list1 (Fcons (Qnil, Qnil)));
|
|
10051 set_specifier_caching (Vuse_left_overflow,
|
438
|
10052 offsetof (struct window, use_left_overflow),
|
428
|
10053 some_window_value_changed,
|
444
|
10054 0, 0, 0);
|
428
|
10055
|
|
10056 DEFVAR_SPECIFIER ("use-right-overflow", &Vuse_right_overflow /*
|
|
10057 *Non-nil means use the right outside margin as extra whitespace when
|
3025
|
10058 displaying `whitespace' or `inside-margin' glyphs.
|
428
|
10059 This is a specifier; use `set-specifier' to change it.
|
|
10060 */ );
|
|
10061 Vuse_right_overflow = Fmake_specifier (Qboolean);
|
|
10062 set_specifier_fallback (Vuse_right_overflow, list1 (Fcons (Qnil, Qnil)));
|
|
10063 set_specifier_caching (Vuse_right_overflow,
|
438
|
10064 offsetof (struct window, use_right_overflow),
|
428
|
10065 some_window_value_changed,
|
444
|
10066 0, 0, 0);
|
428
|
10067
|
|
10068 DEFVAR_SPECIFIER ("text-cursor-visible-p", &Vtext_cursor_visible_p /*
|
|
10069 *Non-nil means the text cursor is visible (this is usually the case).
|
|
10070 This is a specifier; use `set-specifier' to change it.
|
|
10071 */ );
|
|
10072 Vtext_cursor_visible_p = Fmake_specifier (Qboolean);
|
|
10073 set_specifier_fallback (Vtext_cursor_visible_p, list1 (Fcons (Qnil, Qt)));
|
|
10074 set_specifier_caching (Vtext_cursor_visible_p,
|
438
|
10075 offsetof (struct window, text_cursor_visible_p),
|
428
|
10076 text_cursor_visible_p_changed,
|
444
|
10077 0, 0, 0);
|
428
|
10078
|
|
10079 }
|