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