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