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