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