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