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