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