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