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);
|
3094
|
4180
|
|
4181 if (dash_pixsize == 0)
|
|
4182 num_to_add = 0;
|
|
4183 else {
|
|
4184 num_to_add = (max_pixsize - cur_pixsize) / dash_pixsize;
|
|
4185 num_to_add++;
|
|
4186 }
|
428
|
4187 }
|
|
4188
|
|
4189 while (num_to_add--)
|
|
4190 pos = add_string_to_fstring_db_runes
|
867
|
4191 (data, (const Ibyte *) "-", pos, pos, max_pos);
|
428
|
4192 }
|
2552
|
4193 else if (*this_str != 0)
|
428
|
4194 {
|
2552
|
4195 Ichar ch = itext_ichar (this_str);
|
867
|
4196 Ibyte *str;
|
438
|
4197 Charcount size;
|
|
4198
|
428
|
4199 decode_mode_spec (w, ch, type);
|
|
4200
|
867
|
4201 str = Dynarr_atp (mode_spec_ibyte_string, 0);
|
438
|
4202 size = bytecount_to_charcount
|
|
4203 /* Skip the null character added by `decode_mode_spec' */
|
867
|
4204 (str, Dynarr_length (mode_spec_ibyte_string)) - 1;
|
438
|
4205
|
|
4206 if (size <= *offset)
|
|
4207 *offset -= size;
|
|
4208 else
|
|
4209 {
|
867
|
4210 const Ibyte *tmp_str = itext_n_addr (str, *offset);
|
438
|
4211
|
440
|
4212 /* #### NOTE: I don't understand why a tmp_max is not
|
438
|
4213 computed and used here as in the plain string case
|
|
4214 above. -- dv */
|
|
4215 pos = add_string_to_fstring_db_runes (data, tmp_str,
|
|
4216 pos, pos,
|
|
4217 max_pos);
|
|
4218 *offset = 0;
|
|
4219 }
|
428
|
4220 }
|
|
4221
|
2552
|
4222 /* NOT this_str++. There could be any sort of character at
|
428
|
4223 the current position. */
|
2552
|
4224 INC_IBYTEPTR (this_str);
|
428
|
4225 }
|
|
4226
|
|
4227 if (max_pixsize > 0)
|
|
4228 {
|
|
4229 int cur_pixsize;
|
|
4230 SET_CURRENT_MODE_CHARS_PIXSIZE;
|
|
4231
|
|
4232 if (cur_pixsize >= max_pixsize)
|
|
4233 break;
|
|
4234 }
|
|
4235 }
|
|
4236 }
|
|
4237 else if (SYMBOLP (elt))
|
|
4238 {
|
|
4239 /* A symbol: process the value of the symbol recursively
|
|
4240 as if it appeared here directly. */
|
|
4241 Lisp_Object tem = symbol_value_in_buffer (elt, w->buffer);
|
|
4242
|
|
4243 if (!UNBOUNDP (tem))
|
|
4244 {
|
438
|
4245 /* If value is a string, output that string literally:
|
428
|
4246 don't check for % within it. */
|
|
4247 if (STRINGP (tem))
|
|
4248 {
|
867
|
4249 Ibyte *str = XSTRING_DATA (tem);
|
826
|
4250 Charcount size = string_char_length (tem);
|
438
|
4251
|
|
4252 if (size <= *offset)
|
|
4253 *offset -= size;
|
|
4254 else
|
|
4255 {
|
867
|
4256 const Ibyte *tmp_str = itext_n_addr (str, *offset);
|
438
|
4257
|
440
|
4258 /* #### NOTE: I don't understand why a tmp_max is not
|
438
|
4259 computed and used here as in the plain string case
|
|
4260 above. -- dv */
|
|
4261 pos = add_string_to_fstring_db_runes (data, tmp_str, pos,
|
|
4262 min_pos, max_pos);
|
|
4263 *offset = 0;
|
|
4264 }
|
428
|
4265 }
|
|
4266 /* Give up right away for nil or t. */
|
|
4267 else if (!EQ (tem, elt))
|
|
4268 {
|
|
4269 elt = tem;
|
|
4270 goto tail_recurse;
|
|
4271 }
|
|
4272 }
|
|
4273 }
|
|
4274 else if (GENERIC_SPECIFIERP (elt))
|
|
4275 {
|
|
4276 Lisp_Object window, tem;
|
793
|
4277 window = wrap_window (w);
|
428
|
4278 tem = specifier_instance_no_quit (elt, Qunbound, window,
|
793
|
4279 ERROR_ME_DEBUG_WARN, 0, Qzero);
|
428
|
4280 if (!UNBOUNDP (tem))
|
|
4281 {
|
|
4282 elt = tem;
|
|
4283 goto tail_recurse;
|
|
4284 }
|
|
4285 }
|
|
4286 else if (CONSP (elt))
|
|
4287 {
|
|
4288 /* A cons cell: four distinct cases.
|
438
|
4289 * - If first element is a string or a cons, process all the elements
|
|
4290 * and effectively concatenate them.
|
|
4291 * - If first element is a negative number, truncate displaying cdr to
|
|
4292 * at most that many characters. If positive, pad (with spaces)
|
|
4293 * to at least that many characters.
|
771
|
4294 * - If first element is another symbol or a boolean specifier, process
|
|
4295 * the cadr or caddr recursively according to whether the symbol's
|
|
4296 * value or specifier's instance is non-nil or nil.
|
|
4297 * - If first element is , process the cadr or caddr
|
|
4298 * recursively according to whether the instance of the specifier in
|
|
4299 * the modeline's window is non-nil or nil.
|
442
|
4300 * - If first element is an extent, process the cdr recursively
|
|
4301 * and handle the extent's face.
|
428
|
4302 */
|
438
|
4303
|
428
|
4304 Lisp_Object car, tem;
|
|
4305
|
|
4306 car = XCAR (elt);
|
771
|
4307 if (SYMBOLP (car) || BOOLEAN_SPECIFIERP (car))
|
438
|
4308 {
|
|
4309 elt = XCDR (elt);
|
|
4310 if (!CONSP (elt))
|
|
4311 goto invalid;
|
|
4312
|
771
|
4313 if (SYMBOLP (car))
|
|
4314 tem = symbol_value_in_buffer (car, w->buffer);
|
|
4315 else
|
|
4316 tem = specifier_instance_no_quit (car, Qunbound, wrap_window (w),
|
793
|
4317 ERROR_ME_DEBUG_WARN, 0, Qzero);
|
438
|
4318 /* elt is now the cdr, and we know it is a cons cell.
|
|
4319 Use its car if CAR has a non-nil value. */
|
771
|
4320 if (!UNBOUNDP (tem) && !NILP (tem))
|
438
|
4321 {
|
771
|
4322 elt = XCAR (elt);
|
|
4323 goto tail_recurse;
|
438
|
4324 }
|
771
|
4325 /* Symbol's value or specifier's instance is nil or unbound
|
438
|
4326 * Get the cddr of the original list
|
|
4327 * and if possible find the caddr and use that.
|
|
4328 */
|
|
4329 elt = XCDR (elt);
|
|
4330 if (NILP (elt))
|
|
4331 ;
|
|
4332 else if (!CONSP (elt))
|
|
4333 goto invalid;
|
|
4334 else
|
|
4335 {
|
|
4336 elt = XCAR (elt);
|
|
4337 goto tail_recurse;
|
|
4338 }
|
|
4339 }
|
428
|
4340 else if (INTP (car))
|
|
4341 {
|
|
4342 Charcount lim = XINT (car);
|
|
4343
|
|
4344 elt = XCDR (elt);
|
|
4345
|
|
4346 if (lim < 0)
|
|
4347 {
|
|
4348 /* Negative int means reduce maximum width.
|
|
4349 * DO NOT change MIN_PIXPOS here!
|
|
4350 * (20 -10 . foo) should truncate foo to 10 col
|
|
4351 * and then pad to 20.
|
|
4352 */
|
|
4353 if (max_pos == -1)
|
|
4354 max_pos = pos - lim;
|
|
4355 else
|
|
4356 max_pos = min (max_pos, pos - lim);
|
|
4357 }
|
|
4358 else if (lim > 0)
|
|
4359 {
|
|
4360 /* Padding specified. Don't let it be more than
|
|
4361 * current maximum.
|
|
4362 */
|
|
4363 lim += pos;
|
|
4364 if (max_pos != -1 && lim > max_pos)
|
|
4365 lim = max_pos;
|
|
4366 /* If that's more padding than already wanted, queue it.
|
|
4367 * But don't reduce padding already specified even if
|
|
4368 * that is beyond the current truncation point.
|
|
4369 */
|
|
4370 if (lim > min_pos)
|
|
4371 min_pos = lim;
|
|
4372 }
|
|
4373 goto tail_recurse;
|
|
4374 }
|
|
4375 else if (STRINGP (car) || CONSP (car))
|
|
4376 {
|
|
4377 int limit = 50;
|
438
|
4378
|
428
|
4379 /* LIMIT is to protect against circular lists. */
|
|
4380 while (CONSP (elt) && --limit > 0
|
|
4381 && (pos < max_pos || max_pos == -1))
|
|
4382 {
|
|
4383 pos = generate_fstring_runes (w, data, pos, pos, max_pos,
|
438
|
4384 XCAR (elt), depth, max_pixsize,
|
|
4385 findex, type, offset, cur_ext);
|
428
|
4386 elt = XCDR (elt);
|
|
4387 }
|
|
4388 }
|
|
4389 else if (EXTENTP (car))
|
|
4390 {
|
|
4391 struct extent *ext = XEXTENT (car);
|
|
4392
|
|
4393 if (EXTENT_LIVE_P (ext))
|
|
4394 {
|
|
4395 face_index old_findex = data->findex;
|
|
4396 Lisp_Object face;
|
|
4397 Lisp_Object font_inst;
|
|
4398 face_index new_findex;
|
|
4399 Bytecount start = data->bytepos;
|
|
4400
|
|
4401 face = extent_face (ext);
|
|
4402 if (FACEP (face))
|
|
4403 {
|
|
4404 /* #### needs to merge faces, sigh */
|
|
4405 /* #### needs to handle list of faces */
|
|
4406 new_findex = get_builtin_face_cache_index (w, face);
|
|
4407 /* !!#### not right; needs to compute the max height of
|
|
4408 all the charsets */
|
|
4409 font_inst = WINDOW_FACE_CACHEL_FONT (w, new_findex,
|
|
4410 Vcharset_ascii);
|
|
4411
|
|
4412 data->dl->ascent = max (data->dl->ascent,
|
|
4413 XFONT_INSTANCE (font_inst)->ascent);
|
|
4414 data->dl->descent = max (data->dl->descent,
|
|
4415 XFONT_INSTANCE (font_inst)->
|
|
4416 descent);
|
|
4417 }
|
|
4418 else
|
|
4419 new_findex = old_findex;
|
|
4420
|
|
4421 data->findex = new_findex;
|
|
4422 pos = generate_fstring_runes (w, data, pos, pos, max_pos,
|
|
4423 XCDR (elt), depth - 1,
|
438
|
4424 max_pixsize, new_findex, type,
|
|
4425 offset, car);
|
428
|
4426 data->findex = old_findex;
|
|
4427 Dynarr_add (formatted_string_extent_dynarr, ext);
|
|
4428 Dynarr_add (formatted_string_extent_start_dynarr, start);
|
|
4429 Dynarr_add (formatted_string_extent_end_dynarr, data->bytepos);
|
|
4430 }
|
|
4431 }
|
|
4432 }
|
|
4433 else if (GLYPHP (elt))
|
|
4434 {
|
438
|
4435 /* Glyphs are considered as one character with respect to the modeline
|
|
4436 horizontal scrolling facility. -- dv */
|
|
4437 if (*offset > 0)
|
|
4438 *offset -= 1;
|
|
4439 else
|
|
4440 pos = add_glyph_to_fstring_db_runes (data, elt, pos, pos, max_pos,
|
|
4441 cur_ext);
|
428
|
4442 }
|
|
4443 else
|
|
4444 {
|
|
4445 invalid:
|
438
|
4446 {
|
|
4447 char *str = GETTEXT ("*invalid*");
|
|
4448 Charcount size = (Charcount) strlen (str); /* is this ok ?? -- dv */
|
|
4449
|
|
4450 if (size <= *offset)
|
|
4451 *offset -= size;
|
|
4452 else
|
|
4453 {
|
867
|
4454 const Ibyte *tmp_str =
|
|
4455 itext_n_addr ((const Ibyte *) str, *offset);
|
438
|
4456
|
440
|
4457 /* #### NOTE: I don't understand why a tmp_max is not computed and
|
438
|
4458 used here as in the plain string case above. -- dv */
|
|
4459 pos = add_string_to_fstring_db_runes (data, tmp_str, pos,
|
|
4460 min_pos, max_pos);
|
|
4461 *offset = 0;
|
|
4462 }
|
|
4463 }
|
428
|
4464 }
|
|
4465
|
|
4466 if (min_pos > pos)
|
|
4467 {
|
867
|
4468 add_string_to_fstring_db_runes (data, (const Ibyte *) "", pos,
|
438
|
4469 min_pos, -1);
|
428
|
4470 }
|
|
4471
|
|
4472 return pos;
|
|
4473 }
|
|
4474
|
|
4475 /* Update just the modeline. Assumes the desired display structs. If
|
|
4476 they do not have a modeline block, it does nothing. */
|
|
4477 static void
|
|
4478 regenerate_modeline (struct window *w)
|
|
4479 {
|
|
4480 display_line_dynarr *dla = window_display_lines (w, DESIRED_DISP);
|
|
4481
|
|
4482 if (!Dynarr_length (dla) || !Dynarr_atp (dla, 0)->modeline)
|
|
4483 return;
|
|
4484 else
|
|
4485 {
|
|
4486 generate_modeline (w, Dynarr_atp (dla, 0), DESIRED_DISP);
|
|
4487 redisplay_update_line (w, 0, 0, 0);
|
|
4488 }
|
|
4489 }
|
|
4490
|
|
4491 /* Make sure that modeline display line is present in the given
|
|
4492 display structs if the window has a modeline and update that
|
|
4493 line. Returns true if a modeline was needed. */
|
|
4494 static int
|
|
4495 ensure_modeline_generated (struct window *w, int type)
|
|
4496 {
|
|
4497 int need_modeline;
|
|
4498
|
|
4499 /* minibuffer windows don't have modelines */
|
|
4500 if (MINI_WINDOW_P (w))
|
|
4501 need_modeline = 0;
|
|
4502 /* windows which haven't had it turned off do */
|
|
4503 else if (WINDOW_HAS_MODELINE_P (w))
|
|
4504 need_modeline = 1;
|
|
4505 /* windows which have it turned off don't have a divider if there is
|
|
4506 a horizontal scrollbar */
|
|
4507 else if (window_scrollbar_height (w))
|
|
4508 need_modeline = 0;
|
|
4509 /* and in this case there is none */
|
|
4510 else
|
|
4511 need_modeline = 1;
|
|
4512
|
|
4513 if (need_modeline)
|
|
4514 {
|
|
4515 display_line_dynarr *dla;
|
|
4516
|
|
4517 dla = window_display_lines (w, type);
|
|
4518
|
|
4519 /* We don't care if there is a display line which is not
|
|
4520 currently a modeline because it is definitely going to become
|
|
4521 one if we have gotten to this point. */
|
|
4522 if (Dynarr_length (dla) == 0)
|
|
4523 {
|
|
4524 if (Dynarr_largest (dla) > 0)
|
800
|
4525 Dynarr_increment (dla);
|
428
|
4526 else
|
|
4527 {
|
|
4528 struct display_line modeline;
|
|
4529 xzero (modeline);
|
|
4530 Dynarr_add (dla, modeline);
|
|
4531 }
|
|
4532 }
|
|
4533
|
|
4534 /* If we're adding a new place marker go ahead and generate the
|
|
4535 modeline so that it is available for use by
|
|
4536 window_modeline_height. */
|
|
4537 generate_modeline (w, Dynarr_atp (dla, 0), type);
|
|
4538 }
|
|
4539
|
|
4540 return need_modeline;
|
|
4541 }
|
|
4542
|
|
4543 /* #### Kludge or not a kludge. I tend towards the former. */
|
|
4544 int
|
|
4545 real_current_modeline_height (struct window *w)
|
|
4546 {
|
|
4547 Fset_marker (w->start[CMOTION_DISP], w->start[CURRENT_DISP], w->buffer);
|
|
4548 Fset_marker (w->pointm[CMOTION_DISP], w->pointm[CURRENT_DISP], w->buffer);
|
|
4549
|
|
4550 if (ensure_modeline_generated (w, CMOTION_DISP))
|
|
4551 {
|
|
4552 display_line_dynarr *dla = window_display_lines (w, CMOTION_DISP);
|
|
4553
|
|
4554 if (Dynarr_length (dla))
|
|
4555 {
|
|
4556 if (Dynarr_atp (dla, 0)->modeline)
|
|
4557 return (Dynarr_atp (dla, 0)->ascent +
|
|
4558 Dynarr_atp (dla, 0)->descent);
|
|
4559 }
|
|
4560 }
|
|
4561 return 0;
|
|
4562 }
|
|
4563
|
|
4564
|
|
4565 /***************************************************************************/
|
819
|
4566 /* */
|
826
|
4567 /* displayable string routines */
|
819
|
4568 /* */
|
428
|
4569 /***************************************************************************/
|
|
4570
|
|
4571 /* Given a position for a string in a window, ensure that the given
|
|
4572 display line DL accurately represents the text on a line starting
|
|
4573 at the given position.
|
|
4574
|
|
4575 Yes, this is duplicating the code of create_text_block, but it
|
|
4576 looked just too hard to change create_text_block to handle strings
|
|
4577 *and* buffers. We already make a distinction between the two
|
|
4578 elsewhere in the code so I think unifying them would require a
|
|
4579 complete MULE rewrite. Besides, the other distinction is that these
|
|
4580 functions cover text that the user *cannot edit* so we can remove
|
|
4581 everything to do with cursors, minibuffers etc. Eventually the
|
|
4582 modeline routines should be modified to use this code as it copes
|
|
4583 with many more types of display situation. */
|
|
4584
|
665
|
4585 static Charbpos
|
428
|
4586 create_string_text_block (struct window *w, Lisp_Object disp_string,
|
|
4587 struct display_line *dl,
|
826
|
4588 Charcount start_pos,
|
428
|
4589 prop_block_dynarr **prop,
|
|
4590 face_index default_face)
|
|
4591 {
|
|
4592 struct frame *f = XFRAME (w->frame);
|
|
4593 /* Note that a lot of the buffer controlled stuff has been left in
|
|
4594 because you might well want to make use of it (selective display
|
|
4595 etc), its just the buffer text that we do not use. However, it
|
|
4596 seems to be possible for buffer to be nil sometimes so protect
|
|
4597 against this case. */
|
|
4598 struct buffer *b = BUFFERP (w->buffer) ? XBUFFER (w->buffer) : 0;
|
|
4599 struct device *d = XDEVICE (f->device);
|
|
4600
|
|
4601 /* we're working with these a lot so precalculate them */
|
|
4602 Bytecount slen = XSTRING_LENGTH (disp_string);
|
826
|
4603 Bytecount byte_string_zv = slen;
|
|
4604 Bytecount byte_start_pos = string_index_char_to_byte (disp_string, start_pos);
|
428
|
4605
|
|
4606 pos_data data;
|
|
4607
|
|
4608 int truncate_win = b ? window_truncation_on (w) : 0;
|
|
4609
|
442
|
4610 /* We're going to ditch selective display for static text, it's an
|
|
4611 FSF thing and invisible extents are the way to go here.
|
|
4612 Implementing it also relies on a number of buffer-specific
|
428
|
4613 functions that we don't have the luxury of being able to use
|
|
4614 here. */
|
|
4615
|
|
4616 /* The variable ctl-arrow allows the user to specify what characters
|
|
4617 can actually be displayed and which octal should be used for.
|
|
4618 #### This variable should probably have some rethought done to
|
|
4619 it.
|
|
4620
|
|
4621 #### It would also be really nice if you could specify that
|
|
4622 the characters come out in hex instead of in octal. Mule
|
|
4623 does that by adding a ctl-hexa variable similar to ctl-arrow,
|
|
4624 but that's bogus -- we need a more general solution. I
|
|
4625 think you need to extend the concept of display tables
|
|
4626 into a more general conversion mechanism. Ideally you
|
|
4627 could specify a Lisp function that converts characters,
|
|
4628 but this violates the Second Golden Rule and besides would
|
|
4629 make things way way way way slow.
|
|
4630
|
|
4631 So instead, we extend the display-table concept, which was
|
|
4632 historically limited to 256-byte vectors, to one of the
|
|
4633 following:
|
|
4634
|
|
4635 a) A 256-entry vector, for backward compatibility;
|
|
4636 b) char-table, mapping characters to values;
|
|
4637 c) range-table, mapping ranges of characters to values;
|
|
4638 d) a list of the above.
|
|
4639
|
|
4640 The (d) option allows you to specify multiple display tables
|
|
4641 instead of just one. Each display table can specify conversions
|
|
4642 for some characters and leave others unchanged. The way the
|
|
4643 character gets displayed is determined by the first display table
|
|
4644 with a binding for that character. This way, you could call a
|
|
4645 function `enable-hex-display' that adds a hex display-table to
|
|
4646 the list of display tables for the current buffer.
|
|
4647
|
|
4648 #### ...not yet implemented... Also, we extend the concept of
|
|
4649 "mapping" to include a printf-like spec. Thus you can make all
|
|
4650 extended characters show up as hex with a display table like
|
|
4651 this:
|
|
4652
|
|
4653 #s(range-table data ((256 524288) (format "%x")))
|
|
4654
|
|
4655 Since more than one display table is possible, you have
|
|
4656 great flexibility in mapping ranges of characters. */
|
867
|
4657 Ichar printable_min = b ? (CHAR_OR_CHAR_INTP (b->ctl_arrow)
|
428
|
4658 ? XCHAR_OR_CHAR_INT (b->ctl_arrow)
|
|
4659 : ((EQ (b->ctl_arrow, Qt) || EQ (b->ctl_arrow, Qnil))
|
|
4660 ? 255 : 160)) : 255;
|
|
4661
|
|
4662 Lisp_Object face_dt, window_dt;
|
|
4663
|
|
4664 /* The text display block for this display line. */
|
|
4665 struct display_block *db = get_display_block_from_line (dl, TEXT);
|
|
4666
|
|
4667 /* The first time through the main loop we need to force the glyph
|
|
4668 data to be updated. */
|
|
4669 int initial = 1;
|
|
4670
|
|
4671 /* Apparently the new extent_fragment_update returns an end position
|
|
4672 equal to the position passed in if there are no more runs to be
|
|
4673 displayed. */
|
|
4674 int no_more_frags = 0;
|
|
4675
|
|
4676 dl->used_prop_data = 0;
|
|
4677 dl->num_chars = 0;
|
442
|
4678 dl->line_continuation = 0;
|
428
|
4679
|
|
4680 /* set up faces to use for clearing areas, used by
|
|
4681 output_display_line */
|
|
4682 dl->default_findex = default_face;
|
|
4683 if (default_face)
|
|
4684 {
|
|
4685 dl->left_margin_findex = default_face;
|
|
4686 dl->right_margin_findex = default_face;
|
|
4687 }
|
|
4688 else
|
|
4689 {
|
434
|
4690 dl->left_margin_findex =
|
428
|
4691 get_builtin_face_cache_index (w, Vleft_margin_face);
|
434
|
4692 dl->right_margin_findex =
|
428
|
4693 get_builtin_face_cache_index (w, Vright_margin_face);
|
|
4694 }
|
|
4695
|
|
4696 xzero (data);
|
|
4697 data.ef = extent_fragment_new (disp_string, f);
|
|
4698
|
|
4699 /* These values are used by all of the rune addition routines. We add
|
|
4700 them to this structure for ease of passing. */
|
|
4701 data.d = d;
|
793
|
4702 data.window = wrap_window (w);
|
428
|
4703 data.db = db;
|
|
4704 data.dl = dl;
|
|
4705
|
826
|
4706 data.byte_charpos = byte_start_pos;
|
428
|
4707 data.pixpos = dl->bounds.left_in;
|
|
4708 data.last_charset = Qunbound;
|
|
4709 data.last_findex = default_face;
|
|
4710 data.result_str = Qnil;
|
|
4711 data.string = disp_string;
|
|
4712
|
|
4713 /* Set the right boundary adjusting it to take into account any end
|
|
4714 glyph. Save the width of the end glyph for later use. */
|
|
4715 data.max_pixpos = dl->bounds.right_in;
|
819
|
4716 data.max_pixpos -= data.end_glyph_width;
|
428
|
4717
|
|
4718 data.cursor_type = NO_CURSOR;
|
|
4719 data.cursor_x = -1;
|
|
4720
|
|
4721 data.start_col = 0;
|
|
4722 /* I don't think we want this, string areas should not scroll with
|
434
|
4723 the window
|
428
|
4724 data.start_col = w->hscroll;
|
826
|
4725 data.byte_start_col_enabled = (w->hscroll ? byte_start_pos : 0);
|
428
|
4726 */
|
826
|
4727 data.byte_start_col_enabled = 0;
|
428
|
4728 data.hscroll_glyph_width_adjust = 0;
|
|
4729
|
|
4730 /* We regenerate the line from the very beginning. */
|
|
4731 Dynarr_reset (db->runes);
|
|
4732
|
|
4733 /* Why is this less than or equal and not just less than? If the
|
|
4734 starting position is already equal to the maximum we can't add
|
|
4735 anything else, right? Wrong. We might still have a newline to
|
|
4736 add. A newline can use the room allocated for an end glyph since
|
|
4737 if we add it we know we aren't going to be adding any end
|
|
4738 glyph. */
|
|
4739
|
|
4740 /* #### Chuck -- I think this condition should be while (1).
|
|
4741 Otherwise if (e.g.) there is one begin-glyph and one end-glyph
|
|
4742 and the begin-glyph ends exactly at the end of the window, the
|
|
4743 end-glyph and text might not be displayed. while (1) ensures
|
|
4744 that the loop terminates only when either (a) there is
|
|
4745 propagation data or (b) the end-of-line or end-of-buffer is hit.
|
|
4746
|
|
4747 #### Also I think you need to ensure that the operation
|
|
4748 "add begin glyphs; add end glyphs; add text" is atomic and
|
|
4749 can't get interrupted in the middle. If you run off the end
|
|
4750 of the line during that operation, then you keep accumulating
|
|
4751 propagation data until you're done. Otherwise, if the (e.g.)
|
|
4752 there's a begin glyph at a particular position and attempting
|
|
4753 to display that glyph results in window-end being hit and
|
|
4754 propagation data being generated, then the character at that
|
|
4755 position won't be displayed.
|
|
4756
|
|
4757 #### See also the comment after the end of this loop, below.
|
|
4758 */
|
|
4759 while (data.pixpos <= data.max_pixpos)
|
|
4760 {
|
|
4761 /* #### This check probably should not be necessary. */
|
826
|
4762 if (data.byte_charpos > byte_string_zv)
|
428
|
4763 {
|
|
4764 /* #### urk! More of this lossage! */
|
826
|
4765 data.byte_charpos--;
|
428
|
4766 goto done;
|
|
4767 }
|
|
4768
|
|
4769 /* Check for face changes. */
|
826
|
4770 if (initial || (!no_more_frags && data.byte_charpos == data.ef->end))
|
428
|
4771 {
|
819
|
4772 Lisp_Object last_glyph = Qnil;
|
|
4773 /* Deal with clipped glyphs that we have already displayed. */
|
|
4774 if (*prop && Dynarr_atp (*prop, 0)->type == PROP_GLYPH)
|
|
4775 {
|
|
4776 last_glyph = Dynarr_atp (*prop, 0)->data.p_glyph.glyph;
|
|
4777 Dynarr_free (*prop);
|
|
4778 *prop = 0;
|
|
4779 }
|
428
|
4780 /* Now compute the face and begin/end-glyph information. */
|
|
4781 data.findex =
|
793
|
4782 /* Remember that the extent-fragment routines deal in
|
826
|
4783 Bytexpos's. */
|
|
4784 extent_fragment_update (w, data.ef, data.byte_charpos, last_glyph);
|
428
|
4785 /* This is somewhat cheesy but the alternative is to
|
|
4786 propagate default_face into extent_fragment_update. */
|
|
4787 if (data.findex == DEFAULT_INDEX)
|
|
4788 data.findex = default_face;
|
|
4789
|
|
4790 get_display_tables (w, data.findex, &face_dt, &window_dt);
|
|
4791
|
826
|
4792 if (data.byte_charpos == data.ef->end)
|
428
|
4793 no_more_frags = 1;
|
|
4794 }
|
|
4795 initial = 0;
|
|
4796
|
|
4797 /* Determine what is next to be displayed. We first handle any
|
665
|
4798 glyphs returned by glyphs_at_charbpos. If there are no glyphs to
|
428
|
4799 display then we determine what to do based on the character at the
|
|
4800 current buffer position. */
|
|
4801
|
|
4802 /* If the current position is covered by an invisible extent, do
|
|
4803 nothing (except maybe add some ellipses).
|
|
4804
|
|
4805 #### The behavior of begin and end-glyphs at the edge of an
|
|
4806 invisible extent should be investigated further. This is
|
|
4807 fairly low priority though. */
|
|
4808 if (data.ef->invisible)
|
|
4809 {
|
|
4810 /* #### Chuck, perhaps you could look at this code? I don't
|
|
4811 really know what I'm doing. */
|
|
4812 if (*prop)
|
|
4813 {
|
|
4814 Dynarr_free (*prop);
|
|
4815 *prop = 0;
|
|
4816 }
|
|
4817
|
|
4818 /* The extent fragment code only sets this when we should
|
|
4819 really display the ellipses. It makes sure the ellipses
|
|
4820 don't get displayed more than once in a row. */
|
|
4821 if (data.ef->invisible_ellipses)
|
|
4822 {
|
|
4823 struct glyph_block gb;
|
|
4824
|
|
4825 data.ef->invisible_ellipses_already_displayed = 1;
|
|
4826 data.ef->invisible_ellipses = 0;
|
|
4827 gb.extent = Qnil;
|
|
4828 gb.glyph = Vinvisible_text_glyph;
|
|
4829 *prop = add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0,
|
|
4830 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX));
|
|
4831 /* Perhaps they shouldn't propagate if the very next thing
|
|
4832 is to display a newline (for compatibility with
|
|
4833 selective-display-ellipses)? Maybe that's too
|
|
4834 abstruse. */
|
|
4835 if (*prop)
|
|
4836 goto done;
|
|
4837 }
|
|
4838
|
638
|
4839 /* #### What if we're dealing with a display table? */
|
428
|
4840 if (data.start_col)
|
|
4841 data.start_col--;
|
|
4842
|
826
|
4843 if (data.byte_charpos == byte_string_zv)
|
428
|
4844 goto done;
|
|
4845 else
|
826
|
4846 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos);
|
428
|
4847 }
|
|
4848
|
|
4849 /* If there is propagation data, then it represents the current
|
|
4850 buffer position being displayed. Add them and advance the
|
|
4851 position counter. This might also add the minibuffer
|
|
4852 prompt. */
|
|
4853 else if (*prop)
|
|
4854 {
|
|
4855 dl->used_prop_data = 1;
|
|
4856 *prop = add_propagation_runes (prop, &data);
|
|
4857
|
|
4858 if (*prop)
|
|
4859 goto done; /* gee, a really narrow window */
|
826
|
4860 else if (data.byte_charpos == byte_string_zv)
|
428
|
4861 goto done;
|
826
|
4862 else if (data.byte_charpos < 0)
|
428
|
4863 /* #### urk urk urk! Aborts are not very fun! Fix this please! */
|
826
|
4864 data.byte_charpos = 0;
|
428
|
4865 else
|
826
|
4866 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos);
|
428
|
4867 }
|
|
4868
|
|
4869 /* If there are end glyphs, add them to the line. These are
|
|
4870 the end glyphs for the previous run of text. We add them
|
|
4871 here rather than doing them at the end of handling the
|
|
4872 previous run so that glyphs at the beginning and end of
|
|
4873 a line are handled correctly. */
|
|
4874 else if (Dynarr_length (data.ef->end_glyphs) > 0)
|
|
4875 {
|
867
|
4876 data.ch = string_ichar (disp_string, data.byte_charpos);
|
428
|
4877 *prop = add_glyph_runes (&data, END_GLYPHS);
|
819
|
4878
|
|
4879 if (*prop) {
|
428
|
4880 goto done;
|
819
|
4881 }
|
428
|
4882 }
|
|
4883
|
|
4884 /* If there are begin glyphs, add them to the line. */
|
|
4885 else if (Dynarr_length (data.ef->begin_glyphs) > 0)
|
|
4886 {
|
867
|
4887 data.ch = string_ichar (disp_string, data.byte_charpos);
|
428
|
4888 *prop = add_glyph_runes (&data, BEGIN_GLYPHS);
|
819
|
4889
|
|
4890 if (*prop) {
|
428
|
4891 goto done;
|
819
|
4892 }
|
428
|
4893 }
|
|
4894
|
|
4895 /* If at end-of-buffer, we've already processed begin and
|
|
4896 end-glyphs at this point and there's no text to process,
|
|
4897 so we're done. */
|
826
|
4898 else if (data.byte_charpos == byte_string_zv)
|
428
|
4899 goto done;
|
|
4900
|
|
4901 else
|
|
4902 {
|
|
4903 Lisp_Object entry = Qnil;
|
|
4904 /* Get the character at the current buffer position. */
|
867
|
4905 data.ch = string_ichar (disp_string, data.byte_charpos);
|
428
|
4906 if (!NILP (face_dt) || !NILP (window_dt))
|
|
4907 entry = display_table_entry (data.ch, face_dt, window_dt);
|
|
4908
|
|
4909 /* If there is a display table entry for it, hand it off to
|
|
4910 add_disp_table_entry_runes and let it worry about it. */
|
|
4911 if (!NILP (entry) && !EQ (entry, make_char (data.ch)))
|
|
4912 {
|
|
4913 *prop = add_disp_table_entry_runes (&data, entry);
|
|
4914
|
|
4915 if (*prop)
|
|
4916 goto done;
|
|
4917 }
|
|
4918
|
|
4919 /* Check if we have hit a newline character. If so, add a marker
|
|
4920 to the line and end this loop. */
|
|
4921 else if (data.ch == '\n')
|
|
4922 {
|
|
4923 /* We aren't going to be adding an end glyph so give its
|
|
4924 space back in order to make sure that the cursor can
|
|
4925 fit. */
|
819
|
4926 data.max_pixpos += data.end_glyph_width;
|
428
|
4927 goto done;
|
|
4928 }
|
|
4929
|
|
4930 /* If the current character is considered to be printable, then
|
|
4931 just add it. */
|
|
4932 else if (data.ch >= printable_min)
|
|
4933 {
|
867
|
4934 *prop = add_ichar_rune (&data);
|
428
|
4935 if (*prop)
|
|
4936 goto done;
|
|
4937 }
|
|
4938
|
|
4939 /* If the current character is a tab, determine the next tab
|
|
4940 starting position and add a blank rune which extends from the
|
|
4941 current pixel position to that starting position. */
|
|
4942 else if (data.ch == '\t')
|
|
4943 {
|
|
4944 int tab_start_pixpos = data.pixpos;
|
|
4945 int next_tab_start;
|
|
4946 int char_tab_width;
|
|
4947 int prop_width = 0;
|
|
4948
|
|
4949 if (data.start_col > 1)
|
|
4950 tab_start_pixpos -= (space_width (w) * (data.start_col - 1));
|
|
4951
|
|
4952 next_tab_start =
|
|
4953 next_tab_position (w, tab_start_pixpos,
|
|
4954 dl->bounds.left_in +
|
|
4955 data.hscroll_glyph_width_adjust);
|
|
4956 if (next_tab_start > data.max_pixpos)
|
|
4957 {
|
|
4958 prop_width = next_tab_start - data.max_pixpos;
|
|
4959 next_tab_start = data.max_pixpos;
|
|
4960 }
|
|
4961 data.blank_width = next_tab_start - data.pixpos;
|
|
4962 char_tab_width =
|
|
4963 (next_tab_start - tab_start_pixpos) / space_width (w);
|
|
4964
|
|
4965 *prop = add_blank_rune (&data, w, char_tab_width);
|
|
4966
|
|
4967 /* add_blank_rune is only supposed to be called with
|
819
|
4968 sizes guaranteed to fit in the available space. */
|
428
|
4969 assert (!(*prop));
|
|
4970
|
|
4971 if (prop_width)
|
|
4972 {
|
|
4973 struct prop_block pb;
|
|
4974 *prop = Dynarr_new (prop_block);
|
|
4975
|
|
4976 pb.type = PROP_BLANK;
|
|
4977 pb.data.p_blank.width = prop_width;
|
|
4978 pb.data.p_blank.findex = data.findex;
|
|
4979 Dynarr_add (*prop, pb);
|
|
4980
|
|
4981 goto done;
|
|
4982 }
|
|
4983 }
|
|
4984
|
|
4985 /* If character is a control character, pass it off to
|
|
4986 add_control_char_runes.
|
|
4987
|
|
4988 The is_*() routines have undefined results on
|
|
4989 arguments outside of the range [-1, 255]. (This
|
|
4990 often bites people who carelessly use `char' instead
|
|
4991 of `unsigned char'.)
|
|
4992 */
|
867
|
4993 else if (data.ch < 0x100 && iscntrl ((Ibyte) data.ch))
|
428
|
4994 {
|
|
4995 *prop = add_control_char_runes (&data, b);
|
|
4996
|
|
4997 if (*prop)
|
|
4998 goto done;
|
|
4999 }
|
|
5000
|
|
5001 /* If the character is above the ASCII range and we have not
|
|
5002 already handled it, then print it as an octal number. */
|
|
5003 else if (data.ch >= 0200)
|
|
5004 {
|
|
5005 *prop = add_octal_runes (&data);
|
|
5006
|
|
5007 if (*prop)
|
|
5008 goto done;
|
|
5009 }
|
|
5010
|
|
5011 /* Assume the current character is considered to be printable,
|
|
5012 then just add it. */
|
|
5013 else
|
|
5014 {
|
867
|
5015 *prop = add_ichar_rune (&data);
|
428
|
5016 if (*prop)
|
|
5017 goto done;
|
|
5018 }
|
|
5019
|
826
|
5020 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos);
|
428
|
5021 }
|
|
5022 }
|
|
5023
|
819
|
5024 done:
|
428
|
5025
|
|
5026 /* Determine the starting point of the next line if we did not hit the
|
|
5027 end of the buffer. */
|
826
|
5028 if (data.byte_charpos < byte_string_zv)
|
428
|
5029 {
|
|
5030 /* #### This check is not correct. If the line terminated
|
|
5031 due to a begin-glyph or end-glyph hitting window-end, then
|
826
|
5032 data.ch will not point to the character at data.byte_charpos. If
|
428
|
5033 you make the two changes mentioned at the top of this loop,
|
|
5034 you should be able to say '(if (*prop))'. That should also
|
826
|
5035 make it possible to eliminate the data.byte_charpos < BYTE_BUF_ZV (b)
|
428
|
5036 check. */
|
|
5037
|
|
5038 /* The common case is that the line ended because we hit a newline.
|
|
5039 In that case, the next character is just the next buffer
|
|
5040 position. */
|
|
5041 if (data.ch == '\n')
|
|
5042 {
|
826
|
5043 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos);
|
428
|
5044 }
|
|
5045
|
|
5046 /* Otherwise we have a buffer line which cannot fit on one display
|
|
5047 line. */
|
|
5048 else
|
|
5049 {
|
|
5050 struct glyph_block gb;
|
|
5051 struct glyph_cachel *cachel;
|
|
5052
|
|
5053 /* If the line is to be truncated then we actually have to look
|
|
5054 for the next newline. We also add the end-of-line glyph which
|
|
5055 we know will fit because we adjusted the right border before
|
|
5056 we starting laying out the line. */
|
819
|
5057 data.max_pixpos += data.end_glyph_width;
|
428
|
5058 data.findex = default_face;
|
|
5059 gb.extent = Qnil;
|
|
5060
|
|
5061 if (truncate_win)
|
|
5062 {
|
826
|
5063 Bytecount byte_pos;
|
428
|
5064
|
|
5065 /* Now find the start of the next line. */
|
867
|
5066 byte_pos = byte_find_next_ichar_in_string (disp_string, '\n',
|
826
|
5067 data.byte_charpos, 1);
|
428
|
5068
|
|
5069 data.cursor_type = NO_CURSOR;
|
826
|
5070 data.byte_charpos = byte_pos;
|
428
|
5071 gb.glyph = Vtruncation_glyph;
|
|
5072 cachel = GLYPH_CACHEL (w, TRUN_GLYPH_INDEX);
|
|
5073 }
|
|
5074 else
|
|
5075 {
|
|
5076 /* The cursor can never be on the continuation glyph. */
|
|
5077 data.cursor_type = NO_CURSOR;
|
|
5078
|
826
|
5079 /* data.byte_charpos is already at the start of the next line. */
|
428
|
5080
|
442
|
5081 dl->line_continuation = 1;
|
428
|
5082 gb.glyph = Vcontinuation_glyph;
|
|
5083 cachel = GLYPH_CACHEL (w, CONT_GLYPH_INDEX);
|
|
5084 }
|
|
5085
|
819
|
5086 if (data.end_glyph_width)
|
428
|
5087 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, cachel);
|
|
5088
|
826
|
5089 if (truncate_win && data.byte_charpos == byte_string_zv)
|
428
|
5090 {
|
867
|
5091 const Ibyte *endb = itext_n_addr (XSTRING_DATA (disp_string),
|
826
|
5092 byte_string_zv);
|
867
|
5093 DEC_IBYTEPTR (endb);
|
|
5094 if (itext_ichar (endb) != '\n')
|
428
|
5095 {
|
|
5096 /* #### Damn this losing shit. */
|
826
|
5097 data.byte_charpos++;
|
428
|
5098 }
|
|
5099 }
|
|
5100 }
|
|
5101 }
|
826
|
5102 else if (data.byte_charpos == byte_string_zv)
|
428
|
5103 {
|
|
5104 /* create_text_block () adds a bogus \n marker here which screws
|
|
5105 up subwindow display. Since we never have a cursor in the
|
|
5106 gutter we can safely ignore it. */
|
|
5107 }
|
|
5108 /* Calculate left whitespace boundary. */
|
|
5109 {
|
|
5110 int elt = 0;
|
|
5111
|
|
5112 /* Whitespace past a newline is considered right whitespace. */
|
|
5113 while (elt < Dynarr_length (db->runes))
|
|
5114 {
|
|
5115 struct rune *rb = Dynarr_atp (db->runes, elt);
|
|
5116
|
|
5117 if ((rb->type == RUNE_CHAR && rb->object.chr.ch == ' ')
|
|
5118 || rb->type == RUNE_BLANK)
|
|
5119 {
|
|
5120 dl->bounds.left_white += rb->width;
|
|
5121 elt++;
|
|
5122 }
|
|
5123 else
|
|
5124 elt = Dynarr_length (db->runes);
|
|
5125 }
|
|
5126 }
|
|
5127
|
|
5128 /* Calculate right whitespace boundary. */
|
|
5129 {
|
|
5130 int elt = Dynarr_length (db->runes) - 1;
|
|
5131 int done = 0;
|
|
5132
|
|
5133 while (!done && elt >= 0)
|
|
5134 {
|
|
5135 struct rune *rb = Dynarr_atp (db->runes, elt);
|
|
5136
|
|
5137 if (!(rb->type == RUNE_CHAR && rb->object.chr.ch < 0x100
|
|
5138 && isspace (rb->object.chr.ch))
|
|
5139 && !rb->type == RUNE_BLANK)
|
|
5140 {
|
|
5141 dl->bounds.right_white = rb->xpos + rb->width;
|
|
5142 done = 1;
|
|
5143 }
|
|
5144
|
|
5145 elt--;
|
|
5146
|
|
5147 }
|
|
5148
|
|
5149 /* The line is blank so everything is considered to be right
|
|
5150 whitespace. */
|
|
5151 if (!done)
|
|
5152 dl->bounds.right_white = dl->bounds.left_in;
|
|
5153 }
|
|
5154
|
|
5155 /* Set the display blocks bounds. */
|
|
5156 db->start_pos = dl->bounds.left_in;
|
|
5157 if (Dynarr_length (db->runes))
|
|
5158 {
|
|
5159 struct rune *rb = Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
|
|
5160
|
|
5161 db->end_pos = rb->xpos + rb->width;
|
|
5162 }
|
|
5163 else
|
|
5164 db->end_pos = dl->bounds.right_white;
|
|
5165
|
819
|
5166 calculate_baseline (&data);
|
428
|
5167
|
|
5168 dl->ascent = data.new_ascent;
|
|
5169 dl->descent = data.new_descent;
|
|
5170
|
|
5171 {
|
|
5172 unsigned short ascent = (unsigned short) XINT (w->minimum_line_ascent);
|
|
5173
|
|
5174 if (dl->ascent < ascent)
|
|
5175 dl->ascent = ascent;
|
|
5176 }
|
|
5177 {
|
|
5178 unsigned short descent = (unsigned short) XINT (w->minimum_line_descent);
|
|
5179
|
|
5180 if (dl->descent < descent)
|
|
5181 dl->descent = descent;
|
|
5182 }
|
|
5183
|
819
|
5184 calculate_yoffset (dl, db);
|
|
5185
|
428
|
5186 dl->cursor_elt = data.cursor_x;
|
|
5187 /* #### lossage lossage lossage! Fix this shit! */
|
826
|
5188 if (data.byte_charpos > byte_string_zv)
|
|
5189 dl->end_charpos = buffer_or_string_bytexpos_to_charxpos (disp_string,
|
|
5190 byte_string_zv);
|
428
|
5191 else
|
826
|
5192 dl->end_charpos =
|
|
5193 buffer_or_string_bytexpos_to_charxpos (disp_string,
|
|
5194 data.byte_charpos) - 1;
|
428
|
5195 if (truncate_win)
|
434
|
5196 data.dl->num_chars =
|
826
|
5197 string_column_at_point (disp_string, dl->end_charpos,
|
793
|
5198 b ? XINT (b->tab_width) : 8);
|
428
|
5199 else
|
|
5200 /* This doesn't correctly take into account tabs and control
|
|
5201 characters but if the window isn't being truncated then this
|
|
5202 value isn't going to end up being used anyhow. */
|
826
|
5203 data.dl->num_chars = dl->end_charpos - dl->charpos;
|
428
|
5204
|
|
5205 /* #### handle horizontally scrolled line with text none of which
|
|
5206 was actually laid out. */
|
|
5207
|
|
5208 /* #### handle any remainder of overlay arrow */
|
|
5209
|
|
5210 if (*prop == ADD_FAILED)
|
|
5211 *prop = NULL;
|
|
5212
|
|
5213 if (truncate_win && *prop)
|
|
5214 {
|
|
5215 Dynarr_free (*prop);
|
|
5216 *prop = NULL;
|
|
5217 }
|
|
5218
|
|
5219 extent_fragment_delete (data.ef);
|
|
5220
|
|
5221 /* #### If we started at EOB, then make sure we return a value past
|
|
5222 it so that regenerate_window will exit properly. This is bogus.
|
|
5223 The main loop should get fixed so that it isn't necessary to call
|
|
5224 this function if we are already at EOB. */
|
|
5225
|
826
|
5226 if (data.byte_charpos == byte_string_zv && byte_start_pos == byte_string_zv)
|
793
|
5227 return string_index_byte_to_char (disp_string,
|
826
|
5228 data.byte_charpos) + 1; /* Yuck! */
|
428
|
5229 else
|
826
|
5230 return string_index_byte_to_char (disp_string, data.byte_charpos);
|
428
|
5231 }
|
|
5232
|
|
5233 /* Given a display line and a starting position, ensure that the
|
|
5234 contents of the display line accurately represent the visual
|
|
5235 representation of the buffer contents starting from the given
|
|
5236 position when displayed in the given window. The display line ends
|
|
5237 when the contents of the line reach the right boundary of the given
|
434
|
5238 window.
|
|
5239
|
428
|
5240 This is very similar to generate_display_line but with the same
|
|
5241 limitations as create_string_text_block. I have taken the liberty
|
665
|
5242 of fixing the bytebpos stuff though.*/
|
|
5243
|
|
5244 static Charbpos
|
428
|
5245 generate_string_display_line (struct window *w, Lisp_Object disp_string,
|
|
5246 struct display_line *dl,
|
826
|
5247 Charcount start_pos,
|
428
|
5248 prop_block_dynarr **prop,
|
|
5249 face_index default_face)
|
|
5250 {
|
826
|
5251 Charcount ret_charcount;
|
428
|
5252
|
|
5253 /* you must set bounds before calling this. */
|
434
|
5254
|
428
|
5255 /* Reset what this line is using. */
|
|
5256 if (dl->display_blocks)
|
|
5257 Dynarr_reset (dl->display_blocks);
|
|
5258 if (dl->left_glyphs)
|
|
5259 {
|
|
5260 Dynarr_free (dl->left_glyphs);
|
|
5261 dl->left_glyphs = 0;
|
|
5262 }
|
|
5263 if (dl->right_glyphs)
|
|
5264 {
|
|
5265 Dynarr_free (dl->right_glyphs);
|
|
5266 dl->right_glyphs = 0;
|
|
5267 }
|
|
5268
|
|
5269 /* We aren't generating a modeline at the moment. */
|
|
5270 dl->modeline = 0;
|
|
5271
|
|
5272 /* Create a display block for the text region of the line. */
|
826
|
5273 ret_charcount = create_string_text_block (w, disp_string, dl, start_pos,
|
|
5274 prop, default_face);
|
|
5275 dl->charpos = start_pos;
|
|
5276 if (dl->end_charpos < dl->charpos)
|
|
5277 dl->end_charpos = dl->charpos;
|
428
|
5278
|
|
5279 /* If there are left glyphs associated with any character in the
|
|
5280 text block, then create a display block to handle them. */
|
|
5281 if (dl->left_glyphs != NULL && Dynarr_length (dl->left_glyphs))
|
|
5282 create_left_glyph_block (w, dl, 0);
|
|
5283
|
|
5284 /* If there are right glyphs associated with any character in the
|
|
5285 text block, then create a display block to handle them. */
|
|
5286 if (dl->right_glyphs != NULL && Dynarr_length (dl->right_glyphs))
|
|
5287 create_right_glyph_block (w, dl);
|
|
5288
|
826
|
5289 return ret_charcount;
|
428
|
5290 }
|
|
5291
|
2518
|
5292 /*
|
|
5293
|
|
5294 Info on Re-entrancy crashes, with backtraces given:
|
|
5295
|
|
5296 (Info-goto-node "(internals)Nasty Bugs due to Reentrancy in Redisplay Structures handling QUIT")
|
1318
|
5297 */
|
|
5298
|
|
5299
|
428
|
5300 /* This is ripped off from regenerate_window. All we want to do is
|
|
5301 loop through elements in the string creating display lines until we
|
|
5302 have covered the provided area. Simple really. */
|
|
5303 void
|
|
5304 generate_displayable_area (struct window *w, Lisp_Object disp_string,
|
|
5305 int xpos, int ypos, int width, int height,
|
|
5306 display_line_dynarr* dla,
|
826
|
5307 Charcount start_pos,
|
428
|
5308 face_index default_face)
|
|
5309 {
|
|
5310 int yend = ypos + height;
|
|
5311 Charcount s_zv;
|
|
5312 prop_block_dynarr *prop = 0;
|
|
5313 layout_bounds bounds;
|
2518
|
5314 int depth = -1;
|
|
5315
|
428
|
5316 /* if there's nothing to do then do nothing. code after this assumes
|
|
5317 there is something to do. */
|
|
5318 if (NILP (disp_string))
|
|
5319 return;
|
|
5320
|
2518
|
5321 /* See comment in regenerate_window() */
|
|
5322 if (!in_display)
|
|
5323 depth = enter_redisplay_critical_section ();
|
|
5324
|
|
5325 assert (dla);
|
|
5326 Dynarr_reset (dla);
|
|
5327
|
826
|
5328 s_zv = string_char_length (disp_string);
|
428
|
5329
|
|
5330 bounds.left_out = xpos;
|
|
5331 bounds.right_out = xpos + width;
|
|
5332 /* The inner boundaries mark where the glyph margins are located. */
|
|
5333 bounds.left_in = bounds.left_out + window_left_margin_width (w);
|
|
5334 bounds.right_in = bounds.right_out - window_right_margin_width (w);
|
|
5335 /* We cannot fully calculate the whitespace boundaries as they
|
|
5336 depend on the contents of the line being displayed. */
|
|
5337 bounds.left_white = bounds.left_in;
|
|
5338 bounds.right_white = bounds.right_in;
|
|
5339
|
|
5340 while (ypos < yend)
|
|
5341 {
|
|
5342 struct display_line dl;
|
|
5343 struct display_line *dlp;
|
826
|
5344 Charcount next_pos;
|
428
|
5345 int local;
|
851
|
5346 int pos_of_dlp = -1;
|
428
|
5347
|
|
5348 if (Dynarr_length (dla) < Dynarr_largest (dla))
|
|
5349 {
|
851
|
5350 pos_of_dlp = Dynarr_length (dla);
|
|
5351 dlp = Dynarr_atp (dla, pos_of_dlp);
|
428
|
5352 local = 0;
|
|
5353 }
|
|
5354 else
|
|
5355 {
|
|
5356
|
|
5357 xzero (dl);
|
|
5358 dlp = &dl;
|
|
5359 local = 1;
|
|
5360 }
|
|
5361
|
|
5362 dlp->bounds = bounds;
|
|
5363 dlp->offset = 0;
|
1318
|
5364 Dynarr_lock (dla);
|
428
|
5365 next_pos = generate_string_display_line (w, disp_string, dlp, start_pos,
|
|
5366 &prop, default_face);
|
1318
|
5367 Dynarr_unlock (dla);
|
428
|
5368 /* we need to make sure that we continue along the line if there
|
|
5369 is more left to display otherwise we just end up redisplaying
|
|
5370 the same chunk over and over again. */
|
|
5371 if (next_pos == start_pos && next_pos < s_zv)
|
|
5372 start_pos++;
|
|
5373 else
|
|
5374 start_pos = next_pos;
|
|
5375
|
|
5376 dlp->ypos = ypos + dlp->ascent;
|
|
5377 ypos = dlp->ypos + dlp->descent;
|
|
5378
|
|
5379 if (ypos > yend)
|
|
5380 {
|
|
5381 int visible_height = dlp->ascent + dlp->descent;
|
|
5382
|
|
5383 dlp->clip = (ypos - yend);
|
|
5384 visible_height -= dlp->clip;
|
|
5385
|
|
5386 if (visible_height < VERTICAL_CLIP (w, 1))
|
|
5387 {
|
|
5388 if (local)
|
|
5389 free_display_line (dlp);
|
|
5390 break;
|
|
5391 }
|
|
5392 }
|
|
5393 else
|
|
5394 dlp->clip = 0;
|
|
5395
|
851
|
5396 assert (pos_of_dlp < 0 || pos_of_dlp == Dynarr_length (dla));
|
428
|
5397 Dynarr_add (dla, *dlp);
|
|
5398
|
|
5399 /* #### This type of check needs to be done down in the
|
|
5400 generate_display_line call. */
|
|
5401 if (start_pos >= s_zv)
|
|
5402 break;
|
|
5403 }
|
|
5404
|
|
5405 if (prop)
|
|
5406 Dynarr_free (prop);
|
2518
|
5407
|
|
5408 if (depth >= 0)
|
|
5409 exit_redisplay_critical_section (depth);
|
428
|
5410 }
|
|
5411
|
|
5412
|
|
5413 /***************************************************************************/
|
|
5414 /* */
|
|
5415 /* window-regeneration routines */
|
|
5416 /* */
|
|
5417 /***************************************************************************/
|
|
5418
|
|
5419 /* For a given window and starting position in the buffer it contains,
|
|
5420 ensure that the TYPE display lines accurately represent the
|
|
5421 presentation of the window. We pass the buffer instead of getting
|
|
5422 it from the window since redisplay_window may have temporarily
|
|
5423 changed it to the echo area buffer. */
|
|
5424
|
|
5425 static void
|
2518
|
5426 regenerate_window (struct window *w, Charbpos start_pos, Charbpos point,
|
|
5427 int type)
|
428
|
5428 {
|
|
5429 struct frame *f = XFRAME (w->frame);
|
|
5430 struct buffer *b = XBUFFER (w->buffer);
|
|
5431 int ypos = WINDOW_TEXT_TOP (w);
|
|
5432 int yend; /* set farther down */
|
|
5433 int yclip = WINDOW_TEXT_TOP_CLIP (w);
|
442
|
5434 int force;
|
2518
|
5435 int depth = -1;
|
428
|
5436
|
|
5437 prop_block_dynarr *prop;
|
|
5438 layout_bounds bounds;
|
|
5439 display_line_dynarr *dla;
|
|
5440 int need_modeline;
|
|
5441
|
|
5442 /* The lines had better exist by this point. */
|
|
5443 if (!(dla = window_display_lines (w, type)))
|
2500
|
5444 ABORT ();
|
2518
|
5445
|
|
5446 if (!in_display)
|
|
5447 depth = enter_redisplay_critical_section ();
|
|
5448
|
|
5449 /* This is one spot where a re-entrancy crash will occur, due to a check
|
|
5450 in the dynarr to make sure it isn't "locked" */
|
|
5451 /*
|
|
5452
|
|
5453 Info on Re-entrancy crashes, with backtraces given:
|
|
5454
|
|
5455 (Info-goto-node "(internals)Nasty Bugs due to Reentrancy in Redisplay Structures handling QUIT")
|
|
5456 */
|
|
5457
|
428
|
5458 Dynarr_reset (dla);
|
|
5459 w->max_line_len = 0;
|
|
5460
|
|
5461 /* Normally these get updated in redisplay_window but it is possible
|
|
5462 for this function to get called from some other points where that
|
|
5463 update may not have occurred. This acts as a safety check. */
|
|
5464 if (!Dynarr_length (w->face_cachels))
|
|
5465 reset_face_cachels (w);
|
|
5466 if (!Dynarr_length (w->glyph_cachels))
|
|
5467 reset_glyph_cachels (w);
|
|
5468
|
|
5469 Fset_marker (w->start[type], make_int (start_pos), w->buffer);
|
|
5470 Fset_marker (w->pointm[type], make_int (point), w->buffer);
|
|
5471 w->last_point_x[type] = -1;
|
|
5472 w->last_point_y[type] = -1;
|
|
5473
|
|
5474 /* Make sure a modeline is in the structs if needed. */
|
|
5475 need_modeline = ensure_modeline_generated (w, type);
|
|
5476
|
|
5477 /* Wait until here to set this so that the structs have a modeline
|
|
5478 generated in the case where one didn't exist. */
|
|
5479 yend = WINDOW_TEXT_BOTTOM (w);
|
|
5480
|
|
5481 bounds = calculate_display_line_boundaries (w, 0);
|
|
5482
|
|
5483 /* 97/3/14 jhod: stuff added here to support pre-prompts (used for input systems) */
|
|
5484 if (MINI_WINDOW_P (w)
|
|
5485 && (!NILP (Vminibuf_prompt) || !NILP (Vminibuf_preprompt))
|
|
5486 && !echo_area_active (f)
|
|
5487 && start_pos == BUF_BEGV (b))
|
|
5488 {
|
|
5489 struct prop_block pb;
|
|
5490 Lisp_Object string;
|
|
5491 prop = Dynarr_new (prop_block);
|
|
5492
|
|
5493 string = concat2(Vminibuf_preprompt, Vminibuf_prompt);
|
|
5494 pb.type = PROP_MINIBUF_PROMPT;
|
|
5495 pb.data.p_string.str = XSTRING_DATA(string);
|
|
5496 pb.data.p_string.len = XSTRING_LENGTH(string);
|
|
5497 Dynarr_add (prop, pb);
|
|
5498 }
|
|
5499 else
|
|
5500 prop = 0;
|
|
5501
|
442
|
5502 /* When we are computing things for scrolling purposes, make
|
|
5503 sure at least one line is always generated */
|
|
5504 force = (type == CMOTION_DISP);
|
|
5505
|
|
5506 /* Make sure this is set always */
|
|
5507 /* Note the conversion at end */
|
|
5508 w->window_end_pos[type] = start_pos;
|
|
5509 while (ypos < yend || force)
|
428
|
5510 {
|
|
5511 struct display_line dl;
|
|
5512 struct display_line *dlp;
|
|
5513 int local;
|
851
|
5514 int pos_of_dlp = -1;
|
428
|
5515
|
|
5516 if (Dynarr_length (dla) < Dynarr_largest (dla))
|
|
5517 {
|
851
|
5518 pos_of_dlp = Dynarr_length (dla);
|
|
5519 dlp = Dynarr_atp (dla, pos_of_dlp);
|
428
|
5520 local = 0;
|
|
5521 }
|
|
5522 else
|
|
5523 {
|
|
5524
|
|
5525 xzero (dl);
|
|
5526 dlp = &dl;
|
|
5527 local = 1;
|
|
5528 }
|
|
5529
|
|
5530 dlp->bounds = bounds;
|
|
5531 dlp->offset = 0;
|
1318
|
5532 Dynarr_lock (dla);
|
428
|
5533 start_pos = generate_display_line (w, dlp, 1, start_pos, &prop, type);
|
1318
|
5534 Dynarr_unlock (dla);
|
428
|
5535
|
|
5536 if (yclip > dlp->ascent)
|
|
5537 {
|
|
5538 /* this should never happen, but if it does just display the
|
|
5539 whole line */
|
|
5540 yclip = 0;
|
|
5541 }
|
|
5542
|
|
5543 dlp->ypos = (ypos + dlp->ascent) - yclip;
|
|
5544 ypos = dlp->ypos + dlp->descent;
|
|
5545
|
|
5546 /* See if we've been asked to start midway through a line, for
|
|
5547 partial display line scrolling. */
|
434
|
5548 if (yclip)
|
428
|
5549 {
|
|
5550 dlp->top_clip = yclip;
|
|
5551 yclip = 0;
|
|
5552 }
|
|
5553 else
|
|
5554 dlp->top_clip = 0;
|
|
5555
|
|
5556 if (ypos > yend)
|
|
5557 {
|
|
5558 int visible_height = dlp->ascent + dlp->descent;
|
|
5559
|
|
5560 dlp->clip = (ypos - yend);
|
|
5561 /* Although this seems strange we could have a single very
|
|
5562 tall line visible for which we need to account for both
|
|
5563 the top clip and the bottom clip. */
|
|
5564 visible_height -= (dlp->clip + dlp->top_clip);
|
|
5565
|
442
|
5566 if (visible_height < VERTICAL_CLIP (w, 1) && !force)
|
428
|
5567 {
|
|
5568 if (local)
|
|
5569 free_display_line (dlp);
|
|
5570 break;
|
|
5571 }
|
|
5572 }
|
|
5573 else
|
|
5574 dlp->clip = 0;
|
|
5575
|
|
5576 if (dlp->cursor_elt != -1)
|
|
5577 {
|
|
5578 /* #### This check is steaming crap. Have to get things
|
|
5579 fixed so when create_text_block hits EOB, we're done,
|
|
5580 period. */
|
|
5581 if (w->last_point_x[type] == -1)
|
|
5582 {
|
|
5583 w->last_point_x[type] = dlp->cursor_elt;
|
|
5584 w->last_point_y[type] = Dynarr_length (dla);
|
|
5585 }
|
|
5586 else
|
|
5587 {
|
|
5588 /* #### This means that we've added a cursor at EOB
|
|
5589 twice. Yuck oh yuck. */
|
1318
|
5590 struct display_block *db;
|
|
5591
|
|
5592 Dynarr_lock (dla);
|
|
5593 db = get_display_block_from_line (dlp, TEXT);
|
|
5594 Dynarr_unlock (dla);
|
428
|
5595
|
|
5596 Dynarr_atp (db->runes, dlp->cursor_elt)->cursor_type = NO_CURSOR;
|
|
5597 dlp->cursor_elt = -1;
|
|
5598 }
|
|
5599 }
|
|
5600
|
|
5601 if (dlp->num_chars > w->max_line_len)
|
|
5602 w->max_line_len = dlp->num_chars;
|
|
5603
|
851
|
5604 assert (pos_of_dlp < 0 || pos_of_dlp == Dynarr_length (dla));
|
428
|
5605 Dynarr_add (dla, *dlp);
|
|
5606
|
|
5607 /* #### This isn't right, but it is close enough for now. */
|
|
5608 w->window_end_pos[type] = start_pos;
|
|
5609
|
|
5610 /* #### This type of check needs to be done down in the
|
|
5611 generate_display_line call. */
|
|
5612 if (start_pos > BUF_ZV (b))
|
|
5613 break;
|
442
|
5614
|
|
5615 force = 0;
|
428
|
5616 }
|
|
5617
|
|
5618 if (prop)
|
|
5619 Dynarr_free (prop);
|
|
5620
|
|
5621 /* #### More not quite right, but close enough. */
|
442
|
5622 /* Ben sez: apparently window_end_pos[] is measured
|
428
|
5623 as the number of characters between the window end and the
|
|
5624 end of the buffer? This seems rather weirdo. What's
|
442
|
5625 the justification for this?
|
|
5626
|
|
5627 JV sez: Because BUF_Z (b) would be a good initial value, however
|
|
5628 that can change. This representation allows initalizing with 0.
|
|
5629 */
|
428
|
5630 w->window_end_pos[type] = BUF_Z (b) - w->window_end_pos[type];
|
|
5631
|
|
5632 if (need_modeline)
|
|
5633 {
|
|
5634 /* We know that this is the right thing to use because we put it
|
|
5635 there when we first started working in this function. */
|
|
5636 generate_modeline (w, Dynarr_atp (dla, 0), type);
|
|
5637 }
|
2518
|
5638
|
|
5639 if (depth >= 0)
|
|
5640 exit_redisplay_critical_section (depth);
|
428
|
5641 }
|
|
5642
|
826
|
5643 #define REGEN_INC_FIND_START_END \
|
|
5644 do { \
|
|
5645 /* Determine start and end of lines. */ \
|
|
5646 if (!Dynarr_length (cdla)) \
|
|
5647 return 0; \
|
|
5648 else \
|
|
5649 { \
|
428
|
5650 if (Dynarr_atp (cdla, 0)->modeline && Dynarr_atp (ddla, 0)->modeline) \
|
826
|
5651 { \
|
|
5652 dla_start = 1; \
|
|
5653 } \
|
|
5654 else if (!Dynarr_atp (cdla, 0)->modeline \
|
|
5655 && !Dynarr_atp (ddla, 0)->modeline) \
|
|
5656 { \
|
|
5657 dla_start = 0; \
|
|
5658 } \
|
|
5659 else \
|
2500
|
5660 ABORT (); /* structs differ */ \
|
826
|
5661 \
|
|
5662 dla_end = Dynarr_length (cdla) - 1; \
|
|
5663 } \
|
|
5664 \
|
|
5665 start_pos = (Dynarr_atp (cdla, dla_start)->charpos \
|
|
5666 + Dynarr_atp (cdla, dla_start)->offset); \
|
|
5667 /* If this isn't true, then startp has changed and we need to do a \
|
|
5668 full regen. */ \
|
|
5669 if (startp != start_pos) \
|
|
5670 return 0; \
|
|
5671 \
|
|
5672 /* Point is outside the visible region so give up. */ \
|
|
5673 if (pointm < start_pos) \
|
|
5674 return 0; \
|
|
5675 \
|
428
|
5676 } while (0)
|
|
5677
|
|
5678 /* This attempts to incrementally update the display structures. It
|
|
5679 returns a boolean indicating success or failure. This function is
|
|
5680 very similar to regenerate_window_incrementally and is in fact only
|
|
5681 called from that function. However, because of the nature of the
|
|
5682 changes it deals with it sometimes makes different assumptions
|
|
5683 which can lead to success which are much more difficult to make
|
|
5684 when dealing with buffer changes. */
|
|
5685
|
|
5686 static int
|
665
|
5687 regenerate_window_extents_only_changed (struct window *w, Charbpos startp,
|
|
5688 Charbpos pointm,
|
428
|
5689 Charcount beg_unchanged,
|
|
5690 Charcount end_unchanged)
|
|
5691 {
|
|
5692 struct buffer *b = XBUFFER (w->buffer);
|
|
5693 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
|
|
5694 display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP);
|
|
5695
|
|
5696 int dla_start = 0;
|
|
5697 int dla_end, line;
|
|
5698 int first_line, last_line;
|
665
|
5699 Charbpos start_pos;
|
428
|
5700 /* Don't define this in the loop where it is used because we
|
|
5701 definitely want its value to survive between passes. */
|
|
5702 prop_block_dynarr *prop = NULL;
|
|
5703
|
|
5704 /* If we don't have any buffer change recorded but the modiff flag has
|
|
5705 been incremented, then fail. I'm not sure of the exact circumstances
|
|
5706 under which this can happen, but I believe that it is probably a
|
|
5707 reasonable happening. */
|
|
5708 if (!point_visible (w, pointm, CURRENT_DISP)
|
|
5709 || XINT (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b))
|
|
5710 return 0;
|
|
5711
|
|
5712 /* If the cursor is moved we attempt to update it. If we succeed we
|
|
5713 go ahead and proceed with the optimization attempt. */
|
|
5714 if (!EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer)
|
|
5715 || pointm != marker_position (w->last_point[CURRENT_DISP]))
|
|
5716 {
|
|
5717 struct frame *f = XFRAME (w->frame);
|
|
5718 struct device *d = XDEVICE (f->device);
|
|
5719 struct frame *sel_f = device_selected_frame (d);
|
|
5720 int success = 0;
|
|
5721
|
|
5722 if (w->last_point_x[CURRENT_DISP] != -1
|
|
5723 && w->last_point_y[CURRENT_DISP] != -1)
|
|
5724 {
|
|
5725
|
|
5726 if (redisplay_move_cursor (w, pointm, WINDOW_TTY_P (w)))
|
|
5727 {
|
|
5728 /* Always regenerate the modeline in case it is
|
|
5729 displaying the current line or column. */
|
|
5730 regenerate_modeline (w);
|
|
5731 success = 1;
|
|
5732 }
|
|
5733 }
|
|
5734 else if (w != XWINDOW (FRAME_SELECTED_WINDOW (sel_f)))
|
|
5735 {
|
|
5736 if (f->modeline_changed)
|
|
5737 regenerate_modeline (w);
|
|
5738 success = 1;
|
|
5739 }
|
|
5740
|
|
5741 if (!success)
|
|
5742 return 0;
|
|
5743 }
|
|
5744
|
|
5745 if (beg_unchanged == -1 && end_unchanged == -1)
|
|
5746 return 1;
|
|
5747
|
|
5748 /* assert: There are no buffer modifications or they are all below the
|
|
5749 visible region. We assume that regenerate_window_incrementally has
|
|
5750 not called us unless this is true. */
|
|
5751
|
|
5752 REGEN_INC_FIND_START_END;
|
|
5753
|
|
5754 /* If the changed are starts before the visible area, give up. */
|
|
5755 if (beg_unchanged < startp)
|
|
5756 return 0;
|
|
5757
|
|
5758 /* Find what display line the extent changes first affect. */
|
|
5759 line = dla_start;
|
|
5760 while (line <= dla_end)
|
|
5761 {
|
|
5762 struct display_line *dl = Dynarr_atp (cdla, line);
|
826
|
5763 Charbpos lstart = dl->charpos + dl->offset;
|
|
5764 Charbpos lend = dl->end_charpos + dl->offset;
|
428
|
5765
|
|
5766 if (beg_unchanged >= lstart && beg_unchanged <= lend)
|
|
5767 break;
|
|
5768
|
|
5769 line++;
|
|
5770 }
|
|
5771
|
|
5772 /* If the changes are below the visible area then if point hasn't
|
|
5773 moved return success otherwise fail in order to be safe. */
|
|
5774 if (line > dla_end)
|
|
5775 {
|
|
5776 if (EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer)
|
|
5777 && pointm == marker_position (w->last_point[CURRENT_DISP]))
|
|
5778 return 1;
|
|
5779 else
|
|
5780 return 0;
|
|
5781 }
|
|
5782
|
|
5783 /* At this point we know what line the changes first affect. We now
|
|
5784 begin redrawing lines as long as we are still in the affected
|
|
5785 region and the line's size and positioning don't change.
|
|
5786 Otherwise we fail. If we fail we will have altered the desired
|
|
5787 structs which could lead to an assertion failure. However, if we
|
|
5788 fail the next thing that is going to happen is a full regen so we
|
|
5789 will actually end up being safe. */
|
|
5790 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b));
|
|
5791 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b));
|
|
5792 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp), w->buffer);
|
|
5793 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm), w->buffer);
|
|
5794
|
|
5795 first_line = last_line = line;
|
|
5796 while (line <= dla_end)
|
|
5797 {
|
2286
|
5798 Charbpos old_start, old_end;
|
428
|
5799 struct display_line *cdl = Dynarr_atp (cdla, line);
|
|
5800 struct display_line *ddl = Dynarr_atp (ddla, line);
|
|
5801 struct display_block *db;
|
|
5802 int initial_size;
|
|
5803
|
826
|
5804 assert (cdl->charpos == ddl->charpos);
|
|
5805 assert (cdl->end_charpos == ddl->end_charpos);
|
428
|
5806 assert (cdl->offset == ddl->offset);
|
|
5807
|
|
5808 db = get_display_block_from_line (ddl, TEXT);
|
|
5809 initial_size = Dynarr_length (db->runes);
|
826
|
5810 old_start = ddl->charpos + ddl->offset;
|
|
5811 old_end = ddl->end_charpos + ddl->offset;
|
428
|
5812
|
|
5813 /* If this is the first line being updated and it used
|
|
5814 propagation data, fail. Otherwise we'll be okay because
|
|
5815 we'll have the necessary propagation data. */
|
|
5816 if (line == first_line && ddl->used_prop_data)
|
|
5817 return 0;
|
|
5818
|
2286
|
5819 generate_display_line (w, ddl, 0, ddl->charpos + ddl->offset,
|
|
5820 &prop, DESIRED_DISP);
|
428
|
5821 ddl->offset = 0;
|
|
5822
|
|
5823 /* #### If there is propagated stuff the fail. We could
|
|
5824 probably actually deal with this if the line had propagated
|
|
5825 information when originally created by a full
|
|
5826 regeneration. */
|
|
5827 if (prop)
|
|
5828 {
|
|
5829 Dynarr_free (prop);
|
|
5830 return 0;
|
|
5831 }
|
|
5832
|
|
5833 /* If any line position parameters have changed or a
|
|
5834 cursor has disappeared or disappeared, fail. */
|
|
5835 db = get_display_block_from_line (ddl, TEXT);
|
|
5836 if (cdl->ypos != ddl->ypos
|
|
5837 || cdl->ascent != ddl->ascent
|
|
5838 || cdl->descent != ddl->descent
|
|
5839 || cdl->top_clip != ddl->top_clip
|
|
5840 || (cdl->cursor_elt != -1 && ddl->cursor_elt == -1)
|
|
5841 || (cdl->cursor_elt == -1 && ddl->cursor_elt != -1)
|
826
|
5842 || old_start != ddl->charpos
|
|
5843 || old_end != ddl->end_charpos
|
428
|
5844 || initial_size != Dynarr_length (db->runes))
|
|
5845 {
|
|
5846 return 0;
|
|
5847 }
|
|
5848
|
|
5849 if (ddl->cursor_elt != -1)
|
|
5850 {
|
|
5851 w->last_point_x[DESIRED_DISP] = ddl->cursor_elt;
|
|
5852 w->last_point_y[DESIRED_DISP] = line;
|
|
5853 }
|
|
5854
|
|
5855 last_line = line;
|
|
5856
|
|
5857 /* If the extent changes end on the line we just updated then
|
|
5858 we're done. Otherwise go on to the next line. */
|
826
|
5859 if (end_unchanged <= ddl->end_charpos)
|
428
|
5860 break;
|
|
5861 else
|
|
5862 line++;
|
|
5863 }
|
|
5864
|
|
5865 redisplay_update_line (w, first_line, last_line, 1);
|
|
5866 return 1;
|
|
5867 }
|
|
5868
|
|
5869 /* Attempt to update the display data structures based on knowledge of
|
|
5870 the changed region in the buffer. Returns a boolean indicating
|
|
5871 success or failure. If this function returns a failure then a
|
|
5872 regenerate_window _must_ be performed next in order to maintain
|
|
5873 invariants located here. */
|
|
5874
|
|
5875 static int
|
665
|
5876 regenerate_window_incrementally (struct window *w, Charbpos startp,
|
|
5877 Charbpos pointm)
|
428
|
5878 {
|
|
5879 struct buffer *b = XBUFFER (w->buffer);
|
|
5880 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
|
|
5881 display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP);
|
|
5882 Charcount beg_unchanged, end_unchanged;
|
|
5883 Charcount extent_beg_unchanged, extent_end_unchanged;
|
|
5884
|
|
5885 int dla_start = 0;
|
|
5886 int dla_end, line;
|
665
|
5887 Charbpos start_pos;
|
428
|
5888
|
|
5889 /* If this function is called, the current and desired structures
|
|
5890 had better be identical. If they are not, then that is a bug. */
|
|
5891 assert (Dynarr_length (cdla) == Dynarr_length (ddla));
|
|
5892
|
|
5893 /* We don't handle minibuffer windows yet. The minibuffer prompt
|
|
5894 screws us up. */
|
|
5895 if (MINI_WINDOW_P (w))
|
|
5896 return 0;
|
|
5897
|
|
5898 extent_beg_unchanged = BUF_EXTENT_BEGIN_UNCHANGED (b);
|
|
5899 extent_end_unchanged = (BUF_EXTENT_END_UNCHANGED (b) == -1
|
|
5900 ? -1
|
|
5901 : BUF_Z (b) - BUF_EXTENT_END_UNCHANGED (b));
|
|
5902
|
|
5903 /* If nothing has changed in the buffer, then make sure point is ok
|
|
5904 and succeed. */
|
|
5905 if (BUF_BEGIN_UNCHANGED (b) == -1 && BUF_END_UNCHANGED (b) == -1)
|
|
5906 return regenerate_window_extents_only_changed (w, startp, pointm,
|
|
5907 extent_beg_unchanged,
|
|
5908 extent_end_unchanged);
|
|
5909
|
|
5910 /* We can't deal with deleted newlines. */
|
|
5911 if (BUF_NEWLINE_WAS_DELETED (b))
|
|
5912 return 0;
|
|
5913
|
|
5914 beg_unchanged = BUF_BEGIN_UNCHANGED (b);
|
|
5915 end_unchanged = (BUF_END_UNCHANGED (b) == -1
|
|
5916 ? -1
|
|
5917 : BUF_Z (b) - BUF_END_UNCHANGED (b));
|
|
5918
|
|
5919 REGEN_INC_FIND_START_END;
|
|
5920
|
|
5921 /* If the changed area starts before the visible area, give up. */
|
|
5922 if (beg_unchanged < startp)
|
|
5923 return 0;
|
|
5924
|
|
5925 /* Find what display line the buffer changes first affect. */
|
|
5926 line = dla_start;
|
|
5927 while (line <= dla_end)
|
|
5928 {
|
|
5929 struct display_line *dl = Dynarr_atp (cdla, line);
|
826
|
5930 Charbpos lstart = dl->charpos + dl->offset;
|
|
5931 Charbpos lend = dl->end_charpos + dl->offset;
|
428
|
5932
|
|
5933 if (beg_unchanged >= lstart && beg_unchanged <= lend)
|
|
5934 break;
|
|
5935
|
|
5936 line++;
|
|
5937 }
|
|
5938
|
|
5939 /* If the changes are below the visible area then if point hasn't
|
|
5940 moved return success otherwise fail in order to be safe. */
|
|
5941 if (line > dla_end)
|
|
5942 return regenerate_window_extents_only_changed (w, startp, pointm,
|
|
5943 extent_beg_unchanged,
|
|
5944 extent_end_unchanged);
|
|
5945 else
|
|
5946 /* At this point we know what line the changes first affect. We
|
|
5947 now redraw that line. If the changes are contained within it
|
|
5948 we are going to succeed and can update just that one line.
|
|
5949 Otherwise we fail. If we fail we will have altered the desired
|
|
5950 structs which could lead to an assertion failure. However, if
|
|
5951 we fail the next thing that is going to happen is a full regen
|
|
5952 so we will actually end up being safe. */
|
|
5953 {
|
|
5954 prop_block_dynarr *prop = NULL;
|
|
5955 struct display_line *cdl = Dynarr_atp (cdla, line);
|
|
5956 struct display_line *ddl = Dynarr_atp (ddla, line);
|
|
5957
|
826
|
5958 assert (cdl->charpos == ddl->charpos);
|
|
5959 assert (cdl->end_charpos == ddl->end_charpos);
|
428
|
5960 assert (cdl->offset == ddl->offset);
|
|
5961
|
442
|
5962 /* If the line continues to next display line, fail. */
|
|
5963 if (ddl->line_continuation)
|
|
5964 return 0;
|
428
|
5965
|
|
5966 /* If the line was generated using propagation data, fail. */
|
|
5967 if (ddl->used_prop_data)
|
|
5968 return 0;
|
|
5969
|
2286
|
5970 generate_display_line (w, ddl, 0, ddl->charpos + ddl->offset,
|
|
5971 &prop, DESIRED_DISP);
|
428
|
5972 ddl->offset = 0;
|
|
5973
|
|
5974 /* If there is propagated stuff then it is pretty much a
|
|
5975 guarantee that more than just the one line is affected. */
|
|
5976 if (prop)
|
|
5977 {
|
|
5978 Dynarr_free (prop);
|
|
5979 return 0;
|
|
5980 }
|
|
5981
|
442
|
5982 /* If the line continues to next display line, fail. */
|
|
5983 if (ddl->line_continuation)
|
|
5984 return 0;
|
428
|
5985
|
|
5986 /* If any line position parameters have changed or a
|
|
5987 cursor has disappeared or disappeared, fail. */
|
|
5988 if (cdl->ypos != ddl->ypos
|
|
5989 || cdl->ascent != ddl->ascent
|
|
5990 || cdl->descent != ddl->descent
|
|
5991 || cdl->top_clip != ddl->top_clip
|
|
5992 || (cdl->cursor_elt != -1 && ddl->cursor_elt == -1)
|
|
5993 || (cdl->cursor_elt == -1 && ddl->cursor_elt != -1))
|
|
5994 {
|
|
5995 return 0;
|
|
5996 }
|
|
5997
|
|
5998 /* If the changed area also ends on this line, then we may be in
|
|
5999 business. Update everything and return success. */
|
826
|
6000 if (end_unchanged >= ddl->charpos && end_unchanged <= ddl->end_charpos)
|
428
|
6001 {
|
|
6002 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b));
|
|
6003 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b));
|
|
6004 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp),
|
|
6005 w->buffer);
|
|
6006 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm),
|
|
6007 w->buffer);
|
|
6008
|
|
6009 if (ddl->cursor_elt != -1)
|
|
6010 {
|
|
6011 w->last_point_x[DESIRED_DISP] = ddl->cursor_elt;
|
|
6012 w->last_point_y[DESIRED_DISP] = line;
|
|
6013 }
|
|
6014
|
|
6015 redisplay_update_line (w, line, line, 1);
|
|
6016 regenerate_modeline (w);
|
|
6017
|
|
6018 /* #### For now we just flush the cache until this has been
|
|
6019 tested. After that is done, this should correct the
|
|
6020 cache directly. */
|
|
6021 Dynarr_reset (w->line_start_cache);
|
|
6022
|
|
6023 /* Adjust the extent changed boundaries to remove any
|
|
6024 overlap with the buffer changes since we've just
|
|
6025 successfully updated that area. */
|
|
6026 if (extent_beg_unchanged != -1
|
|
6027 && extent_beg_unchanged >= beg_unchanged
|
|
6028 && extent_beg_unchanged < end_unchanged)
|
|
6029 extent_beg_unchanged = end_unchanged;
|
|
6030
|
|
6031 if (extent_end_unchanged != -1
|
|
6032 && extent_end_unchanged >= beg_unchanged
|
|
6033 && extent_end_unchanged < end_unchanged)
|
|
6034 extent_end_unchanged = beg_unchanged - 1;
|
|
6035
|
|
6036 if (extent_end_unchanged <= extent_beg_unchanged)
|
|
6037 extent_beg_unchanged = extent_end_unchanged = -1;
|
|
6038
|
|
6039 /* This could lead to odd results if it fails, but since the
|
|
6040 buffer changes update succeeded this probably will to.
|
|
6041 We already know that the extent changes start at or after
|
|
6042 the line because we checked before entering the loop. */
|
|
6043 if (extent_beg_unchanged != -1
|
|
6044 && extent_end_unchanged != -1
|
826
|
6045 && ((extent_beg_unchanged < ddl->charpos)
|
|
6046 || (extent_end_unchanged > ddl->end_charpos)))
|
428
|
6047 return regenerate_window_extents_only_changed (w, startp, pointm,
|
|
6048 extent_beg_unchanged,
|
|
6049 extent_end_unchanged);
|
|
6050 else
|
|
6051 return 1;
|
|
6052 }
|
|
6053 }
|
|
6054
|
|
6055 /* Oh, well. */
|
|
6056 return 0;
|
|
6057 }
|
|
6058
|
|
6059 /* Given a window and a point, update the given display lines such
|
|
6060 that point is displayed in the middle of the window.
|
|
6061 Return the window's new start position. */
|
|
6062
|
665
|
6063 static Charbpos
|
|
6064 regenerate_window_point_center (struct window *w, Charbpos point, int type)
|
428
|
6065 {
|
665
|
6066 Charbpos startp;
|
428
|
6067
|
|
6068 /* We need to make sure that the modeline is generated so that the
|
|
6069 window height can be calculated correctly. */
|
|
6070 ensure_modeline_generated (w, type);
|
|
6071
|
|
6072 startp = start_with_line_at_pixpos (w, point, window_half_pixpos (w));
|
|
6073 regenerate_window (w, startp, point, type);
|
|
6074 Fset_marker (w->start[type], make_int (startp), w->buffer);
|
|
6075
|
|
6076 return startp;
|
|
6077 }
|
|
6078
|
|
6079 /* Given a window and a set of display lines, return a boolean
|
|
6080 indicating whether the given point is contained within. */
|
|
6081
|
|
6082 static int
|
665
|
6083 point_visible (struct window *w, Charbpos point, int type)
|
428
|
6084 {
|
|
6085 struct buffer *b = XBUFFER (w->buffer);
|
|
6086 display_line_dynarr *dla = window_display_lines (w, type);
|
|
6087 int first_line;
|
|
6088
|
|
6089 if (Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
|
|
6090 first_line = 1;
|
|
6091 else
|
|
6092 first_line = 0;
|
|
6093
|
|
6094 if (Dynarr_length (dla) > first_line)
|
|
6095 {
|
665
|
6096 Charbpos start, end;
|
428
|
6097 struct display_line *dl = Dynarr_atp (dla, first_line);
|
|
6098
|
826
|
6099 start = dl->charpos;
|
428
|
6100 end = BUF_Z (b) - w->window_end_pos[type] - 1;
|
|
6101
|
|
6102 if (point >= start && point <= end)
|
|
6103 {
|
|
6104 if (!MINI_WINDOW_P (w) && scroll_on_clipped_lines)
|
|
6105 {
|
|
6106 dl = Dynarr_atp (dla, Dynarr_length (dla) - 1);
|
|
6107
|
826
|
6108 if (point >= (dl->charpos + dl->offset)
|
|
6109 && point <= (dl->end_charpos + dl->offset))
|
428
|
6110 return !dl->clip;
|
|
6111 else
|
|
6112 return 1;
|
|
6113 }
|
|
6114 else
|
|
6115 return 1;
|
|
6116 }
|
|
6117 else
|
|
6118 return 0;
|
|
6119 }
|
|
6120 else
|
|
6121 return 0;
|
|
6122 }
|
|
6123
|
|
6124 /* Return pixel position the middle of the window, not including the
|
|
6125 modeline and any potential horizontal scrollbar. */
|
|
6126
|
|
6127 int
|
|
6128 window_half_pixpos (struct window *w)
|
|
6129 {
|
|
6130 return WINDOW_TEXT_TOP (w) + (WINDOW_TEXT_HEIGHT (w) >> 1);
|
|
6131 }
|
|
6132
|
|
6133 /* Return the display line which is currently in the middle of the
|
|
6134 window W for display lines TYPE. */
|
|
6135
|
|
6136 int
|
665
|
6137 line_at_center (struct window *w, int type, Charbpos start, Charbpos point)
|
428
|
6138 {
|
|
6139 display_line_dynarr *dla;
|
|
6140 int half;
|
|
6141 int elt;
|
|
6142 int first_elt = (MINI_WINDOW_P (w) ? 0 : 1);
|
|
6143
|
|
6144 if (type == CMOTION_DISP)
|
|
6145 regenerate_window (w, start, point, type);
|
|
6146
|
|
6147 dla = window_display_lines (w, type);
|
|
6148 half = window_half_pixpos (w);
|
|
6149
|
|
6150 for (elt = first_elt; elt < Dynarr_length (dla); elt++)
|
|
6151 {
|
|
6152 struct display_line *dl = Dynarr_atp (dla, elt);
|
|
6153 int line_bot = dl->ypos + dl->descent;
|
|
6154
|
|
6155 if (line_bot > half)
|
|
6156 return elt;
|
|
6157 }
|
|
6158
|
|
6159 /* We may not have a line at the middle if the end of the buffer is
|
|
6160 being displayed. */
|
|
6161 return -1;
|
|
6162 }
|
|
6163
|
|
6164 /* Return a value for point that would place it at the beginning of
|
|
6165 the line which is in the middle of the window. */
|
|
6166
|
665
|
6167 Charbpos
|
|
6168 point_at_center (struct window *w, int type, Charbpos start, Charbpos point)
|
428
|
6169 {
|
|
6170 /* line_at_center will regenerate the display structures, if necessary. */
|
|
6171 int line = line_at_center (w, type, start, point);
|
|
6172
|
|
6173 if (line == -1)
|
|
6174 return BUF_ZV (XBUFFER (w->buffer));
|
|
6175 else
|
|
6176 {
|
|
6177 display_line_dynarr *dla = window_display_lines (w, type);
|
|
6178 struct display_line *dl = Dynarr_atp (dla, line);
|
|
6179
|
826
|
6180 return dl->charpos;
|
428
|
6181 }
|
|
6182 }
|
|
6183
|
|
6184 /* For a given window, ensure that the current visual representation
|
|
6185 is accurate. */
|
|
6186
|
|
6187 static void
|
|
6188 redisplay_window (Lisp_Object window, int skip_selected)
|
|
6189 {
|
|
6190 struct window *w = XWINDOW (window);
|
|
6191 struct frame *f = XFRAME (w->frame);
|
|
6192 struct device *d = XDEVICE (f->device);
|
|
6193 Lisp_Object old_buffer = w->buffer;
|
|
6194 Lisp_Object the_buffer = w->buffer;
|
|
6195 struct buffer *b;
|
|
6196 int echo_active = 0;
|
|
6197 int startp = 1;
|
|
6198 int pointm;
|
|
6199 int old_startp = 1;
|
|
6200 int old_pointm = 1;
|
|
6201 int selected_in_its_frame;
|
|
6202 int selected_globally;
|
|
6203 int skip_output = 0;
|
|
6204 int truncation_changed;
|
|
6205 int inactive_minibuffer =
|
|
6206 (MINI_WINDOW_P (w) &&
|
|
6207 (f != device_selected_frame (d)) &&
|
|
6208 !is_surrogate_for_selected_frame (f));
|
|
6209
|
|
6210 /* #### In the new world this function actually does a bunch of
|
|
6211 optimizations such as buffer-based scrolling, but none of that is
|
|
6212 implemented yet. */
|
|
6213
|
|
6214 /* If this is a combination window, do its children; that's all.
|
|
6215 The selected window is always a leaf so we don't check for
|
|
6216 skip_selected here. */
|
|
6217 if (!NILP (w->vchild))
|
|
6218 {
|
|
6219 redisplay_windows (w->vchild, skip_selected);
|
|
6220 return;
|
|
6221 }
|
|
6222 if (!NILP (w->hchild))
|
|
6223 {
|
|
6224 redisplay_windows (w->hchild, skip_selected);
|
|
6225 return;
|
|
6226 }
|
|
6227
|
|
6228 /* Is this window the selected window on its frame? */
|
|
6229 selected_in_its_frame = (w == XWINDOW (FRAME_SELECTED_WINDOW (f)));
|
|
6230 selected_globally =
|
|
6231 selected_in_its_frame &&
|
|
6232 EQ(DEVICE_CONSOLE(d), Vselected_console) &&
|
|
6233 XDEVICE(CONSOLE_SELECTED_DEVICE(XCONSOLE(DEVICE_CONSOLE(d)))) == d &&
|
|
6234 XFRAME(DEVICE_SELECTED_FRAME(d)) == f;
|
|
6235 if (skip_selected && selected_in_its_frame)
|
|
6236 return;
|
|
6237
|
|
6238 /* It is possible that the window is not fully initialized yet. */
|
|
6239 if (NILP (w->buffer))
|
|
6240 return;
|
|
6241
|
|
6242 if (MINI_WINDOW_P (w) && echo_area_active (f))
|
|
6243 {
|
|
6244 w->buffer = the_buffer = Vecho_area_buffer;
|
|
6245 echo_active = 1;
|
|
6246 }
|
|
6247
|
|
6248 b = XBUFFER (w->buffer);
|
|
6249
|
|
6250 if (echo_active)
|
|
6251 {
|
|
6252 old_pointm = selected_globally
|
|
6253 ? BUF_PT (b)
|
|
6254 : marker_position (w->pointm[CURRENT_DISP]);
|
|
6255 pointm = 1;
|
|
6256 }
|
|
6257 else
|
|
6258 {
|
|
6259 if (selected_globally)
|
|
6260 {
|
|
6261 pointm = BUF_PT (b);
|
|
6262 }
|
|
6263 else
|
|
6264 {
|
|
6265 pointm = marker_position (w->pointm[CURRENT_DISP]);
|
|
6266
|
|
6267 if (pointm < BUF_BEGV (b))
|
|
6268 pointm = BUF_BEGV (b);
|
|
6269 else if (pointm > BUF_ZV (b))
|
|
6270 pointm = BUF_ZV (b);
|
|
6271 }
|
|
6272 }
|
|
6273 Fset_marker (w->pointm[DESIRED_DISP], make_int (pointm), the_buffer);
|
|
6274
|
|
6275 /* If the buffer has changed we have to invalidate all of our face
|
|
6276 cache elements. */
|
|
6277 if ((!echo_active && b != window_display_buffer (w))
|
|
6278 || !Dynarr_length (w->face_cachels)
|
|
6279 || f->faces_changed)
|
|
6280 reset_face_cachels (w);
|
|
6281 else
|
|
6282 mark_face_cachels_as_not_updated (w);
|
|
6283
|
|
6284 /* Ditto the glyph cache elements, although we do *not* invalidate
|
|
6285 the cache purely because glyphs have changed - this is now
|
|
6286 handled by the dirty flag.*/
|
|
6287 if ((!echo_active && b != window_display_buffer (w))
|
440
|
6288 || !Dynarr_length (w->glyph_cachels) || f->faces_changed)
|
428
|
6289 reset_glyph_cachels (w);
|
|
6290 else
|
|
6291 mark_glyph_cachels_as_not_updated (w);
|
|
6292
|
|
6293 /* If the marker's buffer is not the window's buffer, then we need
|
|
6294 to find a new starting position. */
|
|
6295 if (!MINI_WINDOW_P (w)
|
|
6296 && !EQ (Fmarker_buffer (w->start[CURRENT_DISP]), w->buffer))
|
|
6297 {
|
|
6298 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP);
|
|
6299
|
|
6300 goto regeneration_done;
|
|
6301 }
|
|
6302
|
|
6303 if (echo_active)
|
|
6304 {
|
|
6305 old_startp = marker_position (w->start[CURRENT_DISP]);
|
|
6306 startp = 1;
|
|
6307 }
|
|
6308 else
|
|
6309 {
|
|
6310 startp = marker_position (w->start[CURRENT_DISP]);
|
|
6311 if (startp < BUF_BEGV (b))
|
|
6312 startp = BUF_BEGV (b);
|
|
6313 else if (startp > BUF_ZV (b))
|
|
6314 startp = BUF_ZV (b);
|
|
6315 }
|
|
6316 Fset_marker (w->start[DESIRED_DISP], make_int (startp), the_buffer);
|
|
6317
|
|
6318 truncation_changed = (find_window_mirror (w)->truncate_win !=
|
647
|
6319 (unsigned int) window_truncation_on (w));
|
428
|
6320
|
|
6321 /* If w->force_start is set, then some function set w->start and we
|
|
6322 should display from there and change point, if necessary, to
|
|
6323 ensure that it is visible. */
|
|
6324 if (w->force_start || inactive_minibuffer)
|
|
6325 {
|
|
6326 w->force_start = 0;
|
|
6327 w->last_modified[DESIRED_DISP] = Qzero;
|
|
6328 w->last_facechange[DESIRED_DISP] = Qzero;
|
|
6329
|
|
6330 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6331
|
|
6332 if (!point_visible (w, pointm, DESIRED_DISP) && !inactive_minibuffer)
|
|
6333 {
|
|
6334 pointm = point_at_center (w, DESIRED_DISP, 0, 0);
|
|
6335
|
|
6336 if (selected_globally)
|
|
6337 BUF_SET_PT (b, pointm);
|
|
6338
|
|
6339 Fset_marker (w->pointm[DESIRED_DISP], make_int (pointm),
|
|
6340 the_buffer);
|
|
6341
|
|
6342 /* #### BUFU amounts of overkill just to get the cursor
|
|
6343 location marked properly. FIX ME FIX ME FIX ME */
|
|
6344 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6345 }
|
|
6346
|
|
6347 goto regeneration_done;
|
|
6348 }
|
|
6349
|
|
6350 /* If nothing has changed since the last redisplay, then we just
|
|
6351 need to make sure that point is still visible. */
|
|
6352 if (XINT (w->last_modified[CURRENT_DISP]) >= BUF_MODIFF (b)
|
|
6353 && XINT (w->last_facechange[CURRENT_DISP]) >= BUF_FACECHANGE (b)
|
|
6354 && pointm >= startp
|
|
6355 /* This check is to make sure we restore the minibuffer after a
|
|
6356 temporary change to the echo area. */
|
|
6357 && !(MINI_WINDOW_P (w) && f->buffers_changed)
|
|
6358 && !f->frame_changed
|
|
6359 && !truncation_changed
|
442
|
6360 /* check whether start is really at the beginning of a line GE */
|
428
|
6361 && (!w->start_at_line_beg || beginning_of_line_p (b, startp))
|
|
6362 )
|
|
6363 {
|
|
6364 /* Check if the cursor has actually moved. */
|
|
6365 if (EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer)
|
|
6366 && pointm == marker_position (w->last_point[CURRENT_DISP])
|
|
6367 && selected_globally
|
|
6368 && !w->windows_changed
|
|
6369 && !f->clip_changed
|
|
6370 && !f->extents_changed
|
|
6371 && !f->faces_changed
|
|
6372 && !f->glyphs_changed
|
|
6373 && !f->subwindows_changed
|
442
|
6374 /* && !f->subwindows_state_changed*/
|
428
|
6375 && !f->point_changed
|
|
6376 && !f->windows_structure_changed)
|
|
6377 {
|
|
6378 /* If not, we're done. */
|
|
6379 if (f->modeline_changed)
|
|
6380 regenerate_modeline (w);
|
|
6381
|
|
6382 skip_output = 1;
|
|
6383 goto regeneration_done;
|
|
6384 }
|
|
6385 else
|
|
6386 {
|
|
6387 /* If the new point is visible in the redisplay structures,
|
|
6388 then let the output update routines handle it, otherwise
|
|
6389 do things the hard way. */
|
|
6390 if (!w->windows_changed
|
|
6391 && !f->clip_changed
|
|
6392 && !f->extents_changed
|
|
6393 && !f->faces_changed
|
|
6394 && !f->glyphs_changed
|
|
6395 && !f->subwindows_changed
|
442
|
6396 /* && !f->subwindows_state_changed*/
|
428
|
6397 && !f->windows_structure_changed)
|
|
6398 {
|
|
6399 if (point_visible (w, pointm, CURRENT_DISP)
|
|
6400 && w->last_point_x[CURRENT_DISP] != -1
|
|
6401 && w->last_point_y[CURRENT_DISP] != -1)
|
|
6402 {
|
|
6403 if (redisplay_move_cursor (w, pointm, FRAME_TTY_P (f)))
|
|
6404 {
|
|
6405 /* Always regenerate in case it is displaying
|
|
6406 the current line or column. */
|
|
6407 regenerate_modeline (w);
|
|
6408
|
|
6409 skip_output = 1;
|
|
6410 goto regeneration_done;
|
|
6411 }
|
|
6412 }
|
|
6413 else if (!selected_in_its_frame && !f->point_changed)
|
|
6414 {
|
|
6415 if (f->modeline_changed)
|
|
6416 regenerate_modeline (w);
|
|
6417
|
|
6418 skip_output = 1;
|
|
6419 goto regeneration_done;
|
|
6420 }
|
|
6421 }
|
|
6422
|
|
6423 /* If we weren't able to take the shortcut method, then use
|
|
6424 the brute force method. */
|
|
6425 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6426
|
|
6427 if (point_visible (w, pointm, DESIRED_DISP))
|
|
6428 goto regeneration_done;
|
|
6429 }
|
|
6430 }
|
|
6431
|
|
6432 /* Check if the starting point is no longer at the beginning of a
|
|
6433 line, in which case find a new starting point. We also recenter
|
|
6434 if our start position is equal to point-max. Otherwise we'll end
|
|
6435 up with a blank window. */
|
|
6436 else if (((w->start_at_line_beg || MINI_WINDOW_P (w))
|
|
6437 && !(startp == BUF_BEGV (b)
|
|
6438 || BUF_FETCH_CHAR (b, startp - 1) == '\n'))
|
|
6439 || (pointm == startp &&
|
|
6440 EQ (Fmarker_buffer (w->last_start[CURRENT_DISP]), w->buffer) &&
|
|
6441 startp < marker_position (w->last_start[CURRENT_DISP]))
|
|
6442 || (startp == BUF_ZV (b)))
|
|
6443 {
|
|
6444 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP);
|
|
6445
|
|
6446 goto regeneration_done;
|
|
6447 }
|
|
6448 /* See if we can update the data structures locally based on
|
|
6449 knowledge of what changed in the buffer. */
|
|
6450 else if (!w->windows_changed
|
|
6451 && !f->clip_changed
|
|
6452 && !f->faces_changed
|
|
6453 && !f->glyphs_changed
|
|
6454 && !f->subwindows_changed
|
442
|
6455 /* && !f->subwindows_state_changed*/
|
428
|
6456 && !f->windows_structure_changed
|
|
6457 && !f->frame_changed
|
|
6458 && !truncation_changed
|
|
6459 && pointm >= startp
|
|
6460 && regenerate_window_incrementally (w, startp, pointm))
|
|
6461 {
|
|
6462 if (f->modeline_changed
|
|
6463 || XINT (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b)
|
|
6464 || XINT (w->last_facechange[CURRENT_DISP]) < BUF_FACECHANGE (b))
|
|
6465 regenerate_modeline (w);
|
|
6466
|
|
6467 skip_output = 1;
|
|
6468 goto regeneration_done;
|
|
6469 }
|
|
6470 /* #### This is where a check for structure based scrolling would go. */
|
|
6471 /* If all else fails, try just regenerating and see what happens. */
|
|
6472 else
|
|
6473 {
|
|
6474 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6475
|
|
6476 if (point_visible (w, pointm, DESIRED_DISP))
|
|
6477 goto regeneration_done;
|
|
6478 }
|
|
6479
|
|
6480 /* We still haven't gotten the window regenerated with point
|
|
6481 visible. Next we try scrolling a little and see if point comes
|
|
6482 back onto the screen. */
|
|
6483 if (scroll_step > 0)
|
|
6484 {
|
|
6485 int scrolled = scroll_conservatively;
|
|
6486 for (; scrolled >= 0; scrolled -= scroll_step)
|
|
6487 {
|
|
6488 startp = vmotion (w, startp,
|
|
6489 (pointm < startp) ? -scroll_step : scroll_step, 0);
|
|
6490 regenerate_window (w, startp, pointm, DESIRED_DISP);
|
|
6491
|
|
6492 if (point_visible (w, pointm, DESIRED_DISP))
|
|
6493 goto regeneration_done;
|
|
6494 }
|
|
6495 }
|
|
6496
|
|
6497 /* We still haven't managed to get the screen drawn with point on
|
|
6498 the screen, so just center it and be done with it. */
|
|
6499 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP);
|
|
6500
|
|
6501
|
|
6502 regeneration_done:
|
|
6503
|
|
6504 /* If the window's frame is changed then reset the current display
|
|
6505 lines in order to force a full repaint. */
|
|
6506 if (f->frame_changed)
|
|
6507 {
|
|
6508 display_line_dynarr *cla = window_display_lines (w, CURRENT_DISP);
|
|
6509
|
|
6510 Dynarr_reset (cla);
|
|
6511 }
|
|
6512
|
|
6513 /* Must do this before calling redisplay_output_window because it
|
|
6514 sets some markers on the window. */
|
|
6515 if (echo_active)
|
|
6516 {
|
|
6517 w->buffer = old_buffer;
|
|
6518 Fset_marker (w->pointm[DESIRED_DISP], make_int (old_pointm), old_buffer);
|
|
6519 Fset_marker (w->start[DESIRED_DISP], make_int (old_startp), old_buffer);
|
|
6520 }
|
|
6521
|
|
6522 /* These also have to be set before calling redisplay_output_window
|
|
6523 since it sets the CURRENT_DISP values based on them. */
|
|
6524 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b));
|
|
6525 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b));
|
|
6526 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp), w->buffer);
|
|
6527 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm), w->buffer);
|
|
6528
|
|
6529 if (!skip_output)
|
|
6530 {
|
665
|
6531 Charbpos start = marker_position (w->start[DESIRED_DISP]);
|
|
6532 Charbpos end = (w->window_end_pos[DESIRED_DISP] == -1
|
428
|
6533 ? BUF_ZV (b)
|
|
6534 : BUF_Z (b) - w->window_end_pos[DESIRED_DISP] - 1);
|
|
6535 /* Don't pollute the cache if not sure if we are correct */
|
|
6536 if (w->start_at_line_beg)
|
|
6537 update_line_start_cache (w, start, end, pointm, 1);
|
|
6538 redisplay_output_window (w);
|
|
6539 /*
|
|
6540 * If we just displayed the echo area, the line start cache is
|
|
6541 * no longer valid, because the minibuffer window is associated
|
|
6542 * with the window now.
|
|
6543 */
|
|
6544 if (echo_active)
|
|
6545 w->line_cache_last_updated = make_int (-1);
|
|
6546 }
|
|
6547
|
|
6548 /* #### This should be dependent on face changes and will need to be
|
|
6549 somewhere else once tty updates occur on a per-frame basis. */
|
|
6550 mark_face_cachels_as_clean (w);
|
|
6551
|
438
|
6552 /* The glyph cachels only get dirty if someone changed something.
|
|
6553 Since redisplay has now effectively ended we can reset the dirty
|
|
6554 flag since everything must be up-to-date. */
|
428
|
6555 if (glyphs_changed)
|
|
6556 mark_glyph_cachels_as_clean (w);
|
|
6557
|
|
6558 w->windows_changed = 0;
|
|
6559 }
|
|
6560
|
|
6561 /* Call buffer_reset_changes for all buffers present in any window
|
|
6562 currently visible in all frames on all devices. #### There has to
|
|
6563 be a better way to do this. */
|
|
6564
|
|
6565 static int
|
2286
|
6566 reset_buffer_changes_mapfun (struct window *w, void *UNUSED (closure))
|
428
|
6567 {
|
|
6568 buffer_reset_changes (XBUFFER (w->buffer));
|
|
6569 return 0;
|
|
6570 }
|
|
6571
|
|
6572 static void
|
|
6573 reset_buffer_changes (void)
|
|
6574 {
|
|
6575 Lisp_Object frmcons, devcons, concons;
|
|
6576
|
|
6577 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
6578 {
|
|
6579 struct frame *f = XFRAME (XCAR (frmcons));
|
|
6580
|
|
6581 if (FRAME_REPAINT_P (f))
|
|
6582 map_windows (f, reset_buffer_changes_mapfun, 0);
|
|
6583 }
|
|
6584 }
|
|
6585
|
|
6586 /* Ensure that all windows underneath the given window in the window
|
|
6587 hierarchy are correctly displayed. */
|
|
6588
|
|
6589 static void
|
|
6590 redisplay_windows (Lisp_Object window, int skip_selected)
|
|
6591 {
|
|
6592 for (; !NILP (window) ; window = XWINDOW (window)->next)
|
|
6593 {
|
|
6594 redisplay_window (window, skip_selected);
|
|
6595 }
|
|
6596 }
|
|
6597
|
1318
|
6598 /* Register an action to be called at the end of redisplay.
|
|
6599 in_display is 0 when this is called.
|
|
6600 This is used when it is discovered that an action needs to be taken,
|
|
6601 but it's during redisplay, so it's not safe. (Typically, it's an action
|
|
6602 that needs to enter redisplay, which can't happen reentrantly.)
|
|
6603
|
|
6604 NEVER signal an error in these functions.
|
|
6605 */
|
|
6606
|
|
6607 void
|
|
6608 register_post_redisplay_action (void (*fun) (Lisp_Object), Lisp_Object arg)
|
|
6609 {
|
|
6610 Vpost_redisplay_actions = nconc2 (Vpost_redisplay_actions,
|
|
6611 list1 (Fcons (make_opaque_ptr
|
|
6612 ((void *) fun), arg)));
|
|
6613 }
|
|
6614
|
1320
|
6615 static int running_post_redisplay_actions;
|
|
6616
|
1318
|
6617 static void
|
|
6618 run_post_redisplay_actions (void)
|
|
6619 {
|
1320
|
6620 int depth;
|
|
6621
|
|
6622 if (running_post_redisplay_actions)
|
|
6623 return;
|
|
6624
|
|
6625 depth = internal_bind_int (&running_post_redisplay_actions, 1);
|
|
6626 /* If the function pushes further actions, they will be tacked onto
|
|
6627 the end of the list, and we'll run them when we're done with the
|
|
6628 current ones. */
|
1318
|
6629 while (!NILP (Vpost_redisplay_actions))
|
|
6630 {
|
|
6631 Lisp_Object car = XCAR (Vpost_redisplay_actions);
|
|
6632 void (*fun) (Lisp_Object) =
|
|
6633 (void (*)(Lisp_Object)) get_opaque_ptr (XCAR (car));
|
|
6634 (*fun) (XCDR (car));
|
|
6635 free_opaque_ptr (XCAR (car));
|
|
6636 free_cons (car);
|
|
6637 Vpost_redisplay_actions = XCDR (Vpost_redisplay_actions);
|
|
6638 }
|
1320
|
6639 unbind_to (depth);
|
1318
|
6640 }
|
|
6641
|
|
6642 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS
|
|
6643
|
|
6644 static Lisp_Object
|
2286
|
6645 commit_ritual_suicide (Lisp_Object UNUSED (ceci_nest_pas_une_pipe))
|
1318
|
6646 {
|
|
6647 assert (!in_display);
|
|
6648 return Qnil;
|
|
6649 }
|
|
6650
|
|
6651 #endif
|
|
6652
|
|
6653 /* Within the guts of redisplay, we are defenseless and cannot allow any of
|
|
6654 the following to happen:
|
|
6655
|
|
6656 1) garbage collection
|
|
6657 2) QUIT
|
|
6658 3) any non-local exits
|
|
6659 4) frame size changes
|
|
6660 5) deletion of any buffers, windows, frames, etc.
|
|
6661 6) modification of buffer text
|
|
6662 7) reentrant entry of redisplay (see the stack trace above
|
|
6663 generate_displayable_area())
|
|
6664
|
|
6665 The general reason is that the redisplay code is written to assume that
|
|
6666 it is the only code running, and thus (a) cannot tolerate structures
|
|
6667 changed out from under it (hence 1, 4, 5, 6, 7) and (b) at various points
|
|
6668 within redisplay the redisplay structures may be in an inconsistent
|
|
6669 state and there are no unwind-protects to clean the structures up in
|
|
6670 case of non-local exit (hence 2, 3). Fixing redisplay to address these
|
|
6671 issues is hard and perhaps not worth it (and might slow things down a
|
|
6672 fair amount). We address 1, 4, 5 and 6 ourselves inside of
|
|
6673 enter_redisplay_critical_section() by simply inhibiting them, but we
|
|
6674 cannot handle 2 and 3, which must be handled at the actual point where
|
|
6675 they may occur (especially, internal_equal() or any place that may call
|
|
6676 Lisp), by wrapping the code in call_trapping_problems() or
|
|
6677 call_with_suspended_errors(). [[ NOTE: We could address QUIT by inhibiting
|
|
6678 it but this would be anti-social because it would prevent the user from
|
|
6679 interrupting any Lisp code called within the critical section. With the
|
|
6680 call_*() wrapping, C-g will interrupt the Lisp code and throw back to
|
|
6681 the innermost wrapping. ]] In fact we do turn off QUIT handling, since
|
|
6682 it's just too dangerous otherwise. See below.
|
|
6683
|
|
6684 Code calling enter_redisplay_critical_section() must check for reentrancy
|
|
6685 (#7) and take appropriate corrective action.
|
|
6686
|
|
6687 To help debug potential problems, we arrange (when
|
|
6688 ERROR_CHECK_TRAPPING_PROBLEMS is set) to crash automatically every time
|
|
6689 we execute QUIT or call Lisp code unless proper wrapping is in place, as
|
|
6690 well as further checks when we actually Fsignal(), Fthrow(),
|
|
6691 garbage_collect_1().
|
|
6692
|
|
6693 #### If a frame-size change does occur we should probably actually be
|
|
6694 preempting redisplay. */
|
|
6695
|
|
6696 /* Count of number of recursive times we call
|
|
6697 enter_redisplay_critical_section() or
|
|
6698 enter_redisplay_critical_section_maybe().
|
|
6699 enter_redisplay_critical_section() cannot occur reentrantly but we have
|
|
6700 to know in the *maybe() version whether to exit the section when we're
|
|
6701 done. */
|
|
6702 static int in_display_nesting;
|
|
6703
|
|
6704 static Lisp_Object
|
2286
|
6705 end_hold_frame_size_changes (Lisp_Object UNUSED (obj))
|
1318
|
6706 {
|
|
6707 if (!hold_frame_size_changes)
|
|
6708 {
|
|
6709 /* we used to have a function to do this for only one frame, and
|
|
6710 it was typical to call it at the end of a critical section
|
|
6711 (which occurs once per frame); but what then happens if multiple
|
|
6712 frames have frame changes held up?
|
|
6713
|
|
6714 This means we are O(N^2) over frames. I seriously doubt it matters.
|
|
6715 --ben */
|
|
6716 Lisp_Object frmcons, devcons, concons;
|
|
6717
|
|
6718 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
6719 {
|
|
6720 struct frame *f = XFRAME (XCAR (frmcons));
|
|
6721 if (f->size_change_pending)
|
|
6722 change_frame_size (f, f->new_height, f->new_width, 0);
|
|
6723 }
|
|
6724 }
|
|
6725 return Qnil;
|
|
6726 }
|
|
6727
|
|
6728 /* Call this to temporarily prevent frame-size changes from being processed.
|
|
6729 To undo, use unbind_to(), passing it the value returned by this function.
|
|
6730 */
|
|
6731
|
|
6732 int
|
|
6733 begin_hold_frame_size_changes (void)
|
|
6734 {
|
|
6735 int depth = specpdl_depth ();
|
|
6736 record_unwind_protect (end_hold_frame_size_changes, Qnil);
|
|
6737 internal_bind_int (&hold_frame_size_changes, 1 + hold_frame_size_changes);
|
|
6738 return depth;
|
|
6739 }
|
|
6740
|
|
6741 int
|
|
6742 enter_redisplay_critical_section (void)
|
|
6743 {
|
|
6744 int depth = specpdl_depth ();
|
|
6745
|
|
6746 /* Reentrant entry is deadly. The calling function must check for this. */
|
|
6747 assert (!in_display);
|
|
6748 begin_hold_frame_size_changes ();
|
|
6749 /* Make sure in_display gets reset, but don't set it yet so that
|
|
6750 commit_ritual_suicide() can be used. */
|
|
6751 internal_bind_int (&in_display, 0);
|
|
6752 internal_bind_int (&in_display_nesting, 1 + in_display_nesting);
|
|
6753 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS
|
|
6754 /* Force every call to QUIT to check for in_displayness. This will
|
|
6755 verify proper wrapping, as in the previous comment, aborting if not. */
|
|
6756 something_happened++;
|
|
6757 /* Verify that no nonlocal exits blow past us. */
|
|
6758 record_unwind_protect (commit_ritual_suicide, Qnil);
|
|
6759 #endif
|
|
6760 in_display++;
|
|
6761
|
|
6762 set_trapping_problems_flags (INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY);
|
|
6763 /* Even checking for QUIT can cause arbitrary Lisp code to be executed,
|
|
6764 e.g. through a menu handler. We really don't want that happening
|
|
6765 inside of redisplay. Code that we `eval' is at least written with the
|
|
6766 expectation that it's inside of redisplay, and shouldn't try anything
|
|
6767 weird; but that's not the case for menu code (e.g. custom loads huge
|
|
6768 amounts of LISP FILES from a menu handler! FMH!). Safest just to turn
|
|
6769 this off. We could turn it on using UNINHIBIT_QUIT or
|
|
6770 begin_do_check_for_quit() in certain places if we want, if we know
|
|
6771 it's not in an especially tricky place. */
|
|
6772 begin_dont_check_for_quit ();
|
|
6773 return depth;
|
|
6774 }
|
|
6775
|
|
6776 void
|
|
6777 exit_redisplay_critical_section (int depth)
|
|
6778 {
|
|
6779 in_display--;
|
|
6780 assert (!in_display);
|
|
6781 unbind_to (depth);
|
|
6782
|
|
6783 run_post_redisplay_actions ();
|
|
6784 }
|
|
6785
|
|
6786 /* Enter the redisplay critical section if we're not already in it. This
|
|
6787 is for code that needs frame changes held up and other protections from
|
|
6788 being inside, but doesn't modify the redisplay structures, and doesn't
|
|
6789 look at them in a way that they will be confused by inconsistencies. */
|
|
6790
|
|
6791 int
|
|
6792 enter_redisplay_critical_section_maybe (void)
|
|
6793 {
|
|
6794 if (!in_display)
|
|
6795 return enter_redisplay_critical_section ();
|
|
6796 else
|
|
6797 return internal_bind_int (&in_display_nesting, 1 + in_display_nesting);
|
|
6798 }
|
|
6799
|
|
6800 void
|
|
6801 exit_redisplay_critical_section_maybe (int depth)
|
|
6802 {
|
|
6803 if (in_display_nesting == 1)
|
|
6804 exit_redisplay_critical_section (depth);
|
|
6805 else
|
|
6806 unbind_to (depth);
|
|
6807 }
|
|
6808
|
1279
|
6809 /* Ensure that all windows on the given frame are correctly displayed.
|
|
6810 Return non-zero if pre-empted. */
|
428
|
6811
|
442
|
6812 int
|
428
|
6813 redisplay_frame (struct frame *f, int preemption_check)
|
|
6814 {
|
|
6815 struct device *d = XDEVICE (f->device);
|
853
|
6816 int depth;
|
428
|
6817
|
1279
|
6818 assert (f->init_finished);
|
|
6819
|
1318
|
6820 /* NOTE: Without sufficient checks for stream frames, we got weird
|
|
6821 crashes in pdump. These came and went very easily -- adding the
|
|
6822 critical-section code for redisplay was enough to trigger them.
|
|
6823 Perhaps I should have debugged them but there didn't seem to be any
|
|
6824 point. --ben */
|
1279
|
6825 if (FRAME_STREAM_P (f)) /* nothing to do */
|
|
6826 return 0;
|
|
6827
|
1318
|
6828 /* Reentrancy into redisplay can be deadly. See stack trace above
|
|
6829 generate_displayable_area(). */
|
|
6830 if (in_display)
|
|
6831 return 1;
|
|
6832
|
545
|
6833 if (preemption_check
|
|
6834 && !DEVICE_IMPL_FLAG (d, XDEVIMPF_DONT_PREEMPT_REDISPLAY))
|
428
|
6835 {
|
|
6836 /* The preemption check itself takes a lot of time,
|
|
6837 so normally don't do it here. We do it if called
|
|
6838 from Lisp, though (`redisplay-frame'). */
|
|
6839 int preempted;
|
|
6840
|
|
6841 REDISPLAY_PREEMPTION_CHECK;
|
|
6842 if (preempted)
|
|
6843 return 1;
|
|
6844 }
|
|
6845
|
442
|
6846 if (!internal_equal (f->old_buffer_alist, f->buffer_alist, 0))
|
|
6847 {
|
|
6848 Lisp_Object frame;
|
|
6849
|
|
6850 f->old_buffer_alist = Freplace_list (f->old_buffer_alist,
|
|
6851 f->buffer_alist);
|
793
|
6852 frame = wrap_frame (f);
|
442
|
6853 va_run_hook_with_args (Qbuffer_list_changed_hook, 1, frame);
|
|
6854 }
|
|
6855
|
428
|
6856 /* Before we put a hold on frame size changes, attempt to process
|
|
6857 any which are already pending. */
|
|
6858 if (f->size_change_pending)
|
|
6859 change_frame_size (f, f->new_height, f->new_width, 0);
|
|
6860
|
|
6861 /* If frame size might need to be changed, due to changed size
|
|
6862 of toolbars, scrollbars etc, change it now */
|
|
6863 if (f->size_slipped)
|
|
6864 {
|
|
6865 adjust_frame_size (f);
|
|
6866 assert (!f->size_slipped);
|
|
6867 }
|
|
6868
|
1318
|
6869 /* The menubar, toolbar, and icon updates should be done before
|
853
|
6870 enter_redisplay_critical_section is called and we are officially
|
3025
|
6871 `in_display'. They is because they tend to eval Lisp code, which
|
1318
|
6872 needs to be carefully wrapped within the critical section (and hence
|
|
6873 is difficult to debug). */
|
428
|
6874
|
|
6875 #ifdef HAVE_MENUBARS
|
|
6876 /* Update the menubar. It is done first since it could change
|
|
6877 the menubar's visibility. This way we avoid having flashing
|
|
6878 caused by an Expose event generated by the visibility change
|
|
6879 being handled. */
|
|
6880 update_frame_menubars (f);
|
|
6881 #endif /* HAVE_MENUBARS */
|
|
6882 #ifdef HAVE_TOOLBARS
|
905
|
6883 /* Update the toolbars geometry. We don't update the toolbars
|
|
6884 themselves at this point since the space they are trying to
|
|
6885 occupy may currently by occupied by gutter elements. Instead we
|
|
6886 update the geometry, then update the gutter geometry, then update
|
|
6887 the gutters - which will cause mapped windows to be repositioned
|
|
6888 - and finally update the toolbars. */
|
|
6889 update_frame_toolbars_geometry (f);
|
428
|
6890 #endif /* HAVE_TOOLBARS */
|
442
|
6891 /* Gutter update proper has to be done inside display when no frame
|
|
6892 size changes can occur, thus we separately update the gutter
|
|
6893 geometry here if it needs it. */
|
|
6894 update_frame_gutter_geometry (f);
|
428
|
6895
|
|
6896 /* If we clear the frame we have to force its contents to be redrawn. */
|
|
6897 if (f->clear)
|
|
6898 f->frame_changed = 1;
|
|
6899
|
442
|
6900 /* Invalidate the subwindow caches. We use subwindows_changed here
|
|
6901 to cause subwindows to get instantiated. This is because
|
428
|
6902 subwindows_state_changed is less strict - dealing with things
|
|
6903 like the clicked state of button. We have to do this before
|
|
6904 redisplaying the gutters as subwindows get unmapped in the
|
|
6905 process.*/
|
442
|
6906 if (f->frame_changed)
|
|
6907 reset_frame_subwindow_instance_cache (f);
|
|
6908
|
|
6909 if (f->frame_changed || f->subwindows_changed)
|
|
6910 {
|
428
|
6911 /* we have to do this so the gutter gets regenerated. */
|
|
6912 reset_gutter_display_lines (f);
|
|
6913 }
|
|
6914
|
853
|
6915 depth = enter_redisplay_critical_section ();
|
428
|
6916
|
|
6917 /* ----------------- BEGIN CRITICAL REDISPLAY SECTION ---------------- */
|
1318
|
6918
|
|
6919 /* See comments in enter_redisplay_critical_section() */
|
428
|
6920
|
442
|
6921 MAYBE_DEVMETH (d, frame_output_begin, (f));
|
|
6922
|
|
6923 /* We can now update the gutters, safe in the knowledge that our
|
|
6924 efforts won't get undone. */
|
|
6925
|
|
6926 /* This can call lisp, but redisplay is protected by binding
|
|
6927 inhibit_quit. More importantly the code involving display lines
|
|
6928 *assumes* that GC will not happen and so does not GCPRO
|
|
6929 anything. Since we use this code the whole time with the gutters
|
1318
|
6930 we cannot allow GC to happen when manipulating the gutters.
|
|
6931
|
|
6932 This must be inside of the critical section for various reasons.
|
|
6933 For example, it messes with display structures, which be left in
|
|
6934 an inconsistent state. */
|
442
|
6935 update_frame_gutters (f);
|
|
6936
|
428
|
6937 /* Erase the frame before outputting its contents. */
|
|
6938 if (f->clear)
|
|
6939 {
|
442
|
6940 MAYBE_DEVMETH (d, clear_frame, (f));
|
428
|
6941 }
|
|
6942
|
|
6943 /* Do the selected window first. */
|
|
6944 redisplay_window (FRAME_SELECTED_WINDOW (f), 0);
|
|
6945
|
|
6946 /* Then do the rest. */
|
|
6947 redisplay_windows (f->root_window, 1);
|
|
6948
|
442
|
6949 MAYBE_DEVMETH (d, frame_output_end, (f));
|
428
|
6950
|
|
6951 update_frame_title (f);
|
|
6952
|
905
|
6953 #ifdef HAVE_TOOLBARS
|
|
6954 /* Finally update the toolbars. It seems its possible to get in a
|
|
6955 cycle between updating the gutter and the toolbars. Basically we
|
|
6956 want to end up with both being up-to-date and this doesn't seem
|
|
6957 possible in a single pass. */
|
|
6958 update_frame_toolbars (f);
|
|
6959 #endif /* HAVE_TOOLBARS */
|
|
6960
|
428
|
6961 CLASS_RESET_CHANGED_FLAGS (f);
|
|
6962 f->window_face_cache_reset = 0;
|
|
6963 f->echo_area_garbaged = 0;
|
|
6964 f->clear = 0;
|
|
6965
|
|
6966 if (!f->size_change_pending)
|
|
6967 f->size_changed = 0;
|
|
6968
|
|
6969 /* ----------------- END CRITICAL REDISPLAY SECTION ---------------- */
|
|
6970
|
853
|
6971 /* Allow frame size changes to occur again. */
|
|
6972 exit_redisplay_critical_section (depth);
|
428
|
6973
|
|
6974 return 0;
|
|
6975 }
|
|
6976
|
440
|
6977 /* Ensure that all frames on the given device are correctly displayed.
|
|
6978 If AUTOMATIC is non-zero, and the device implementation indicates
|
|
6979 no automatic redisplay, as printers do, then the device is not
|
|
6980 redisplayed. AUTOMATIC is set to zero when called from lisp
|
|
6981 functions (redraw-device) and (redisplay-device), and to non-zero
|
|
6982 when called from "lazy" redisplay();
|
|
6983 */
|
428
|
6984
|
|
6985 static int
|
440
|
6986 redisplay_device (struct device *d, int automatic)
|
428
|
6987 {
|
|
6988 Lisp_Object frame, frmcons;
|
|
6989 int size_change_failed = 0;
|
|
6990 struct frame *f;
|
|
6991
|
545
|
6992 if (automatic && DEVICE_IMPL_FLAG (d, XDEVIMPF_NO_AUTO_REDISPLAY))
|
440
|
6993 return 0;
|
|
6994
|
428
|
6995 if (DEVICE_STREAM_P (d)) /* nothing to do */
|
|
6996 return 0;
|
|
6997
|
|
6998 /* It is possible that redisplay has been called before the
|
545
|
6999 device is fully initialized, or that the console implementation
|
|
7000 allows frameless devices. If so then continue with the next
|
|
7001 device. */
|
428
|
7002 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
7003 return 0;
|
|
7004
|
545
|
7005 if (!DEVICE_IMPL_FLAG (d, XDEVIMPF_DONT_PREEMPT_REDISPLAY))
|
|
7006 {
|
|
7007 int preempted;
|
|
7008 REDISPLAY_PREEMPTION_CHECK;
|
|
7009 if (preempted)
|
|
7010 return 1;
|
|
7011 }
|
428
|
7012
|
|
7013 /* Always do the selected frame first. */
|
|
7014 frame = DEVICE_SELECTED_FRAME (d);
|
|
7015
|
|
7016 f = XFRAME (frame);
|
|
7017
|
|
7018 if (f->icon_changed || f->windows_changed)
|
|
7019 update_frame_icon (f);
|
|
7020
|
|
7021 if (FRAME_REPAINT_P (f))
|
|
7022 {
|
|
7023 if (CLASS_REDISPLAY_FLAGS_CHANGEDP(f))
|
|
7024 {
|
588
|
7025 int preempted = redisplay_frame (f, 1);
|
545
|
7026 if (preempted)
|
|
7027 return 1;
|
|
7028 }
|
428
|
7029
|
|
7030 /* If the frame redisplay did not get preempted, then this flag
|
|
7031 should have gotten set to 0. It might be possible for that
|
|
7032 not to happen if a size change event were to occur at an odd
|
|
7033 time. To make sure we don't miss anything we simply don't
|
|
7034 reset the top level flags until the condition ends up being
|
|
7035 in the right state. */
|
|
7036 if (f->size_changed)
|
|
7037 size_change_failed = 1;
|
|
7038 }
|
|
7039
|
|
7040 DEVICE_FRAME_LOOP (frmcons, d)
|
|
7041 {
|
|
7042 f = XFRAME (XCAR (frmcons));
|
|
7043
|
|
7044 if (f == XFRAME (DEVICE_SELECTED_FRAME (d)))
|
|
7045 continue;
|
|
7046
|
|
7047 if (f->icon_changed || f->windows_changed)
|
|
7048 update_frame_icon (f);
|
|
7049
|
|
7050 if (FRAME_REPAINT_P (f))
|
|
7051 {
|
430
|
7052 if (CLASS_REDISPLAY_FLAGS_CHANGEDP (f))
|
428
|
7053 {
|
588
|
7054 int preempted = redisplay_frame (f, 1);
|
545
|
7055 if (preempted)
|
|
7056 return 1;
|
428
|
7057 }
|
|
7058
|
|
7059 if (f->size_change_pending)
|
|
7060 size_change_failed = 1;
|
|
7061 }
|
|
7062 }
|
|
7063
|
|
7064 /* If we get here then we redisplayed all of our frames without
|
|
7065 getting preempted so mark ourselves as clean. */
|
|
7066 CLASS_RESET_CHANGED_FLAGS (d);
|
|
7067
|
|
7068 if (!size_change_failed)
|
|
7069 d->size_changed = 0;
|
|
7070
|
|
7071 return 0;
|
|
7072 }
|
|
7073
|
|
7074 /* Ensure that all windows on all frames on all devices are displaying
|
|
7075 the current contents of their respective buffers. */
|
|
7076
|
|
7077 static void
|
|
7078 redisplay_without_hooks (void)
|
|
7079 {
|
|
7080 Lisp_Object devcons, concons;
|
|
7081 int size_change_failed = 0;
|
1292
|
7082 PROFILE_DECLARE ();
|
|
7083
|
|
7084 PROFILE_RECORD_ENTERING_SECTION (QSin_redisplay);
|
428
|
7085
|
|
7086 if (asynch_device_change_pending)
|
|
7087 handle_asynch_device_change ();
|
|
7088
|
|
7089 if (!GLOBAL_REDISPLAY_FLAGS_CHANGEDP &&
|
430
|
7090 !disable_preemption && preemption_count < max_preempts)
|
428
|
7091 goto done;
|
|
7092
|
|
7093 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
7094 {
|
|
7095 struct device *d = XDEVICE (XCAR (devcons));
|
|
7096 int preempted;
|
|
7097
|
430
|
7098 if (CLASS_REDISPLAY_FLAGS_CHANGEDP (d))
|
428
|
7099 {
|
440
|
7100 preempted = redisplay_device (d, 1);
|
428
|
7101
|
|
7102 if (preempted)
|
|
7103 {
|
|
7104 preemption_count++;
|
|
7105 RESET_CHANGED_SET_FLAGS;
|
|
7106 goto done;
|
|
7107 }
|
|
7108
|
|
7109 /* See comment in redisplay_device. */
|
|
7110 if (d->size_changed)
|
|
7111 size_change_failed = 1;
|
|
7112 }
|
|
7113 }
|
|
7114 preemption_count = 0;
|
|
7115
|
|
7116 /* Mark redisplay as accurate */
|
|
7117 GLOBAL_RESET_CHANGED_FLAGS;
|
|
7118 RESET_CHANGED_SET_FLAGS;
|
|
7119
|
|
7120 if (faces_changed)
|
|
7121 {
|
|
7122 mark_all_faces_as_clean ();
|
|
7123 faces_changed = 0;
|
|
7124 }
|
|
7125
|
|
7126 if (!size_change_failed)
|
|
7127 size_changed = 0;
|
|
7128
|
|
7129 reset_buffer_changes ();
|
|
7130
|
|
7131 done:
|
800
|
7132 #ifdef ERROR_CHECK_DISPLAY
|
|
7133 sledgehammer_check_redisplay_structs ();
|
|
7134 #endif /* ERROR_CHECK_DISPLAY */
|
1292
|
7135
|
|
7136 PROFILE_RECORD_EXITING_SECTION (QSin_redisplay);
|
428
|
7137 }
|
|
7138
|
1318
|
7139 /* Note: All places in the C code that call redisplay() are prepared to
|
|
7140 handle GCing, which can happen from run_pre_idle_hook(). However, we
|
|
7141 can't currently handle GC inside the guts of redisplay; see
|
|
7142 enter_redisplay_critical_section().
|
853
|
7143
|
|
7144 (#### What about other external entry points to the redisplay code?
|
|
7145 Someone should go through and make sure that all callers can handle
|
|
7146 GC there, too.)
|
|
7147 */
|
|
7148
|
428
|
7149 void
|
|
7150 redisplay (void)
|
|
7151 {
|
853
|
7152 run_pre_idle_hook ();
|
|
7153 redisplay_no_pre_idle_hook ();
|
|
7154 }
|
|
7155
|
|
7156 void
|
|
7157 redisplay_no_pre_idle_hook (void)
|
|
7158 {
|
428
|
7159 if (last_display_warning_tick != display_warning_tick &&
|
|
7160 !inhibit_warning_display)
|
|
7161 {
|
|
7162 /* If an error occurs during this function, oh well.
|
|
7163 If we report another warning, we could get stuck in an
|
|
7164 infinite loop reporting warnings. */
|
853
|
7165 call0_trapping_problems
|
|
7166 (0, Qdisplay_warning_buffer,
|
|
7167 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION);
|
428
|
7168 last_display_warning_tick = display_warning_tick;
|
|
7169 }
|
|
7170
|
|
7171 redisplay_without_hooks ();
|
|
7172 }
|
|
7173
|
853
|
7174 Lisp_Object
|
|
7175 eval_within_redisplay (Lisp_Object dont_trust_this_damn_sucker)
|
|
7176 {
|
|
7177 return
|
|
7178 eval_in_buffer_trapping_problems
|
|
7179 ("Error calling function within redisplay", current_buffer,
|
1318
|
7180 dont_trust_this_damn_sucker, 0);
|
853
|
7181 }
|
428
|
7182
|
|
7183 /* Efficiently determine the window line number, and return a pointer
|
|
7184 to its printed representation. Do this regardless of whether
|
|
7185 line-number-mode is on. The first line in the buffer is counted as
|
|
7186 1. If narrowing is in effect, the lines are counted from the
|
|
7187 beginning of the visible portion of the buffer. */
|
|
7188 static char *
|
|
7189 window_line_number (struct window *w, int type)
|
|
7190 {
|
|
7191 struct device *d = XDEVICE (XFRAME (w->frame)->device);
|
|
7192 struct buffer *b = XBUFFER (w->buffer);
|
|
7193 /* Be careful in the order of these tests. The first clause will
|
|
7194 fail if DEVICE_SELECTED_FRAME == Qnil (since w->frame cannot be).
|
|
7195 This can occur when the frame title is computed really early */
|
665
|
7196 Charbpos pos =
|
428
|
7197 ((EQ(DEVICE_SELECTED_FRAME(d), w->frame) &&
|
|
7198 (w == XWINDOW (FRAME_SELECTED_WINDOW (device_selected_frame(d)))) &&
|
|
7199 EQ(DEVICE_CONSOLE(d), Vselected_console) &&
|
|
7200 XDEVICE(CONSOLE_SELECTED_DEVICE(XCONSOLE(DEVICE_CONSOLE(d)))) == d )
|
|
7201 ? BUF_PT (b)
|
|
7202 : marker_position (w->pointm[type]));
|
|
7203 EMACS_INT line;
|
|
7204
|
|
7205 line = buffer_line_number (b, pos, 1);
|
|
7206
|
603
|
7207 {
|
|
7208 static char window_line_number_buf[DECIMAL_PRINT_SIZE (long)];
|
|
7209
|
|
7210 long_to_string (window_line_number_buf, line + 1);
|
|
7211
|
|
7212 return window_line_number_buf;
|
|
7213 }
|
428
|
7214 }
|
|
7215
|
|
7216
|
|
7217 /* Given a character representing an object in a modeline
|
|
7218 specification, return a string (stored into the global array
|
867
|
7219 `mode_spec_ibyte_string') with the information that object
|
428
|
7220 represents.
|
|
7221
|
|
7222 This function is largely unchanged from previous versions of the
|
|
7223 redisplay engine.
|
|
7224
|
|
7225 Warning! This code is also used for frame titles and can be called
|
|
7226 very early in the device/frame update process! JV
|
|
7227 */
|
|
7228
|
|
7229 static void
|
867
|
7230 decode_mode_spec (struct window *w, Ichar spec, int type)
|
428
|
7231 {
|
|
7232 Lisp_Object obj = Qnil;
|
442
|
7233 const char *str = NULL;
|
428
|
7234 struct buffer *b = XBUFFER (w->buffer);
|
|
7235
|
867
|
7236 Dynarr_reset (mode_spec_ibyte_string);
|
428
|
7237
|
|
7238 switch (spec)
|
|
7239 {
|
|
7240 /* print buffer name */
|
|
7241 case 'b':
|
|
7242 obj = b->name;
|
|
7243 break;
|
|
7244
|
|
7245 /* print visited file name */
|
|
7246 case 'f':
|
|
7247 obj = b->filename;
|
|
7248 break;
|
|
7249
|
|
7250 /* print the current column */
|
|
7251 case 'c':
|
|
7252 {
|
665
|
7253 Charbpos pt = (w == XWINDOW (Fselected_window (Qnil)))
|
428
|
7254 ? BUF_PT (b)
|
|
7255 : marker_position (w->pointm[type]);
|
|
7256 int col = column_at_point (b, pt, 1) + !!column_number_start_at_one;
|
603
|
7257 char buf[DECIMAL_PRINT_SIZE (long)];
|
428
|
7258
|
|
7259 long_to_string (buf, col);
|
|
7260
|
867
|
7261 Dynarr_add_many (mode_spec_ibyte_string,
|
|
7262 (const Ibyte *) buf, strlen (buf));
|
428
|
7263
|
|
7264 goto decode_mode_spec_done;
|
|
7265 }
|
|
7266 /* print the file coding system */
|
|
7267 case 'C':
|
|
7268 {
|
|
7269 Lisp_Object codesys = b->buffer_file_coding_system;
|
|
7270 /* Be very careful here not to get an error. */
|
|
7271 if (NILP (codesys) || SYMBOLP (codesys) || CODING_SYSTEMP (codesys))
|
|
7272 {
|
771
|
7273 codesys = find_coding_system_for_text_file (codesys, 0);
|
428
|
7274 if (CODING_SYSTEMP (codesys))
|
|
7275 obj = XCODING_SYSTEM_MNEMONIC (codesys);
|
|
7276 }
|
|
7277 }
|
|
7278 break;
|
|
7279
|
|
7280 /* print the current line number */
|
|
7281 case 'l':
|
|
7282 str = window_line_number (w, type);
|
|
7283 break;
|
|
7284
|
|
7285 /* print value of mode-name (obsolete) */
|
|
7286 case 'm':
|
|
7287 obj = b->mode_name;
|
|
7288 break;
|
|
7289
|
|
7290 /* print hyphen and frame number, if != 1 */
|
|
7291 case 'N':
|
|
7292 #ifdef HAVE_TTY
|
|
7293 {
|
|
7294 struct frame *f = XFRAME (w->frame);
|
|
7295 if (FRAME_TTY_P (f) && f->order_count > 1 && f->order_count <= 99999999)
|
|
7296 {
|
|
7297 /* Naughty, naughty */
|
|
7298 char * writable_str = alloca_array (char, 10);
|
|
7299 sprintf (writable_str, "-%d", f->order_count);
|
|
7300 str = writable_str;
|
|
7301 }
|
|
7302 }
|
|
7303 #endif /* HAVE_TTY */
|
|
7304 break;
|
|
7305
|
|
7306 /* print Narrow if appropriate */
|
|
7307 case 'n':
|
|
7308 if (BUF_BEGV (b) > BUF_BEG (b)
|
|
7309 || BUF_ZV (b) < BUF_Z (b))
|
|
7310 str = " Narrow";
|
|
7311 break;
|
|
7312
|
|
7313 /* print %, * or hyphen, if buffer is read-only, modified or neither */
|
|
7314 case '*':
|
|
7315 str = (!NILP (b->read_only)
|
|
7316 ? "%"
|
|
7317 : ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
|
|
7318 ? "*"
|
|
7319 : "-"));
|
|
7320 break;
|
|
7321
|
|
7322 /* print * or hyphen -- XEmacs change to allow a buffer to be
|
|
7323 read-only but still indicate whether it is modified. */
|
|
7324 case '+':
|
|
7325 str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
|
|
7326 ? "*"
|
|
7327 : (!NILP (b->read_only)
|
|
7328 ? "%"
|
|
7329 : "-"));
|
|
7330 break;
|
|
7331
|
|
7332 /* #### defined in 19.29 decode_mode_spec, but not in
|
|
7333 modeline-format doc string. */
|
|
7334 /* This differs from %* in that it ignores read-only-ness. */
|
|
7335 case '&':
|
|
7336 str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
|
|
7337 ? "*"
|
|
7338 : "-");
|
|
7339 break;
|
|
7340
|
|
7341 /* print process status */
|
|
7342 case 's':
|
|
7343 obj = Fget_buffer_process (w->buffer);
|
|
7344 if (NILP (obj))
|
|
7345 str = GETTEXT ("no process");
|
|
7346 else
|
|
7347 obj = Fsymbol_name (Fprocess_status (obj));
|
|
7348 break;
|
|
7349
|
|
7350 /* Print name of selected frame. */
|
|
7351 case 'S':
|
|
7352 obj = XFRAME (w->frame)->name;
|
|
7353 break;
|
|
7354
|
|
7355 /* indicate TEXT or BINARY */
|
|
7356 case 't':
|
|
7357 /* #### NT does not use this any more. Now what? */
|
|
7358 str = "T";
|
|
7359 break;
|
|
7360
|
|
7361 /* print percent of buffer above top of window, or Top, Bot or All */
|
|
7362 case 'p':
|
|
7363 {
|
665
|
7364 Charbpos pos = marker_position (w->start[type]);
|
428
|
7365
|
|
7366 /* This had better be while the desired lines are being done. */
|
|
7367 if (w->window_end_pos[type] <= BUF_Z (b) - BUF_ZV (b))
|
|
7368 {
|
|
7369 if (pos <= BUF_BEGV (b))
|
|
7370 str = "All";
|
|
7371 else
|
|
7372 str = "Bottom";
|
|
7373 }
|
|
7374 else if (pos <= BUF_BEGV (b))
|
|
7375 str = "Top";
|
|
7376 else
|
|
7377 {
|
|
7378 /* This hard limit is ok since the string it will hold has a
|
|
7379 fixed maximum length of 3. But just to be safe... */
|
|
7380 char buf[10];
|
|
7381 Charcount chars = pos - BUF_BEGV (b);
|
|
7382 Charcount total = BUF_ZV (b) - BUF_BEGV (b);
|
|
7383
|
|
7384 /* Avoid overflow on big buffers */
|
|
7385 int percent = total > LONG_MAX/200 ?
|
|
7386 (chars + total/200) / (total / 100) :
|
|
7387 (chars * 100 + total/2) / total;
|
|
7388
|
|
7389 /* We can't normally display a 3-digit number, so get us a
|
|
7390 2-digit number that is close. */
|
|
7391 if (percent == 100)
|
|
7392 percent = 99;
|
|
7393
|
|
7394 sprintf (buf, "%d%%", percent);
|
867
|
7395 Dynarr_add_many (mode_spec_ibyte_string, (Ibyte *) buf,
|
428
|
7396 strlen (buf));
|
|
7397
|
|
7398 goto decode_mode_spec_done;
|
|
7399 }
|
|
7400 break;
|
|
7401 }
|
|
7402
|
|
7403 /* print percent of buffer above bottom of window, perhaps plus
|
|
7404 Top, or print Bottom or All */
|
|
7405 case 'P':
|
|
7406 {
|
665
|
7407 Charbpos toppos = marker_position (w->start[type]);
|
|
7408 Charbpos botpos = BUF_Z (b) - w->window_end_pos[type];
|
428
|
7409
|
|
7410 /* botpos is only accurate as of the last redisplay, so we can
|
|
7411 only treat it as a hint. In particular, after erase-buffer,
|
|
7412 botpos may be negative. */
|
|
7413 if (botpos < toppos)
|
|
7414 botpos = toppos;
|
|
7415
|
|
7416 if (botpos >= BUF_ZV (b))
|
|
7417 {
|
|
7418 if (toppos <= BUF_BEGV (b))
|
|
7419 str = "All";
|
|
7420 else
|
|
7421 str = "Bottom";
|
|
7422 }
|
|
7423 else
|
|
7424 {
|
|
7425 /* This hard limit is ok since the string it will hold has a
|
|
7426 fixed maximum length of around 6. But just to be safe... */
|
|
7427 char buf[10];
|
|
7428 Charcount chars = botpos - BUF_BEGV (b);
|
|
7429 Charcount total = BUF_ZV (b) - BUF_BEGV (b);
|
|
7430
|
|
7431 /* Avoid overflow on big buffers */
|
|
7432 int percent = total > LONG_MAX/200 ?
|
|
7433 (chars + total/200) / (total / 100) :
|
|
7434 (chars * 100 + total/2) / max (total, 1);
|
|
7435
|
|
7436 /* We can't normally display a 3-digit number, so get us a
|
|
7437 2-digit number that is close. */
|
|
7438 if (percent == 100)
|
|
7439 percent = 99;
|
|
7440
|
|
7441 if (toppos <= BUF_BEGV (b))
|
|
7442 sprintf (buf, "Top%d%%", percent);
|
|
7443 else
|
|
7444 sprintf (buf, "%d%%", percent);
|
|
7445
|
867
|
7446 Dynarr_add_many (mode_spec_ibyte_string, (Ibyte *) buf,
|
428
|
7447 strlen (buf));
|
|
7448
|
|
7449 goto decode_mode_spec_done;
|
|
7450 }
|
|
7451 break;
|
|
7452 }
|
|
7453
|
|
7454 /* print % */
|
|
7455 case '%':
|
|
7456 str = "%";
|
|
7457 break;
|
|
7458
|
|
7459 /* print one [ for each recursive editing level. */
|
|
7460 case '[':
|
|
7461 {
|
|
7462 int i;
|
|
7463
|
|
7464 if (command_loop_level > 5)
|
|
7465 {
|
|
7466 str = "[[[... ";
|
|
7467 break;
|
|
7468 }
|
|
7469
|
|
7470 for (i = 0; i < command_loop_level; i++)
|
867
|
7471 Dynarr_add (mode_spec_ibyte_string, '[');
|
428
|
7472
|
|
7473 goto decode_mode_spec_done;
|
|
7474 }
|
|
7475
|
|
7476 /* print one ] for each recursive editing level. */
|
|
7477 case ']':
|
|
7478 {
|
|
7479 int i;
|
|
7480
|
|
7481 if (command_loop_level > 5)
|
|
7482 {
|
|
7483 str = "...]]]";
|
|
7484 break;
|
|
7485 }
|
|
7486
|
|
7487 for (i = 0; i < command_loop_level; i++)
|
867
|
7488 Dynarr_add (mode_spec_ibyte_string, ']');
|
428
|
7489
|
|
7490 goto decode_mode_spec_done;
|
|
7491 }
|
|
7492
|
|
7493 /* print infinitely many dashes -- handle at top level now */
|
|
7494 case '-':
|
|
7495 break;
|
|
7496
|
|
7497 }
|
|
7498
|
|
7499 if (STRINGP (obj))
|
867
|
7500 Dynarr_add_many (mode_spec_ibyte_string,
|
428
|
7501 XSTRING_DATA (obj),
|
|
7502 XSTRING_LENGTH (obj));
|
|
7503 else if (str)
|
867
|
7504 Dynarr_add_many (mode_spec_ibyte_string, (Ibyte *) str, strlen (str));
|
428
|
7505
|
|
7506 decode_mode_spec_done:
|
867
|
7507 Dynarr_add (mode_spec_ibyte_string, '\0');
|
428
|
7508 }
|
|
7509
|
|
7510 /* Given a display line, free all of its data structures. */
|
|
7511
|
|
7512 static void
|
|
7513 free_display_line (struct display_line *dl)
|
|
7514 {
|
|
7515 int block;
|
|
7516
|
|
7517 if (dl->display_blocks)
|
|
7518 {
|
|
7519 for (block = 0; block < Dynarr_largest (dl->display_blocks); block++)
|
1318
|
7520 {
|
428
|
7521 struct display_block *db = Dynarr_atp (dl->display_blocks, block);
|
|
7522
|
|
7523 Dynarr_free (db->runes);
|
|
7524 }
|
|
7525
|
|
7526 Dynarr_free (dl->display_blocks);
|
|
7527 dl->display_blocks = NULL;
|
|
7528 }
|
|
7529
|
|
7530 if (dl->left_glyphs)
|
|
7531 {
|
|
7532 Dynarr_free (dl->left_glyphs);
|
|
7533 dl->left_glyphs = NULL;
|
|
7534 }
|
|
7535
|
|
7536 if (dl->right_glyphs)
|
|
7537 {
|
|
7538 Dynarr_free (dl->right_glyphs);
|
|
7539 dl->right_glyphs = NULL;
|
|
7540 }
|
|
7541 }
|
|
7542
|
|
7543
|
|
7544 /* Given an array of display lines, free them and all data structures
|
|
7545 contained within them. */
|
|
7546
|
|
7547 void
|
|
7548 free_display_lines (display_line_dynarr *dla)
|
|
7549 {
|
|
7550 int line;
|
|
7551
|
|
7552 for (line = 0; line < Dynarr_largest (dla); line++)
|
|
7553 {
|
|
7554 free_display_line (Dynarr_atp (dla, line));
|
|
7555 }
|
|
7556
|
|
7557 Dynarr_free (dla);
|
|
7558 }
|
|
7559
|
|
7560 /* Call internal free routine for each set of display lines. */
|
|
7561
|
|
7562 void
|
|
7563 free_display_structs (struct window_mirror *mir)
|
|
7564 {
|
|
7565 if (mir->current_display_lines)
|
|
7566 {
|
|
7567 free_display_lines (mir->current_display_lines);
|
|
7568 mir->current_display_lines = 0;
|
|
7569 }
|
|
7570
|
|
7571 if (mir->desired_display_lines)
|
|
7572 {
|
|
7573 free_display_lines (mir->desired_display_lines);
|
|
7574 mir->desired_display_lines = 0;
|
|
7575 }
|
|
7576 }
|
|
7577
|
|
7578
|
|
7579 static void
|
|
7580 mark_glyph_block_dynarr (glyph_block_dynarr *gba)
|
|
7581 {
|
|
7582 if (gba)
|
|
7583 {
|
|
7584 glyph_block *gb = Dynarr_atp (gba, 0);
|
|
7585 glyph_block *gb_last = Dynarr_atp (gba, Dynarr_length (gba));
|
|
7586
|
|
7587 for (; gb < gb_last; gb++)
|
|
7588 {
|
|
7589 if (!NILP (gb->glyph))
|
|
7590 mark_object (gb->glyph);
|
|
7591 if (!NILP (gb->extent))
|
|
7592 mark_object (gb->extent);
|
|
7593 }
|
|
7594 }
|
|
7595 }
|
|
7596
|
442
|
7597 /* See the comment in image_instantiate_cache_result as to why marking
|
|
7598 the glyph will also mark the image_instance. */
|
|
7599 void
|
428
|
7600 mark_redisplay_structs (display_line_dynarr *dla)
|
|
7601 {
|
|
7602 display_line *dl = Dynarr_atp (dla, 0);
|
|
7603 display_line *dl_last = Dynarr_atp (dla, Dynarr_length (dla));
|
|
7604
|
|
7605 for (; dl < dl_last; dl++)
|
|
7606 {
|
|
7607 display_block_dynarr *dba = dl->display_blocks;
|
|
7608 display_block *db = Dynarr_atp (dba, 0);
|
|
7609 display_block *db_last = Dynarr_atp (dba, Dynarr_length (dba));
|
|
7610
|
|
7611 for (; db < db_last; db++)
|
|
7612 {
|
|
7613 rune_dynarr *ra = db->runes;
|
|
7614 rune *r = Dynarr_atp (ra, 0);
|
|
7615 rune *r_last = Dynarr_atp (ra, Dynarr_length (ra));
|
|
7616
|
|
7617 for (; r < r_last; r++)
|
|
7618 {
|
|
7619 if (r->type == RUNE_DGLYPH)
|
|
7620 {
|
|
7621 if (!NILP (r->object.dglyph.glyph))
|
|
7622 mark_object (r->object.dglyph.glyph);
|
|
7623 if (!NILP (r->object.dglyph.extent))
|
|
7624 mark_object (r->object.dglyph.extent);
|
|
7625 }
|
|
7626 }
|
|
7627 }
|
|
7628
|
|
7629 mark_glyph_block_dynarr (dl->left_glyphs);
|
|
7630 mark_glyph_block_dynarr (dl->right_glyphs);
|
|
7631 }
|
|
7632 }
|
|
7633
|
|
7634
|
2367
|
7635
|
|
7636 /*
|
|
7637
|
|
7638 Info on line-start cache:
|
|
7639
|
|
7640 (Info-goto-node "(internals)Line Start Cache")
|
|
7641 */
|
428
|
7642
|
|
7643 /* This will get used quite a bit so we don't want to be constantly
|
|
7644 allocating and freeing it. */
|
|
7645 static line_start_cache_dynarr *internal_cache;
|
|
7646
|
|
7647 /* Makes internal_cache represent the TYPE display structs and only
|
|
7648 the TYPE display structs. */
|
|
7649
|
|
7650 static void
|
|
7651 update_internal_cache_list (struct window *w, int type)
|
|
7652 {
|
|
7653 int line;
|
|
7654 display_line_dynarr *dla = window_display_lines (w, type);
|
|
7655
|
|
7656 Dynarr_reset (internal_cache);
|
|
7657 for (line = 0; line < Dynarr_length (dla); line++)
|
|
7658 {
|
|
7659 struct display_line *dl = Dynarr_atp (dla, line);
|
|
7660
|
|
7661 if (dl->modeline)
|
|
7662 continue;
|
|
7663 else
|
|
7664 {
|
|
7665 struct line_start_cache lsc;
|
434
|
7666
|
826
|
7667 lsc.start = dl->charpos;
|
|
7668 lsc.end = dl->end_charpos;
|
428
|
7669 lsc.height = dl->ascent + dl->descent;
|
|
7670
|
|
7671 Dynarr_add (internal_cache, lsc);
|
|
7672 }
|
|
7673 }
|
|
7674 }
|
|
7675
|
|
7676 /* Reset the line cache if necessary. This should be run at the
|
|
7677 beginning of any function which access the cache. */
|
|
7678
|
|
7679 static void
|
|
7680 validate_line_start_cache (struct window *w)
|
|
7681 {
|
|
7682 struct buffer *b = XBUFFER (w->buffer);
|
|
7683 struct frame *f = XFRAME (w->frame);
|
|
7684
|
|
7685 if (!w->line_cache_validation_override)
|
|
7686 {
|
|
7687 /* f->extents_changed used to be in here because extent face and
|
|
7688 size changes can cause text shifting. However, the extent
|
|
7689 covering the region is constantly having its face set and
|
|
7690 priority altered by the mouse code. This means that the line
|
|
7691 start cache is constantly being invalidated. This is bad
|
|
7692 since the mouse code also triggers heavy usage of the cache.
|
|
7693 Since it is an unlikely that f->extents being changed
|
|
7694 indicates that the cache really needs to be updated and if it
|
|
7695 does redisplay will catch it pretty quickly we no longer
|
|
7696 invalidate the cache if it is set. This greatly speeds up
|
|
7697 dragging out regions with the mouse. */
|
|
7698 if (XINT (w->line_cache_last_updated) < BUF_MODIFF (b)
|
|
7699 || f->faces_changed
|
|
7700 || f->clip_changed)
|
|
7701 {
|
|
7702 Dynarr_reset (w->line_start_cache);
|
|
7703 }
|
|
7704 }
|
|
7705 }
|
|
7706
|
|
7707 /* Return the very first buffer position contained in the given
|
|
7708 window's cache, or -1 if the cache is empty. Assumes that the
|
|
7709 cache is valid. */
|
|
7710
|
665
|
7711 static Charbpos
|
428
|
7712 line_start_cache_start (struct window *w)
|
|
7713 {
|
|
7714 line_start_cache_dynarr *cache = w->line_start_cache;
|
|
7715
|
|
7716 if (!Dynarr_length (cache))
|
|
7717 return -1;
|
|
7718 else
|
|
7719 return Dynarr_atp (cache, 0)->start;
|
|
7720 }
|
|
7721
|
|
7722 /* Return the very last buffer position contained in the given
|
|
7723 window's cache, or -1 if the cache is empty. Assumes that the
|
|
7724 cache is valid. */
|
|
7725
|
665
|
7726 static Charbpos
|
428
|
7727 line_start_cache_end (struct window *w)
|
|
7728 {
|
|
7729 line_start_cache_dynarr *cache = w->line_start_cache;
|
|
7730
|
|
7731 if (!Dynarr_length (cache))
|
|
7732 return -1;
|
|
7733 else
|
|
7734 return Dynarr_atp (cache, Dynarr_length (cache) - 1)->end;
|
|
7735 }
|
|
7736
|
|
7737 /* Return the index of the line POINT is contained within in window
|
|
7738 W's line start cache. It will enlarge the cache or move the cache
|
|
7739 window in order to have POINT be present in the cache. MIN_PAST is
|
|
7740 a guarantee of the number of entries in the cache present on either
|
|
7741 side of POINT (unless a buffer boundary is hit). If MIN_PAST is -1
|
|
7742 then it will be treated as 0, but the cache window will not be
|
|
7743 allowed to shift. Returns -1 if POINT cannot be found in the cache
|
|
7744 for any reason. */
|
|
7745
|
|
7746 int
|
665
|
7747 point_in_line_start_cache (struct window *w, Charbpos point, int min_past)
|
428
|
7748 {
|
|
7749 struct buffer *b = XBUFFER (w->buffer);
|
|
7750 line_start_cache_dynarr *cache = w->line_start_cache;
|
647
|
7751 int top, bottom, pos;
|
428
|
7752
|
|
7753 validate_line_start_cache (w);
|
|
7754 w->line_cache_validation_override++;
|
|
7755
|
|
7756 /* Let functions pass in negative values, but we still treat -1
|
|
7757 specially. */
|
|
7758 /* #### bogosity alert */
|
|
7759 if (min_past < 0 && min_past != -1)
|
|
7760 min_past = -min_past;
|
|
7761
|
|
7762 if (!Dynarr_length (cache) || line_start_cache_start (w) > point
|
|
7763 || line_start_cache_end (w) < point)
|
|
7764 {
|
|
7765 int loop;
|
|
7766 int win_char_height = window_char_height (w, 1);
|
|
7767
|
|
7768 /* Occasionally we get here with a 0 height
|
|
7769 window. find_next_newline_no_quit will abort if we pass it a
|
|
7770 count of 0 so handle that case. */
|
|
7771 if (!win_char_height)
|
|
7772 win_char_height = 1;
|
|
7773
|
|
7774 if (!Dynarr_length (cache))
|
|
7775 {
|
665
|
7776 Charbpos from = find_next_newline_no_quit (b, point, -1);
|
|
7777 Charbpos to = find_next_newline_no_quit (b, from, win_char_height);
|
428
|
7778
|
|
7779 update_line_start_cache (w, from, to, point, 0);
|
|
7780
|
|
7781 if (!Dynarr_length (cache))
|
|
7782 {
|
|
7783 w->line_cache_validation_override--;
|
|
7784 return -1;
|
|
7785 }
|
|
7786 }
|
|
7787
|
|
7788 assert (Dynarr_length (cache));
|
|
7789
|
|
7790 loop = 0;
|
|
7791 while (line_start_cache_start (w) > point
|
|
7792 && (loop < cache_adjustment || min_past == -1))
|
|
7793 {
|
665
|
7794 Charbpos from, to;
|
428
|
7795
|
|
7796 from = line_start_cache_start (w);
|
|
7797 if (from <= BUF_BEGV (b))
|
|
7798 break;
|
|
7799
|
|
7800 from = find_next_newline_no_quit (b, from, -win_char_height);
|
|
7801 to = line_start_cache_end (w);
|
|
7802
|
|
7803 update_line_start_cache (w, from, to, point, 0);
|
|
7804 loop++;
|
|
7805 }
|
|
7806
|
|
7807 if (line_start_cache_start (w) > point)
|
|
7808 {
|
665
|
7809 Charbpos from, to;
|
428
|
7810
|
|
7811 from = find_next_newline_no_quit (b, point, -1);
|
|
7812 if (from >= BUF_ZV (b))
|
|
7813 {
|
|
7814 to = find_next_newline_no_quit (b, from, -win_char_height);
|
|
7815 from = to;
|
|
7816 to = BUF_ZV (b);
|
|
7817 }
|
|
7818 else
|
|
7819 to = find_next_newline_no_quit (b, from, win_char_height);
|
|
7820
|
|
7821 update_line_start_cache (w, from, to, point, 0);
|
|
7822 }
|
|
7823
|
|
7824 loop = 0;
|
|
7825 while (line_start_cache_end (w) < point
|
|
7826 && (loop < cache_adjustment || min_past == -1))
|
|
7827 {
|
665
|
7828 Charbpos from, to;
|
428
|
7829
|
|
7830 to = line_start_cache_end (w);
|
|
7831 if (to >= BUF_ZV (b))
|
|
7832 break;
|
|
7833
|
|
7834 from = line_start_cache_end (w);
|
|
7835 to = find_next_newline_no_quit (b, from, win_char_height);
|
|
7836
|
|
7837 update_line_start_cache (w, from, to, point, 0);
|
|
7838 loop++;
|
|
7839 }
|
|
7840
|
|
7841 if (line_start_cache_end (w) < point)
|
|
7842 {
|
665
|
7843 Charbpos from, to;
|
428
|
7844
|
|
7845 from = find_next_newline_no_quit (b, point, -1);
|
|
7846 if (from >= BUF_ZV (b))
|
|
7847 {
|
|
7848 to = find_next_newline_no_quit (b, from, -win_char_height);
|
|
7849 from = to;
|
|
7850 to = BUF_ZV (b);
|
|
7851 }
|
|
7852 else
|
|
7853 to = find_next_newline_no_quit (b, from, win_char_height);
|
|
7854
|
|
7855 update_line_start_cache (w, from, to, point, 0);
|
|
7856 }
|
|
7857 }
|
|
7858
|
|
7859 assert (Dynarr_length (cache));
|
|
7860
|
|
7861 if (min_past == -1)
|
|
7862 min_past = 0;
|
|
7863
|
|
7864 /* This could happen if the buffer is narrowed. */
|
|
7865 if (line_start_cache_start (w) > point
|
|
7866 || line_start_cache_end (w) < point)
|
|
7867 {
|
|
7868 w->line_cache_validation_override--;
|
|
7869 return -1;
|
|
7870 }
|
|
7871
|
|
7872 find_point_loop:
|
|
7873
|
|
7874 top = Dynarr_length (cache) - 1;
|
|
7875 bottom = 0;
|
|
7876
|
|
7877 while (1)
|
|
7878 {
|
647
|
7879 int new_pos;
|
665
|
7880 Charbpos start, end;
|
428
|
7881
|
|
7882 pos = (bottom + top + 1) >> 1;
|
|
7883 start = Dynarr_atp (cache, pos)->start;
|
|
7884 end = Dynarr_atp (cache, pos)->end;
|
|
7885
|
|
7886 if (point >= start && point <= end)
|
|
7887 {
|
|
7888 if (pos < min_past && line_start_cache_start (w) > BUF_BEGV (b))
|
|
7889 {
|
665
|
7890 Charbpos from =
|
428
|
7891 find_next_newline_no_quit (b, line_start_cache_start (w),
|
|
7892 -min_past - 1);
|
665
|
7893 Charbpos to = line_start_cache_end (w);
|
428
|
7894
|
|
7895 update_line_start_cache (w, from, to, point, 0);
|
|
7896 goto find_point_loop;
|
|
7897 }
|
|
7898 else if ((Dynarr_length (cache) - pos - 1) < min_past
|
|
7899 && line_start_cache_end (w) < BUF_ZV (b))
|
|
7900 {
|
665
|
7901 Charbpos from = line_start_cache_end (w);
|
|
7902 Charbpos to = find_next_newline_no_quit (b, from,
|
428
|
7903 (min_past
|
|
7904 ? min_past
|
|
7905 : 1));
|
|
7906
|
|
7907 update_line_start_cache (w, from, to, point, 0);
|
|
7908 goto find_point_loop;
|
|
7909 }
|
|
7910 else
|
|
7911 {
|
|
7912 w->line_cache_validation_override--;
|
|
7913 return pos;
|
|
7914 }
|
|
7915 }
|
|
7916 else if (point > end)
|
|
7917 bottom = pos + 1;
|
|
7918 else if (point < start)
|
|
7919 top = pos - 1;
|
|
7920 else
|
2500
|
7921 ABORT ();
|
428
|
7922
|
|
7923 new_pos = (bottom + top + 1) >> 1;
|
|
7924 if (pos == new_pos)
|
|
7925 {
|
|
7926 w->line_cache_validation_override--;
|
|
7927 return -1;
|
|
7928 }
|
|
7929 }
|
|
7930 }
|
|
7931
|
|
7932 /* Return a boolean indicating if POINT would be visible in window W
|
1708
|
7933 if display of the window was to begin at STARTP. If PARTIALLY is
|
|
7934 zero, then if POINT has fewer visible pixels than the window clip,
|
|
7935 0 is returned; otherwise, 1 is returned if POINT has any visible
|
|
7936 pixels. */
|
428
|
7937 int
|
1708
|
7938 point_would_be_visible (struct window *w, Charbpos startp, Charbpos point,
|
|
7939 int partially)
|
428
|
7940 {
|
|
7941 struct buffer *b = XBUFFER (w->buffer);
|
430
|
7942 int pixpos = -WINDOW_TEXT_TOP_CLIP(w);
|
428
|
7943 int bottom = WINDOW_TEXT_HEIGHT (w);
|
|
7944 int start_elt;
|
|
7945
|
|
7946 /* If point is before the intended start it obviously can't be visible. */
|
|
7947 if (point < startp)
|
|
7948 return 0;
|
|
7949
|
|
7950 /* If point or start are not in the accessible buffer range, then
|
|
7951 fail. */
|
|
7952 if (startp < BUF_BEGV (b) || startp > BUF_ZV (b)
|
|
7953 || point < BUF_BEGV (b) || point > BUF_ZV (b))
|
|
7954 return 0;
|
|
7955
|
|
7956 validate_line_start_cache (w);
|
|
7957 w->line_cache_validation_override++;
|
|
7958
|
|
7959 start_elt = point_in_line_start_cache (w, startp, 0);
|
|
7960 if (start_elt == -1)
|
|
7961 {
|
|
7962 w->line_cache_validation_override--;
|
|
7963 return 0;
|
|
7964 }
|
|
7965
|
|
7966 assert (line_start_cache_start (w) <= startp
|
|
7967 && line_start_cache_end (w) >= startp);
|
|
7968
|
|
7969 while (1)
|
|
7970 {
|
|
7971 int height;
|
|
7972
|
|
7973 /* Expand the cache if necessary. */
|
|
7974 if (start_elt == Dynarr_length (w->line_start_cache))
|
|
7975 {
|
665
|
7976 Charbpos old_startp =
|
428
|
7977 Dynarr_atp (w->line_start_cache, start_elt - 1)->start;
|
|
7978
|
|
7979 start_elt = point_in_line_start_cache (w, old_startp,
|
|
7980 window_char_height (w, 0));
|
|
7981
|
|
7982 /* We've already actually processed old_startp, so increment
|
|
7983 immediately. */
|
|
7984 start_elt++;
|
|
7985
|
|
7986 /* If this happens we didn't add any extra elements. Bummer. */
|
|
7987 if (start_elt == Dynarr_length (w->line_start_cache))
|
|
7988 {
|
|
7989 w->line_cache_validation_override--;
|
|
7990 return 0;
|
|
7991 }
|
|
7992 }
|
|
7993
|
|
7994 height = Dynarr_atp (w->line_start_cache, start_elt)->height;
|
|
7995
|
|
7996 if (pixpos + height > bottom)
|
|
7997 {
|
1708
|
7998 if (bottom - pixpos < (partially ? 0 : VERTICAL_CLIP (w, 0)))
|
428
|
7999 {
|
|
8000 w->line_cache_validation_override--;
|
|
8001 return 0;
|
|
8002 }
|
|
8003 }
|
|
8004
|
|
8005 pixpos += height;
|
|
8006 if (point <= Dynarr_atp (w->line_start_cache, start_elt)->end)
|
|
8007 {
|
|
8008 w->line_cache_validation_override--;
|
|
8009 return 1;
|
|
8010 }
|
|
8011
|
|
8012 start_elt++;
|
|
8013 }
|
|
8014 }
|
|
8015
|
|
8016 /* For the given window W, if display starts at STARTP, what will be
|
|
8017 the buffer position at the beginning or end of the last line
|
|
8018 displayed. The end of the last line is also know as the window end
|
|
8019 position.
|
|
8020
|
442
|
8021 WARNING: It is possible that redisplay failed to layout any lines for the
|
|
8022 windows. Under normal circumstances this is rare. However it seems that it
|
|
8023 does occur in the following situation: A mouse event has come in and we
|
|
8024 need to compute its location in a window. That code (in
|
|
8025 pixel_to_glyph_translation) already can handle 0 as an error return value.
|
|
8026
|
428
|
8027 #### With a little work this could probably be reworked as just a
|
|
8028 call to start_with_line_at_pixpos. */
|
|
8029
|
665
|
8030 static Charbpos
|
|
8031 start_end_of_last_line (struct window *w, Charbpos startp, int end,
|
442
|
8032 int may_error)
|
428
|
8033 {
|
|
8034 struct buffer *b = XBUFFER (w->buffer);
|
|
8035 line_start_cache_dynarr *cache = w->line_start_cache;
|
|
8036 int pixpos = 0;
|
|
8037 int bottom = WINDOW_TEXT_HEIGHT (w);
|
665
|
8038 Charbpos cur_start;
|
428
|
8039 int start_elt;
|
|
8040
|
|
8041 validate_line_start_cache (w);
|
|
8042 w->line_cache_validation_override++;
|
|
8043
|
|
8044 if (startp < BUF_BEGV (b))
|
|
8045 startp = BUF_BEGV (b);
|
|
8046 else if (startp > BUF_ZV (b))
|
|
8047 startp = BUF_ZV (b);
|
|
8048 cur_start = startp;
|
|
8049
|
|
8050 start_elt = point_in_line_start_cache (w, cur_start, 0);
|
|
8051 if (start_elt == -1)
|
442
|
8052 return may_error ? 0 : startp;
|
428
|
8053
|
|
8054 while (1)
|
|
8055 {
|
|
8056 int height = Dynarr_atp (cache, start_elt)->height;
|
|
8057
|
|
8058 cur_start = Dynarr_atp (cache, start_elt)->start;
|
|
8059
|
|
8060 if (pixpos + height > bottom)
|
|
8061 {
|
|
8062 /* Adjust for any possible clip. */
|
|
8063 if (bottom - pixpos < VERTICAL_CLIP (w, 0))
|
|
8064 start_elt--;
|
|
8065
|
|
8066 if (start_elt < 0)
|
|
8067 {
|
|
8068 w->line_cache_validation_override--;
|
|
8069 if (end)
|
|
8070 return BUF_ZV (b);
|
|
8071 else
|
|
8072 return BUF_BEGV (b);
|
|
8073 }
|
|
8074 else
|
|
8075 {
|
|
8076 w->line_cache_validation_override--;
|
|
8077 if (end)
|
|
8078 return Dynarr_atp (cache, start_elt)->end;
|
|
8079 else
|
|
8080 return Dynarr_atp (cache, start_elt)->start;
|
|
8081 }
|
|
8082 }
|
|
8083
|
|
8084 pixpos += height;
|
|
8085 start_elt++;
|
|
8086 if (start_elt == Dynarr_length (cache))
|
|
8087 {
|
665
|
8088 Charbpos from = line_start_cache_end (w);
|
428
|
8089 int win_char_height = window_char_height (w, 0);
|
665
|
8090 Charbpos to = find_next_newline_no_quit (b, from,
|
428
|
8091 (win_char_height
|
|
8092 ? win_char_height
|
|
8093 : 1));
|
|
8094
|
|
8095 /* We've hit the end of the bottom so that's what it is. */
|
|
8096 if (from >= BUF_ZV (b))
|
|
8097 {
|
|
8098 w->line_cache_validation_override--;
|
|
8099 return BUF_ZV (b);
|
|
8100 }
|
|
8101
|
|
8102 update_line_start_cache (w, from, to, BUF_PT (b), 0);
|
|
8103
|
|
8104 /* Updating the cache invalidates any current indexes. */
|
|
8105 start_elt = point_in_line_start_cache (w, cur_start, -1) + 1;
|
|
8106 }
|
|
8107 }
|
|
8108 }
|
|
8109
|
|
8110 /* For the given window W, if display starts at STARTP, what will be
|
|
8111 the buffer position at the beginning of the last line displayed. */
|
|
8112
|
665
|
8113 Charbpos
|
|
8114 start_of_last_line (struct window *w, Charbpos startp)
|
428
|
8115 {
|
442
|
8116 return start_end_of_last_line (w, startp, 0 , 0);
|
428
|
8117 }
|
|
8118
|
|
8119 /* For the given window W, if display starts at STARTP, what will be
|
|
8120 the buffer position at the end of the last line displayed. This is
|
|
8121 also know as the window end position. */
|
|
8122
|
665
|
8123 Charbpos
|
|
8124 end_of_last_line (struct window *w, Charbpos startp)
|
428
|
8125 {
|
442
|
8126 return start_end_of_last_line (w, startp, 1, 0);
|
428
|
8127 }
|
|
8128
|
665
|
8129 static Charbpos
|
|
8130 end_of_last_line_may_error (struct window *w, Charbpos startp)
|
442
|
8131 {
|
|
8132 return start_end_of_last_line (w, startp, 1, 1);
|
|
8133 }
|
|
8134
|
|
8135
|
428
|
8136 /* For window W, what does the starting position have to be so that
|
|
8137 the line containing POINT will cover pixel position PIXPOS. */
|
|
8138
|
665
|
8139 Charbpos
|
|
8140 start_with_line_at_pixpos (struct window *w, Charbpos point, int pixpos)
|
428
|
8141 {
|
|
8142 struct buffer *b = XBUFFER (w->buffer);
|
|
8143 int cur_elt;
|
665
|
8144 Charbpos cur_pos, prev_pos = point;
|
428
|
8145 int point_line_height;
|
|
8146 int pixheight = pixpos - WINDOW_TEXT_TOP (w);
|
|
8147
|
|
8148 validate_line_start_cache (w);
|
|
8149 w->line_cache_validation_override++;
|
|
8150
|
|
8151 cur_elt = point_in_line_start_cache (w, point, 0);
|
|
8152 /* #### See comment in update_line_start_cache about big minibuffers. */
|
|
8153 if (cur_elt < 0)
|
|
8154 {
|
|
8155 w->line_cache_validation_override--;
|
|
8156 return point;
|
|
8157 }
|
|
8158
|
|
8159 point_line_height = Dynarr_atp (w->line_start_cache, cur_elt)->height;
|
|
8160
|
|
8161 while (1)
|
|
8162 {
|
|
8163 cur_pos = Dynarr_atp (w->line_start_cache, cur_elt)->start;
|
|
8164
|
|
8165 pixheight -= Dynarr_atp (w->line_start_cache, cur_elt)->height;
|
|
8166
|
|
8167 /* Do not take into account the value of vertical_clip here.
|
|
8168 That is the responsibility of the calling functions. */
|
|
8169 if (pixheight < 0)
|
|
8170 {
|
|
8171 w->line_cache_validation_override--;
|
|
8172 if (-pixheight > point_line_height)
|
|
8173 /* We can't make the target line cover pixpos, so put it
|
|
8174 above pixpos. That way it will at least be visible. */
|
|
8175 return prev_pos;
|
|
8176 else
|
|
8177 return cur_pos;
|
|
8178 }
|
|
8179
|
|
8180 cur_elt--;
|
|
8181 while (cur_elt < 0)
|
|
8182 {
|
665
|
8183 Charbpos from, to;
|
428
|
8184 int win_char_height;
|
|
8185
|
|
8186 if (cur_pos <= BUF_BEGV (b))
|
|
8187 {
|
|
8188 w->line_cache_validation_override--;
|
|
8189 return BUF_BEGV (b);
|
|
8190 }
|
|
8191
|
|
8192 win_char_height = window_char_height (w, 0);
|
|
8193 if (!win_char_height)
|
|
8194 win_char_height = 1;
|
|
8195
|
|
8196 from = find_next_newline_no_quit (b, cur_pos, -win_char_height);
|
|
8197 to = line_start_cache_end (w);
|
|
8198 update_line_start_cache (w, from, to, point, 0);
|
|
8199
|
|
8200 cur_elt = point_in_line_start_cache (w, cur_pos, 2) - 1;
|
|
8201 assert (cur_elt >= -1);
|
|
8202 /* This used to be cur_elt>=0 under the assumption that if
|
|
8203 point is in the top line and not at BUF_BEGV, then
|
434
|
8204 setting the window_start to a newline before the start of
|
428
|
8205 the first line will always cause scrolling.
|
|
8206
|
|
8207 However in my (jv) opinion this is wrong. That new line
|
|
8208 can be hidden in various ways: invisible extents, an
|
|
8209 explicit window-start not at a newline character etc.
|
|
8210 The existence of those are indeed known to create crashes
|
|
8211 on that assert. So we have no option but to continue the
|
|
8212 search if we found point at the top of the line_start_cache
|
|
8213 again. */
|
434
|
8214 cur_pos = Dynarr_atp (w->line_start_cache,0)->start;
|
428
|
8215 }
|
|
8216 prev_pos = cur_pos;
|
|
8217 }
|
|
8218 }
|
|
8219
|
|
8220 /* For window W, what does the starting position have to be so that
|
|
8221 the line containing point is on display line LINE. If LINE is
|
|
8222 positive it is considered to be the number of lines from the top of
|
|
8223 the window (0 is the top line). If it is negative the number is
|
|
8224 considered to be the number of lines from the bottom (-1 is the
|
|
8225 bottom line). */
|
|
8226
|
665
|
8227 Charbpos
|
|
8228 start_with_point_on_display_line (struct window *w, Charbpos point, int line)
|
428
|
8229 {
|
|
8230 validate_line_start_cache (w);
|
|
8231 w->line_cache_validation_override++;
|
|
8232
|
|
8233 if (line >= 0)
|
|
8234 {
|
|
8235 int cur_elt = point_in_line_start_cache (w, point, line);
|
|
8236
|
|
8237 if (cur_elt - line < 0)
|
|
8238 cur_elt = 0; /* Hit the top */
|
|
8239 else
|
|
8240 cur_elt -= line;
|
|
8241
|
|
8242 w->line_cache_validation_override--;
|
|
8243 return Dynarr_atp (w->line_start_cache, cur_elt)->start;
|
|
8244 }
|
|
8245 else
|
|
8246 {
|
|
8247 /* The calculated value of pixpos is correct for the bottom line
|
|
8248 or what we want when line is -1. Therefore we subtract one
|
|
8249 because we have already handled one line. */
|
|
8250 int new_line = -line - 1;
|
|
8251 int cur_elt = point_in_line_start_cache (w, point, new_line);
|
|
8252 int pixpos = WINDOW_TEXT_BOTTOM (w);
|
665
|
8253 Charbpos retval, search_point;
|
428
|
8254
|
|
8255 /* If scroll_on_clipped_lines is false, the last "visible" line of
|
|
8256 the window covers the pixel at WINDOW_TEXT_BOTTOM (w) - 1.
|
|
8257 If s_o_c_l is true, then we don't want to count a clipped
|
|
8258 line, so back up from the bottom by the height of the line
|
|
8259 containing point. */
|
|
8260 if (scroll_on_clipped_lines)
|
|
8261 pixpos -= Dynarr_atp (w->line_start_cache, cur_elt)->height;
|
|
8262 else
|
|
8263 pixpos -= 1;
|
|
8264
|
|
8265 if (cur_elt + new_line >= Dynarr_length (w->line_start_cache))
|
|
8266 {
|
|
8267 /* Hit the bottom of the buffer. */
|
|
8268 int adjustment =
|
|
8269 (cur_elt + new_line) - Dynarr_length (w->line_start_cache) + 1;
|
|
8270 Lisp_Object window;
|
|
8271 int defheight;
|
|
8272
|
793
|
8273 window = wrap_window (w);
|
428
|
8274 default_face_height_and_width (window, &defheight, 0);
|
|
8275
|
|
8276 cur_elt = Dynarr_length (w->line_start_cache) - 1;
|
|
8277
|
|
8278 pixpos -= (adjustment * defheight);
|
|
8279 if (pixpos < WINDOW_TEXT_TOP (w))
|
|
8280 pixpos = WINDOW_TEXT_TOP (w);
|
|
8281 }
|
|
8282 else
|
|
8283 cur_elt = cur_elt + new_line;
|
|
8284
|
|
8285 search_point = Dynarr_atp (w->line_start_cache, cur_elt)->start;
|
|
8286
|
|
8287 retval = start_with_line_at_pixpos (w, search_point, pixpos);
|
|
8288 w->line_cache_validation_override--;
|
|
8289 return retval;
|
|
8290 }
|
|
8291 }
|
|
8292
|
|
8293 /* This is used to speed up vertical scrolling by caching the known
|
|
8294 buffer starting positions for display lines. This allows the
|
|
8295 scrolling routines to avoid costly calls to regenerate_window. If
|
|
8296 NO_REGEN is true then it will only add the values in the DESIRED
|
|
8297 display structs which are in the given range.
|
|
8298
|
|
8299 Note also that the FROM/TO values are minimums. It is possible
|
|
8300 that this function will actually add information outside of the
|
|
8301 lines containing those positions. This can't hurt but it could
|
|
8302 possibly help.
|
|
8303
|
|
8304 #### We currently force the cache to have only 1 contiguous region.
|
|
8305 It might help to make the cache a dynarr of caches so that we can
|
|
8306 cover more areas. This might, however, turn out to be a lot of
|
|
8307 overhead for too little gain. */
|
|
8308
|
|
8309 static void
|
665
|
8310 update_line_start_cache (struct window *w, Charbpos from, Charbpos to,
|
|
8311 Charbpos point, int no_regen)
|
428
|
8312 {
|
|
8313 struct buffer *b = XBUFFER (w->buffer);
|
|
8314 line_start_cache_dynarr *cache = w->line_start_cache;
|
665
|
8315 Charbpos low_bound, high_bound;
|
428
|
8316
|
|
8317 validate_line_start_cache (w);
|
|
8318 w->line_cache_validation_override++;
|
|
8319
|
|
8320 if (from < BUF_BEGV (b))
|
|
8321 from = BUF_BEGV (b);
|
|
8322 if (to > BUF_ZV (b))
|
|
8323 to = BUF_ZV (b);
|
|
8324
|
|
8325 if (from > to)
|
|
8326 {
|
|
8327 w->line_cache_validation_override--;
|
|
8328 return;
|
|
8329 }
|
|
8330
|
|
8331 if (Dynarr_length (cache))
|
|
8332 {
|
|
8333 low_bound = line_start_cache_start (w);
|
|
8334 high_bound = line_start_cache_end (w);
|
|
8335
|
|
8336 /* Check to see if the desired range is already in the cache. */
|
|
8337 if (from >= low_bound && to <= high_bound)
|
|
8338 {
|
|
8339 w->line_cache_validation_override--;
|
|
8340 return;
|
|
8341 }
|
|
8342
|
|
8343 /* Check to make sure that the desired range is adjacent to the
|
|
8344 current cache. If not, invalidate the cache. */
|
|
8345 if (to < low_bound || from > high_bound)
|
|
8346 {
|
|
8347 Dynarr_reset (cache);
|
|
8348 low_bound = high_bound = -1;
|
|
8349 }
|
|
8350 }
|
|
8351 else
|
|
8352 {
|
|
8353 low_bound = high_bound = -1;
|
|
8354 }
|
|
8355
|
|
8356 w->line_cache_last_updated = make_int (BUF_MODIFF (b));
|
|
8357
|
|
8358 /* This could be integrated into the next two sections, but it is easier
|
|
8359 to follow what's going on by having it separate. */
|
|
8360 if (no_regen)
|
|
8361 {
|
665
|
8362 Charbpos start, end;
|
428
|
8363
|
|
8364 update_internal_cache_list (w, DESIRED_DISP);
|
|
8365 if (!Dynarr_length (internal_cache))
|
|
8366 {
|
|
8367 w->line_cache_validation_override--;
|
|
8368 return;
|
|
8369 }
|
|
8370
|
|
8371 start = Dynarr_atp (internal_cache, 0)->start;
|
|
8372 end =
|
|
8373 Dynarr_atp (internal_cache, Dynarr_length (internal_cache) - 1)->end;
|
|
8374
|
|
8375 /* We aren't allowed to generate additional information to fill in
|
|
8376 gaps, so if the DESIRED structs don't overlap the cache, reset the
|
|
8377 cache. */
|
|
8378 if (Dynarr_length (cache))
|
|
8379 {
|
|
8380 if (end < low_bound || start > high_bound)
|
|
8381 Dynarr_reset (cache);
|
|
8382
|
|
8383 /* #### What should really happen if what we are doing is
|
|
8384 extending a line (the last line)? */
|
|
8385 if (Dynarr_length (cache) == 1
|
|
8386 && Dynarr_length (internal_cache) == 1)
|
|
8387 Dynarr_reset (cache);
|
|
8388 }
|
|
8389
|
|
8390 if (!Dynarr_length (cache))
|
|
8391 {
|
|
8392 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8393 Dynarr_length (internal_cache));
|
|
8394 w->line_cache_validation_override--;
|
|
8395 return;
|
|
8396 }
|
|
8397
|
|
8398 /* An extra check just in case the calling function didn't pass in
|
|
8399 the bounds of the DESIRED structs in the first place. */
|
|
8400 if (start >= low_bound && end <= high_bound)
|
|
8401 {
|
|
8402 w->line_cache_validation_override--;
|
|
8403 return;
|
|
8404 }
|
|
8405
|
|
8406 /* At this point we know that the internal cache partially overlaps
|
|
8407 the main cache. */
|
|
8408 if (start < low_bound)
|
|
8409 {
|
|
8410 int ic_elt = Dynarr_length (internal_cache) - 1;
|
|
8411 while (ic_elt >= 0)
|
|
8412 {
|
|
8413 if (Dynarr_atp (internal_cache, ic_elt)->start < low_bound)
|
|
8414 break;
|
|
8415 else
|
|
8416 ic_elt--;
|
|
8417 }
|
|
8418
|
|
8419 if (!(ic_elt >= 0))
|
|
8420 {
|
|
8421 Dynarr_reset (cache);
|
|
8422 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8423 Dynarr_length (internal_cache));
|
|
8424 w->line_cache_validation_override--;
|
|
8425 return;
|
|
8426 }
|
|
8427
|
|
8428 Dynarr_insert_many_at_start (cache, Dynarr_atp (internal_cache, 0),
|
|
8429 ic_elt + 1);
|
|
8430 }
|
|
8431
|
|
8432 if (end > high_bound)
|
|
8433 {
|
|
8434 int ic_elt = 0;
|
|
8435
|
|
8436 while (ic_elt < Dynarr_length (internal_cache))
|
|
8437 {
|
|
8438 if (Dynarr_atp (internal_cache, ic_elt)->start > high_bound)
|
|
8439 break;
|
|
8440 else
|
|
8441 ic_elt++;
|
|
8442 }
|
|
8443
|
|
8444 if (!(ic_elt < Dynarr_length (internal_cache)))
|
|
8445 {
|
|
8446 Dynarr_reset (cache);
|
|
8447 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8448 Dynarr_length (internal_cache));
|
|
8449 w->line_cache_validation_override--;
|
|
8450 return;
|
|
8451 }
|
|
8452
|
|
8453 Dynarr_add_many (cache, Dynarr_atp (internal_cache, ic_elt),
|
|
8454 Dynarr_length (internal_cache) - ic_elt);
|
|
8455 }
|
|
8456
|
|
8457 w->line_cache_validation_override--;
|
|
8458 return;
|
|
8459 }
|
|
8460
|
|
8461 if (!Dynarr_length (cache) || from < low_bound)
|
|
8462 {
|
665
|
8463 Charbpos startp = find_next_newline_no_quit (b, from, -1);
|
428
|
8464 int marker = 0;
|
|
8465 int old_lb = low_bound;
|
|
8466
|
|
8467 while (startp < old_lb || low_bound == -1)
|
|
8468 {
|
|
8469 int ic_elt;
|
665
|
8470 Charbpos new_startp;
|
428
|
8471
|
|
8472 regenerate_window (w, startp, point, CMOTION_DISP);
|
|
8473 update_internal_cache_list (w, CMOTION_DISP);
|
|
8474
|
|
8475 /* If this assert is triggered then regenerate_window failed
|
442
|
8476 to layout a single line. This is not possible since we
|
|
8477 force at least a single line to be layout for CMOTION_DISP */
|
|
8478 assert (Dynarr_length (internal_cache));
|
428
|
8479 assert (startp == Dynarr_atp (internal_cache, 0)->start);
|
|
8480
|
|
8481 ic_elt = Dynarr_length (internal_cache) - 1;
|
|
8482 if (low_bound != -1)
|
|
8483 {
|
|
8484 while (ic_elt >= 0)
|
|
8485 {
|
|
8486 if (Dynarr_atp (internal_cache, ic_elt)->start < old_lb)
|
|
8487 break;
|
|
8488 else
|
|
8489 ic_elt--;
|
|
8490 }
|
|
8491 }
|
|
8492 assert (ic_elt >= 0);
|
|
8493
|
|
8494 new_startp = Dynarr_atp (internal_cache, ic_elt)->end + 1;
|
|
8495
|
|
8496 /*
|
|
8497 * Handle invisible text properly:
|
|
8498 * If the last line we're inserting has the same end as the
|
|
8499 * line before which it will be added, merge the two lines.
|
|
8500 */
|
|
8501 if (Dynarr_length (cache) &&
|
|
8502 Dynarr_atp (internal_cache, ic_elt)->end ==
|
|
8503 Dynarr_atp (cache, marker)->end)
|
|
8504 {
|
|
8505 Dynarr_atp (cache, marker)->start
|
|
8506 = Dynarr_atp (internal_cache, ic_elt)->start;
|
|
8507 Dynarr_atp (cache, marker)->height
|
|
8508 = Dynarr_atp (internal_cache, ic_elt)->height;
|
|
8509 ic_elt--;
|
|
8510 }
|
|
8511
|
|
8512 if (ic_elt >= 0) /* we still have lines to add.. */
|
|
8513 {
|
|
8514 Dynarr_insert_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8515 ic_elt + 1, marker);
|
|
8516 marker += (ic_elt + 1);
|
|
8517 }
|
|
8518
|
|
8519 if (startp < low_bound || low_bound == -1)
|
|
8520 low_bound = startp;
|
|
8521 startp = new_startp;
|
|
8522 if (startp > BUF_ZV (b))
|
|
8523 {
|
|
8524 w->line_cache_validation_override--;
|
|
8525 return;
|
|
8526 }
|
|
8527 }
|
|
8528 }
|
|
8529
|
|
8530 assert (Dynarr_length (cache));
|
|
8531 assert (from >= low_bound);
|
|
8532
|
|
8533 /* Readjust the high_bound to account for any changes made while
|
|
8534 correcting the low_bound. */
|
|
8535 high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end;
|
|
8536
|
|
8537 if (to > high_bound)
|
|
8538 {
|
665
|
8539 Charbpos startp = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end + 1;
|
428
|
8540
|
|
8541 do
|
|
8542 {
|
|
8543 regenerate_window (w, startp, point, CMOTION_DISP);
|
|
8544 update_internal_cache_list (w, CMOTION_DISP);
|
|
8545
|
|
8546 /* See comment above about regenerate_window failing. */
|
|
8547 assert (Dynarr_length (internal_cache));
|
|
8548
|
|
8549 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
|
|
8550 Dynarr_length (internal_cache));
|
|
8551 high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end;
|
|
8552 startp = high_bound + 1;
|
|
8553 }
|
|
8554 while (to > high_bound);
|
|
8555 }
|
|
8556
|
|
8557 w->line_cache_validation_override--;
|
|
8558 assert (to <= high_bound);
|
|
8559 }
|
|
8560
|
|
8561
|
|
8562 /* Given x and y coordinates in characters, relative to a window,
|
|
8563 return the pixel location corresponding to those coordinates. The
|
|
8564 pixel location returned is the center of the given character
|
|
8565 position. The pixel values are generated relative to the window,
|
|
8566 not the frame.
|
|
8567
|
|
8568 The modeline is considered to be part of the window. */
|
|
8569
|
|
8570 void
|
|
8571 glyph_to_pixel_translation (struct window *w, int char_x, int char_y,
|
|
8572 int *pix_x, int *pix_y)
|
|
8573 {
|
|
8574 display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP);
|
|
8575 int num_disp_lines, modeline;
|
|
8576 Lisp_Object window;
|
|
8577 int defheight, defwidth;
|
|
8578
|
793
|
8579 window = wrap_window (w);
|
428
|
8580 default_face_height_and_width (window, &defheight, &defwidth);
|
|
8581
|
|
8582 /* If we get a bogus value indicating somewhere above or to the left of
|
|
8583 the window, use the first window line or character position
|
|
8584 instead. */
|
|
8585 if (char_y < 0)
|
|
8586 char_y = 0;
|
|
8587 if (char_x < 0)
|
|
8588 char_x = 0;
|
|
8589
|
|
8590 num_disp_lines = Dynarr_length (dla);
|
|
8591 modeline = 0;
|
|
8592 if (num_disp_lines)
|
|
8593 {
|
|
8594 if (Dynarr_atp (dla, 0)->modeline)
|
|
8595 {
|
|
8596 num_disp_lines--;
|
|
8597 modeline = 1;
|
|
8598 }
|
|
8599 }
|
|
8600
|
|
8601 /* First check if the y position intersects the display lines. */
|
|
8602 if (char_y < num_disp_lines)
|
|
8603 {
|
|
8604 struct display_line *dl = Dynarr_atp (dla, char_y + modeline);
|
|
8605 struct display_block *db = get_display_block_from_line (dl, TEXT);
|
|
8606
|
|
8607 *pix_y = (dl->ypos - dl->ascent +
|
647
|
8608 ((dl->ascent + dl->descent - dl->clip) >> 1));
|
428
|
8609
|
|
8610 if (char_x < Dynarr_length (db->runes))
|
|
8611 {
|
|
8612 struct rune *rb = Dynarr_atp (db->runes, char_x);
|
|
8613
|
|
8614 *pix_x = rb->xpos + (rb->width >> 1);
|
|
8615 }
|
|
8616 else
|
|
8617 {
|
|
8618 int last_rune = Dynarr_length (db->runes) - 1;
|
|
8619 struct rune *rb = Dynarr_atp (db->runes, last_rune);
|
|
8620
|
|
8621 char_x -= last_rune;
|
|
8622
|
|
8623 *pix_x = rb->xpos + rb->width;
|
|
8624 *pix_x += ((char_x - 1) * defwidth);
|
|
8625 *pix_x += (defwidth >> 1);
|
|
8626 }
|
|
8627 }
|
|
8628 else
|
|
8629 {
|
|
8630 /* It didn't intersect, so extrapolate. #### For now, we include the
|
|
8631 modeline in this since we don't have true character positions in
|
|
8632 it. */
|
|
8633
|
|
8634 if (!Dynarr_length (w->face_cachels))
|
|
8635 reset_face_cachels (w);
|
|
8636
|
|
8637 char_y -= num_disp_lines;
|
|
8638
|
|
8639 if (Dynarr_length (dla))
|
|
8640 {
|
|
8641 struct display_line *dl = Dynarr_atp (dla, Dynarr_length (dla) - 1);
|
|
8642 *pix_y = dl->ypos + dl->descent - dl->clip;
|
|
8643 }
|
|
8644 else
|
|
8645 *pix_y = WINDOW_TEXT_TOP (w);
|
|
8646
|
|
8647 *pix_y += (char_y * defheight);
|
|
8648 *pix_y += (defheight >> 1);
|
|
8649
|
|
8650 *pix_x = WINDOW_TEXT_LEFT (w);
|
|
8651 /* Don't adjust by one because this is still the unadjusted value. */
|
|
8652 *pix_x += (char_x * defwidth);
|
|
8653 *pix_x += (defwidth >> 1);
|
|
8654 }
|
|
8655
|
|
8656 if (*pix_x > w->pixel_left + w->pixel_width)
|
|
8657 *pix_x = w->pixel_left + w->pixel_width;
|
|
8658 if (*pix_y > w->pixel_top + w->pixel_height)
|
|
8659 *pix_y = w->pixel_top + w->pixel_height;
|
|
8660
|
|
8661 *pix_x -= w->pixel_left;
|
|
8662 *pix_y -= w->pixel_top;
|
|
8663 }
|
|
8664
|
|
8665 /* Given a display line and a position, determine if there is a glyph
|
|
8666 there and return information about it if there is. */
|
|
8667
|
|
8668 static void
|
|
8669 get_position_object (struct display_line *dl, Lisp_Object *obj1,
|
|
8670 Lisp_Object *obj2, int x_coord, int *low_x_coord,
|
|
8671 int *high_x_coord)
|
|
8672 {
|
|
8673 struct display_block *db;
|
|
8674 int elt;
|
|
8675 int block =
|
|
8676 get_next_display_block (dl->bounds, dl->display_blocks, x_coord, 0);
|
|
8677
|
|
8678 /* We use get_next_display_block to get the actual display block
|
|
8679 that would be displayed at x_coord. */
|
|
8680
|
|
8681 if (block == NO_BLOCK)
|
|
8682 return;
|
|
8683 else
|
|
8684 db = Dynarr_atp (dl->display_blocks, block);
|
|
8685
|
|
8686 for (elt = 0; elt < Dynarr_length (db->runes); elt++)
|
|
8687 {
|
|
8688 struct rune *rb = Dynarr_atp (db->runes, elt);
|
|
8689
|
|
8690 if (rb->xpos <= x_coord && x_coord < (rb->xpos + rb->width))
|
|
8691 {
|
|
8692 if (rb->type == RUNE_DGLYPH)
|
|
8693 {
|
|
8694 *obj1 = rb->object.dglyph.glyph;
|
|
8695 *obj2 = rb->object.dglyph.extent;
|
|
8696 }
|
|
8697 else
|
|
8698 {
|
|
8699 *obj1 = Qnil;
|
|
8700 *obj2 = Qnil;
|
|
8701 }
|
|
8702
|
|
8703 if (low_x_coord)
|
|
8704 *low_x_coord = rb->xpos;
|
|
8705 if (high_x_coord)
|
|
8706 *high_x_coord = rb->xpos + rb->width;
|
|
8707
|
|
8708 return;
|
|
8709 }
|
|
8710 }
|
|
8711 }
|
|
8712
|
|
8713 #define UPDATE_CACHE_RETURN \
|
|
8714 do { \
|
|
8715 d->pixel_to_glyph_cache.valid = 1; \
|
|
8716 d->pixel_to_glyph_cache.low_x_coord = low_x_coord; \
|
|
8717 d->pixel_to_glyph_cache.high_x_coord = high_x_coord; \
|
|
8718 d->pixel_to_glyph_cache.low_y_coord = low_y_coord; \
|
|
8719 d->pixel_to_glyph_cache.high_y_coord = high_y_coord; \
|
|
8720 d->pixel_to_glyph_cache.frame = f; \
|
|
8721 d->pixel_to_glyph_cache.col = *col; \
|
|
8722 d->pixel_to_glyph_cache.row = *row; \
|
|
8723 d->pixel_to_glyph_cache.obj_x = *obj_x; \
|
|
8724 d->pixel_to_glyph_cache.obj_y = *obj_y; \
|
|
8725 d->pixel_to_glyph_cache.w = *w; \
|
826
|
8726 d->pixel_to_glyph_cache.charpos = *charpos; \
|
428
|
8727 d->pixel_to_glyph_cache.closest = *closest; \
|
|
8728 d->pixel_to_glyph_cache.modeline_closest = *modeline_closest; \
|
|
8729 d->pixel_to_glyph_cache.obj1 = *obj1; \
|
|
8730 d->pixel_to_glyph_cache.obj2 = *obj2; \
|
|
8731 d->pixel_to_glyph_cache.retval = position; \
|
|
8732 RETURN_SANS_WARNINGS position; \
|
|
8733 } while (0)
|
|
8734
|
|
8735 /* Given x and y coordinates in pixels relative to a frame, return
|
|
8736 information about what is located under those coordinates.
|
|
8737
|
|
8738 The return value will be one of:
|
|
8739
|
|
8740 OVER_TOOLBAR: over one of the 4 frame toolbars
|
|
8741 OVER_MODELINE: over a modeline
|
|
8742 OVER_BORDER: over an internal border
|
|
8743 OVER_NOTHING: over the text area, but not over text
|
|
8744 OVER_OUTSIDE: outside of the frame border
|
|
8745 OVER_TEXT: over text in the text area
|
|
8746
|
|
8747 OBJ1 is one of
|
|
8748
|
|
8749 -- a toolbar button
|
|
8750 -- a glyph
|
|
8751 -- nil if the coordinates are not over a glyph or a toolbar button.
|
|
8752
|
|
8753 OBJ2 is one of
|
|
8754
|
|
8755 -- an extent, if the coordinates are over a glyph in the text area
|
|
8756 -- nil otherwise.
|
|
8757
|
|
8758 If the coordinates are over a glyph, OBJ_X and OBJ_Y give the
|
|
8759 equivalent coordinates relative to the upper-left corner of the glyph.
|
|
8760
|
|
8761 If the coordinates are over a character, OBJ_X and OBJ_Y give the
|
|
8762 equivalent coordinates relative to the upper-left corner of the character.
|
|
8763
|
|
8764 Otherwise, OBJ_X and OBJ_Y are undefined.
|
|
8765 */
|
|
8766
|
|
8767 int
|
|
8768 pixel_to_glyph_translation (struct frame *f, int x_coord, int y_coord,
|
|
8769 int *col, int *row, int *obj_x, int *obj_y,
|
826
|
8770 struct window **w, Charbpos *charpos,
|
665
|
8771 Charbpos *closest, Charcount *modeline_closest,
|
428
|
8772 Lisp_Object *obj1, Lisp_Object *obj2)
|
|
8773 {
|
|
8774 struct device *d;
|
|
8775 struct pixel_to_glyph_translation_cache *cache;
|
|
8776 Lisp_Object window;
|
|
8777 int frm_left, frm_right, frm_top, frm_bottom;
|
|
8778 int low_x_coord, high_x_coord, low_y_coord, high_y_coord;
|
|
8779 int position = OVER_NOTHING;
|
|
8780 int device_check_failed = 0;
|
|
8781 display_line_dynarr *dla;
|
|
8782
|
|
8783 /* This is a safety valve in case this got called with a frame in
|
|
8784 the middle of being deleted. */
|
|
8785 if (!DEVICEP (f->device) || !DEVICE_LIVE_P (XDEVICE (f->device)))
|
|
8786 {
|
|
8787 device_check_failed = 1;
|
|
8788 d = NULL, cache = NULL; /* Warning suppression */
|
|
8789 }
|
|
8790 else
|
|
8791 {
|
|
8792 d = XDEVICE (f->device);
|
|
8793 cache = &d->pixel_to_glyph_cache;
|
|
8794 }
|
|
8795
|
|
8796 if (!device_check_failed
|
|
8797 && cache->valid
|
|
8798 && cache->frame == f
|
|
8799 && cache->low_x_coord <= x_coord
|
|
8800 && cache->high_x_coord > x_coord
|
|
8801 && cache->low_y_coord <= y_coord
|
|
8802 && cache->high_y_coord > y_coord)
|
|
8803 {
|
|
8804 *col = cache->col;
|
|
8805 *row = cache->row;
|
|
8806 *obj_x = cache->obj_x;
|
|
8807 *obj_y = cache->obj_y;
|
|
8808 *w = cache->w;
|
826
|
8809 *charpos = cache->charpos;
|
428
|
8810 *closest = cache->closest;
|
|
8811 *modeline_closest = cache->modeline_closest;
|
|
8812 *obj1 = cache->obj1;
|
|
8813 *obj2 = cache->obj2;
|
|
8814
|
|
8815 return cache->retval;
|
|
8816 }
|
|
8817 else
|
|
8818 {
|
|
8819 *col = 0;
|
|
8820 *row = 0;
|
|
8821 *obj_x = 0;
|
|
8822 *obj_y = 0;
|
|
8823 *w = 0;
|
826
|
8824 *charpos = 0;
|
428
|
8825 *closest = 0;
|
|
8826 *modeline_closest = -1;
|
|
8827 *obj1 = Qnil;
|
|
8828 *obj2 = Qnil;
|
|
8829
|
|
8830 low_x_coord = x_coord;
|
|
8831 high_x_coord = x_coord + 1;
|
|
8832 low_y_coord = y_coord;
|
|
8833 high_y_coord = y_coord + 1;
|
|
8834 }
|
|
8835
|
|
8836 if (device_check_failed)
|
|
8837 return OVER_NOTHING;
|
|
8838
|
|
8839 frm_left = FRAME_LEFT_BORDER_END (f);
|
|
8840 frm_right = FRAME_RIGHT_BORDER_START (f);
|
|
8841 frm_top = FRAME_TOP_BORDER_END (f);
|
|
8842 frm_bottom = FRAME_BOTTOM_BORDER_START (f);
|
|
8843
|
|
8844 /* Check if the mouse is outside of the text area actually used by
|
|
8845 redisplay. */
|
|
8846 if (y_coord < frm_top)
|
|
8847 {
|
|
8848 if (y_coord >= FRAME_TOP_BORDER_START (f))
|
|
8849 {
|
|
8850 low_y_coord = FRAME_TOP_BORDER_START (f);
|
|
8851 high_y_coord = frm_top;
|
|
8852 position = OVER_BORDER;
|
|
8853 }
|
|
8854 else if (y_coord >= 0)
|
|
8855 {
|
|
8856 low_y_coord = 0;
|
|
8857 high_y_coord = FRAME_TOP_BORDER_START (f);
|
|
8858 position = OVER_TOOLBAR;
|
|
8859 }
|
|
8860 else
|
|
8861 {
|
|
8862 low_y_coord = y_coord;
|
|
8863 high_y_coord = 0;
|
|
8864 position = OVER_OUTSIDE;
|
|
8865 }
|
|
8866 }
|
|
8867 else if (y_coord >= frm_bottom)
|
|
8868 {
|
|
8869 if (y_coord < FRAME_BOTTOM_BORDER_END (f))
|
|
8870 {
|
|
8871 low_y_coord = frm_bottom;
|
|
8872 high_y_coord = FRAME_BOTTOM_BORDER_END (f);
|
|
8873 position = OVER_BORDER;
|
|
8874 }
|
|
8875 else if (y_coord < FRAME_PIXHEIGHT (f))
|
|
8876 {
|
|
8877 low_y_coord = FRAME_BOTTOM_BORDER_END (f);
|
|
8878 high_y_coord = FRAME_PIXHEIGHT (f);
|
|
8879 position = OVER_TOOLBAR;
|
|
8880 }
|
|
8881 else
|
|
8882 {
|
|
8883 low_y_coord = FRAME_PIXHEIGHT (f);
|
|
8884 high_y_coord = y_coord;
|
|
8885 position = OVER_OUTSIDE;
|
|
8886 }
|
|
8887 }
|
|
8888
|
|
8889 if (position != OVER_TOOLBAR && position != OVER_BORDER)
|
|
8890 {
|
|
8891 if (x_coord < frm_left)
|
|
8892 {
|
|
8893 if (x_coord >= FRAME_LEFT_BORDER_START (f))
|
|
8894 {
|
|
8895 low_x_coord = FRAME_LEFT_BORDER_START (f);
|
|
8896 high_x_coord = frm_left;
|
|
8897 position = OVER_BORDER;
|
|
8898 }
|
|
8899 else if (x_coord >= 0)
|
|
8900 {
|
|
8901 low_x_coord = 0;
|
|
8902 high_x_coord = FRAME_LEFT_BORDER_START (f);
|
|
8903 position = OVER_TOOLBAR;
|
|
8904 }
|
|
8905 else
|
|
8906 {
|
|
8907 low_x_coord = x_coord;
|
|
8908 high_x_coord = 0;
|
|
8909 position = OVER_OUTSIDE;
|
|
8910 }
|
|
8911 }
|
|
8912 else if (x_coord >= frm_right)
|
|
8913 {
|
|
8914 if (x_coord < FRAME_RIGHT_BORDER_END (f))
|
|
8915 {
|
|
8916 low_x_coord = frm_right;
|
|
8917 high_x_coord = FRAME_RIGHT_BORDER_END (f);
|
|
8918 position = OVER_BORDER;
|
|
8919 }
|
|
8920 else if (x_coord < FRAME_PIXWIDTH (f))
|
|
8921 {
|
|
8922 low_x_coord = FRAME_RIGHT_BORDER_END (f);
|
|
8923 high_x_coord = FRAME_PIXWIDTH (f);
|
|
8924 position = OVER_TOOLBAR;
|
|
8925 }
|
|
8926 else
|
|
8927 {
|
|
8928 low_x_coord = FRAME_PIXWIDTH (f);
|
|
8929 high_x_coord = x_coord;
|
|
8930 position = OVER_OUTSIDE;
|
|
8931 }
|
|
8932 }
|
|
8933 }
|
|
8934
|
|
8935 #ifdef HAVE_TOOLBARS
|
|
8936 if (position == OVER_TOOLBAR)
|
|
8937 {
|
|
8938 *obj1 = toolbar_button_at_pixpos (f, x_coord, y_coord);
|
|
8939 *obj2 = Qnil;
|
|
8940 *w = 0;
|
|
8941 UPDATE_CACHE_RETURN;
|
|
8942 }
|
|
8943 #endif /* HAVE_TOOLBARS */
|
|
8944
|
|
8945 /* We still have to return the window the pointer is next to and its
|
|
8946 relative y position even if it is outside the x boundary. */
|
|
8947 if (x_coord < frm_left)
|
|
8948 x_coord = frm_left;
|
|
8949 else if (x_coord > frm_right)
|
|
8950 x_coord = frm_right;
|
|
8951
|
|
8952 /* Same in reverse. */
|
|
8953 if (y_coord < frm_top)
|
|
8954 y_coord = frm_top;
|
|
8955 else if (y_coord > frm_bottom)
|
|
8956 y_coord = frm_bottom;
|
|
8957
|
|
8958 /* Find what window the given coordinates are actually in. */
|
|
8959 window = f->root_window;
|
|
8960 *w = find_window_by_pixel_pos (x_coord, y_coord, window);
|
|
8961
|
|
8962 /* If we didn't find a window, we're done. */
|
|
8963 if (!*w)
|
|
8964 {
|
|
8965 UPDATE_CACHE_RETURN;
|
|
8966 }
|
|
8967 else if (position != OVER_NOTHING)
|
|
8968 {
|
|
8969 *closest = 0;
|
|
8970 *modeline_closest = -1;
|
|
8971
|
|
8972 if (high_y_coord <= frm_top || high_y_coord >= frm_bottom)
|
|
8973 {
|
|
8974 *w = 0;
|
|
8975 UPDATE_CACHE_RETURN;
|
|
8976 }
|
|
8977 }
|
|
8978
|
|
8979 /* Check if the window is a minibuffer but isn't active. */
|
|
8980 if (MINI_WINDOW_P (*w) && !minibuf_level)
|
|
8981 {
|
|
8982 /* Must reset the window value since some callers will ignore
|
|
8983 the return value if it is set. */
|
|
8984 *w = 0;
|
|
8985 UPDATE_CACHE_RETURN;
|
|
8986 }
|
|
8987
|
|
8988 /* See if the point is over window vertical divider */
|
|
8989 if (window_needs_vertical_divider (*w))
|
|
8990 {
|
|
8991 int div_x_high = WINDOW_RIGHT (*w);
|
|
8992 int div_x_low = div_x_high - window_divider_width (*w);
|
|
8993 int div_y_high = WINDOW_BOTTOM (*w);
|
|
8994 int div_y_low = WINDOW_TOP (*w);
|
|
8995
|
|
8996 if (div_x_low < x_coord && x_coord <= div_x_high &&
|
|
8997 div_y_low < y_coord && y_coord <= div_y_high)
|
|
8998 {
|
|
8999 low_x_coord = div_x_low;
|
|
9000 high_x_coord = div_x_high;
|
|
9001 low_y_coord = div_y_low;
|
|
9002 high_y_coord = div_y_high;
|
|
9003 position = OVER_V_DIVIDER;
|
|
9004 UPDATE_CACHE_RETURN;
|
|
9005 }
|
|
9006 }
|
|
9007
|
|
9008 dla = window_display_lines (*w, CURRENT_DISP);
|
|
9009
|
|
9010 for (*row = 0; *row < Dynarr_length (dla); (*row)++)
|
|
9011 {
|
|
9012 int really_over_nothing = 0;
|
|
9013 struct display_line *dl = Dynarr_atp (dla, *row);
|
|
9014
|
|
9015 if ((int) (dl->ypos - dl->ascent) <= y_coord
|
|
9016 && y_coord <= (int) (dl->ypos + dl->descent))
|
|
9017 {
|
|
9018 int check_margin_glyphs = 0;
|
|
9019 struct display_block *db = get_display_block_from_line (dl, TEXT);
|
|
9020 struct rune *rb = 0;
|
|
9021
|
|
9022 if (x_coord < dl->bounds.left_white
|
|
9023 || x_coord >= dl->bounds.right_white)
|
|
9024 check_margin_glyphs = 1;
|
|
9025
|
|
9026 low_y_coord = dl->ypos - dl->ascent;
|
|
9027 high_y_coord = dl->ypos + dl->descent + 1;
|
|
9028
|
|
9029 if (position == OVER_BORDER
|
|
9030 || position == OVER_OUTSIDE
|
|
9031 || check_margin_glyphs)
|
|
9032 {
|
|
9033 int x_check, left_bound;
|
|
9034
|
|
9035 if (check_margin_glyphs)
|
|
9036 {
|
|
9037 x_check = x_coord;
|
|
9038 left_bound = dl->bounds.left_white;
|
|
9039 }
|
|
9040 else
|
|
9041 {
|
|
9042 x_check = high_x_coord;
|
|
9043 left_bound = frm_left;
|
|
9044 }
|
|
9045
|
|
9046 if (Dynarr_length (db->runes))
|
|
9047 {
|
|
9048 if (x_check <= left_bound)
|
|
9049 {
|
|
9050 if (dl->modeline)
|
826
|
9051 *modeline_closest = Dynarr_atp (db->runes, 0)->charpos;
|
428
|
9052 else
|
826
|
9053 *closest = Dynarr_atp (db->runes, 0)->charpos;
|
428
|
9054 }
|
|
9055 else
|
|
9056 {
|
|
9057 if (dl->modeline)
|
|
9058 *modeline_closest =
|
|
9059 Dynarr_atp (db->runes,
|
826
|
9060 Dynarr_length (db->runes) - 1)->charpos;
|
428
|
9061 else
|
|
9062 *closest =
|
|
9063 Dynarr_atp (db->runes,
|
826
|
9064 Dynarr_length (db->runes) - 1)->charpos;
|
428
|
9065 }
|
|
9066
|
|
9067 if (dl->modeline)
|
|
9068 *modeline_closest += dl->offset;
|
|
9069 else
|
|
9070 *closest += dl->offset;
|
|
9071 }
|
|
9072 else
|
|
9073 {
|
|
9074 /* #### What should be here. */
|
|
9075 if (dl->modeline)
|
|
9076 *modeline_closest = 0;
|
|
9077 else
|
|
9078 *closest = 0;
|
|
9079 }
|
|
9080
|
|
9081 if (check_margin_glyphs)
|
|
9082 {
|
|
9083 if (x_coord < dl->bounds.left_in
|
|
9084 || x_coord >= dl->bounds.right_in)
|
|
9085 {
|
|
9086 /* If we are over the outside margins then we
|
|
9087 know the loop over the text block isn't going
|
|
9088 to accomplish anything. So we go ahead and
|
|
9089 set what information we can right here and
|
|
9090 return. */
|
|
9091 (*row)--;
|
|
9092 *obj_y = y_coord - (dl->ypos - dl->ascent);
|
|
9093 get_position_object (dl, obj1, obj2, x_coord,
|
|
9094 &low_x_coord, &high_x_coord);
|
|
9095
|
|
9096 UPDATE_CACHE_RETURN;
|
|
9097 }
|
|
9098 }
|
|
9099 else
|
|
9100 UPDATE_CACHE_RETURN;
|
|
9101 }
|
|
9102
|
|
9103 for (*col = 0; *col <= Dynarr_length (db->runes); (*col)++)
|
|
9104 {
|
|
9105 int past_end = (*col == Dynarr_length (db->runes));
|
|
9106
|
|
9107 if (!past_end)
|
|
9108 rb = Dynarr_atp (db->runes, *col);
|
|
9109
|
|
9110 if (past_end ||
|
|
9111 (rb->xpos <= x_coord && x_coord < rb->xpos + rb->width))
|
|
9112 {
|
|
9113 if (past_end)
|
|
9114 {
|
|
9115 (*col)--;
|
|
9116 rb = Dynarr_atp (db->runes, *col);
|
|
9117 }
|
|
9118
|
826
|
9119 *charpos = rb->charpos + dl->offset;
|
428
|
9120 low_x_coord = rb->xpos;
|
|
9121 high_x_coord = rb->xpos + rb->width;
|
|
9122
|
|
9123 if (rb->type == RUNE_DGLYPH)
|
|
9124 {
|
|
9125 int elt = *col + 1;
|
|
9126
|
|
9127 /* Find the first character after the glyph. */
|
|
9128 while (elt < Dynarr_length (db->runes))
|
|
9129 {
|
|
9130 if (Dynarr_atp (db->runes, elt)->type != RUNE_DGLYPH)
|
|
9131 {
|
|
9132 if (dl->modeline)
|
|
9133 *modeline_closest =
|
826
|
9134 (Dynarr_atp (db->runes, elt)->charpos +
|
428
|
9135 dl->offset);
|
|
9136 else
|
|
9137 *closest =
|
826
|
9138 (Dynarr_atp (db->runes, elt)->charpos +
|
428
|
9139 dl->offset);
|
|
9140 break;
|
|
9141 }
|
|
9142
|
|
9143 elt++;
|
|
9144 }
|
|
9145
|
|
9146 /* In this case we failed to find a non-glyph
|
|
9147 character so we return the last position
|
|
9148 displayed on the line. */
|
|
9149 if (elt == Dynarr_length (db->runes))
|
|
9150 {
|
|
9151 if (dl->modeline)
|
826
|
9152 *modeline_closest = dl->end_charpos + dl->offset;
|
428
|
9153 else
|
826
|
9154 *closest = dl->end_charpos + dl->offset;
|
428
|
9155 really_over_nothing = 1;
|
|
9156 }
|
|
9157 }
|
|
9158 else
|
|
9159 {
|
|
9160 if (dl->modeline)
|
826
|
9161 *modeline_closest = rb->charpos + dl->offset;
|
428
|
9162 else
|
826
|
9163 *closest = rb->charpos + dl->offset;
|
428
|
9164 }
|
|
9165
|
|
9166 if (dl->modeline)
|
|
9167 {
|
|
9168 *row = window_displayed_height (*w);
|
|
9169
|
|
9170 if (position == OVER_NOTHING)
|
|
9171 position = OVER_MODELINE;
|
|
9172
|
|
9173 if (rb->type == RUNE_DGLYPH)
|
|
9174 {
|
|
9175 *obj1 = rb->object.dglyph.glyph;
|
|
9176 *obj2 = rb->object.dglyph.extent;
|
|
9177 }
|
|
9178 else if (rb->type == RUNE_CHAR)
|
|
9179 {
|
|
9180 *obj1 = Qnil;
|
|
9181 *obj2 = Qnil;
|
|
9182 }
|
|
9183 else
|
|
9184 {
|
|
9185 *obj1 = Qnil;
|
|
9186 *obj2 = Qnil;
|
|
9187 }
|
|
9188
|
|
9189 UPDATE_CACHE_RETURN;
|
|
9190 }
|
|
9191 else if (past_end
|
|
9192 || (rb->type == RUNE_CHAR
|
|
9193 && rb->object.chr.ch == '\n'))
|
|
9194 {
|
|
9195 (*row)--;
|
|
9196 /* At this point we may have glyphs in the right
|
|
9197 inside margin. */
|
|
9198 if (check_margin_glyphs)
|
|
9199 get_position_object (dl, obj1, obj2, x_coord,
|
|
9200 &low_x_coord, &high_x_coord);
|
|
9201 UPDATE_CACHE_RETURN;
|
|
9202 }
|
|
9203 else
|
|
9204 {
|
|
9205 (*row)--;
|
|
9206 if (rb->type == RUNE_DGLYPH)
|
|
9207 {
|
|
9208 *obj1 = rb->object.dglyph.glyph;
|
|
9209 *obj2 = rb->object.dglyph.extent;
|
|
9210 }
|
|
9211 else if (rb->type == RUNE_CHAR)
|
|
9212 {
|
|
9213 *obj1 = Qnil;
|
|
9214 *obj2 = Qnil;
|
|
9215 }
|
|
9216 else
|
|
9217 {
|
|
9218 *obj1 = Qnil;
|
|
9219 *obj2 = Qnil;
|
|
9220 }
|
|
9221
|
|
9222 *obj_x = x_coord - rb->xpos;
|
|
9223 *obj_y = y_coord - (dl->ypos - dl->ascent);
|
|
9224
|
|
9225 /* At this point we may have glyphs in the left
|
|
9226 inside margin. */
|
|
9227 if (check_margin_glyphs)
|
|
9228 get_position_object (dl, obj1, obj2, x_coord, 0, 0);
|
|
9229
|
|
9230 if (position == OVER_NOTHING && !really_over_nothing)
|
|
9231 position = OVER_TEXT;
|
|
9232
|
|
9233 UPDATE_CACHE_RETURN;
|
|
9234 }
|
|
9235 }
|
|
9236 }
|
|
9237 }
|
|
9238 }
|
|
9239
|
|
9240 *row = Dynarr_length (dla) - 1;
|
|
9241 if (FRAME_WIN_P (f))
|
|
9242 {
|
|
9243 int bot_elt = Dynarr_length (dla) - 1;
|
|
9244
|
|
9245 if (bot_elt >= 0)
|
|
9246 {
|
|
9247 struct display_line *dl = Dynarr_atp (dla, bot_elt);
|
|
9248 int adj_area = y_coord - (dl->ypos + dl->descent);
|
|
9249 Lisp_Object lwin;
|
|
9250 int defheight;
|
|
9251
|
793
|
9252 lwin = wrap_window (*w);
|
428
|
9253 default_face_height_and_width (lwin, 0, &defheight);
|
|
9254
|
|
9255 *row += (adj_area / defheight);
|
|
9256 }
|
|
9257 }
|
|
9258
|
|
9259 /* #### This should be checked out some more to determine what
|
|
9260 should really be going on. */
|
|
9261 if (!MARKERP ((*w)->start[CURRENT_DISP]))
|
|
9262 *closest = 0;
|
|
9263 else
|
442
|
9264 *closest = end_of_last_line_may_error (*w,
|
428
|
9265 marker_position ((*w)->start[CURRENT_DISP]));
|
|
9266 *col = 0;
|
|
9267 UPDATE_CACHE_RETURN;
|
|
9268 }
|
|
9269 #undef UPDATE_CACHE_RETURN
|
|
9270
|
|
9271
|
|
9272 /***************************************************************************/
|
|
9273 /* */
|
|
9274 /* Lisp functions */
|
|
9275 /* */
|
|
9276 /***************************************************************************/
|
|
9277
|
|
9278 DEFUN ("redisplay-echo-area", Fredisplay_echo_area, 0, 0, 0, /*
|
|
9279 Ensure that all minibuffers are correctly showing the echo area.
|
|
9280 */
|
|
9281 ())
|
|
9282 {
|
|
9283 Lisp_Object devcons, concons;
|
|
9284
|
1318
|
9285 if (in_display)
|
|
9286 return Qnil;
|
|
9287
|
428
|
9288 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
9289 {
|
|
9290 struct device *d = XDEVICE (XCAR (devcons));
|
|
9291 Lisp_Object frmcons;
|
|
9292
|
1279
|
9293 if (DEVICE_STREAM_P (d))
|
|
9294 continue;
|
|
9295
|
428
|
9296 DEVICE_FRAME_LOOP (frmcons, d)
|
|
9297 {
|
|
9298 struct frame *f = XFRAME (XCAR (frmcons));
|
853
|
9299 int depth;
|
428
|
9300
|
|
9301 if (FRAME_REPAINT_P (f) && FRAME_HAS_MINIBUF_P (f))
|
|
9302 {
|
|
9303 Lisp_Object window = FRAME_MINIBUF_WINDOW (f);
|
442
|
9304
|
|
9305 MAYBE_DEVMETH (d, frame_output_begin, (f));
|
|
9306
|
428
|
9307 /*
|
|
9308 * If the frame size has changed, there may be random
|
|
9309 * chud on the screen left from previous messages
|
|
9310 * because redisplay_frame hasn't been called yet.
|
|
9311 * Clear the screen to get rid of the potential mess.
|
|
9312 */
|
|
9313 if (f->echo_area_garbaged)
|
|
9314 {
|
442
|
9315 MAYBE_DEVMETH (d, clear_frame, (f));
|
428
|
9316 f->echo_area_garbaged = 0;
|
|
9317 }
|
853
|
9318 depth = enter_redisplay_critical_section ();
|
428
|
9319 redisplay_window (window, 0);
|
853
|
9320 exit_redisplay_critical_section (depth);
|
442
|
9321 MAYBE_DEVMETH (d, frame_output_end, (f));
|
428
|
9322 }
|
|
9323 }
|
|
9324 }
|
|
9325
|
|
9326 return Qnil;
|
|
9327 }
|
|
9328
|
|
9329 DEFUN ("redraw-frame", Fredraw_frame, 0, 2, 0, /*
|
|
9330 Clear frame FRAME and output again what is supposed to appear on it.
|
|
9331 FRAME defaults to the selected frame if omitted.
|
|
9332 Normally, redisplay is preempted as normal if input arrives. However,
|
|
9333 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
|
|
9334 input and is guaranteed to proceed to completion.
|
|
9335 */
|
|
9336 (frame, no_preempt))
|
|
9337 {
|
|
9338 struct frame *f = decode_frame (frame);
|
|
9339 int count = specpdl_depth ();
|
|
9340
|
|
9341 if (!NILP (no_preempt))
|
853
|
9342 internal_bind_int (&disable_preemption, 1 + disable_preemption);
|
428
|
9343
|
|
9344 f->clear = 1;
|
|
9345 redisplay_frame (f, 1);
|
|
9346
|
442
|
9347 /* See the comment in Fredisplay_frame. */
|
|
9348 RESET_CHANGED_SET_FLAGS;
|
|
9349
|
771
|
9350 return unbind_to (count);
|
428
|
9351 }
|
|
9352
|
|
9353 DEFUN ("redisplay-frame", Fredisplay_frame, 0, 2, 0, /*
|
|
9354 Ensure that FRAME's contents are correctly displayed.
|
|
9355 This differs from `redraw-frame' in that it only redraws what needs to
|
|
9356 be updated, as opposed to unconditionally clearing and redrawing
|
|
9357 the frame.
|
|
9358 FRAME defaults to the selected frame if omitted.
|
|
9359 Normally, redisplay is preempted as normal if input arrives. However,
|
|
9360 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
|
|
9361 input and is guaranteed to proceed to completion.
|
|
9362 */
|
|
9363 (frame, no_preempt))
|
|
9364 {
|
|
9365 struct frame *f = decode_frame (frame);
|
|
9366 int count = specpdl_depth ();
|
|
9367
|
|
9368 if (!NILP (no_preempt))
|
853
|
9369 internal_bind_int (&disable_preemption, 1 + disable_preemption);
|
428
|
9370
|
|
9371 redisplay_frame (f, 1);
|
|
9372
|
442
|
9373 /* If we don't reset the global redisplay flags here, subsequent
|
|
9374 changes to the display will not get registered by redisplay
|
|
9375 because it thinks it already has registered changes. If you
|
|
9376 really knew what you were doing you could confuse redisplay by
|
|
9377 calling Fredisplay_frame while updating another frame. We assume
|
|
9378 that if you know what you are doing you will not be that
|
|
9379 stupid. */
|
|
9380 RESET_CHANGED_SET_FLAGS;
|
|
9381
|
771
|
9382 return unbind_to (count);
|
428
|
9383 }
|
|
9384
|
|
9385 DEFUN ("redraw-device", Fredraw_device, 0, 2, 0, /*
|
|
9386 Clear device DEVICE and output again what is supposed to appear on it.
|
|
9387 DEVICE defaults to the selected device if omitted.
|
|
9388 Normally, redisplay is preempted as normal if input arrives. However,
|
|
9389 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
|
|
9390 input and is guaranteed to proceed to completion.
|
|
9391 */
|
|
9392 (device, no_preempt))
|
|
9393 {
|
|
9394 struct device *d = decode_device (device);
|
|
9395 Lisp_Object frmcons;
|
|
9396 int count = specpdl_depth ();
|
|
9397
|
|
9398 if (!NILP (no_preempt))
|
853
|
9399 internal_bind_int (&disable_preemption, 1 + disable_preemption);
|
428
|
9400
|
|
9401 DEVICE_FRAME_LOOP (frmcons, d)
|
|
9402 {
|
|
9403 XFRAME (XCAR (frmcons))->clear = 1;
|
|
9404 }
|
440
|
9405 redisplay_device (d, 0);
|
428
|
9406
|
442
|
9407 /* See the comment in Fredisplay_frame. */
|
|
9408 RESET_CHANGED_SET_FLAGS;
|
|
9409
|
771
|
9410 return unbind_to (count);
|
428
|
9411 }
|
|
9412
|
|
9413 DEFUN ("redisplay-device", Fredisplay_device, 0, 2, 0, /*
|
|
9414 Ensure that DEVICE's contents are correctly displayed.
|
|
9415 This differs from `redraw-device' in that it only redraws what needs to
|
|
9416 be updated, as opposed to unconditionally clearing and redrawing
|
|
9417 the device.
|
|
9418 DEVICE defaults to the selected device if omitted.
|
|
9419 Normally, redisplay is preempted as normal if input arrives. However,
|
|
9420 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for
|
|
9421 input and is guaranteed to proceed to completion.
|
853
|
9422
|
|
9423 Note: If you simply want everything redisplayed, the current idiom is
|
|
9424 `(sit-for 0)'.
|
428
|
9425 */
|
|
9426 (device, no_preempt))
|
|
9427 {
|
|
9428 struct device *d = decode_device (device);
|
|
9429 int count = specpdl_depth ();
|
|
9430
|
|
9431 if (!NILP (no_preempt))
|
853
|
9432 internal_bind_int (&disable_preemption, 1 + disable_preemption);
|
428
|
9433
|
440
|
9434 redisplay_device (d, 0);
|
428
|
9435
|
442
|
9436 /* See the comment in Fredisplay_frame. */
|
|
9437 RESET_CHANGED_SET_FLAGS;
|
|
9438
|
771
|
9439 return unbind_to (count);
|
428
|
9440 }
|
|
9441
|
|
9442 /* Big lie. Big lie. This will force all modelines to be updated
|
|
9443 regardless if the all flag is set or not. It remains in existence
|
|
9444 solely for backwards compatibility. */
|
|
9445 DEFUN ("redraw-modeline", Fredraw_modeline, 0, 1, 0, /*
|
|
9446 Force the modeline of the current buffer to be redisplayed.
|
|
9447 With optional non-nil ALL, force redisplay of all modelines.
|
|
9448 */
|
2286
|
9449 (UNUSED (all)))
|
428
|
9450 {
|
|
9451 MARK_MODELINE_CHANGED;
|
|
9452 return Qnil;
|
|
9453 }
|
|
9454
|
|
9455 DEFUN ("force-cursor-redisplay", Fforce_cursor_redisplay, 0, 1, 0, /*
|
|
9456 Force an immediate update of the cursor on FRAME.
|
|
9457 FRAME defaults to the selected frame if omitted.
|
|
9458 */
|
|
9459 (frame))
|
|
9460 {
|
1279
|
9461 struct frame *f = decode_frame (frame);
|
|
9462
|
|
9463 if (!FRAME_STREAM_P (f))
|
|
9464 redisplay_redraw_cursor (f, 1);
|
428
|
9465 return Qnil;
|
|
9466 }
|
|
9467
|
|
9468
|
|
9469 /***************************************************************************/
|
|
9470 /* */
|
872
|
9471 /* Change flags */
|
428
|
9472 /* */
|
|
9473 /***************************************************************************/
|
|
9474
|
|
9475 static void
|
2286
|
9476 margin_width_changed_in_frame (Lisp_Object UNUSED (specifier),
|
|
9477 struct frame *UNUSED (f),
|
|
9478 Lisp_Object UNUSED (oldval))
|
428
|
9479 {
|
|
9480 /* Nothing to be done? */
|
|
9481 }
|
|
9482
|
|
9483 int
|
2286
|
9484 redisplay_variable_changed (Lisp_Object UNUSED (sym),
|
|
9485 Lisp_Object *UNUSED (val),
|
|
9486 Lisp_Object UNUSED (in_object),
|
|
9487 int UNUSED (flags))
|
428
|
9488 {
|
|
9489 /* #### clip_changed should really be renamed something like
|
|
9490 global_redisplay_change. */
|
|
9491 MARK_CLIP_CHANGED;
|
|
9492 return 0;
|
|
9493 }
|
|
9494
|
|
9495 /* This is called if the built-in glyphs have their properties
|
|
9496 changed. */
|
|
9497 void
|
2286
|
9498 redisplay_glyph_changed (Lisp_Object UNUSED (glyph),
|
|
9499 Lisp_Object UNUSED (property), Lisp_Object locale)
|
428
|
9500 {
|
|
9501 if (WINDOWP (locale))
|
|
9502 {
|
|
9503 MARK_FRAME_GLYPHS_CHANGED (XFRAME (WINDOW_FRAME (XWINDOW (locale))));
|
|
9504 }
|
|
9505 else if (FRAMEP (locale))
|
|
9506 {
|
|
9507 MARK_FRAME_GLYPHS_CHANGED (XFRAME (locale));
|
|
9508 }
|
|
9509 else if (DEVICEP (locale))
|
|
9510 {
|
|
9511 Lisp_Object frmcons;
|
|
9512 DEVICE_FRAME_LOOP (frmcons, XDEVICE (locale))
|
|
9513 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons)));
|
|
9514 }
|
|
9515 else if (CONSOLEP (locale))
|
|
9516 {
|
|
9517 Lisp_Object frmcons, devcons;
|
|
9518 CONSOLE_FRAME_LOOP_NO_BREAK (frmcons, devcons, XCONSOLE (locale))
|
|
9519 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons)));
|
|
9520 }
|
|
9521 else /* global or buffer */
|
|
9522 {
|
|
9523 Lisp_Object frmcons, devcons, concons;
|
|
9524 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
9525 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons)));
|
|
9526 }
|
|
9527 }
|
|
9528
|
|
9529 static void
|
2286
|
9530 text_cursor_visible_p_changed (Lisp_Object UNUSED (specifier),
|
|
9531 struct window *w, Lisp_Object UNUSED (oldval))
|
428
|
9532 {
|
|
9533 if (XFRAME (w->frame)->init_finished)
|
|
9534 Fforce_cursor_redisplay (w->frame);
|
|
9535 }
|
|
9536
|
872
|
9537 void
|
|
9538 mark_buffers_changed (void)
|
|
9539 {
|
|
9540 MARK_TYPE_CHANGED (buffers);
|
|
9541 }
|
|
9542
|
|
9543 void
|
|
9544 mark_clip_changed (void)
|
|
9545 {
|
|
9546 MARK_TYPE_CHANGED (clip);
|
|
9547 }
|
|
9548
|
|
9549 void
|
|
9550 mark_extents_changed (void)
|
|
9551 {
|
|
9552 MARK_TYPE_CHANGED (extents);
|
|
9553 }
|
|
9554
|
|
9555 void
|
|
9556 mark_icon_changed (void)
|
|
9557 {
|
|
9558 MARK_TYPE_CHANGED (icon);
|
|
9559 }
|
|
9560
|
|
9561 void
|
|
9562 mark_menubar_changed (void)
|
|
9563 {
|
|
9564 MARK_TYPE_CHANGED (menubar);
|
|
9565 }
|
|
9566
|
|
9567 void
|
|
9568 mark_modeline_changed (void)
|
|
9569 {
|
|
9570 MARK_TYPE_CHANGED (modeline);
|
|
9571 }
|
|
9572
|
|
9573 void
|
|
9574 mark_point_changed (void)
|
|
9575 {
|
|
9576 MARK_TYPE_CHANGED (point);
|
|
9577 }
|
|
9578
|
|
9579 void
|
|
9580 mark_toolbar_changed (void)
|
|
9581 {
|
|
9582 MARK_TYPE_CHANGED (toolbar);
|
|
9583 }
|
|
9584
|
|
9585 void
|
|
9586 mark_gutter_changed (void)
|
|
9587 {
|
|
9588 MARK_TYPE_CHANGED (gutter);
|
|
9589 }
|
|
9590
|
|
9591 void
|
|
9592 mark_glyphs_changed (void)
|
|
9593 {
|
|
9594 MARK_TYPE_CHANGED (glyphs);
|
|
9595 }
|
|
9596
|
|
9597 void
|
|
9598 mark_subwindows_changed (void)
|
|
9599 {
|
|
9600 MARK_TYPE_CHANGED (subwindows);
|
|
9601 }
|
|
9602
|
|
9603 void
|
|
9604 mark_subwindows_state_changed (void)
|
|
9605 {
|
|
9606 MARK_TYPE_CHANGED (subwindows_state);
|
|
9607 }
|
|
9608
|
428
|
9609 #ifdef MEMORY_USAGE_STATS
|
|
9610
|
|
9611
|
|
9612 /***************************************************************************/
|
|
9613 /* */
|
|
9614 /* memory usage computation */
|
|
9615 /* */
|
|
9616 /***************************************************************************/
|
|
9617
|
|
9618 static int
|
|
9619 compute_rune_dynarr_usage (rune_dynarr *dyn, struct overhead_stats *ovstats)
|
|
9620 {
|
|
9621 return dyn ? Dynarr_memory_usage (dyn, ovstats) : 0;
|
|
9622 }
|
|
9623
|
|
9624 static int
|
|
9625 compute_display_block_dynarr_usage (display_block_dynarr *dyn,
|
|
9626 struct overhead_stats *ovstats)
|
|
9627 {
|
|
9628 int total, i;
|
|
9629
|
|
9630 if (!dyn)
|
|
9631 return 0;
|
|
9632
|
|
9633 total = Dynarr_memory_usage (dyn, ovstats);
|
|
9634 for (i = 0; i < Dynarr_largest (dyn); i++)
|
|
9635 total += compute_rune_dynarr_usage (Dynarr_at (dyn, i).runes, ovstats);
|
|
9636
|
|
9637 return total;
|
|
9638 }
|
|
9639
|
|
9640 static int
|
|
9641 compute_glyph_block_dynarr_usage (glyph_block_dynarr *dyn,
|
|
9642 struct overhead_stats *ovstats)
|
|
9643 {
|
|
9644 return dyn ? Dynarr_memory_usage (dyn, ovstats) : 0;
|
|
9645 }
|
|
9646
|
|
9647 int
|
|
9648 compute_display_line_dynarr_usage (display_line_dynarr *dyn,
|
|
9649 struct overhead_stats *ovstats)
|
|
9650 {
|
|
9651 int total, i;
|
|
9652
|
|
9653 if (!dyn)
|
|
9654 return 0;
|
|
9655
|
|
9656 total = Dynarr_memory_usage (dyn, ovstats);
|
|
9657 for (i = 0; i < Dynarr_largest (dyn); i++)
|
|
9658 {
|
|
9659 struct display_line *dl = &Dynarr_at (dyn, i);
|
|
9660 total += compute_display_block_dynarr_usage(dl->display_blocks, ovstats);
|
|
9661 total += compute_glyph_block_dynarr_usage (dl->left_glyphs, ovstats);
|
|
9662 total += compute_glyph_block_dynarr_usage (dl->right_glyphs, ovstats);
|
|
9663 }
|
|
9664
|
|
9665 return total;
|
|
9666 }
|
|
9667
|
|
9668 int
|
|
9669 compute_line_start_cache_dynarr_usage (line_start_cache_dynarr *dyn,
|
|
9670 struct overhead_stats *ovstats)
|
|
9671 {
|
|
9672 return dyn ? Dynarr_memory_usage (dyn, ovstats) : 0;
|
|
9673 }
|
|
9674
|
|
9675 #endif /* MEMORY_USAGE_STATS */
|
|
9676
|
1204
|
9677 #ifdef ERROR_CHECK_DISPLAY
|
|
9678
|
800
|
9679 static int
|
2286
|
9680 sledgehammer_check_redisplay_structs_1 (struct window *w,
|
|
9681 void *UNUSED (closure))
|
800
|
9682 {
|
|
9683 int i, j;
|
|
9684 display_line_dynarr *dl;
|
|
9685
|
|
9686 dl = window_display_lines (w, CURRENT_DISP);
|
|
9687
|
|
9688 for (i = 0; i < Dynarr_largest (dl); i++)
|
|
9689 for (j = i + 1; j < Dynarr_largest (dl); j++)
|
|
9690 assert (Dynarr_atp (dl, i)->display_blocks !=
|
|
9691 Dynarr_atp (dl, j)->display_blocks);
|
|
9692
|
|
9693 dl = window_display_lines (w, DESIRED_DISP);
|
|
9694
|
|
9695 for (i = 0; i < Dynarr_largest (dl); i++)
|
|
9696 for (j = i + 1; j < Dynarr_largest (dl); j++)
|
|
9697 assert (Dynarr_atp (dl, i)->display_blocks !=
|
|
9698 Dynarr_atp (dl, j)->display_blocks);
|
|
9699
|
|
9700 return 0;
|
|
9701 }
|
|
9702
|
|
9703 static void
|
|
9704 sledgehammer_check_redisplay_structs (void)
|
|
9705 {
|
|
9706 map_windows (0, sledgehammer_check_redisplay_structs_1, NULL);
|
|
9707 }
|
|
9708
|
1204
|
9709 #endif /* ERROR_CHECK_DISPLAY */
|
|
9710
|
428
|
9711
|
|
9712 /***************************************************************************/
|
|
9713 /* */
|
|
9714 /* initialization */
|
|
9715 /* */
|
|
9716 /***************************************************************************/
|
|
9717
|
|
9718 void
|
|
9719 init_redisplay (void)
|
|
9720 {
|
|
9721 disable_preemption = 0;
|
|
9722 preemption_count = 0;
|
|
9723
|
|
9724 #ifndef PDUMP
|
|
9725 if (!initialized)
|
|
9726 #endif
|
|
9727 {
|
440
|
9728 if (!cmotion_display_lines)
|
|
9729 cmotion_display_lines = Dynarr_new (display_line);
|
867
|
9730 if (!mode_spec_ibyte_string)
|
|
9731 mode_spec_ibyte_string = Dynarr_new (Ibyte);
|
440
|
9732 if (!formatted_string_extent_dynarr)
|
|
9733 formatted_string_extent_dynarr = Dynarr_new (EXTENT);
|
|
9734 if (!formatted_string_extent_start_dynarr)
|
|
9735 formatted_string_extent_start_dynarr = Dynarr_new (Bytecount);
|
|
9736 if (!formatted_string_extent_end_dynarr)
|
|
9737 formatted_string_extent_end_dynarr = Dynarr_new (Bytecount);
|
|
9738 if (!internal_cache)
|
|
9739 internal_cache = Dynarr_new (line_start_cache);
|
428
|
9740 }
|
|
9741
|
|
9742 /* window system is nil when in -batch mode */
|
|
9743 if (!initialized || noninteractive)
|
|
9744 return;
|
|
9745
|
|
9746 /* If the user wants to use a window system, we shouldn't bother
|
|
9747 initializing the terminal. This is especially important when the
|
|
9748 terminal is so dumb that emacs gives up before and doesn't bother
|
|
9749 using the window system.
|
|
9750
|
|
9751 If the DISPLAY environment variable is set, try to use X, and die
|
|
9752 with an error message if that doesn't work. */
|
|
9753
|
|
9754 #ifdef HAVE_X_WINDOWS
|
|
9755 if (!strcmp (display_use, "x"))
|
|
9756 {
|
|
9757 /* Some stuff checks this way early. */
|
|
9758 Vwindow_system = Qx;
|
|
9759 Vinitial_window_system = Qx;
|
|
9760 return;
|
|
9761 }
|
|
9762 #endif /* HAVE_X_WINDOWS */
|
|
9763
|
462
|
9764 #ifdef HAVE_GTK
|
|
9765 if (!strcmp (display_use, "gtk"))
|
|
9766 {
|
|
9767 Vwindow_system = Qgtk;
|
|
9768 Vinitial_window_system = Qgtk;
|
|
9769 return;
|
|
9770 }
|
|
9771 #endif
|
|
9772
|
428
|
9773 #ifdef HAVE_MS_WINDOWS
|
|
9774 if (!strcmp (display_use, "mswindows"))
|
|
9775 {
|
|
9776 /* Some stuff checks this way early. */
|
|
9777 Vwindow_system = Qmswindows;
|
|
9778 Vinitial_window_system = Qmswindows;
|
|
9779 return;
|
|
9780 }
|
|
9781 #endif /* HAVE_MS_WINDOWS */
|
|
9782
|
|
9783 #ifdef HAVE_TTY
|
|
9784 /* If no window system has been specified, try to use the terminal. */
|
|
9785 if (!isatty (0))
|
|
9786 {
|
|
9787 stderr_out ("XEmacs: standard input is not a tty\n");
|
|
9788 exit (1);
|
|
9789 }
|
|
9790
|
|
9791 /* Look at the TERM variable */
|
771
|
9792 if (!egetenv ("TERM"))
|
428
|
9793 {
|
|
9794 stderr_out ("Please set the environment variable TERM; see tset(1).\n");
|
|
9795 exit (1);
|
|
9796 }
|
|
9797
|
|
9798 Vinitial_window_system = Qtty;
|
|
9799 return;
|
|
9800 #else /* not HAVE_TTY */
|
|
9801 /* No DISPLAY specified, and no TTY support. */
|
|
9802 stderr_out ("XEmacs: Cannot open display.\n\
|
|
9803 Please set the environmental variable DISPLAY to an appropriate value.\n");
|
|
9804 exit (1);
|
|
9805 #endif
|
|
9806 /* Unreached. */
|
|
9807 }
|
|
9808
|
|
9809 void
|
|
9810 syms_of_redisplay (void)
|
|
9811 {
|
563
|
9812 DEFSYMBOL (Qcursor_in_echo_area);
|
|
9813 DEFSYMBOL (Qdisplay_warning_buffer);
|
|
9814 DEFSYMBOL (Qbar_cursor);
|
|
9815 DEFSYMBOL (Qtop_bottom);
|
|
9816 DEFSYMBOL (Qbuffer_list_changed_hook);
|
428
|
9817
|
|
9818 DEFSUBR (Fredisplay_echo_area);
|
|
9819 DEFSUBR (Fredraw_frame);
|
|
9820 DEFSUBR (Fredisplay_frame);
|
|
9821 DEFSUBR (Fredraw_device);
|
|
9822 DEFSUBR (Fredisplay_device);
|
|
9823 DEFSUBR (Fredraw_modeline);
|
|
9824 DEFSUBR (Fforce_cursor_redisplay);
|
|
9825 }
|
|
9826
|
|
9827 void
|
|
9828 vars_of_redisplay (void)
|
|
9829 {
|
1292
|
9830 QSin_redisplay = build_msg_string ("(in redisplay)");
|
|
9831 staticpro (&QSin_redisplay);
|
428
|
9832
|
1318
|
9833 Vpost_redisplay_actions = Qnil;
|
|
9834 staticpro (&Vpost_redisplay_actions);
|
|
9835
|
428
|
9836 #if 0
|
|
9837 staticpro (&last_arrow_position);
|
|
9838 staticpro (&last_arrow_string);
|
|
9839 last_arrow_position = Qnil;
|
|
9840 last_arrow_string = Qnil;
|
|
9841 #endif /* 0 */
|
|
9842
|
|
9843 /* #### Probably temporary */
|
|
9844 DEFVAR_INT ("redisplay-cache-adjustment", &cache_adjustment /*
|
|
9845 \(Temporary) Setting this will impact the performance of the internal
|
|
9846 line start cache.
|
|
9847 */ );
|
|
9848 cache_adjustment = 2;
|
|
9849
|
1268
|
9850 DEFVAR_INT ("maximum-preempts", &max_preempts /*
|
|
9851 Maximum number of times redisplay can be preempted by user input.
|
|
9852 */ );
|
|
9853 max_preempts = INIT_MAX_PREEMPTS;
|
|
9854
|
428
|
9855 DEFVAR_INT_MAGIC ("pixel-vertical-clip-threshold", &vertical_clip /*
|
|
9856 Minimum pixel height for clipped bottom display line.
|
|
9857 A clipped line shorter than this won't be displayed.
|
|
9858 */ ,
|
|
9859 redisplay_variable_changed);
|
|
9860 vertical_clip = 5;
|
|
9861
|
|
9862 DEFVAR_INT_MAGIC ("pixel-horizontal-clip-threshold", &horizontal_clip /*
|
|
9863 Minimum visible area for clipped glyphs at right boundary.
|
|
9864 Clipped glyphs shorter than this won't be displayed.
|
|
9865 Only pixmap glyph instances are currently allowed to be clipped.
|
|
9866 */ ,
|
|
9867 redisplay_variable_changed);
|
|
9868 horizontal_clip = 5;
|
|
9869
|
|
9870 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string /*
|
|
9871 String displayed by modeline-format's "%m" specification.
|
|
9872 */ );
|
|
9873 Vglobal_mode_string = Qnil;
|
|
9874
|
|
9875 DEFVAR_LISP_MAGIC ("overlay-arrow-position", &Voverlay_arrow_position /*
|
|
9876 Marker for where to display an arrow on top of the buffer text.
|
|
9877 This must be the beginning of a line in order to work.
|
|
9878 See also `overlay-arrow-string'.
|
|
9879 */ ,
|
|
9880 redisplay_variable_changed);
|
|
9881 Voverlay_arrow_position = Qnil;
|
|
9882
|
|
9883 DEFVAR_LISP_MAGIC ("overlay-arrow-string", &Voverlay_arrow_string /*
|
442
|
9884 String or glyph to display as an arrow. See also `overlay-arrow-position'.
|
444
|
9885 \(Note that despite the name of this variable, it can be set to a glyph as
|
442
|
9886 well as a string.)
|
428
|
9887 */ ,
|
|
9888 redisplay_variable_changed);
|
|
9889 Voverlay_arrow_string = Qnil;
|
|
9890
|
|
9891 DEFVAR_INT ("scroll-step", &scroll_step /*
|
|
9892 *The number of lines to try scrolling a window by when point moves out.
|
|
9893 If that fails to bring point back on frame, point is centered instead.
|
|
9894 If this is zero, point is always centered after it moves off screen.
|
|
9895 */ );
|
|
9896 scroll_step = 0;
|
|
9897
|
|
9898 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively /*
|
|
9899 *Scroll up to this many lines, to bring point back on screen.
|
|
9900 */ );
|
|
9901 scroll_conservatively = 0;
|
|
9902
|
|
9903 DEFVAR_BOOL_MAGIC ("truncate-partial-width-windows",
|
|
9904 &truncate_partial_width_windows /*
|
|
9905 *Non-nil means truncate lines in all windows less than full frame wide.
|
|
9906 */ ,
|
|
9907 redisplay_variable_changed);
|
|
9908 truncate_partial_width_windows = 1;
|
|
9909
|
442
|
9910 DEFVAR_LISP ("visible-bell", &Vvisible_bell /*
|
|
9911 *Non-nil substitutes a visual signal for the audible bell.
|
|
9912
|
|
9913 Default behavior is to flash the whole screen. On some platforms,
|
|
9914 special effects are available using the following values:
|
|
9915
|
3025
|
9916 `display' Flash the whole screen (ie, the default behavior).
|
|
9917 `top-bottom' Flash only the top and bottom lines of the selected frame.
|
442
|
9918
|
|
9919 When effects are unavailable on a platform, the visual bell is the
|
|
9920 default, whole screen. (Currently only X supports any special effects.)
|
428
|
9921 */ );
|
442
|
9922 Vvisible_bell = Qnil;
|
428
|
9923
|
|
9924 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter /*
|
|
9925 *Non-nil means no need to redraw entire frame after suspending.
|
|
9926 A non-nil value is useful if the terminal can automatically preserve
|
|
9927 Emacs's frame display when you reenter Emacs.
|
|
9928 It is up to you to set this variable if your terminal can do that.
|
|
9929 */ );
|
|
9930 no_redraw_on_reenter = 0;
|
|
9931
|
|
9932 DEFVAR_LISP ("window-system", &Vwindow_system /*
|
|
9933 A symbol naming the window-system under which Emacs is running,
|
|
9934 such as `x', or nil if emacs is running on an ordinary terminal.
|
|
9935
|
|
9936 Do not use this variable, except for GNU Emacs compatibility, as it
|
|
9937 gives wrong values in a multi-device environment. Use `console-type'
|
|
9938 instead.
|
|
9939 */ );
|
|
9940 Vwindow_system = Qnil;
|
|
9941
|
|
9942 /* #### Temporary shit until window-system is eliminated. */
|
|
9943 DEFVAR_CONST_LISP ("initial-window-system", &Vinitial_window_system /*
|
|
9944 DON'T TOUCH
|
|
9945 */ );
|
|
9946 Vinitial_window_system = Qnil;
|
|
9947
|
|
9948 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area /*
|
|
9949 Non-nil means put cursor in minibuffer, at end of any message there.
|
|
9950 */ );
|
|
9951 cursor_in_echo_area = 0;
|
|
9952
|
|
9953 /* #### Shouldn't this be generalized as follows:
|
|
9954
|
|
9955 if nil, use block cursor.
|
|
9956 if a number, use a bar cursor of that width.
|
|
9957 Otherwise, use a 1-pixel bar cursor.
|
|
9958
|
|
9959 #### Or better yet, this variable should be trashed entirely
|
|
9960 (use a Lisp-magic variable to maintain compatibility)
|
|
9961 and a specifier `cursor-shape' added, which allows a block
|
|
9962 cursor, a bar cursor, a flashing block or bar cursor,
|
|
9963 maybe a caret cursor, etc. */
|
|
9964
|
|
9965 DEFVAR_LISP ("bar-cursor", &Vbar_cursor /*
|
448
|
9966 *Use vertical bar cursor if non-nil. If t width is 1 pixel, otherwise 2.
|
428
|
9967 */ );
|
|
9968 Vbar_cursor = Qnil;
|
|
9969
|
442
|
9970 DEFVAR_LISP ("buffer-list-changed-hook", &Vbuffer_list_changed_hook /*
|
|
9971 Function or functions to call when a frame's buffer list has changed.
|
|
9972 This is called during redisplay, before redisplaying each frame.
|
|
9973 Functions on this hook are called with one argument, the frame.
|
|
9974 */ );
|
|
9975 Vbuffer_list_changed_hook = Qnil;
|
|
9976
|
428
|
9977 DEFVAR_INT ("display-warning-tick", &display_warning_tick /*
|
|
9978 Bump this to tell the C code to call `display-warning-buffer'
|
|
9979 at next redisplay. You should not normally change this; the function
|
|
9980 `display-warning' automatically does this at appropriate times.
|
|
9981 */ );
|
|
9982 display_warning_tick = 0;
|
|
9983
|
|
9984 DEFVAR_BOOL ("inhibit-warning-display", &inhibit_warning_display /*
|
|
9985 Non-nil means inhibit display of warning messages.
|
|
9986 You should *bind* this, not set it. Any pending warning messages
|
|
9987 will be displayed when the binding no longer applies.
|
|
9988 */ );
|
|
9989 /* reset to 0 by startup.el after the splash screen has displayed.
|
|
9990 This way, the warnings don't obliterate the splash screen. */
|
|
9991 inhibit_warning_display = 1;
|
|
9992
|
|
9993 DEFVAR_BOOL ("column-number-start-at-one", &column_number_start_at_one /*
|
|
9994 *Non-nil means column display number starts at 1.
|
|
9995 */ );
|
|
9996 column_number_start_at_one = 0;
|
|
9997 }
|
|
9998
|
|
9999 void
|
|
10000 specifier_vars_of_redisplay (void)
|
|
10001 {
|
|
10002 DEFVAR_SPECIFIER ("left-margin-width", &Vleft_margin_width /*
|
|
10003 *Width of left margin.
|
|
10004 This is a specifier; use `set-specifier' to change it.
|
|
10005 */ );
|
|
10006 Vleft_margin_width = Fmake_specifier (Qnatnum);
|
|
10007 set_specifier_fallback (Vleft_margin_width, list1 (Fcons (Qnil, Qzero)));
|
|
10008 set_specifier_caching (Vleft_margin_width,
|
438
|
10009 offsetof (struct window, left_margin_width),
|
428
|
10010 some_window_value_changed,
|
438
|
10011 offsetof (struct frame, left_margin_width),
|
444
|
10012 margin_width_changed_in_frame, 0);
|
428
|
10013
|
|
10014 DEFVAR_SPECIFIER ("right-margin-width", &Vright_margin_width /*
|
|
10015 *Width of right margin.
|
|
10016 This is a specifier; use `set-specifier' to change it.
|
|
10017 */ );
|
|
10018 Vright_margin_width = Fmake_specifier (Qnatnum);
|
|
10019 set_specifier_fallback (Vright_margin_width, list1 (Fcons (Qnil, Qzero)));
|
|
10020 set_specifier_caching (Vright_margin_width,
|
438
|
10021 offsetof (struct window, right_margin_width),
|
428
|
10022 some_window_value_changed,
|
438
|
10023 offsetof (struct frame, right_margin_width),
|
444
|
10024 margin_width_changed_in_frame, 0);
|
428
|
10025
|
|
10026 DEFVAR_SPECIFIER ("minimum-line-ascent", &Vminimum_line_ascent /*
|
|
10027 *Minimum ascent height of lines.
|
|
10028 This is a specifier; use `set-specifier' to change it.
|
|
10029 */ );
|
|
10030 Vminimum_line_ascent = Fmake_specifier (Qnatnum);
|
|
10031 set_specifier_fallback (Vminimum_line_ascent, list1 (Fcons (Qnil, Qzero)));
|
|
10032 set_specifier_caching (Vminimum_line_ascent,
|
438
|
10033 offsetof (struct window, minimum_line_ascent),
|
428
|
10034 some_window_value_changed,
|
444
|
10035 0, 0, 0);
|
428
|
10036
|
|
10037 DEFVAR_SPECIFIER ("minimum-line-descent", &Vminimum_line_descent /*
|
|
10038 *Minimum descent height of lines.
|
|
10039 This is a specifier; use `set-specifier' to change it.
|
|
10040 */ );
|
|
10041 Vminimum_line_descent = Fmake_specifier (Qnatnum);
|
|
10042 set_specifier_fallback (Vminimum_line_descent, list1 (Fcons (Qnil, Qzero)));
|
|
10043 set_specifier_caching (Vminimum_line_descent,
|
438
|
10044 offsetof (struct window, minimum_line_descent),
|
428
|
10045 some_window_value_changed,
|
444
|
10046 0, 0, 0);
|
428
|
10047
|
|
10048 DEFVAR_SPECIFIER ("use-left-overflow", &Vuse_left_overflow /*
|
|
10049 *Non-nil means use the left outside margin as extra whitespace when
|
3025
|
10050 displaying `whitespace' or `inside-margin' glyphs.
|
428
|
10051 This is a specifier; use `set-specifier' to change it.
|
|
10052 */ );
|
|
10053 Vuse_left_overflow = Fmake_specifier (Qboolean);
|
|
10054 set_specifier_fallback (Vuse_left_overflow, list1 (Fcons (Qnil, Qnil)));
|
|
10055 set_specifier_caching (Vuse_left_overflow,
|
438
|
10056 offsetof (struct window, use_left_overflow),
|
428
|
10057 some_window_value_changed,
|
444
|
10058 0, 0, 0);
|
428
|
10059
|
|
10060 DEFVAR_SPECIFIER ("use-right-overflow", &Vuse_right_overflow /*
|
|
10061 *Non-nil means use the right outside margin as extra whitespace when
|
3025
|
10062 displaying `whitespace' or `inside-margin' glyphs.
|
428
|
10063 This is a specifier; use `set-specifier' to change it.
|
|
10064 */ );
|
|
10065 Vuse_right_overflow = Fmake_specifier (Qboolean);
|
|
10066 set_specifier_fallback (Vuse_right_overflow, list1 (Fcons (Qnil, Qnil)));
|
|
10067 set_specifier_caching (Vuse_right_overflow,
|
438
|
10068 offsetof (struct window, use_right_overflow),
|
428
|
10069 some_window_value_changed,
|
444
|
10070 0, 0, 0);
|
428
|
10071
|
|
10072 DEFVAR_SPECIFIER ("text-cursor-visible-p", &Vtext_cursor_visible_p /*
|
|
10073 *Non-nil means the text cursor is visible (this is usually the case).
|
|
10074 This is a specifier; use `set-specifier' to change it.
|
|
10075 */ );
|
|
10076 Vtext_cursor_visible_p = Fmake_specifier (Qboolean);
|
|
10077 set_specifier_fallback (Vtext_cursor_visible_p, list1 (Fcons (Qnil, Qt)));
|
|
10078 set_specifier_caching (Vtext_cursor_visible_p,
|
438
|
10079 offsetof (struct window, text_cursor_visible_p),
|
428
|
10080 text_cursor_visible_p_changed,
|
444
|
10081 0, 0, 0);
|
428
|
10082
|
|
10083 }
|