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