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