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