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