comparison src/extents.h @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 859a2309aef8
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 /* Copyright (c) 1994, 1995 Free Software Foundation.
2 Copyright (c) 1995 Ben Wing.
3
4 This file is part of XEmacs.
5
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* Synched up with: Not in FSF. */
22
23 #ifndef _XEMACS_EXTENTS_H_
24 #define _XEMACS_EXTENTS_H_
25
26 DECLARE_LRECORD (extent, struct extent);
27 #define XEXTENT(x) XRECORD (x, extent, struct extent)
28 #define XSETEXTENT(x, p) XSETRECORD (x, p, extent)
29 #define EXTENTP(x) RECORDP (x, extent)
30 #define GC_EXTENTP(x) GC_RECORDP (x, extent)
31 #define CHECK_EXTENT(x) CHECK_RECORD (x, extent)
32 #define CONCHECK_EXTENT(x) CONCHECK_RECORD (x, extent)
33
34 struct extent
35 {
36 struct lrecord_header lheader;
37
38 Memind start;
39 Memind end;
40 Lisp_Object object; /* A buffer, string, Qnil (extent detached from no
41 buffer), Qt (destroyed extent) */
42
43 /* Extent properties are conceptually a plist, but the most common
44 props are implemented as bits instead of conses.
45 */
46 struct
47 {
48 Lisp_Object face;
49
50 /* These flags are simply an optimization for common boolean properties
51 which go onto the extent's property list. Any of them would work if
52 done in the normal way, but the space savings of doing these in this
53 way is significant. Note that if you add a flag, there are numerous
54 places in extents.c that need to know about it.
55
56 Another consideration is that some of these properties are accessed
57 during redisplay, so it's good for access to them to be fast (a bit
58 reference instead of a search down a plist).
59
60 `begin_glyph_layout' and `end_glyph_layout' are unusual in
61 that they have 4 states instead of 2.
62
63 Other special extent properties are stored in an auxiliary
64 structure that sits at the beginning of the plist. The has_aux
65 flag indicates whether this structure exists. The has_parent
66 flag is an optimization indicating whether the extent has a parent
67 (this could also be determined by looking in the aux structure). */
68
69 unsigned int begin_glyph_layout :2; /* 2 text, margins, or whitespace */
70 unsigned int end_glyph_layout :2; /* 4 text, margins, or whitespace */
71 unsigned int has_parent : 1; /* 5 extent has a parent */
72 unsigned int has_aux : 1; /* 6 extent has an aux. structure */
73 unsigned int start_open : 1; /* 7 insertion behavior at start */
74 unsigned int end_open : 1; /* 8 insertion behavior at end */
75 unsigned int unused9 : 1; /* 9 unused */
76 unsigned int unique : 1; /* 10 there may be only one attached */
77 unsigned int duplicable : 1; /* 11 copied to strings by kill/undo */
78 unsigned int replicating : 1; /* 12 invoke old extent-replica behav.*/
79 unsigned int detachable : 1; /* 13 extent detaches if text deleted */
80 unsigned int internal : 1; /* 14 used by map-extents etc. */
81 unsigned int unused15 : 1; /* 15 unused */
82 unsigned int unused16 : 1; /* 16 unused */
83 /* --- Adding more flags will cause the extent struct grow by another
84 word. It's not clear that this would make a difference, however,
85 because on 32-bit machines things tend to get allocated in chunks
86 of 4 bytes. */
87 } flags;
88 /* The plist may have an auxiliary structure as its first element */
89 Lisp_Object plist;
90 };
91
92 typedef struct extent *EXTENT;
93
94 /* Basic properties of an extent (not affected by the extent's parent) */
95 #define extent_object(e) ((e)->object)
96 #define extent_start(e) ((e)->start + 0)
97 #define extent_end(e) ((e)->end + 0)
98 #define set_extent_start(e, val) ((e)->start = (val))
99 #define set_extent_end(e, val) ((e)->end = (val))
100 #define extent_endpoint(e, endp) ((endp) ? extent_end (e) : extent_start (e))
101 #define set_extent_endpoint(e, val, endp) \
102 ((endp) ? set_extent_end (e, val) : set_extent_start (e, val))
103 #define extent_detached_p(e) (extent_start (e) < 0)
104
105 /* the layouts for glyphs (extent->flags.glyph_layout). Must fit in 2 bits. */
106 #define GL_TEXT 0
107 #define GL_OUTSIDE_MARGIN 1
108 #define GL_INSIDE_MARGIN 2
109 #define GL_WHITESPACE 3
110
111 /* Additional information that may be present in an extent. The idea is
112 that fast access is provided to this information, but since (hopefully)
113 most extents won't have this set on them, we usually don't need to
114 have this structure around and thus the size of an extent is smaller. */
115
116 struct extent_auxiliary
117 {
118 struct lcrecord_header header;
119
120 Lisp_Object begin_glyph;
121 Lisp_Object end_glyph;
122 Lisp_Object parent;
123 /* We use a weak list here. Originally I didn't do this and
124 depended on having the extent's finalization method remove
125 itself from its parent's children list. This runs into
126 lots and lots of problems though because everything is in
127 a really really bizarre state when an extent's finalization
128 method is called (it happens in sweep_extents() by way of
129 ADDITIONAL_FREE_extent()) and it's extremely difficult to
130 avoid getting hosed by just-freed objects. */
131 Lisp_Object children;
132 Lisp_Object invisible;
133 Lisp_Object read_only;
134 Lisp_Object mouse_face;
135 #ifdef ENERGIZE
136 Energize_Extent_Data *energize_data;
137 #endif
138 int priority;
139 };
140
141 extern struct extent_auxiliary extent_auxiliary_defaults;
142
143 DECLARE_LRECORD (extent_auxiliary, struct extent_auxiliary);
144 #define XEXTENT_AUXILIARY(x) \
145 XRECORD (x, extent_auxiliary, struct extent_auxiliary)
146 #define XSETEXTENT_AUXILIARY(x, p) XSETRECORD (x, p, extent_auxiliary)
147 #define EXTENT_AUXILIARYP(x) RECORDP (x, extent_auxiliary)
148 #define GC_EXTENT_AUXILIARYP(x) GC_RECORDP (x, extent_auxiliary)
149 #define CHECK_EXTENT_AUXILIARY(x) CHECK_RECORD (x, extent_auxiliary)
150 #define CONCHECK_EXTENT_AUXILIARY(x) CONCHECK_RECORD (x, extent_auxiliary)
151
152 struct extent_info
153 {
154 struct lcrecord_header header;
155
156 struct extent_list *extents;
157 struct stack_of_extents *soe;
158 };
159
160 DECLARE_LRECORD (extent_info, struct extent_info);
161 #define XEXTENT_INFO(x) \
162 XRECORD (x, extent_info, struct extent_info)
163 #define XSETEXTENT_INFO(x, p) XSETRECORD (x, p, extent_info)
164 #define EXTENT_INFOP(x) RECORDP (x, extent_info)
165 #define GC_EXTENT_INFOP(x) GC_RECORDP (x, extent_info)
166 #define CHECK_EXTENT_INFO(x) CHECK_RECORD (x, extent_info)
167 #define CONCHECK_EXTENT_INFO(x) CONCHECK_RECORD (x, extent_info)
168
169 void flush_cached_extent_info (Lisp_Object extent_info);
170
171 /* Note that we take pains in all the macros below never to evaluate
172 the extent argument more than once. This may not be necessary
173 but is much less likely to introduce subtle bugs. */
174
175 MAC_DECLARE_EXTERN (EXTENT, MTancestor_extent)
176 MAC_DECLARE_EXTERN (EXTENT, MTaux_extent)
177 MAC_DECLARE_EXTERN (EXTENT, MTplist_extent)
178 MAC_DECLARE_EXTERN (EXTENT, MTensure_extent)
179 MAC_DECLARE_EXTERN (EXTENT, MTset_extent)
180
181 /* extent_ancestor() chases all the parent links until there aren't any
182 more. extent_ancestor_1() does the same thing but it a function;
183 the following macro optimizes the most common case. */
184
185 #define extent_ancestor(e) \
186 MAC_BEGIN \
187 MAC_DECLARE (EXTENT, MTancestor_extent, e) \
188 (MTancestor_extent->flags.has_parent ? \
189 extent_ancestor_1 (MTancestor_extent) : \
190 MTancestor_extent) \
191 MAC_END
192
193 /* a "normal" field is one that is stored in the `struct flags' structure
194 in an extent. an "aux" field is one that is stored in the extent's
195 auxiliary structure.
196
197 The functions below that have `extent_no_chase' in their name operate
198 on an extent directly (ignoring its parent), and should normally
199 only be used on extents known not to have a parent. The other
200 versions chase down any parent links. */
201
202 #define extent_no_chase_normal_field(e, field) ((e)->flags.field)
203
204 #define extent_no_chase_aux_field(e, field) \
205 MAC_BEGIN \
206 MAC_DECLARE (EXTENT, MTaux_extent, e) \
207 (MTaux_extent->flags.has_aux ? \
208 XEXTENT_AUXILIARY (XCONS (MTaux_extent->plist)->car)->field \
209 : extent_auxiliary_defaults.field) \
210 MAC_END
211
212 #define extent_normal_field(e, field) \
213 extent_no_chase_normal_field (extent_ancestor (e), field)
214
215 #define extent_aux_field(e, field) \
216 extent_no_chase_aux_field (extent_ancestor (e), field)
217
218 #define ensure_extent_has_auxiliary(e) \
219 MAC_BEGIN \
220 MAC_DECLARE (EXTENT, MTensure_extent, e) \
221 (MTensure_extent->flags.has_aux ? (void) 0 : \
222 allocate_extent_auxiliary (MTensure_extent)) \
223 MAC_END
224
225 #define set_extent_no_chase_aux_field(e, field, value) \
226 MAC_BEGIN \
227 MAC_DECLARE (EXTENT, MTset_extent, e) \
228 ensure_extent_has_auxiliary (MTset_extent) \
229 MAC_SEP \
230 XEXTENT_AUXILIARY (XCONS (MTset_extent->plist)->car)->field = \
231 (value) \
232 MAC_END
233
234 #define set_extent_no_chase_normal_field(e, field, value) \
235 extent_no_chase_normal_field (e, field) = (value)
236
237 #define set_extent_aux_field(e, field, value) \
238 set_extent_no_chase_aux_field (extent_ancestor (e), field, value)
239
240 #define set_extent_normal_field(e, field, value) \
241 set_extent_ancestor_normal_field (extent_no_chase (e), field, value)
242
243 /* The `parent' and `children' fields are not affected by any
244 parent links. We don't provide any settors for these fields
245 because they need special handling and it's cleaner just to
246 do this in the particular functions that need to do this. */
247
248 #define extent_parent(e) extent_no_chase_aux_field (e, parent)
249 #define extent_children(e) extent_no_chase_aux_field (e, children)
250
251 #define extent_begin_glyph(e) extent_aux_field (e, begin_glyph)
252 #define extent_end_glyph(e) extent_aux_field (e, end_glyph)
253 #define extent_priority(e) extent_aux_field (e, priority)
254 #define extent_invisible(e) extent_aux_field (e, invisible)
255 #define extent_read_only(e) extent_aux_field (e, read_only)
256 #define extent_mouse_face(e) extent_aux_field (e, mouse_face)
257 #ifdef ENERGIZE
258 #define extent_energize_data(e) extent_aux_field (e, energize_data)
259 #endif
260
261 #define set_extent_begin_glyph(e, value) \
262 set_extent_aux_field (e, begin_glyph, value)
263 #define set_extent_end_glyph(e, value) \
264 set_extent_aux_field (e, end_glyph, value)
265 #define set_extent_priority(e, value) \
266 set_extent_aux_field (e, priority, value)
267 #define set_extent_invisible_1(e, value) \
268 set_extent_aux_field (e, invisible, value)
269 #define set_extent_read_only(e, value) \
270 set_extent_aux_field (e, read_only, value)
271 #define set_extent_mouse_face(e, value) \
272 set_extent_aux_field (e, mouse_face, value)
273 #ifdef ENERGIZE
274 #define set_extent_energize_data(e, value) \
275 set_extent_aux_field (e, energize_data, value)
276 #endif
277
278 #define extent_face(e) extent_normal_field (e, face)
279 #define extent_begin_glyph_layout(e) \
280 extent_normal_field (e, begin_glyph_layout)
281 #define extent_end_glyph_layout(e) extent_normal_field (e, end_glyph_layout)
282 #define extent_start_open_p(e) extent_normal_field (e, start_open)
283 #define extent_end_open_p(e) extent_normal_field (e, end_open)
284 #define extent_unique_p(e) extent_normal_field (e, unique)
285 #define extent_duplicable_p(e) extent_normal_field (e, duplicable)
286 #define extent_replicating_p(e) extent_normal_field (e, replicating)
287 #define extent_detachable_p(e) extent_normal_field (e, detachable)
288 #define extent_internal_p(e) extent_normal_field (e, internal)
289
290 #define extent_no_chase_plist_addr(e) \
291 MAC_BEGIN \
292 MAC_DECLARE (EXTENT, MTplist_extent, e) \
293 (MTplist_extent->flags.has_aux ? \
294 &XCONS (MTplist_extent->plist)->cdr : \
295 &MTplist_extent->plist) \
296 MAC_END
297 #define extent_no_chase_plist(e) (*extent_no_chase_plist_addr (e))
298
299 #define extent_plist_addr(e) extent_no_chase_plist_addr (extent_ancestor (e))
300 #define extent_plist_slot(e) extent_no_chase_plist (extent_ancestor (e))
301
302 /* flags for map_extents() and friends */
303 #define ME_END_CLOSED (1 << 0)
304 #define ME_START_OPEN (1 << 1)
305 #define ME_ALL_EXTENTS_CLOSED (1 << 2)
306 #define ME_ALL_EXTENTS_OPEN (2 << 2)
307 #define ME_ALL_EXTENTS_CLOSED_OPEN (3 << 2)
308 #define ME_ALL_EXTENTS_OPEN_CLOSED (4 << 2)
309 #define ME_ALL_EXTENTS_MASK (7 << 2)
310 #define ME_START_IN_REGION (1 << 5)
311 #define ME_END_IN_REGION (2 << 5)
312 #define ME_START_AND_END_IN_REGION (3 << 5)
313 #define ME_START_OR_END_IN_REGION (4 << 5)
314 #define ME_IN_REGION_MASK (7 << 5)
315 #define ME_NEGATE_IN_REGION (1 << 8)
316 /* the following flags are internal-only */
317 #define ME_INCLUDE_INTERNAL (1 << 9)
318 #define ME_MIGHT_THROW (1 << 10)
319 #define ME_MIGHT_MODIFY_TEXT (1 << 11)
320 #define ME_MIGHT_MODIFY_EXTENTS (1 << 12)
321 #define ME_MIGHT_MOVE_SOE (1 << 13)
322 #define ME_MIGHT_CALL_ELISP (ME_MIGHT_THROW | ME_MIGHT_MODIFY_TEXT | \
323 ME_MIGHT_MODIFY_EXTENTS | ME_MIGHT_MOVE_SOE)
324
325
326 #define EXTENT_LIVE_P(e) (!EQ (extent_object (e), Qt))
327
328 #define CHECK_LIVE_EXTENT(x) \
329 do { CHECK_EXTENT (x); \
330 if (!EXTENT_LIVE_P (XEXTENT (x))) \
331 dead_wrong_type_argument (Qextent_live_p, (x)); } while (0)
332 #define CONCHECK_LIVE_EXTENT(x) \
333 do { CONCHECK_EXTENT (x); \
334 if (!EXTENT_LIVE_P (XEXTENT (x))) \
335 x = wrong_type_argument (Qextent_live_p, (x)); } while (0)
336
337 extern Lisp_Object Qextent_live_p;
338
339 extern int inside_undo;
340
341 struct extent_fragment *extent_fragment_new (Lisp_Object buffer_or_string,
342 struct frame *frm);
343 face_index extent_fragment_update (struct window *w,
344 struct extent_fragment *ef,
345 /* Note this is in Bytinds */
346 Bytind pos);
347 void extent_fragment_delete (struct extent_fragment *ef);
348
349 extern Lisp_Object Vlast_highlighted_extent;
350
351
352 #ifdef emacs /* things other than emacs want the structs */
353
354 /* from alloc.c */
355 struct extent *allocate_extent (void);
356
357 /* from extents.c */
358 EXTENT extent_ancestor_1 (EXTENT e);
359 void allocate_extent_auxiliary (EXTENT ext);
360 void init_buffer_extents (struct buffer *b);
361 void uninit_buffer_extents (struct buffer *b);
362 void map_extents (Bufpos from, Bufpos to, int (*fn) (EXTENT extent,
363 void * arg),
364 void *arg, Lisp_Object obj, EXTENT after,
365 unsigned int flags);
366
367 /* Note the following five functions are NOT in Bufpos's */
368 void adjust_extents (Lisp_Object object, Memind from,
369 Memind to, int amount);
370 void adjust_extents_for_deletion (Lisp_Object object, Bytind from,
371 Bytind to, int gapsize,
372 int numdel);
373 void verify_extent_modification (Lisp_Object object, Bytind from,
374 Bytind to,
375 Lisp_Object inhibit_read_only_value);
376 void process_extents_for_insertion (Lisp_Object object,
377 Bytind opoint, Bytecount length);
378 void process_extents_for_deletion (Lisp_Object object, Bytind from,
379 Bytind to, int destroy_them);
380
381 void set_extent_glyph (EXTENT extent, Lisp_Object glyph, int endp,
382 unsigned int layout);
383
384 void add_string_extents (Lisp_Object string, struct buffer *buf,
385 Bytind opoint, Bytecount length);
386 void splice_in_string_extents (Lisp_Object string, struct buffer *buf,
387 Bytind opoint, Bytecount length,
388 Bytecount pos);
389 void copy_string_extents (Lisp_Object new_string,
390 Lisp_Object old_string,
391 Bytecount new_pos, Bytecount old_pos,
392 Bytecount length);
393
394 void detach_all_extents (Lisp_Object object);
395 void set_extent_endpoints (EXTENT extent, Bytind s, Bytind e,
396 Lisp_Object object);
397
398 #ifdef ERROR_CHECK_EXTENTS
399 void sledgehammer_extent_check (Lisp_Object obj);
400 #endif
401
402 #ifdef MEMORY_USAGE_STATS
403 int compute_buffer_extent_usage (struct buffer *b,
404 struct overhead_stats *ovstats);
405 #endif
406
407 #endif /* emacs */
408
409 #endif /* _XEMACS_EXTENTS_H_ */