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