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