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