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