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