Mercurial > hg > xemacs-beta
annotate src/extents.c @ 5168:cf900a2f1fa3
extract gap array from extents.c, use in range tables
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-03-22 Ben Wing <ben@xemacs.org>
* Makefile.in.in (objs):
* array.c:
* array.c (gap_array_adjust_markers):
* array.c (gap_array_move_gap):
* array.c (gap_array_make_gap):
* array.c (gap_array_insert_els):
* array.c (gap_array_delete_els):
* array.c (gap_array_make_marker):
* array.c (gap_array_delete_marker):
* array.c (gap_array_delete_all_markers):
* array.c (gap_array_clone):
* array.h:
* depend:
* emacs.c (main_1):
* extents.c:
* extents.c (EXTENT_GAP_ARRAY_AT):
* extents.c (extent_list_num_els):
* extents.c (extent_list_locate):
* extents.c (extent_list_at):
* extents.c (extent_list_delete_all):
* extents.c (allocate_extent_list):
* extents.c (syms_of_extents):
* extents.h:
* extents.h (XEXTENT_LIST_MARKER):
* lisp.h:
* rangetab.c:
* rangetab.c (mark_range_table):
* rangetab.c (print_range_table):
* rangetab.c (range_table_equal):
* rangetab.c (range_table_hash):
* rangetab.c (verify_range_table):
* rangetab.c (get_range_table_pos):
* rangetab.c (Fmake_range_table):
* rangetab.c (Fcopy_range_table):
* rangetab.c (Fget_range_table):
* rangetab.c (put_range_table):
* rangetab.c (Fclear_range_table):
* rangetab.c (Fmap_range_table):
* rangetab.c (unified_range_table_bytes_needed):
* rangetab.c (unified_range_table_copy_data):
* rangetab.c (unified_range_table_lookup):
* rangetab.h:
* rangetab.h (struct range_table_entry):
* rangetab.h (struct Lisp_Range_Table):
* rangetab.h (rangetab_gap_array_at):
* symsinit.h:
Rename dynarr.c to array.c. Move gap array from extents.c to array.c.
Extract dynarr, gap array and stack-like malloc into new file array.h.
Rename GAP_ARRAY_NUM_ELS -> gap_array_length(). Add gap_array_at(),
gap_array_atp().
Rewrite range table code to use gap arrays. Make put_range_table()
smarter so that its operation is O(log n) for adding a localized
range.
* gc.c (lispdesc_block_size_1):
Don't ABORT() when two elements are located at the same place.
This will happen with a size-0 gap array -- both parts of the array
(before and after gap) are in the same place.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Mon, 22 Mar 2010 19:12:15 -0500 |
parents | 1fae11d56ad2 |
children | 6c6d78781d59 |
rev | line source |
---|---|
428 | 1 /* Copyright (c) 1994, 1995 Free Software Foundation, Inc. |
2 Copyright (c) 1995 Sun Microsystems, Inc. | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3 Copyright (c) 1995, 1996, 2000, 2002, 2003, 2004, 2005, 2010 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Not in FSF. */ | |
23 | |
24 /* This file has been Mule-ized. */ | |
25 | |
26 /* Written by Ben Wing <ben@xemacs.org>. | |
27 | |
28 [Originally written by some people at Lucid. | |
29 Hacked on by jwz. | |
30 Start/end-open stuff added by John Rose (john.rose@eng.sun.com). | |
31 Rewritten from scratch by Ben Wing, December 1994.] */ | |
32 | |
33 /* Commentary: | |
34 | |
35 Extents are regions over a buffer, with a start and an end position | |
36 denoting the region of the buffer included in the extent. In | |
37 addition, either end can be closed or open, meaning that the endpoint | |
38 is or is not logically included in the extent. Insertion of a character | |
39 at a closed endpoint causes the character to go inside the extent; | |
40 insertion at an open endpoint causes the character to go outside. | |
41 | |
42 Extent endpoints are stored using memory indices (see insdel.c), | |
43 to minimize the amount of adjusting that needs to be done when | |
44 characters are inserted or deleted. | |
45 | |
46 (Formerly, extent endpoints at the gap could be either before or | |
47 after the gap, depending on the open/closedness of the endpoint. | |
48 The intent of this was to make it so that insertions would | |
49 automatically go inside or out of extents as necessary with no | |
50 further work needing to be done. It didn't work out that way, | |
51 however, and just ended up complexifying and buggifying all the | |
52 rest of the code.) | |
53 | |
54 Extents are compared using memory indices. There are two orderings | |
55 for extents and both orders are kept current at all times. The normal | |
56 or "display" order is as follows: | |
57 | |
58 Extent A is "less than" extent B, that is, earlier in the display order, | |
59 if: A-start < B-start, | |
60 or if: A-start = B-start, and A-end > B-end | |
61 | |
62 So if two extents begin at the same position, the larger of them is the | |
63 earlier one in the display order (EXTENT_LESS is true). | |
64 | |
65 For the e-order, the same thing holds: Extent A is "less than" extent B | |
66 in e-order, that is, later in the buffer, | |
67 if: A-end < B-end, | |
68 or if: A-end = B-end, and A-start > B-start | |
69 | |
70 So if two extents end at the same position, the smaller of them is the | |
71 earlier one in the e-order (EXTENT_E_LESS is true). | |
72 | |
73 The display order and the e-order are complementary orders: any | |
74 theorem about the display order also applies to the e-order if you | |
75 swap all occurrences of "display order" and "e-order", "less than" | |
76 and "greater than", and "extent start" and "extent end". | |
77 | |
78 Extents can be zero-length, and will end up that way if their endpoints | |
79 are explicitly set that way or if their detachable property is nil | |
80 and all the text in the extent is deleted. (The exception is open-open | |
81 zero-length extents, which are barred from existing because there is | |
82 no sensible way to define their properties. Deletion of the text in | |
83 an open-open extent causes it to be converted into a closed-open | |
84 extent.) Zero-length extents are primarily used to represent | |
85 annotations, and behave as follows: | |
86 | |
87 1) Insertion at the position of a zero-length extent expands the extent | |
88 if both endpoints are closed; goes after the extent if it is closed-open; | |
89 and goes before the extent if it is open-closed. | |
90 | |
91 2) Deletion of a character on a side of a zero-length extent whose | |
92 corresponding endpoint is closed causes the extent to be detached if | |
93 it is detachable; if the extent is not detachable or the corresponding | |
94 endpoint is open, the extent remains in the buffer, moving as necessary. | |
95 | |
96 Note that closed-open, non-detachable zero-length extents behave exactly | |
97 like markers and that open-closed, non-detachable zero-length extents | |
98 behave like the "point-type" marker in Mule. | |
99 | |
100 | |
101 #### The following information is wrong in places. | |
102 | |
103 More about the different orders: | |
104 -------------------------------- | |
105 | |
106 The extents in a buffer are ordered by "display order" because that | |
107 is that order that the redisplay mechanism needs to process them in. | |
108 The e-order is an auxiliary ordering used to facilitate operations | |
109 over extents. The operations that can be performed on the ordered | |
110 list of extents in a buffer are | |
111 | |
112 1) Locate where an extent would go if inserted into the list. | |
113 2) Insert an extent into the list. | |
114 3) Remove an extent from the list. | |
115 4) Map over all the extents that overlap a range. | |
116 | |
117 (4) requires being able to determine the first and last extents | |
118 that overlap a range. | |
119 | |
120 NOTE: "overlap" is used as follows: | |
121 | |
122 -- two ranges overlap if they have at least one point in common. | |
123 Whether the endpoints are open or closed makes a difference here. | |
124 -- a point overlaps a range if the point is contained within the | |
125 range; this is equivalent to treating a point P as the range | |
126 [P, P]. | |
127 -- In the case of an *extent* overlapping a point or range, the | |
128 extent is normally treated as having closed endpoints. This | |
129 applies consistently in the discussion of stacks of extents | |
130 and such below. Note that this definition of overlap is not | |
131 necessarily consistent with the extents that `map-extents' | |
132 maps over, since `map-extents' sometimes pays attention to | |
133 whether the endpoints of an extents are open or closed. | |
134 But for our purposes, it greatly simplifies things to treat | |
135 all extents as having closed endpoints. | |
136 | |
137 First, define >, <, <=, etc. as applied to extents to mean | |
138 comparison according to the display order. Comparison between an | |
139 extent E and an index I means comparison between E and the range | |
140 [I, I]. | |
141 Also define e>, e<, e<=, etc. to mean comparison according to the | |
142 e-order. | |
143 For any range R, define R(0) to be the starting index of the range | |
144 and R(1) to be the ending index of the range. | |
145 For any extent E, define E(next) to be the extent directly following | |
146 E, and E(prev) to be the extent directly preceding E. Assume | |
147 E(next) and E(prev) can be determined from E in constant time. | |
148 (This is because we store the extent list as a doubly linked | |
149 list.) | |
150 Similarly, define E(e-next) and E(e-prev) to be the extents | |
151 directly following and preceding E in the e-order. | |
152 | |
153 Now: | |
154 | |
155 Let R be a range. | |
156 Let F be the first extent overlapping R. | |
157 Let L be the last extent overlapping R. | |
158 | |
159 Theorem 1: R(1) lies between L and L(next), i.e. L <= R(1) < L(next). | |
160 | |
161 This follows easily from the definition of display order. The | |
162 basic reason that this theorem applies is that the display order | |
163 sorts by increasing starting index. | |
164 | |
165 Therefore, we can determine L just by looking at where we would | |
166 insert R(1) into the list, and if we know F and are moving forward | |
167 over extents, we can easily determine when we've hit L by comparing | |
168 the extent we're at to R(1). | |
169 | |
170 Theorem 2: F(e-prev) e< [1, R(0)] e<= F. | |
171 | |
172 This is the analog of Theorem 1, and applies because the e-order | |
173 sorts by increasing ending index. | |
174 | |
175 Therefore, F can be found in the same amount of time as operation (1), | |
176 i.e. the time that it takes to locate where an extent would go if | |
177 inserted into the e-order list. | |
178 | |
179 If the lists were stored as balanced binary trees, then operation (1) | |
180 would take logarithmic time, which is usually quite fast. However, | |
181 currently they're stored as simple doubly-linked lists, and instead | |
182 we do some caching to try to speed things up. | |
183 | |
184 Define a "stack of extents" (or "SOE") as the set of extents | |
185 (ordered in the display order) that overlap an index I, together with | |
186 the SOE's "previous" extent, which is an extent that precedes I in | |
187 the e-order. (Hopefully there will not be very many extents between | |
188 I and the previous extent.) | |
189 | |
190 Now: | |
191 | |
192 Let I be an index, let S be the stack of extents on I, let F be | |
193 the first extent in S, and let P be S's previous extent. | |
194 | |
195 Theorem 3: The first extent in S is the first extent that overlaps | |
196 any range [I, J]. | |
197 | |
198 Proof: Any extent that overlaps [I, J] but does not include I must | |
199 have a start index > I, and thus be greater than any extent in S. | |
200 | |
201 Therefore, finding the first extent that overlaps a range R is the | |
202 same as finding the first extent that overlaps R(0). | |
203 | |
204 Theorem 4: Let I2 be an index such that I2 > I, and let F2 be the | |
205 first extent that overlaps I2. Then, either F2 is in S or F2 is | |
206 greater than any extent in S. | |
207 | |
208 Proof: If F2 does not include I then its start index is greater | |
209 than I and thus it is greater than any extent in S, including F. | |
210 Otherwise, F2 includes I and thus is in S, and thus F2 >= F. | |
211 | |
212 */ | |
213 | |
214 #include <config.h> | |
215 #include "lisp.h" | |
216 | |
217 #include "buffer.h" | |
218 #include "debug.h" | |
219 #include "device.h" | |
220 #include "elhash.h" | |
872 | 221 #include "extents-impl.h" |
428 | 222 #include "faces.h" |
223 #include "frame.h" | |
224 #include "glyphs.h" | |
225 #include "insdel.h" | |
226 #include "keymap.h" | |
227 #include "opaque.h" | |
228 #include "process.h" | |
1292 | 229 #include "profile.h" |
428 | 230 #include "redisplay.h" |
442 | 231 #include "gutter.h" |
428 | 232 |
233 /* ------------------------------- */ | |
234 /* extent list */ | |
235 /* ------------------------------- */ | |
236 | |
237 typedef struct extent_list_marker | |
238 { | |
3092 | 239 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
240 NORMAL_LISP_OBJECT_HEADER header; |
3092 | 241 #endif /* NEW_GC */ |
428 | 242 Gap_Array_Marker *m; |
243 int endp; | |
244 struct extent_list_marker *next; | |
245 } Extent_List_Marker; | |
246 | |
247 typedef struct extent_list | |
248 { | |
3092 | 249 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
250 NORMAL_LISP_OBJECT_HEADER header; |
3092 | 251 #endif /* NEW_GC */ |
428 | 252 Gap_Array *start; |
253 Gap_Array *end; | |
254 Extent_List_Marker *markers; | |
255 } Extent_List; | |
256 | |
3092 | 257 #ifndef NEW_GC |
428 | 258 static Extent_List_Marker *extent_list_marker_freelist; |
3092 | 259 #endif /* not NEW_GC */ |
428 | 260 |
261 #define EXTENT_LESS_VALS(e,st,nd) ((extent_start (e) < (st)) || \ | |
262 ((extent_start (e) == (st)) && \ | |
263 (extent_end (e) > (nd)))) | |
264 | |
265 #define EXTENT_EQUAL_VALS(e,st,nd) ((extent_start (e) == (st)) && \ | |
266 (extent_end (e) == (nd))) | |
267 | |
268 #define EXTENT_LESS_EQUAL_VALS(e,st,nd) ((extent_start (e) < (st)) || \ | |
269 ((extent_start (e) == (st)) && \ | |
270 (extent_end (e) >= (nd)))) | |
271 | |
272 /* Is extent E1 less than extent E2 in the display order? */ | |
273 #define EXTENT_LESS(e1,e2) \ | |
274 EXTENT_LESS_VALS (e1, extent_start (e2), extent_end (e2)) | |
275 | |
276 /* Is extent E1 equal to extent E2? */ | |
277 #define EXTENT_EQUAL(e1,e2) \ | |
278 EXTENT_EQUAL_VALS (e1, extent_start (e2), extent_end (e2)) | |
279 | |
280 /* Is extent E1 less than or equal to extent E2 in the display order? */ | |
281 #define EXTENT_LESS_EQUAL(e1,e2) \ | |
282 EXTENT_LESS_EQUAL_VALS (e1, extent_start (e2), extent_end (e2)) | |
283 | |
284 #define EXTENT_E_LESS_VALS(e,st,nd) ((extent_end (e) < (nd)) || \ | |
285 ((extent_end (e) == (nd)) && \ | |
286 (extent_start (e) > (st)))) | |
287 | |
288 #define EXTENT_E_LESS_EQUAL_VALS(e,st,nd) ((extent_end (e) < (nd)) || \ | |
289 ((extent_end (e) == (nd)) && \ | |
290 (extent_start (e) >= (st)))) | |
291 | |
292 /* Is extent E1 less than extent E2 in the e-order? */ | |
293 #define EXTENT_E_LESS(e1,e2) \ | |
294 EXTENT_E_LESS_VALS(e1, extent_start (e2), extent_end (e2)) | |
295 | |
296 /* Is extent E1 less than or equal to extent E2 in the e-order? */ | |
297 #define EXTENT_E_LESS_EQUAL(e1,e2) \ | |
298 EXTENT_E_LESS_EQUAL_VALS (e1, extent_start (e2), extent_end (e2)) | |
299 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
300 #define EXTENT_GAP_ARRAY_AT(ga, pos) gap_array_at (ga, pos, EXTENT) |
428 | 301 |
302 /* ------------------------------- */ | |
303 /* buffer-extent primitives */ | |
304 /* ------------------------------- */ | |
305 | |
306 typedef struct stack_of_extents | |
307 { | |
3092 | 308 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
309 NORMAL_LISP_OBJECT_HEADER header; |
3092 | 310 #endif /* NEW_GC */ |
428 | 311 Extent_List *extents; |
826 | 312 Memxpos pos; /* Position of stack of extents. EXTENTS is the list of |
428 | 313 all extents that overlap this position. This position |
314 can be -1 if the stack of extents is invalid (this | |
315 happens when a buffer is first created or a string's | |
316 stack of extents is created [a string's stack of extents | |
317 is nuked when a GC occurs, to conserve memory]). */ | |
318 } Stack_Of_Extents; | |
319 | |
320 /* ------------------------------- */ | |
321 /* map-extents */ | |
322 /* ------------------------------- */ | |
323 | |
826 | 324 typedef int (*map_extents_fun) (EXTENT extent, void *arg); |
325 | |
428 | 326 typedef int Endpoint_Index; |
327 | |
826 | 328 #define memxpos_to_startind(x, start_open) \ |
428 | 329 ((Endpoint_Index) (((x) << 1) + !!(start_open))) |
826 | 330 #define memxpos_to_endind(x, end_open) \ |
428 | 331 ((Endpoint_Index) (((x) << 1) - !!(end_open))) |
332 | |
333 /* ------------------------------- */ | |
334 /* buffer-or-string primitives */ | |
335 /* ------------------------------- */ | |
336 | |
826 | 337 /* Similar for Bytebpos's and start/end indices. */ |
338 | |
339 #define buffer_or_string_bytexpos_to_startind(obj, ind, start_open) \ | |
340 memxpos_to_startind (buffer_or_string_bytexpos_to_memxpos (obj, ind), \ | |
428 | 341 start_open) |
342 | |
826 | 343 #define buffer_or_string_bytexpos_to_endind(obj, ind, end_open) \ |
344 memxpos_to_endind (buffer_or_string_bytexpos_to_memxpos (obj, ind), \ | |
428 | 345 end_open) |
346 | |
347 /* ------------------------------- */ | |
348 /* Lisp-level functions */ | |
349 /* ------------------------------- */ | |
350 | |
351 /* flags for decode_extent() */ | |
352 #define DE_MUST_HAVE_BUFFER 1 | |
353 #define DE_MUST_BE_ATTACHED 2 | |
354 | |
355 Lisp_Object Vlast_highlighted_extent; | |
1292 | 356 |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
357 Lisp_Object Vextent_auxiliary_defaults; |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
358 |
1292 | 359 Lisp_Object QSin_map_extents_internal; |
360 | |
458 | 361 Fixnum mouse_highlight_priority; |
428 | 362 |
363 Lisp_Object Qextentp; | |
364 Lisp_Object Qextent_live_p; | |
365 | |
366 Lisp_Object Qall_extents_closed; | |
367 Lisp_Object Qall_extents_open; | |
368 Lisp_Object Qall_extents_closed_open; | |
369 Lisp_Object Qall_extents_open_closed; | |
370 Lisp_Object Qstart_in_region; | |
371 Lisp_Object Qend_in_region; | |
372 Lisp_Object Qstart_and_end_in_region; | |
373 Lisp_Object Qstart_or_end_in_region; | |
374 Lisp_Object Qnegate_in_region; | |
375 | |
376 Lisp_Object Qdetached; | |
377 Lisp_Object Qdestroyed; | |
378 Lisp_Object Qbegin_glyph; | |
379 Lisp_Object Qend_glyph; | |
380 Lisp_Object Qstart_open; | |
381 Lisp_Object Qend_open; | |
382 Lisp_Object Qstart_closed; | |
383 Lisp_Object Qend_closed; | |
384 Lisp_Object Qread_only; | |
385 /* Qhighlight defined in general.c */ | |
386 Lisp_Object Qunique; | |
387 Lisp_Object Qduplicable; | |
388 Lisp_Object Qdetachable; | |
389 Lisp_Object Qpriority; | |
390 Lisp_Object Qmouse_face; | |
391 Lisp_Object Qinitial_redisplay_function; | |
392 | |
393 Lisp_Object Qglyph_layout; /* This exists only for backwards compatibility. */ | |
394 Lisp_Object Qbegin_glyph_layout, Qend_glyph_layout; | |
395 Lisp_Object Qoutside_margin; | |
396 Lisp_Object Qinside_margin; | |
397 Lisp_Object Qwhitespace; | |
398 /* Qtext defined in general.c */ | |
399 | |
400 Lisp_Object Qcopy_function; | |
401 Lisp_Object Qpaste_function; | |
402 | |
403 static Lisp_Object canonicalize_extent_property (Lisp_Object prop, | |
404 Lisp_Object value); | |
826 | 405 |
406 typedef struct | |
407 { | |
408 Lisp_Object key, value; | |
409 } Lisp_Object_pair; | |
410 typedef struct | |
411 { | |
412 Dynarr_declare (Lisp_Object_pair); | |
413 } Lisp_Object_pair_dynarr; | |
414 | |
415 static void extent_properties (EXTENT e, Lisp_Object_pair_dynarr *props); | |
416 | |
428 | 417 Lisp_Object Vextent_face_memoize_hash_table; |
418 Lisp_Object Vextent_face_reverse_memoize_hash_table; | |
419 Lisp_Object Vextent_face_reusable_list; | |
420 /* FSFmacs bogosity */ | |
421 Lisp_Object Vdefault_text_properties; | |
422 | |
442 | 423 /* if true, we don't want to set any redisplay flags on modeline extent |
424 changes */ | |
425 int in_modeline_generation; | |
426 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
427 int debug_soe; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
428 |
428 | 429 |
430 /************************************************************************/ | |
431 /* Extent list primitives */ | |
432 /************************************************************************/ | |
433 | |
434 /* A list of extents is maintained as a double gap array: one gap array | |
435 is ordered by start index (the "display order") and the other is | |
436 ordered by end index (the "e-order"). Note that positions in an | |
437 extent list should logically be conceived of as referring *to* | |
438 a particular extent (as is the norm in programs) rather than | |
439 sitting between two extents. Note also that callers of these | |
440 functions should not be aware of the fact that the extent list is | |
441 implemented as an array, except for the fact that positions are | |
442 integers (this should be generalized to handle integers and linked | |
443 list equally well). | |
444 */ | |
445 | |
446 /* Number of elements in an extent list */ | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
447 #define extent_list_num_els(el) gap_array_length (el->start) |
428 | 448 |
449 /* Return the position at which EXTENT is located in the specified extent | |
450 list (in the display order if ENDP is 0, in the e-order otherwise). | |
451 If the extent is not found, the position where the extent would | |
452 be inserted is returned. If ENDP is 0, the insertion would go after | |
453 all other equal extents. If ENDP is not 0, the insertion would go | |
454 before all other equal extents. If FOUNDP is not 0, then whether | |
455 the extent was found will get written into it. */ | |
456 | |
457 static int | |
458 extent_list_locate (Extent_List *el, EXTENT extent, int endp, int *foundp) | |
459 { | |
460 Gap_Array *ga = endp ? el->end : el->start; | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
461 int left = 0, right = gap_array_length (ga); |
428 | 462 int oldfoundpos, foundpos; |
463 int found; | |
464 | |
465 while (left != right) | |
466 { | |
467 /* RIGHT might not point to a valid extent (i.e. it's at the end | |
468 of the list), so NEWPOS must round down. */ | |
647 | 469 int newpos = (left + right) >> 1; |
428 | 470 EXTENT e = EXTENT_GAP_ARRAY_AT (ga, (int) newpos); |
471 | |
472 if (endp ? EXTENT_E_LESS (e, extent) : EXTENT_LESS (e, extent)) | |
647 | 473 left = newpos + 1; |
428 | 474 else |
475 right = newpos; | |
476 } | |
477 | |
478 /* Now we're at the beginning of all equal extents. */ | |
479 found = 0; | |
480 oldfoundpos = foundpos = left; | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
481 while (foundpos < gap_array_length (ga)) |
428 | 482 { |
483 EXTENT e = EXTENT_GAP_ARRAY_AT (ga, foundpos); | |
484 if (e == extent) | |
485 { | |
486 found = 1; | |
487 break; | |
488 } | |
489 if (!EXTENT_EQUAL (e, extent)) | |
490 break; | |
491 foundpos++; | |
492 } | |
493 if (foundp) | |
494 *foundp = found; | |
495 if (found || !endp) | |
496 return foundpos; | |
497 else | |
498 return oldfoundpos; | |
499 } | |
500 | |
501 /* Return the position of the first extent that begins at or after POS | |
502 (or ends at or after POS, if ENDP is not 0). | |
503 | |
504 An out-of-range value for POS is allowed, and guarantees that the | |
505 position at the beginning or end of the extent list is returned. */ | |
506 | |
507 static int | |
826 | 508 extent_list_locate_from_pos (Extent_List *el, Memxpos pos, int endp) |
428 | 509 { |
510 struct extent fake_extent; | |
511 /* | |
512 | |
513 Note that if we search for [POS, POS], then we get the following: | |
514 | |
515 -- if ENDP is 0, then all extents whose start position is <= POS | |
516 lie before the returned position, and all extents whose start | |
517 position is > POS lie at or after the returned position. | |
518 | |
519 -- if ENDP is not 0, then all extents whose end position is < POS | |
520 lie before the returned position, and all extents whose end | |
521 position is >= POS lie at or after the returned position. | |
522 | |
523 */ | |
524 set_extent_start (&fake_extent, endp ? pos : pos-1); | |
525 set_extent_end (&fake_extent, endp ? pos : pos-1); | |
526 return extent_list_locate (el, &fake_extent, endp, 0); | |
527 } | |
528 | |
529 /* Return the extent at POS. */ | |
530 | |
531 static EXTENT | |
826 | 532 extent_list_at (Extent_List *el, Memxpos pos, int endp) |
428 | 533 { |
534 Gap_Array *ga = endp ? el->end : el->start; | |
535 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
536 assert (pos >= 0 && pos < gap_array_length (ga)); |
428 | 537 return EXTENT_GAP_ARRAY_AT (ga, pos); |
538 } | |
539 | |
540 /* Insert an extent into an extent list. */ | |
541 | |
542 static void | |
543 extent_list_insert (Extent_List *el, EXTENT extent) | |
544 { | |
545 int pos, foundp; | |
546 | |
547 pos = extent_list_locate (el, extent, 0, &foundp); | |
548 assert (!foundp); | |
1204 | 549 el->start = gap_array_insert_els (el->start, pos, &extent, 1); |
428 | 550 pos = extent_list_locate (el, extent, 1, &foundp); |
551 assert (!foundp); | |
1204 | 552 el->end = gap_array_insert_els (el->end, pos, &extent, 1); |
428 | 553 } |
554 | |
555 /* Delete an extent from an extent list. */ | |
556 | |
557 static void | |
558 extent_list_delete (Extent_List *el, EXTENT extent) | |
559 { | |
560 int pos, foundp; | |
561 | |
562 pos = extent_list_locate (el, extent, 0, &foundp); | |
563 assert (foundp); | |
564 gap_array_delete_els (el->start, pos, 1); | |
565 pos = extent_list_locate (el, extent, 1, &foundp); | |
566 assert (foundp); | |
567 gap_array_delete_els (el->end, pos, 1); | |
568 } | |
569 | |
570 static void | |
571 extent_list_delete_all (Extent_List *el) | |
572 { | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
573 gap_array_delete_els (el->start, 0, gap_array_length (el->start)); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
574 gap_array_delete_els (el->end, 0, gap_array_length (el->end)); |
428 | 575 } |
576 | |
577 static Extent_List_Marker * | |
578 extent_list_make_marker (Extent_List *el, int pos, int endp) | |
579 { | |
580 Extent_List_Marker *m; | |
581 | |
3092 | 582 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
583 m = XEXTENT_LIST_MARKER (ALLOC_NORMAL_LISP_OBJECT (extent_list_marker)); |
3092 | 584 #else /* not NEW_GC */ |
428 | 585 if (extent_list_marker_freelist) |
586 { | |
587 m = extent_list_marker_freelist; | |
588 extent_list_marker_freelist = extent_list_marker_freelist->next; | |
589 } | |
590 else | |
591 m = xnew (Extent_List_Marker); | |
3092 | 592 #endif /* not NEW_GC */ |
428 | 593 |
594 m->m = gap_array_make_marker (endp ? el->end : el->start, pos); | |
595 m->endp = endp; | |
596 m->next = el->markers; | |
597 el->markers = m; | |
598 return m; | |
599 } | |
600 | |
601 #define extent_list_move_marker(el, mkr, pos) \ | |
602 gap_array_move_marker((mkr)->endp ? (el)->end : (el)->start, (mkr)->m, pos) | |
603 | |
604 static void | |
605 extent_list_delete_marker (Extent_List *el, Extent_List_Marker *m) | |
606 { | |
607 Extent_List_Marker *p, *prev; | |
608 | |
609 for (prev = 0, p = el->markers; p && p != m; prev = p, p = p->next) | |
610 ; | |
611 assert (p); | |
612 if (prev) | |
613 prev->next = p->next; | |
614 else | |
615 el->markers = p->next; | |
3092 | 616 #ifdef NEW_GC |
617 gap_array_delete_marker (m->endp ? el->end : el->start, m->m); | |
618 #else /* not NEW_GC */ | |
428 | 619 m->next = extent_list_marker_freelist; |
620 extent_list_marker_freelist = m; | |
621 gap_array_delete_marker (m->endp ? el->end : el->start, m->m); | |
3092 | 622 #endif /* not NEW_GC */ |
428 | 623 } |
624 | |
625 #define extent_list_marker_pos(el, mkr) \ | |
626 gap_array_marker_pos ((mkr)->endp ? (el)->end : (el)->start, (mkr)->m) | |
627 | |
628 static Extent_List * | |
629 allocate_extent_list (void) | |
630 { | |
3092 | 631 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
632 Extent_List *el = XEXTENT_LIST (ALLOC_NORMAL_LISP_OBJECT (extent_list)); |
3092 | 633 #else /* not NEW_GC */ |
428 | 634 Extent_List *el = xnew (Extent_List); |
3092 | 635 #endif /* not NEW_GC */ |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
636 el->start = make_gap_array (sizeof (EXTENT), 1); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
637 el->end = make_gap_array (sizeof (EXTENT), 1); |
428 | 638 el->markers = 0; |
639 return el; | |
640 } | |
641 | |
3092 | 642 #ifndef NEW_GC |
428 | 643 static void |
644 free_extent_list (Extent_List *el) | |
645 { | |
646 free_gap_array (el->start); | |
647 free_gap_array (el->end); | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
648 xfree (el); |
428 | 649 } |
3092 | 650 #endif /* not NEW_GC */ |
428 | 651 |
652 | |
653 /************************************************************************/ | |
654 /* Auxiliary extent structure */ | |
655 /************************************************************************/ | |
656 | |
1204 | 657 static const struct memory_description extent_auxiliary_description[] ={ |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
658 #define SLOT(x) \ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
659 { XD_LISP_OBJECT, offsetof (struct extent_auxiliary, x) }, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
660 EXTENT_AUXILIARY_SLOTS |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
661 #undef SLOT |
934 | 662 { XD_END } |
663 }; | |
428 | 664 static Lisp_Object |
665 mark_extent_auxiliary (Lisp_Object obj) | |
666 { | |
667 struct extent_auxiliary *data = XEXTENT_AUXILIARY (obj); | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
668 #define SLOT(x) mark_object (data->x); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
669 EXTENT_AUXILIARY_SLOTS |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
670 #undef SLOT |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
671 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
672 return Qnil; |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
673 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
674 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
675 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("extent-auxiliary", |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
676 extent_auxiliary, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
677 mark_extent_auxiliary, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
678 extent_auxiliary_description, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
679 struct extent_auxiliary); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
680 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
681 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
682 static Lisp_Object |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
683 allocate_extent_auxiliary (void) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
684 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
685 Lisp_Object obj = ALLOC_NORMAL_LISP_OBJECT (extent_auxiliary); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
686 struct extent_auxiliary *data = XEXTENT_AUXILIARY (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
687 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
688 #define SLOT(x) data->x = Qnil; |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
689 EXTENT_AUXILIARY_SLOTS |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
690 #undef SLOT |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
691 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
692 return obj; |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
693 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
694 |
428 | 695 void |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
696 attach_extent_auxiliary (EXTENT ext) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
697 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
698 Lisp_Object obj = allocate_extent_auxiliary (); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
699 |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
700 ext->plist = Fcons (obj, ext->plist); |
428 | 701 ext->flags.has_aux = 1; |
702 } | |
703 | |
704 | |
705 /************************************************************************/ | |
706 /* Extent info structure */ | |
707 /************************************************************************/ | |
708 | |
709 /* An extent-info structure consists of a list of the buffer or string's | |
710 extents and a "stack of extents" that lists all of the extents over | |
711 a particular position. The stack-of-extents info is used for | |
712 optimization purposes -- it basically caches some info that might | |
713 be expensive to compute. Certain otherwise hard computations are easy | |
714 given the stack of extents over a particular position, and if the | |
715 stack of extents over a nearby position is known (because it was | |
716 calculated at some prior point in time), it's easy to move the stack | |
717 of extents to the proper position. | |
718 | |
719 Given that the stack of extents is an optimization, and given that | |
720 it requires memory, a string's stack of extents is wiped out each | |
721 time a garbage collection occurs. Therefore, any time you retrieve | |
722 the stack of extents, it might not be there. If you need it to | |
723 be there, use the _force version. | |
724 | |
725 Similarly, a string may or may not have an extent_info structure. | |
726 (Generally it won't if there haven't been any extents added to the | |
727 string.) So use the _force version if you need the extent_info | |
728 structure to be there. */ | |
729 | |
730 static struct stack_of_extents *allocate_soe (void); | |
3092 | 731 #ifndef NEW_GC |
428 | 732 static void free_soe (struct stack_of_extents *soe); |
3092 | 733 #endif /* not NEW_GC */ |
428 | 734 static void soe_invalidate (Lisp_Object obj); |
735 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
736 #ifndef NEW_GC |
1204 | 737 extern const struct sized_memory_description extent_list_marker_description; |
3092 | 738 #endif /* not NEW_GC */ |
1204 | 739 |
740 static const struct memory_description extent_list_marker_description_1[] = { | |
3092 | 741 #ifdef NEW_GC |
742 { XD_LISP_OBJECT, offsetof (Extent_List_Marker, m) }, | |
743 { XD_LISP_OBJECT, offsetof (Extent_List_Marker, next) }, | |
744 #else /* not NEW_GC */ | |
2367 | 745 { XD_BLOCK_PTR, offsetof (Extent_List_Marker, m), 1, |
2551 | 746 { &gap_array_marker_description } }, |
2367 | 747 { XD_BLOCK_PTR, offsetof (Extent_List_Marker, next), 1, |
2551 | 748 { &extent_list_marker_description } }, |
3092 | 749 #endif /* not NEW_GC */ |
1204 | 750 { XD_END } |
751 }; | |
752 | |
3092 | 753 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
754 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("extent-list-marker", |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
755 extent_list_marker, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
756 0, extent_list_marker_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
757 struct extent_list_marker); |
3092 | 758 #else /* not NEW_GC */ |
1204 | 759 const struct sized_memory_description extent_list_marker_description = { |
760 sizeof (Extent_List_Marker), | |
761 extent_list_marker_description_1 | |
762 }; | |
3092 | 763 #endif /* not NEW_GC */ |
1204 | 764 |
765 static const struct memory_description extent_list_description_1[] = { | |
3092 | 766 #ifdef NEW_GC |
767 { XD_LISP_OBJECT, offsetof (Extent_List, start) }, | |
768 { XD_LISP_OBJECT, offsetof (Extent_List, end) }, | |
769 { XD_LISP_OBJECT, offsetof (Extent_List, markers) }, | |
770 #else /* not NEW_GC */ | |
2551 | 771 { XD_BLOCK_PTR, offsetof (Extent_List, start), 1, |
772 { &lispobj_gap_array_description } }, | |
773 { XD_BLOCK_PTR, offsetof (Extent_List, end), 1, | |
774 { &lispobj_gap_array_description }, XD_FLAG_NO_KKCC }, | |
775 { XD_BLOCK_PTR, offsetof (Extent_List, markers), 1, | |
776 { &extent_list_marker_description }, XD_FLAG_NO_KKCC }, | |
3092 | 777 #endif /* not NEW_GC */ |
1204 | 778 { XD_END } |
779 }; | |
780 | |
3092 | 781 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
782 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("extent-list", extent_list, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
783 0, extent_list_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
784 struct extent_list); |
3092 | 785 #else /* not NEW_GC */ |
1204 | 786 static const struct sized_memory_description extent_list_description = { |
787 sizeof (Extent_List), | |
788 extent_list_description_1 | |
789 }; | |
3092 | 790 #endif /* not NEW_GC */ |
1204 | 791 |
792 static const struct memory_description stack_of_extents_description_1[] = { | |
3092 | 793 #ifdef NEW_GC |
794 { XD_LISP_OBJECT, offsetof (Stack_Of_Extents, extents) }, | |
795 #else /* not NEW_GC */ | |
2551 | 796 { XD_BLOCK_PTR, offsetof (Stack_Of_Extents, extents), 1, |
797 { &extent_list_description } }, | |
3092 | 798 #endif /* not NEW_GC */ |
1204 | 799 { XD_END } |
800 }; | |
801 | |
3092 | 802 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
803 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("stack-of-extents", stack_of_extents, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
804 0, stack_of_extents_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
805 struct stack_of_extents); |
3092 | 806 #else /* not NEW_GC */ |
1204 | 807 static const struct sized_memory_description stack_of_extents_description = { |
808 sizeof (Stack_Of_Extents), | |
809 stack_of_extents_description_1 | |
810 }; | |
3092 | 811 #endif /* not NEW_GC */ |
1204 | 812 |
813 static const struct memory_description extent_info_description [] = { | |
3092 | 814 #ifdef NEW_GC |
815 { XD_LISP_OBJECT, offsetof (struct extent_info, extents) }, | |
816 { XD_LISP_OBJECT, offsetof (struct extent_info, soe) }, | |
817 #else /* not NEW_GC */ | |
2367 | 818 { XD_BLOCK_PTR, offsetof (struct extent_info, extents), 1, |
2551 | 819 { &extent_list_description } }, |
2367 | 820 { XD_BLOCK_PTR, offsetof (struct extent_info, soe), 1, |
2551 | 821 { &stack_of_extents_description }, XD_FLAG_NO_KKCC }, |
3092 | 822 #endif /* not NEW_GC */ |
1204 | 823 { XD_END } |
824 }; | |
934 | 825 |
428 | 826 static Lisp_Object |
827 mark_extent_info (Lisp_Object obj) | |
828 { | |
829 struct extent_info *data = (struct extent_info *) XEXTENT_INFO (obj); | |
830 int i; | |
831 Extent_List *list = data->extents; | |
832 | |
833 /* Vbuffer_defaults and Vbuffer_local_symbols are buffer-like | |
834 objects that are created specially and never have their extent | |
835 list initialized (or rather, it is set to zero in | |
836 nuke_all_buffer_slots()). However, these objects get | |
837 garbage-collected so we have to deal. | |
838 | |
839 (Also the list can be zero when we're dealing with a destroyed | |
840 buffer.) */ | |
841 | |
842 if (list) | |
843 { | |
844 for (i = 0; i < extent_list_num_els (list); i++) | |
845 { | |
846 struct extent *extent = extent_list_at (list, i, 0); | |
793 | 847 Lisp_Object exobj = wrap_extent (extent); |
848 | |
428 | 849 mark_object (exobj); |
850 } | |
851 } | |
852 | |
853 return Qnil; | |
854 } | |
855 | |
3263 | 856 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
857 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("extent-info", extent_info, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
858 mark_extent_info, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
859 extent_info_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
860 struct extent_info); |
3263 | 861 #else /* not NEW_GC */ |
428 | 862 static void |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
863 finalize_extent_info (Lisp_Object obj) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
864 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
865 struct extent_info *data = XEXTENT_INFO (obj); |
428 | 866 |
3092 | 867 data->soe = 0; |
868 data->extents = 0; | |
428 | 869 if (data->soe) |
870 { | |
871 free_soe (data->soe); | |
872 data->soe = 0; | |
873 } | |
874 if (data->extents) | |
875 { | |
876 free_extent_list (data->extents); | |
877 data->extents = 0; | |
878 } | |
879 } | |
880 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
881 DEFINE_NODUMP_LISP_OBJECT ("extent-info", extent_info, |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
882 mark_extent_info, internal_object_printer, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
883 finalize_extent_info, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
884 extent_info_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
885 struct extent_info); |
3263 | 886 #endif /* not NEW_GC */ |
428 | 887 |
888 static Lisp_Object | |
889 allocate_extent_info (void) | |
890 { | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
891 Lisp_Object obj = ALLOC_NORMAL_LISP_OBJECT (extent_info); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
892 struct extent_info *data = XEXTENT_INFO (obj); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
893 |
428 | 894 data->extents = allocate_extent_list (); |
895 data->soe = 0; | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
896 return obj; |
428 | 897 } |
898 | |
899 void | |
900 flush_cached_extent_info (Lisp_Object extent_info) | |
901 { | |
902 struct extent_info *data = XEXTENT_INFO (extent_info); | |
903 | |
904 if (data->soe) | |
905 { | |
3092 | 906 #ifndef NEW_GC |
428 | 907 free_soe (data->soe); |
3092 | 908 #endif /* not NEW_GC */ |
428 | 909 data->soe = 0; |
910 } | |
911 } | |
912 | |
913 | |
914 /************************************************************************/ | |
915 /* Buffer/string extent primitives */ | |
916 /************************************************************************/ | |
917 | |
918 /* The functions in this section are the ONLY ones that should know | |
919 about the internal implementation of the extent lists. Other functions | |
920 should only know that there are two orderings on extents, the "display" | |
921 order (sorted by start position, basically) and the e-order (sorted | |
922 by end position, basically), and that certain operations are provided | |
923 to manipulate the list. */ | |
924 | |
925 /* ------------------------------- */ | |
926 /* basic primitives */ | |
927 /* ------------------------------- */ | |
928 | |
929 static Lisp_Object | |
930 decode_buffer_or_string (Lisp_Object object) | |
931 { | |
932 if (NILP (object)) | |
793 | 933 object = wrap_buffer (current_buffer); |
428 | 934 else if (BUFFERP (object)) |
935 CHECK_LIVE_BUFFER (object); | |
936 else if (STRINGP (object)) | |
937 ; | |
938 else | |
939 dead_wrong_type_argument (Qbuffer_or_string_p, object); | |
940 | |
941 return object; | |
942 } | |
943 | |
944 EXTENT | |
945 extent_ancestor_1 (EXTENT e) | |
946 { | |
947 while (e->flags.has_parent) | |
948 { | |
949 /* There should be no circularities except in case of a logic | |
950 error somewhere in the extent code */ | |
951 e = XEXTENT (XEXTENT_AUXILIARY (XCAR (e->plist))->parent); | |
952 } | |
953 return e; | |
954 } | |
955 | |
956 /* Given an extent object (string or buffer or nil), return its extent info. | |
957 This may be 0 for a string. */ | |
958 | |
959 static struct extent_info * | |
960 buffer_or_string_extent_info (Lisp_Object object) | |
961 { | |
962 if (STRINGP (object)) | |
963 { | |
793 | 964 Lisp_Object plist = XSTRING_PLIST (object); |
428 | 965 if (!CONSP (plist) || !EXTENT_INFOP (XCAR (plist))) |
966 return 0; | |
967 return XEXTENT_INFO (XCAR (plist)); | |
968 } | |
969 else if (NILP (object)) | |
970 return 0; | |
971 else | |
972 return XEXTENT_INFO (XBUFFER (object)->extent_info); | |
973 } | |
974 | |
975 /* Given a string or buffer, return its extent list. This may be | |
976 0 for a string. */ | |
977 | |
978 static Extent_List * | |
979 buffer_or_string_extent_list (Lisp_Object object) | |
980 { | |
981 struct extent_info *info = buffer_or_string_extent_info (object); | |
982 | |
983 if (!info) | |
984 return 0; | |
985 return info->extents; | |
986 } | |
987 | |
988 /* Given a string or buffer, return its extent info. If it's not there, | |
989 create it. */ | |
990 | |
991 static struct extent_info * | |
992 buffer_or_string_extent_info_force (Lisp_Object object) | |
993 { | |
994 struct extent_info *info = buffer_or_string_extent_info (object); | |
995 | |
996 if (!info) | |
997 { | |
998 Lisp_Object extent_info; | |
999 | |
1000 assert (STRINGP (object)); /* should never happen for buffers -- | |
1001 the only buffers without an extent | |
1002 info are those after finalization, | |
1003 destroyed buffers, or special | |
1004 Lisp-inaccessible buffer objects. */ | |
1005 extent_info = allocate_extent_info (); | |
793 | 1006 XSTRING_PLIST (object) = Fcons (extent_info, XSTRING_PLIST (object)); |
428 | 1007 return XEXTENT_INFO (extent_info); |
1008 } | |
1009 | |
1010 return info; | |
1011 } | |
1012 | |
1013 /* Detach all the extents in OBJECT. Called from redisplay. */ | |
1014 | |
1015 void | |
1016 detach_all_extents (Lisp_Object object) | |
1017 { | |
1018 struct extent_info *data = buffer_or_string_extent_info (object); | |
1019 | |
1020 if (data) | |
1021 { | |
1022 if (data->extents) | |
1023 { | |
1024 int i; | |
1025 | |
1026 for (i = 0; i < extent_list_num_els (data->extents); i++) | |
1027 { | |
1028 EXTENT e = extent_list_at (data->extents, i, 0); | |
1029 /* No need to do detach_extent(). Just nuke the damn things, | |
1030 which results in the equivalent but faster. */ | |
1031 set_extent_start (e, -1); | |
1032 set_extent_end (e, -1); | |
1033 } | |
3466 | 1034 |
1035 /* But we need to clear all the lists containing extents or | |
1036 havoc will result. */ | |
1037 extent_list_delete_all (data->extents); | |
428 | 1038 } |
1039 soe_invalidate (object); | |
1040 } | |
1041 } | |
1042 | |
1043 | |
1044 void | |
1045 init_buffer_extents (struct buffer *b) | |
1046 { | |
1047 b->extent_info = allocate_extent_info (); | |
1048 } | |
1049 | |
1050 void | |
1051 uninit_buffer_extents (struct buffer *b) | |
1052 { | |
1053 /* Don't destroy the extents here -- there may still be children | |
1054 extents pointing to the extents. */ | |
771 | 1055 detach_all_extents (wrap_buffer (b)); |
3092 | 1056 #ifndef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1057 finalize_extent_info (b->extent_info); |
3092 | 1058 #endif /* not NEW_GC */ |
428 | 1059 } |
1060 | |
1061 /* Retrieve the extent list that an extent is a member of; the | |
1062 return value will never be 0 except in destroyed buffers (in which | |
1063 case the only extents that can refer to this buffer are detached | |
1064 ones). */ | |
1065 | |
1066 #define extent_extent_list(e) buffer_or_string_extent_list (extent_object (e)) | |
1067 | |
1068 /* ------------------------------- */ | |
1069 /* stack of extents */ | |
1070 /* ------------------------------- */ | |
1071 | |
1072 #ifdef ERROR_CHECK_EXTENTS | |
1073 | |
771 | 1074 /* See unicode.c for more about sledgehammer checks */ |
1075 | |
428 | 1076 void |
1077 sledgehammer_extent_check (Lisp_Object object) | |
1078 { | |
1079 int i; | |
1080 int endp; | |
1081 Extent_List *el = buffer_or_string_extent_list (object); | |
1082 struct buffer *buf = 0; | |
1083 | |
1084 if (!el) | |
1085 return; | |
1086 | |
1087 if (BUFFERP (object)) | |
1088 buf = XBUFFER (object); | |
1089 | |
1090 for (endp = 0; endp < 2; endp++) | |
1091 for (i = 1; i < extent_list_num_els (el); i++) | |
1092 { | |
1093 EXTENT e1 = extent_list_at (el, i-1, endp); | |
1094 EXTENT e2 = extent_list_at (el, i, endp); | |
1095 if (buf) | |
1096 { | |
1097 assert (extent_start (e1) <= buf->text->gpt || | |
1098 extent_start (e1) > buf->text->gpt + buf->text->gap_size); | |
1099 assert (extent_end (e1) <= buf->text->gpt || | |
1100 extent_end (e1) > buf->text->gpt + buf->text->gap_size); | |
1101 } | |
1102 assert (extent_start (e1) <= extent_end (e1)); | |
1103 assert (endp ? (EXTENT_E_LESS_EQUAL (e1, e2)) : | |
1104 (EXTENT_LESS_EQUAL (e1, e2))); | |
1105 } | |
1106 } | |
1107 | |
1108 #endif | |
1109 | |
1110 static Stack_Of_Extents * | |
1111 buffer_or_string_stack_of_extents (Lisp_Object object) | |
1112 { | |
1113 struct extent_info *info = buffer_or_string_extent_info (object); | |
1114 if (!info) | |
1115 return 0; | |
1116 return info->soe; | |
1117 } | |
1118 | |
1119 static Stack_Of_Extents * | |
1120 buffer_or_string_stack_of_extents_force (Lisp_Object object) | |
1121 { | |
1122 struct extent_info *info = buffer_or_string_extent_info_force (object); | |
1123 if (!info->soe) | |
1124 info->soe = allocate_soe (); | |
1125 return info->soe; | |
1126 } | |
1127 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1128 #ifdef DEBUG_XEMACS |
428 | 1129 |
1130 static void | |
1131 soe_dump (Lisp_Object obj) | |
1132 { | |
1133 int i; | |
1134 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents (obj); | |
1135 Extent_List *sel; | |
1136 int endp; | |
1137 | |
1138 if (!soe) | |
1139 { | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1140 stderr_out ("No SOE"); |
428 | 1141 return; |
1142 } | |
1143 sel = soe->extents; | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1144 stderr_out ("SOE pos is %ld (memxpos %ld)\n", |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1145 soe->pos < 0 ? soe->pos : |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1146 buffer_or_string_memxpos_to_bytexpos (obj, soe->pos), |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1147 soe->pos); |
428 | 1148 for (endp = 0; endp < 2; endp++) |
1149 { | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1150 stderr_out (endp ? "SOE end:" : "SOE start:"); |
428 | 1151 for (i = 0; i < extent_list_num_els (sel); i++) |
1152 { | |
1153 EXTENT e = extent_list_at (sel, i, endp); | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1154 stderr_out ("\t"); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1155 debug_print (wrap_extent (e)); |
428 | 1156 } |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1157 stderr_out ("\n"); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1158 } |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1159 stderr_out ("\n"); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1160 } |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1161 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1162 #endif /* DEBUG_XEMACS */ |
428 | 1163 |
1164 /* Insert EXTENT into OBJ's stack of extents, if necessary. */ | |
1165 | |
1166 static void | |
1167 soe_insert (Lisp_Object obj, EXTENT extent) | |
1168 { | |
1169 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents (obj); | |
1170 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1171 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1172 if (debug_soe) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1173 { |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1174 stderr_out ("Inserting into SOE: "); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1175 debug_print (wrap_extent (extent)); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1176 stderr_out ("\n"); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1177 } |
428 | 1178 #endif |
1179 if (!soe || soe->pos < extent_start (extent) || | |
1180 soe->pos > extent_end (extent)) | |
1181 { | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1182 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1183 if (debug_soe) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1184 stderr_out ("(not needed)\n\n"); |
428 | 1185 #endif |
1186 return; | |
1187 } | |
1188 extent_list_insert (soe->extents, extent); | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1189 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1190 if (debug_soe) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1191 { |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1192 stderr_out ("SOE afterwards is:\n"); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1193 soe_dump (obj); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1194 } |
428 | 1195 #endif |
1196 } | |
1197 | |
1198 /* Delete EXTENT from OBJ's stack of extents, if necessary. */ | |
1199 | |
1200 static void | |
1201 soe_delete (Lisp_Object obj, EXTENT extent) | |
1202 { | |
1203 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents (obj); | |
1204 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1205 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1206 if (debug_soe) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1207 { |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1208 stderr_out ("Deleting from SOE: "); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1209 debug_print (wrap_extent (extent)); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1210 stderr_out ("\n"); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1211 } |
428 | 1212 #endif |
1213 if (!soe || soe->pos < extent_start (extent) || | |
1214 soe->pos > extent_end (extent)) | |
1215 { | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1216 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1217 if (debug_soe) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1218 stderr_out ("(not needed)\n\n"); |
428 | 1219 #endif |
1220 return; | |
1221 } | |
1222 extent_list_delete (soe->extents, extent); | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1223 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1224 if (debug_soe) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1225 { |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1226 stderr_out ("SOE afterwards is:\n"); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1227 soe_dump (obj); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1228 } |
428 | 1229 #endif |
1230 } | |
1231 | |
1232 /* Move OBJ's stack of extents to lie over the specified position. */ | |
1233 | |
1234 static void | |
826 | 1235 soe_move (Lisp_Object obj, Memxpos pos) |
428 | 1236 { |
1237 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents_force (obj); | |
1238 Extent_List *sel = soe->extents; | |
1239 int numsoe = extent_list_num_els (sel); | |
1240 Extent_List *bel = buffer_or_string_extent_list (obj); | |
1241 int direction; | |
1242 int endp; | |
1243 | |
1244 #ifdef ERROR_CHECK_EXTENTS | |
1245 assert (bel); | |
1246 #endif | |
1247 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1248 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1249 if (debug_soe) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1250 stderr_out ("Moving SOE from %ld (memxpos %ld) to %ld (memxpos %ld)\n", |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1251 soe->pos < 0 ? soe->pos : |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1252 buffer_or_string_memxpos_to_bytexpos (obj, soe->pos), soe->pos, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1253 buffer_or_string_memxpos_to_bytexpos (obj, pos), pos); |
428 | 1254 #endif |
1255 if (soe->pos < pos) | |
1256 { | |
1257 direction = 1; | |
1258 endp = 0; | |
1259 } | |
1260 else if (soe->pos > pos) | |
1261 { | |
1262 direction = -1; | |
1263 endp = 1; | |
1264 } | |
1265 else | |
1266 { | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1267 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1268 if (debug_soe) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1269 stderr_out ("(not needed)\n\n"); |
428 | 1270 #endif |
1271 return; | |
1272 } | |
1273 | |
1274 /* For DIRECTION = 1: Any extent that overlaps POS is either in the | |
1275 SOE (if the extent starts at or before SOE->POS) or is greater | |
1276 (in the display order) than any extent in the SOE (if it starts | |
1277 after SOE->POS). | |
1278 | |
1279 For DIRECTION = -1: Any extent that overlaps POS is either in the | |
1280 SOE (if the extent ends at or after SOE->POS) or is less (in the | |
1281 e-order) than any extent in the SOE (if it ends before SOE->POS). | |
1282 | |
1283 We proceed in two stages: | |
1284 | |
1285 1) delete all extents in the SOE that don't overlap POS. | |
1286 2) insert all extents into the SOE that start (or end, when | |
1287 DIRECTION = -1) in (SOE->POS, POS] and that overlap | |
1288 POS. (Don't include SOE->POS in the range because those | |
1289 extents would already be in the SOE.) | |
1290 */ | |
1291 | |
1292 /* STAGE 1. */ | |
1293 | |
1294 if (numsoe > 0) | |
1295 { | |
1296 /* Delete all extents in the SOE that don't overlap POS. | |
1297 This is all extents that end before (or start after, | |
1298 if DIRECTION = -1) POS. | |
1299 */ | |
1300 | |
1301 /* Deleting extents from the SOE is tricky because it changes | |
1302 the positions of extents. If we are deleting in the forward | |
1303 direction we have to call extent_list_at() on the same position | |
1304 over and over again because positions after the deleted element | |
1305 get shifted back by 1. To make life simplest, we delete forward | |
1306 irrespective of DIRECTION. | |
1307 */ | |
1308 int start, end; | |
1309 int i; | |
1310 | |
1311 if (direction > 0) | |
1312 { | |
1313 start = 0; | |
1314 end = extent_list_locate_from_pos (sel, pos, 1); | |
1315 } | |
1316 else | |
1317 { | |
1318 start = extent_list_locate_from_pos (sel, pos+1, 0); | |
1319 end = numsoe; | |
1320 } | |
1321 | |
1322 for (i = start; i < end; i++) | |
1323 extent_list_delete (sel, extent_list_at (sel, start /* see above */, | |
1324 !endp)); | |
1325 } | |
1326 | |
1327 /* STAGE 2. */ | |
1328 | |
1329 { | |
1330 int start_pos; | |
1331 | |
1332 if (direction < 0) | |
1333 start_pos = extent_list_locate_from_pos (bel, soe->pos, endp) - 1; | |
1334 else | |
1335 start_pos = extent_list_locate_from_pos (bel, soe->pos + 1, endp); | |
1336 | |
1337 for (; start_pos >= 0 && start_pos < extent_list_num_els (bel); | |
1338 start_pos += direction) | |
1339 { | |
1340 EXTENT e = extent_list_at (bel, start_pos, endp); | |
1341 if ((direction > 0) ? | |
1342 (extent_start (e) > pos) : | |
1343 (extent_end (e) < pos)) | |
1344 break; /* All further extents lie on the far side of POS | |
1345 and thus can't overlap. */ | |
1346 if ((direction > 0) ? | |
1347 (extent_end (e) >= pos) : | |
1348 (extent_start (e) <= pos)) | |
1349 extent_list_insert (sel, e); | |
1350 } | |
1351 } | |
1352 | |
1353 soe->pos = pos; | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1354 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1355 if (debug_soe) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1356 { |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1357 stderr_out ("SOE afterwards is:\n"); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1358 soe_dump (obj); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1359 } |
428 | 1360 #endif |
1361 } | |
1362 | |
1363 static void | |
1364 soe_invalidate (Lisp_Object obj) | |
1365 { | |
1366 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents (obj); | |
1367 | |
1368 if (soe) | |
1369 { | |
1370 extent_list_delete_all (soe->extents); | |
1371 soe->pos = -1; | |
1372 } | |
1373 } | |
1374 | |
1375 static struct stack_of_extents * | |
1376 allocate_soe (void) | |
1377 { | |
3092 | 1378 #ifdef NEW_GC |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1379 struct stack_of_extents *soe = |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1380 XSTACK_OF_EXTENTS (ALLOC_NORMAL_LISP_OBJECT (stack_of_extents)); |
3092 | 1381 #else /* not NEW_GC */ |
428 | 1382 struct stack_of_extents *soe = xnew_and_zero (struct stack_of_extents); |
3092 | 1383 #endif /* not NEW_GC */ |
428 | 1384 soe->extents = allocate_extent_list (); |
1385 soe->pos = -1; | |
1386 return soe; | |
1387 } | |
1388 | |
3092 | 1389 #ifndef NEW_GC |
428 | 1390 static void |
1391 free_soe (struct stack_of_extents *soe) | |
1392 { | |
1393 free_extent_list (soe->extents); | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
1394 xfree (soe); |
428 | 1395 } |
3092 | 1396 #endif /* not NEW_GC */ |
428 | 1397 |
1398 /* ------------------------------- */ | |
1399 /* other primitives */ | |
1400 /* ------------------------------- */ | |
1401 | |
1402 /* Return the start (endp == 0) or end (endp == 1) of an extent as | |
1403 a byte index. If you want the value as a memory index, use | |
1404 extent_endpoint(). If you want the value as a buffer position, | |
826 | 1405 use extent_endpoint_char(). */ |
1406 | |
1407 Bytexpos | |
1408 extent_endpoint_byte (EXTENT extent, int endp) | |
1409 { | |
1410 assert (EXTENT_LIVE_P (extent)); | |
1411 assert (!extent_detached_p (extent)); | |
1412 { | |
1413 Memxpos i = endp ? extent_end (extent) : extent_start (extent); | |
1414 Lisp_Object obj = extent_object (extent); | |
1415 return buffer_or_string_memxpos_to_bytexpos (obj, i); | |
1416 } | |
1417 } | |
1418 | |
1419 Charxpos | |
1420 extent_endpoint_char (EXTENT extent, int endp) | |
428 | 1421 { |
1422 assert (EXTENT_LIVE_P (extent)); | |
1423 assert (!extent_detached_p (extent)); | |
1424 { | |
826 | 1425 Memxpos i = endp ? extent_end (extent) : extent_start (extent); |
428 | 1426 Lisp_Object obj = extent_object (extent); |
826 | 1427 return buffer_or_string_memxpos_to_charxpos (obj, i); |
428 | 1428 } |
1429 } | |
1430 | |
1431 static void | |
826 | 1432 signal_single_extent_changed (EXTENT extent, Lisp_Object property, |
2286 | 1433 Bytexpos UNUSED (old_start), |
1434 Bytexpos UNUSED (old_end)) | |
826 | 1435 { |
1436 EXTENT anc = extent_ancestor (extent); | |
1437 /* Redisplay checks */ | |
1438 if (NILP (property) ? | |
1439 (!NILP (extent_face (anc)) || | |
1440 !NILP (extent_begin_glyph (anc)) || | |
1441 !NILP (extent_end_glyph (anc)) || | |
1442 !NILP (extent_mouse_face (anc)) || | |
1443 !NILP (extent_invisible (anc)) || | |
1444 !NILP (extent_initial_redisplay_function (anc))) : | |
1445 EQ (property, Qface) || | |
1446 EQ (property, Qmouse_face) || | |
1447 EQ (property, Qbegin_glyph) || | |
1448 EQ (property, Qend_glyph) || | |
1449 EQ (property, Qbegin_glyph_layout) || | |
1450 EQ (property, Qend_glyph_layout) || | |
1451 EQ (property, Qinvisible) || | |
1452 EQ (property, Qinitial_redisplay_function) || | |
1453 EQ (property, Qpriority)) | |
1454 { | |
1455 Lisp_Object object = extent_object (extent); | |
1456 | |
1457 if (extent_detached_p (extent)) | |
1458 return; | |
1459 | |
1460 else if (STRINGP (object)) | |
1461 { | |
1462 /* #### Changes to string extents can affect redisplay if they are | |
1463 in the modeline or in the gutters. | |
1464 | |
1465 If the extent is in some generated-modeline-string: when we | |
1466 change an extent in generated-modeline-string, this changes its | |
1467 parent, which is in `modeline-format', so we should force the | |
1468 modeline to be updated. But how to determine whether a string | |
1469 is a `generated-modeline-string'? Looping through all buffers | |
1470 is not very efficient. Should we add all | |
1471 `generated-modeline-string' strings to a hash table? Maybe | |
1472 efficiency is not the greatest concern here and there's no big | |
1473 loss in looping over the buffers. | |
1474 | |
1475 If the extent is in a gutter we mark the gutter as | |
1476 changed. This means (a) we can update extents in the gutters | |
1477 when we need it. (b) we don't have to update the gutters when | |
1478 only extents attached to buffers have changed. */ | |
1479 | |
1480 if (!in_modeline_generation) | |
1481 MARK_EXTENTS_CHANGED; | |
1482 gutter_extent_signal_changed_region_maybe | |
1483 (object, extent_endpoint_char (extent, 0), | |
1484 extent_endpoint_char (extent, 1)); | |
1485 } | |
1486 else if (BUFFERP (object)) | |
1487 { | |
1488 struct buffer *b; | |
1489 b = XBUFFER (object); | |
1490 BUF_FACECHANGE (b)++; | |
1491 MARK_EXTENTS_CHANGED; | |
1492 if (NILP (property) ? !NILP (extent_invisible (anc)) : | |
1493 EQ (property, Qinvisible)) | |
1494 MARK_CLIP_CHANGED; | |
1495 buffer_extent_signal_changed_region | |
1496 (b, extent_endpoint_char (extent, 0), | |
1497 extent_endpoint_char (extent, 1)); | |
1498 } | |
1499 } | |
1500 | |
1501 /* Check for syntax table property change */ | |
1502 if (NILP (property) ? !NILP (Fextent_property (wrap_extent (extent), | |
1503 Qsyntax_table, Qnil)) : | |
1504 EQ (property, Qsyntax_table)) | |
3250 | 1505 signal_syntax_cache_extent_changed (extent); |
826 | 1506 } |
1507 | |
1508 /* Make note that a change has happened in EXTENT. The change was either | |
1509 to a property or to the endpoints (but not both at once). If PROPERTY | |
1510 is non-nil, the change happened to that property; otherwise, the change | |
1511 happened to the endpoints, and the old ones are given. Currently, all | |
1512 endpoints changes are in the form of two signals, a detach followed by | |
1513 an attach, and when detaching, we are signalled before the extent is | |
1514 detached. (You can distinguish a detach from an attach because the | |
1515 latter has old_start == -1 and old_end == -1.) (#### We don't currently | |
1516 give the old property. If someone needs that, this will have to | |
1517 change.) KLUDGE: If PROPERTY is Qt, all properties may have changed | |
1518 because the parent was changed. #### We need to handle this properly, by | |
1519 mapping over properties. */ | |
1520 | |
1521 static void | |
1522 signal_extent_changed (EXTENT extent, Lisp_Object property, | |
1523 Bytexpos old_start, Bytexpos old_end, | |
1524 int descendants_too) | |
1525 { | |
428 | 1526 /* we could easily encounter a detached extent while traversing the |
1527 children, but we should never be able to encounter a dead extent. */ | |
1528 assert (EXTENT_LIVE_P (extent)); | |
1529 | |
1530 if (descendants_too) | |
1531 { | |
1532 Lisp_Object children = extent_children (extent); | |
1533 | |
1534 if (!NILP (children)) | |
1535 { | |
826 | 1536 /* first process all of the extent's children. We will lose |
1537 big-time if there are any circularities here, so we sure as | |
1538 hell better ensure that there aren't. */ | |
831 | 1539 LIST_LOOP_2 (child, XWEAK_LIST_LIST (children)) |
1540 signal_extent_changed (XEXTENT (child), property, old_start, | |
840 | 1541 old_end, descendants_too); |
428 | 1542 } |
1543 } | |
1544 | |
826 | 1545 /* now process the extent itself. */ |
1546 signal_single_extent_changed (extent, property, old_start, old_end); | |
1547 } | |
428 | 1548 |
1549 static void | |
826 | 1550 signal_extent_property_changed (EXTENT extent, Lisp_Object property, |
1551 int descendants_too) | |
1552 { | |
1553 signal_extent_changed (extent, property, 0, 0, descendants_too); | |
428 | 1554 } |
1555 | |
1556 static EXTENT | |
1557 make_extent_detached (Lisp_Object object) | |
1558 { | |
1559 EXTENT extent = allocate_extent (); | |
1560 | |
1561 assert (NILP (object) || STRINGP (object) || | |
1562 (BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)))); | |
1563 extent_object (extent) = object; | |
1564 /* Now make sure the extent info exists. */ | |
1565 if (!NILP (object)) | |
1566 buffer_or_string_extent_info_force (object); | |
1567 return extent; | |
1568 } | |
1569 | |
1570 /* A "real" extent is any extent other than the internal (not-user-visible) | |
1571 extents used by `map-extents'. */ | |
1572 | |
1573 static EXTENT | |
1574 real_extent_at_forward (Extent_List *el, int pos, int endp) | |
1575 { | |
1576 for (; pos < extent_list_num_els (el); pos++) | |
1577 { | |
1578 EXTENT e = extent_list_at (el, pos, endp); | |
1579 if (!extent_internal_p (e)) | |
1580 return e; | |
1581 } | |
1582 return 0; | |
1583 } | |
1584 | |
1585 static EXTENT | |
1586 real_extent_at_backward (Extent_List *el, int pos, int endp) | |
1587 { | |
1588 for (; pos >= 0; pos--) | |
1589 { | |
1590 EXTENT e = extent_list_at (el, pos, endp); | |
1591 if (!extent_internal_p (e)) | |
1592 return e; | |
1593 } | |
1594 return 0; | |
1595 } | |
1596 | |
1597 static EXTENT | |
1598 extent_first (Lisp_Object obj) | |
1599 { | |
1600 Extent_List *el = buffer_or_string_extent_list (obj); | |
1601 | |
1602 if (!el) | |
1603 return 0; | |
1604 return real_extent_at_forward (el, 0, 0); | |
1605 } | |
1606 | |
1607 #ifdef DEBUG_XEMACS | |
1608 static EXTENT | |
1609 extent_e_first (Lisp_Object obj) | |
1610 { | |
1611 Extent_List *el = buffer_or_string_extent_list (obj); | |
1612 | |
1613 if (!el) | |
1614 return 0; | |
1615 return real_extent_at_forward (el, 0, 1); | |
1616 } | |
1617 #endif | |
1618 | |
1619 static EXTENT | |
1620 extent_next (EXTENT e) | |
1621 { | |
1622 Extent_List *el = extent_extent_list (e); | |
1623 int foundp; | |
1624 int pos = extent_list_locate (el, e, 0, &foundp); | |
1625 assert (foundp); | |
1626 return real_extent_at_forward (el, pos+1, 0); | |
1627 } | |
1628 | |
1629 #ifdef DEBUG_XEMACS | |
1630 static EXTENT | |
1631 extent_e_next (EXTENT e) | |
1632 { | |
1633 Extent_List *el = extent_extent_list (e); | |
1634 int foundp; | |
1635 int pos = extent_list_locate (el, e, 1, &foundp); | |
1636 assert (foundp); | |
1637 return real_extent_at_forward (el, pos+1, 1); | |
1638 } | |
1639 #endif | |
1640 | |
1641 static EXTENT | |
1642 extent_last (Lisp_Object obj) | |
1643 { | |
1644 Extent_List *el = buffer_or_string_extent_list (obj); | |
1645 | |
1646 if (!el) | |
1647 return 0; | |
1648 return real_extent_at_backward (el, extent_list_num_els (el) - 1, 0); | |
1649 } | |
1650 | |
1651 #ifdef DEBUG_XEMACS | |
1652 static EXTENT | |
1653 extent_e_last (Lisp_Object obj) | |
1654 { | |
1655 Extent_List *el = buffer_or_string_extent_list (obj); | |
1656 | |
1657 if (!el) | |
1658 return 0; | |
1659 return real_extent_at_backward (el, extent_list_num_els (el) - 1, 1); | |
1660 } | |
1661 #endif | |
1662 | |
1663 static EXTENT | |
1664 extent_previous (EXTENT e) | |
1665 { | |
1666 Extent_List *el = extent_extent_list (e); | |
1667 int foundp; | |
1668 int pos = extent_list_locate (el, e, 0, &foundp); | |
1669 assert (foundp); | |
1670 return real_extent_at_backward (el, pos-1, 0); | |
1671 } | |
1672 | |
1673 #ifdef DEBUG_XEMACS | |
1674 static EXTENT | |
1675 extent_e_previous (EXTENT e) | |
1676 { | |
1677 Extent_List *el = extent_extent_list (e); | |
1678 int foundp; | |
1679 int pos = extent_list_locate (el, e, 1, &foundp); | |
1680 assert (foundp); | |
1681 return real_extent_at_backward (el, pos-1, 1); | |
1682 } | |
1683 #endif | |
1684 | |
1685 static void | |
1686 extent_attach (EXTENT extent) | |
1687 { | |
1688 Extent_List *el = extent_extent_list (extent); | |
1689 | |
1690 extent_list_insert (el, extent); | |
1691 soe_insert (extent_object (extent), extent); | |
1692 /* only this extent changed */ | |
826 | 1693 signal_extent_changed (extent, Qnil, -1, -1, 0); |
428 | 1694 } |
1695 | |
1696 static void | |
1697 extent_detach (EXTENT extent) | |
1698 { | |
1699 Extent_List *el; | |
1700 | |
1701 if (extent_detached_p (extent)) | |
1702 return; | |
1703 el = extent_extent_list (extent); | |
1704 | |
1705 /* call this before messing with the extent. */ | |
826 | 1706 signal_extent_changed (extent, Qnil, |
1707 extent_endpoint_byte (extent, 0), | |
1708 extent_endpoint_char (extent, 0), | |
1709 0); | |
428 | 1710 extent_list_delete (el, extent); |
1711 soe_delete (extent_object (extent), extent); | |
1712 set_extent_start (extent, -1); | |
1713 set_extent_end (extent, -1); | |
1714 } | |
1715 | |
1716 /* ------------------------------- */ | |
1717 /* map-extents et al. */ | |
1718 /* ------------------------------- */ | |
1719 | |
1720 /* Returns true iff map_extents() would visit the given extent. | |
1721 See the comments at map_extents() for info on the overlap rule. | |
1722 Assumes that all validation on the extent and buffer positions has | |
1723 already been performed (see Fextent_in_region_p ()). | |
1724 */ | |
1725 static int | |
826 | 1726 extent_in_region_p (EXTENT extent, Bytexpos from, Bytexpos to, |
428 | 1727 unsigned int flags) |
1728 { | |
1729 Lisp_Object obj = extent_object (extent); | |
1730 Endpoint_Index start, end, exs, exe; | |
1731 int start_open, end_open; | |
1732 unsigned int all_extents_flags = flags & ME_ALL_EXTENTS_MASK; | |
1733 unsigned int in_region_flags = flags & ME_IN_REGION_MASK; | |
1734 int retval; | |
1735 | |
1736 /* A zero-length region is treated as closed-closed. */ | |
1737 if (from == to) | |
1738 { | |
1739 flags |= ME_END_CLOSED; | |
1740 flags &= ~ME_START_OPEN; | |
1741 } | |
1742 | |
1743 /* So is a zero-length extent. */ | |
1744 if (extent_start (extent) == extent_end (extent)) | |
1745 start_open = 0, end_open = 0; | |
1746 /* `all_extents_flags' will almost always be zero. */ | |
1747 else if (all_extents_flags == 0) | |
1748 { | |
1749 start_open = extent_start_open_p (extent); | |
1750 end_open = extent_end_open_p (extent); | |
1751 } | |
1752 else | |
1753 switch (all_extents_flags) | |
1754 { | |
1755 case ME_ALL_EXTENTS_CLOSED: start_open = 0, end_open = 0; break; | |
1756 case ME_ALL_EXTENTS_OPEN: start_open = 1, end_open = 1; break; | |
1757 case ME_ALL_EXTENTS_CLOSED_OPEN: start_open = 0, end_open = 1; break; | |
1758 case ME_ALL_EXTENTS_OPEN_CLOSED: start_open = 1, end_open = 0; break; | |
2500 | 1759 default: ABORT(); return 0; |
428 | 1760 } |
1761 | |
826 | 1762 start = buffer_or_string_bytexpos_to_startind (obj, from, |
428 | 1763 flags & ME_START_OPEN); |
826 | 1764 end = buffer_or_string_bytexpos_to_endind (obj, to, |
1765 ! (flags & ME_END_CLOSED)); | |
1766 exs = memxpos_to_startind (extent_start (extent), start_open); | |
1767 exe = memxpos_to_endind (extent_end (extent), end_open); | |
428 | 1768 |
1769 /* It's easy to determine whether an extent lies *outside* the | |
1770 region -- just determine whether it's completely before | |
1771 or completely after the region. Reject all such extents, so | |
1772 we're now left with only the extents that overlap the region. | |
1773 */ | |
1774 | |
1775 if (exs > end || exe < start) | |
1776 return 0; | |
1777 | |
1778 /* See if any further restrictions are called for. */ | |
1779 /* in_region_flags will almost always be zero. */ | |
1780 if (in_region_flags == 0) | |
1781 retval = 1; | |
1782 else | |
1783 switch (in_region_flags) | |
1784 { | |
1785 case ME_START_IN_REGION: | |
1786 retval = start <= exs && exs <= end; break; | |
1787 case ME_END_IN_REGION: | |
1788 retval = start <= exe && exe <= end; break; | |
1789 case ME_START_AND_END_IN_REGION: | |
1790 retval = start <= exs && exe <= end; break; | |
1791 case ME_START_OR_END_IN_REGION: | |
1792 retval = (start <= exs && exs <= end) || (start <= exe && exe <= end); | |
1793 break; | |
1794 default: | |
2500 | 1795 ABORT(); return 0; |
428 | 1796 } |
1797 return flags & ME_NEGATE_IN_REGION ? !retval : retval; | |
1798 } | |
1799 | |
1800 struct map_extents_struct | |
1801 { | |
1802 Extent_List *el; | |
1803 Extent_List_Marker *mkr; | |
1804 EXTENT range; | |
1805 }; | |
1806 | |
1807 static Lisp_Object | |
1808 map_extents_unwind (Lisp_Object obj) | |
1809 { | |
1810 struct map_extents_struct *closure = | |
1811 (struct map_extents_struct *) get_opaque_ptr (obj); | |
1812 free_opaque_ptr (obj); | |
1813 if (closure->range) | |
1814 extent_detach (closure->range); | |
1815 if (closure->mkr) | |
1816 extent_list_delete_marker (closure->el, closure->mkr); | |
1817 return Qnil; | |
1818 } | |
1819 | |
1820 /* This is the guts of `map-extents' and the other functions that | |
1821 map over extents. In theory the operation of this function is | |
1822 simple: just figure out what extents we're mapping over, and | |
1823 call the function on each one of them in the range. Unfortunately | |
1824 there are a wide variety of things that the mapping function | |
1825 might do, and we have to be very tricky to avoid getting messed | |
1826 up. Furthermore, this function needs to be very fast (it is | |
1827 called multiple times every time text is inserted or deleted | |
1828 from a buffer), and so we can't always afford the overhead of | |
1829 dealing with all the possible things that the mapping function | |
1830 might do; thus, there are many flags that can be specified | |
1831 indicating what the mapping function might or might not do. | |
1832 | |
1833 The result of all this is that this is the most complicated | |
1834 function in this file. Change it at your own risk! | |
1835 | |
1836 A potential simplification to the logic below is to determine | |
1837 all the extents that the mapping function should be called on | |
1838 before any calls are actually made and save them in an array. | |
1839 That introduces its own complications, however (the array | |
1840 needs to be marked for garbage-collection, and a static array | |
1841 cannot be used because map_extents() needs to be reentrant). | |
1842 Furthermore, the results might be a little less sensible than | |
1843 the logic below. */ | |
1844 | |
1845 | |
1846 static void | |
826 | 1847 map_extents (Bytexpos from, Bytexpos to, map_extents_fun fn, |
1848 void *arg, Lisp_Object obj, EXTENT after, | |
1849 unsigned int flags) | |
1850 { | |
1851 Memxpos st, en; /* range we're mapping over */ | |
428 | 1852 EXTENT range = 0; /* extent for this, if ME_MIGHT_MODIFY_TEXT */ |
1853 Extent_List *el = 0; /* extent list we're iterating over */ | |
1854 Extent_List_Marker *posm = 0; /* marker for extent list, | |
1855 if ME_MIGHT_MODIFY_EXTENTS */ | |
1856 /* count and struct for unwind-protect, if ME_MIGHT_THROW */ | |
1292 | 1857 int count = specpdl_depth (); |
428 | 1858 struct map_extents_struct closure; |
1292 | 1859 PROFILE_DECLARE (); |
428 | 1860 |
1861 #ifdef ERROR_CHECK_EXTENTS | |
1862 assert (from <= to); | |
1863 assert (from >= buffer_or_string_absolute_begin_byte (obj) && | |
1864 from <= buffer_or_string_absolute_end_byte (obj) && | |
1865 to >= buffer_or_string_absolute_begin_byte (obj) && | |
1866 to <= buffer_or_string_absolute_end_byte (obj)); | |
1867 #endif | |
1868 | |
1869 if (after) | |
1870 { | |
1871 assert (EQ (obj, extent_object (after))); | |
1872 assert (!extent_detached_p (after)); | |
1873 } | |
1874 | |
1875 el = buffer_or_string_extent_list (obj); | |
1292 | 1876 if (!el || !extent_list_num_els (el)) |
428 | 1877 return; |
1878 el = 0; | |
1879 | |
1292 | 1880 PROFILE_RECORD_ENTERING_SECTION (QSin_map_extents_internal); |
1881 | |
826 | 1882 st = buffer_or_string_bytexpos_to_memxpos (obj, from); |
1883 en = buffer_or_string_bytexpos_to_memxpos (obj, to); | |
428 | 1884 |
1885 if (flags & ME_MIGHT_MODIFY_TEXT) | |
1886 { | |
1887 /* The mapping function might change the text in the buffer, | |
1888 so make an internal extent to hold the range we're mapping | |
1889 over. */ | |
1890 range = make_extent_detached (obj); | |
1891 set_extent_start (range, st); | |
1892 set_extent_end (range, en); | |
1893 range->flags.start_open = flags & ME_START_OPEN; | |
1894 range->flags.end_open = !(flags & ME_END_CLOSED); | |
1895 range->flags.internal = 1; | |
1896 range->flags.detachable = 0; | |
1897 extent_attach (range); | |
1898 } | |
1899 | |
1900 if (flags & ME_MIGHT_THROW) | |
1901 { | |
1902 /* The mapping function might throw past us so we need to use an | |
1903 unwind_protect() to eliminate the internal extent and range | |
1904 that we use. */ | |
1905 closure.range = range; | |
1906 closure.mkr = 0; | |
1907 record_unwind_protect (map_extents_unwind, | |
1908 make_opaque_ptr (&closure)); | |
1909 } | |
1910 | |
1911 /* ---------- Figure out where we start and what direction | |
1912 we move in. This is the trickiest part of this | |
1913 function. ---------- */ | |
1914 | |
1915 /* If ME_START_IN_REGION, ME_END_IN_REGION or ME_START_AND_END_IN_REGION | |
1916 was specified and ME_NEGATE_IN_REGION was not specified, our job | |
1917 is simple because of the presence of the display order and e-order. | |
1918 (Note that theoretically do something similar for | |
1919 ME_START_OR_END_IN_REGION, but that would require more trickiness | |
1920 than it's worth to avoid hitting the same extent twice.) | |
1921 | |
1922 In the general case, all the extents that overlap a range can be | |
1923 divided into two classes: those whose start position lies within | |
1924 the range (including the range's end but not including the | |
1925 range's start), and those that overlap the start position, | |
1926 i.e. those in the SOE for the start position. Or equivalently, | |
1927 the extents can be divided into those whose end position lies | |
1928 within the range and those in the SOE for the end position. Note | |
1929 that for this purpose we treat both the range and all extents in | |
1930 the buffer as closed on both ends. If this is not what the ME_ | |
1931 flags specified, then we've mapped over a few too many extents, | |
1932 but no big deal because extent_in_region_p() will filter them | |
1933 out. Ideally, we could move the SOE to the closer of the range's | |
1934 two ends and work forwards or backwards from there. However, in | |
1935 order to make the semantics of the AFTER argument work out, we | |
1936 have to always go in the same direction; so we choose to always | |
1937 move the SOE to the start position. | |
1938 | |
1939 When it comes time to do the SOE stage, we first call soe_move() | |
1940 so that the SOE gets set up. Note that the SOE might get | |
1941 changed while we are mapping over its contents. If we can | |
1942 guarantee that the SOE won't get moved to a new position, we | |
1943 simply need to put a marker in the SOE and we will track deletions | |
1944 and insertions of extents in the SOE. If the SOE might get moved, | |
1945 however (this would happen as a result of a recursive invocation | |
1946 of map-extents or a call to a redisplay-type function), then | |
1947 trying to track its changes is hopeless, so we just keep a | |
1948 marker to the first (or last) extent in the SOE and use that as | |
1949 our bound. | |
1950 | |
1951 Finally, if DONT_USE_SOE is defined, we don't use the SOE at all | |
1952 and instead just map from the beginning of the buffer. This is | |
1953 used for testing purposes and allows the SOE to be calculated | |
1954 using map_extents() instead of the other way around. */ | |
1955 | |
1956 { | |
1957 int range_flag; /* ME_*_IN_REGION subset of flags */ | |
1958 int do_soe_stage = 0; /* Are we mapping over the SOE? */ | |
1959 /* Does the range stage map over start or end positions? */ | |
1960 int range_endp; | |
1961 /* If type == 0, we include the start position in the range stage mapping. | |
1962 If type == 1, we exclude the start position in the range stage mapping. | |
1963 If type == 2, we begin at range_start_pos, an extent-list position. | |
1964 */ | |
1965 int range_start_type = 0; | |
1966 int range_start_pos = 0; | |
1967 int stage; | |
1968 | |
1969 range_flag = flags & ME_IN_REGION_MASK; | |
1970 if ((range_flag == ME_START_IN_REGION || | |
1971 range_flag == ME_START_AND_END_IN_REGION) && | |
1972 !(flags & ME_NEGATE_IN_REGION)) | |
1973 { | |
1974 /* map over start position in [range-start, range-end]. No SOE | |
1975 stage. */ | |
1976 range_endp = 0; | |
1977 } | |
1978 else if (range_flag == ME_END_IN_REGION && !(flags & ME_NEGATE_IN_REGION)) | |
1979 { | |
1980 /* map over end position in [range-start, range-end]. No SOE | |
1981 stage. */ | |
1982 range_endp = 1; | |
1983 } | |
1984 else | |
1985 { | |
1986 /* Need to include the SOE extents. */ | |
1987 #ifdef DONT_USE_SOE | |
1988 /* Just brute-force it: start from the beginning. */ | |
1989 range_endp = 0; | |
1990 range_start_type = 2; | |
1991 range_start_pos = 0; | |
1992 #else | |
1993 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents_force (obj); | |
1994 int numsoe; | |
1995 | |
1996 /* Move the SOE to the closer end of the range. This dictates | |
1997 whether we map over start positions or end positions. */ | |
1998 range_endp = 0; | |
1999 soe_move (obj, st); | |
2000 numsoe = extent_list_num_els (soe->extents); | |
2001 if (numsoe) | |
2002 { | |
2003 if (flags & ME_MIGHT_MOVE_SOE) | |
2004 { | |
2005 int foundp; | |
2006 /* Can't map over SOE, so just extend range to cover the | |
2007 SOE. */ | |
2008 EXTENT e = extent_list_at (soe->extents, 0, 0); | |
2009 range_start_pos = | |
2010 extent_list_locate (buffer_or_string_extent_list (obj), e, 0, | |
2011 &foundp); | |
2012 assert (foundp); | |
2013 range_start_type = 2; | |
2014 } | |
2015 else | |
2016 { | |
2017 /* We can map over the SOE. */ | |
2018 do_soe_stage = 1; | |
2019 range_start_type = 1; | |
2020 } | |
2021 } | |
2022 else | |
2023 { | |
2024 /* No extents in the SOE to map over, so we act just as if | |
2025 ME_START_IN_REGION or ME_END_IN_REGION was specified. | |
2026 RANGE_ENDP already specified so no need to do anything else. */ | |
2027 } | |
2028 } | |
2029 #endif | |
2030 | |
2031 /* ---------- Now loop over the extents. ---------- */ | |
2032 | |
2033 /* We combine the code for the two stages because much of it | |
2034 overlaps. */ | |
2035 for (stage = 0; stage < 2; stage++) | |
2036 { | |
2037 int pos = 0; /* Position in extent list */ | |
2038 | |
2039 /* First set up start conditions */ | |
2040 if (stage == 0) | |
2041 { /* The SOE stage */ | |
2042 if (!do_soe_stage) | |
2043 continue; | |
2044 el = buffer_or_string_stack_of_extents_force (obj)->extents; | |
2045 /* We will always be looping over start extents here. */ | |
2046 assert (!range_endp); | |
2047 pos = 0; | |
2048 } | |
2049 else | |
2050 { /* The range stage */ | |
2051 el = buffer_or_string_extent_list (obj); | |
2052 switch (range_start_type) | |
2053 { | |
2054 case 0: | |
2055 pos = extent_list_locate_from_pos (el, st, range_endp); | |
2056 break; | |
2057 case 1: | |
2058 pos = extent_list_locate_from_pos (el, st + 1, range_endp); | |
2059 break; | |
2060 case 2: | |
2061 pos = range_start_pos; | |
2062 break; | |
2063 } | |
2064 } | |
2065 | |
2066 if (flags & ME_MIGHT_MODIFY_EXTENTS) | |
2067 { | |
2068 /* Create a marker to track changes to the extent list */ | |
2069 if (posm) | |
2070 /* Delete the marker used in the SOE stage. */ | |
2071 extent_list_delete_marker | |
2072 (buffer_or_string_stack_of_extents_force (obj)->extents, posm); | |
2073 posm = extent_list_make_marker (el, pos, range_endp); | |
2074 /* tell the unwind function about the marker. */ | |
2075 closure.el = el; | |
2076 closure.mkr = posm; | |
2077 } | |
2078 | |
2079 /* Now loop! */ | |
2080 for (;;) | |
2081 { | |
2082 EXTENT e; | |
2083 Lisp_Object obj2; | |
2084 | |
2085 /* ----- update position in extent list | |
2086 and fetch next extent ----- */ | |
2087 | |
2088 if (posm) | |
2089 /* fetch POS again to track extent insertions or deletions */ | |
2090 pos = extent_list_marker_pos (el, posm); | |
2091 if (pos >= extent_list_num_els (el)) | |
2092 break; | |
2093 e = extent_list_at (el, pos, range_endp); | |
2094 pos++; | |
2095 if (posm) | |
2096 /* now point the marker to the next one we're going to process. | |
2097 This ensures graceful behavior if this extent is deleted. */ | |
2098 extent_list_move_marker (el, posm, pos); | |
2099 | |
2100 /* ----- deal with internal extents ----- */ | |
2101 | |
2102 if (extent_internal_p (e)) | |
2103 { | |
2104 if (!(flags & ME_INCLUDE_INTERNAL)) | |
2105 continue; | |
2106 else if (e == range) | |
2107 { | |
2108 /* We're processing internal extents and we've | |
2109 come across our own special range extent. | |
2110 (This happens only in adjust_extents*() and | |
2111 process_extents*(), which handle text | |
2112 insertion and deletion.) We need to omit | |
2113 processing of this extent; otherwise | |
2114 we will probably end up prematurely | |
2115 terminating this loop. */ | |
2116 continue; | |
2117 } | |
2118 } | |
2119 | |
2120 /* ----- deal with AFTER condition ----- */ | |
2121 | |
2122 if (after) | |
2123 { | |
2124 /* if e > after, then we can stop skipping extents. */ | |
2125 if (EXTENT_LESS (after, e)) | |
2126 after = 0; | |
2127 else /* otherwise, skip this extent. */ | |
2128 continue; | |
2129 } | |
2130 | |
2131 /* ----- stop if we're completely outside the range ----- */ | |
2132 | |
2133 /* fetch ST and EN again to track text insertions or deletions */ | |
2134 if (range) | |
2135 { | |
2136 st = extent_start (range); | |
2137 en = extent_end (range); | |
2138 } | |
2139 if (extent_endpoint (e, range_endp) > en) | |
2140 { | |
2141 /* Can't be mapping over SOE because all extents in | |
2142 there should overlap ST */ | |
2143 assert (stage == 1); | |
2144 break; | |
2145 } | |
2146 | |
2147 /* ----- Now actually call the function ----- */ | |
2148 | |
2149 obj2 = extent_object (e); | |
2150 if (extent_in_region_p (e, | |
826 | 2151 buffer_or_string_memxpos_to_bytexpos (obj2, |
2152 st), | |
2153 buffer_or_string_memxpos_to_bytexpos (obj2, | |
2154 en), | |
428 | 2155 flags)) |
2156 { | |
2157 if ((*fn)(e, arg)) | |
2158 { | |
2159 /* Function wants us to stop mapping. */ | |
2160 stage = 1; /* so outer for loop will terminate */ | |
2161 break; | |
2162 } | |
2163 } | |
2164 } | |
2165 } | |
2166 /* ---------- Finished looping. ---------- */ | |
2167 } | |
2168 | |
1292 | 2169 if (!(flags & ME_MIGHT_THROW)) |
428 | 2170 { |
2171 /* Delete them ourselves */ | |
2172 if (range) | |
2173 extent_detach (range); | |
2174 if (posm) | |
2175 extent_list_delete_marker (el, posm); | |
2176 } | |
1292 | 2177 |
2178 /* This deletes the range extent and frees the marker, if ME_MIGHT_THROW. */ | |
2179 unbind_to (count); | |
2180 | |
2181 PROFILE_RECORD_EXITING_SECTION (QSin_map_extents_internal); | |
428 | 2182 } |
2183 | |
2184 /* ------------------------------- */ | |
2185 /* adjust_extents() */ | |
2186 /* ------------------------------- */ | |
2187 | |
2188 /* Add AMOUNT to all extent endpoints in the range (FROM, TO]. This | |
2189 happens whenever the gap is moved or (under Mule) a character in a | |
2190 string is substituted for a different-length one. The reason for | |
2191 this is that extent endpoints behave just like markers (all memory | |
2192 indices do) and this adjustment correct for markers -- see | |
2193 adjust_markers(). Note that it is important that we visit all | |
2194 extent endpoints in the range, irrespective of whether the | |
2195 endpoints are open or closed. | |
2196 | |
2197 We could use map_extents() for this (and in fact the function | |
2198 was originally written that way), but the gap is in an incoherent | |
2199 state when this function is called and this function plays | |
2200 around with extent endpoints without detaching and reattaching | |
2201 the extents (this is provably correct and saves lots of time), | |
2202 so for safety we make it just look at the extent lists directly. */ | |
2203 | |
2204 void | |
826 | 2205 adjust_extents (Lisp_Object obj, Memxpos from, Memxpos to, int amount) |
428 | 2206 { |
2207 int endp; | |
2208 int pos; | |
2209 int startpos[2]; | |
2210 Extent_List *el; | |
2211 Stack_Of_Extents *soe; | |
2212 | |
2213 #ifdef ERROR_CHECK_EXTENTS | |
2214 sledgehammer_extent_check (obj); | |
2215 #endif | |
2216 el = buffer_or_string_extent_list (obj); | |
2217 | |
2218 if (!el || !extent_list_num_els(el)) | |
2219 return; | |
2220 | |
2221 /* IMPORTANT! Compute the starting positions of the extents to | |
2222 modify BEFORE doing any modification! Otherwise the starting | |
2223 position for the second time through the loop might get | |
2224 incorrectly calculated (I got bit by this bug real bad). */ | |
2225 startpos[0] = extent_list_locate_from_pos (el, from+1, 0); | |
2226 startpos[1] = extent_list_locate_from_pos (el, from+1, 1); | |
2227 for (endp = 0; endp < 2; endp++) | |
2228 { | |
2229 for (pos = startpos[endp]; pos < extent_list_num_els (el); | |
2230 pos++) | |
2231 { | |
2232 EXTENT e = extent_list_at (el, pos, endp); | |
2233 if (extent_endpoint (e, endp) > to) | |
2234 break; | |
2235 set_extent_endpoint (e, | |
2236 do_marker_adjustment (extent_endpoint (e, endp), | |
2237 from, to, amount), | |
2238 endp); | |
2239 } | |
2240 } | |
2241 | |
2242 /* The index for the buffer's SOE is a memory index and thus | |
2243 needs to be adjusted like a marker. */ | |
2244 soe = buffer_or_string_stack_of_extents (obj); | |
2245 if (soe && soe->pos >= 0) | |
2246 soe->pos = do_marker_adjustment (soe->pos, from, to, amount); | |
2247 } | |
2248 | |
2249 /* ------------------------------- */ | |
2250 /* adjust_extents_for_deletion() */ | |
2251 /* ------------------------------- */ | |
2252 | |
2253 struct adjust_extents_for_deletion_arg | |
2254 { | |
2255 EXTENT_dynarr *list; | |
2256 }; | |
2257 | |
2258 static int | |
2259 adjust_extents_for_deletion_mapper (EXTENT extent, void *arg) | |
2260 { | |
2261 struct adjust_extents_for_deletion_arg *closure = | |
2262 (struct adjust_extents_for_deletion_arg *) arg; | |
2263 | |
2264 Dynarr_add (closure->list, extent); | |
2265 return 0; /* continue mapping */ | |
2266 } | |
2267 | |
2268 /* For all extent endpoints in the range (FROM, TO], move them to the beginning | |
2269 of the new gap. Note that it is important that we visit all extent | |
2270 endpoints in the range, irrespective of whether the endpoints are open or | |
2271 closed. | |
2272 | |
2273 This function deals with weird stuff such as the fact that extents | |
2274 may get reordered. | |
2275 | |
2276 There is no string correspondent for this because you can't | |
2277 delete characters from a string. | |
2278 */ | |
2279 | |
2280 void | |
826 | 2281 adjust_extents_for_deletion (Lisp_Object object, Bytexpos from, |
2282 Bytexpos to, int gapsize, int numdel, | |
428 | 2283 int movegapsize) |
2284 { | |
2285 struct adjust_extents_for_deletion_arg closure; | |
2286 int i; | |
826 | 2287 Memxpos adjust_to = (Memxpos) (to + gapsize); |
428 | 2288 Bytecount amount = - numdel - movegapsize; |
826 | 2289 Memxpos oldsoe = 0, newsoe = 0; |
428 | 2290 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents (object); |
2291 | |
2292 #ifdef ERROR_CHECK_EXTENTS | |
2293 sledgehammer_extent_check (object); | |
2294 #endif | |
2295 closure.list = Dynarr_new (EXTENT); | |
2296 | |
2297 /* We're going to be playing weird games below with extents and the SOE | |
2298 and such, so compute the list now of all the extents that we're going | |
2299 to muck with. If we do the mapping and adjusting together, things can | |
2300 get all screwed up. */ | |
2301 | |
826 | 2302 map_extents (from, to, adjust_extents_for_deletion_mapper, |
2303 (void *) &closure, object, 0, | |
2304 /* extent endpoints move like markers regardless | |
2305 of their open/closeness. */ | |
2306 ME_ALL_EXTENTS_CLOSED | ME_END_CLOSED | | |
2307 ME_START_OR_END_IN_REGION | ME_INCLUDE_INTERNAL); | |
428 | 2308 |
2309 /* | |
2310 Old and new values for the SOE's position. (It gets adjusted | |
2311 like a marker, just like extent endpoints.) | |
2312 */ | |
2313 | |
2314 if (soe) | |
2315 { | |
2316 oldsoe = soe->pos; | |
2317 if (soe->pos >= 0) | |
2318 newsoe = do_marker_adjustment (soe->pos, | |
2319 adjust_to, adjust_to, | |
2320 amount); | |
2321 else | |
2322 newsoe = soe->pos; | |
2323 } | |
2324 | |
2325 for (i = 0; i < Dynarr_length (closure.list); i++) | |
2326 { | |
2327 EXTENT extent = Dynarr_at (closure.list, i); | |
826 | 2328 Memxpos new_start = extent_start (extent); |
2329 Memxpos new_end = extent_end (extent); | |
428 | 2330 |
2331 /* do_marker_adjustment() will not adjust values that should not be | |
2332 adjusted. We're passing the same funky arguments to | |
2333 do_marker_adjustment() as buffer_delete_range() does. */ | |
2334 new_start = | |
2335 do_marker_adjustment (new_start, | |
2336 adjust_to, adjust_to, | |
2337 amount); | |
2338 new_end = | |
2339 do_marker_adjustment (new_end, | |
2340 adjust_to, adjust_to, | |
2341 amount); | |
2342 | |
2343 /* We need to be very careful here so that the SOE doesn't get | |
2344 corrupted. We are shrinking extents out of the deleted region | |
2345 and simultaneously moving the SOE's pos out of the deleted | |
2346 region, so the SOE should contain the same extents at the end | |
2347 as at the beginning. However, extents may get reordered | |
2348 by this process, so we have to operate by pulling the extents | |
2349 out of the buffer and SOE, changing their bounds, and then | |
2350 reinserting them. In order for the SOE not to get screwed up, | |
2351 we have to make sure that the SOE's pos points to its old | |
2352 location whenever we pull an extent out, and points to its | |
2353 new location whenever we put the extent back in. | |
2354 */ | |
2355 | |
2356 if (new_start != extent_start (extent) || | |
2357 new_end != extent_end (extent)) | |
2358 { | |
2359 extent_detach (extent); | |
2360 set_extent_start (extent, new_start); | |
2361 set_extent_end (extent, new_end); | |
2362 if (soe) | |
2363 soe->pos = newsoe; | |
2364 extent_attach (extent); | |
2365 if (soe) | |
2366 soe->pos = oldsoe; | |
2367 } | |
2368 } | |
2369 | |
2370 if (soe) | |
2371 soe->pos = newsoe; | |
2372 | |
2373 #ifdef ERROR_CHECK_EXTENTS | |
2374 sledgehammer_extent_check (object); | |
2375 #endif | |
2376 Dynarr_free (closure.list); | |
2377 } | |
2378 | |
2379 /* ------------------------------- */ | |
2380 /* extent fragments */ | |
2381 /* ------------------------------- */ | |
2382 | |
2383 /* Imagine that the buffer is divided up into contiguous, | |
2384 nonoverlapping "runs" of text such that no extent | |
2385 starts or ends within a run (extents that abut the | |
2386 run don't count). | |
2387 | |
2388 An extent fragment is a structure that holds data about | |
2389 the run that contains a particular buffer position (if | |
2390 the buffer position is at the junction of two runs, the | |
2391 run after the position is used) -- the beginning and | |
2392 end of the run, a list of all of the extents in that | |
2393 run, the "merged face" that results from merging all of | |
2394 the faces corresponding to those extents, the begin and | |
2395 end glyphs at the beginning of the run, etc. This is | |
2396 the information that redisplay needs in order to | |
2397 display this run. | |
2398 | |
2399 Extent fragments have to be very quick to update to | |
2400 a new buffer position when moving linearly through | |
2401 the buffer. They rely on the stack-of-extents code, | |
2402 which does the heavy-duty algorithmic work of determining | |
2403 which extents overly a particular position. */ | |
2404 | |
2405 /* This function returns the position of the beginning of | |
2406 the first run that begins after POS, or returns POS if | |
2407 there are no such runs. */ | |
2408 | |
826 | 2409 static Bytexpos |
2410 extent_find_end_of_run (Lisp_Object obj, Bytexpos pos, int outside_accessible) | |
428 | 2411 { |
2412 Extent_List *sel; | |
2413 Extent_List *bel = buffer_or_string_extent_list (obj); | |
826 | 2414 Bytexpos pos1, pos2; |
428 | 2415 int elind1, elind2; |
826 | 2416 Memxpos mempos = buffer_or_string_bytexpos_to_memxpos (obj, pos); |
2417 Bytexpos limit = outside_accessible ? | |
428 | 2418 buffer_or_string_absolute_end_byte (obj) : |
826 | 2419 buffer_or_string_accessible_end_byte (obj); |
2420 | |
2421 if (!bel || !extent_list_num_els (bel)) | |
428 | 2422 return limit; |
2423 | |
2424 sel = buffer_or_string_stack_of_extents_force (obj)->extents; | |
2425 soe_move (obj, mempos); | |
2426 | |
2427 /* Find the first start position after POS. */ | |
2428 elind1 = extent_list_locate_from_pos (bel, mempos+1, 0); | |
2429 if (elind1 < extent_list_num_els (bel)) | |
826 | 2430 pos1 = buffer_or_string_memxpos_to_bytexpos |
428 | 2431 (obj, extent_start (extent_list_at (bel, elind1, 0))); |
2432 else | |
2433 pos1 = limit; | |
2434 | |
2435 /* Find the first end position after POS. The extent corresponding | |
2436 to this position is either in the SOE or is greater than or | |
2437 equal to POS1, so we just have to look in the SOE. */ | |
2438 elind2 = extent_list_locate_from_pos (sel, mempos+1, 1); | |
2439 if (elind2 < extent_list_num_els (sel)) | |
826 | 2440 pos2 = buffer_or_string_memxpos_to_bytexpos |
428 | 2441 (obj, extent_end (extent_list_at (sel, elind2, 1))); |
2442 else | |
2443 pos2 = limit; | |
2444 | |
2445 return min (min (pos1, pos2), limit); | |
2446 } | |
2447 | |
826 | 2448 static Bytexpos |
2449 extent_find_beginning_of_run (Lisp_Object obj, Bytexpos pos, | |
428 | 2450 int outside_accessible) |
2451 { | |
2452 Extent_List *sel; | |
2453 Extent_List *bel = buffer_or_string_extent_list (obj); | |
826 | 2454 Bytexpos pos1, pos2; |
428 | 2455 int elind1, elind2; |
826 | 2456 Memxpos mempos = buffer_or_string_bytexpos_to_memxpos (obj, pos); |
2457 Bytexpos limit = outside_accessible ? | |
428 | 2458 buffer_or_string_absolute_begin_byte (obj) : |
826 | 2459 buffer_or_string_accessible_begin_byte (obj); |
428 | 2460 |
2461 if (!bel || !extent_list_num_els(bel)) | |
2462 return limit; | |
2463 | |
2464 sel = buffer_or_string_stack_of_extents_force (obj)->extents; | |
2465 soe_move (obj, mempos); | |
2466 | |
2467 /* Find the first end position before POS. */ | |
2468 elind1 = extent_list_locate_from_pos (bel, mempos, 1); | |
2469 if (elind1 > 0) | |
826 | 2470 pos1 = buffer_or_string_memxpos_to_bytexpos |
428 | 2471 (obj, extent_end (extent_list_at (bel, elind1 - 1, 1))); |
2472 else | |
2473 pos1 = limit; | |
2474 | |
2475 /* Find the first start position before POS. The extent corresponding | |
2476 to this position is either in the SOE or is less than or | |
2477 equal to POS1, so we just have to look in the SOE. */ | |
2478 elind2 = extent_list_locate_from_pos (sel, mempos, 0); | |
2479 if (elind2 > 0) | |
826 | 2480 pos2 = buffer_or_string_memxpos_to_bytexpos |
428 | 2481 (obj, extent_start (extent_list_at (sel, elind2 - 1, 0))); |
2482 else | |
2483 pos2 = limit; | |
2484 | |
2485 return max (max (pos1, pos2), limit); | |
2486 } | |
2487 | |
2488 struct extent_fragment * | |
2489 extent_fragment_new (Lisp_Object buffer_or_string, struct frame *frm) | |
2490 { | |
2491 struct extent_fragment *ef = xnew_and_zero (struct extent_fragment); | |
2492 | |
2493 ef->object = buffer_or_string; | |
2494 ef->frm = frm; | |
2495 ef->extents = Dynarr_new (EXTENT); | |
2496 ef->begin_glyphs = Dynarr_new (glyph_block); | |
2497 ef->end_glyphs = Dynarr_new (glyph_block); | |
2498 | |
2499 return ef; | |
2500 } | |
2501 | |
2502 void | |
2503 extent_fragment_delete (struct extent_fragment *ef) | |
2504 { | |
2505 Dynarr_free (ef->extents); | |
2506 Dynarr_free (ef->begin_glyphs); | |
2507 Dynarr_free (ef->end_glyphs); | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2508 xfree (ef); |
428 | 2509 } |
2510 | |
2511 static int | |
2512 extent_priority_sort_function (const void *humpty, const void *dumpty) | |
2513 { | |
442 | 2514 const EXTENT foo = * (const EXTENT *) humpty; |
2515 const EXTENT bar = * (const EXTENT *) dumpty; | |
428 | 2516 if (extent_priority (foo) < extent_priority (bar)) |
2517 return -1; | |
2518 return extent_priority (foo) > extent_priority (bar); | |
2519 } | |
2520 | |
2521 static void | |
2522 extent_fragment_sort_by_priority (EXTENT_dynarr *extarr) | |
2523 { | |
2524 int i; | |
2525 | |
2526 /* Sort our copy of the stack by extent_priority. We use a bubble | |
2527 sort here because it's going to be faster than qsort() for small | |
2528 numbers of extents (less than 10 or so), and 99.999% of the time | |
2529 there won't ever be more extents than this in the stack. */ | |
2530 if (Dynarr_length (extarr) < 10) | |
2531 { | |
2532 for (i = 1; i < Dynarr_length (extarr); i++) | |
2533 { | |
2534 int j = i - 1; | |
2535 while (j >= 0 && | |
2536 (extent_priority (Dynarr_at (extarr, j)) > | |
2537 extent_priority (Dynarr_at (extarr, j+1)))) | |
2538 { | |
2539 EXTENT tmp = Dynarr_at (extarr, j); | |
2540 Dynarr_at (extarr, j) = Dynarr_at (extarr, j+1); | |
2541 Dynarr_at (extarr, j+1) = tmp; | |
2542 j--; | |
2543 } | |
2544 } | |
2545 } | |
2546 else | |
2547 /* But some loser programs mess up and may create a large number | |
2548 of extents overlapping the same spot. This will result in | |
2549 catastrophic behavior if we use the bubble sort above. */ | |
4967 | 2550 qsort (Dynarr_begin (extarr), Dynarr_length (extarr), |
428 | 2551 sizeof (EXTENT), extent_priority_sort_function); |
2552 } | |
2553 | |
2554 /* If PROP is the `invisible' property of an extent, | |
2555 this is 1 if the extent should be treated as invisible. */ | |
2556 | |
2557 #define EXTENT_PROP_MEANS_INVISIBLE(buf, prop) \ | |
2558 (EQ (buf->invisibility_spec, Qt) \ | |
2559 ? ! NILP (prop) \ | |
2560 : invisible_p (prop, buf->invisibility_spec)) | |
2561 | |
2562 /* If PROP is the `invisible' property of a extent, | |
2563 this is 1 if the extent should be treated as invisible | |
2564 and should have an ellipsis. */ | |
2565 | |
2566 #define EXTENT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS(buf, prop) \ | |
2567 (EQ (buf->invisibility_spec, Qt) \ | |
2568 ? 0 \ | |
2569 : invisible_ellipsis_p (prop, buf->invisibility_spec)) | |
2570 | |
2571 /* This is like a combination of memq and assq. | |
2572 Return 1 if PROPVAL appears as an element of LIST | |
2573 or as the car of an element of LIST. | |
2574 If PROPVAL is a list, compare each element against LIST | |
2575 in that way, and return 1 if any element of PROPVAL is found in LIST. | |
2576 Otherwise return 0. | |
2577 This function cannot quit. */ | |
2578 | |
2579 static int | |
2580 invisible_p (REGISTER Lisp_Object propval, Lisp_Object list) | |
2581 { | |
2582 REGISTER Lisp_Object tail, proptail; | |
2583 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
2584 { | |
2585 REGISTER Lisp_Object tem; | |
2586 tem = XCAR (tail); | |
2587 if (EQ (propval, tem)) | |
2588 return 1; | |
2589 if (CONSP (tem) && EQ (propval, XCAR (tem))) | |
2590 return 1; | |
2591 } | |
2592 if (CONSP (propval)) | |
2593 for (proptail = propval; CONSP (proptail); | |
2594 proptail = XCDR (proptail)) | |
2595 { | |
2596 Lisp_Object propelt; | |
2597 propelt = XCAR (proptail); | |
2598 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
2599 { | |
2600 REGISTER Lisp_Object tem; | |
2601 tem = XCAR (tail); | |
2602 if (EQ (propelt, tem)) | |
2603 return 1; | |
2604 if (CONSP (tem) && EQ (propelt, XCAR (tem))) | |
2605 return 1; | |
2606 } | |
2607 } | |
2608 return 0; | |
2609 } | |
2610 | |
2611 /* Return 1 if PROPVAL appears as the car of an element of LIST | |
2612 and the cdr of that element is non-nil. | |
2613 If PROPVAL is a list, check each element of PROPVAL in that way, | |
2614 and the first time some element is found, | |
2615 return 1 if the cdr of that element is non-nil. | |
2616 Otherwise return 0. | |
2617 This function cannot quit. */ | |
2618 | |
2619 static int | |
2620 invisible_ellipsis_p (REGISTER Lisp_Object propval, Lisp_Object list) | |
2621 { | |
2622 REGISTER Lisp_Object tail, proptail; | |
2623 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
2624 { | |
2625 REGISTER Lisp_Object tem; | |
2626 tem = XCAR (tail); | |
2627 if (CONSP (tem) && EQ (propval, XCAR (tem))) | |
2628 return ! NILP (XCDR (tem)); | |
2629 } | |
2630 if (CONSP (propval)) | |
2631 for (proptail = propval; CONSP (proptail); | |
2632 proptail = XCDR (proptail)) | |
2633 { | |
2634 Lisp_Object propelt; | |
2635 propelt = XCAR (proptail); | |
2636 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
2637 { | |
2638 REGISTER Lisp_Object tem; | |
2639 tem = XCAR (tail); | |
2640 if (CONSP (tem) && EQ (propelt, XCAR (tem))) | |
2641 return ! NILP (XCDR (tem)); | |
2642 } | |
2643 } | |
2644 return 0; | |
2645 } | |
2646 | |
2647 face_index | |
2648 extent_fragment_update (struct window *w, struct extent_fragment *ef, | |
826 | 2649 Bytexpos pos, Lisp_Object last_glyph) |
428 | 2650 { |
2651 int i; | |
819 | 2652 int seen_glyph = NILP (last_glyph) ? 1 : 0; |
428 | 2653 Extent_List *sel = |
2654 buffer_or_string_stack_of_extents_force (ef->object)->extents; | |
2655 EXTENT lhe = 0; | |
2656 struct extent dummy_lhe_extent; | |
826 | 2657 Memxpos mempos = buffer_or_string_bytexpos_to_memxpos (ef->object, pos); |
428 | 2658 |
2659 #ifdef ERROR_CHECK_EXTENTS | |
2660 assert (pos >= buffer_or_string_accessible_begin_byte (ef->object) | |
2661 && pos <= buffer_or_string_accessible_end_byte (ef->object)); | |
2662 #endif | |
2663 | |
2664 Dynarr_reset (ef->extents); | |
2665 Dynarr_reset (ef->begin_glyphs); | |
2666 Dynarr_reset (ef->end_glyphs); | |
2667 | |
2668 ef->previously_invisible = ef->invisible; | |
2669 if (ef->invisible) | |
2670 { | |
2671 if (ef->invisible_ellipses) | |
2672 ef->invisible_ellipses_already_displayed = 1; | |
2673 } | |
2674 else | |
2675 ef->invisible_ellipses_already_displayed = 0; | |
2676 ef->invisible = 0; | |
2677 ef->invisible_ellipses = 0; | |
2678 | |
2679 /* Set up the begin and end positions. */ | |
2680 ef->pos = pos; | |
2681 ef->end = extent_find_end_of_run (ef->object, pos, 0); | |
2682 | |
2683 /* Note that extent_find_end_of_run() already moved the SOE for us. */ | |
2684 /* soe_move (ef->object, mempos); */ | |
2685 | |
2686 /* Determine the begin glyphs at POS. */ | |
2687 for (i = 0; i < extent_list_num_els (sel); i++) | |
2688 { | |
2689 EXTENT e = extent_list_at (sel, i, 0); | |
2690 if (extent_start (e) == mempos && !NILP (extent_begin_glyph (e))) | |
2691 { | |
2692 Lisp_Object glyph = extent_begin_glyph (e); | |
4932 | 2693 if (seen_glyph) |
2694 { | |
2695 struct glyph_block gb; | |
2696 | |
2697 xzero (gb); | |
2698 gb.glyph = glyph; | |
2699 gb.extent = wrap_extent (e); | |
2700 Dynarr_add (ef->begin_glyphs, gb); | |
2701 } | |
819 | 2702 else if (EQ (glyph, last_glyph)) |
2703 seen_glyph = 1; | |
428 | 2704 } |
2705 } | |
2706 | |
2707 /* Determine the end glyphs at POS. */ | |
2708 for (i = 0; i < extent_list_num_els (sel); i++) | |
2709 { | |
2710 EXTENT e = extent_list_at (sel, i, 1); | |
2711 if (extent_end (e) == mempos && !NILP (extent_end_glyph (e))) | |
2712 { | |
2713 Lisp_Object glyph = extent_end_glyph (e); | |
4932 | 2714 if (seen_glyph) |
2715 { | |
2716 struct glyph_block gb; | |
2717 | |
2718 xzero (gb); | |
2719 gb.glyph = glyph; | |
2720 gb.extent = wrap_extent (e); | |
2721 Dynarr_add (ef->end_glyphs, gb); | |
2722 } | |
819 | 2723 else if (EQ (glyph, last_glyph)) |
2724 seen_glyph = 1; | |
428 | 2725 } |
2726 } | |
2727 | |
2728 /* We tried determining all the charsets used in the run here, | |
2729 but that fails even if we only do the current line -- display | |
2730 tables or non-printable characters might cause other charsets | |
2731 to be used. */ | |
2732 | |
2733 /* Determine whether the last-highlighted-extent is present. */ | |
2734 if (EXTENTP (Vlast_highlighted_extent)) | |
2735 lhe = XEXTENT (Vlast_highlighted_extent); | |
2736 | |
2737 /* Now add all extents that overlap the character after POS and | |
2738 have a non-nil face. Also check if the character is invisible. */ | |
2739 for (i = 0; i < extent_list_num_els (sel); i++) | |
2740 { | |
2741 EXTENT e = extent_list_at (sel, i, 0); | |
2742 if (extent_end (e) > mempos) | |
2743 { | |
2744 Lisp_Object invis_prop = extent_invisible (e); | |
2745 | |
2746 if (!NILP (invis_prop)) | |
2747 { | |
2748 if (!BUFFERP (ef->object)) | |
2749 /* #### no `string-invisibility-spec' */ | |
2750 ef->invisible = 1; | |
2751 else | |
2752 { | |
2753 if (!ef->invisible_ellipses_already_displayed && | |
2754 EXTENT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS | |
2755 (XBUFFER (ef->object), invis_prop)) | |
2756 { | |
2757 ef->invisible = 1; | |
2758 ef->invisible_ellipses = 1; | |
2759 } | |
2760 else if (EXTENT_PROP_MEANS_INVISIBLE | |
2761 (XBUFFER (ef->object), invis_prop)) | |
2762 ef->invisible = 1; | |
2763 } | |
2764 } | |
2765 | |
2766 /* Remember that one of the extents in the list might be our | |
2767 dummy extent representing the highlighting that is | |
2768 attached to some other extent that is currently | |
2769 mouse-highlighted. When an extent is mouse-highlighted, | |
2770 it is as if there are two extents there, of potentially | |
2771 different priorities: the extent being highlighted, with | |
2772 whatever face and priority it has; and an ephemeral | |
2773 extent in the `mouse-face' face with | |
2774 `mouse-highlight-priority'. | |
2775 */ | |
2776 | |
2777 if (!NILP (extent_face (e))) | |
2778 Dynarr_add (ef->extents, e); | |
2779 if (e == lhe) | |
2780 { | |
2781 Lisp_Object f; | |
2782 /* zeroing isn't really necessary; we only deref `priority' | |
2783 and `face' */ | |
2784 xzero (dummy_lhe_extent); | |
2785 set_extent_priority (&dummy_lhe_extent, | |
2786 mouse_highlight_priority); | |
2787 /* Need to break up the following expression, due to an */ | |
2788 /* error in the Digital UNIX 3.2g C compiler (Digital */ | |
2789 /* UNIX Compiler Driver 3.11). */ | |
2790 f = extent_mouse_face (lhe); | |
2791 extent_face (&dummy_lhe_extent) = f; | |
2792 Dynarr_add (ef->extents, &dummy_lhe_extent); | |
2793 } | |
2794 /* since we are looping anyway, we might as well do this here */ | |
2795 if ((!NILP(extent_initial_redisplay_function (e))) && | |
2796 !extent_in_red_event_p(e)) | |
2797 { | |
2798 Lisp_Object function = extent_initial_redisplay_function (e); | |
2799 Lisp_Object obj; | |
2800 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2801 /* stderr_out ("initial redisplay function called!\n "); */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2802 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2803 /* debug_print (wrap_extent (e)); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2804 stderr_out ("\n"); */ |
428 | 2805 |
2806 /* FIXME: One should probably inhibit the displaying of | |
2807 this extent to reduce flicker */ | |
793 | 2808 extent_in_red_event_p (e) = 1; |
428 | 2809 |
2810 /* call the function */ | |
793 | 2811 obj = wrap_extent (e); |
2812 if (!NILP (function)) | |
2813 Fenqueue_eval_event (function, obj); | |
428 | 2814 } |
2815 } | |
2816 } | |
2817 | |
2818 extent_fragment_sort_by_priority (ef->extents); | |
2819 | |
2820 /* Now merge the faces together into a single face. The code to | |
2821 do this is in faces.c because it involves manipulating faces. */ | |
2822 return get_extent_fragment_face_cache_index (w, ef); | |
2823 } | |
2824 | |
2825 | |
2826 /************************************************************************/ | |
2827 /* extent-object methods */ | |
2828 /************************************************************************/ | |
2829 | |
2830 /* These are the basic helper functions for handling the allocation of | |
2831 extent objects. They are similar to the functions for other | |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
2832 frob-block objects. allocate_extent() is in alloc.c, not here. */ |
428 | 2833 |
2834 static Lisp_Object | |
2835 mark_extent (Lisp_Object obj) | |
2836 { | |
2837 struct extent *extent = XEXTENT (obj); | |
2838 | |
2839 mark_object (extent_object (extent)); | |
2840 mark_object (extent_no_chase_normal_field (extent, face)); | |
2841 return extent->plist; | |
2842 } | |
2843 | |
2844 static void | |
2286 | 2845 print_extent_1 (Lisp_Object obj, Lisp_Object printcharfun, |
2846 int UNUSED (escapeflag)) | |
428 | 2847 { |
2848 EXTENT ext = XEXTENT (obj); | |
2849 EXTENT anc = extent_ancestor (ext); | |
2850 Lisp_Object tail; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
2851 Ascbyte buf[64], *bp = buf; |
428 | 2852 |
2853 /* Retrieve the ancestor and use it, for faster retrieval of properties */ | |
2854 | |
2855 if (!NILP (extent_begin_glyph (anc))) *bp++ = '*'; | |
2856 *bp++ = (extent_start_open_p (anc) ? '(': '['); | |
2857 if (extent_detached_p (ext)) | |
2858 strcpy (bp, "detached"); | |
2859 else | |
826 | 2860 sprintf (bp, "%ld, %ld", |
819 | 2861 XINT (Fextent_start_position (obj)), |
2862 XINT (Fextent_end_position (obj))); | |
428 | 2863 bp += strlen (bp); |
2864 *bp++ = (extent_end_open_p (anc) ? ')': ']'); | |
2865 if (!NILP (extent_end_glyph (anc))) *bp++ = '*'; | |
2866 *bp++ = ' '; | |
2867 | |
2868 if (!NILP (extent_read_only (anc))) *bp++ = '%'; | |
2869 if (!NILP (extent_mouse_face (anc))) *bp++ = 'H'; | |
2870 if (extent_unique_p (anc)) *bp++ = 'U'; | |
2871 else if (extent_duplicable_p (anc)) *bp++ = 'D'; | |
2872 if (!NILP (extent_invisible (anc))) *bp++ = 'I'; | |
2873 | |
2874 if (!NILP (extent_read_only (anc)) || !NILP (extent_mouse_face (anc)) || | |
2875 extent_unique_p (anc) || | |
2876 extent_duplicable_p (anc) || !NILP (extent_invisible (anc))) | |
2877 *bp++ = ' '; | |
2878 *bp = '\0'; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
2879 write_ascstring (printcharfun, buf); |
428 | 2880 |
2881 tail = extent_plist_slot (anc); | |
2882 | |
2883 for (; !NILP (tail); tail = Fcdr (Fcdr (tail))) | |
2884 { | |
2885 Lisp_Object v = XCAR (XCDR (tail)); | |
2886 if (NILP (v)) continue; | |
800 | 2887 write_fmt_string_lisp (printcharfun, "%S ", 1, XCAR (tail)); |
428 | 2888 } |
2889 } | |
2890 | |
2891 static void | |
2892 print_extent (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
2893 { | |
2894 if (escapeflag) | |
2895 { | |
442 | 2896 const char *title = ""; |
2897 const char *name = ""; | |
2898 const char *posttitle = ""; | |
428 | 2899 Lisp_Object obj2 = Qnil; |
2900 | |
2901 /* Destroyed extents have 't' in the object field, causing | |
2500 | 2902 extent_object() to ABORT (maybe). */ |
428 | 2903 if (EXTENT_LIVE_P (XEXTENT (obj))) |
2904 obj2 = extent_object (XEXTENT (obj)); | |
2905 | |
2906 if (NILP (obj2)) | |
2907 title = "no buffer"; | |
2908 else if (BUFFERP (obj2)) | |
2909 { | |
2910 if (BUFFER_LIVE_P (XBUFFER (obj2))) | |
2911 { | |
2912 title = "buffer "; | |
2913 name = (char *) XSTRING_DATA (XBUFFER (obj2)->name); | |
2914 } | |
2915 else | |
2916 { | |
2917 title = "Killed Buffer"; | |
2918 name = ""; | |
2919 } | |
2920 } | |
2921 else | |
2922 { | |
2923 assert (STRINGP (obj2)); | |
2924 title = "string \""; | |
2925 posttitle = "\""; | |
2926 name = (char *) XSTRING_DATA (obj2); | |
2927 } | |
2928 | |
2929 if (print_readably) | |
2930 { | |
2931 if (!EXTENT_LIVE_P (XEXTENT (obj))) | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2932 printing_unreadable_object_fmt ("#<destroyed extent 0x%x>", |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2933 LISP_OBJECT_UID (obj)); |
428 | 2934 else |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2935 printing_unreadable_object_fmt ("#<extent 0x%x>", |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2936 LISP_OBJECT_UID (obj)); |
428 | 2937 } |
2938 | |
2939 if (!EXTENT_LIVE_P (XEXTENT (obj))) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
2940 write_ascstring (printcharfun, "#<destroyed extent"); |
428 | 2941 else |
2942 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
2943 write_ascstring (printcharfun, "#<extent "); |
428 | 2944 print_extent_1 (obj, printcharfun, escapeflag); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
2945 write_ascstring (printcharfun, extent_detached_p (XEXTENT (obj)) |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2946 ? "from " : "in "); |
800 | 2947 write_fmt_string (printcharfun, "%s%s%s", title, name, posttitle); |
428 | 2948 } |
2949 } | |
2950 else | |
2951 { | |
2952 if (print_readably) | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2953 printing_unreadable_object_fmt ("#<extent 0x%x>", |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2954 LISP_OBJECT_UID (obj)); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
2955 write_ascstring (printcharfun, "#<extent"); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
2956 } |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2957 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2958 write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj)); |
428 | 2959 } |
2960 | |
2961 static int | |
2962 properties_equal (EXTENT e1, EXTENT e2, int depth) | |
2963 { | |
2964 /* When this function is called, all indirections have been followed. | |
2965 Thus, the indirection checks in the various macros below will not | |
2966 amount to anything, and could be removed. However, the time | |
2967 savings would probably not be significant. */ | |
2968 if (!(EQ (extent_face (e1), extent_face (e2)) && | |
2969 extent_priority (e1) == extent_priority (e2) && | |
2970 internal_equal (extent_begin_glyph (e1), extent_begin_glyph (e2), | |
2971 depth + 1) && | |
2972 internal_equal (extent_end_glyph (e1), extent_end_glyph (e2), | |
2973 depth + 1))) | |
2974 return 0; | |
2975 | |
2976 /* compare the bit flags. */ | |
2977 { | |
2978 /* The has_aux field should not be relevant. */ | |
2979 int e1_has_aux = e1->flags.has_aux; | |
2980 int e2_has_aux = e2->flags.has_aux; | |
2981 int value; | |
2982 | |
2983 e1->flags.has_aux = e2->flags.has_aux = 0; | |
2984 value = memcmp (&e1->flags, &e2->flags, sizeof (e1->flags)); | |
2985 e1->flags.has_aux = e1_has_aux; | |
2986 e2->flags.has_aux = e2_has_aux; | |
2987 if (value) | |
2988 return 0; | |
2989 } | |
2990 | |
2991 /* compare the random elements of the plists. */ | |
2992 return !plists_differ (extent_no_chase_plist (e1), | |
2993 extent_no_chase_plist (e2), | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
2994 0, 0, depth + 1, 0); |
428 | 2995 } |
2996 | |
2997 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
2998 extent_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
2999 int UNUSED (foldcase)) |
428 | 3000 { |
3001 struct extent *e1 = XEXTENT (obj1); | |
3002 struct extent *e2 = XEXTENT (obj2); | |
3003 return | |
3004 (extent_start (e1) == extent_start (e2) && | |
3005 extent_end (e1) == extent_end (e2) && | |
3006 internal_equal (extent_object (e1), extent_object (e2), depth + 1) && | |
3007 properties_equal (extent_ancestor (e1), extent_ancestor (e2), | |
3008 depth)); | |
3009 } | |
3010 | |
665 | 3011 static Hashcode |
428 | 3012 extent_hash (Lisp_Object obj, int depth) |
3013 { | |
3014 struct extent *e = XEXTENT (obj); | |
3015 /* No need to hash all of the elements; that would take too long. | |
3016 Just hash the most common ones. */ | |
3017 return HASH3 (extent_start (e), extent_end (e), | |
3018 internal_hash (extent_object (e), depth + 1)); | |
3019 } | |
3020 | |
1204 | 3021 static const struct memory_description extent_description[] = { |
442 | 3022 { XD_LISP_OBJECT, offsetof (struct extent, object) }, |
3023 { XD_LISP_OBJECT, offsetof (struct extent, flags.face) }, | |
3024 { XD_LISP_OBJECT, offsetof (struct extent, plist) }, | |
3025 { XD_END } | |
3026 }; | |
3027 | |
428 | 3028 static Lisp_Object |
3029 extent_getprop (Lisp_Object obj, Lisp_Object prop) | |
3030 { | |
3031 return Fextent_property (obj, prop, Qunbound); | |
3032 } | |
3033 | |
3034 static int | |
3035 extent_putprop (Lisp_Object obj, Lisp_Object prop, Lisp_Object value) | |
3036 { | |
3037 Fset_extent_property (obj, prop, value); | |
3038 return 1; | |
3039 } | |
3040 | |
3041 static int | |
3042 extent_remprop (Lisp_Object obj, Lisp_Object prop) | |
3043 { | |
826 | 3044 Lisp_Object retval = Fset_extent_property (obj, prop, Qunbound); |
3045 if (UNBOUNDP (retval)) | |
3046 return -1; | |
3047 else if (!NILP (retval)) | |
3048 return 1; | |
3049 else | |
3050 return 0; | |
428 | 3051 } |
3052 | |
3053 static Lisp_Object | |
3054 extent_plist (Lisp_Object obj) | |
3055 { | |
3056 return Fextent_properties (obj); | |
3057 } | |
3058 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3059 DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT ("extent", extent, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3060 mark_extent, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3061 print_extent, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3062 /* NOTE: If you declare a |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3063 finalization method here, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3064 it will NOT be called. |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3065 Shaft city. */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3066 0, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3067 extent_equal, extent_hash, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3068 extent_description, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
3069 struct extent); |
428 | 3070 |
3071 /************************************************************************/ | |
3072 /* basic extent accessors */ | |
3073 /************************************************************************/ | |
3074 | |
3075 /* These functions are for checking externally-passed extent objects | |
3076 and returning an extent's basic properties, which include the | |
3077 buffer the extent is associated with, the endpoints of the extent's | |
3078 range, the open/closed-ness of those endpoints, and whether the | |
3079 extent is detached. Manipulating these properties requires | |
3080 manipulating the ordered lists that hold extents; thus, functions | |
3081 to do that are in a later section. */ | |
3082 | |
3083 /* Given a Lisp_Object that is supposed to be an extent, make sure it | |
3084 is OK and return an extent pointer. Extents can be in one of four | |
3085 states: | |
3086 | |
3087 1) destroyed | |
3088 2) detached and not associated with a buffer | |
3089 3) detached and associated with a buffer | |
3090 4) attached to a buffer | |
3091 | |
3092 If FLAGS is 0, types 2-4 are allowed. If FLAGS is DE_MUST_HAVE_BUFFER, | |
3093 types 3-4 are allowed. If FLAGS is DE_MUST_BE_ATTACHED, only type 4 | |
3094 is allowed. | |
3095 */ | |
3096 | |
3097 static EXTENT | |
3098 decode_extent (Lisp_Object extent_obj, unsigned int flags) | |
3099 { | |
3100 EXTENT extent; | |
3101 Lisp_Object obj; | |
3102 | |
3103 CHECK_LIVE_EXTENT (extent_obj); | |
3104 extent = XEXTENT (extent_obj); | |
3105 obj = extent_object (extent); | |
3106 | |
3107 /* the following condition will fail if we're dealing with a freed extent */ | |
3108 assert (NILP (obj) || BUFFERP (obj) || STRINGP (obj)); | |
3109 | |
3110 if (flags & DE_MUST_BE_ATTACHED) | |
3111 flags |= DE_MUST_HAVE_BUFFER; | |
3112 | |
3113 /* if buffer is dead, then convert extent to have no buffer. */ | |
3114 if (BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) | |
3115 obj = extent_object (extent) = Qnil; | |
3116 | |
3117 assert (!NILP (obj) || extent_detached_p (extent)); | |
3118 | |
3119 if ((NILP (obj) && (flags & DE_MUST_HAVE_BUFFER)) | |
3120 || (extent_detached_p (extent) && (flags & DE_MUST_BE_ATTACHED))) | |
3121 { | |
442 | 3122 invalid_argument ("extent doesn't belong to a buffer or string", |
3123 extent_obj); | |
428 | 3124 } |
3125 | |
3126 return extent; | |
3127 } | |
3128 | |
826 | 3129 /* Note that the returned value is a char position, not a byte position. */ |
428 | 3130 |
3131 static Lisp_Object | |
3132 extent_endpoint_external (Lisp_Object extent_obj, int endp) | |
3133 { | |
3134 EXTENT extent = decode_extent (extent_obj, 0); | |
3135 | |
3136 if (extent_detached_p (extent)) | |
3137 return Qnil; | |
3138 else | |
826 | 3139 return make_int (extent_endpoint_char (extent, endp)); |
428 | 3140 } |
3141 | |
3142 DEFUN ("extentp", Fextentp, 1, 1, 0, /* | |
3143 Return t if OBJECT is an extent. | |
3144 */ | |
3145 (object)) | |
3146 { | |
3147 return EXTENTP (object) ? Qt : Qnil; | |
3148 } | |
3149 | |
3150 DEFUN ("extent-live-p", Fextent_live_p, 1, 1, 0, /* | |
3151 Return t if OBJECT is an extent that has not been destroyed. | |
3152 */ | |
3153 (object)) | |
3154 { | |
3155 return EXTENTP (object) && EXTENT_LIVE_P (XEXTENT (object)) ? Qt : Qnil; | |
3156 } | |
3157 | |
3158 DEFUN ("extent-detached-p", Fextent_detached_p, 1, 1, 0, /* | |
3159 Return t if EXTENT is detached. | |
3160 */ | |
3161 (extent)) | |
3162 { | |
3163 return extent_detached_p (decode_extent (extent, 0)) ? Qt : Qnil; | |
3164 } | |
3165 | |
3166 DEFUN ("extent-object", Fextent_object, 1, 1, 0, /* | |
3167 Return object (buffer or string) that EXTENT refers to. | |
3168 */ | |
3169 (extent)) | |
3170 { | |
3171 return extent_object (decode_extent (extent, 0)); | |
3172 } | |
3173 | |
3174 DEFUN ("extent-start-position", Fextent_start_position, 1, 1, 0, /* | |
3175 Return start position of EXTENT, or nil if EXTENT is detached. | |
3176 */ | |
3177 (extent)) | |
3178 { | |
3179 return extent_endpoint_external (extent, 0); | |
3180 } | |
3181 | |
3182 DEFUN ("extent-end-position", Fextent_end_position, 1, 1, 0, /* | |
3183 Return end position of EXTENT, or nil if EXTENT is detached. | |
3184 */ | |
3185 (extent)) | |
3186 { | |
3187 return extent_endpoint_external (extent, 1); | |
3188 } | |
3189 | |
3190 DEFUN ("extent-length", Fextent_length, 1, 1, 0, /* | |
3191 Return length of EXTENT in characters. | |
3192 */ | |
3193 (extent)) | |
3194 { | |
3195 EXTENT e = decode_extent (extent, DE_MUST_BE_ATTACHED); | |
826 | 3196 return make_int (extent_endpoint_char (e, 1) |
3197 - extent_endpoint_char (e, 0)); | |
428 | 3198 } |
3199 | |
3200 DEFUN ("next-extent", Fnext_extent, 1, 1, 0, /* | |
3201 Find next extent after EXTENT. | |
3202 If EXTENT is a buffer return the first extent in the buffer; likewise | |
3203 for strings. | |
3204 Extents in a buffer are ordered in what is called the "display" | |
3205 order, which sorts by increasing start positions and then by *decreasing* | |
3206 end positions. | |
3207 If you want to perform an operation on a series of extents, use | |
3208 `map-extents' instead of this function; it is much more efficient. | |
3209 The primary use of this function should be to enumerate all the | |
3210 extents in a buffer. | |
3211 Note: The display order is not necessarily the order that `map-extents' | |
3212 processes extents in! | |
3213 */ | |
3214 (extent)) | |
3215 { | |
3216 EXTENT next; | |
3217 | |
3218 if (EXTENTP (extent)) | |
3219 next = extent_next (decode_extent (extent, DE_MUST_BE_ATTACHED)); | |
3220 else | |
3221 next = extent_first (decode_buffer_or_string (extent)); | |
3222 | |
3223 if (!next) | |
3224 return Qnil; | |
793 | 3225 return wrap_extent (next); |
428 | 3226 } |
3227 | |
3228 DEFUN ("previous-extent", Fprevious_extent, 1, 1, 0, /* | |
3229 Find last extent before EXTENT. | |
3230 If EXTENT is a buffer return the last extent in the buffer; likewise | |
3231 for strings. | |
3232 This function is analogous to `next-extent'. | |
3233 */ | |
3234 (extent)) | |
3235 { | |
3236 EXTENT prev; | |
3237 | |
3238 if (EXTENTP (extent)) | |
3239 prev = extent_previous (decode_extent (extent, DE_MUST_BE_ATTACHED)); | |
3240 else | |
3241 prev = extent_last (decode_buffer_or_string (extent)); | |
3242 | |
3243 if (!prev) | |
3244 return Qnil; | |
793 | 3245 return wrap_extent (prev); |
428 | 3246 } |
3247 | |
3248 #ifdef DEBUG_XEMACS | |
3249 | |
3250 DEFUN ("next-e-extent", Fnext_e_extent, 1, 1, 0, /* | |
3251 Find next extent after EXTENT using the "e" order. | |
3252 If EXTENT is a buffer return the first extent in the buffer; likewise | |
3253 for strings. | |
3254 */ | |
3255 (extent)) | |
3256 { | |
3257 EXTENT next; | |
3258 | |
3259 if (EXTENTP (extent)) | |
3260 next = extent_e_next (decode_extent (extent, DE_MUST_BE_ATTACHED)); | |
3261 else | |
3262 next = extent_e_first (decode_buffer_or_string (extent)); | |
3263 | |
3264 if (!next) | |
3265 return Qnil; | |
793 | 3266 return wrap_extent (next); |
428 | 3267 } |
3268 | |
3269 DEFUN ("previous-e-extent", Fprevious_e_extent, 1, 1, 0, /* | |
3270 Find last extent before EXTENT using the "e" order. | |
3271 If EXTENT is a buffer return the last extent in the buffer; likewise | |
3272 for strings. | |
3273 This function is analogous to `next-e-extent'. | |
3274 */ | |
3275 (extent)) | |
3276 { | |
3277 EXTENT prev; | |
3278 | |
3279 if (EXTENTP (extent)) | |
3280 prev = extent_e_previous (decode_extent (extent, DE_MUST_BE_ATTACHED)); | |
3281 else | |
3282 prev = extent_e_last (decode_buffer_or_string (extent)); | |
3283 | |
3284 if (!prev) | |
3285 return Qnil; | |
793 | 3286 return wrap_extent (prev); |
428 | 3287 } |
3288 | |
3289 #endif | |
3290 | |
3291 DEFUN ("next-extent-change", Fnext_extent_change, 1, 2, 0, /* | |
3292 Return the next position after POS where an extent begins or ends. | |
3293 If POS is at the end of the buffer or string, POS will be returned; | |
3294 otherwise a position greater than POS will always be returned. | |
444 | 3295 If OBJECT is nil, the current buffer is assumed. |
428 | 3296 */ |
3297 (pos, object)) | |
3298 { | |
3299 Lisp_Object obj = decode_buffer_or_string (object); | |
826 | 3300 Bytexpos xpos; |
3301 | |
3302 xpos = get_buffer_or_string_pos_byte (obj, pos, GB_ALLOW_PAST_ACCESSIBLE); | |
3303 xpos = extent_find_end_of_run (obj, xpos, 1); | |
3304 return make_int (buffer_or_string_bytexpos_to_charxpos (obj, xpos)); | |
428 | 3305 } |
3306 | |
3307 DEFUN ("previous-extent-change", Fprevious_extent_change, 1, 2, 0, /* | |
3308 Return the last position before POS where an extent begins or ends. | |
3309 If POS is at the beginning of the buffer or string, POS will be returned; | |
3310 otherwise a position less than POS will always be returned. | |
3311 If OBJECT is nil, the current buffer is assumed. | |
3312 */ | |
3313 (pos, object)) | |
3314 { | |
3315 Lisp_Object obj = decode_buffer_or_string (object); | |
826 | 3316 Bytexpos xpos; |
3317 | |
3318 xpos = get_buffer_or_string_pos_byte (obj, pos, GB_ALLOW_PAST_ACCESSIBLE); | |
3319 xpos = extent_find_beginning_of_run (obj, xpos, 1); | |
3320 return make_int (buffer_or_string_bytexpos_to_charxpos (obj, xpos)); | |
428 | 3321 } |
3322 | |
3323 | |
3324 /************************************************************************/ | |
3325 /* parent and children stuff */ | |
3326 /************************************************************************/ | |
3327 | |
3328 DEFUN ("extent-parent", Fextent_parent, 1, 1, 0, /* | |
3329 Return the parent (if any) of EXTENT. | |
3330 If an extent has a parent, it derives all its properties from that extent | |
3331 and has no properties of its own. (The only "properties" that the | |
3332 extent keeps are the buffer/string it refers to and the start and end | |
3333 points.) It is possible for an extent's parent to itself have a parent. | |
3334 */ | |
3335 (extent)) | |
3336 /* do I win the prize for the strangest split infinitive? */ | |
3337 { | |
3338 EXTENT e = decode_extent (extent, 0); | |
3339 return extent_parent (e); | |
3340 } | |
3341 | |
3342 DEFUN ("extent-children", Fextent_children, 1, 1, 0, /* | |
3343 Return a list of the children (if any) of EXTENT. | |
3344 The children of an extent are all those extents whose parent is that extent. | |
3345 This function does not recursively trace children of children. | |
3346 \(To do that, use `extent-descendants'.) | |
3347 */ | |
3348 (extent)) | |
3349 { | |
3350 EXTENT e = decode_extent (extent, 0); | |
3351 Lisp_Object children = extent_children (e); | |
3352 | |
3353 if (!NILP (children)) | |
3354 return Fcopy_sequence (XWEAK_LIST_LIST (children)); | |
3355 else | |
3356 return Qnil; | |
3357 } | |
3358 | |
3359 static void | |
3360 remove_extent_from_children_list (EXTENT e, Lisp_Object child) | |
3361 { | |
3362 Lisp_Object children = extent_children (e); | |
3363 | |
3364 #ifdef ERROR_CHECK_EXTENTS | |
3365 assert (!NILP (memq_no_quit (child, XWEAK_LIST_LIST (children)))); | |
3366 #endif | |
3367 XWEAK_LIST_LIST (children) = | |
3368 delq_no_quit (child, XWEAK_LIST_LIST (children)); | |
3369 } | |
3370 | |
3371 static void | |
3372 add_extent_to_children_list (EXTENT e, Lisp_Object child) | |
3373 { | |
3374 Lisp_Object children = extent_children (e); | |
3375 | |
3376 if (NILP (children)) | |
3377 { | |
3378 children = make_weak_list (WEAK_LIST_SIMPLE); | |
3379 set_extent_no_chase_aux_field (e, children, children); | |
3380 } | |
3381 | |
3382 #ifdef ERROR_CHECK_EXTENTS | |
3383 assert (NILP (memq_no_quit (child, XWEAK_LIST_LIST (children)))); | |
3384 #endif | |
3385 XWEAK_LIST_LIST (children) = Fcons (child, XWEAK_LIST_LIST (children)); | |
3386 } | |
3387 | |
826 | 3388 |
3389 static int | |
3390 compare_key_value_pairs (const void *humpty, const void *dumpty) | |
3391 { | |
3392 Lisp_Object_pair *foo = (Lisp_Object_pair *) humpty; | |
3393 Lisp_Object_pair *bar = (Lisp_Object_pair *) dumpty; | |
3394 if (EQ (foo->key, bar->key)) | |
3395 return 0; | |
3396 return !NILP (Fstring_lessp (foo->key, bar->key)) ? -1 : 1; | |
3397 } | |
3398 | |
428 | 3399 DEFUN ("set-extent-parent", Fset_extent_parent, 2, 2, 0, /* |
3400 Set the parent of EXTENT to PARENT (may be nil). | |
3401 See `extent-parent'. | |
3402 */ | |
3403 (extent, parent)) | |
3404 { | |
3405 EXTENT e = decode_extent (extent, 0); | |
3406 Lisp_Object cur_parent = extent_parent (e); | |
3407 Lisp_Object rest; | |
3408 | |
793 | 3409 extent = wrap_extent (e); |
428 | 3410 if (!NILP (parent)) |
3411 CHECK_LIVE_EXTENT (parent); | |
3412 if (EQ (parent, cur_parent)) | |
3413 return Qnil; | |
3414 for (rest = parent; !NILP (rest); rest = extent_parent (XEXTENT (rest))) | |
3415 if (EQ (rest, extent)) | |
563 | 3416 signal_error (Qinvalid_change, |
442 | 3417 "Circular parent chain would result", |
3418 extent); | |
428 | 3419 if (NILP (parent)) |
3420 { | |
3421 remove_extent_from_children_list (XEXTENT (cur_parent), extent); | |
3422 set_extent_no_chase_aux_field (e, parent, Qnil); | |
3423 e->flags.has_parent = 0; | |
3424 } | |
3425 else | |
3426 { | |
3427 add_extent_to_children_list (XEXTENT (parent), extent); | |
3428 set_extent_no_chase_aux_field (e, parent, parent); | |
3429 e->flags.has_parent = 1; | |
3430 } | |
3431 /* changing the parent also changes the properties of all children. */ | |
3432 { | |
826 | 3433 Lisp_Object_pair_dynarr *oldprops, *newprops; |
3434 int i, orignewlength; | |
3435 | |
3436 /* perhaps there's a smarter way, but the following will work, | |
3437 and it's O(N*log N): | |
3438 | |
3439 (1) get the old props. | |
3440 (2) get the new props. | |
3441 (3) sort both. | |
3442 (4) loop through old props; if key not in new, add it, with value | |
3443 Qunbound. | |
3444 (5) vice-versa for new props. | |
3445 (6) sort both again. | |
3446 (7) now we have identical lists of keys; we run through and compare | |
3447 the values. | |
3448 | |
3449 Of course in reality the number of properties will be low, so | |
3450 an N^2 algorithm wouldn't be a problem, but the stuff below is just | |
3451 as easy to write given the existence of qsort and bsearch. | |
3452 */ | |
3453 | |
3454 oldprops = Dynarr_new (Lisp_Object_pair); | |
3455 newprops = Dynarr_new (Lisp_Object_pair); | |
3456 if (!NILP (cur_parent)) | |
3457 extent_properties (XEXTENT (cur_parent), oldprops); | |
3458 if (!NILP (parent)) | |
3459 extent_properties (XEXTENT (parent), newprops); | |
3460 | |
4967 | 3461 qsort (Dynarr_begin (oldprops), Dynarr_length (oldprops), |
826 | 3462 sizeof (Lisp_Object_pair), compare_key_value_pairs); |
4967 | 3463 qsort (Dynarr_begin (newprops), Dynarr_length (newprops), |
826 | 3464 sizeof (Lisp_Object_pair), compare_key_value_pairs); |
3465 orignewlength = Dynarr_length (newprops); | |
3466 for (i = 0; i < Dynarr_length (oldprops); i++) | |
3467 { | |
4967 | 3468 if (!bsearch (Dynarr_atp (oldprops, i), Dynarr_begin (newprops), |
826 | 3469 Dynarr_length (newprops), sizeof (Lisp_Object_pair), |
3470 compare_key_value_pairs)) | |
3471 { | |
3025 | 3472 Lisp_Object_pair new_; |
3473 new_.key = Dynarr_at (oldprops, i).key; | |
3474 new_.value = Qunbound; | |
3475 Dynarr_add (newprops, new_); | |
826 | 3476 } |
3477 } | |
3478 for (i = 0; i < orignewlength; i++) | |
3479 { | |
859 | 3480 if (!Dynarr_length (oldprops) || !bsearch (Dynarr_atp (newprops, i), |
4967 | 3481 Dynarr_begin (oldprops), |
859 | 3482 Dynarr_length (oldprops), |
3483 sizeof (Lisp_Object_pair), | |
3484 compare_key_value_pairs)) | |
826 | 3485 { |
3025 | 3486 Lisp_Object_pair new_; |
3487 new_.key = Dynarr_at (newprops, i).key; | |
3488 new_.value = Qunbound; | |
3489 Dynarr_add (oldprops, new_); | |
826 | 3490 } |
3491 } | |
4967 | 3492 qsort (Dynarr_begin (oldprops), Dynarr_length (oldprops), |
826 | 3493 sizeof (Lisp_Object_pair), compare_key_value_pairs); |
4967 | 3494 qsort (Dynarr_begin (newprops), Dynarr_length (newprops), |
826 | 3495 sizeof (Lisp_Object_pair), compare_key_value_pairs); |
3496 for (i = 0; i < Dynarr_length (oldprops); i++) | |
3497 { | |
3498 assert (EQ (Dynarr_at (oldprops, i).key, Dynarr_at (newprops, i).key)); | |
3499 if (!EQ (Dynarr_at (oldprops, i).value, Dynarr_at (newprops, i).value)) | |
3500 signal_extent_property_changed (e, Dynarr_at (oldprops, i).key, 1); | |
3501 } | |
3502 | |
3503 Dynarr_free (oldprops); | |
3504 Dynarr_free (newprops); | |
3505 #if 0 | |
3506 { | |
428 | 3507 int old_invis = (!NILP (cur_parent) && |
3508 !NILP (extent_invisible (XEXTENT (cur_parent)))); | |
3509 int new_invis = (!NILP (parent) && | |
3510 !NILP (extent_invisible (XEXTENT (parent)))); | |
3511 | |
3512 extent_maybe_changed_for_redisplay (e, 1, new_invis != old_invis); | |
3513 } | |
826 | 3514 #endif /* 0 */ |
3515 } | |
428 | 3516 return Qnil; |
3517 } | |
3518 | |
3519 | |
3520 /************************************************************************/ | |
3521 /* basic extent mutators */ | |
3522 /************************************************************************/ | |
3523 | |
3524 /* Note: If you track non-duplicable extents by undo, you'll get bogus | |
3525 undo records for transient extents via update-extent. | |
3526 For example, query-replace will do this. | |
3527 */ | |
3528 | |
3529 static void | |
826 | 3530 set_extent_endpoints_1 (EXTENT extent, Memxpos start, Memxpos end) |
428 | 3531 { |
3532 #ifdef ERROR_CHECK_EXTENTS | |
3533 Lisp_Object obj = extent_object (extent); | |
3534 | |
3535 assert (start <= end); | |
3536 if (BUFFERP (obj)) | |
3537 { | |
665 | 3538 assert (valid_membpos_p (XBUFFER (obj), start)); |
3539 assert (valid_membpos_p (XBUFFER (obj), end)); | |
428 | 3540 } |
3541 #endif | |
3542 | |
3543 /* Optimization: if the extent is already where we want it to be, | |
3544 do nothing. */ | |
3545 if (!extent_detached_p (extent) && extent_start (extent) == start && | |
3546 extent_end (extent) == end) | |
3547 return; | |
3548 | |
3549 if (extent_detached_p (extent)) | |
3550 { | |
3551 if (extent_duplicable_p (extent)) | |
3552 { | |
793 | 3553 Lisp_Object extent_obj = wrap_extent (extent); |
3554 | |
428 | 3555 record_extent (extent_obj, 1); |
3556 } | |
3557 } | |
3558 else | |
3559 extent_detach (extent); | |
3560 | |
3561 set_extent_start (extent, start); | |
3562 set_extent_end (extent, end); | |
3563 extent_attach (extent); | |
3564 } | |
3565 | |
3566 /* Set extent's endpoints to S and E, and put extent in buffer or string | |
3567 OBJECT. (If OBJECT is nil, do not change the extent's object.) */ | |
3568 | |
3569 void | |
826 | 3570 set_extent_endpoints (EXTENT extent, Bytexpos s, Bytexpos e, |
3571 Lisp_Object object) | |
3572 { | |
3573 Memxpos start, end; | |
428 | 3574 |
3575 if (NILP (object)) | |
3576 { | |
3577 object = extent_object (extent); | |
3578 assert (!NILP (object)); | |
3579 } | |
3580 else if (!EQ (object, extent_object (extent))) | |
3581 { | |
3582 extent_detach (extent); | |
3583 extent_object (extent) = object; | |
3584 } | |
3585 | |
3586 start = s < 0 ? extent_start (extent) : | |
826 | 3587 buffer_or_string_bytexpos_to_memxpos (object, s); |
428 | 3588 end = e < 0 ? extent_end (extent) : |
826 | 3589 buffer_or_string_bytexpos_to_memxpos (object, e); |
428 | 3590 set_extent_endpoints_1 (extent, start, end); |
3591 } | |
3592 | |
3593 static void | |
3594 set_extent_openness (EXTENT extent, int start_open, int end_open) | |
3595 { | |
3596 if (start_open != -1) | |
826 | 3597 { |
3598 extent_start_open_p (extent) = start_open; | |
3599 signal_extent_property_changed (extent, Qstart_open, 1); | |
3600 } | |
428 | 3601 if (end_open != -1) |
826 | 3602 { |
3603 extent_end_open_p (extent) = end_open; | |
3604 signal_extent_property_changed (extent, Qend_open, 1); | |
3605 } | |
428 | 3606 } |
3607 | |
3608 static EXTENT | |
826 | 3609 make_extent (Lisp_Object object, Bytexpos from, Bytexpos to) |
428 | 3610 { |
3611 EXTENT extent; | |
3612 | |
3613 extent = make_extent_detached (object); | |
3614 set_extent_endpoints (extent, from, to, Qnil); | |
3615 return extent; | |
3616 } | |
3617 | |
826 | 3618 /* Copy ORIGINAL, changing it to span FROM,TO in OBJECT. */ |
3619 | |
428 | 3620 static EXTENT |
826 | 3621 copy_extent (EXTENT original, Bytexpos from, Bytexpos to, Lisp_Object object) |
428 | 3622 { |
3623 EXTENT e; | |
3624 | |
3625 e = make_extent_detached (object); | |
3626 if (from >= 0) | |
3627 set_extent_endpoints (e, from, to, Qnil); | |
3628 | |
3629 e->plist = Fcopy_sequence (original->plist); | |
3630 memcpy (&e->flags, &original->flags, sizeof (e->flags)); | |
3631 if (e->flags.has_aux) | |
3632 { | |
3633 /* also need to copy the aux struct. It won't work for | |
3634 this extent to share the same aux struct as the original | |
3635 one. */ | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3636 Lisp_Object ea = ALLOC_NORMAL_LISP_OBJECT (extent_auxiliary); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3637 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3638 copy_lisp_object (ea, XCAR (original->plist)); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
3639 XCAR (e->plist) = ea; |
428 | 3640 } |
3641 | |
3642 { | |
3643 /* we may have just added another child to the parent extent. */ | |
3644 Lisp_Object parent = extent_parent (e); | |
3645 if (!NILP (parent)) | |
3646 { | |
793 | 3647 Lisp_Object extent = wrap_extent (e); |
3648 | |
428 | 3649 add_extent_to_children_list (XEXTENT (parent), extent); |
3650 } | |
3651 } | |
3652 | |
3653 return e; | |
3654 } | |
3655 | |
3656 static void | |
3657 destroy_extent (EXTENT extent) | |
3658 { | |
3659 Lisp_Object rest, nextrest, children; | |
3660 Lisp_Object extent_obj; | |
3661 | |
3662 if (!extent_detached_p (extent)) | |
3663 extent_detach (extent); | |
3664 /* disassociate the extent from its children and parent */ | |
3665 children = extent_children (extent); | |
3666 if (!NILP (children)) | |
3667 { | |
3668 LIST_LOOP_DELETING (rest, nextrest, XWEAK_LIST_LIST (children)) | |
3669 Fset_extent_parent (XCAR (rest), Qnil); | |
3670 } | |
793 | 3671 extent_obj = wrap_extent (extent); |
428 | 3672 Fset_extent_parent (extent_obj, Qnil); |
3673 /* mark the extent as destroyed */ | |
3674 extent_object (extent) = Qt; | |
3675 } | |
3676 | |
3677 DEFUN ("make-extent", Fmake_extent, 2, 3, 0, /* | |
3678 Make an extent for the range [FROM, TO) in BUFFER-OR-STRING. | |
3679 BUFFER-OR-STRING defaults to the current buffer. Insertions at point | |
3680 TO will be outside of the extent; insertions at FROM will be inside the | |
3681 extent, causing the extent to grow. (This is the same way that markers | |
3682 behave.) You can change the behavior of insertions at the endpoints | |
3683 using `set-extent-property'. The extent is initially detached if both | |
3684 FROM and TO are nil, and in this case BUFFER-OR-STRING defaults to nil, | |
3685 meaning the extent is in no buffer and no string. | |
3686 */ | |
3687 (from, to, buffer_or_string)) | |
3688 { | |
3689 Lisp_Object extent_obj; | |
3690 Lisp_Object obj; | |
3691 | |
3692 obj = decode_buffer_or_string (buffer_or_string); | |
3693 if (NILP (from) && NILP (to)) | |
3694 { | |
3695 if (NILP (buffer_or_string)) | |
3696 obj = Qnil; | |
793 | 3697 extent_obj = wrap_extent (make_extent_detached (obj)); |
428 | 3698 } |
3699 else | |
3700 { | |
826 | 3701 Bytexpos start, end; |
428 | 3702 |
3703 get_buffer_or_string_range_byte (obj, from, to, &start, &end, | |
3704 GB_ALLOW_PAST_ACCESSIBLE); | |
826 | 3705 extent_obj = wrap_extent (make_extent (obj, start, end)); |
428 | 3706 } |
3707 return extent_obj; | |
3708 } | |
3709 | |
3710 DEFUN ("copy-extent", Fcopy_extent, 1, 2, 0, /* | |
3711 Make a copy of EXTENT. It is initially detached. | |
3712 Optional argument BUFFER-OR-STRING defaults to EXTENT's buffer or string. | |
3713 */ | |
3714 (extent, buffer_or_string)) | |
3715 { | |
3716 EXTENT ext = decode_extent (extent, 0); | |
3717 | |
3718 if (NILP (buffer_or_string)) | |
3719 buffer_or_string = extent_object (ext); | |
3720 else | |
3721 buffer_or_string = decode_buffer_or_string (buffer_or_string); | |
3722 | |
793 | 3723 return wrap_extent (copy_extent (ext, -1, -1, buffer_or_string)); |
428 | 3724 } |
3725 | |
3726 DEFUN ("delete-extent", Fdelete_extent, 1, 1, 0, /* | |
3727 Remove EXTENT from its buffer and destroy it. | |
3728 This does not modify the buffer's text, only its display properties. | |
3729 The extent cannot be used thereafter. | |
3730 */ | |
3731 (extent)) | |
3732 { | |
3733 EXTENT ext; | |
3734 | |
3735 /* We do not call decode_extent() here because already-destroyed | |
3736 extents are OK. */ | |
3737 CHECK_EXTENT (extent); | |
3738 ext = XEXTENT (extent); | |
3739 | |
3740 if (!EXTENT_LIVE_P (ext)) | |
3741 return Qnil; | |
3742 destroy_extent (ext); | |
3743 return Qnil; | |
3744 } | |
3745 | |
3746 DEFUN ("detach-extent", Fdetach_extent, 1, 1, 0, /* | |
3747 Remove EXTENT from its buffer in such a way that it can be re-inserted. | |
3748 An extent is also detached when all of its characters are all killed by a | |
3749 deletion, unless its `detachable' property has been unset. | |
3750 | |
3751 Extents which have the `duplicable' attribute are tracked by the undo | |
3752 mechanism. Detachment via `detach-extent' and string deletion is recorded, | |
3753 as is attachment via `insert-extent' and string insertion. Extent motion, | |
3754 face changes, and attachment via `make-extent' and `set-extent-endpoints' | |
3755 are not recorded. This means that extent changes which are to be undo-able | |
3756 must be performed by character editing, or by insertion and detachment of | |
3757 duplicable extents. | |
3758 */ | |
3759 (extent)) | |
3760 { | |
3761 EXTENT ext = decode_extent (extent, 0); | |
3762 | |
3763 if (extent_detached_p (ext)) | |
3764 return extent; | |
3765 if (extent_duplicable_p (ext)) | |
3766 record_extent (extent, 0); | |
3767 extent_detach (ext); | |
3768 | |
3769 return extent; | |
3770 } | |
3771 | |
3772 DEFUN ("set-extent-endpoints", Fset_extent_endpoints, 3, 4, 0, /* | |
3773 Set the endpoints of EXTENT to START, END. | |
3774 If START and END are null, call detach-extent on EXTENT. | |
3775 BUFFER-OR-STRING specifies the new buffer or string that the extent should | |
3776 be in, and defaults to EXTENT's buffer or string. (If nil, and EXTENT | |
3777 is in no buffer and no string, it defaults to the current buffer.) | |
3778 See documentation on `detach-extent' for a discussion of undo recording. | |
3779 */ | |
3780 (extent, start, end, buffer_or_string)) | |
3781 { | |
3782 EXTENT ext; | |
826 | 3783 Bytexpos s, e; |
428 | 3784 |
3785 ext = decode_extent (extent, 0); | |
3786 | |
3787 if (NILP (buffer_or_string)) | |
3788 { | |
3789 buffer_or_string = extent_object (ext); | |
3790 if (NILP (buffer_or_string)) | |
3791 buffer_or_string = Fcurrent_buffer (); | |
3792 } | |
3793 else | |
3794 buffer_or_string = decode_buffer_or_string (buffer_or_string); | |
3795 | |
3796 if (NILP (start) && NILP (end)) | |
3797 return Fdetach_extent (extent); | |
3798 | |
3799 get_buffer_or_string_range_byte (buffer_or_string, start, end, &s, &e, | |
3800 GB_ALLOW_PAST_ACCESSIBLE); | |
3801 | |
468 | 3802 buffer_or_string_extent_info_force (buffer_or_string); |
428 | 3803 set_extent_endpoints (ext, s, e, buffer_or_string); |
3804 return extent; | |
3805 } | |
3806 | |
3807 | |
3808 /************************************************************************/ | |
3809 /* mapping over extents */ | |
3810 /************************************************************************/ | |
3811 | |
3812 static unsigned int | |
3813 decode_map_extents_flags (Lisp_Object flags) | |
3814 { | |
3815 unsigned int retval = 0; | |
3816 unsigned int all_extents_specified = 0; | |
3817 unsigned int in_region_specified = 0; | |
3818 | |
3819 if (EQ (flags, Qt)) /* obsoleteness compatibility */ | |
3820 return ME_END_CLOSED; | |
3821 if (NILP (flags)) | |
3822 return 0; | |
3823 if (SYMBOLP (flags)) | |
3824 flags = Fcons (flags, Qnil); | |
3825 while (!NILP (flags)) | |
3826 { | |
3827 Lisp_Object sym; | |
3828 CHECK_CONS (flags); | |
3829 sym = XCAR (flags); | |
3830 CHECK_SYMBOL (sym); | |
3831 if (EQ (sym, Qall_extents_closed) || EQ (sym, Qall_extents_open) || | |
3832 EQ (sym, Qall_extents_closed_open) || | |
3833 EQ (sym, Qall_extents_open_closed)) | |
3834 { | |
3835 if (all_extents_specified) | |
563 | 3836 invalid_argument ("Only one `all-extents-*' flag may be specified", Qunbound); |
428 | 3837 all_extents_specified = 1; |
3838 } | |
3839 if (EQ (sym, Qstart_in_region) || EQ (sym, Qend_in_region) || | |
3840 EQ (sym, Qstart_and_end_in_region) || | |
3841 EQ (sym, Qstart_or_end_in_region)) | |
3842 { | |
3843 if (in_region_specified) | |
563 | 3844 invalid_argument ("Only one `*-in-region' flag may be specified", Qunbound); |
428 | 3845 in_region_specified = 1; |
3846 } | |
3847 | |
3848 /* I do so love that conditional operator ... */ | |
3849 retval |= | |
3850 EQ (sym, Qend_closed) ? ME_END_CLOSED : | |
3851 EQ (sym, Qstart_open) ? ME_START_OPEN : | |
3852 EQ (sym, Qall_extents_closed) ? ME_ALL_EXTENTS_CLOSED : | |
3853 EQ (sym, Qall_extents_open) ? ME_ALL_EXTENTS_OPEN : | |
3854 EQ (sym, Qall_extents_closed_open) ? ME_ALL_EXTENTS_CLOSED_OPEN : | |
3855 EQ (sym, Qall_extents_open_closed) ? ME_ALL_EXTENTS_OPEN_CLOSED : | |
3856 EQ (sym, Qstart_in_region) ? ME_START_IN_REGION : | |
3857 EQ (sym, Qend_in_region) ? ME_END_IN_REGION : | |
3858 EQ (sym, Qstart_and_end_in_region) ? ME_START_AND_END_IN_REGION : | |
3859 EQ (sym, Qstart_or_end_in_region) ? ME_START_OR_END_IN_REGION : | |
3860 EQ (sym, Qnegate_in_region) ? ME_NEGATE_IN_REGION : | |
563 | 3861 (invalid_constant ("Invalid `map-extents' flag", sym), 0); |
428 | 3862 |
3863 flags = XCDR (flags); | |
3864 } | |
3865 return retval; | |
3866 } | |
3867 | |
3868 DEFUN ("extent-in-region-p", Fextent_in_region_p, 1, 4, 0, /* | |
3869 Return whether EXTENT overlaps a specified region. | |
3870 This is equivalent to whether `map-extents' would visit EXTENT when called | |
3871 with these args. | |
3872 */ | |
3873 (extent, from, to, flags)) | |
3874 { | |
826 | 3875 Bytexpos start, end; |
428 | 3876 EXTENT ext = decode_extent (extent, DE_MUST_BE_ATTACHED); |
3877 Lisp_Object obj = extent_object (ext); | |
3878 | |
3879 get_buffer_or_string_range_byte (obj, from, to, &start, &end, GB_ALLOW_NIL | | |
3880 GB_ALLOW_PAST_ACCESSIBLE); | |
3881 | |
3882 return extent_in_region_p (ext, start, end, decode_map_extents_flags (flags)) ? | |
3883 Qt : Qnil; | |
3884 } | |
3885 | |
3886 struct slow_map_extents_arg | |
3887 { | |
3888 Lisp_Object map_arg; | |
3889 Lisp_Object map_routine; | |
3890 Lisp_Object result; | |
3891 Lisp_Object property; | |
3892 Lisp_Object value; | |
3893 }; | |
3894 | |
3895 static int | |
3896 slow_map_extents_function (EXTENT extent, void *arg) | |
3897 { | |
3898 /* This function can GC */ | |
3899 struct slow_map_extents_arg *closure = (struct slow_map_extents_arg *) arg; | |
793 | 3900 Lisp_Object extent_obj = wrap_extent (extent); |
3901 | |
428 | 3902 |
3903 /* make sure this extent qualifies according to the PROPERTY | |
3904 and VALUE args */ | |
3905 | |
3906 if (!NILP (closure->property)) | |
3907 { | |
3908 Lisp_Object value = Fextent_property (extent_obj, closure->property, | |
3909 Qnil); | |
3910 if ((NILP (closure->value) && NILP (value)) || | |
3911 (!NILP (closure->value) && !EQ (value, closure->value))) | |
3912 return 0; | |
3913 } | |
3914 | |
3915 closure->result = call2 (closure->map_routine, extent_obj, | |
3916 closure->map_arg); | |
3917 return !NILP (closure->result); | |
3918 } | |
3919 | |
3920 DEFUN ("map-extents", Fmap_extents, 1, 8, 0, /* | |
3921 Map FUNCTION over the extents which overlap a region in OBJECT. | |
3922 OBJECT is normally a buffer or string but could be an extent (see below). | |
3923 The region is normally bounded by [FROM, TO) (i.e. the beginning of the | |
3924 region is closed and the end of the region is open), but this can be | |
3925 changed with the FLAGS argument (see below for a complete discussion). | |
3926 | |
3927 FUNCTION is called with the arguments (extent, MAPARG). The arguments | |
3928 OBJECT, FROM, TO, MAPARG, and FLAGS are all optional and default to | |
3929 the current buffer, the beginning of OBJECT, the end of OBJECT, nil, | |
3930 and nil, respectively. `map-extents' returns the first non-nil result | |
3931 produced by FUNCTION, and no more calls to FUNCTION are made after it | |
3932 returns non-nil. | |
3933 | |
3934 If OBJECT is an extent, FROM and TO default to the extent's endpoints, | |
3935 and the mapping omits that extent and its predecessors. This feature | |
3936 supports restarting a loop based on `map-extents'. Note: OBJECT must | |
3937 be attached to a buffer or string, and the mapping is done over that | |
3938 buffer or string. | |
3939 | |
3940 An extent overlaps the region if there is any point in the extent that is | |
3941 also in the region. (For the purpose of overlap, zero-length extents and | |
3942 regions are treated as closed on both ends regardless of their endpoints' | |
3943 specified open/closedness.) Note that the endpoints of an extent or region | |
3944 are considered to be in that extent or region if and only if the | |
3945 corresponding end is closed. For example, the extent [5,7] overlaps the | |
3946 region [2,5] because 5 is in both the extent and the region. However, (5,7] | |
3947 does not overlap [2,5] because 5 is not in the extent, and neither [5,7] nor | |
3948 \(5,7] overlaps the region [2,5) because 5 is not in the region. | |
3949 | |
3950 The optional FLAGS can be a symbol or a list of one or more symbols, | |
3951 modifying the behavior of `map-extents'. Allowed symbols are: | |
3952 | |
3953 end-closed The region's end is closed. | |
3954 | |
3955 start-open The region's start is open. | |
3956 | |
3957 all-extents-closed Treat all extents as closed on both ends for the | |
3958 purpose of determining whether they overlap the | |
3959 region, irrespective of their actual open- or | |
3960 closedness. | |
3961 all-extents-open Treat all extents as open on both ends. | |
3962 all-extents-closed-open Treat all extents as start-closed, end-open. | |
3963 all-extents-open-closed Treat all extents as start-open, end-closed. | |
3964 | |
3965 start-in-region In addition to the above conditions for extent | |
3966 overlap, the extent's start position must lie within | |
3967 the specified region. Note that, for this | |
3968 condition, open start positions are treated as if | |
3969 0.5 was added to the endpoint's value, and open | |
3970 end positions are treated as if 0.5 was subtracted | |
3971 from the endpoint's value. | |
3972 end-in-region The extent's end position must lie within the | |
3973 region. | |
3974 start-and-end-in-region Both the extent's start and end positions must lie | |
3975 within the region. | |
3976 start-or-end-in-region Either the extent's start or end position must lie | |
3977 within the region. | |
3978 | |
3979 negate-in-region The condition specified by a `*-in-region' flag | |
3980 must NOT hold for the extent to be considered. | |
3981 | |
3982 | |
3983 At most one of `all-extents-closed', `all-extents-open', | |
3984 `all-extents-closed-open', and `all-extents-open-closed' may be specified. | |
3985 | |
3986 At most one of `start-in-region', `end-in-region', | |
3987 `start-and-end-in-region', and `start-or-end-in-region' may be specified. | |
3988 | |
3989 If optional arg PROPERTY is non-nil, only extents with that property set | |
3990 on them will be visited. If optional arg VALUE is non-nil, only extents | |
3991 whose value for that property is `eq' to VALUE will be visited. | |
3992 */ | |
3993 (function, object, from, to, maparg, flags, property, value)) | |
3994 { | |
3995 /* This function can GC */ | |
3996 struct slow_map_extents_arg closure; | |
3997 unsigned int me_flags; | |
826 | 3998 Bytexpos start, end; |
428 | 3999 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
4000 EXTENT after = 0; | |
4001 | |
4002 if (EXTENTP (object)) | |
4003 { | |
4004 after = decode_extent (object, DE_MUST_BE_ATTACHED); | |
4005 if (NILP (from)) | |
4006 from = Fextent_start_position (object); | |
4007 if (NILP (to)) | |
4008 to = Fextent_end_position (object); | |
4009 object = extent_object (after); | |
4010 } | |
4011 else | |
4012 object = decode_buffer_or_string (object); | |
4013 | |
4014 get_buffer_or_string_range_byte (object, from, to, &start, &end, | |
4015 GB_ALLOW_NIL | GB_ALLOW_PAST_ACCESSIBLE); | |
4016 | |
4017 me_flags = decode_map_extents_flags (flags); | |
4018 | |
4019 if (!NILP (property)) | |
4020 { | |
4021 if (!NILP (value)) | |
4022 value = canonicalize_extent_property (property, value); | |
4023 } | |
4024 | |
4025 GCPRO5 (function, maparg, object, property, value); | |
4026 | |
4027 closure.map_arg = maparg; | |
4028 closure.map_routine = function; | |
4029 closure.result = Qnil; | |
4030 closure.property = property; | |
4031 closure.value = value; | |
4032 | |
826 | 4033 map_extents (start, end, slow_map_extents_function, |
4034 (void *) &closure, object, after, | |
4035 /* You never know what the user might do ... */ | |
4036 me_flags | ME_MIGHT_CALL_ELISP); | |
428 | 4037 |
4038 UNGCPRO; | |
4039 return closure.result; | |
4040 } | |
4041 | |
4042 | |
4043 /************************************************************************/ | |
4044 /* mapping over extents -- other functions */ | |
4045 /************************************************************************/ | |
4046 | |
4047 /* ------------------------------- */ | |
4048 /* map-extent-children */ | |
4049 /* ------------------------------- */ | |
4050 | |
4051 struct slow_map_extent_children_arg | |
4052 { | |
4053 Lisp_Object map_arg; | |
4054 Lisp_Object map_routine; | |
4055 Lisp_Object result; | |
4056 Lisp_Object property; | |
4057 Lisp_Object value; | |
826 | 4058 Bytexpos start_min; |
4059 Bytexpos prev_start; | |
4060 Bytexpos prev_end; | |
428 | 4061 }; |
4062 | |
4063 static int | |
4064 slow_map_extent_children_function (EXTENT extent, void *arg) | |
4065 { | |
4066 /* This function can GC */ | |
4067 struct slow_map_extent_children_arg *closure = | |
4068 (struct slow_map_extent_children_arg *) arg; | |
4069 Lisp_Object extent_obj; | |
826 | 4070 Bytexpos start = extent_endpoint_byte (extent, 0); |
4071 Bytexpos end = extent_endpoint_byte (extent, 1); | |
428 | 4072 /* Make sure the extent starts inside the region of interest, |
4073 rather than just overlaps it. | |
4074 */ | |
4075 if (start < closure->start_min) | |
4076 return 0; | |
4077 /* Make sure the extent is not a child of a previous visited one. | |
4078 We know already, because of extent ordering, | |
4079 that start >= prev_start, and that if | |
4080 start == prev_start, then end <= prev_end. | |
4081 */ | |
4082 if (start == closure->prev_start) | |
4083 { | |
4084 if (end < closure->prev_end) | |
4085 return 0; | |
4086 } | |
4087 else /* start > prev_start */ | |
4088 { | |
4089 if (start < closure->prev_end) | |
4090 return 0; | |
4091 /* corner case: prev_end can be -1 if there is no prev */ | |
4092 } | |
793 | 4093 extent_obj = wrap_extent (extent); |
428 | 4094 |
4095 /* make sure this extent qualifies according to the PROPERTY | |
4096 and VALUE args */ | |
4097 | |
4098 if (!NILP (closure->property)) | |
4099 { | |
4100 Lisp_Object value = Fextent_property (extent_obj, closure->property, | |
4101 Qnil); | |
4102 if ((NILP (closure->value) && NILP (value)) || | |
4103 (!NILP (closure->value) && !EQ (value, closure->value))) | |
4104 return 0; | |
4105 } | |
4106 | |
4107 closure->result = call2 (closure->map_routine, extent_obj, | |
4108 closure->map_arg); | |
4109 | |
4110 /* Since the callback may change the buffer, compute all stored | |
4111 buffer positions here. | |
4112 */ | |
4113 closure->start_min = -1; /* no need for this any more */ | |
826 | 4114 closure->prev_start = extent_endpoint_byte (extent, 0); |
4115 closure->prev_end = extent_endpoint_byte (extent, 1); | |
428 | 4116 |
4117 return !NILP (closure->result); | |
4118 } | |
4119 | |
4120 DEFUN ("map-extent-children", Fmap_extent_children, 1, 8, 0, /* | |
4121 Map FUNCTION over the extents in the region from FROM to TO. | |
4122 FUNCTION is called with arguments (extent, MAPARG). See `map-extents' | |
4123 for a full discussion of the arguments FROM, TO, and FLAGS. | |
4124 | |
4125 The arguments are the same as for `map-extents', but this function differs | |
4126 in that it only visits extents which start in the given region, and also | |
4127 in that, after visiting an extent E, it skips all other extents which start | |
4128 inside E but end before E's end. | |
4129 | |
4130 Thus, this function may be used to walk a tree of extents in a buffer: | |
4131 (defun walk-extents (buffer &optional ignore) | |
4132 (map-extent-children 'walk-extents buffer)) | |
4133 */ | |
4134 (function, object, from, to, maparg, flags, property, value)) | |
4135 { | |
4136 /* This function can GC */ | |
4137 struct slow_map_extent_children_arg closure; | |
4138 unsigned int me_flags; | |
826 | 4139 Bytexpos start, end; |
428 | 4140 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
4141 EXTENT after = 0; | |
4142 | |
4143 if (EXTENTP (object)) | |
4144 { | |
4145 after = decode_extent (object, DE_MUST_BE_ATTACHED); | |
4146 if (NILP (from)) | |
4147 from = Fextent_start_position (object); | |
4148 if (NILP (to)) | |
4149 to = Fextent_end_position (object); | |
4150 object = extent_object (after); | |
4151 } | |
4152 else | |
4153 object = decode_buffer_or_string (object); | |
4154 | |
4155 get_buffer_or_string_range_byte (object, from, to, &start, &end, | |
4156 GB_ALLOW_NIL | GB_ALLOW_PAST_ACCESSIBLE); | |
4157 | |
4158 me_flags = decode_map_extents_flags (flags); | |
4159 | |
4160 if (!NILP (property)) | |
4161 { | |
4162 if (!NILP (value)) | |
4163 value = canonicalize_extent_property (property, value); | |
4164 } | |
4165 | |
4166 GCPRO5 (function, maparg, object, property, value); | |
4167 | |
4168 closure.map_arg = maparg; | |
4169 closure.map_routine = function; | |
4170 closure.result = Qnil; | |
4171 closure.property = property; | |
4172 closure.value = value; | |
4173 closure.start_min = start; | |
4174 closure.prev_start = -1; | |
4175 closure.prev_end = -1; | |
826 | 4176 map_extents (start, end, slow_map_extent_children_function, |
4177 (void *) &closure, object, after, | |
4178 /* You never know what the user might do ... */ | |
4179 me_flags | ME_MIGHT_CALL_ELISP); | |
428 | 4180 |
4181 UNGCPRO; | |
4182 return closure.result; | |
4183 } | |
4184 | |
4185 /* ------------------------------- */ | |
4186 /* extent-at */ | |
4187 /* ------------------------------- */ | |
4188 | |
4189 /* find "smallest" matching extent containing pos -- (flag == 0) means | |
4190 all extents match, else (EXTENT_FLAGS (extent) & flag) must be true; | |
4191 for more than one matching extent with precisely the same endpoints, | |
4192 we choose the last extent in the extents_list. | |
4193 The search stops just before "before", if that is non-null. | |
4194 */ | |
4195 | |
4196 struct extent_at_arg | |
4197 { | |
442 | 4198 Lisp_Object best_match; /* or list of extents */ |
826 | 4199 Memxpos best_start; |
4200 Memxpos best_end; | |
428 | 4201 Lisp_Object prop; |
4202 EXTENT before; | |
442 | 4203 int all_extents; |
428 | 4204 }; |
4205 | |
4206 static enum extent_at_flag | |
4207 decode_extent_at_flag (Lisp_Object at_flag) | |
4208 { | |
4209 if (NILP (at_flag)) | |
4210 return EXTENT_AT_AFTER; | |
4211 | |
4212 CHECK_SYMBOL (at_flag); | |
4213 if (EQ (at_flag, Qafter)) return EXTENT_AT_AFTER; | |
4214 if (EQ (at_flag, Qbefore)) return EXTENT_AT_BEFORE; | |
4215 if (EQ (at_flag, Qat)) return EXTENT_AT_AT; | |
4216 | |
563 | 4217 invalid_constant ("Invalid AT-FLAG in `extent-at'", at_flag); |
1204 | 4218 RETURN_NOT_REACHED (EXTENT_AT_AFTER); |
428 | 4219 } |
4220 | |
4221 static int | |
4222 extent_at_mapper (EXTENT e, void *arg) | |
4223 { | |
4224 struct extent_at_arg *closure = (struct extent_at_arg *) arg; | |
4225 | |
4226 if (e == closure->before) | |
4227 return 1; | |
4228 | |
4229 /* If closure->prop is non-nil, then the extent is only acceptable | |
4230 if it has a non-nil value for that property. */ | |
4231 if (!NILP (closure->prop)) | |
4232 { | |
793 | 4233 Lisp_Object extent = wrap_extent (e); |
4234 | |
428 | 4235 if (NILP (Fextent_property (extent, closure->prop, Qnil))) |
4236 return 0; | |
4237 } | |
4238 | |
442 | 4239 if (!closure->all_extents) |
428 | 4240 { |
442 | 4241 EXTENT current; |
4242 | |
4243 if (NILP (closure->best_match)) | |
428 | 4244 goto accept; |
442 | 4245 current = XEXTENT (closure->best_match); |
428 | 4246 /* redundant but quick test */ |
442 | 4247 if (extent_start (current) > extent_start (e)) |
428 | 4248 return 0; |
4249 | |
4250 /* we return the "last" best fit, instead of the first -- | |
4251 this is because then the glyph closest to two equivalent | |
4252 extents corresponds to the "extent-at" the text just past | |
4253 that same glyph */ | |
4254 else if (!EXTENT_LESS_VALS (e, closure->best_start, | |
4255 closure->best_end)) | |
4256 goto accept; | |
4257 else | |
4258 return 0; | |
4259 accept: | |
793 | 4260 closure->best_match = wrap_extent (e); |
428 | 4261 closure->best_start = extent_start (e); |
4262 closure->best_end = extent_end (e); | |
4263 } | |
442 | 4264 else |
4265 { | |
793 | 4266 Lisp_Object extent = wrap_extent (e); |
4267 | |
442 | 4268 closure->best_match = Fcons (extent, closure->best_match); |
4269 } | |
428 | 4270 |
4271 return 0; | |
4272 } | |
4273 | |
826 | 4274 Lisp_Object |
4275 extent_at (Bytexpos position, Lisp_Object object, | |
4276 Lisp_Object property, EXTENT before, | |
4277 enum extent_at_flag at_flag, int all_extents) | |
428 | 4278 { |
4279 struct extent_at_arg closure; | |
442 | 4280 struct gcpro gcpro1; |
428 | 4281 |
4282 /* it might be argued that invalid positions should cause | |
4283 errors, but the principle of least surprise dictates that | |
4284 nil should be returned (extent-at is often used in | |
4285 response to a mouse event, and in many cases previous events | |
4286 have changed the buffer contents). | |
4287 | |
4288 Also, the openness stuff in the text-property code currently | |
4289 does not check its limits and might go off the end. */ | |
4290 if ((at_flag == EXTENT_AT_BEFORE | |
4291 ? position <= buffer_or_string_absolute_begin_byte (object) | |
4292 : position < buffer_or_string_absolute_begin_byte (object)) | |
4293 || (at_flag == EXTENT_AT_AFTER | |
4294 ? position >= buffer_or_string_absolute_end_byte (object) | |
4295 : position > buffer_or_string_absolute_end_byte (object))) | |
4296 return Qnil; | |
4297 | |
442 | 4298 closure.best_match = Qnil; |
428 | 4299 closure.prop = property; |
4300 closure.before = before; | |
442 | 4301 closure.all_extents = all_extents; |
4302 | |
4303 GCPRO1 (closure.best_match); | |
826 | 4304 map_extents (at_flag == EXTENT_AT_BEFORE ? prev_bytexpos (object, position) : |
4305 position, | |
4306 at_flag == EXTENT_AT_AFTER ? next_bytexpos (object, position) : | |
4307 position, | |
4308 extent_at_mapper, (void *) &closure, object, 0, | |
4309 ME_START_OPEN | ME_ALL_EXTENTS_CLOSED); | |
442 | 4310 if (all_extents) |
4311 closure.best_match = Fnreverse (closure.best_match); | |
4312 UNGCPRO; | |
4313 | |
4314 return closure.best_match; | |
428 | 4315 } |
4316 | |
4317 DEFUN ("extent-at", Fextent_at, 1, 5, 0, /* | |
4318 Find "smallest" extent at POS in OBJECT having PROPERTY set. | |
4319 Normally, an extent is "at" POS if it overlaps the region (POS, POS+1); | |
4320 i.e. if it covers the character after POS. (However, see the definition | |
4321 of AT-FLAG.) "Smallest" means the extent that comes last in the display | |
4322 order; this normally means the extent whose start position is closest to | |
4323 POS. See `next-extent' for more information. | |
4324 OBJECT specifies a buffer or string and defaults to the current buffer. | |
4325 PROPERTY defaults to nil, meaning that any extent will do. | |
4326 Properties are attached to extents with `set-extent-property', which see. | |
4327 Returns nil if POS is invalid or there is no matching extent at POS. | |
4328 If the fourth argument BEFORE is not nil, it must be an extent; any returned | |
4329 extent will precede that extent. This feature allows `extent-at' to be | |
4330 used by a loop over extents. | |
4331 AT-FLAG controls how end cases are handled, and should be one of: | |
4332 | |
4333 nil or `after' An extent is at POS if it covers the character | |
4334 after POS. This is consistent with the way | |
4335 that text properties work. | |
4336 `before' An extent is at POS if it covers the character | |
4337 before POS. | |
4338 `at' An extent is at POS if it overlaps or abuts POS. | |
4339 This includes all zero-length extents at POS. | |
4340 | |
4341 Note that in all cases, the start-openness and end-openness of the extents | |
4342 considered is ignored. If you want to pay attention to those properties, | |
4343 you should use `map-extents', which gives you more control. | |
4344 */ | |
4345 (pos, object, property, before, at_flag)) | |
4346 { | |
826 | 4347 Bytexpos position; |
428 | 4348 EXTENT before_extent; |
4349 enum extent_at_flag fl; | |
4350 | |
4351 object = decode_buffer_or_string (object); | |
4352 position = get_buffer_or_string_pos_byte (object, pos, GB_NO_ERROR_IF_BAD); | |
4353 if (NILP (before)) | |
4354 before_extent = 0; | |
4355 else | |
4356 before_extent = decode_extent (before, DE_MUST_BE_ATTACHED); | |
4357 if (before_extent && !EQ (object, extent_object (before_extent))) | |
442 | 4358 invalid_argument ("extent not in specified buffer or string", object); |
428 | 4359 fl = decode_extent_at_flag (at_flag); |
4360 | |
826 | 4361 return extent_at (position, object, property, before_extent, fl, 0); |
442 | 4362 } |
4363 | |
4364 DEFUN ("extents-at", Fextents_at, 1, 5, 0, /* | |
4365 Find all extents at POS in OBJECT having PROPERTY set. | |
4366 Normally, an extent is "at" POS if it overlaps the region (POS, POS+1); | |
4367 i.e. if it covers the character after POS. (However, see the definition | |
4368 of AT-FLAG.) | |
4369 This provides similar functionality to `extent-list', but does so in a way | |
4370 that is compatible with `extent-at'. (For example, errors due to POS out of | |
4371 range are ignored; this makes it safer to use this function in response to | |
4372 a mouse event, because in many cases previous events have changed the buffer | |
4373 contents.) | |
4374 OBJECT specifies a buffer or string and defaults to the current buffer. | |
4375 PROPERTY defaults to nil, meaning that any extent will do. | |
4376 Properties are attached to extents with `set-extent-property', which see. | |
4377 Returns nil if POS is invalid or there is no matching extent at POS. | |
4378 If the fourth argument BEFORE is not nil, it must be an extent; any returned | |
4379 extent will precede that extent. This feature allows `extents-at' to be | |
4380 used by a loop over extents. | |
4381 AT-FLAG controls how end cases are handled, and should be one of: | |
4382 | |
4383 nil or `after' An extent is at POS if it covers the character | |
4384 after POS. This is consistent with the way | |
4385 that text properties work. | |
4386 `before' An extent is at POS if it covers the character | |
4387 before POS. | |
4388 `at' An extent is at POS if it overlaps or abuts POS. | |
4389 This includes all zero-length extents at POS. | |
4390 | |
4391 Note that in all cases, the start-openness and end-openness of the extents | |
4392 considered is ignored. If you want to pay attention to those properties, | |
4393 you should use `map-extents', which gives you more control. | |
4394 */ | |
4395 (pos, object, property, before, at_flag)) | |
4396 { | |
826 | 4397 Bytexpos position; |
442 | 4398 EXTENT before_extent; |
4399 enum extent_at_flag fl; | |
4400 | |
4401 object = decode_buffer_or_string (object); | |
4402 position = get_buffer_or_string_pos_byte (object, pos, GB_NO_ERROR_IF_BAD); | |
4403 if (NILP (before)) | |
4404 before_extent = 0; | |
4405 else | |
4406 before_extent = decode_extent (before, DE_MUST_BE_ATTACHED); | |
4407 if (before_extent && !EQ (object, extent_object (before_extent))) | |
4408 invalid_argument ("extent not in specified buffer or string", object); | |
4409 fl = decode_extent_at_flag (at_flag); | |
4410 | |
826 | 4411 return extent_at (position, object, property, before_extent, fl, 1); |
428 | 4412 } |
4413 | |
4414 /* ------------------------------- */ | |
4415 /* verify_extent_modification() */ | |
4416 /* ------------------------------- */ | |
4417 | |
4418 /* verify_extent_modification() is called when a buffer or string is | |
4419 modified to check whether the modification is occuring inside a | |
4420 read-only extent. | |
4421 */ | |
4422 | |
4423 struct verify_extents_arg | |
4424 { | |
4425 Lisp_Object object; | |
826 | 4426 Memxpos start; |
4427 Memxpos end; | |
428 | 4428 Lisp_Object iro; /* value of inhibit-read-only */ |
4429 }; | |
4430 | |
4431 static int | |
4432 verify_extent_mapper (EXTENT extent, void *arg) | |
4433 { | |
4434 struct verify_extents_arg *closure = (struct verify_extents_arg *) arg; | |
4435 Lisp_Object prop = extent_read_only (extent); | |
4436 | |
4437 if (NILP (prop)) | |
4438 return 0; | |
4439 | |
4440 if (CONSP (closure->iro) && !NILP (Fmemq (prop, closure->iro))) | |
4441 return 0; | |
4442 | |
4443 #if 0 /* Nobody seems to care for this any more -sb */ | |
4444 /* Allow deletion if the extent is completely contained in | |
4445 the region being deleted. | |
4446 This is important for supporting tokens which are internally | |
4447 write-protected, but which can be killed and yanked as a whole. | |
4448 Ignore open/closed distinctions at this point. | |
4449 -- Rose | |
4450 */ | |
4451 if (closure->start != closure->end && | |
4452 extent_start (extent) >= closure->start && | |
4453 extent_end (extent) <= closure->end) | |
4454 return 0; | |
4455 #endif | |
4456 | |
4457 while (1) | |
4458 Fsignal (Qbuffer_read_only, (list1 (closure->object))); | |
4459 | |
1204 | 4460 RETURN_NOT_REACHED(0); |
428 | 4461 } |
4462 | |
4463 /* Value of Vinhibit_read_only is precomputed and passed in for | |
4464 efficiency */ | |
4465 | |
4466 void | |
826 | 4467 verify_extent_modification (Lisp_Object object, Bytexpos from, Bytexpos to, |
428 | 4468 Lisp_Object inhibit_read_only_value) |
4469 { | |
4470 int closed; | |
4471 struct verify_extents_arg closure; | |
4472 | |
4473 /* If insertion, visit closed-endpoint extents touching the insertion | |
4474 point because the text would go inside those extents. If deletion, | |
4475 treat the range as open on both ends so that touching extents are not | |
4476 visited. Note that we assume that an insertion is occurring if the | |
4477 changed range has zero length, and a deletion otherwise. This | |
4478 fails if a change (i.e. non-insertion, non-deletion) is happening. | |
4479 As far as I know, this doesn't currently occur in XEmacs. --ben */ | |
4480 closed = (from==to); | |
4481 closure.object = object; | |
826 | 4482 closure.start = buffer_or_string_bytexpos_to_memxpos (object, from); |
4483 closure.end = buffer_or_string_bytexpos_to_memxpos (object, to); | |
428 | 4484 closure.iro = inhibit_read_only_value; |
4485 | |
826 | 4486 map_extents (from, to, verify_extent_mapper, (void *) &closure, |
4487 object, 0, closed ? ME_END_CLOSED : ME_START_OPEN); | |
428 | 4488 } |
4489 | |
4490 /* ------------------------------------ */ | |
4491 /* process_extents_for_insertion() */ | |
4492 /* ------------------------------------ */ | |
4493 | |
4494 struct process_extents_for_insertion_arg | |
4495 { | |
826 | 4496 Bytexpos opoint; |
428 | 4497 int length; |
4498 Lisp_Object object; | |
4499 }; | |
4500 | |
4501 /* A region of length LENGTH was just inserted at OPOINT. Modify all | |
4502 of the extents as required for the insertion, based on their | |
4503 start-open/end-open properties. | |
4504 */ | |
4505 | |
4506 static int | |
4507 process_extents_for_insertion_mapper (EXTENT extent, void *arg) | |
4508 { | |
4509 struct process_extents_for_insertion_arg *closure = | |
4510 (struct process_extents_for_insertion_arg *) arg; | |
826 | 4511 Memxpos indice = buffer_or_string_bytexpos_to_memxpos (closure->object, |
4512 closure->opoint); | |
428 | 4513 |
4514 /* When this function is called, one end of the newly-inserted text should | |
4515 be adjacent to some endpoint of the extent, or disjoint from it. If | |
4516 the insertion overlaps any existing extent, something is wrong. | |
4517 */ | |
4518 #ifdef ERROR_CHECK_EXTENTS | |
5053
0e803dc6f096
fix to assert in extents.c, so `make check' works
Ben Wing <ben@xemacs.org>
parents:
5050
diff
changeset
|
4519 assert (extent_start (extent) <= indice || extent_start (extent) >= indice + closure->length); |
0e803dc6f096
fix to assert in extents.c, so `make check' works
Ben Wing <ben@xemacs.org>
parents:
5050
diff
changeset
|
4520 assert (extent_end (extent) <= indice || extent_end (extent) >= indice + closure->length); |
428 | 4521 #endif |
4522 | |
4523 /* The extent-adjustment code adjusted the extent's endpoints as if | |
468 | 4524 all extents were closed-open -- endpoints at the insertion point |
4525 remain unchanged. We need to fix the other kinds of extents: | |
4526 | |
4527 1. Start position of start-open extents needs to be moved. | |
4528 | |
4529 2. End position of end-closed extents needs to be moved. | |
4530 | |
4531 Note that both conditions hold for zero-length (] extents at the | |
4532 insertion point. But under these rules, zero-length () extents | |
4533 would get adjusted such that their start is greater than their | |
4534 end; instead of allowing that, we treat them as [) extents by | |
4535 modifying condition #1 to not fire nothing when dealing with a | |
4536 zero-length open-open extent. | |
4537 | |
4538 Existence of zero-length open-open extents is unfortunately an | |
4539 inelegant part of the extent model, but there is no way around | |
4540 it. */ | |
428 | 4541 |
4542 { | |
826 | 4543 Memxpos new_start = extent_start (extent); |
4544 Memxpos new_end = extent_end (extent); | |
468 | 4545 |
4546 if (indice == extent_start (extent) && extent_start_open_p (extent) | |
4547 /* zero-length () extents are exempt; see comment above. */ | |
4548 && !(new_start == new_end && extent_end_open_p (extent)) | |
4549 ) | |
428 | 4550 new_start += closure->length; |
4551 if (indice == extent_end (extent) && !extent_end_open_p (extent)) | |
4552 new_end += closure->length; | |
468 | 4553 |
428 | 4554 set_extent_endpoints_1 (extent, new_start, new_end); |
4555 } | |
4556 | |
4557 return 0; | |
4558 } | |
4559 | |
4560 void | |
826 | 4561 process_extents_for_insertion (Lisp_Object object, Bytexpos opoint, |
428 | 4562 Bytecount length) |
4563 { | |
4564 struct process_extents_for_insertion_arg closure; | |
4565 | |
4566 closure.opoint = opoint; | |
4567 closure.length = length; | |
4568 closure.object = object; | |
4569 | |
826 | 4570 map_extents (opoint, opoint + length, |
4571 process_extents_for_insertion_mapper, | |
4572 (void *) &closure, object, 0, | |
4573 ME_END_CLOSED | ME_MIGHT_MODIFY_EXTENTS | | |
4574 ME_INCLUDE_INTERNAL); | |
428 | 4575 } |
4576 | |
4577 /* ------------------------------------ */ | |
4578 /* process_extents_for_deletion() */ | |
4579 /* ------------------------------------ */ | |
4580 | |
4581 struct process_extents_for_deletion_arg | |
4582 { | |
826 | 4583 Memxpos start, end; |
428 | 4584 int destroy_included_extents; |
4585 }; | |
4586 | |
4587 /* This function is called when we're about to delete the range [from, to]. | |
4588 Detach all of the extents that are completely inside the range [from, to], | |
4589 if they're detachable or open-open. */ | |
4590 | |
4591 static int | |
4592 process_extents_for_deletion_mapper (EXTENT extent, void *arg) | |
4593 { | |
4594 struct process_extents_for_deletion_arg *closure = | |
4595 (struct process_extents_for_deletion_arg *) arg; | |
4596 | |
4597 /* If the extent lies completely within the range that | |
4598 is being deleted, then nuke the extent if it's detachable | |
4599 (otherwise, it will become a zero-length extent). */ | |
4600 | |
4601 if (closure->start <= extent_start (extent) && | |
4602 extent_end (extent) <= closure->end) | |
4603 { | |
4604 if (extent_detachable_p (extent)) | |
4605 { | |
4606 if (closure->destroy_included_extents) | |
4607 destroy_extent (extent); | |
4608 else | |
4609 extent_detach (extent); | |
4610 } | |
4611 } | |
4612 | |
4613 return 0; | |
4614 } | |
4615 | |
4616 /* DESTROY_THEM means destroy the extents instead of just deleting them. | |
4617 It is unused currently, but perhaps might be used (there used to | |
4618 be a function process_extents_for_destruction(), #if 0'd out, | |
4619 that did the equivalent). */ | |
4620 void | |
826 | 4621 process_extents_for_deletion (Lisp_Object object, Bytexpos from, |
4622 Bytexpos to, int destroy_them) | |
428 | 4623 { |
4624 struct process_extents_for_deletion_arg closure; | |
4625 | |
826 | 4626 closure.start = buffer_or_string_bytexpos_to_memxpos (object, from); |
4627 closure.end = buffer_or_string_bytexpos_to_memxpos (object, to); | |
428 | 4628 closure.destroy_included_extents = destroy_them; |
4629 | |
826 | 4630 map_extents (from, to, process_extents_for_deletion_mapper, |
4631 (void *) &closure, object, 0, | |
4632 ME_END_CLOSED | ME_MIGHT_MODIFY_EXTENTS); | |
428 | 4633 } |
4634 | |
4635 /* ------------------------------- */ | |
4636 /* report_extent_modification() */ | |
4637 /* ------------------------------- */ | |
826 | 4638 |
4639 struct report_extent_modification_closure | |
4640 { | |
428 | 4641 Lisp_Object buffer; |
826 | 4642 Charxpos start, end; |
428 | 4643 int afterp; |
4644 int speccount; | |
4645 }; | |
4646 | |
4647 static Lisp_Object | |
4648 report_extent_modification_restore (Lisp_Object buffer) | |
4649 { | |
4650 if (current_buffer != XBUFFER (buffer)) | |
4651 Fset_buffer (buffer); | |
4652 return Qnil; | |
4653 } | |
4654 | |
4655 static int | |
4656 report_extent_modification_mapper (EXTENT extent, void *arg) | |
4657 { | |
4658 struct report_extent_modification_closure *closure = | |
4659 (struct report_extent_modification_closure *)arg; | |
4660 Lisp_Object exobj, startobj, endobj; | |
4661 Lisp_Object hook = (closure->afterp | |
4662 ? extent_after_change_functions (extent) | |
4663 : extent_before_change_functions (extent)); | |
4664 if (NILP (hook)) | |
4665 return 0; | |
4666 | |
793 | 4667 exobj = wrap_extent (extent); |
4668 startobj = make_int (closure->start); | |
4669 endobj = make_int (closure->end); | |
428 | 4670 |
4671 /* Now that we are sure to call elisp, set up an unwind-protect so | |
4672 inside_change_hook gets restored in case we throw. Also record | |
4673 the current buffer, in case we change it. Do the recording only | |
438 | 4674 once. |
4675 | |
4676 One confusing thing here is that our caller never actually calls | |
771 | 4677 unbind_to (closure.speccount). This is because |
826 | 4678 map_extents() unbinds before, and with a smaller |
771 | 4679 speccount. The additional unbind_to_1() in |
438 | 4680 report_extent_modification() would cause XEmacs to abort. */ |
428 | 4681 if (closure->speccount == -1) |
4682 { | |
4683 closure->speccount = specpdl_depth (); | |
4684 record_unwind_protect (report_extent_modification_restore, | |
4685 Fcurrent_buffer ()); | |
4686 } | |
4687 | |
4688 /* The functions will expect closure->buffer to be the current | |
4689 buffer, so change it if it isn't. */ | |
4690 if (current_buffer != XBUFFER (closure->buffer)) | |
4691 Fset_buffer (closure->buffer); | |
4692 | |
4693 /* #### It's a shame that we can't use any of the existing run_hook* | |
4694 functions here. This is so because all of them work with | |
4695 symbols, to be able to retrieve default values of local hooks. | |
438 | 4696 <sigh> |
4697 | |
4698 #### Idea: we could set up a dummy symbol, and call the hook | |
4699 functions on *that*. */ | |
428 | 4700 |
4701 if (!CONSP (hook) || EQ (XCAR (hook), Qlambda)) | |
4702 call3 (hook, exobj, startobj, endobj); | |
4703 else | |
4704 { | |
2367 | 4705 EXTERNAL_LIST_LOOP_2 (elt, hook) |
438 | 4706 /* #### Shouldn't this perform the same Fset_buffer() check as |
4707 above? */ | |
2367 | 4708 call3 (elt, exobj, startobj, endobj); |
428 | 4709 } |
4710 return 0; | |
4711 } | |
4712 | |
4713 void | |
665 | 4714 report_extent_modification (Lisp_Object buffer, Charbpos start, Charbpos end, |
438 | 4715 int afterp) |
428 | 4716 { |
4717 struct report_extent_modification_closure closure; | |
4718 | |
4719 closure.buffer = buffer; | |
4720 closure.start = start; | |
4721 closure.end = end; | |
4722 closure.afterp = afterp; | |
4723 closure.speccount = -1; | |
4724 | |
826 | 4725 map_extents (charbpos_to_bytebpos (XBUFFER (buffer), start), |
4726 charbpos_to_bytebpos (XBUFFER (buffer), end), | |
4727 report_extent_modification_mapper, (void *)&closure, | |
428 | 4728 buffer, NULL, ME_MIGHT_CALL_ELISP); |
4729 } | |
4730 | |
4731 | |
4732 /************************************************************************/ | |
4733 /* extent properties */ | |
4734 /************************************************************************/ | |
4735 | |
4736 static void | |
4737 set_extent_invisible (EXTENT extent, Lisp_Object value) | |
4738 { | |
4739 if (!EQ (extent_invisible (extent), value)) | |
4740 { | |
4741 set_extent_invisible_1 (extent, value); | |
826 | 4742 signal_extent_property_changed (extent, Qinvisible, 1); |
428 | 4743 } |
4744 } | |
4745 | |
4746 /* This function does "memoization" -- similar to the interning | |
4747 that happens with symbols. Given a list of faces, an equivalent | |
4748 list is returned such that if this function is called twice with | |
4749 input that is `equal', the resulting outputs will be `eq'. | |
4750 | |
4751 Note that the inputs and outputs are in general *not* `equal' -- | |
4752 faces in symbol form become actual face objects in the output. | |
4753 This is necessary so that temporary faces stay around. */ | |
4754 | |
4755 static Lisp_Object | |
4756 memoize_extent_face_internal (Lisp_Object list) | |
4757 { | |
4758 int len; | |
4759 int thelen; | |
4760 Lisp_Object cons, thecons; | |
4761 Lisp_Object oldtail, tail; | |
4762 struct gcpro gcpro1; | |
4763 | |
4764 if (NILP (list)) | |
4765 return Qnil; | |
4766 if (!CONSP (list)) | |
4767 return Fget_face (list); | |
4768 | |
4769 /* To do the memoization, we use a hash table mapping from | |
4770 external lists to internal lists. We do `equal' comparisons | |
4771 on the keys so the memoization works correctly. | |
4772 | |
4773 Note that we canonicalize things so that the keys in the | |
4774 hash table (the external lists) always contain symbols and | |
4775 the values (the internal lists) always contain face objects. | |
4776 | |
4777 We also maintain a "reverse" table that maps from the internal | |
4778 lists to the external equivalents. The idea here is twofold: | |
4779 | |
4780 1) `extent-face' wants to return a list containing face symbols | |
4781 rather than face objects. | |
4782 2) We don't want things to get quite so messed up if the user | |
4783 maliciously side-effects the returned lists. | |
4784 */ | |
4785 | |
4786 len = XINT (Flength (list)); | |
4787 thelen = XINT (Flength (Vextent_face_reusable_list)); | |
4788 oldtail = Qnil; | |
4789 tail = Qnil; | |
4790 GCPRO1 (oldtail); | |
4791 | |
4792 /* We canonicalize the given list into another list. | |
4793 We try to avoid consing except when necessary, so we have | |
4794 a reusable list. | |
4795 */ | |
4796 | |
4797 if (thelen < len) | |
4798 { | |
4799 cons = Vextent_face_reusable_list; | |
4800 while (!NILP (XCDR (cons))) | |
4801 cons = XCDR (cons); | |
4802 XCDR (cons) = Fmake_list (make_int (len - thelen), Qnil); | |
4803 } | |
4804 else if (thelen > len) | |
4805 { | |
4806 int i; | |
4807 | |
4808 /* Truncate the list temporarily so it's the right length; | |
4809 remember the old tail. */ | |
4810 cons = Vextent_face_reusable_list; | |
4811 for (i = 0; i < len - 1; i++) | |
4812 cons = XCDR (cons); | |
4813 tail = cons; | |
4814 oldtail = XCDR (cons); | |
4815 XCDR (cons) = Qnil; | |
4816 } | |
4817 | |
4818 thecons = Vextent_face_reusable_list; | |
2367 | 4819 { |
4820 EXTERNAL_LIST_LOOP_2 (face, list) | |
4821 { | |
4822 face = Fget_face (face); | |
4823 | |
4824 XCAR (thecons) = Fface_name (face); | |
4825 thecons = XCDR (thecons); | |
4826 } | |
4827 } | |
428 | 4828 |
4829 list = Fgethash (Vextent_face_reusable_list, Vextent_face_memoize_hash_table, | |
4830 Qnil); | |
4831 if (NILP (list)) | |
4832 { | |
4833 Lisp_Object symlist = Fcopy_sequence (Vextent_face_reusable_list); | |
4834 Lisp_Object facelist = Fcopy_sequence (Vextent_face_reusable_list); | |
4835 | |
4836 LIST_LOOP (cons, facelist) | |
4837 { | |
4838 XCAR (cons) = Fget_face (XCAR (cons)); | |
4839 } | |
4840 Fputhash (symlist, facelist, Vextent_face_memoize_hash_table); | |
4841 Fputhash (facelist, symlist, Vextent_face_reverse_memoize_hash_table); | |
4842 list = facelist; | |
4843 } | |
4844 | |
4845 /* Now restore the truncated tail of the reusable list, if necessary. */ | |
4846 if (!NILP (tail)) | |
4847 XCDR (tail) = oldtail; | |
4848 | |
4849 UNGCPRO; | |
4850 return list; | |
4851 } | |
4852 | |
4853 static Lisp_Object | |
4854 external_of_internal_memoized_face (Lisp_Object face) | |
4855 { | |
4856 if (NILP (face)) | |
4857 return Qnil; | |
4858 else if (!CONSP (face)) | |
4859 return XFACE (face)->name; | |
4860 else | |
4861 { | |
4862 face = Fgethash (face, Vextent_face_reverse_memoize_hash_table, | |
4863 Qunbound); | |
4864 assert (!UNBOUNDP (face)); | |
4865 return face; | |
4866 } | |
4867 } | |
4868 | |
826 | 4869 /* The idea here is that if we're given a list of faces, we |
4870 need to "memoize" this so that two lists of faces that are `equal' | |
4871 turn into the same object. When `set-extent-face' is called, we | |
4872 "memoize" into a list of actual faces; when `extent-face' is called, | |
4873 we do a reverse lookup to get the list of symbols. */ | |
4874 | |
428 | 4875 static Lisp_Object |
4876 canonicalize_extent_property (Lisp_Object prop, Lisp_Object value) | |
4877 { | |
4878 if (EQ (prop, Qface) || EQ (prop, Qmouse_face)) | |
4879 value = (external_of_internal_memoized_face | |
4880 (memoize_extent_face_internal (value))); | |
4881 return value; | |
4882 } | |
4883 | |
4884 /* Do we need a lisp-level function ? */ | |
826 | 4885 DEFUN ("set-extent-initial-redisplay-function", |
4886 Fset_extent_initial_redisplay_function, | |
444 | 4887 2,2,0, /* |
428 | 4888 Note: This feature is experimental! |
4889 | |
4890 Set initial-redisplay-function of EXTENT to the function | |
4891 FUNCTION. | |
4892 | |
4893 The first time the EXTENT is (re)displayed, an eval event will be | |
4894 dispatched calling FUNCTION with EXTENT as its only argument. | |
4895 */ | |
4896 (extent, function)) | |
4897 { | |
826 | 4898 /* #### This is totally broken. */ |
4899 EXTENT e = decode_extent (extent, DE_MUST_BE_ATTACHED); | |
428 | 4900 |
4901 e = extent_ancestor (e); /* Is this needed? Macro also does chasing!*/ | |
826 | 4902 set_extent_initial_redisplay_function (e, function); |
4903 extent_in_red_event_p (e) = 0; /* If the function changed we can spawn | |
428 | 4904 new events */ |
826 | 4905 signal_extent_property_changed (e, Qinitial_redisplay_function, 1); |
428 | 4906 return function; |
4907 } | |
4908 | |
4909 DEFUN ("extent-face", Fextent_face, 1, 1, 0, /* | |
4910 Return the name of the face in which EXTENT is displayed, or nil | |
4911 if the extent's face is unspecified. This might also return a list | |
4912 of face names. | |
4913 */ | |
4914 (extent)) | |
4915 { | |
4916 Lisp_Object face; | |
4917 | |
4918 CHECK_EXTENT (extent); | |
4919 face = extent_face (XEXTENT (extent)); | |
4920 | |
4921 return external_of_internal_memoized_face (face); | |
4922 } | |
4923 | |
4924 DEFUN ("set-extent-face", Fset_extent_face, 2, 2, 0, /* | |
4925 Make the given EXTENT have the graphic attributes specified by FACE. | |
4926 FACE can also be a list of faces, and all faces listed will apply, | |
4927 with faces earlier in the list taking priority over those later in the | |
4928 list. | |
4929 */ | |
4930 (extent, face)) | |
4931 { | |
4932 EXTENT e = decode_extent(extent, 0); | |
4933 Lisp_Object orig_face = face; | |
4934 | |
4935 /* retrieve the ancestor for efficiency and proper redisplay noting. */ | |
4936 e = extent_ancestor (e); | |
4937 | |
4938 face = memoize_extent_face_internal (face); | |
4939 | |
4940 extent_face (e) = face; | |
826 | 4941 signal_extent_property_changed (e, Qface, 1); |
428 | 4942 |
4943 return orig_face; | |
4944 } | |
4945 | |
4946 | |
4947 DEFUN ("extent-mouse-face", Fextent_mouse_face, 1, 1, 0, /* | |
4948 Return the face used to highlight EXTENT when the mouse passes over it. | |
4949 The return value will be a face name, a list of face names, or nil | |
4950 if the extent's mouse face is unspecified. | |
4951 */ | |
4952 (extent)) | |
4953 { | |
4954 Lisp_Object face; | |
4955 | |
4956 CHECK_EXTENT (extent); | |
4957 face = extent_mouse_face (XEXTENT (extent)); | |
4958 | |
4959 return external_of_internal_memoized_face (face); | |
4960 } | |
4961 | |
4962 DEFUN ("set-extent-mouse-face", Fset_extent_mouse_face, 2, 2, 0, /* | |
4963 Set the face used to highlight EXTENT when the mouse passes over it. | |
4964 FACE can also be a list of faces, and all faces listed will apply, | |
4965 with faces earlier in the list taking priority over those later in the | |
4966 list. | |
4967 */ | |
4968 (extent, face)) | |
4969 { | |
4970 EXTENT e; | |
4971 Lisp_Object orig_face = face; | |
4972 | |
4973 CHECK_EXTENT (extent); | |
4974 e = XEXTENT (extent); | |
4975 /* retrieve the ancestor for efficiency and proper redisplay noting. */ | |
4976 e = extent_ancestor (e); | |
4977 | |
4978 face = memoize_extent_face_internal (face); | |
4979 | |
4980 set_extent_mouse_face (e, face); | |
826 | 4981 signal_extent_property_changed (e, Qmouse_face, 1); |
428 | 4982 |
4983 return orig_face; | |
4984 } | |
4985 | |
4986 void | |
4987 set_extent_glyph (EXTENT extent, Lisp_Object glyph, int endp, | |
4988 glyph_layout layout) | |
4989 { | |
4990 extent = extent_ancestor (extent); | |
4991 | |
4992 if (!endp) | |
4993 { | |
4994 set_extent_begin_glyph (extent, glyph); | |
647 | 4995 set_extent_begin_glyph_layout (extent, layout); |
826 | 4996 signal_extent_property_changed (extent, Qbegin_glyph, 1); |
4997 signal_extent_property_changed (extent, Qbegin_glyph_layout, 1); | |
428 | 4998 } |
4999 else | |
5000 { | |
5001 set_extent_end_glyph (extent, glyph); | |
647 | 5002 set_extent_end_glyph_layout (extent, layout); |
826 | 5003 signal_extent_property_changed (extent, Qend_glyph, 1); |
5004 signal_extent_property_changed (extent, Qend_glyph_layout, 1); | |
428 | 5005 } |
5006 } | |
5007 | |
5008 static Lisp_Object | |
5009 glyph_layout_to_symbol (glyph_layout layout) | |
5010 { | |
5011 switch (layout) | |
5012 { | |
5013 case GL_TEXT: return Qtext; | |
5014 case GL_OUTSIDE_MARGIN: return Qoutside_margin; | |
5015 case GL_INSIDE_MARGIN: return Qinside_margin; | |
5016 case GL_WHITESPACE: return Qwhitespace; | |
5017 default: | |
2500 | 5018 ABORT (); |
428 | 5019 return Qnil; /* unreached */ |
5020 } | |
5021 } | |
5022 | |
5023 static glyph_layout | |
5024 symbol_to_glyph_layout (Lisp_Object layout_obj) | |
5025 { | |
5026 if (NILP (layout_obj)) | |
5027 return GL_TEXT; | |
5028 | |
5029 CHECK_SYMBOL (layout_obj); | |
5030 if (EQ (layout_obj, Qoutside_margin)) return GL_OUTSIDE_MARGIN; | |
5031 if (EQ (layout_obj, Qinside_margin)) return GL_INSIDE_MARGIN; | |
5032 if (EQ (layout_obj, Qwhitespace)) return GL_WHITESPACE; | |
5033 if (EQ (layout_obj, Qtext)) return GL_TEXT; | |
5034 | |
563 | 5035 invalid_constant ("Unknown glyph layout type", layout_obj); |
1204 | 5036 RETURN_NOT_REACHED (GL_TEXT); |
428 | 5037 } |
5038 | |
5039 static Lisp_Object | |
5040 set_extent_glyph_1 (Lisp_Object extent_obj, Lisp_Object glyph, int endp, | |
5041 Lisp_Object layout_obj) | |
5042 { | |
442 | 5043 EXTENT extent = decode_extent (extent_obj, 0); |
428 | 5044 glyph_layout layout = symbol_to_glyph_layout (layout_obj); |
5045 | |
5046 /* Make sure we've actually been given a valid glyph or it's nil | |
5047 (meaning we're deleting a glyph from an extent). */ | |
5048 if (!NILP (glyph)) | |
5049 CHECK_BUFFER_GLYPH (glyph); | |
5050 | |
5051 set_extent_glyph (extent, glyph, endp, layout); | |
5052 return glyph; | |
5053 } | |
5054 | |
5055 DEFUN ("set-extent-begin-glyph", Fset_extent_begin_glyph, 2, 3, 0, /* | |
5056 Display a bitmap, subwindow or string at the beginning of EXTENT. | |
5057 BEGIN-GLYPH must be a glyph object. The layout policy defaults to `text'. | |
5058 */ | |
5059 (extent, begin_glyph, layout)) | |
5060 { | |
5061 return set_extent_glyph_1 (extent, begin_glyph, 0, layout); | |
5062 } | |
5063 | |
5064 DEFUN ("set-extent-end-glyph", Fset_extent_end_glyph, 2, 3, 0, /* | |
5065 Display a bitmap, subwindow or string at the end of EXTENT. | |
5066 END-GLYPH must be a glyph object. The layout policy defaults to `text'. | |
5067 */ | |
5068 (extent, end_glyph, layout)) | |
5069 { | |
5070 return set_extent_glyph_1 (extent, end_glyph, 1, layout); | |
5071 } | |
5072 | |
5073 DEFUN ("extent-begin-glyph", Fextent_begin_glyph, 1, 1, 0, /* | |
5074 Return the glyph object displayed at the beginning of EXTENT. | |
5075 If there is none, nil is returned. | |
5076 */ | |
5077 (extent)) | |
5078 { | |
5079 return extent_begin_glyph (decode_extent (extent, 0)); | |
5080 } | |
5081 | |
5082 DEFUN ("extent-end-glyph", Fextent_end_glyph, 1, 1, 0, /* | |
5083 Return the glyph object displayed at the end of EXTENT. | |
5084 If there is none, nil is returned. | |
5085 */ | |
5086 (extent)) | |
5087 { | |
5088 return extent_end_glyph (decode_extent (extent, 0)); | |
5089 } | |
5090 | |
5091 DEFUN ("set-extent-begin-glyph-layout", Fset_extent_begin_glyph_layout, 2, 2, 0, /* | |
5092 Set the layout policy of EXTENT's begin glyph. | |
5093 Access this using the `extent-begin-glyph-layout' function. | |
5094 */ | |
5095 (extent, layout)) | |
5096 { | |
5097 EXTENT e = decode_extent (extent, 0); | |
5098 e = extent_ancestor (e); | |
647 | 5099 set_extent_begin_glyph_layout (e, symbol_to_glyph_layout (layout)); |
826 | 5100 signal_extent_property_changed (e, Qbegin_glyph_layout, 1); |
428 | 5101 return layout; |
5102 } | |
5103 | |
5104 DEFUN ("set-extent-end-glyph-layout", Fset_extent_end_glyph_layout, 2, 2, 0, /* | |
5105 Set the layout policy of EXTENT's end glyph. | |
5106 Access this using the `extent-end-glyph-layout' function. | |
5107 */ | |
5108 (extent, layout)) | |
5109 { | |
5110 EXTENT e = decode_extent (extent, 0); | |
5111 e = extent_ancestor (e); | |
647 | 5112 set_extent_end_glyph_layout (e, symbol_to_glyph_layout (layout)); |
826 | 5113 signal_extent_property_changed (e, Qend_glyph_layout, 1); |
428 | 5114 return layout; |
5115 } | |
5116 | |
5117 DEFUN ("extent-begin-glyph-layout", Fextent_begin_glyph_layout, 1, 1, 0, /* | |
5118 Return the layout policy associated with EXTENT's begin glyph. | |
5119 Set this using the `set-extent-begin-glyph-layout' function. | |
5120 */ | |
5121 (extent)) | |
5122 { | |
5123 EXTENT e = decode_extent (extent, 0); | |
5124 return glyph_layout_to_symbol ((glyph_layout) extent_begin_glyph_layout (e)); | |
5125 } | |
5126 | |
5127 DEFUN ("extent-end-glyph-layout", Fextent_end_glyph_layout, 1, 1, 0, /* | |
5128 Return the layout policy associated with EXTENT's end glyph. | |
5129 Set this using the `set-extent-end-glyph-layout' function. | |
5130 */ | |
5131 (extent)) | |
5132 { | |
5133 EXTENT e = decode_extent (extent, 0); | |
5134 return glyph_layout_to_symbol ((glyph_layout) extent_end_glyph_layout (e)); | |
5135 } | |
5136 | |
5137 DEFUN ("set-extent-priority", Fset_extent_priority, 2, 2, 0, /* | |
5138 Set the display priority of EXTENT to PRIORITY (an integer). | |
5139 When the extent attributes are being merged for display, the priority | |
5140 is used to determine which extent takes precedence in the event of a | |
5141 conflict (two extents whose faces both specify font, for example: the | |
5142 font of the extent with the higher priority will be used). | |
5143 Extents are created with priority 0; priorities may be negative. | |
5144 */ | |
5145 (extent, priority)) | |
5146 { | |
5147 EXTENT e = decode_extent (extent, 0); | |
5148 | |
5149 CHECK_INT (priority); | |
5150 e = extent_ancestor (e); | |
5151 set_extent_priority (e, XINT (priority)); | |
826 | 5152 signal_extent_property_changed (e, Qpriority, 1); |
428 | 5153 return priority; |
5154 } | |
5155 | |
5156 DEFUN ("extent-priority", Fextent_priority, 1, 1, 0, /* | |
5157 Return the display priority of EXTENT; see `set-extent-priority'. | |
5158 */ | |
5159 (extent)) | |
5160 { | |
5161 EXTENT e = decode_extent (extent, 0); | |
5162 return make_int (extent_priority (e)); | |
5163 } | |
5164 | |
5165 DEFUN ("set-extent-property", Fset_extent_property, 3, 3, 0, /* | |
5166 Change a property of an extent. | |
5167 PROPERTY may be any symbol; the value stored may be accessed with | |
5168 the `extent-property' function. | |
2758 | 5169 |
428 | 5170 The following symbols have predefined meanings: |
5171 | |
5172 detached Removes the extent from its buffer; setting this is | |
5173 the same as calling `detach-extent'. | |
5174 | |
5175 destroyed Removes the extent from its buffer, and makes it | |
5176 unusable in the future; this is the same calling | |
5177 `delete-extent'. | |
5178 | |
5179 priority Change redisplay priority; same as `set-extent-priority'. | |
5180 | |
5181 start-open Whether the set of characters within the extent is | |
5182 treated being open on the left, that is, whether | |
5183 the start position is an exclusive, rather than | |
5184 inclusive, boundary. If true, then characters | |
5185 inserted exactly at the beginning of the extent | |
5186 will remain outside of the extent; otherwise they | |
5187 will go into the extent, extending it. | |
5188 | |
5189 end-open Whether the set of characters within the extent is | |
5190 treated being open on the right, that is, whether | |
5191 the end position is an exclusive, rather than | |
5192 inclusive, boundary. If true, then characters | |
5193 inserted exactly at the end of the extent will | |
5194 remain outside of the extent; otherwise they will | |
5195 go into the extent, extending it. | |
5196 | |
5197 By default, extents have the `end-open' but not the | |
5198 `start-open' property set. | |
5199 | |
5200 read-only Text within this extent will be unmodifiable. | |
5201 | |
5202 initial-redisplay-function (EXPERIMENTAL) | |
5203 function to be called the first time (part of) the extent | |
5204 is redisplayed. It will be called with the extent as its | |
5205 first argument. | |
1041 | 5206 Note: The function will not be called immediately |
5207 during redisplay, an eval event will be dispatched. | |
428 | 5208 |
5209 detachable Whether the extent gets detached (as with | |
5210 `detach-extent') when all the text within the | |
5211 extent is deleted. This is true by default. If | |
5212 this property is not set, the extent becomes a | |
5213 zero-length extent when its text is deleted. (In | |
5214 such a case, the `start-open' property is | |
5215 automatically removed if both the `start-open' and | |
5216 `end-open' properties are set, since zero-length | |
5217 extents open on both ends are not allowed.) | |
5218 | |
5219 face The face in which to display the text. Setting | |
5220 this is the same as calling `set-extent-face'. | |
5221 | |
1041 | 5222 mouse-face If non-nil, the extent will be highlighted in this |
5223 face when the mouse moves over it. | |
428 | 5224 |
5225 pointer If non-nil, and a valid pointer glyph, this specifies | |
5226 the shape of the mouse pointer while over the extent. | |
5227 | |
5228 highlight Obsolete: Setting this property is equivalent to | |
1041 | 5229 setting a `mouse-face' property of `highlight'. |
5230 Reading this property returns non-nil if | |
5231 the extent has a non-nil `mouse-face' property. | |
428 | 5232 |
5233 duplicable Whether this extent should be copied into strings, | |
5234 so that kill, yank, and undo commands will restore | |
5235 or copy it. `duplicable' extents are copied from | |
5236 an extent into a string when `buffer-substring' or | |
5237 a similar function creates a string. The extents | |
5238 in a string are copied into other strings created | |
5239 from the string using `concat' or `substring'. | |
5240 When `insert' or a similar function inserts the | |
5241 string into a buffer, the extents are copied back | |
5242 into the buffer. | |
5243 | |
5244 unique Meaningful only in conjunction with `duplicable'. | |
5245 When this is set, there may be only one instance | |
5246 of this extent attached at a time: if it is copied | |
5247 to the kill ring and then yanked, the extent is | |
5248 not copied. If, however, it is killed (removed | |
5249 from the buffer) and then yanked, it will be | |
5250 re-attached at the new position. | |
5251 | |
5252 invisible If the value is non-nil, text under this extent | |
5253 may be treated as not present for the purpose of | |
5254 redisplay, or may be displayed using an ellipsis | |
5255 or other marker; see `buffer-invisibility-spec' | |
5256 and `invisible-text-glyph'. In all cases, | |
5257 however, the text is still visible to other | |
5258 functions that examine a buffer's text. | |
5259 | |
5260 keymap This keymap is consulted for mouse clicks on this | |
5261 extent, or keypresses made while point is within the | |
5262 extent. | |
5263 | |
5264 copy-function This is a hook that is run when a duplicable extent | |
5265 is about to be copied from a buffer to a string (or | |
5266 the kill ring). It is called with three arguments, | |
5267 the extent, and the buffer-positions within it | |
5268 which are being copied. If this function returns | |
5269 nil, then the extent will not be copied; otherwise | |
5270 it will. | |
5271 | |
5272 paste-function This is a hook that is run when a duplicable extent is | |
5273 about to be copied from a string (or the kill ring) | |
5274 into a buffer. It is called with three arguments, | |
5275 the original extent, and the buffer positions which | |
5276 the copied extent will occupy. (This hook is run | |
5277 after the corresponding text has already been | |
5278 inserted into the buffer.) Note that the extent | |
5279 argument may be detached when this function is run. | |
5280 If this function returns nil, no extent will be | |
5281 inserted. Otherwise, there will be an extent | |
5282 covering the range in question. | |
5283 | |
5284 If the original extent is not attached to a buffer, | |
5285 then it will be re-attached at this range. | |
5286 Otherwise, a copy will be made, and that copy | |
5287 attached here. | |
5288 | |
5289 The copy-function and paste-function are meaningful | |
5290 only for extents with the `duplicable' flag set, | |
5291 and if they are not specified, behave as if `t' was | |
5292 the returned value. When these hooks are invoked, | |
5293 the current buffer is the buffer which the extent | |
5294 is being copied from/to, respectively. | |
5295 | |
5296 begin-glyph A glyph to be displayed at the beginning of the extent, | |
5297 or nil. | |
5298 | |
5299 end-glyph A glyph to be displayed at the end of the extent, | |
5300 or nil. | |
5301 | |
5302 begin-glyph-layout The layout policy (one of `text', `whitespace', | |
5303 `inside-margin', or `outside-margin') of the extent's | |
5304 begin glyph. | |
5305 | |
1041 | 5306 end-glyph-layout The layout policy of the extent's end glyph. |
5307 | |
5308 syntax-table A cons or a syntax table object. If a cons, the car must | |
2767 | 5309 be an integer (interpreted as a syntax code, applicable |
5310 to all characters in the extent). Otherwise, syntax of | |
5311 characters in the extent is looked up in the syntax | |
5312 table. You should use the text property API to | |
5313 manipulate this property. (This may be required in the | |
5314 future.) | |
5315 | |
5316 The following property is available if `atomic-extents.el'--part of the | |
5317 `edit-utils' package--has been loaded: | |
2758 | 5318 |
5319 atomic When set, point will never fall inside the extent. | |
5320 Not as useful as you might think, as | |
5321 `delete-backward-char' still removes characters one by | |
2767 | 5322 one. This property as currently implemented is a |
5323 kludge, and be prepared for it to go away if and when we | |
5324 implement something better. | |
2758 | 5325 |
428 | 5326 */ |
5327 (extent, property, value)) | |
5328 { | |
5329 /* This function can GC if property is `keymap' */ | |
5330 EXTENT e = decode_extent (extent, 0); | |
826 | 5331 int signal_change = 0; |
5332 | |
5333 /* If VALUE is unbound, the property is being removed through `remprop'. | |
5334 Return Qunbound if removal disallowed, Qt if anything removed, | |
5335 Qnil otherwise. */ | |
5336 | |
5337 /* Keep in synch with stuff below. */ | |
5338 if (UNBOUNDP (value)) | |
5339 { | |
5340 int retval; | |
5341 | |
5342 if (EQ (property, Qread_only) | |
5343 || EQ (property, Qunique) | |
5344 || EQ (property, Qduplicable) | |
5345 || EQ (property, Qinvisible) | |
5346 || EQ (property, Qdetachable) | |
5347 || EQ (property, Qdetached) | |
5348 || EQ (property, Qdestroyed) | |
5349 || EQ (property, Qpriority) | |
5350 || EQ (property, Qface) | |
5351 || EQ (property, Qinitial_redisplay_function) | |
5352 || EQ (property, Qafter_change_functions) | |
5353 || EQ (property, Qbefore_change_functions) | |
5354 || EQ (property, Qmouse_face) | |
5355 || EQ (property, Qhighlight) | |
5356 || EQ (property, Qbegin_glyph_layout) | |
5357 || EQ (property, Qend_glyph_layout) | |
5358 || EQ (property, Qglyph_layout) | |
5359 || EQ (property, Qbegin_glyph) | |
5360 || EQ (property, Qend_glyph) | |
5361 || EQ (property, Qstart_open) | |
5362 || EQ (property, Qend_open) | |
5363 || EQ (property, Qstart_closed) | |
5364 || EQ (property, Qend_closed) | |
5365 || EQ (property, Qkeymap)) | |
5366 return Qunbound; | |
5367 | |
5368 retval = external_remprop (extent_plist_addr (e), property, 0, | |
5369 ERROR_ME); | |
5370 if (retval) | |
5371 signal_extent_property_changed (e, property, 1); | |
5372 return retval ? Qt : Qnil; | |
5373 } | |
428 | 5374 |
5375 if (EQ (property, Qread_only)) | |
826 | 5376 { |
5377 set_extent_read_only (e, value); | |
5378 signal_change = 1; | |
5379 } | |
428 | 5380 else if (EQ (property, Qunique)) |
826 | 5381 { |
5382 extent_unique_p (e) = !NILP (value); | |
5383 signal_change = 1; | |
5384 } | |
428 | 5385 else if (EQ (property, Qduplicable)) |
826 | 5386 { |
5387 extent_duplicable_p (e) = !NILP (value); | |
5388 signal_change = 1; | |
5389 } | |
428 | 5390 else if (EQ (property, Qinvisible)) |
5391 set_extent_invisible (e, value); | |
5392 else if (EQ (property, Qdetachable)) | |
826 | 5393 { |
5394 extent_detachable_p (e) = !NILP (value); | |
5395 signal_change = 1; | |
5396 } | |
428 | 5397 else if (EQ (property, Qdetached)) |
5398 { | |
5399 if (NILP (value)) | |
826 | 5400 invalid_operation ("can only set `detached' to t", Qunbound); |
428 | 5401 Fdetach_extent (extent); |
5402 } | |
5403 else if (EQ (property, Qdestroyed)) | |
5404 { | |
5405 if (NILP (value)) | |
826 | 5406 invalid_operation ("can only set `destroyed' to t", Qunbound); |
428 | 5407 Fdelete_extent (extent); |
5408 } | |
5409 else if (EQ (property, Qpriority)) | |
5410 Fset_extent_priority (extent, value); | |
5411 else if (EQ (property, Qface)) | |
5412 Fset_extent_face (extent, value); | |
5413 else if (EQ (property, Qinitial_redisplay_function)) | |
5414 Fset_extent_initial_redisplay_function (extent, value); | |
5415 else if (EQ (property, Qbefore_change_functions)) | |
826 | 5416 { |
5417 set_extent_before_change_functions (e, value); | |
5418 signal_change = 1; | |
5419 } | |
428 | 5420 else if (EQ (property, Qafter_change_functions)) |
826 | 5421 { |
5422 set_extent_after_change_functions (e, value); | |
5423 signal_change = 1; | |
5424 } | |
428 | 5425 else if (EQ (property, Qmouse_face)) |
5426 Fset_extent_mouse_face (extent, value); | |
5427 /* Obsolete: */ | |
5428 else if (EQ (property, Qhighlight)) | |
5429 Fset_extent_mouse_face (extent, Qhighlight); | |
5430 else if (EQ (property, Qbegin_glyph_layout)) | |
5431 Fset_extent_begin_glyph_layout (extent, value); | |
5432 else if (EQ (property, Qend_glyph_layout)) | |
5433 Fset_extent_end_glyph_layout (extent, value); | |
5434 /* For backwards compatibility. We use begin glyph because it is by | |
5435 far the more used of the two. */ | |
5436 else if (EQ (property, Qglyph_layout)) | |
5437 Fset_extent_begin_glyph_layout (extent, value); | |
5438 else if (EQ (property, Qbegin_glyph)) | |
5439 Fset_extent_begin_glyph (extent, value, Qnil); | |
5440 else if (EQ (property, Qend_glyph)) | |
5441 Fset_extent_end_glyph (extent, value, Qnil); | |
5442 else if (EQ (property, Qstart_open)) | |
5443 set_extent_openness (e, !NILP (value), -1); | |
5444 else if (EQ (property, Qend_open)) | |
5445 set_extent_openness (e, -1, !NILP (value)); | |
5446 /* Support (but don't document...) the obvious *_closed antonyms. */ | |
5447 else if (EQ (property, Qstart_closed)) | |
5448 set_extent_openness (e, NILP (value), -1); | |
5449 else if (EQ (property, Qend_closed)) | |
5450 set_extent_openness (e, -1, NILP (value)); | |
5451 else | |
5452 { | |
5453 if (EQ (property, Qkeymap)) | |
5454 while (!NILP (value) && NILP (Fkeymapp (value))) | |
5455 value = wrong_type_argument (Qkeymapp, value); | |
5456 | |
5457 external_plist_put (extent_plist_addr (e), property, value, 0, ERROR_ME); | |
826 | 5458 signal_change = 1; |
428 | 5459 } |
5460 | |
826 | 5461 if (signal_change) |
5462 signal_extent_property_changed (e, property, 1); | |
428 | 5463 return value; |
5464 } | |
5465 | |
5466 DEFUN ("set-extent-properties", Fset_extent_properties, 2, 2, 0, /* | |
5467 Change some properties of EXTENT. | |
5468 PLIST is a property list. | |
5469 For a list of built-in properties, see `set-extent-property'. | |
5470 */ | |
5471 (extent, plist)) | |
5472 { | |
5473 /* This function can GC, if one of the properties is `keymap' */ | |
5474 Lisp_Object property, value; | |
5475 struct gcpro gcpro1; | |
5476 GCPRO1 (plist); | |
5477 | |
5478 plist = Fcopy_sequence (plist); | |
5479 Fcanonicalize_plist (plist, Qnil); | |
5480 | |
5481 while (!NILP (plist)) | |
5482 { | |
5483 property = Fcar (plist); plist = Fcdr (plist); | |
5484 value = Fcar (plist); plist = Fcdr (plist); | |
5485 Fset_extent_property (extent, property, value); | |
5486 } | |
5487 UNGCPRO; | |
5488 return Qnil; | |
5489 } | |
5490 | |
5491 DEFUN ("extent-property", Fextent_property, 2, 3, 0, /* | |
5492 Return EXTENT's value for property PROPERTY. | |
444 | 5493 If no such property exists, DEFAULT is returned. |
428 | 5494 See `set-extent-property' for the built-in property names. |
5495 */ | |
5496 (extent, property, default_)) | |
5497 { | |
5498 EXTENT e = decode_extent (extent, 0); | |
5499 | |
5500 if (EQ (property, Qdetached)) | |
5501 return extent_detached_p (e) ? Qt : Qnil; | |
5502 else if (EQ (property, Qdestroyed)) | |
5503 return !EXTENT_LIVE_P (e) ? Qt : Qnil; | |
5504 else if (EQ (property, Qstart_open)) | |
5505 return extent_normal_field (e, start_open) ? Qt : Qnil; | |
5506 else if (EQ (property, Qend_open)) | |
5507 return extent_normal_field (e, end_open) ? Qt : Qnil; | |
5508 else if (EQ (property, Qunique)) | |
5509 return extent_normal_field (e, unique) ? Qt : Qnil; | |
5510 else if (EQ (property, Qduplicable)) | |
5511 return extent_normal_field (e, duplicable) ? Qt : Qnil; | |
5512 else if (EQ (property, Qdetachable)) | |
5513 return extent_normal_field (e, detachable) ? Qt : Qnil; | |
5514 /* Support (but don't document...) the obvious *_closed antonyms. */ | |
5515 else if (EQ (property, Qstart_closed)) | |
5516 return extent_start_open_p (e) ? Qnil : Qt; | |
5517 else if (EQ (property, Qend_closed)) | |
5518 return extent_end_open_p (e) ? Qnil : Qt; | |
5519 else if (EQ (property, Qpriority)) | |
5520 return make_int (extent_priority (e)); | |
5521 else if (EQ (property, Qread_only)) | |
5522 return extent_read_only (e); | |
5523 else if (EQ (property, Qinvisible)) | |
5524 return extent_invisible (e); | |
5525 else if (EQ (property, Qface)) | |
5526 return Fextent_face (extent); | |
5527 else if (EQ (property, Qinitial_redisplay_function)) | |
5528 return extent_initial_redisplay_function (e); | |
5529 else if (EQ (property, Qbefore_change_functions)) | |
5530 return extent_before_change_functions (e); | |
5531 else if (EQ (property, Qafter_change_functions)) | |
5532 return extent_after_change_functions (e); | |
5533 else if (EQ (property, Qmouse_face)) | |
5534 return Fextent_mouse_face (extent); | |
5535 /* Obsolete: */ | |
5536 else if (EQ (property, Qhighlight)) | |
5537 return !NILP (Fextent_mouse_face (extent)) ? Qt : Qnil; | |
5538 else if (EQ (property, Qbegin_glyph_layout)) | |
5539 return Fextent_begin_glyph_layout (extent); | |
5540 else if (EQ (property, Qend_glyph_layout)) | |
5541 return Fextent_end_glyph_layout (extent); | |
5542 /* For backwards compatibility. We use begin glyph because it is by | |
5543 far the more used of the two. */ | |
5544 else if (EQ (property, Qglyph_layout)) | |
5545 return Fextent_begin_glyph_layout (extent); | |
5546 else if (EQ (property, Qbegin_glyph)) | |
5547 return extent_begin_glyph (e); | |
5548 else if (EQ (property, Qend_glyph)) | |
5549 return extent_end_glyph (e); | |
5550 else | |
5551 { | |
5552 Lisp_Object value = external_plist_get (extent_plist_addr (e), | |
5553 property, 0, ERROR_ME); | |
5554 return UNBOUNDP (value) ? default_ : value; | |
5555 } | |
5556 } | |
5557 | |
826 | 5558 static void |
5559 extent_properties (EXTENT e, Lisp_Object_pair_dynarr *props) | |
5560 { | |
5561 Lisp_Object face, anc_obj; | |
428 | 5562 glyph_layout layout; |
826 | 5563 EXTENT anc; |
5564 | |
5565 #define ADD_PROP(miftaaH, maal) \ | |
5566 do { \ | |
5567 Lisp_Object_pair p; \ | |
5568 p.key = miftaaH; \ | |
5569 p.value = maal; \ | |
5570 Dynarr_add (props, p); \ | |
5571 } while (0) | |
5572 | |
428 | 5573 if (!EXTENT_LIVE_P (e)) |
826 | 5574 { |
5575 ADD_PROP (Qdestroyed, Qt); | |
5576 return; | |
5577 } | |
428 | 5578 |
5579 anc = extent_ancestor (e); | |
793 | 5580 anc_obj = wrap_extent (anc); |
428 | 5581 |
5582 /* For efficiency, use the ancestor for all properties except detached */ | |
826 | 5583 { |
5584 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, extent_plist_slot (anc)) | |
5585 ADD_PROP (key, value); | |
5586 } | |
428 | 5587 |
5588 if (!NILP (face = Fextent_face (anc_obj))) | |
826 | 5589 ADD_PROP (Qface, face); |
428 | 5590 |
5591 if (!NILP (face = Fextent_mouse_face (anc_obj))) | |
826 | 5592 ADD_PROP (Qmouse_face, face); |
428 | 5593 |
5594 if ((layout = (glyph_layout) extent_begin_glyph_layout (anc)) != GL_TEXT) | |
5595 { | |
5596 Lisp_Object sym = glyph_layout_to_symbol (layout); | |
826 | 5597 ADD_PROP (Qglyph_layout, sym); /* compatibility */ |
5598 ADD_PROP (Qbegin_glyph_layout, sym); | |
428 | 5599 } |
5600 | |
5601 if ((layout = (glyph_layout) extent_end_glyph_layout (anc)) != GL_TEXT) | |
826 | 5602 ADD_PROP (Qend_glyph_layout, glyph_layout_to_symbol (layout)); |
428 | 5603 |
5604 if (!NILP (extent_end_glyph (anc))) | |
826 | 5605 ADD_PROP (Qend_glyph, extent_end_glyph (anc)); |
428 | 5606 |
5607 if (!NILP (extent_begin_glyph (anc))) | |
826 | 5608 ADD_PROP (Qbegin_glyph, extent_begin_glyph (anc)); |
428 | 5609 |
5610 if (extent_priority (anc) != 0) | |
826 | 5611 ADD_PROP (Qpriority, make_int (extent_priority (anc))); |
428 | 5612 |
5613 if (!NILP (extent_initial_redisplay_function (anc))) | |
826 | 5614 ADD_PROP (Qinitial_redisplay_function, |
5615 extent_initial_redisplay_function (anc)); | |
428 | 5616 |
5617 if (!NILP (extent_before_change_functions (anc))) | |
826 | 5618 ADD_PROP (Qbefore_change_functions, extent_before_change_functions (anc)); |
428 | 5619 |
5620 if (!NILP (extent_after_change_functions (anc))) | |
826 | 5621 ADD_PROP (Qafter_change_functions, extent_after_change_functions (anc)); |
428 | 5622 |
5623 if (!NILP (extent_invisible (anc))) | |
826 | 5624 ADD_PROP (Qinvisible, extent_invisible (anc)); |
428 | 5625 |
5626 if (!NILP (extent_read_only (anc))) | |
826 | 5627 ADD_PROP (Qread_only, extent_read_only (anc)); |
428 | 5628 |
5629 if (extent_normal_field (anc, end_open)) | |
826 | 5630 ADD_PROP (Qend_open, Qt); |
428 | 5631 |
5632 if (extent_normal_field (anc, start_open)) | |
826 | 5633 ADD_PROP (Qstart_open, Qt); |
428 | 5634 |
5635 if (extent_normal_field (anc, detachable)) | |
826 | 5636 ADD_PROP (Qdetachable, Qt); |
428 | 5637 |
5638 if (extent_normal_field (anc, duplicable)) | |
826 | 5639 ADD_PROP (Qduplicable, Qt); |
428 | 5640 |
5641 if (extent_normal_field (anc, unique)) | |
826 | 5642 ADD_PROP (Qunique, Qt); |
428 | 5643 |
5644 /* detached is not an inherited property */ | |
5645 if (extent_detached_p (e)) | |
826 | 5646 ADD_PROP (Qdetached, Qt); |
5647 | |
5648 #undef ADD_PROP | |
5649 } | |
5650 | |
5651 DEFUN ("extent-properties", Fextent_properties, 1, 1, 0, /* | |
5652 Return a property list of the attributes of EXTENT. | |
5653 Do not modify this list; use `set-extent-property' instead. | |
5654 */ | |
5655 (extent)) | |
5656 { | |
5657 EXTENT e; | |
5658 Lisp_Object result = Qnil; | |
5659 Lisp_Object_pair_dynarr *props; | |
5660 int i; | |
5661 | |
5662 CHECK_EXTENT (extent); | |
5663 e = XEXTENT (extent); | |
5664 props = Dynarr_new (Lisp_Object_pair); | |
5665 extent_properties (e, props); | |
5666 | |
5667 for (i = 0; i < Dynarr_length (props); i++) | |
5668 result = cons3 (Dynarr_at (props, i).key, Dynarr_at (props, i).value, | |
5669 result); | |
5670 | |
5671 Dynarr_free (props); | |
428 | 5672 return result; |
5673 } | |
5674 | |
5675 | |
5676 /************************************************************************/ | |
5677 /* highlighting */ | |
5678 /************************************************************************/ | |
5679 | |
5680 /* The display code looks into the Vlast_highlighted_extent variable to | |
5681 correctly display highlighted extents. This updates that variable, | |
5682 and marks the appropriate buffers as needing some redisplay. | |
5683 */ | |
5684 static void | |
5685 do_highlight (Lisp_Object extent_obj, int highlight_p) | |
5686 { | |
5687 if (( highlight_p && (EQ (Vlast_highlighted_extent, extent_obj))) || | |
5688 (!highlight_p && (EQ (Vlast_highlighted_extent, Qnil)))) | |
5689 return; | |
5690 if (EXTENTP (Vlast_highlighted_extent) && | |
5691 EXTENT_LIVE_P (XEXTENT (Vlast_highlighted_extent))) | |
5692 { | |
5693 /* do not recurse on descendants. Only one extent is highlighted | |
5694 at a time. */ | |
826 | 5695 /* A bit of a lie. */ |
5696 signal_extent_property_changed (XEXTENT (Vlast_highlighted_extent), | |
5697 Qface, 0); | |
428 | 5698 } |
5699 Vlast_highlighted_extent = Qnil; | |
5700 if (!NILP (extent_obj) | |
5701 && BUFFERP (extent_object (XEXTENT (extent_obj))) | |
5702 && highlight_p) | |
5703 { | |
826 | 5704 signal_extent_property_changed (XEXTENT (extent_obj), Qface, 0); |
428 | 5705 Vlast_highlighted_extent = extent_obj; |
5706 } | |
5707 } | |
5708 | |
5709 DEFUN ("force-highlight-extent", Fforce_highlight_extent, 1, 2, 0, /* | |
5710 Highlight or unhighlight the given extent. | |
5711 If the second arg is non-nil, it will be highlighted, else dehighlighted. | |
5712 This is the same as `highlight-extent', except that it will work even | |
5713 on extents without the `mouse-face' property. | |
5714 */ | |
5715 (extent, highlight_p)) | |
5716 { | |
5717 if (NILP (extent)) | |
5718 highlight_p = Qnil; | |
5719 else | |
793 | 5720 extent = wrap_extent (decode_extent (extent, DE_MUST_BE_ATTACHED)); |
428 | 5721 do_highlight (extent, !NILP (highlight_p)); |
5722 return Qnil; | |
5723 } | |
5724 | |
5725 DEFUN ("highlight-extent", Fhighlight_extent, 1, 2, 0, /* | |
5726 Highlight EXTENT, if it is highlightable. | |
5727 \(that is, if it has the `mouse-face' property). | |
5728 If the second arg is non-nil, it will be highlighted, else dehighlighted. | |
5729 Highlighted extents are displayed as if they were merged with the face | |
5730 or faces specified by the `mouse-face' property. | |
5731 */ | |
5732 (extent, highlight_p)) | |
5733 { | |
5734 if (EXTENTP (extent) && NILP (extent_mouse_face (XEXTENT (extent)))) | |
5735 return Qnil; | |
5736 else | |
5737 return Fforce_highlight_extent (extent, highlight_p); | |
5738 } | |
5739 | |
5740 | |
5741 /************************************************************************/ | |
5742 /* strings and extents */ | |
5743 /************************************************************************/ | |
5744 | |
5745 /* copy/paste hooks */ | |
5746 | |
5747 static int | |
826 | 5748 run_extent_copy_paste_internal (EXTENT e, Charxpos from, Charxpos to, |
428 | 5749 Lisp_Object object, |
5750 Lisp_Object prop) | |
5751 { | |
5752 /* This function can GC */ | |
5753 Lisp_Object extent; | |
5754 Lisp_Object copy_fn; | |
793 | 5755 extent = wrap_extent (e); |
428 | 5756 copy_fn = Fextent_property (extent, prop, Qnil); |
5757 if (!NILP (copy_fn)) | |
5758 { | |
5759 Lisp_Object flag; | |
5760 struct gcpro gcpro1, gcpro2, gcpro3; | |
5761 GCPRO3 (extent, copy_fn, object); | |
5762 if (BUFFERP (object)) | |
5763 flag = call3_in_buffer (XBUFFER (object), copy_fn, extent, | |
5764 make_int (from), make_int (to)); | |
5765 else | |
5766 flag = call3 (copy_fn, extent, make_int (from), make_int (to)); | |
5767 UNGCPRO; | |
5768 if (NILP (flag) || !EXTENT_LIVE_P (XEXTENT (extent))) | |
5769 return 0; | |
5770 } | |
5771 return 1; | |
5772 } | |
5773 | |
5774 static int | |
826 | 5775 run_extent_copy_function (EXTENT e, Bytexpos from, Bytexpos to) |
428 | 5776 { |
5777 Lisp_Object object = extent_object (e); | |
5778 /* This function can GC */ | |
5779 return run_extent_copy_paste_internal | |
826 | 5780 (e, buffer_or_string_bytexpos_to_charxpos (object, from), |
5781 buffer_or_string_bytexpos_to_charxpos (object, to), object, | |
428 | 5782 Qcopy_function); |
5783 } | |
5784 | |
5785 static int | |
826 | 5786 run_extent_paste_function (EXTENT e, Bytexpos from, Bytexpos to, |
428 | 5787 Lisp_Object object) |
5788 { | |
5789 /* This function can GC */ | |
5790 return run_extent_copy_paste_internal | |
826 | 5791 (e, buffer_or_string_bytexpos_to_charxpos (object, from), |
5792 buffer_or_string_bytexpos_to_charxpos (object, to), object, | |
428 | 5793 Qpaste_function); |
5794 } | |
5795 | |
826 | 5796 static int |
5797 run_extent_paste_function_char (EXTENT e, Charxpos from, Charxpos to, | |
5798 Lisp_Object object) | |
5799 { | |
5800 /* This function can GC */ | |
5801 return run_extent_copy_paste_internal (e, from, to, object, Qpaste_function); | |
5802 } | |
5803 | |
428 | 5804 static Lisp_Object |
826 | 5805 insert_extent (EXTENT extent, Bytexpos new_start, Bytexpos new_end, |
428 | 5806 Lisp_Object object, int run_hooks) |
5807 { | |
5808 /* This function can GC */ | |
5809 if (!EQ (extent_object (extent), object)) | |
5810 goto copy_it; | |
5811 | |
5812 if (extent_detached_p (extent)) | |
5813 { | |
5814 if (run_hooks && | |
5815 !run_extent_paste_function (extent, new_start, new_end, object)) | |
5816 /* The paste-function said don't re-attach this extent here. */ | |
5817 return Qnil; | |
5818 else | |
826 | 5819 set_extent_endpoints (extent, new_start, new_end, Qnil); |
428 | 5820 } |
5821 else | |
5822 { | |
826 | 5823 Bytexpos exstart = extent_endpoint_byte (extent, 0); |
5824 Bytexpos exend = extent_endpoint_byte (extent, 1); | |
428 | 5825 |
5826 if (exend < new_start || exstart > new_end) | |
5827 goto copy_it; | |
5828 else | |
5829 { | |
5830 new_start = min (exstart, new_start); | |
5831 new_end = max (exend, new_end); | |
5832 if (exstart != new_start || exend != new_end) | |
826 | 5833 set_extent_endpoints (extent, new_start, new_end, Qnil); |
428 | 5834 } |
5835 } | |
5836 | |
793 | 5837 return wrap_extent (extent); |
428 | 5838 |
5839 copy_it: | |
5840 if (run_hooks && | |
5841 !run_extent_paste_function (extent, new_start, new_end, object)) | |
5842 /* The paste-function said don't attach a copy of the extent here. */ | |
5843 return Qnil; | |
5844 else | |
793 | 5845 return wrap_extent (copy_extent (extent, new_start, new_end, object)); |
428 | 5846 } |
5847 | |
5848 DEFUN ("insert-extent", Finsert_extent, 1, 5, 0, /* | |
5849 Insert EXTENT from START to END in BUFFER-OR-STRING. | |
5850 BUFFER-OR-STRING defaults to the current buffer if omitted. | |
826 | 5851 If EXTENT is already on the same object, and overlaps or is adjacent to |
5852 the given range, its range is merely extended to include the new range. | |
5853 Otherwise, a copy is made of the extent at the new position and object. | |
5854 When a copy is made, the new extent is returned, copy/paste hooks are run, | |
5855 and the change is noted for undo recording. When no copy is made, nil is | |
5856 returned. See documentation on `detach-extent' for a discussion of undo | |
5857 recording. | |
5858 | |
428 | 5859 The fourth arg, NO-HOOKS, can be used to inhibit the running of the |
826 | 5860 extent's `paste-function' property if it has one. |
5861 | |
5862 It's not really clear why this function exists any more. It was a holdover | |
5863 from a much older implementation of extents, before extents could really | |
5864 exist on strings. | |
428 | 5865 */ |
5866 (extent, start, end, no_hooks, buffer_or_string)) | |
5867 { | |
5868 EXTENT ext = decode_extent (extent, 0); | |
5869 Lisp_Object copy; | |
826 | 5870 Bytexpos s, e; |
428 | 5871 |
5872 buffer_or_string = decode_buffer_or_string (buffer_or_string); | |
5873 get_buffer_or_string_range_byte (buffer_or_string, start, end, &s, &e, | |
5874 GB_ALLOW_PAST_ACCESSIBLE); | |
5875 | |
5876 copy = insert_extent (ext, s, e, buffer_or_string, NILP (no_hooks)); | |
5877 if (EXTENTP (copy)) | |
5878 { | |
5879 if (extent_duplicable_p (XEXTENT (copy))) | |
5880 record_extent (copy, 1); | |
5881 } | |
5882 return copy; | |
5883 } | |
5884 | |
5885 | |
5886 /* adding buffer extents to a string */ | |
5887 | |
5888 struct add_string_extents_arg | |
5889 { | |
826 | 5890 Bytexpos from; |
428 | 5891 Bytecount length; |
5892 Lisp_Object string; | |
5893 }; | |
5894 | |
5895 static int | |
5896 add_string_extents_mapper (EXTENT extent, void *arg) | |
5897 { | |
5898 /* This function can GC */ | |
5899 struct add_string_extents_arg *closure = | |
5900 (struct add_string_extents_arg *) arg; | |
826 | 5901 Bytecount start = extent_endpoint_byte (extent, 0) - closure->from; |
5902 Bytecount end = extent_endpoint_byte (extent, 1) - closure->from; | |
428 | 5903 |
5904 if (extent_duplicable_p (extent)) | |
5905 { | |
5906 start = max (start, 0); | |
5907 end = min (end, closure->length); | |
5908 | |
5909 /* Run the copy-function to give an extent the option of | |
5910 not being copied into the string (or kill ring). | |
5911 */ | |
5912 if (extent_duplicable_p (extent) && | |
5913 !run_extent_copy_function (extent, start + closure->from, | |
5914 end + closure->from)) | |
5915 return 0; | |
5916 copy_extent (extent, start, end, closure->string); | |
5917 } | |
5918 | |
5919 return 0; | |
5920 } | |
5921 | |
826 | 5922 struct add_string_extents_the_hard_way_arg |
5923 { | |
5924 Charxpos from; | |
5925 Charcount length; | |
5926 Lisp_Object string; | |
5927 }; | |
5928 | |
5929 static int | |
5930 add_string_extents_the_hard_way_mapper (EXTENT extent, void *arg) | |
5931 { | |
5932 /* This function can GC */ | |
5933 struct add_string_extents_arg *closure = | |
5934 (struct add_string_extents_arg *) arg; | |
5935 Charcount start = extent_endpoint_char (extent, 0) - closure->from; | |
5936 Charcount end = extent_endpoint_char (extent, 1) - closure->from; | |
5937 | |
5938 if (extent_duplicable_p (extent)) | |
5939 { | |
5940 start = max (start, 0); | |
5941 end = min (end, closure->length); | |
5942 | |
5943 /* Run the copy-function to give an extent the option of | |
5944 not being copied into the string (or kill ring). | |
5945 */ | |
5946 if (extent_duplicable_p (extent) && | |
5947 !run_extent_copy_function (extent, start + closure->from, | |
5948 end + closure->from)) | |
5949 return 0; | |
5950 copy_extent (extent, | |
5951 string_index_char_to_byte (closure->string, start), | |
5952 string_index_char_to_byte (closure->string, end), | |
5953 closure->string); | |
5954 } | |
5955 | |
5956 return 0; | |
5957 } | |
5958 | |
428 | 5959 /* Add the extents in buffer BUF from OPOINT to OPOINT+LENGTH to |
5960 the string STRING. */ | |
5961 void | |
826 | 5962 add_string_extents (Lisp_Object string, struct buffer *buf, Bytexpos opoint, |
428 | 5963 Bytecount length) |
5964 { | |
5965 /* This function can GC */ | |
5966 struct gcpro gcpro1, gcpro2; | |
5967 Lisp_Object buffer; | |
5968 | |
771 | 5969 buffer = wrap_buffer (buf); |
428 | 5970 GCPRO2 (buffer, string); |
826 | 5971 |
5972 if (XSTRING_FORMAT (string) == BUF_FORMAT (buf)) | |
5973 { | |
5974 struct add_string_extents_arg closure; | |
5975 closure.from = opoint; | |
5976 closure.length = length; | |
5977 closure.string = string; | |
5978 map_extents (opoint, opoint + length, add_string_extents_mapper, | |
5979 (void *) &closure, buffer, 0, | |
5980 /* ignore extents that just abut the region */ | |
5981 ME_END_CLOSED | ME_ALL_EXTENTS_OPEN | | |
5982 /* we are calling E-Lisp (the extent's copy function) | |
5983 so anything might happen */ | |
5984 ME_MIGHT_CALL_ELISP); | |
5985 } | |
5986 else | |
5987 { | |
5988 struct add_string_extents_the_hard_way_arg closure; | |
5989 closure.from = bytebpos_to_charbpos (buf, opoint); | |
5990 closure.length = (bytebpos_to_charbpos (buf, opoint + length) - | |
5991 closure.from); | |
5992 closure.string = string; | |
5993 | |
5994 /* If the string and buffer are in different formats, things get | |
5995 tricky; the only reasonable way to do the operation is entirely in | |
5996 char offsets, which are invariant to format changes. In practice, | |
5997 this won't be time-consuming because the byte/char conversions are | |
5998 mostly in the buffer, which will be in a fixed-width format. */ | |
5999 map_extents (opoint, opoint + length, | |
6000 add_string_extents_the_hard_way_mapper, | |
6001 (void *) &closure, buffer, 0, | |
6002 /* ignore extents that just abut the region */ | |
6003 ME_END_CLOSED | ME_ALL_EXTENTS_OPEN | | |
6004 /* we are calling E-Lisp (the extent's copy function) | |
6005 so anything might happen */ | |
6006 ME_MIGHT_CALL_ELISP); | |
6007 | |
6008 } | |
6009 | |
428 | 6010 UNGCPRO; |
6011 } | |
6012 | |
6013 struct splice_in_string_extents_arg | |
6014 { | |
6015 Bytecount pos; | |
6016 Bytecount length; | |
826 | 6017 Bytexpos opoint; |
428 | 6018 Lisp_Object buffer; |
6019 }; | |
6020 | |
6021 static int | |
6022 splice_in_string_extents_mapper (EXTENT extent, void *arg) | |
6023 { | |
6024 /* This function can GC */ | |
6025 struct splice_in_string_extents_arg *closure = | |
6026 (struct splice_in_string_extents_arg *) arg; | |
6027 /* BASE_START and BASE_END are the limits in the buffer of the string | |
6028 that was just inserted. | |
826 | 6029 |
428 | 6030 NEW_START and NEW_END are the prospective buffer positions of the |
6031 extent that is going into the buffer. */ | |
826 | 6032 Bytexpos base_start = closure->opoint; |
6033 Bytexpos base_end = base_start + closure->length; | |
6034 Bytexpos new_start = (base_start + extent_endpoint_byte (extent, 0) - | |
6035 closure->pos); | |
6036 Bytexpos new_end = (base_start + extent_endpoint_byte (extent, 1) - | |
428 | 6037 closure->pos); |
6038 | |
6039 if (new_start < base_start) | |
6040 new_start = base_start; | |
6041 if (new_end > base_end) | |
6042 new_end = base_end; | |
6043 if (new_end <= new_start) | |
6044 return 0; | |
6045 | |
6046 if (!extent_duplicable_p (extent)) | |
6047 return 0; | |
6048 | |
6049 if (!inside_undo && | |
6050 !run_extent_paste_function (extent, new_start, new_end, | |
6051 closure->buffer)) | |
6052 return 0; | |
6053 copy_extent (extent, new_start, new_end, closure->buffer); | |
6054 | |
6055 return 0; | |
6056 } | |
6057 | |
826 | 6058 struct splice_in_string_extents_the_hard_way_arg |
6059 { | |
6060 Charcount pos; | |
6061 Charcount length; | |
6062 Charxpos opoint; | |
6063 Lisp_Object buffer; | |
6064 }; | |
6065 | |
6066 static int | |
6067 splice_in_string_extents_the_hard_way_mapper (EXTENT extent, void *arg) | |
6068 { | |
6069 /* This function can GC */ | |
6070 struct splice_in_string_extents_arg *closure = | |
6071 (struct splice_in_string_extents_arg *) arg; | |
6072 /* BASE_START and BASE_END are the limits in the buffer of the string | |
6073 that was just inserted. | |
6074 | |
6075 NEW_START and NEW_END are the prospective buffer positions of the | |
6076 extent that is going into the buffer. */ | |
6077 Charxpos base_start = closure->opoint; | |
6078 Charxpos base_end = base_start + closure->length; | |
6079 Charxpos new_start = (base_start + extent_endpoint_char (extent, 0) - | |
6080 closure->pos); | |
6081 Charxpos new_end = (base_start + extent_endpoint_char (extent, 1) - | |
6082 closure->pos); | |
6083 | |
6084 if (new_start < base_start) | |
6085 new_start = base_start; | |
6086 if (new_end > base_end) | |
6087 new_end = base_end; | |
6088 if (new_end <= new_start) | |
6089 return 0; | |
6090 | |
6091 if (!extent_duplicable_p (extent)) | |
6092 return 0; | |
6093 | |
6094 if (!inside_undo && | |
6095 !run_extent_paste_function_char (extent, new_start, new_end, | |
6096 closure->buffer)) | |
6097 return 0; | |
6098 copy_extent (extent, | |
6099 charbpos_to_bytebpos (XBUFFER (closure->buffer), new_start), | |
6100 charbpos_to_bytebpos (XBUFFER (closure->buffer), new_end), | |
6101 closure->buffer); | |
6102 | |
6103 return 0; | |
6104 } | |
6105 | |
428 | 6106 /* We have just inserted a section of STRING (starting at POS, of |
6107 length LENGTH) into buffer BUF at OPOINT. Do whatever is necessary | |
6108 to get the string's extents into the buffer. */ | |
6109 | |
6110 void | |
6111 splice_in_string_extents (Lisp_Object string, struct buffer *buf, | |
826 | 6112 Bytexpos opoint, Bytecount length, Bytecount pos) |
6113 { | |
428 | 6114 struct gcpro gcpro1, gcpro2; |
793 | 6115 Lisp_Object buffer = wrap_buffer (buf); |
6116 | |
428 | 6117 GCPRO2 (buffer, string); |
826 | 6118 if (XSTRING_FORMAT (string) == BUF_FORMAT (buf)) |
6119 { | |
6120 struct splice_in_string_extents_arg closure; | |
6121 closure.opoint = opoint; | |
6122 closure.pos = pos; | |
6123 closure.length = length; | |
6124 closure.buffer = buffer; | |
6125 map_extents (pos, pos + length, | |
6126 splice_in_string_extents_mapper, | |
6127 (void *) &closure, string, 0, | |
6128 /* ignore extents that just abut the region */ | |
6129 ME_END_CLOSED | ME_ALL_EXTENTS_OPEN | | |
6130 /* we are calling E-Lisp (the extent's copy function) | |
6131 so anything might happen */ | |
6132 ME_MIGHT_CALL_ELISP); | |
6133 } | |
6134 else | |
6135 { | |
6136 struct splice_in_string_extents_the_hard_way_arg closure; | |
6137 closure.opoint = bytebpos_to_charbpos (buf, opoint); | |
6138 closure.pos = string_index_byte_to_char (string, pos); | |
6139 closure.length = string_offset_byte_to_char_len (string, pos, length); | |
6140 closure.buffer = buffer; | |
6141 | |
6142 /* If the string and buffer are in different formats, things get | |
6143 tricky; the only reasonable way to do the operation is entirely in | |
6144 char offsets, which are invariant to format changes. In practice, | |
6145 this won't be time-consuming because the byte/char conversions are | |
6146 mostly in the buffer, which will be in a fixed-width format. */ | |
6147 map_extents (pos, pos + length, | |
6148 splice_in_string_extents_the_hard_way_mapper, | |
6149 (void *) &closure, string, 0, | |
6150 /* ignore extents that just abut the region */ | |
6151 ME_END_CLOSED | ME_ALL_EXTENTS_OPEN | | |
6152 /* we are calling E-Lisp (the extent's copy function) | |
6153 so anything might happen */ | |
6154 ME_MIGHT_CALL_ELISP); | |
6155 | |
6156 } | |
428 | 6157 UNGCPRO; |
6158 } | |
6159 | |
6160 struct copy_string_extents_arg | |
6161 { | |
6162 Bytecount new_pos; | |
6163 Bytecount old_pos; | |
6164 Bytecount length; | |
6165 Lisp_Object new_string; | |
6166 }; | |
6167 | |
6168 struct copy_string_extents_1_arg | |
6169 { | |
6170 Lisp_Object parent_in_question; | |
6171 EXTENT found_extent; | |
6172 }; | |
6173 | |
6174 static int | |
6175 copy_string_extents_mapper (EXTENT extent, void *arg) | |
6176 { | |
6177 struct copy_string_extents_arg *closure = | |
6178 (struct copy_string_extents_arg *) arg; | |
6179 Bytecount old_start, old_end, new_start, new_end; | |
6180 | |
826 | 6181 old_start = extent_endpoint_byte (extent, 0); |
6182 old_end = extent_endpoint_byte (extent, 1); | |
428 | 6183 |
6184 old_start = max (closure->old_pos, old_start); | |
6185 old_end = min (closure->old_pos + closure->length, old_end); | |
6186 | |
6187 if (old_start >= old_end) | |
6188 return 0; | |
6189 | |
6190 new_start = old_start + closure->new_pos - closure->old_pos; | |
6191 new_end = old_end + closure->new_pos - closure->old_pos; | |
6192 | |
6193 copy_extent (extent, new_start, new_end, closure->new_string); | |
6194 return 0; | |
6195 } | |
6196 | |
6197 /* The string NEW_STRING was partially constructed from OLD_STRING. | |
6198 In particular, the section of length LEN starting at NEW_POS in | |
6199 NEW_STRING came from the section of the same length starting at | |
6200 OLD_POS in OLD_STRING. Copy the extents as appropriate. */ | |
6201 | |
6202 void | |
6203 copy_string_extents (Lisp_Object new_string, Lisp_Object old_string, | |
6204 Bytecount new_pos, Bytecount old_pos, | |
6205 Bytecount length) | |
6206 { | |
6207 struct copy_string_extents_arg closure; | |
6208 struct gcpro gcpro1, gcpro2; | |
6209 | |
6210 closure.new_pos = new_pos; | |
6211 closure.old_pos = old_pos; | |
6212 closure.new_string = new_string; | |
6213 closure.length = length; | |
6214 GCPRO2 (new_string, old_string); | |
826 | 6215 map_extents (old_pos, old_pos + length, |
6216 copy_string_extents_mapper, | |
6217 (void *) &closure, old_string, 0, | |
6218 /* ignore extents that just abut the region */ | |
6219 ME_END_CLOSED | ME_ALL_EXTENTS_OPEN | | |
6220 /* we are calling E-Lisp (the extent's copy function) | |
6221 so anything might happen */ | |
6222 ME_MIGHT_CALL_ELISP); | |
428 | 6223 UNGCPRO; |
6224 } | |
6225 | |
6226 /* Checklist for sanity checking: | |
6227 - {kill, yank, copy} at {open, closed} {start, end} of {writable, read-only} extent | |
6228 - {kill, copy} & yank {once, repeatedly} duplicable extent in {same, different} buffer | |
6229 */ | |
6230 | |
6231 | |
6232 /************************************************************************/ | |
6233 /* text properties */ | |
6234 /************************************************************************/ | |
6235 | |
6236 /* Text properties | |
6237 Originally this stuff was implemented in lisp (all of the functionality | |
6238 exists to make that possible) but speed was a problem. | |
6239 */ | |
6240 | |
6241 Lisp_Object Qtext_prop; | |
6242 Lisp_Object Qtext_prop_extent_paste_function; | |
6243 | |
826 | 6244 /* Retrieve the value of the property PROP of the text at position POSITION |
6245 in OBJECT. TEXT-PROPS-ONLY means only look at extents with the | |
6246 `text-prop' property, i.e. extents created by the text property | |
6247 routines. Otherwise, all extents are examined. &&#### finish Note that | |
6248 the default extent_at_flag is EXTENT_AT_DEFAULT (same as | |
6249 EXTENT_AT_AFTER). */ | |
6250 Lisp_Object | |
6251 get_char_property (Bytexpos position, Lisp_Object prop, | |
6252 Lisp_Object object, enum extent_at_flag fl, | |
6253 int text_props_only) | |
428 | 6254 { |
6255 Lisp_Object extent; | |
6256 | |
6257 /* text_props_only specifies whether we only consider text-property | |
3025 | 6258 extents (those with the `text-prop' property set) or all extents. */ |
428 | 6259 if (!text_props_only) |
826 | 6260 extent = extent_at (position, object, prop, 0, fl, 0); |
428 | 6261 else |
6262 { | |
6263 EXTENT prior = 0; | |
6264 while (1) | |
6265 { | |
826 | 6266 extent = extent_at (position, object, Qtext_prop, prior, fl, 0); |
428 | 6267 if (NILP (extent)) |
6268 return Qnil; | |
6269 if (EQ (prop, Fextent_property (extent, Qtext_prop, Qnil))) | |
6270 break; | |
6271 prior = XEXTENT (extent); | |
6272 } | |
6273 } | |
6274 | |
6275 if (!NILP (extent)) | |
6276 return Fextent_property (extent, prop, Qnil); | |
6277 if (!NILP (Vdefault_text_properties)) | |
6278 return Fplist_get (Vdefault_text_properties, prop, Qnil); | |
6279 return Qnil; | |
6280 } | |
6281 | |
6282 static Lisp_Object | |
826 | 6283 get_char_property_char (Lisp_Object pos, Lisp_Object prop, Lisp_Object object, |
6284 Lisp_Object at_flag, int text_props_only) | |
6285 { | |
6286 Bytexpos position; | |
428 | 6287 int invert = 0; |
6288 | |
6289 object = decode_buffer_or_string (object); | |
6290 position = get_buffer_or_string_pos_byte (object, pos, GB_NO_ERROR_IF_BAD); | |
6291 | |
6292 /* We canonicalize the start/end-open/closed properties to the | |
6293 non-default version -- "adding" the default property really | |
6294 needs to remove the non-default one. See below for more | |
6295 on this. */ | |
6296 if (EQ (prop, Qstart_closed)) | |
6297 { | |
6298 prop = Qstart_open; | |
6299 invert = 1; | |
6300 } | |
6301 | |
6302 if (EQ (prop, Qend_open)) | |
6303 { | |
6304 prop = Qend_closed; | |
6305 invert = 1; | |
6306 } | |
6307 | |
6308 { | |
6309 Lisp_Object val = | |
826 | 6310 get_char_property (position, prop, object, |
6311 decode_extent_at_flag (at_flag), | |
6312 text_props_only); | |
428 | 6313 if (invert) |
6314 val = NILP (val) ? Qt : Qnil; | |
6315 return val; | |
6316 } | |
6317 } | |
6318 | |
6319 DEFUN ("get-text-property", Fget_text_property, 2, 4, 0, /* | |
6320 Return the value of the PROP property at the given position. | |
6321 Optional arg OBJECT specifies the buffer or string to look in, and | |
6322 defaults to the current buffer. | |
6323 Optional arg AT-FLAG controls what it means for a property to be "at" | |
6324 a position, and has the same meaning as in `extent-at'. | |
6325 This examines only those properties added with `put-text-property'. | |
6326 See also `get-char-property'. | |
6327 */ | |
6328 (pos, prop, object, at_flag)) | |
6329 { | |
826 | 6330 return get_char_property_char (pos, prop, object, at_flag, 1); |
428 | 6331 } |
6332 | |
6333 DEFUN ("get-char-property", Fget_char_property, 2, 4, 0, /* | |
6334 Return the value of the PROP property at the given position. | |
6335 Optional arg OBJECT specifies the buffer or string to look in, and | |
6336 defaults to the current buffer. | |
6337 Optional arg AT-FLAG controls what it means for a property to be "at" | |
6338 a position, and has the same meaning as in `extent-at'. | |
6339 This examines properties on all extents. | |
6340 See also `get-text-property'. | |
6341 */ | |
6342 (pos, prop, object, at_flag)) | |
6343 { | |
826 | 6344 return get_char_property_char (pos, prop, object, at_flag, 0); |
428 | 6345 } |
6346 | |
6347 /* About start/end-open/closed: | |
6348 | |
6349 These properties have to be handled specially because of their | |
6350 strange behavior. If I put the "start-open" property on a region, | |
6351 then *all* text-property extents in the region have to have their | |
6352 start be open. This is unlike all other properties, which don't | |
6353 affect the extents of text properties other than their own. | |
6354 | |
6355 So: | |
6356 | |
6357 1) We have to map start-closed to (not start-open) and end-open | |
6358 to (not end-closed) -- i.e. adding the default is really the | |
6359 same as remove the non-default property. It won't work, for | |
6360 example, to have both "start-open" and "start-closed" on | |
6361 the same region. | |
6362 2) Whenever we add one of these properties, we go through all | |
6363 text-property extents in the region and set the appropriate | |
6364 open/closedness on them. | |
6365 3) Whenever we change a text-property extent for a property, | |
6366 we have to make sure we set the open/closedness properly. | |
6367 | |
6368 (2) and (3) together rely on, and maintain, the invariant | |
6369 that the open/closedness of text-property extents is correct | |
6370 at the beginning and end of each operation. | |
6371 */ | |
6372 | |
6373 struct put_text_prop_arg | |
6374 { | |
6375 Lisp_Object prop, value; /* The property and value we are storing */ | |
826 | 6376 Bytexpos start, end; /* The region into which we are storing it */ |
428 | 6377 Lisp_Object object; |
6378 Lisp_Object the_extent; /* Our chosen extent; this is used for | |
6379 communication between subsequent passes. */ | |
6380 int changed_p; /* Output: whether we have modified anything */ | |
6381 }; | |
6382 | |
6383 static int | |
6384 put_text_prop_mapper (EXTENT e, void *arg) | |
6385 { | |
6386 struct put_text_prop_arg *closure = (struct put_text_prop_arg *) arg; | |
6387 | |
6388 Lisp_Object object = closure->object; | |
6389 Lisp_Object value = closure->value; | |
826 | 6390 Bytexpos e_start, e_end; |
6391 Bytexpos start = closure->start; | |
6392 Bytexpos end = closure->end; | |
428 | 6393 Lisp_Object extent, e_val; |
6394 int is_eq; | |
6395 | |
793 | 6396 extent = wrap_extent (e); |
428 | 6397 |
3025 | 6398 /* Note: in some cases when the property itself is `start-open' |
6399 or `end-closed', the checks to set the openness may do a bit | |
428 | 6400 of extra work; but it won't hurt because we then fix up the |
6401 openness later on in put_text_prop_openness_mapper(). */ | |
6402 if (!EQ (Fextent_property (extent, Qtext_prop, Qnil), closure->prop)) | |
6403 /* It's not for this property; do nothing. */ | |
6404 return 0; | |
6405 | |
826 | 6406 e_start = extent_endpoint_byte (e, 0); |
6407 e_end = extent_endpoint_byte (e, 1); | |
428 | 6408 e_val = Fextent_property (extent, closure->prop, Qnil); |
6409 is_eq = EQ (value, e_val); | |
6410 | |
6411 if (!NILP (value) && NILP (closure->the_extent) && is_eq) | |
6412 { | |
6413 /* We want there to be an extent here at the end, and we haven't picked | |
6414 one yet, so use this one. Extend it as necessary. We only reuse an | |
6415 extent which has an EQ value for the prop in question to avoid | |
6416 side-effecting the kill ring (that is, we never change the property | |
6417 on an extent after it has been created.) | |
6418 */ | |
6419 if (e_start != start || e_end != end) | |
6420 { | |
826 | 6421 Bytexpos new_start = min (e_start, start); |
6422 Bytexpos new_end = max (e_end, end); | |
428 | 6423 set_extent_endpoints (e, new_start, new_end, Qnil); |
6424 /* If we changed the endpoint, then we need to set its | |
6425 openness. */ | |
6426 set_extent_openness (e, new_start != e_start | |
826 | 6427 ? !NILP (get_char_property |
428 | 6428 (start, Qstart_open, object, |
6429 EXTENT_AT_AFTER, 1)) : -1, | |
6430 new_end != e_end | |
826 | 6431 ? NILP (get_char_property |
6432 (prev_bytexpos (object, end), | |
6433 Qend_closed, object, | |
428 | 6434 EXTENT_AT_AFTER, 1)) |
6435 : -1); | |
6436 closure->changed_p = 1; | |
6437 } | |
6438 closure->the_extent = extent; | |
6439 } | |
6440 | |
6441 /* Even if we're adding a prop, at this point, we want all other extents of | |
6442 this prop to go away (as now they overlap). So the theory here is that, | |
6443 when we are adding a prop to a region that has multiple (disjoint) | |
6444 occurrences of that prop in it already, we pick one of those and extend | |
6445 it, and remove the others. | |
6446 */ | |
6447 | |
6448 else if (EQ (extent, closure->the_extent)) | |
6449 { | |
6450 /* just in case map-extents hits it again (does that happen?) */ | |
6451 ; | |
6452 } | |
6453 else if (e_start >= start && e_end <= end) | |
6454 { | |
6455 /* Extent is contained in region; remove it. Don't destroy or modify | |
6456 it, because we don't want to change the attributes pointed to by the | |
6457 duplicates in the kill ring. | |
6458 */ | |
6459 extent_detach (e); | |
6460 closure->changed_p = 1; | |
6461 } | |
6462 else if (!NILP (closure->the_extent) && | |
6463 is_eq && | |
6464 e_start <= end && | |
6465 e_end >= start) | |
6466 { | |
6467 EXTENT te = XEXTENT (closure->the_extent); | |
6468 /* This extent overlaps, and has the same prop/value as the extent we've | |
6469 decided to reuse, so we can remove this existing extent as well (the | |
6470 whole thing, even the part outside of the region) and extend | |
6471 the-extent to cover it, resulting in the minimum number of extents in | |
6472 the buffer. | |
6473 */ | |
826 | 6474 Bytexpos the_start = extent_endpoint_byte (te, 0); |
6475 Bytexpos the_end = extent_endpoint_byte (te, 1); | |
428 | 6476 if (e_start != the_start && /* note AND not OR -- hmm, why is this |
6477 the case? I think it's because the | |
6478 assumption that the text-property | |
6479 extents don't overlap makes it | |
6480 OK; changing it to an OR would | |
6481 result in changed_p sometimes getting | |
6482 falsely marked. Is this bad? */ | |
6483 e_end != the_end) | |
6484 { | |
826 | 6485 Bytexpos new_start = min (e_start, the_start); |
6486 Bytexpos new_end = max (e_end, the_end); | |
428 | 6487 set_extent_endpoints (te, new_start, new_end, Qnil); |
6488 /* If we changed the endpoint, then we need to set its | |
6489 openness. We are setting the endpoint to be the same as | |
6490 that of the extent we're about to remove, and we assume | |
6491 (the invariant mentioned above) that extent has the | |
6492 proper endpoint setting, so we just use it. */ | |
6493 set_extent_openness (te, new_start != e_start ? | |
6494 (int) extent_start_open_p (e) : -1, | |
6495 new_end != e_end ? | |
6496 (int) extent_end_open_p (e) : -1); | |
6497 closure->changed_p = 1; | |
6498 } | |
6499 extent_detach (e); | |
6500 } | |
6501 else if (e_end <= end) | |
6502 { | |
6503 /* Extent begins before start but ends before end, so we can just | |
6504 decrease its end position. | |
6505 */ | |
6506 if (e_end != start) | |
6507 { | |
6508 set_extent_endpoints (e, e_start, start, Qnil); | |
826 | 6509 set_extent_openness (e, -1, |
6510 NILP (get_char_property | |
6511 (prev_bytexpos (object, start), | |
6512 Qend_closed, object, | |
6513 EXTENT_AT_AFTER, 1))); | |
428 | 6514 closure->changed_p = 1; |
6515 } | |
6516 } | |
6517 else if (e_start >= start) | |
6518 { | |
6519 /* Extent ends after end but begins after start, so we can just | |
6520 increase its start position. | |
6521 */ | |
6522 if (e_start != end) | |
6523 { | |
6524 set_extent_endpoints (e, end, e_end, Qnil); | |
826 | 6525 set_extent_openness (e, !NILP (get_char_property |
428 | 6526 (end, Qstart_open, object, |
6527 EXTENT_AT_AFTER, 1)), -1); | |
6528 closure->changed_p = 1; | |
6529 } | |
6530 } | |
6531 else | |
6532 { | |
6533 /* Otherwise, `extent' straddles the region. We need to split it. | |
6534 */ | |
6535 set_extent_endpoints (e, e_start, start, Qnil); | |
826 | 6536 set_extent_openness (e, -1, NILP (get_char_property |
6537 (prev_bytexpos (object, start), | |
6538 Qend_closed, object, | |
428 | 6539 EXTENT_AT_AFTER, 1))); |
6540 set_extent_openness (copy_extent (e, end, e_end, extent_object (e)), | |
826 | 6541 !NILP (get_char_property |
428 | 6542 (end, Qstart_open, object, |
6543 EXTENT_AT_AFTER, 1)), -1); | |
6544 closure->changed_p = 1; | |
6545 } | |
6546 | |
6547 return 0; /* to continue mapping. */ | |
6548 } | |
6549 | |
6550 static int | |
6551 put_text_prop_openness_mapper (EXTENT e, void *arg) | |
6552 { | |
6553 struct put_text_prop_arg *closure = (struct put_text_prop_arg *) arg; | |
826 | 6554 Bytexpos e_start, e_end; |
6555 Bytexpos start = closure->start; | |
6556 Bytexpos end = closure->end; | |
793 | 6557 Lisp_Object extent = wrap_extent (e); |
6558 | |
826 | 6559 e_start = extent_endpoint_byte (e, 0); |
6560 e_end = extent_endpoint_byte (e, 1); | |
428 | 6561 |
6562 if (NILP (Fextent_property (extent, Qtext_prop, Qnil))) | |
6563 { | |
6564 /* It's not a text-property extent; do nothing. */ | |
6565 ; | |
6566 } | |
6567 /* Note end conditions and NILP/!NILP's carefully. */ | |
6568 else if (EQ (closure->prop, Qstart_open) | |
6569 && e_start >= start && e_start < end) | |
6570 set_extent_openness (e, !NILP (closure->value), -1); | |
6571 else if (EQ (closure->prop, Qend_closed) | |
6572 && e_end > start && e_end <= end) | |
6573 set_extent_openness (e, -1, NILP (closure->value)); | |
6574 | |
6575 return 0; /* to continue mapping. */ | |
6576 } | |
6577 | |
6578 static int | |
826 | 6579 put_text_prop (Bytexpos start, Bytexpos end, Lisp_Object object, |
428 | 6580 Lisp_Object prop, Lisp_Object value, |
6581 int duplicable_p) | |
6582 { | |
6583 /* This function can GC */ | |
6584 struct put_text_prop_arg closure; | |
6585 | |
6586 if (start == end) /* There are no characters in the region. */ | |
6587 return 0; | |
6588 | |
6589 /* convert to the non-default versions, since a nil property is | |
6590 the same as it not being present. */ | |
6591 if (EQ (prop, Qstart_closed)) | |
6592 { | |
6593 prop = Qstart_open; | |
6594 value = NILP (value) ? Qt : Qnil; | |
6595 } | |
6596 else if (EQ (prop, Qend_open)) | |
6597 { | |
6598 prop = Qend_closed; | |
6599 value = NILP (value) ? Qt : Qnil; | |
6600 } | |
6601 | |
6602 value = canonicalize_extent_property (prop, value); | |
6603 | |
6604 closure.prop = prop; | |
6605 closure.value = value; | |
6606 closure.start = start; | |
6607 closure.end = end; | |
6608 closure.object = object; | |
6609 closure.changed_p = 0; | |
6610 closure.the_extent = Qnil; | |
6611 | |
826 | 6612 map_extents (start, end, |
6613 put_text_prop_mapper, | |
6614 (void *) &closure, object, 0, | |
6615 /* get all extents that abut the region */ | |
6616 ME_ALL_EXTENTS_CLOSED | ME_END_CLOSED | | |
6617 #if 0 | |
6618 /* it might move the SOE because the callback function calls | |
6619 get_char_property(), which calls extent_at(), which calls | |
6620 map_extents() | |
6621 | |
6622 #### this was comment out before, and nothing seemed broken; | |
6623 #### but when I added the above comment and uncommented it, | |
6624 #### text property operations (e.g. font-lock) suddenly | |
6625 #### became *WAY* slow, and dominated font-lock, when a | |
6626 #### single extent spanning the entire buffer | |
6627 #### existed. --ben */ | |
6628 ME_MIGHT_MOVE_SOE | | |
6629 #endif | |
6630 /* it might QUIT or error if the user has | |
6631 fucked with the extent plist. */ | |
6632 ME_MIGHT_THROW | | |
6633 ME_MIGHT_MODIFY_EXTENTS); | |
428 | 6634 |
6635 /* If we made it through the loop without reusing an extent | |
6636 (and we want there to be one) make it now. | |
6637 */ | |
6638 if (!NILP (value) && NILP (closure.the_extent)) | |
6639 { | |
826 | 6640 Lisp_Object extent = |
6641 wrap_extent (make_extent (object, start, end)); | |
793 | 6642 |
428 | 6643 closure.changed_p = 1; |
6644 Fset_extent_property (extent, Qtext_prop, prop); | |
6645 Fset_extent_property (extent, prop, value); | |
6646 if (duplicable_p) | |
6647 { | |
6648 extent_duplicable_p (XEXTENT (extent)) = 1; | |
6649 Fset_extent_property (extent, Qpaste_function, | |
6650 Qtext_prop_extent_paste_function); | |
6651 } | |
6652 set_extent_openness (XEXTENT (extent), | |
826 | 6653 !NILP (get_char_property |
428 | 6654 (start, Qstart_open, object, |
6655 EXTENT_AT_AFTER, 1)), | |
826 | 6656 NILP (get_char_property |
6657 (prev_bytexpos (object, end), | |
6658 Qend_closed, object, | |
428 | 6659 EXTENT_AT_AFTER, 1))); |
6660 } | |
6661 | |
6662 if (EQ (prop, Qstart_open) || EQ (prop, Qend_closed)) | |
6663 { | |
826 | 6664 map_extents (start, end, put_text_prop_openness_mapper, |
6665 (void *) &closure, object, 0, | |
6666 /* get all extents that abut the region */ | |
6667 ME_ALL_EXTENTS_CLOSED | ME_END_CLOSED | | |
6668 ME_MIGHT_MODIFY_EXTENTS); | |
428 | 6669 } |
6670 | |
6671 return closure.changed_p; | |
6672 } | |
6673 | |
6674 DEFUN ("put-text-property", Fput_text_property, 4, 5, 0, /* | |
6675 Adds the given property/value to all characters in the specified region. | |
6676 The property is conceptually attached to the characters rather than the | |
6677 region. The properties are copied when the characters are copied/pasted. | |
6678 Fifth argument OBJECT is the buffer or string containing the text, and | |
6679 defaults to the current buffer. | |
6680 */ | |
6681 (start, end, prop, value, object)) | |
6682 { | |
6683 /* This function can GC */ | |
826 | 6684 Bytexpos s, e; |
428 | 6685 |
6686 object = decode_buffer_or_string (object); | |
6687 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0); | |
6688 put_text_prop (s, e, object, prop, value, 1); | |
6689 return prop; | |
6690 } | |
6691 | |
6692 DEFUN ("put-nonduplicable-text-property", Fput_nonduplicable_text_property, | |
6693 4, 5, 0, /* | |
6694 Adds the given property/value to all characters in the specified region. | |
6695 The property is conceptually attached to the characters rather than the | |
6696 region, however the properties will not be copied when the characters | |
6697 are copied. | |
6698 Fifth argument OBJECT is the buffer or string containing the text, and | |
6699 defaults to the current buffer. | |
6700 */ | |
6701 (start, end, prop, value, object)) | |
6702 { | |
6703 /* This function can GC */ | |
826 | 6704 Bytexpos s, e; |
428 | 6705 |
6706 object = decode_buffer_or_string (object); | |
6707 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0); | |
6708 put_text_prop (s, e, object, prop, value, 0); | |
6709 return prop; | |
6710 } | |
6711 | |
6712 DEFUN ("add-text-properties", Fadd_text_properties, 3, 4, 0, /* | |
6713 Add properties to the characters from START to END. | |
6714 The third argument PROPS is a property list specifying the property values | |
6715 to add. The optional fourth argument, OBJECT, is the buffer or string | |
6716 containing the text and defaults to the current buffer. Returns t if | |
6717 any property was changed, nil otherwise. | |
6718 */ | |
6719 (start, end, props, object)) | |
6720 { | |
6721 /* This function can GC */ | |
6722 int changed = 0; | |
826 | 6723 Bytexpos s, e; |
428 | 6724 |
6725 object = decode_buffer_or_string (object); | |
6726 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0); | |
6727 CHECK_LIST (props); | |
6728 for (; !NILP (props); props = Fcdr (Fcdr (props))) | |
6729 { | |
6730 Lisp_Object prop = XCAR (props); | |
6731 Lisp_Object value = Fcar (XCDR (props)); | |
6732 changed |= put_text_prop (s, e, object, prop, value, 1); | |
6733 } | |
6734 return changed ? Qt : Qnil; | |
6735 } | |
6736 | |
6737 | |
6738 DEFUN ("add-nonduplicable-text-properties", Fadd_nonduplicable_text_properties, | |
6739 3, 4, 0, /* | |
6740 Add nonduplicable properties to the characters from START to END. | |
6741 \(The properties will not be copied when the characters are copied.) | |
6742 The third argument PROPS is a property list specifying the property values | |
6743 to add. The optional fourth argument, OBJECT, is the buffer or string | |
6744 containing the text and defaults to the current buffer. Returns t if | |
6745 any property was changed, nil otherwise. | |
6746 */ | |
6747 (start, end, props, object)) | |
6748 { | |
6749 /* This function can GC */ | |
6750 int changed = 0; | |
826 | 6751 Bytexpos s, e; |
428 | 6752 |
6753 object = decode_buffer_or_string (object); | |
6754 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0); | |
6755 CHECK_LIST (props); | |
6756 for (; !NILP (props); props = Fcdr (Fcdr (props))) | |
6757 { | |
6758 Lisp_Object prop = XCAR (props); | |
6759 Lisp_Object value = Fcar (XCDR (props)); | |
6760 changed |= put_text_prop (s, e, object, prop, value, 0); | |
6761 } | |
6762 return changed ? Qt : Qnil; | |
6763 } | |
6764 | |
6765 DEFUN ("remove-text-properties", Fremove_text_properties, 3, 4, 0, /* | |
6766 Remove the given properties from all characters in the specified region. | |
6767 PROPS should be a plist, but the values in that plist are ignored (treated | |
6768 as nil). Returns t if any property was changed, nil otherwise. | |
6769 Fourth argument OBJECT is the buffer or string containing the text, and | |
6770 defaults to the current buffer. | |
6771 */ | |
6772 (start, end, props, object)) | |
6773 { | |
6774 /* This function can GC */ | |
6775 int changed = 0; | |
826 | 6776 Bytexpos s, e; |
428 | 6777 |
6778 object = decode_buffer_or_string (object); | |
6779 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0); | |
6780 CHECK_LIST (props); | |
6781 for (; !NILP (props); props = Fcdr (Fcdr (props))) | |
6782 { | |
6783 Lisp_Object prop = XCAR (props); | |
6784 changed |= put_text_prop (s, e, object, prop, Qnil, 1); | |
6785 } | |
6786 return changed ? Qt : Qnil; | |
6787 } | |
6788 | |
6789 /* Whenever a text-prop extent is pasted into a buffer (via `yank' or `insert' | |
6790 or whatever) we attach the properties to the buffer by calling | |
6791 `put-text-property' instead of by simply allowing the extent to be copied or | |
6792 re-attached. Then we return nil, telling the extents code not to attach it | |
6793 again. By handing the insertion hackery in this way, we make kill/yank | |
6794 behave consistently with put-text-property and not fragment the extents | |
6795 (since text-prop extents must partition, not overlap). | |
6796 | |
6797 The lisp implementation of this was probably fast enough, but since I moved | |
6798 the rest of the put-text-prop code here, I moved this as well for | |
6799 completeness. | |
6800 */ | |
6801 DEFUN ("text-prop-extent-paste-function", Ftext_prop_extent_paste_function, | |
6802 3, 3, 0, /* | |
6803 Used as the `paste-function' property of `text-prop' extents. | |
6804 */ | |
6805 (extent, from, to)) | |
6806 { | |
6807 /* This function can GC */ | |
6808 Lisp_Object prop, val; | |
6809 | |
6810 prop = Fextent_property (extent, Qtext_prop, Qnil); | |
6811 if (NILP (prop)) | |
563 | 6812 signal_error (Qinternal_error, |
442 | 6813 "Internal error: no text-prop", extent); |
428 | 6814 val = Fextent_property (extent, prop, Qnil); |
6815 #if 0 | |
6816 /* removed by bill perry, 2/9/97 | |
6817 ** This little bit of code would not allow you to have a text property | |
6818 ** with a value of Qnil. This is bad bad bad. | |
6819 */ | |
6820 if (NILP (val)) | |
563 | 6821 signal_error_2 (Qinternal_error, |
442 | 6822 "Internal error: no text-prop", |
6823 extent, prop); | |
428 | 6824 #endif |
6825 Fput_text_property (from, to, prop, val, Qnil); | |
6826 return Qnil; /* important! */ | |
6827 } | |
6828 | |
826 | 6829 Bytexpos |
2506 | 6830 next_previous_single_property_change (Bytexpos pos, Lisp_Object prop, |
6831 Lisp_Object object, Bytexpos limit, | |
6832 Boolint next, Boolint text_props_only) | |
826 | 6833 { |
6834 Lisp_Object extent, value; | |
6835 int limit_was_nil; | |
2506 | 6836 enum extent_at_flag at_flag = next ? EXTENT_AT_AFTER : EXTENT_AT_BEFORE; |
826 | 6837 if (limit < 0) |
6838 { | |
2506 | 6839 limit = (next ? buffer_or_string_accessible_end_byte : |
6840 buffer_or_string_accessible_begin_byte) (object); | |
826 | 6841 limit_was_nil = 1; |
6842 } | |
6843 else | |
6844 limit_was_nil = 0; | |
6845 | |
2506 | 6846 /* Retrieve initial property value to compare against */ |
6847 extent = extent_at (pos, object, prop, 0, at_flag, 0); | |
6848 /* If we only want text-prop extents, ignore all others */ | |
6849 if (text_props_only && !NILP (extent) && | |
6850 NILP (Fextent_property (extent, Qtext_prop, Qnil))) | |
6851 extent = Qnil; | |
826 | 6852 if (!NILP (extent)) |
6853 value = Fextent_property (extent, prop, Qnil); | |
6854 else | |
6855 value = Qnil; | |
6856 | |
6857 while (1) | |
6858 { | |
2506 | 6859 pos = (next ? extent_find_end_of_run : extent_find_beginning_of_run) |
6860 (object, pos, 1); | |
6861 if (next ? pos >= limit : pos <= limit) | |
6862 break; /* property is the same all the way to the beginning/end */ | |
6863 extent = extent_at (pos, object, prop, 0, at_flag, 0); | |
6864 /* If we only want text-prop extents, ignore all others */ | |
6865 if (text_props_only && !NILP (extent) && | |
6866 NILP (Fextent_property (extent, Qtext_prop, Qnil))) | |
6867 extent = Qnil; | |
826 | 6868 if ((NILP (extent) && !NILP (value)) || |
6869 (!NILP (extent) && !EQ (value, | |
6870 Fextent_property (extent, prop, Qnil)))) | |
6871 return pos; | |
6872 } | |
6873 | |
6874 if (limit_was_nil) | |
6875 return -1; | |
6876 else | |
6877 return limit; | |
6878 } | |
6879 | |
2506 | 6880 static Lisp_Object |
6881 next_previous_single_property_change_fn (Lisp_Object pos, Lisp_Object prop, | |
6882 Lisp_Object object, Lisp_Object limit, | |
6883 Boolint next, Boolint text_props_only) | |
6884 { | |
6885 Bytexpos xpos; | |
6886 Bytexpos blim; | |
6887 | |
6888 object = decode_buffer_or_string (object); | |
6889 xpos = get_buffer_or_string_pos_byte (object, pos, 0); | |
6890 blim = !NILP (limit) ? get_buffer_or_string_pos_byte (object, limit, 0) : -1; | |
6891 blim = next_previous_single_property_change (xpos, prop, object, blim, | |
6892 next, text_props_only); | |
6893 | |
6894 if (blim < 0) | |
6895 return Qnil; | |
826 | 6896 else |
2506 | 6897 return make_int (buffer_or_string_bytexpos_to_charxpos (object, blim)); |
826 | 6898 } |
428 | 6899 |
6900 DEFUN ("next-single-property-change", Fnext_single_property_change, | |
6901 2, 4, 0, /* | |
6902 Return the position of next property change for a specific property. | |
6903 Scans characters forward from POS till it finds a change in the PROP | |
6904 property, then returns the position of the change. The optional third | |
6905 argument OBJECT is the buffer or string to scan (defaults to the current | |
6906 buffer). | |
6907 The property values are compared with `eq'. | |
444 | 6908 Return nil if the property is constant all the way to the end of OBJECT. |
428 | 6909 If the value is non-nil, it is a position greater than POS, never equal. |
6910 | |
6911 If the optional fourth argument LIMIT is non-nil, don't search | |
6912 past position LIMIT; return LIMIT if nothing is found before LIMIT. | |
6913 If two or more extents with conflicting non-nil values for PROP overlap | |
6914 a particular character, it is undefined which value is considered to be | |
6915 the value of PROP. (Note that this situation will not happen if you always | |
6916 use the text-property primitives.) | |
2506 | 6917 |
6918 This function looks only at extents created using the text-property primitives. | |
6919 To look at all extents, use `next-single-char-property-change'. | |
428 | 6920 */ |
6921 (pos, prop, object, limit)) | |
6922 { | |
2506 | 6923 return next_previous_single_property_change_fn (pos, prop, object, limit, |
6924 1, 1); | |
826 | 6925 } |
428 | 6926 |
6927 DEFUN ("previous-single-property-change", Fprevious_single_property_change, | |
6928 2, 4, 0, /* | |
6929 Return the position of next property change for a specific property. | |
6930 Scans characters backward from POS till it finds a change in the PROP | |
6931 property, then returns the position of the change. The optional third | |
6932 argument OBJECT is the buffer or string to scan (defaults to the current | |
6933 buffer). | |
6934 The property values are compared with `eq'. | |
444 | 6935 Return nil if the property is constant all the way to the start of OBJECT. |
428 | 6936 If the value is non-nil, it is a position less than POS, never equal. |
6937 | |
6938 If the optional fourth argument LIMIT is non-nil, don't search back | |
6939 past position LIMIT; return LIMIT if nothing is found until LIMIT. | |
6940 If two or more extents with conflicting non-nil values for PROP overlap | |
6941 a particular character, it is undefined which value is considered to be | |
6942 the value of PROP. (Note that this situation will not happen if you always | |
6943 use the text-property primitives.) | |
2506 | 6944 |
6945 This function looks only at extents created using the text-property primitives. | |
5147
b0ab9aa48977
fix up doc of next-single-char-property-change and friends
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
6946 To look at all extents, use `previous-single-char-property-change'. |
2506 | 6947 */ |
6948 (pos, prop, object, limit)) | |
6949 { | |
6950 return next_previous_single_property_change_fn (pos, prop, object, limit, | |
6951 0, 1); | |
6952 } | |
6953 | |
6954 DEFUN ("next-single-char-property-change", Fnext_single_char_property_change, | |
6955 2, 4, 0, /* | |
6956 Return the position of next property change for a specific property. | |
6957 Scans characters forward from POS till it finds a change in the PROP | |
6958 property, then returns the position of the change. The optional third | |
6959 argument OBJECT is the buffer or string to scan (defaults to the current | |
6960 buffer). | |
6961 The property values are compared with `eq'. | |
6962 Return nil if the property is constant all the way to the end of OBJECT. | |
6963 If the value is non-nil, it is a position greater than POS, never equal. | |
6964 | |
6965 If the optional fourth argument LIMIT is non-nil, don't search | |
6966 past position LIMIT; return LIMIT if nothing is found before LIMIT. | |
6967 If two or more extents with conflicting non-nil values for PROP overlap | |
6968 a particular character, it is undefined which value is considered to be | |
6969 the value of PROP. (Note that this situation will not happen if you always | |
6970 use the text-property primitives.) | |
6971 | |
6972 This function looks at all extents. To look at only extents created using the | |
5147
b0ab9aa48977
fix up doc of next-single-char-property-change and friends
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
6973 text-property primitives, use `next-single-property-change'. |
428 | 6974 */ |
6975 (pos, prop, object, limit)) | |
6976 { | |
2506 | 6977 return next_previous_single_property_change_fn (pos, prop, object, limit, |
6978 1, 0); | |
6979 } | |
6980 | |
6981 DEFUN ("previous-single-char-property-change", | |
6982 Fprevious_single_char_property_change, | |
6983 2, 4, 0, /* | |
6984 Return the position of next property change for a specific property. | |
6985 Scans characters backward from POS till it finds a change in the PROP | |
6986 property, then returns the position of the change. The optional third | |
6987 argument OBJECT is the buffer or string to scan (defaults to the current | |
6988 buffer). | |
6989 The property values are compared with `eq'. | |
6990 Return nil if the property is constant all the way to the start of OBJECT. | |
6991 If the value is non-nil, it is a position less than POS, never equal. | |
6992 | |
6993 If the optional fourth argument LIMIT is non-nil, don't search back | |
6994 past position LIMIT; return LIMIT if nothing is found until LIMIT. | |
6995 If two or more extents with conflicting non-nil values for PROP overlap | |
6996 a particular character, it is undefined which value is considered to be | |
6997 the value of PROP. (Note that this situation will not happen if you always | |
6998 use the text-property primitives.) | |
6999 | |
7000 This function looks at all extents. To look at only extents created using the | |
5147
b0ab9aa48977
fix up doc of next-single-char-property-change and friends
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
7001 text-property primitives, use `previous-single-property-change'. |
2506 | 7002 */ |
7003 (pos, prop, object, limit)) | |
7004 { | |
7005 return next_previous_single_property_change_fn (pos, prop, object, limit, | |
7006 0, 0); | |
428 | 7007 } |
7008 | |
7009 #ifdef MEMORY_USAGE_STATS | |
7010 | |
7011 int | |
2286 | 7012 compute_buffer_extent_usage (struct buffer *UNUSED (b), |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7013 struct usage_stats *UNUSED (ustats)) |
428 | 7014 { |
7015 /* #### not yet written */ | |
7016 return 0; | |
7017 } | |
7018 | |
7019 #endif /* MEMORY_USAGE_STATS */ | |
7020 | |
7021 | |
7022 /************************************************************************/ | |
7023 /* initialization */ | |
7024 /************************************************************************/ | |
7025 | |
7026 void | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7027 extent_objects_create (void) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7028 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7029 OBJECT_HAS_METHOD (extent, getprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7030 OBJECT_HAS_METHOD (extent, putprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7031 OBJECT_HAS_METHOD (extent, remprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7032 OBJECT_HAS_METHOD (extent, plist); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7033 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7034 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5147
diff
changeset
|
7035 void |
428 | 7036 syms_of_extents (void) |
7037 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
7038 INIT_LISP_OBJECT (extent); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
7039 INIT_LISP_OBJECT (extent_info); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
7040 INIT_LISP_OBJECT (extent_auxiliary); |
3092 | 7041 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
7042 INIT_LISP_OBJECT (extent_list_marker); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
7043 INIT_LISP_OBJECT (extent_list); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
7044 INIT_LISP_OBJECT (stack_of_extents); |
3263 | 7045 #endif /* NEW_GC */ |
442 | 7046 |
563 | 7047 DEFSYMBOL (Qextentp); |
7048 DEFSYMBOL (Qextent_live_p); | |
7049 | |
7050 DEFSYMBOL (Qall_extents_closed); | |
7051 DEFSYMBOL (Qall_extents_open); | |
7052 DEFSYMBOL (Qall_extents_closed_open); | |
7053 DEFSYMBOL (Qall_extents_open_closed); | |
7054 DEFSYMBOL (Qstart_in_region); | |
7055 DEFSYMBOL (Qend_in_region); | |
7056 DEFSYMBOL (Qstart_and_end_in_region); | |
7057 DEFSYMBOL (Qstart_or_end_in_region); | |
7058 DEFSYMBOL (Qnegate_in_region); | |
7059 | |
7060 DEFSYMBOL (Qdetached); | |
7061 DEFSYMBOL (Qdestroyed); | |
7062 DEFSYMBOL (Qbegin_glyph); | |
7063 DEFSYMBOL (Qend_glyph); | |
7064 DEFSYMBOL (Qstart_open); | |
7065 DEFSYMBOL (Qend_open); | |
7066 DEFSYMBOL (Qstart_closed); | |
7067 DEFSYMBOL (Qend_closed); | |
7068 DEFSYMBOL (Qread_only); | |
7069 /* DEFSYMBOL (Qhighlight); in faces.c */ | |
7070 DEFSYMBOL (Qunique); | |
7071 DEFSYMBOL (Qduplicable); | |
7072 DEFSYMBOL (Qdetachable); | |
7073 DEFSYMBOL (Qpriority); | |
7074 DEFSYMBOL (Qmouse_face); | |
7075 DEFSYMBOL (Qinitial_redisplay_function); | |
7076 | |
7077 | |
7078 DEFSYMBOL (Qglyph_layout); /* backwards compatibility */ | |
7079 DEFSYMBOL (Qbegin_glyph_layout); | |
7080 DEFSYMBOL (Qend_glyph_layout); | |
7081 DEFSYMBOL (Qoutside_margin); | |
7082 DEFSYMBOL (Qinside_margin); | |
7083 DEFSYMBOL (Qwhitespace); | |
428 | 7084 /* Qtext defined in general.c */ |
7085 | |
563 | 7086 DEFSYMBOL (Qpaste_function); |
7087 DEFSYMBOL (Qcopy_function); | |
7088 | |
7089 DEFSYMBOL (Qtext_prop); | |
7090 DEFSYMBOL (Qtext_prop_extent_paste_function); | |
428 | 7091 |
7092 DEFSUBR (Fextentp); | |
7093 DEFSUBR (Fextent_live_p); | |
7094 DEFSUBR (Fextent_detached_p); | |
7095 DEFSUBR (Fextent_start_position); | |
7096 DEFSUBR (Fextent_end_position); | |
7097 DEFSUBR (Fextent_object); | |
7098 DEFSUBR (Fextent_length); | |
7099 | |
7100 DEFSUBR (Fmake_extent); | |
7101 DEFSUBR (Fcopy_extent); | |
7102 DEFSUBR (Fdelete_extent); | |
7103 DEFSUBR (Fdetach_extent); | |
7104 DEFSUBR (Fset_extent_endpoints); | |
7105 DEFSUBR (Fnext_extent); | |
7106 DEFSUBR (Fprevious_extent); | |
1204 | 7107 #ifdef DEBUG_XEMACS |
428 | 7108 DEFSUBR (Fnext_e_extent); |
7109 DEFSUBR (Fprevious_e_extent); | |
7110 #endif | |
7111 DEFSUBR (Fnext_extent_change); | |
7112 DEFSUBR (Fprevious_extent_change); | |
7113 | |
7114 DEFSUBR (Fextent_parent); | |
7115 DEFSUBR (Fextent_children); | |
7116 DEFSUBR (Fset_extent_parent); | |
7117 | |
7118 DEFSUBR (Fextent_in_region_p); | |
7119 DEFSUBR (Fmap_extents); | |
7120 DEFSUBR (Fmap_extent_children); | |
7121 DEFSUBR (Fextent_at); | |
442 | 7122 DEFSUBR (Fextents_at); |
428 | 7123 |
7124 DEFSUBR (Fset_extent_initial_redisplay_function); | |
7125 DEFSUBR (Fextent_face); | |
7126 DEFSUBR (Fset_extent_face); | |
7127 DEFSUBR (Fextent_mouse_face); | |
7128 DEFSUBR (Fset_extent_mouse_face); | |
7129 DEFSUBR (Fset_extent_begin_glyph); | |
7130 DEFSUBR (Fset_extent_end_glyph); | |
7131 DEFSUBR (Fextent_begin_glyph); | |
7132 DEFSUBR (Fextent_end_glyph); | |
7133 DEFSUBR (Fset_extent_begin_glyph_layout); | |
7134 DEFSUBR (Fset_extent_end_glyph_layout); | |
7135 DEFSUBR (Fextent_begin_glyph_layout); | |
7136 DEFSUBR (Fextent_end_glyph_layout); | |
7137 DEFSUBR (Fset_extent_priority); | |
7138 DEFSUBR (Fextent_priority); | |
7139 DEFSUBR (Fset_extent_property); | |
7140 DEFSUBR (Fset_extent_properties); | |
7141 DEFSUBR (Fextent_property); | |
7142 DEFSUBR (Fextent_properties); | |
7143 | |
7144 DEFSUBR (Fhighlight_extent); | |
7145 DEFSUBR (Fforce_highlight_extent); | |
7146 | |
7147 DEFSUBR (Finsert_extent); | |
7148 | |
7149 DEFSUBR (Fget_text_property); | |
7150 DEFSUBR (Fget_char_property); | |
7151 DEFSUBR (Fput_text_property); | |
7152 DEFSUBR (Fput_nonduplicable_text_property); | |
7153 DEFSUBR (Fadd_text_properties); | |
7154 DEFSUBR (Fadd_nonduplicable_text_properties); | |
7155 DEFSUBR (Fremove_text_properties); | |
7156 DEFSUBR (Ftext_prop_extent_paste_function); | |
7157 DEFSUBR (Fnext_single_property_change); | |
7158 DEFSUBR (Fprevious_single_property_change); | |
2506 | 7159 DEFSUBR (Fnext_single_char_property_change); |
7160 DEFSUBR (Fprevious_single_char_property_change); | |
428 | 7161 } |
7162 | |
7163 void | |
7164 vars_of_extents (void) | |
7165 { | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
7166 #ifdef DEBUG_XEMACS |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
7167 DEFVAR_BOOL ("debug-soe", &debug_soe /* |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
7168 If non-nil, display debugging information about the SOE ("stack of extents"). |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
7169 The SOE is a cache of extents overlapping a specified region, used to |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
7170 speed up `map-extents' and certain other functions. |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
7171 */ ); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
7172 debug_soe = 0; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
7173 #endif /* DEBUG_XEMACS */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
7174 |
428 | 7175 DEFVAR_INT ("mouse-highlight-priority", &mouse_highlight_priority /* |
7176 The priority to use for the mouse-highlighting pseudo-extent | |
7177 that is used to highlight extents with the `mouse-face' attribute set. | |
7178 See `set-extent-priority'. | |
7179 */ ); | |
7180 /* Set mouse-highlight-priority (which ends up being used both for the | |
7181 mouse-highlighting pseudo-extent and the primary selection extent) | |
7182 to a very high value because very few extents should override it. | |
7183 1000 gives lots of room below it for different-prioritized extents. | |
7184 10 doesn't. ediff, for example, likes to use priorities around 100. | |
7185 --ben */ | |
7186 mouse_highlight_priority = /* 10 */ 1000; | |
7187 | |
7188 DEFVAR_LISP ("default-text-properties", &Vdefault_text_properties /* | |
7189 Property list giving default values for text properties. | |
7190 Whenever a character does not specify a value for a property, the value | |
7191 stored in this list is used instead. This only applies when the | |
7192 functions `get-text-property' or `get-char-property' are called. | |
7193 */ ); | |
7194 Vdefault_text_properties = Qnil; | |
7195 | |
7196 staticpro (&Vlast_highlighted_extent); | |
7197 Vlast_highlighted_extent = Qnil; | |
7198 | |
7199 Vextent_face_reusable_list = Fcons (Qnil, Qnil); | |
7200 staticpro (&Vextent_face_reusable_list); | |
771 | 7201 |
428 | 7202 staticpro (&Vextent_face_memoize_hash_table); |
7203 /* The memoize hash table maps from lists of symbols to lists of | |
7204 faces. It needs to be `equal' to implement the memoization. | |
7205 The reverse table maps in the other direction and just needs | |
7206 to do `eq' comparison because the lists of faces are already | |
7207 memoized. */ | |
7208 Vextent_face_memoize_hash_table = | |
7209 make_lisp_hash_table (100, HASH_TABLE_VALUE_WEAK, HASH_TABLE_EQUAL); | |
7210 staticpro (&Vextent_face_reverse_memoize_hash_table); | |
7211 Vextent_face_reverse_memoize_hash_table = | |
7212 make_lisp_hash_table (100, HASH_TABLE_KEY_WEAK, HASH_TABLE_EQ); | |
1292 | 7213 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
7214 QSin_map_extents_internal = build_defer_string ("(in map-extents-internal)"); |
1292 | 7215 staticpro (&QSin_map_extents_internal); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
7216 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
7217 Vextent_auxiliary_defaults = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
7218 allocate_extent_auxiliary (); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
7219 staticpro (&Vextent_auxiliary_defaults); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
7220 } |