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