0
|
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 */
|
96
|
78 unsigned int REPLICATING : 1; /* 12 invoke old extent-replica behav.*/
|
|
79 /* Not used any more */
|
0
|
80 unsigned int detachable : 1; /* 13 extent detaches if text deleted */
|
|
81 unsigned int internal : 1; /* 14 used by map-extents etc. */
|
|
82 unsigned int unused15 : 1; /* 15 unused */
|
|
83 unsigned int unused16 : 1; /* 16 unused */
|
|
84 /* --- Adding more flags will cause the extent struct grow by another
|
|
85 word. It's not clear that this would make a difference, however,
|
|
86 because on 32-bit machines things tend to get allocated in chunks
|
|
87 of 4 bytes. */
|
|
88 } flags;
|
|
89 /* The plist may have an auxiliary structure as its first element */
|
|
90 Lisp_Object plist;
|
|
91 };
|
|
92
|
|
93 /* Basic properties of an extent (not affected by the extent's parent) */
|
|
94 #define extent_object(e) ((e)->object)
|
|
95 #define extent_start(e) ((e)->start + 0)
|
|
96 #define extent_end(e) ((e)->end + 0)
|
|
97 #define set_extent_start(e, val) ((e)->start = (val))
|
|
98 #define set_extent_end(e, val) ((e)->end = (val))
|
|
99 #define extent_endpoint(e, endp) ((endp) ? extent_end (e) : extent_start (e))
|
|
100 #define set_extent_endpoint(e, val, endp) \
|
|
101 ((endp) ? set_extent_end (e, val) : set_extent_start (e, val))
|
|
102 #define extent_detached_p(e) (extent_start (e) < 0)
|
|
103
|
|
104 /* the layouts for glyphs (extent->flags.glyph_layout). Must fit in 2 bits. */
|
|
105 #define GL_TEXT 0
|
|
106 #define GL_OUTSIDE_MARGIN 1
|
|
107 #define GL_INSIDE_MARGIN 2
|
|
108 #define GL_WHITESPACE 3
|
|
109
|
|
110 /* Additional information that may be present in an extent. The idea is
|
|
111 that fast access is provided to this information, but since (hopefully)
|
|
112 most extents won't have this set on them, we usually don't need to
|
|
113 have this structure around and thus the size of an extent is smaller. */
|
|
114
|
185
|
115 typedef struct extent_auxiliary extent_auxiliary;
|
0
|
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)) \
|
185
|
223 MAC_END
|
0
|
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_detachable_p(e) extent_normal_field (e, detachable)
|
|
287 #define extent_internal_p(e) extent_normal_field (e, internal)
|
|
288
|
|
289 #define extent_no_chase_plist_addr(e) \
|
|
290 MAC_BEGIN \
|
|
291 MAC_DECLARE (EXTENT, MTplist_extent, e) \
|
|
292 (MTplist_extent->flags.has_aux ? \
|
|
293 &XCONS (MTplist_extent->plist)->cdr : \
|
|
294 &MTplist_extent->plist) \
|
185
|
295 MAC_END
|
0
|
296 #define extent_no_chase_plist(e) (*extent_no_chase_plist_addr (e))
|
|
297
|
|
298 #define extent_plist_addr(e) extent_no_chase_plist_addr (extent_ancestor (e))
|
|
299 #define extent_plist_slot(e) extent_no_chase_plist (extent_ancestor (e))
|
|
300
|
|
301 /* flags for map_extents() and friends */
|
|
302 #define ME_END_CLOSED (1 << 0)
|
|
303 #define ME_START_OPEN (1 << 1)
|
|
304 #define ME_ALL_EXTENTS_CLOSED (1 << 2)
|
|
305 #define ME_ALL_EXTENTS_OPEN (2 << 2)
|
|
306 #define ME_ALL_EXTENTS_CLOSED_OPEN (3 << 2)
|
|
307 #define ME_ALL_EXTENTS_OPEN_CLOSED (4 << 2)
|
|
308 #define ME_ALL_EXTENTS_MASK (7 << 2)
|
|
309 #define ME_START_IN_REGION (1 << 5)
|
|
310 #define ME_END_IN_REGION (2 << 5)
|
|
311 #define ME_START_AND_END_IN_REGION (3 << 5)
|
|
312 #define ME_START_OR_END_IN_REGION (4 << 5)
|
|
313 #define ME_IN_REGION_MASK (7 << 5)
|
|
314 #define ME_NEGATE_IN_REGION (1 << 8)
|
|
315 /* the following flags are internal-only */
|
|
316 #define ME_INCLUDE_INTERNAL (1 << 9)
|
|
317 #define ME_MIGHT_THROW (1 << 10)
|
|
318 #define ME_MIGHT_MODIFY_TEXT (1 << 11)
|
|
319 #define ME_MIGHT_MODIFY_EXTENTS (1 << 12)
|
|
320 #define ME_MIGHT_MOVE_SOE (1 << 13)
|
|
321 #define ME_MIGHT_CALL_ELISP (ME_MIGHT_THROW | ME_MIGHT_MODIFY_TEXT | \
|
|
322 ME_MIGHT_MODIFY_EXTENTS | ME_MIGHT_MOVE_SOE)
|
|
323
|
|
324
|
|
325 #define EXTENT_LIVE_P(e) (!EQ (extent_object (e), Qt))
|
|
326
|
|
327 #define CHECK_LIVE_EXTENT(x) \
|
|
328 do { CHECK_EXTENT (x); \
|
|
329 if (!EXTENT_LIVE_P (XEXTENT (x))) \
|
|
330 dead_wrong_type_argument (Qextent_live_p, (x)); } while (0)
|
|
331 #define CONCHECK_LIVE_EXTENT(x) \
|
|
332 do { CONCHECK_EXTENT (x); \
|
|
333 if (!EXTENT_LIVE_P (XEXTENT (x))) \
|
|
334 x = wrong_type_argument (Qextent_live_p, (x)); } while (0)
|
|
335
|
|
336 extern Lisp_Object Qextent_live_p;
|
|
337
|
|
338 extern int inside_undo;
|
|
339
|
|
340 struct extent_fragment *extent_fragment_new (Lisp_Object buffer_or_string,
|
|
341 struct frame *frm);
|
|
342 face_index extent_fragment_update (struct window *w,
|
|
343 struct extent_fragment *ef,
|
|
344 /* Note this is in Bytinds */
|
|
345 Bytind pos);
|
|
346 void extent_fragment_delete (struct extent_fragment *ef);
|
|
347
|
|
348 extern Lisp_Object Vlast_highlighted_extent;
|
|
349
|
|
350
|
|
351 #ifdef emacs /* things other than emacs want the structs */
|
|
352
|
|
353 /* from alloc.c */
|
|
354 struct extent *allocate_extent (void);
|
|
355
|
|
356 /* from extents.c */
|
|
357 EXTENT extent_ancestor_1 (EXTENT e);
|
|
358 void allocate_extent_auxiliary (EXTENT ext);
|
|
359 void init_buffer_extents (struct buffer *b);
|
|
360 void uninit_buffer_extents (struct buffer *b);
|
|
361 void map_extents (Bufpos from, Bufpos to, int (*fn) (EXTENT extent,
|
|
362 void * arg),
|
|
363 void *arg, Lisp_Object obj, EXTENT after,
|
|
364 unsigned int flags);
|
|
365
|
|
366 /* Note the following five functions are NOT in Bufpos's */
|
|
367 void adjust_extents (Lisp_Object object, Memind from,
|
|
368 Memind to, int amount);
|
|
369 void adjust_extents_for_deletion (Lisp_Object object, Bytind from,
|
|
370 Bytind to, int gapsize,
|
98
|
371 int numdel, int movegapsize);
|
0
|
372 void verify_extent_modification (Lisp_Object object, Bytind from,
|
|
373 Bytind to,
|
|
374 Lisp_Object inhibit_read_only_value);
|
|
375 void process_extents_for_insertion (Lisp_Object object,
|
|
376 Bytind opoint, Bytecount length);
|
|
377 void process_extents_for_deletion (Lisp_Object object, Bytind from,
|
|
378 Bytind to, int destroy_them);
|
|
379
|
|
380 void set_extent_glyph (EXTENT extent, Lisp_Object glyph, int endp,
|
|
381 unsigned int layout);
|
|
382
|
|
383 void add_string_extents (Lisp_Object string, struct buffer *buf,
|
|
384 Bytind opoint, Bytecount length);
|
|
385 void splice_in_string_extents (Lisp_Object string, struct buffer *buf,
|
|
386 Bytind opoint, Bytecount length,
|
|
387 Bytecount pos);
|
|
388 void copy_string_extents (Lisp_Object new_string,
|
|
389 Lisp_Object old_string,
|
|
390 Bytecount new_pos, Bytecount old_pos,
|
|
391 Bytecount length);
|
|
392
|
|
393 void detach_all_extents (Lisp_Object object);
|
|
394 void set_extent_endpoints (EXTENT extent, Bytind s, Bytind e,
|
|
395 Lisp_Object object);
|
|
396
|
|
397 #ifdef ERROR_CHECK_EXTENTS
|
|
398 void sledgehammer_extent_check (Lisp_Object obj);
|
|
399 #endif
|
|
400
|
|
401 #ifdef MEMORY_USAGE_STATS
|
|
402 int compute_buffer_extent_usage (struct buffer *b,
|
|
403 struct overhead_stats *ovstats);
|
|
404 #endif
|
|
405
|
|
406 #endif /* emacs */
|
|
407
|
|
408 #endif /* _XEMACS_EXTENTS_H_ */
|