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