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