0
|
1 /* Copyright (c) 1994, 1995 Free Software Foundation, Inc.
|
|
2 Copyright (c) 1995 Sun Microsystems, Inc.
|
|
3 Copyright (c) 1995, 1996 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* This file has been Mule-ized. */
|
|
25
|
|
26 /* Written by Ben Wing <wing@666.com>.
|
|
27
|
|
28 [Originally written by some people at Lucid.
|
|
29 Hacked on by jwz.
|
|
30 Start/end-open stuff added by John Rose (john.rose@eng.sun.com).
|
|
31 Rewritten from scratch by Ben Wing, December 1994.] */
|
|
32
|
|
33 /* Commentary:
|
|
34
|
|
35 Extents are regions over a buffer, with a start and an end position
|
|
36 denoting the region of the buffer included in the extent. In
|
|
37 addition, either end can be closed or open, meaning that the endpoint
|
|
38 is or is not logically included in the extent. Insertion of a character
|
|
39 at a closed endpoint causes the character to go inside the extent;
|
|
40 insertion at an open endpoint causes the character to go outside.
|
|
41
|
|
42 Extent endpoints are stored using memory indices (see insdel.c),
|
|
43 to minimize the amount of adjusting that needs to be done when
|
|
44 characters are inserted or deleted.
|
|
45
|
|
46 (Formerly, extent endpoints at the gap could be either before or
|
|
47 after the gap, depending on the open/closedness of the endpoint.
|
|
48 The intent of this was to make it so that insertions would
|
|
49 automatically go inside or out of extents as necessary with no
|
|
50 further work needing to be done. It didn't work out that way,
|
|
51 however, and just ended up complexifying and buggifying all the
|
|
52 rest of the code.)
|
|
53
|
|
54 Extents are compared using memory indices. There are two orderings
|
|
55 for extents and both orders are kept current at all times. The normal
|
|
56 or "display" order is as follows:
|
|
57
|
|
58 Extent A is "less than" extent B, that is, earlier in the display order,
|
|
59 if: A-start < B-start,
|
|
60 or if: A-start = B-start, and A-end > B-end
|
|
61
|
|
62 So if two extents begin at the same position, the larger of them is the
|
|
63 earlier one in the display order (EXTENT_LESS is true).
|
|
64
|
|
65 For the e-order, the same thing holds: Extent A is "less than" extent B
|
|
66 in e-order, that is, later in the buffer,
|
|
67 if: A-end < B-end,
|
|
68 or if: A-end = B-end, and A-start > B-start
|
|
69
|
|
70 So if two extents end at the same position, the smaller of them is the
|
|
71 earlier one in the e-order (EXTENT_E_LESS is true).
|
|
72
|
|
73 The display order and the e-order are complementary orders: any
|
|
74 theorem about the display order also applies to the e-order if you
|
|
75 swap all occurrences of "display order" and "e-order", "less than"
|
|
76 and "greater than", and "extent start" and "extent end".
|
|
77
|
|
78 Extents can be zero-length, and will end up that way if their endpoints
|
|
79 are explicitly set that way or if their detachable property is nil
|
|
80 and all the text in the extent is deleted. (The exception is open-open
|
|
81 zero-length extents, which are barred from existing because there is
|
|
82 no sensible way to define their properties. Deletion of the text in
|
|
83 an open-open extent causes it to be converted into a closed-open
|
|
84 extent.) Zero-length extents are primarily used to represent
|
|
85 annotations, and behave as follows:
|
|
86
|
|
87 1) Insertion at the position of a zero-length extent expands the extent
|
|
88 if both endpoints are closed; goes after the extent if it is closed-open;
|
|
89 and goes before the extent if it is open-closed.
|
|
90
|
|
91 2) Deletion of a character on a side of a zero-length extent whose
|
|
92 corresponding endpoint is closed causes the extent to be detached if
|
|
93 it is detachable; if the extent is not detachable or the corresponding
|
|
94 endpoint is open, the extent remains in the buffer, moving as necessary.
|
|
95
|
|
96 Note that closed-open, non-detachable zero-length extents behave exactly
|
|
97 like markers and that open-closed, non-detachable zero-length extents
|
|
98 behave like the "point-type" marker in Mule.
|
|
99
|
|
100
|
|
101 #### The following information is wrong in places.
|
|
102
|
|
103 More about the different orders:
|
|
104 --------------------------------
|
|
105
|
|
106 The extents in a buffer are ordered by "display order" because that
|
|
107 is that order that the redisplay mechanism needs to process them in.
|
|
108 The e-order is an auxiliary ordering used to facilitate operations
|
|
109 over extents. The operations that can be performed on the ordered
|
|
110 list of extents in a buffer are
|
|
111
|
|
112 1) Locate where an extent would go if inserted into the list.
|
|
113 2) Insert an extent into the list.
|
|
114 3) Remove an extent from the list.
|
|
115 4) Map over all the extents that overlap a range.
|
|
116
|
|
117 (4) requires being able to determine the first and last extents
|
|
118 that overlap a range.
|
|
119
|
|
120 NOTE: "overlap" is used as follows:
|
|
121
|
|
122 -- two ranges overlap if they have at least one point in common.
|
|
123 Whether the endpoints are open or closed makes a difference here.
|
|
124 -- a point overlaps a range if the point is contained within the
|
|
125 range; this is equivalent to treating a point P as the range
|
|
126 [P, P].
|
|
127 -- In the case of an *extent* overlapping a point or range, the
|
|
128 extent is normally treated as having closed endpoints. This
|
|
129 applies consistently in the discussion of stacks of extents
|
|
130 and such below. Note that this definition of overlap is not
|
|
131 necessarily consistent with the extents that `map-extents'
|
|
132 maps over, since `map-extents' sometimes pays attention to
|
|
133 whether the endpoints of an extents are open or closed.
|
|
134 But for our purposes, it greatly simplifies things to treat
|
|
135 all extents as having closed endpoints.
|
|
136
|
|
137 First, define >, <, <=, etc. as applied to extents to mean
|
|
138 comparison according to the display order. Comparison between an
|
|
139 extent E and an index I means comparison between E and the range
|
|
140 [I, I].
|
|
141 Also define e>, e<, e<=, etc. to mean comparison according to the
|
|
142 e-order.
|
|
143 For any range R, define R(0) to be the starting index of the range
|
|
144 and R(1) to be the ending index of the range.
|
|
145 For any extent E, define E(next) to be the extent directly following
|
|
146 E, and E(prev) to be the extent directly preceding E. Assume
|
|
147 E(next) and E(prev) can be determined from E in constant time.
|
|
148 (This is because we store the extent list as a doubly linked
|
|
149 list.)
|
|
150 Similarly, define E(e-next) and E(e-prev) to be the extents
|
|
151 directly following and preceding E in the e-order.
|
|
152
|
|
153 Now:
|
|
154
|
|
155 Let R be a range.
|
|
156 Let F be the first extent overlapping R.
|
|
157 Let L be the last extent overlapping R.
|
|
158
|
|
159 Theorem 1: R(1) lies between L and L(next), i.e. L <= R(1) < L(next).
|
|
160
|
|
161 This follows easily from the definition of display order. The
|
|
162 basic reason that this theorem applies is that the display order
|
|
163 sorts by increasing starting index.
|
|
164
|
|
165 Therefore, we can determine L just by looking at where we would
|
|
166 insert R(1) into the list, and if we know F and are moving forward
|
|
167 over extents, we can easily determine when we've hit L by comparing
|
|
168 the extent we're at to R(1).
|
|
169
|
|
170 Theorem 2: F(e-prev) e< [1, R(0)] e<= F.
|
|
171
|
|
172 This is the analog of Theorem 1, and applies because the e-order
|
|
173 sorts by increasing ending index.
|
|
174
|
|
175 Therefore, F can be found in the same amount of time as operation (1),
|
|
176 i.e. the time that it takes to locate where an extent would go if
|
|
177 inserted into the e-order list.
|
|
178
|
|
179 If the lists were stored as balanced binary trees, then operation (1)
|
|
180 would take logarithmic time, which is usually quite fast. However,
|
|
181 currently they're stored as simple doubly-linked lists, and instead
|
|
182 we do some caching to try to speed things up.
|
|
183
|
|
184 Define a "stack of extents" (or "SOE") as the set of extents
|
|
185 (ordered in the display order) that overlap an index I, together with
|
|
186 the SOE's "previous" extent, which is an extent that precedes I in
|
|
187 the e-order. (Hopefully there will not be very many extents between
|
|
188 I and the previous extent.)
|
|
189
|
|
190 Now:
|
|
191
|
|
192 Let I be an index, let S be the stack of extents on I, let F be
|
|
193 the first extent in S, and let P be S's previous extent.
|
|
194
|
|
195 Theorem 3: The first extent in S is the first extent that overlaps
|
|
196 any range [I, J].
|
|
197
|
|
198 Proof: Any extent that overlaps [I, J] but does not include I must
|
|
199 have a start index > I, and thus be greater than any extent in S.
|
|
200
|
|
201 Therefore, finding the first extent that overlaps a range R is the
|
|
202 same as finding the first extent that overlaps R(0).
|
|
203
|
|
204 Theorem 4: Let I2 be an index such that I2 > I, and let F2 be the
|
|
205 first extent that overlaps I2. Then, either F2 is in S or F2 is
|
|
206 greater than any extent in S.
|
|
207
|
|
208 Proof: If F2 does not include I then its start index is greater
|
|
209 than I and thus it is greater than any extent in S, including F.
|
|
210 Otherwise, F2 includes I and thus is in S, and thus F2 >= F.
|
|
211
|
|
212 */
|
|
213
|
|
214 #include <config.h>
|
|
215 #include "lisp.h"
|
|
216
|
|
217 #include "buffer.h"
|
|
218 #include "debug.h"
|
|
219 #include "device.h"
|
|
220 #include "elhash.h"
|
|
221 #include "extents.h"
|
|
222 #include "faces.h"
|
|
223 #include "frame.h"
|
|
224 #include "glyphs.h"
|
|
225 #include "hash.h"
|
|
226 #include "insdel.h"
|
|
227 #include "opaque.h"
|
|
228 #include "process.h"
|
|
229 #include "redisplay.h"
|
|
230
|
|
231 /* ------------------------------- */
|
|
232 /* gap array */
|
|
233 /* ------------------------------- */
|
|
234
|
|
235 /* Note that this object is not extent-specific and should perhaps be
|
|
236 moved into another file. */
|
|
237
|
|
238 /* Holds a marker that moves as elements in the array are inserted and
|
|
239 deleted, similar to standard markers. */
|
|
240
|
|
241 typedef struct gap_array_marker
|
|
242 {
|
|
243 int pos;
|
|
244 struct gap_array_marker *next;
|
|
245 } Gap_Array_Marker;
|
|
246
|
|
247 /* Holds a "gap array", which is an array of elements with a gap located
|
|
248 in it. Insertions and deletions with a high degree of locality
|
|
249 are very fast, essentially in constant time. Array positions as
|
|
250 used and returned in the gap array functions are independent of
|
|
251 the gap. */
|
|
252
|
|
253 typedef struct gap_array
|
|
254 {
|
|
255 char *array;
|
|
256 int gap;
|
|
257 int gapsize;
|
|
258 int numels;
|
|
259 int elsize;
|
|
260 Gap_Array_Marker *markers;
|
|
261 } Gap_Array;
|
|
262
|
|
263 Gap_Array_Marker *gap_array_marker_freelist;
|
|
264
|
|
265 /* Convert a "memory position" (i.e. taking the gap into account) into
|
|
266 the address of the element at (i.e. after) that position. "Memory
|
|
267 positions" are only used internally and are of type Memind.
|
|
268 "Array positions" are used externally and are of type int. */
|
|
269 #define GAP_ARRAY_MEMEL_ADDR(ga, memel) ((ga)->array + (ga)->elsize*(memel))
|
|
270
|
|
271 /* Number of elements currently in a gap array */
|
|
272 #define GAP_ARRAY_NUM_ELS(ga) ((ga)->numels)
|
|
273
|
|
274 #define GAP_ARRAY_ARRAY_TO_MEMORY_POS(ga, pos) \
|
|
275 ((pos) <= (ga)->gap ? (pos) : (pos) + (ga)->gapsize)
|
|
276
|
|
277 #define GAP_ARRAY_MEMORY_TO_ARRAY_POS(ga, pos) \
|
|
278 ((pos) <= (ga)->gap ? (pos) : (pos) - (ga)->gapsize)
|
|
279
|
|
280 /* Convert an array position into the address of the element at
|
|
281 (i.e. after) that position. */
|
|
282 #define GAP_ARRAY_EL_ADDR(ga, pos) ((pos) < (ga)->gap ? \
|
|
283 GAP_ARRAY_MEMEL_ADDR(ga, pos) : \
|
|
284 GAP_ARRAY_MEMEL_ADDR(ga, (pos) + (ga)->gapsize))
|
|
285
|
|
286 /* ------------------------------- */
|
|
287 /* extent list */
|
|
288 /* ------------------------------- */
|
|
289
|
|
290 typedef struct extent_list_marker
|
|
291 {
|
|
292 Gap_Array_Marker *m;
|
|
293 int endp;
|
|
294 struct extent_list_marker *next;
|
|
295 } Extent_List_Marker;
|
|
296
|
|
297 typedef struct extent_list
|
|
298 {
|
|
299 Gap_Array *start;
|
|
300 Gap_Array *end;
|
|
301 Extent_List_Marker *markers;
|
|
302 } Extent_List;
|
|
303
|
|
304 Extent_List_Marker *extent_list_marker_freelist;
|
|
305
|
|
306 #define EXTENT_LESS_VALS(e,st,nd) ((extent_start (e) < (st)) || \
|
|
307 ((extent_start (e) == (st)) && \
|
|
308 (extent_end (e) > (nd))))
|
|
309
|
|
310 #define EXTENT_EQUAL_VALS(e,st,nd) ((extent_start (e) == (st)) && \
|
|
311 (extent_end (e) == (nd)))
|
|
312
|
|
313 #define EXTENT_LESS_EQUAL_VALS(e,st,nd) ((extent_start (e) < (st)) || \
|
|
314 ((extent_start (e) == (st)) && \
|
|
315 (extent_end (e) >= (nd))))
|
|
316
|
|
317 /* Is extent E1 less than extent E2 in the display order? */
|
|
318 #define EXTENT_LESS(e1,e2) \
|
|
319 EXTENT_LESS_VALS (e1, extent_start (e2), extent_end (e2))
|
|
320
|
|
321 /* Is extent E1 equal to extent E2? */
|
|
322 #define EXTENT_EQUAL(e1,e2) \
|
|
323 EXTENT_EQUAL_VALS (e1, extent_start (e2), extent_end (e2))
|
|
324
|
|
325 /* Is extent E1 less than or equal to extent E2 in the display order? */
|
|
326 #define EXTENT_LESS_EQUAL(e1,e2) \
|
|
327 EXTENT_LESS_EQUAL_VALS (e1, extent_start (e2), extent_end (e2))
|
|
328
|
|
329 #define EXTENT_E_LESS_VALS(e,st,nd) ((extent_end (e) < (nd)) || \
|
|
330 ((extent_end (e) == (nd)) && \
|
|
331 (extent_start (e) > (st))))
|
|
332
|
|
333 #define EXTENT_E_LESS_EQUAL_VALS(e,st,nd) ((extent_end (e) < (nd)) || \
|
|
334 ((extent_end (e) == (nd)) && \
|
|
335 (extent_start (e) >= (st))))
|
|
336
|
|
337 /* Is extent E1 less than extent E2 in the e-order? */
|
|
338 #define EXTENT_E_LESS(e1,e2) \
|
|
339 EXTENT_E_LESS_VALS(e1, extent_start (e2), extent_end (e2))
|
|
340
|
|
341 /* Is extent E1 less than or equal to extent E2 in the e-order? */
|
|
342 #define EXTENT_E_LESS_EQUAL(e1,e2) \
|
|
343 EXTENT_E_LESS_EQUAL_VALS (e1, extent_start (e2), extent_end (e2))
|
|
344
|
|
345 #define EXTENT_GAP_ARRAY_AT(ga, pos) (* (EXTENT *) GAP_ARRAY_EL_ADDR(ga, pos))
|
|
346
|
|
347 /* ------------------------------- */
|
|
348 /* auxiliary extent structure */
|
|
349 /* ------------------------------- */
|
|
350
|
|
351 struct extent_auxiliary extent_auxiliary_defaults;
|
|
352
|
|
353 MAC_DEFINE (EXTENT, MTancestor_extent)
|
|
354 MAC_DEFINE (EXTENT, MTaux_extent)
|
|
355 MAC_DEFINE (EXTENT, MTplist_extent)
|
|
356 MAC_DEFINE (EXTENT, MTensure_extent)
|
|
357 MAC_DEFINE (EXTENT, MTset_extent)
|
|
358
|
|
359 /* ------------------------------- */
|
|
360 /* buffer-extent primitives */
|
|
361 /* ------------------------------- */
|
|
362
|
|
363 typedef struct stack_of_extents
|
|
364 {
|
|
365 Extent_List *extents;
|
|
366 Memind pos; /* Position of stack of extents. EXTENTS is the list of
|
|
367 all extents that overlap this position. This position
|
|
368 can be -1 if the stack of extents is invalid (this
|
|
369 happens when a buffer is first created or a string's
|
|
370 stack of extents is created [a string's stack of extents
|
|
371 is nuked when a GC occurs, to conserve memory]). */
|
|
372 } Stack_Of_Extents;
|
|
373
|
|
374 /* ------------------------------- */
|
|
375 /* map-extents */
|
|
376 /* ------------------------------- */
|
|
377
|
|
378 typedef int Endpoint_Index;
|
|
379
|
|
380 #define memind_to_startind(x, start_open) \
|
|
381 ((Endpoint_Index) (((x) << 1) + !!(start_open)))
|
|
382 #define memind_to_endind(x, end_open) \
|
|
383 ((Endpoint_Index) (((x) << 1) - !!(end_open)))
|
|
384
|
|
385 /* Combination macros */
|
|
386 #define bytind_to_startind(buf, x, start_open) \
|
|
387 memind_to_startind (bytind_to_memind (buf, x), start_open)
|
|
388 #define bytind_to_endind(buf, x, end_open) \
|
|
389 memind_to_endind (bytind_to_memind (buf, x), end_open)
|
|
390
|
|
391 /* ------------------------------- */
|
|
392 /* buffer-or-string primitives */
|
|
393 /* ------------------------------- */
|
|
394
|
|
395 /* Similar for Bytinds and start/end indices. */
|
|
396
|
|
397 #define buffer_or_string_bytind_to_startind(obj, ind, start_open) \
|
|
398 memind_to_startind (buffer_or_string_bytind_to_memind (obj, ind), \
|
|
399 start_open)
|
|
400
|
|
401 #define buffer_or_string_bytind_to_endind(obj, ind, end_open) \
|
|
402 memind_to_endind (buffer_or_string_bytind_to_memind (obj, ind), \
|
|
403 end_open)
|
|
404
|
|
405 /* ------------------------------- */
|
|
406 /* Lisp-level functions */
|
|
407 /* ------------------------------- */
|
|
408
|
|
409 /* flags for decode_extent() */
|
|
410 #define DE_MUST_HAVE_BUFFER 1
|
|
411 #define DE_MUST_BE_ATTACHED 2
|
|
412
|
|
413 /* #### remove this crap */
|
|
414 #ifdef ENERGIZE
|
|
415 extern void restore_energize_extent_state (EXTENT extent);
|
|
416 #endif
|
|
417
|
|
418 Lisp_Object Vlast_highlighted_extent;
|
|
419 int mouse_highlight_priority;
|
|
420
|
|
421 Lisp_Object Qextentp;
|
|
422 Lisp_Object Qextent_live_p;
|
|
423
|
|
424 Lisp_Object Qend_closed;
|
|
425 Lisp_Object Qstart_open;
|
|
426 Lisp_Object Qall_extents_closed;
|
|
427 Lisp_Object Qall_extents_open;
|
|
428 Lisp_Object Qall_extents_closed_open;
|
|
429 Lisp_Object Qall_extents_open_closed;
|
|
430 Lisp_Object Qstart_in_region;
|
|
431 Lisp_Object Qend_in_region;
|
|
432 Lisp_Object Qstart_and_end_in_region;
|
|
433 Lisp_Object Qstart_or_end_in_region;
|
|
434 Lisp_Object Qnegate_in_region;
|
|
435
|
|
436 Lisp_Object Qdetached;
|
|
437 Lisp_Object Qdestroyed;
|
|
438 Lisp_Object Qbegin_glyph;
|
|
439 Lisp_Object Qend_glyph;
|
|
440 Lisp_Object Qstart_open;
|
|
441 Lisp_Object Qend_open;
|
|
442 Lisp_Object Qstart_closed;
|
|
443 Lisp_Object Qend_closed;
|
|
444 Lisp_Object Qread_only;
|
|
445 /* Qhighlight defined in general.c */
|
|
446 Lisp_Object Qunique;
|
|
447 Lisp_Object Qduplicable;
|
|
448 Lisp_Object 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);
|
|
750
|
|
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));
|
|
939 return (data->parent);
|
|
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;
|
|
1097 }
|
|
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);
|
|
1150
|
|
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
|
|
1285 static char *print_extent_1 (char *buf, Lisp_Object extent);
|
|
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
|
|
1550 static Bytind
|
|
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
|
32
|
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))
|
32
|
1601 extent_changed_for_redisplay (XEXTENT (XCAR (rest)), 1,
|
|
1602 invisibility_change);
|
0
|
1603 }
|
|
1604 }
|
|
1605
|
|
1606 /* now mark the extent itself. */
|
|
1607
|
|
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;
|
32
|
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
|
|
1639 /* A change to an extent occurred that will might affect redisplay.
|
|
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
|
32
|
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);
|
|
1650 if (!NILP (extent_face (anc)) || !NILP (extent_begin_glyph (anc)) ||
|
|
1651 !NILP (extent_end_glyph (anc)) || !NILP (extent_mouse_face (anc)) ||
|
32
|
1652 !NILP (extent_invisible (anc)) || invisibility_change)
|
|
1653 extent_changed_for_redisplay (extent, descendants_too,
|
|
1654 invisibility_change);
|
0
|
1655 }
|
|
1656
|
|
1657 static EXTENT
|
|
1658 make_extent_detached (Lisp_Object object)
|
|
1659 {
|
|
1660 EXTENT extent = allocate_extent ();
|
|
1661
|
|
1662 assert (NILP (object) || STRINGP (object) ||
|
|
1663 (BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object))));
|
|
1664 extent_object (extent) = object;
|
|
1665 /* Now make sure the extent info exists. */
|
|
1666 if (!NILP (object))
|
|
1667 (void) buffer_or_string_extent_info_force (object);
|
|
1668 return extent;
|
|
1669 }
|
|
1670
|
|
1671 /* A "real" extent is any extent other than the internal (not-user-visible)
|
|
1672 extents used by `map-extents'. */
|
|
1673
|
|
1674 static EXTENT
|
|
1675 real_extent_at_forward (Extent_List *el, int pos, int endp)
|
|
1676 {
|
|
1677 for (; pos < extent_list_num_els (el); pos++)
|
|
1678 {
|
|
1679 EXTENT e = extent_list_at (el, pos, endp);
|
|
1680 if (!extent_internal_p (e))
|
|
1681 return e;
|
|
1682 }
|
|
1683 return 0;
|
|
1684 }
|
|
1685
|
|
1686 static EXTENT
|
|
1687 real_extent_at_backward (Extent_List *el, int pos, int endp)
|
|
1688 {
|
|
1689 for (; pos >= 0; pos--)
|
|
1690 {
|
|
1691 EXTENT e = extent_list_at (el, pos, endp);
|
|
1692 if (!extent_internal_p (e))
|
|
1693 return e;
|
|
1694 }
|
|
1695 return 0;
|
|
1696 }
|
|
1697
|
|
1698 static EXTENT
|
|
1699 extent_first (Lisp_Object obj)
|
|
1700 {
|
|
1701 Extent_List *el = buffer_or_string_extent_list (obj);
|
|
1702
|
|
1703 if (!el)
|
|
1704 return 0;
|
|
1705 return real_extent_at_forward (el, 0, 0);
|
|
1706 }
|
|
1707
|
|
1708 #ifdef DEBUG_XEMACS
|
|
1709 static EXTENT
|
|
1710 extent_e_first (Lisp_Object obj)
|
|
1711 {
|
|
1712 Extent_List *el = buffer_or_string_extent_list (obj);
|
|
1713
|
|
1714 if (!el)
|
|
1715 return 0;
|
|
1716 return real_extent_at_forward (el, 0, 1);
|
|
1717 }
|
|
1718 #endif
|
|
1719
|
|
1720 static EXTENT
|
|
1721 extent_next (EXTENT e)
|
|
1722 {
|
|
1723 Extent_List *el = extent_extent_list (e);
|
|
1724 int foundp;
|
|
1725 int pos;
|
|
1726
|
|
1727 pos = extent_list_locate (el, e, 0, &foundp);
|
|
1728 assert (foundp);
|
|
1729 return real_extent_at_forward (el, pos+1, 0);
|
|
1730 }
|
|
1731
|
|
1732 #ifdef DEBUG_XEMACS
|
|
1733 static EXTENT
|
|
1734 extent_e_next (EXTENT e)
|
|
1735 {
|
|
1736 Extent_List *el = extent_extent_list (e);
|
|
1737 int foundp;
|
|
1738 int pos;
|
|
1739
|
|
1740 pos = extent_list_locate (el, e, 1, &foundp);
|
|
1741 assert (foundp);
|
|
1742 return real_extent_at_forward (el, pos+1, 1);
|
|
1743 }
|
|
1744 #endif
|
|
1745
|
|
1746 static EXTENT
|
|
1747 extent_last (Lisp_Object obj)
|
|
1748 {
|
|
1749 Extent_List *el = buffer_or_string_extent_list (obj);
|
|
1750
|
|
1751 if (!el)
|
|
1752 return 0;
|
|
1753 return real_extent_at_backward (el, extent_list_num_els (el) - 1, 0);
|
|
1754 }
|
|
1755
|
|
1756 #ifdef DEBUG_XEMACS
|
|
1757 static EXTENT
|
|
1758 extent_e_last (Lisp_Object obj)
|
|
1759 {
|
|
1760 Extent_List *el = buffer_or_string_extent_list (obj);
|
|
1761
|
|
1762 if (!el)
|
|
1763 return 0;
|
|
1764 return real_extent_at_backward (el, extent_list_num_els (el) - 1, 1);
|
|
1765 }
|
|
1766 #endif
|
|
1767
|
|
1768 static EXTENT
|
|
1769 extent_previous (EXTENT e)
|
|
1770 {
|
|
1771 Extent_List *el = extent_extent_list (e);
|
|
1772 int foundp;
|
|
1773 int pos;
|
|
1774
|
|
1775 pos = extent_list_locate (el, e, 0, &foundp);
|
|
1776 assert (foundp);
|
|
1777 return real_extent_at_backward (el, pos-1, 0);
|
|
1778 }
|
|
1779
|
|
1780 #ifdef DEBUG_XEMACS
|
|
1781 static EXTENT
|
|
1782 extent_e_previous (EXTENT e)
|
|
1783 {
|
|
1784 Extent_List *el = extent_extent_list (e);
|
|
1785 int foundp;
|
|
1786 int pos;
|
|
1787
|
|
1788 pos = extent_list_locate (el, e, 1, &foundp);
|
|
1789 assert (foundp);
|
|
1790 return real_extent_at_backward (el, pos-1, 1);
|
|
1791 }
|
|
1792 #endif
|
|
1793
|
|
1794 static void
|
|
1795 extent_attach (EXTENT extent)
|
|
1796 {
|
|
1797 Extent_List *el = extent_extent_list (extent);
|
|
1798
|
|
1799 extent_list_insert (el, extent);
|
|
1800 soe_insert (extent_object (extent), extent);
|
|
1801 /* only this extent changed */
|
32
|
1802 extent_maybe_changed_for_redisplay (extent, 0,
|
|
1803 !NILP (extent_invisible (extent)));
|
0
|
1804 }
|
|
1805
|
|
1806 static void
|
|
1807 extent_detach (EXTENT extent)
|
|
1808 {
|
|
1809 Extent_List *el;
|
|
1810
|
|
1811 if (extent_detached_p (extent))
|
|
1812 return;
|
|
1813 el = extent_extent_list (extent);
|
|
1814
|
|
1815 /* call this before messing with the extent. */
|
32
|
1816 extent_maybe_changed_for_redisplay (extent, 0,
|
|
1817 !NILP (extent_invisible (extent)));
|
0
|
1818 extent_list_delete (el, extent);
|
|
1819 soe_delete (extent_object (extent), extent);
|
|
1820 set_extent_start (extent, -1);
|
|
1821 set_extent_end (extent, -1);
|
|
1822 }
|
|
1823
|
|
1824 /* ------------------------------- */
|
|
1825 /* map-extents et al. */
|
|
1826 /* ------------------------------- */
|
|
1827
|
|
1828 /* Returns true iff map_extents() would visit the given extent.
|
|
1829 See the comments at map_extents() for info on the overlap rule.
|
|
1830 Assumes that all validation on the extent and buffer positions has
|
|
1831 already been performed (see Fextent_in_region_p ()).
|
|
1832 */
|
|
1833 static int
|
|
1834 extent_in_region_p (EXTENT extent, Bytind from, Bytind to,
|
|
1835 unsigned int flags)
|
|
1836 {
|
|
1837 Lisp_Object obj = extent_object (extent);
|
|
1838 Endpoint_Index start, end, exs, exe;
|
|
1839 int start_open, end_open;
|
|
1840 unsigned int all_extents_flags = flags & ME_ALL_EXTENTS_MASK;
|
|
1841 unsigned int in_region_flags = flags & ME_IN_REGION_MASK;
|
|
1842 int retval;
|
|
1843
|
|
1844 /* A zero-length region is treated as closed-closed. */
|
|
1845 if (from == to)
|
|
1846 {
|
|
1847 flags |= ME_END_CLOSED;
|
|
1848 flags &= ~ME_START_OPEN;
|
|
1849 }
|
|
1850
|
|
1851 switch (all_extents_flags)
|
|
1852 {
|
|
1853 case ME_ALL_EXTENTS_CLOSED:
|
|
1854 start_open = end_open = 0; break;
|
|
1855 case ME_ALL_EXTENTS_OPEN:
|
|
1856 start_open = end_open = 1; break;
|
|
1857 case ME_ALL_EXTENTS_CLOSED_OPEN:
|
|
1858 start_open = 0; end_open = 1; break;
|
|
1859 case ME_ALL_EXTENTS_OPEN_CLOSED:
|
|
1860 start_open = 1; end_open = 0; break;
|
|
1861 default:
|
|
1862 start_open = extent_start_open_p (extent);
|
|
1863 end_open = extent_end_open_p (extent);
|
|
1864 break;
|
|
1865 }
|
|
1866
|
|
1867 /* So is a zero-length extent. */
|
|
1868 if (extent_start (extent) == extent_end (extent))
|
|
1869 start_open = end_open = 0;
|
|
1870
|
|
1871 start = buffer_or_string_bytind_to_startind (obj, from,
|
|
1872 flags & ME_START_OPEN);
|
|
1873 end = buffer_or_string_bytind_to_endind (obj, to, ! (flags & ME_END_CLOSED));
|
|
1874 exs = memind_to_startind (extent_start (extent), start_open);
|
|
1875 exe = memind_to_endind (extent_end (extent), end_open);
|
|
1876
|
|
1877 /* It's easy to determine whether an extent lies *outside* the
|
|
1878 region -- just determine whether it's completely before
|
|
1879 or completely after the region. Reject all such extents, so
|
|
1880 we're now left with only the extents that overlap the region.
|
|
1881 */
|
|
1882
|
|
1883 if (exs > end || exe < start)
|
|
1884 return 0;
|
|
1885
|
|
1886 /* See if any further restrictions are called for. */
|
|
1887 switch (in_region_flags)
|
|
1888 {
|
|
1889 case ME_START_IN_REGION:
|
|
1890 retval = start <= exs && exs <= end; break;
|
|
1891 case ME_END_IN_REGION:
|
|
1892 retval = start <= exe && exe <= end; break;
|
|
1893 case ME_START_AND_END_IN_REGION:
|
|
1894 retval = start <= exs && exe <= end; break;
|
|
1895 case ME_START_OR_END_IN_REGION:
|
|
1896 retval = (start <= exs && exs <= end) || (start <= exe && exe <= end);
|
|
1897 break;
|
|
1898 default:
|
|
1899 retval = 1; break;
|
|
1900 }
|
|
1901 return flags & ME_NEGATE_IN_REGION ? !retval : retval;
|
|
1902 }
|
|
1903
|
|
1904 struct map_extents_struct
|
|
1905 {
|
|
1906 Extent_List *el;
|
|
1907 Extent_List_Marker *mkr;
|
|
1908 EXTENT range;
|
|
1909 };
|
|
1910
|
|
1911 static Lisp_Object
|
|
1912 map_extents_unwind (Lisp_Object obj)
|
|
1913 {
|
|
1914 struct map_extents_struct *closure =
|
|
1915 (struct map_extents_struct *) get_opaque_ptr (obj);
|
|
1916 free_opaque_ptr (obj);
|
|
1917 if (closure->range)
|
|
1918 extent_detach (closure->range);
|
|
1919 if (closure->mkr)
|
|
1920 extent_list_delete_marker (closure->el, closure->mkr);
|
|
1921 return Qnil;
|
|
1922 }
|
|
1923
|
|
1924 /* This is the guts of `map-extents' and the other functions that
|
|
1925 map over extents. In theory the operation of this function is
|
|
1926 simple: just figure out what extents we're mapping over, and
|
|
1927 call the function on each one of them in the range. Unfortunately
|
|
1928 there are a wide variety of things that the mapping function
|
|
1929 might do, and we have to be very tricky to avoid getting messed
|
|
1930 up. Furthermore, this function needs to be very fast (it is
|
|
1931 called multiple times every time text is inserted or deleted
|
|
1932 from a buffer), and so we can't always afford the overhead of
|
|
1933 dealing with all the possible things that the mapping function
|
|
1934 might do; thus, there are many flags that can be specified
|
|
1935 indicating what the mapping function might or might not do.
|
|
1936
|
|
1937 The result of all this is that this is the most complicated
|
|
1938 function in this file. Change it at your own risk!
|
|
1939
|
|
1940 A potential simplification to the logic below is to determine
|
|
1941 all the extents that the mapping function should be called on
|
|
1942 before any calls are actually made and save them in an array.
|
|
1943 That introduces its own complications, however (the array
|
|
1944 needs to be marked for garbage-collection, and a static array
|
|
1945 cannot be used because map_extents() needs to be reentrant).
|
|
1946 Furthermore, the results might be a little less sensible than
|
|
1947 the logic below. */
|
|
1948
|
|
1949
|
|
1950 static void
|
|
1951 map_extents_bytind (Bytind from, Bytind to,
|
|
1952 int (*fn) (EXTENT extent, void *arg), void *arg,
|
|
1953 Lisp_Object obj, EXTENT after, unsigned int flags)
|
|
1954 {
|
|
1955 Memind st, en; /* range we're mapping over */
|
|
1956 EXTENT range = 0; /* extent for this, if ME_MIGHT_MODIFY_TEXT */
|
|
1957 Extent_List *el = 0; /* extent list we're iterating over */
|
|
1958 Extent_List_Marker *posm = 0; /* marker for extent list,
|
|
1959 if ME_MIGHT_MODIFY_EXTENTS */
|
|
1960 /* count and struct for unwind-protect, if ME_MIGHT_THROW */
|
|
1961 int count = 0;
|
|
1962 struct map_extents_struct closure;
|
|
1963
|
|
1964 #ifdef ERROR_CHECK_EXTENTS
|
|
1965 assert (from <= to);
|
|
1966 assert (from >= buffer_or_string_absolute_begin_byte (obj) &&
|
|
1967 from <= buffer_or_string_absolute_end_byte (obj) &&
|
|
1968 to >= buffer_or_string_absolute_begin_byte (obj) &&
|
|
1969 to <= buffer_or_string_absolute_end_byte (obj));
|
|
1970 #endif
|
|
1971
|
|
1972 if (after)
|
|
1973 {
|
|
1974 assert (EQ (obj, extent_object (after)));
|
|
1975 assert (!extent_detached_p (after));
|
|
1976 }
|
|
1977
|
14
|
1978 el = buffer_or_string_extent_list (obj);
|
|
1979 if (!el || !extent_list_num_els(el))
|
0
|
1980 return;
|
14
|
1981 el = 0;
|
0
|
1982
|
|
1983 st = buffer_or_string_bytind_to_memind (obj, from);
|
|
1984 en = buffer_or_string_bytind_to_memind (obj, to);
|
|
1985
|
|
1986 if (flags & ME_MIGHT_MODIFY_TEXT)
|
|
1987 {
|
|
1988 /* The mapping function might change the text in the buffer,
|
|
1989 so make an internal extent to hold the range we're mapping
|
|
1990 over. */
|
|
1991 range = make_extent_detached (obj);
|
|
1992 set_extent_start (range, st);
|
|
1993 set_extent_end (range, en);
|
|
1994 range->flags.start_open = flags & ME_START_OPEN;
|
|
1995 range->flags.end_open = !(flags & ME_END_CLOSED);
|
|
1996 range->flags.internal = 1;
|
|
1997 range->flags.detachable = 0;
|
|
1998 extent_attach (range);
|
|
1999 }
|
|
2000
|
|
2001 if (flags & ME_MIGHT_THROW)
|
|
2002 {
|
|
2003 /* The mapping function might throw past us so we need to use an
|
|
2004 unwind_protect() to eliminate the internal extent and range
|
|
2005 that we use. */
|
|
2006 count = specpdl_depth ();
|
|
2007 closure.range = range;
|
|
2008 closure.mkr = 0;
|
|
2009 record_unwind_protect (map_extents_unwind,
|
|
2010 make_opaque_ptr (&closure));
|
|
2011 }
|
|
2012
|
|
2013 /* ---------- Figure out where we start and what direction
|
|
2014 we move in. This is the trickiest part of this
|
|
2015 function. ---------- */
|
|
2016
|
|
2017 /* If ME_START_IN_REGION, ME_END_IN_REGION or ME_START_AND_END_IN_REGION
|
|
2018 was specified and ME_NEGATE_IN_REGION was not specified, our job
|
|
2019 is simple because of the presence of the display order and e-order.
|
|
2020 (Note that theoretically do something similar for
|
|
2021 ME_START_OR_END_IN_REGION, but that would require more trickiness
|
|
2022 than it's worth to avoid hitting the same extent twice.)
|
|
2023
|
|
2024 In the general case, all the extents that overlap a range can be
|
|
2025 divided into two classes: those whose start position lies within
|
|
2026 the range (including the range's end but not including the
|
|
2027 range's start), and those that overlap the start position,
|
|
2028 i.e. those in the SOE for the start position. Or equivalently,
|
|
2029 the extents can be divided into those whose end position lies
|
|
2030 within the range and those in the SOE for the end position. Note
|
|
2031 that for this purpose we treat both the range and all extents in
|
|
2032 the buffer as closed on both ends. If this is not what the ME_
|
|
2033 flags specified, then we've mapped over a few too many extents,
|
|
2034 but no big deal because extent_in_region_p() will filter them
|
|
2035 out. Ideally, we could move the SOE to the closer of the range's
|
|
2036 two ends and work forwards or backwards from there. However, in
|
|
2037 order to make the semantics of the AFTER argument work out, we
|
|
2038 have to always go in the same direction; so we choose to always
|
|
2039 move the SOE to the start position.
|
|
2040
|
|
2041 When it comes time to do the SOE stage, we first call soe_move()
|
|
2042 so that the SOE gets set up. Note that the SOE might get
|
|
2043 changed while we are mapping over its contents. If we can
|
|
2044 guarantee that the SOE won't get moved to a new position, we
|
|
2045 simply need to put a marker in the SOE and we will track deletions
|
|
2046 and insertions of extents in the SOE. If the SOE might get moved,
|
|
2047 however (this would happen as a result of a recursive invocation
|
|
2048 of map-extents or a call to a redisplay-type function), then
|
|
2049 trying to track its changes is hopeless, so we just keep a
|
|
2050 marker to the first (or last) extent in the SOE and use that as
|
|
2051 our bound.
|
|
2052
|
|
2053 Finally, if DONT_USE_SOE is defined, we don't use the SOE at all
|
|
2054 and instead just map from the beginning of the buffer. This is
|
|
2055 used for testing purposes and allows the SOE to be calculated
|
|
2056 using map_extents() instead of the other way around. */
|
|
2057
|
|
2058 {
|
|
2059 int range_flag; /* ME_*_IN_REGION subset of flags */
|
|
2060 int do_soe_stage = 0; /* Are we mapping over the SOE? */
|
|
2061 /* Does the range stage map over start or end positions? */
|
|
2062 int range_endp;
|
|
2063 /* If type == 0, we include the start position in the range stage mapping.
|
|
2064 If type == 1, we exclude the start position in the range stage mapping.
|
|
2065 If type == 2, we begin at range_start_pos, an extent-list position.
|
|
2066 */
|
|
2067 int range_start_type = 0;
|
|
2068 int range_start_pos = 0;
|
|
2069 int stage;
|
|
2070
|
|
2071 range_flag = flags & ME_IN_REGION_MASK;
|
|
2072 if ((range_flag == ME_START_IN_REGION ||
|
|
2073 range_flag == ME_START_AND_END_IN_REGION) &&
|
|
2074 !(flags & ME_NEGATE_IN_REGION))
|
|
2075 {
|
|
2076 /* map over start position in [range-start, range-end]. No SOE
|
|
2077 stage. */
|
|
2078 range_endp = 0;
|
|
2079 }
|
|
2080 else if (range_flag == ME_END_IN_REGION && !(flags & ME_NEGATE_IN_REGION))
|
|
2081 {
|
|
2082 /* map over end position in [range-start, range-end]. No SOE
|
|
2083 stage. */
|
|
2084 range_endp = 1;
|
|
2085 }
|
|
2086 else
|
|
2087 {
|
|
2088 /* Need to include the SOE extents. */
|
|
2089 #ifdef DONT_USE_SOE
|
|
2090 /* Just brute-force it: start from the beginning. */
|
|
2091 range_endp = 0;
|
|
2092 range_start_type = 2;
|
|
2093 range_start_pos = 0;
|
|
2094 #else
|
|
2095 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents_force (obj);
|
|
2096 int numsoe;
|
|
2097
|
|
2098 /* Move the SOE to the closer end of the range. This dictates
|
|
2099 whether we map over start positions or end positions. */
|
|
2100 range_endp = 0;
|
|
2101 soe_move (obj, st);
|
|
2102 numsoe = extent_list_num_els (soe->extents);
|
|
2103 if (numsoe)
|
|
2104 {
|
|
2105 if (flags & ME_MIGHT_MOVE_SOE)
|
|
2106 {
|
|
2107 int foundp;
|
|
2108 /* Can't map over SOE, so just extend range to cover the
|
|
2109 SOE. */
|
|
2110 EXTENT e = extent_list_at (soe->extents, 0, 0);
|
|
2111 range_start_pos =
|
|
2112 extent_list_locate (buffer_or_string_extent_list (obj), e, 0,
|
|
2113 &foundp);
|
|
2114 assert (foundp);
|
|
2115 range_start_type = 2;
|
|
2116 }
|
|
2117 else
|
|
2118 {
|
|
2119 /* We can map over the SOE. */
|
|
2120 do_soe_stage = 1;
|
|
2121 range_start_type = 1;
|
|
2122 }
|
|
2123 }
|
|
2124 else
|
|
2125 {
|
|
2126 /* No extents in the SOE to map over, so we act just as if
|
|
2127 ME_START_IN_REGION or ME_END_IN_REGION was specified.
|
|
2128 RANGE_ENDP already specified so no need to do anything else. */
|
|
2129 }
|
|
2130 }
|
|
2131 #endif
|
|
2132
|
|
2133 /* ---------- Now loop over the extents. ---------- */
|
|
2134
|
|
2135 /* We combine the code for the two stages because much of it
|
|
2136 overlaps. */
|
|
2137 for (stage = 0; stage < 2; stage++)
|
|
2138 {
|
|
2139 int pos = 0; /* Position in extent list */
|
|
2140
|
|
2141 /* First set up start conditions */
|
|
2142 if (stage == 0)
|
|
2143 { /* The SOE stage */
|
|
2144 if (!do_soe_stage)
|
|
2145 continue;
|
|
2146 el = buffer_or_string_stack_of_extents_force (obj)->extents;
|
|
2147 /* We will always be looping over start extents here. */
|
|
2148 assert (!range_endp);
|
|
2149 pos = 0;
|
|
2150 }
|
|
2151 else
|
|
2152 { /* The range stage */
|
|
2153 el = buffer_or_string_extent_list (obj);
|
|
2154 switch (range_start_type)
|
|
2155 {
|
|
2156 case 0:
|
|
2157 pos = extent_list_locate_from_pos (el, st, range_endp);
|
|
2158 break;
|
|
2159 case 1:
|
|
2160 pos = extent_list_locate_from_pos (el, st + 1, range_endp);
|
|
2161 break;
|
|
2162 case 2:
|
|
2163 pos = range_start_pos;
|
|
2164 break;
|
|
2165 }
|
|
2166 }
|
|
2167
|
|
2168 if (flags & ME_MIGHT_MODIFY_EXTENTS)
|
|
2169 {
|
|
2170 /* Create a marker to track changes to the extent list */
|
|
2171 if (posm)
|
|
2172 /* Delete the marker used in the SOE stage. */
|
|
2173 extent_list_delete_marker
|
|
2174 (buffer_or_string_stack_of_extents_force (obj)->extents, posm);
|
|
2175 posm = extent_list_make_marker (el, pos, range_endp);
|
|
2176 /* tell the unwind function about the marker. */
|
|
2177 closure.el = el;
|
|
2178 closure.mkr = posm;
|
|
2179 }
|
|
2180
|
|
2181 /* Now loop! */
|
|
2182 for (;;)
|
|
2183 {
|
|
2184 EXTENT e;
|
|
2185 Lisp_Object obj2;
|
|
2186
|
|
2187 /* ----- update position in extent list
|
|
2188 and fetch next extent ----- */
|
|
2189
|
|
2190 if (posm)
|
|
2191 /* fetch POS again to track extent insertions or deletions */
|
|
2192 pos = extent_list_marker_pos (el, posm);
|
|
2193 if (pos >= extent_list_num_els (el))
|
|
2194 break;
|
|
2195 e = extent_list_at (el, pos, range_endp);
|
|
2196 pos++;
|
|
2197 if (posm)
|
|
2198 /* now point the marker to the next one we're going to process.
|
|
2199 This ensures graceful behavior if this extent is deleted. */
|
|
2200 extent_list_move_marker (el, posm, pos);
|
|
2201
|
|
2202 /* ----- deal with internal extents ----- */
|
|
2203
|
|
2204 if (extent_internal_p (e))
|
|
2205 {
|
|
2206 if (!(flags & ME_INCLUDE_INTERNAL))
|
|
2207 continue;
|
|
2208 else if (e == range)
|
|
2209 {
|
|
2210 /* We're processing internal extents and we've
|
|
2211 come across our own special range extent.
|
|
2212 (This happens only in adjust_extents*() and
|
|
2213 process_extents*(), which handle text
|
|
2214 insertion and deletion.) We need to omit
|
|
2215 processing of this extent; otherwise
|
|
2216 we will probably end up prematurely
|
|
2217 terminating this loop. */
|
|
2218 continue;
|
|
2219 }
|
|
2220 }
|
|
2221
|
|
2222 /* ----- deal with AFTER condition ----- */
|
|
2223
|
|
2224 if (after)
|
|
2225 {
|
|
2226 /* if e > after, then we can stop skipping extents. */
|
|
2227 if (EXTENT_LESS (after, e))
|
|
2228 after = 0;
|
|
2229 else /* otherwise, skip this extent. */
|
|
2230 continue;
|
|
2231 }
|
|
2232
|
|
2233 /* ----- stop if we're completely outside the range ----- */
|
|
2234
|
|
2235 /* fetch ST and EN again to track text insertions or deletions */
|
|
2236 if (range)
|
|
2237 {
|
|
2238 st = extent_start (range);
|
|
2239 en = extent_end (range);
|
|
2240 }
|
|
2241 if (extent_endpoint (e, range_endp) > en)
|
|
2242 {
|
|
2243 /* Can't be mapping over SOE because all extents in
|
|
2244 there should overlap ST */
|
|
2245 assert (stage == 1);
|
|
2246 break;
|
|
2247 }
|
|
2248
|
|
2249 /* ----- Now actually call the function ----- */
|
|
2250
|
|
2251 obj2 = extent_object (e);
|
|
2252 if (extent_in_region_p (e,
|
|
2253 buffer_or_string_memind_to_bytind (obj2,
|
|
2254 st),
|
|
2255 buffer_or_string_memind_to_bytind (obj2,
|
|
2256 en),
|
|
2257 flags))
|
|
2258 {
|
|
2259 if ((*fn)(e, arg))
|
|
2260 {
|
|
2261 /* Function wants us to stop mapping. */
|
|
2262 stage = 1; /* so outer for loop will terminate */
|
|
2263 break;
|
|
2264 }
|
|
2265 }
|
|
2266 }
|
|
2267 }
|
|
2268 /* ---------- Finished looping. ---------- */
|
|
2269 }
|
|
2270
|
|
2271 if (flags & ME_MIGHT_THROW)
|
|
2272 /* This deletes the range extent and frees the marker. */
|
|
2273 unbind_to (count, Qnil);
|
|
2274 else
|
|
2275 {
|
|
2276 /* Delete them ourselves */
|
|
2277 if (range)
|
|
2278 extent_detach (range);
|
|
2279 if (posm)
|
|
2280 extent_list_delete_marker (el, posm);
|
|
2281 }
|
|
2282 }
|
|
2283
|
|
2284 void
|
|
2285 map_extents (Bufpos from, Bufpos to, int (*fn) (EXTENT extent, void *arg),
|
|
2286 void *arg, Lisp_Object obj, EXTENT after, unsigned int flags)
|
|
2287 {
|
|
2288 map_extents_bytind (buffer_or_string_bufpos_to_bytind (obj, from),
|
|
2289 buffer_or_string_bufpos_to_bytind (obj, to), fn, arg,
|
|
2290 obj, after, flags);
|
|
2291 }
|
|
2292
|
|
2293 /* ------------------------------- */
|
|
2294 /* adjust_extents() */
|
|
2295 /* ------------------------------- */
|
|
2296
|
|
2297 /* Add AMOUNT to all extent endpoints in the range (FROM, TO]. This
|
|
2298 happens whenever the gap is moved or (under Mule) a character in a
|
|
2299 string is substituted for a different-length one. The reason for
|
|
2300 this is that extent endpoints behave just like markers (all memory
|
|
2301 indices do) and this adjustment correct for markers -- see
|
|
2302 adjust_markers(). Note that it is important that we visit all
|
|
2303 extent endpoints in the range, irrespective of whether the
|
|
2304 endpoints are open or closed.
|
|
2305
|
|
2306 We could use map_extents() for this (and in fact the function
|
|
2307 was originally written that way), but the gap is in an incoherent
|
|
2308 state when this function is called and this function plays
|
|
2309 around with extent endpoints without detaching and reattaching
|
|
2310 the extents (this is provably correct and saves lots of time),
|
|
2311 so for safety we make it just look at the extent lists directly. */
|
|
2312
|
|
2313 void
|
|
2314 adjust_extents (Lisp_Object obj, Memind from, Memind to, int amount)
|
|
2315 {
|
|
2316 int endp;
|
|
2317 int pos;
|
|
2318 int startpos[2];
|
|
2319 Extent_List *el;
|
|
2320 Stack_Of_Extents *soe;
|
|
2321
|
|
2322 #ifdef ERROR_CHECK_EXTENTS
|
|
2323 sledgehammer_extent_check (obj);
|
|
2324 #endif
|
|
2325 el = buffer_or_string_extent_list (obj);
|
|
2326
|
14
|
2327 if (!el || !extent_list_num_els(el))
|
0
|
2328 return;
|
14
|
2329
|
0
|
2330 /* IMPORTANT! Compute the starting positions of the extents to
|
|
2331 modify BEFORE doing any modification! Otherwise the starting
|
|
2332 position for the second time through the loop might get
|
|
2333 incorrectly calculated (I got bit by this bug real bad). */
|
|
2334 startpos[0] = extent_list_locate_from_pos (el, from+1, 0);
|
|
2335 startpos[1] = extent_list_locate_from_pos (el, from+1, 1);
|
|
2336 for (endp = 0; endp < 2; endp++)
|
|
2337 {
|
|
2338 for (pos = startpos[endp]; pos < extent_list_num_els (el);
|
|
2339 pos++)
|
|
2340 {
|
|
2341 EXTENT e = extent_list_at (el, pos, endp);
|
|
2342 if (extent_endpoint (e, endp) > to)
|
|
2343 break;
|
|
2344 set_extent_endpoint (e,
|
|
2345 do_marker_adjustment (extent_endpoint (e, endp),
|
|
2346 from, to, amount),
|
|
2347 endp);
|
|
2348 }
|
|
2349 }
|
|
2350
|
|
2351 /* The index for the buffer's SOE is a memory index and thus
|
|
2352 needs to be adjusted like a marker. */
|
|
2353 soe = buffer_or_string_stack_of_extents (obj);
|
|
2354 if (soe && soe->pos >= 0)
|
|
2355 soe->pos = do_marker_adjustment (soe->pos, from, to, amount);
|
|
2356 }
|
|
2357
|
|
2358 /* ------------------------------- */
|
|
2359 /* adjust_extents_for_deletion() */
|
|
2360 /* ------------------------------- */
|
|
2361
|
|
2362 struct adjust_extents_for_deletion_arg
|
|
2363 {
|
|
2364 extent_dynarr *list;
|
|
2365 };
|
|
2366
|
|
2367 static int
|
|
2368 adjust_extents_for_deletion_mapper (EXTENT extent, void *arg)
|
|
2369 {
|
|
2370 struct adjust_extents_for_deletion_arg *closure =
|
|
2371 (struct adjust_extents_for_deletion_arg *) arg;
|
|
2372
|
|
2373 Dynarr_add (closure->list, extent);
|
|
2374 return 0; /* continue mapping */
|
|
2375 }
|
|
2376
|
|
2377 /* For all extent endpoints in the range (FROM, TO], move them to the beginning
|
|
2378 of the new gap. Note that it is important that we visit all extent
|
|
2379 endpoints in the range, irrespective of whether the endpoints are open or
|
|
2380 closed.
|
|
2381
|
|
2382 This function deals with weird stuff such as the fact that extents
|
|
2383 may get reordered.
|
|
2384
|
|
2385 There is no string correspondent for this because you can't
|
|
2386 delete characters from a string.
|
|
2387 */
|
|
2388
|
|
2389 void
|
|
2390 adjust_extents_for_deletion (Lisp_Object object, Bytind from,
|
|
2391 Bytind to, int gapsize, int numdel)
|
|
2392 {
|
|
2393 struct adjust_extents_for_deletion_arg closure;
|
|
2394 int i;
|
|
2395 Memind oldsoe, newsoe;
|
|
2396 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents (object);
|
|
2397
|
|
2398 #ifdef ERROR_CHECK_EXTENTS
|
|
2399 sledgehammer_extent_check (object);
|
|
2400 #endif
|
|
2401 closure.list = (extent_dynarr *) Dynarr_new (EXTENT);
|
|
2402
|
|
2403 /* We're going to be playing weird games below with extents and the SOE
|
|
2404 and such, so compute the list now of all the extents that we're going
|
|
2405 to muck with. If we do the mapping and adjusting together, things can
|
|
2406 get all screwed up. */
|
|
2407
|
|
2408 map_extents_bytind (from, to, adjust_extents_for_deletion_mapper,
|
|
2409 (void *) &closure, object, 0,
|
|
2410 /* extent endpoints move like markers regardless
|
|
2411 of their open/closeness. */
|
|
2412 ME_ALL_EXTENTS_CLOSED | ME_END_CLOSED |
|
|
2413 ME_START_OR_END_IN_REGION | ME_INCLUDE_INTERNAL);
|
|
2414
|
|
2415 /*
|
|
2416 Old and new values for the SOE's position. (It gets adjusted
|
|
2417 like a marker, just like extent endpoints.)
|
|
2418 */
|
|
2419
|
|
2420 if (soe)
|
|
2421 {
|
|
2422 oldsoe = soe->pos;
|
|
2423 if (soe->pos >= 0)
|
|
2424 newsoe = do_marker_adjustment (soe->pos,
|
|
2425 (Memind) (to + gapsize),
|
|
2426 (Memind) (to + gapsize),
|
|
2427 - numdel - gapsize);
|
|
2428 else
|
|
2429 newsoe = soe->pos;
|
|
2430 }
|
|
2431
|
|
2432 for (i = 0; i < Dynarr_length (closure.list); i++)
|
|
2433 {
|
|
2434 EXTENT extent = Dynarr_at (closure.list, i);
|
|
2435 Memind new_start, new_end;
|
|
2436
|
|
2437 /* do_marker_adjustment() will not adjust values that should not be
|
|
2438 adjusted. We're passing the same funky arguments to
|
|
2439 do_marker_adjustment() as buffer_delete_range() does. */
|
|
2440 new_start =
|
|
2441 do_marker_adjustment (extent_start (extent),
|
|
2442 (Memind) (to + gapsize),
|
|
2443 (Memind) (to + gapsize),
|
|
2444 - numdel - gapsize);
|
|
2445 new_end =
|
|
2446 do_marker_adjustment (extent_end (extent),
|
|
2447 (Memind) (to + gapsize),
|
|
2448 (Memind) (to + gapsize),
|
|
2449 - numdel - gapsize);
|
|
2450
|
|
2451 /* We need to be very careful here so that the SOE doesn't get
|
|
2452 corrupted. We are shrinking extents out of the deleted region
|
|
2453 and simultaneously moving the SOE's pos out of the deleted
|
|
2454 region, so the SOE should contain the same extents at the end
|
|
2455 as at the beginning. However, extents may get reordered
|
|
2456 by this process, so we have to operate by pulling the extents
|
|
2457 out of the buffer and SOE, changing their bounds, and then
|
|
2458 reinserting them. In order for the SOE not to get screwed up,
|
|
2459 we have to make sure that the SOE's pos points to its old
|
|
2460 location whenever we pull an extent out, and points to its
|
|
2461 new location whenever we put the extent back in.
|
|
2462 */
|
|
2463
|
|
2464 if (new_start != extent_start (extent) ||
|
|
2465 new_end != extent_end (extent))
|
|
2466 {
|
|
2467 extent_detach (extent);
|
|
2468 set_extent_start (extent, new_start);
|
|
2469 set_extent_end (extent, new_end);
|
|
2470 if (soe)
|
|
2471 soe->pos = newsoe;
|
|
2472 extent_attach (extent);
|
|
2473 if (soe)
|
|
2474 soe->pos = oldsoe;
|
|
2475 }
|
|
2476 }
|
|
2477
|
|
2478 if (soe)
|
|
2479 soe->pos = newsoe;
|
|
2480
|
|
2481 #ifdef ERROR_CHECK_EXTENTS
|
|
2482 sledgehammer_extent_check (object);
|
|
2483 #endif
|
|
2484 Dynarr_free (closure.list);
|
|
2485 }
|
|
2486
|
|
2487 /* ------------------------------- */
|
|
2488 /* extent fragments */
|
|
2489 /* ------------------------------- */
|
|
2490
|
|
2491 /* Imagine that the buffer is divided up into contiguous,
|
|
2492 nonoverlapping "runs" of text such that no extent
|
|
2493 starts or ends within a run (extents that abut the
|
|
2494 run don't count).
|
|
2495
|
|
2496 An extent fragment is a structure that holds data about
|
|
2497 the run that contains a particular buffer position (if
|
|
2498 the buffer position is at the junction of two runs, the
|
|
2499 run after the position is used) -- the beginning and
|
|
2500 end of the run, a list of all of the extents in that
|
|
2501 run, the "merged face" that results from merging all of
|
|
2502 the faces corresponding to those extents, the begin and
|
|
2503 end glyphs at the beginning of the run, etc. This is
|
|
2504 the information that redisplay needs in order to
|
|
2505 display this run.
|
|
2506
|
|
2507 Extent fragments have to be very quick to update to
|
|
2508 a new buffer position when moving linearly through
|
|
2509 the buffer. They rely on the stack-of-extents code,
|
|
2510 which does the heavy-duty algorithmic work of determining
|
|
2511 which extents overly a particular position. */
|
|
2512
|
|
2513 /* This function returns the position of the beginning of
|
|
2514 the first run that begins after POS, or returns POS if
|
|
2515 there are no such runs. */
|
|
2516
|
|
2517 static Bytind
|
|
2518 extent_find_end_of_run (Lisp_Object obj, Bytind pos, int outside_accessible)
|
|
2519 {
|
|
2520 Extent_List *sel;
|
|
2521 Extent_List *bel = buffer_or_string_extent_list (obj);
|
|
2522 Bytind pos1, pos2;
|
|
2523 int elind1, elind2;
|
|
2524 Memind mempos = buffer_or_string_bytind_to_memind (obj, pos);
|
|
2525 Bytind limit = outside_accessible ?
|
|
2526 buffer_or_string_absolute_end_byte (obj) :
|
|
2527 buffer_or_string_accessible_end_byte (obj);
|
|
2528
|
14
|
2529 if (!bel || !extent_list_num_els(bel))
|
0
|
2530 return limit;
|
|
2531
|
|
2532 sel = buffer_or_string_stack_of_extents_force (obj)->extents;
|
|
2533 soe_move (obj, mempos);
|
|
2534
|
|
2535 /* Find the first start position after POS. */
|
|
2536 elind1 = extent_list_locate_from_pos (bel, mempos+1, 0);
|
|
2537 if (elind1 < extent_list_num_els (bel))
|
|
2538 pos1 = buffer_or_string_memind_to_bytind
|
|
2539 (obj, extent_start (extent_list_at (bel, elind1, 0)));
|
|
2540 else
|
|
2541 pos1 = limit;
|
|
2542
|
|
2543 /* Find the first end position after POS. The extent corresponding
|
|
2544 to this position is either in the SOE or is greater than or
|
|
2545 equal to POS1, so we just have to look in the SOE. */
|
|
2546 elind2 = extent_list_locate_from_pos (sel, mempos+1, 1);
|
|
2547 if (elind2 < extent_list_num_els (sel))
|
|
2548 pos2 = buffer_or_string_memind_to_bytind
|
|
2549 (obj, extent_end (extent_list_at (sel, elind2, 1)));
|
|
2550 else
|
|
2551 pos2 = limit;
|
|
2552
|
|
2553 return min (min (pos1, pos2), limit);
|
|
2554 }
|
|
2555
|
|
2556 static Bytind
|
|
2557 extent_find_beginning_of_run (Lisp_Object obj, Bytind pos,
|
|
2558 int outside_accessible)
|
|
2559 {
|
|
2560 Extent_List *sel;
|
|
2561 Extent_List *bel = buffer_or_string_extent_list (obj);
|
|
2562 Bytind pos1, pos2;
|
|
2563 int elind1, elind2;
|
|
2564 Memind mempos = buffer_or_string_bytind_to_memind (obj, pos);
|
|
2565 Bytind limit = outside_accessible ?
|
|
2566 buffer_or_string_absolute_begin_byte (obj) :
|
|
2567 buffer_or_string_accessible_begin_byte (obj);
|
|
2568
|
14
|
2569 if (!bel || !extent_list_num_els(bel))
|
0
|
2570 return limit;
|
|
2571
|
|
2572 sel = buffer_or_string_stack_of_extents_force (obj)->extents;
|
|
2573 soe_move (obj, mempos);
|
|
2574
|
|
2575 /* Find the first end position before POS. */
|
|
2576 elind1 = extent_list_locate_from_pos (bel, mempos, 1);
|
|
2577 if (elind1 > 0)
|
|
2578 pos1 = buffer_or_string_memind_to_bytind
|
|
2579 (obj, extent_end (extent_list_at (bel, elind1 - 1, 1)));
|
|
2580 else
|
|
2581 pos1 = limit;
|
|
2582
|
|
2583 /* Find the first start position before POS. The extent corresponding
|
|
2584 to this position is either in the SOE or is less than or
|
|
2585 equal to POS1, so we just have to look in the SOE. */
|
|
2586 elind2 = extent_list_locate_from_pos (sel, mempos, 0);
|
|
2587 if (elind2 > 0)
|
|
2588 pos2 = buffer_or_string_memind_to_bytind
|
|
2589 (obj, extent_start (extent_list_at (sel, elind2 - 1, 0)));
|
|
2590 else
|
|
2591 pos2 = limit;
|
|
2592
|
|
2593 return max (max (pos1, pos2), limit);
|
|
2594 }
|
|
2595
|
|
2596 struct extent_fragment *
|
|
2597 extent_fragment_new (Lisp_Object buffer_or_string, struct frame *frm)
|
|
2598 {
|
|
2599 struct extent_fragment *ef = (struct extent_fragment *)
|
|
2600 xmalloc (sizeof (struct extent_fragment));
|
|
2601
|
|
2602 memset (ef, 0, sizeof (*ef));
|
|
2603 ef->object = buffer_or_string;
|
|
2604 ef->frm = frm;
|
|
2605 ef->extents = Dynarr_new (EXTENT);
|
|
2606 ef->begin_glyphs = Dynarr_new (struct glyph_block);
|
|
2607 ef->end_glyphs = Dynarr_new (struct glyph_block);
|
|
2608
|
|
2609 return ef;
|
|
2610 }
|
|
2611
|
|
2612 void
|
|
2613 extent_fragment_delete (struct extent_fragment *ef)
|
|
2614 {
|
|
2615 Dynarr_free (ef->extents);
|
|
2616 Dynarr_free (ef->begin_glyphs);
|
|
2617 Dynarr_free (ef->end_glyphs);
|
|
2618 xfree (ef);
|
|
2619 }
|
|
2620
|
|
2621 static int
|
|
2622 extent_priority_sort_function (const void *humpty, const void *dumpty)
|
|
2623 {
|
|
2624 CONST EXTENT foo = * (CONST EXTENT *) humpty;
|
|
2625 CONST EXTENT bar = * (CONST EXTENT *) dumpty;
|
|
2626 if (extent_priority (foo) < extent_priority (bar))
|
|
2627 return -1;
|
|
2628 return (extent_priority (foo) > extent_priority (bar));
|
|
2629 }
|
|
2630
|
|
2631 static void
|
|
2632 extent_fragment_sort_by_priority (extent_dynarr *extarr)
|
|
2633 {
|
|
2634 int i;
|
|
2635
|
|
2636 /* Sort our copy of the stack by extent_priority. We use a bubble
|
|
2637 sort here because it's going to be faster than qsort() for small
|
|
2638 numbers of extents (less than 10 or so), and 99.999% of the time
|
|
2639 there won't ever be more extents than this in the stack. */
|
|
2640 if (Dynarr_length (extarr) < 10)
|
|
2641 {
|
|
2642 for (i = 1; i < Dynarr_length (extarr); i++)
|
|
2643 {
|
|
2644 int j = i - 1;
|
|
2645 while (j >= 0 &&
|
|
2646 (extent_priority (Dynarr_at (extarr, j)) >
|
|
2647 extent_priority (Dynarr_at (extarr, j+1))))
|
|
2648 {
|
|
2649 EXTENT tmp = Dynarr_at (extarr, j);
|
|
2650 Dynarr_at (extarr, j) = Dynarr_at (extarr, j+1);
|
|
2651 Dynarr_at (extarr, j+1) = tmp;
|
|
2652 j--;
|
|
2653 }
|
|
2654 }
|
|
2655 }
|
|
2656 else
|
|
2657 /* But some loser programs mess up and may create a large number
|
|
2658 of extents overlapping the same spot. This will result in
|
|
2659 catastrophic behavior if we use the bubble sort above. */
|
|
2660 qsort (Dynarr_atp (extarr, 0), Dynarr_length (extarr),
|
|
2661 sizeof (EXTENT), extent_priority_sort_function);
|
|
2662 }
|
|
2663
|
|
2664 /* If PROP is the `invisible' property of an extent,
|
|
2665 this is 1 if the extent should be treated as invisible. */
|
|
2666
|
|
2667 #define EXTENT_PROP_MEANS_INVISIBLE(buf, prop) \
|
|
2668 (EQ (buf->invisibility_spec, Qt) \
|
|
2669 ? ! NILP (prop) \
|
|
2670 : invisible_p (prop, buf->invisibility_spec))
|
|
2671
|
|
2672 /* If PROP is the `invisible' property of a extent,
|
|
2673 this is 1 if the extent should be treated as invisible
|
|
2674 and should have an ellipsis. */
|
|
2675
|
|
2676 #define EXTENT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS(buf, prop) \
|
|
2677 (EQ (buf->invisibility_spec, Qt) \
|
|
2678 ? 0 \
|
|
2679 : invisible_ellipsis_p (prop, buf->invisibility_spec))
|
|
2680
|
|
2681 /* This is like a combination of memq and assq.
|
|
2682 Return 1 if PROPVAL appears as an element of LIST
|
|
2683 or as the car of an element of LIST.
|
|
2684 If PROPVAL is a list, compare each element against LIST
|
|
2685 in that way, and return 1 if any element of PROPVAL is found in LIST.
|
|
2686 Otherwise return 0.
|
|
2687 This function cannot quit. */
|
|
2688
|
|
2689 static int
|
|
2690 invisible_p (REGISTER Lisp_Object propval, Lisp_Object list)
|
|
2691 {
|
|
2692 REGISTER Lisp_Object tail, proptail;
|
|
2693 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
2694 {
|
|
2695 REGISTER Lisp_Object tem;
|
|
2696 tem = XCAR (tail);
|
|
2697 if (EQ (propval, tem))
|
|
2698 return 1;
|
|
2699 if (CONSP (tem) && EQ (propval, XCAR (tem)))
|
|
2700 return 1;
|
|
2701 }
|
|
2702 if (CONSP (propval))
|
|
2703 for (proptail = propval; CONSP (proptail);
|
|
2704 proptail = XCDR (proptail))
|
|
2705 {
|
|
2706 Lisp_Object propelt;
|
|
2707 propelt = XCAR (proptail);
|
|
2708 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
2709 {
|
|
2710 REGISTER Lisp_Object tem;
|
|
2711 tem = XCAR (tail);
|
|
2712 if (EQ (propelt, tem))
|
|
2713 return 1;
|
|
2714 if (CONSP (tem) && EQ (propelt, XCAR (tem)))
|
|
2715 return 1;
|
|
2716 }
|
|
2717 }
|
|
2718 return 0;
|
|
2719 }
|
|
2720
|
|
2721 /* Return 1 if PROPVAL appears as the car of an element of LIST
|
|
2722 and the cdr of that element is non-nil.
|
|
2723 If PROPVAL is a list, check each element of PROPVAL in that way,
|
|
2724 and the first time some element is found,
|
|
2725 return 1 if the cdr of that element is non-nil.
|
|
2726 Otherwise return 0.
|
|
2727 This function cannot quit. */
|
|
2728
|
|
2729 static int
|
|
2730 invisible_ellipsis_p (REGISTER Lisp_Object propval, Lisp_Object list)
|
|
2731 {
|
|
2732 REGISTER Lisp_Object tail, proptail;
|
|
2733 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
2734 {
|
|
2735 REGISTER Lisp_Object tem;
|
|
2736 tem = XCAR (tail);
|
|
2737 if (CONSP (tem) && EQ (propval, XCAR (tem)))
|
|
2738 return ! NILP (XCDR (tem));
|
|
2739 }
|
|
2740 if (CONSP (propval))
|
|
2741 for (proptail = propval; CONSP (proptail);
|
|
2742 proptail = XCDR (proptail))
|
|
2743 {
|
|
2744 Lisp_Object propelt;
|
|
2745 propelt = XCAR (proptail);
|
|
2746 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
2747 {
|
|
2748 REGISTER Lisp_Object tem;
|
|
2749 tem = XCAR (tail);
|
|
2750 if (CONSP (tem) && EQ (propelt, XCAR (tem)))
|
|
2751 return ! NILP (XCDR (tem));
|
|
2752 }
|
|
2753 }
|
|
2754 return 0;
|
|
2755 }
|
|
2756
|
|
2757 face_index
|
|
2758 extent_fragment_update (struct window *w, struct extent_fragment *ef,
|
|
2759 Bytind pos)
|
|
2760 {
|
|
2761 int i;
|
|
2762 Extent_List *sel =
|
|
2763 buffer_or_string_stack_of_extents_force (ef->object)->extents;
|
|
2764 EXTENT lhe = 0;
|
|
2765 struct extent dummy_lhe_extent;
|
|
2766 Memind mempos = buffer_or_string_bytind_to_memind (ef->object, pos);
|
|
2767
|
|
2768 #ifdef ERROR_CHECK_EXTENTS
|
|
2769 assert (pos >= buffer_or_string_accessible_begin_byte (ef->object)
|
|
2770 && pos <= buffer_or_string_accessible_end_byte (ef->object));
|
|
2771 #endif
|
|
2772
|
|
2773 Dynarr_reset (ef->extents);
|
|
2774 Dynarr_reset (ef->begin_glyphs);
|
|
2775 Dynarr_reset (ef->end_glyphs);
|
|
2776
|
|
2777 ef->previously_invisible = ef->invisible;
|
|
2778 if (ef->invisible)
|
|
2779 {
|
|
2780 if (ef->invisible_ellipses)
|
|
2781 ef->invisible_ellipses_already_displayed = 1;
|
|
2782 }
|
|
2783 else
|
|
2784 ef->invisible_ellipses_already_displayed = 0;
|
|
2785 ef->invisible = 0;
|
|
2786 ef->invisible_ellipses = 0;
|
|
2787
|
|
2788 /* Set up the begin and end positions. */
|
|
2789 ef->pos = pos;
|
|
2790 ef->end = extent_find_end_of_run (ef->object, pos, 0);
|
|
2791
|
|
2792 /* Note that extent_find_end_of_run() already moved the SOE for us. */
|
|
2793 /* soe_move (ef->object, mempos); */
|
|
2794
|
|
2795 /* Determine the begin glyphs at POS. */
|
|
2796 for (i = 0; i < extent_list_num_els (sel); i++)
|
|
2797 {
|
|
2798 EXTENT e = extent_list_at (sel, i, 0);
|
|
2799 if (extent_start (e) == mempos && !NILP (extent_begin_glyph (e)))
|
|
2800 {
|
|
2801 Lisp_Object glyph = extent_begin_glyph (e);
|
|
2802 struct glyph_block gb;
|
|
2803
|
|
2804 gb.glyph = glyph;
|
|
2805 gb.extent = Qnil;
|
|
2806 XSETEXTENT (gb.extent, e);
|
|
2807 Dynarr_add (ef->begin_glyphs, gb);
|
|
2808 }
|
|
2809 }
|
|
2810
|
|
2811 /* Determine the end glyphs at POS. */
|
|
2812 for (i = 0; i < extent_list_num_els (sel); i++)
|
|
2813 {
|
|
2814 EXTENT e = extent_list_at (sel, i, 1);
|
|
2815 if (extent_end (e) == mempos && !NILP (extent_end_glyph (e)))
|
|
2816 {
|
|
2817 Lisp_Object glyph = extent_end_glyph (e);
|
|
2818 struct glyph_block gb;
|
|
2819
|
|
2820 gb.glyph = glyph;
|
|
2821 gb.extent = Qnil;
|
|
2822 XSETEXTENT (gb.extent, e);
|
|
2823 Dynarr_add (ef->end_glyphs, gb);
|
|
2824 }
|
|
2825 }
|
|
2826
|
|
2827 /* We tried determining all the charsets used in the run here,
|
|
2828 but that fails even if we only do the current line -- display
|
|
2829 tables or non-printable characters might cause other charsets
|
|
2830 to be used. */
|
|
2831
|
|
2832 /* Determine whether the last-highlighted-extent is present. */
|
|
2833 if (EXTENTP (Vlast_highlighted_extent))
|
|
2834 lhe = XEXTENT (Vlast_highlighted_extent);
|
|
2835
|
|
2836 /* Now add all extents that overlap the character after POS and
|
|
2837 have a non-nil face. Also check if the character is invisible. */
|
|
2838 for (i = 0; i < extent_list_num_els (sel); i++)
|
|
2839 {
|
|
2840 EXTENT e = extent_list_at (sel, i, 0);
|
|
2841 if (extent_end (e) > mempos)
|
|
2842 {
|
|
2843 Lisp_Object invis_prop = extent_invisible (e);
|
|
2844
|
|
2845 if (!NILP (invis_prop))
|
|
2846 {
|
|
2847 if (!BUFFERP (ef->object))
|
|
2848 /* #### no `string-invisibility-spec' */
|
|
2849 ef->invisible = 1;
|
|
2850 else
|
|
2851 {
|
|
2852 if (!ef->invisible_ellipses_already_displayed &&
|
|
2853 EXTENT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS
|
|
2854 (XBUFFER (ef->object), invis_prop))
|
|
2855 {
|
|
2856 ef->invisible = 1;
|
|
2857 ef->invisible_ellipses = 1;
|
|
2858 }
|
|
2859 else if (EXTENT_PROP_MEANS_INVISIBLE
|
|
2860 (XBUFFER (ef->object), invis_prop))
|
|
2861 ef->invisible = 1;
|
|
2862 }
|
|
2863 }
|
|
2864
|
|
2865 /* Remember that one of the extents in the list might be our
|
|
2866 dummy extent representing the highlighting that is
|
|
2867 attached to some other extent that is currently
|
|
2868 mouse-highlighted. When an extent is mouse-highlighted,
|
|
2869 it is as if there are two extents there, of potentially
|
|
2870 different priorities: the extent being highlighted, with
|
|
2871 whatever face and priority it has; and an ephemeral
|
|
2872 extent in the `mouse-face' face with
|
|
2873 `mouse-highlight-priority'.
|
|
2874 */
|
|
2875
|
|
2876 if (!NILP (extent_face (e)))
|
|
2877 Dynarr_add (ef->extents, e);
|
|
2878 if (e == lhe)
|
|
2879 {
|
|
2880 /* memset isn't really necessary; we only deref `priority'
|
|
2881 and `face' */
|
|
2882 memset (&dummy_lhe_extent, 0, sizeof (dummy_lhe_extent));
|
|
2883 set_extent_priority (&dummy_lhe_extent,
|
|
2884 mouse_highlight_priority);
|
|
2885 extent_face (&dummy_lhe_extent) = extent_mouse_face (lhe);
|
|
2886 Dynarr_add (ef->extents, &dummy_lhe_extent);
|
|
2887 }
|
|
2888 }
|
|
2889 }
|
|
2890
|
|
2891 extent_fragment_sort_by_priority (ef->extents);
|
|
2892
|
|
2893 /* Now merge the faces together into a single face. The code to
|
|
2894 do this is in faces.c because it involves manipulating faces. */
|
|
2895 return get_extent_fragment_face_cache_index (w, ef);
|
|
2896 }
|
|
2897
|
|
2898
|
|
2899 /************************************************************************/
|
|
2900 /* extent-object methods */
|
|
2901 /************************************************************************/
|
|
2902
|
|
2903 /* These are the basic helper functions for handling the allocation of
|
|
2904 extent objects. They are similar to the functions for other
|
|
2905 lrecord objects. allocate_extent() is in alloc.c, not here. */
|
|
2906
|
|
2907 static Lisp_Object mark_extent (Lisp_Object, void (*) (Lisp_Object));
|
|
2908 static int extent_equal (Lisp_Object, Lisp_Object, int depth);
|
|
2909 static unsigned long extent_hash (Lisp_Object obj, int depth);
|
|
2910 static void print_extent (Lisp_Object obj, Lisp_Object printcharfun,
|
|
2911 int escapeflag);
|
|
2912 static Lisp_Object extent_getprop (Lisp_Object obj, Lisp_Object prop);
|
|
2913 static int extent_putprop (Lisp_Object obj, Lisp_Object prop,
|
|
2914 Lisp_Object value);
|
|
2915 static int extent_remprop (Lisp_Object obj, Lisp_Object prop);
|
|
2916 static Lisp_Object extent_plist (Lisp_Object obj);
|
|
2917
|
|
2918 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS ("extent", extent,
|
|
2919 mark_extent,
|
|
2920 print_extent,
|
|
2921 /* NOTE: If you declare a
|
|
2922 finalization method here,
|
|
2923 it will NOT be called.
|
|
2924 Shaft city. */
|
|
2925 0,
|
|
2926 extent_equal, extent_hash,
|
|
2927 extent_getprop, extent_putprop,
|
|
2928 extent_remprop, extent_plist,
|
|
2929 struct extent);
|
|
2930
|
|
2931 static Lisp_Object
|
|
2932 mark_extent (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
2933 {
|
|
2934 struct extent *extent = XEXTENT (obj);
|
|
2935
|
|
2936 ((markobj) (extent_object (extent)));
|
|
2937 ((markobj) (extent_no_chase_normal_field (extent, face)));
|
|
2938 return (extent->plist);
|
|
2939 }
|
|
2940
|
|
2941 static char *
|
|
2942 print_extent_1 (char *buf, Lisp_Object extent_obj)
|
|
2943 {
|
|
2944 EXTENT ext = XEXTENT (extent_obj);
|
|
2945 EXTENT anc = extent_ancestor (ext);
|
|
2946 char *bp = buf;
|
|
2947 Lisp_Object tail;
|
|
2948
|
|
2949 /* Retrieve the ancestor and use it, for faster retrieval of properties */
|
|
2950
|
|
2951 if (!NILP (extent_begin_glyph (anc))) *bp++ = '*';
|
|
2952 *bp++ = (extent_start_open_p (anc) ? '(': '[');
|
|
2953 if (extent_detached_p (ext))
|
|
2954 sprintf (bp, "detached");
|
|
2955 else
|
|
2956 {
|
|
2957 Bufpos from = XINT (Fextent_start_position (extent_obj));
|
|
2958 Bufpos to = XINT (Fextent_end_position (extent_obj));
|
|
2959 sprintf (bp, "%d, %d", from, to);
|
|
2960 }
|
|
2961 bp += strlen (bp);
|
|
2962 *bp++ = (extent_end_open_p (anc) ? ')': ']');
|
|
2963 if (!NILP (extent_end_glyph (anc))) *bp++ = '*';
|
|
2964 *bp++ = ' ';
|
|
2965
|
|
2966 if (!NILP (extent_read_only (anc))) *bp++ = '%';
|
|
2967 if (!NILP (extent_mouse_face (anc))) *bp++ = 'H';
|
|
2968 if (extent_unique_p (anc)) *bp++ = 'U';
|
|
2969 else if (extent_duplicable_p (anc)) *bp++ = 'D';
|
|
2970 if (!NILP (extent_invisible (anc))) *bp++ = 'I';
|
|
2971
|
|
2972 if (!NILP (extent_read_only (anc)) || !NILP (extent_mouse_face (anc)) ||
|
20
|
2973 extent_unique_p (anc) ||
|
0
|
2974 extent_duplicable_p (anc) || !NILP (extent_invisible (anc)))
|
|
2975 *bp++ = ' ';
|
|
2976
|
|
2977 tail = extent_plist_slot (anc);
|
|
2978
|
|
2979 for (; !NILP (tail); tail = Fcdr (Fcdr (tail)))
|
|
2980 {
|
|
2981 struct Lisp_String *k = XSYMBOL (XCAR (tail))->name;
|
|
2982 Lisp_Object v = XCAR (XCDR (tail));
|
|
2983 if (NILP (v)) continue;
|
|
2984 memcpy (bp, (char *) string_data (k), string_length (k));
|
|
2985 bp += string_length (k);
|
|
2986 *bp++ = ' ';
|
|
2987 }
|
|
2988
|
|
2989 sprintf (bp, "0x%lx", (long) ext);
|
|
2990 bp += strlen (bp);
|
|
2991
|
|
2992 *bp++ = 0;
|
|
2993 return buf;
|
|
2994 }
|
|
2995
|
|
2996 static void
|
|
2997 print_extent (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
2998 {
|
|
2999 char buf2[256];
|
|
3000
|
|
3001 if (escapeflag)
|
|
3002 {
|
|
3003 CONST char *title = "";
|
|
3004 CONST char *name = "";
|
|
3005 CONST char *posttitle = "";
|
|
3006 Lisp_Object obj2 = Qnil;
|
|
3007
|
|
3008 /* Destroyed extents have 't' in the object field, causing
|
|
3009 extent_object() to abort (maybe). */
|
|
3010 if (EXTENT_LIVE_P (XEXTENT (obj)))
|
|
3011 obj2 = extent_object (XEXTENT (obj));
|
|
3012
|
|
3013 if (NILP (obj2))
|
|
3014 title = "no buffer";
|
|
3015 else if (BUFFERP (obj2))
|
|
3016 {
|
|
3017 if (BUFFER_LIVE_P (XBUFFER (obj2)))
|
|
3018 {
|
|
3019 title = "buffer ";
|
16
|
3020 name = (char *) XSTRING_DATA (XBUFFER (obj2)->name);
|
0
|
3021 }
|
|
3022 else
|
|
3023 {
|
|
3024 title = "Killed Buffer";
|
|
3025 name = "";
|
|
3026 }
|
|
3027 }
|
|
3028 else
|
|
3029 {
|
|
3030 assert (STRINGP (obj2));
|
|
3031 title = "string \"";
|
|
3032 posttitle = "\"";
|
16
|
3033 name = (char *) XSTRING_DATA (obj2);
|
0
|
3034 }
|
|
3035
|
|
3036 if (print_readably)
|
|
3037 {
|
|
3038 if (!EXTENT_LIVE_P (XEXTENT (obj)))
|
|
3039 error ("printing unreadable object #<destroyed extent>");
|
|
3040 else
|
|
3041 error ("printing unreadable object #<extent %s>",
|
|
3042 print_extent_1 (buf2, obj));
|
|
3043 }
|
|
3044
|
|
3045 if (!EXTENT_LIVE_P (XEXTENT (obj)))
|
|
3046 write_c_string ("#<destroyed extent", printcharfun);
|
|
3047 else
|
|
3048 {
|
|
3049 char buf[256];
|
|
3050 write_c_string ("#<extent ", printcharfun);
|
|
3051 if (extent_detached_p (XEXTENT (obj)))
|
|
3052 sprintf (buf, "%s from %s%s%s",
|
|
3053 print_extent_1 (buf2, obj), title, name, posttitle);
|
|
3054 else
|
|
3055 sprintf (buf, "%s in %s%s%s",
|
|
3056 print_extent_1 (buf2, obj),
|
|
3057 title, name, posttitle);
|
|
3058 write_c_string (buf, printcharfun);
|
|
3059 }
|
|
3060 }
|
|
3061 else
|
|
3062 {
|
|
3063 if (print_readably)
|
|
3064 error ("printing unreadable object #<extent>");
|
|
3065 write_c_string ("#<extent", printcharfun);
|
|
3066 }
|
|
3067 write_c_string (">", printcharfun);
|
|
3068 }
|
|
3069
|
|
3070 static int
|
|
3071 properties_equal (EXTENT e1, EXTENT e2, int depth)
|
|
3072 {
|
|
3073 /* When this function is called, all indirections have been followed.
|
|
3074 Thus, the indirection checks in the various macros below will not
|
|
3075 amount to anything, and could be removed. However, the time
|
|
3076 savings would probably not be significant. */
|
|
3077 if (!(EQ (extent_face (e1), extent_face (e2)) &&
|
|
3078 extent_priority (e1) == extent_priority (e2) &&
|
|
3079 internal_equal (extent_begin_glyph (e1), extent_begin_glyph (e2),
|
|
3080 depth + 1) &&
|
|
3081 internal_equal (extent_end_glyph (e1), extent_end_glyph (e2),
|
|
3082 depth + 1)))
|
|
3083 return 0;
|
|
3084
|
|
3085 /* compare the bit flags. */
|
|
3086 {
|
|
3087 /* The has_aux field should not be relevant. */
|
|
3088 int e1_has_aux = e1->flags.has_aux;
|
|
3089 int e2_has_aux = e2->flags.has_aux;
|
|
3090 int value;
|
|
3091
|
|
3092 e1->flags.has_aux = e2->flags.has_aux = 0;
|
|
3093 value = memcmp (&e1->flags, &e2->flags, sizeof (e1->flags));
|
|
3094 e1->flags.has_aux = e1_has_aux;
|
|
3095 e2->flags.has_aux = e2_has_aux;
|
|
3096 if (value)
|
|
3097 return 0;
|
|
3098 }
|
|
3099
|
|
3100 /* compare the random elements of the plists. */
|
|
3101 return (!plists_differ (extent_no_chase_plist (e1),
|
|
3102 extent_no_chase_plist (e2),
|
|
3103 0, 0, depth + 1));
|
|
3104 }
|
|
3105
|
|
3106 static int
|
|
3107 extent_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
3108 {
|
|
3109 struct extent *e1 = XEXTENT (o1);
|
|
3110 struct extent *e2 = XEXTENT (o2);
|
|
3111 return
|
|
3112 (extent_start (e1) == extent_start (e2) &&
|
|
3113 extent_end (e1) == extent_end (e2) &&
|
|
3114 internal_equal (extent_object (e1), extent_object (e2), depth + 1) &&
|
|
3115 properties_equal (extent_ancestor (e1), extent_ancestor (e2),
|
|
3116 depth));
|
|
3117 }
|
|
3118
|
|
3119 static unsigned long
|
|
3120 extent_hash (Lisp_Object obj, int depth)
|
|
3121 {
|
|
3122 struct extent *e = XEXTENT (obj);
|
|
3123 /* No need to hash all of the elements; that would take too long.
|
|
3124 Just hash the most common ones. */
|
|
3125 return HASH3 (extent_start (e), extent_end (e),
|
|
3126 internal_hash (extent_object (e), depth + 1));
|
|
3127 }
|
|
3128
|
|
3129 static Lisp_Object
|
|
3130 extent_getprop (Lisp_Object obj, Lisp_Object prop)
|
|
3131 {
|
|
3132 return Fextent_property (obj, prop, Qunbound);
|
|
3133 }
|
|
3134
|
|
3135 static int
|
|
3136 extent_putprop (Lisp_Object obj, Lisp_Object prop, Lisp_Object value)
|
|
3137 {
|
|
3138 error ("Not yet implemented"); /* #### */
|
|
3139 return 0;
|
|
3140 }
|
|
3141
|
|
3142 static int
|
|
3143 extent_remprop (Lisp_Object obj, Lisp_Object prop)
|
|
3144 {
|
|
3145 error ("Not yet implemented"); /* #### */
|
|
3146 return 0;
|
|
3147 }
|
|
3148
|
|
3149 static Lisp_Object
|
|
3150 extent_plist (Lisp_Object obj)
|
|
3151 {
|
|
3152 return Fextent_properties (obj);
|
|
3153 }
|
|
3154
|
|
3155
|
|
3156 /************************************************************************/
|
|
3157 /* basic extent accessors */
|
|
3158 /************************************************************************/
|
|
3159
|
|
3160 /* These functions are for checking externally-passed extent objects
|
|
3161 and returning an extent's basic properties, which include the
|
|
3162 buffer the extent is associated with, the endpoints of the extent's
|
|
3163 range, the open/closed-ness of those endpoints, and whether the
|
|
3164 extent is detached. Manipulating these properties requires
|
|
3165 manipulating the ordered lists that hold extents; thus, functions
|
|
3166 to do that are in a later section. */
|
|
3167
|
|
3168 /* Given a Lisp_Object that is supposed to be an extent, make sure it
|
|
3169 is OK and return an extent pointer. Extents can be in one of four
|
|
3170 states:
|
|
3171
|
|
3172 1) destroyed
|
|
3173 2) detached and not associated with a buffer
|
|
3174 3) detached and associated with a buffer
|
|
3175 4) attached to a buffer
|
|
3176
|
|
3177 If FLAGS is 0, types 2-4 are allowed. If FLAGS is DE_MUST_HAVE_BUFFER,
|
|
3178 types 3-4 are allowed. If FLAGS is DE_MUST_BE_ATTACHED, only type 4
|
|
3179 is allowed.
|
|
3180 */
|
|
3181
|
|
3182 static EXTENT
|
|
3183 decode_extent (Lisp_Object extent_obj, unsigned int flags)
|
|
3184 {
|
|
3185 EXTENT extent;
|
|
3186 Lisp_Object obj;
|
|
3187
|
|
3188 CHECK_LIVE_EXTENT (extent_obj);
|
|
3189 extent = XEXTENT (extent_obj);
|
|
3190 obj = extent_object (extent);
|
|
3191
|
|
3192 /* the following condition will fail if we're dealing with a freed extent */
|
|
3193 assert (NILP (obj) || BUFFERP (obj) || STRINGP (obj));
|
|
3194
|
|
3195 if (flags & DE_MUST_BE_ATTACHED)
|
|
3196 flags |= DE_MUST_HAVE_BUFFER;
|
|
3197
|
|
3198 /* if buffer is dead, then convert extent to have no buffer. */
|
|
3199 if (BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj)))
|
|
3200 obj = extent_object (extent) = Qnil;
|
|
3201
|
|
3202 assert (!NILP (obj) || extent_detached_p (extent));
|
|
3203
|
|
3204 if (NILP (obj) && (flags & DE_MUST_HAVE_BUFFER))
|
|
3205 {
|
|
3206 signal_simple_error ("extent doesn't belong to a buffer or string",
|
|
3207 extent_obj);
|
|
3208 }
|
|
3209
|
|
3210 if (extent_detached_p (extent) && (flags & DE_MUST_BE_ATTACHED))
|
|
3211 {
|
|
3212 signal_simple_error ("extent cannot be detached", extent_obj);
|
|
3213 }
|
|
3214
|
|
3215 return extent;
|
|
3216 }
|
|
3217
|
|
3218 /* Note that the returned value is a buffer position, not a byte index. */
|
|
3219
|
|
3220 static Lisp_Object
|
|
3221 extent_endpoint_external (Lisp_Object extent_obj, int endp)
|
|
3222 {
|
|
3223 EXTENT extent = decode_extent (extent_obj, 0);
|
|
3224
|
|
3225 if (extent_detached_p (extent))
|
|
3226 return Qnil;
|
|
3227 else
|
|
3228 return make_int (extent_endpoint_bufpos (extent, endp));
|
|
3229 }
|
|
3230
|
20
|
3231 DEFUN ("extentp", Fextentp, 1, 1, 0, /*
|
0
|
3232 T if OBJECT is an extent.
|
20
|
3233 */
|
|
3234 (object))
|
0
|
3235 {
|
|
3236 if (EXTENTP (object))
|
|
3237 return Qt;
|
|
3238 return Qnil;
|
|
3239 }
|
|
3240
|
20
|
3241 DEFUN ("extent-live-p", Fextent_live_p, 1, 1, 0, /*
|
0
|
3242 T if OBJECT is an extent and the extent has not been destroyed.
|
20
|
3243 */
|
|
3244 (object))
|
0
|
3245 {
|
|
3246 if (EXTENTP (object) && EXTENT_LIVE_P (XEXTENT (object)))
|
|
3247 return Qt;
|
|
3248 return Qnil;
|
|
3249 }
|
|
3250
|
20
|
3251 DEFUN ("extent-detached-p", Fextent_detached_p, 1, 1, 0, /*
|
0
|
3252 T if EXTENT is detached.
|
20
|
3253 */
|
|
3254 (extent))
|
0
|
3255 {
|
|
3256 if (extent_detached_p (decode_extent (extent, 0)))
|
|
3257 return Qt;
|
|
3258 return Qnil;
|
|
3259 }
|
|
3260
|
20
|
3261 DEFUN ("extent-object", Fextent_object, 1, 1, 0, /*
|
0
|
3262 Return object (buffer or string) EXTENT refers to.
|
20
|
3263 */
|
|
3264 (extent))
|
0
|
3265 {
|
|
3266 return extent_object (decode_extent (extent, 0));
|
|
3267 }
|
|
3268
|
20
|
3269 DEFUN ("extent-start-position", Fextent_start_position, 1, 1, 0, /*
|
0
|
3270 Return start position of EXTENT, or nil if EXTENT is detached.
|
20
|
3271 */
|
|
3272 (extent))
|
0
|
3273 {
|
|
3274 return extent_endpoint_external (extent, 0);
|
|
3275 }
|
|
3276
|
20
|
3277 DEFUN ("extent-end-position", Fextent_end_position, 1, 1, 0, /*
|
0
|
3278 Return end position of EXTENT, or nil if EXTENT is detached.
|
20
|
3279 */
|
|
3280 (extent))
|
0
|
3281 {
|
|
3282 return extent_endpoint_external (extent, 1);
|
|
3283 }
|
|
3284
|
20
|
3285 DEFUN ("extent-length", Fextent_length, 1, 1, 0, /*
|
0
|
3286 Return length of EXTENT in characters.
|
20
|
3287 */
|
|
3288 (extent))
|
0
|
3289 {
|
|
3290 EXTENT e = decode_extent (extent, DE_MUST_BE_ATTACHED);
|
|
3291 return make_int (extent_endpoint_bufpos (e, 1)
|
|
3292 - extent_endpoint_bufpos (e, 0));
|
|
3293 }
|
|
3294
|
20
|
3295 DEFUN ("next-extent", Fnext_extent, 1, 1, 0, /*
|
0
|
3296 Find next extent after EXTENT.
|
|
3297 If EXTENT is a buffer return the first extent in the buffer; likewise
|
|
3298 for strings.
|
|
3299 Extents in a buffer are ordered in what is called the \"display\"
|
|
3300 order, which sorts by increasing start positions and then by *decreasing*
|
|
3301 end positions.
|
|
3302 If you want to perform an operation on a series of extents, use
|
|
3303 `map-extents' instead of this function; it is much more efficient.
|
|
3304 The primary use of this function should be to enumerate all the
|
|
3305 extents in a buffer.
|
|
3306 Note: The display order is not necessarily the order that `map-extents'
|
|
3307 processes extents in!
|
20
|
3308 */
|
|
3309 (extent))
|
0
|
3310 {
|
|
3311 Lisp_Object val;
|
|
3312 EXTENT next;
|
|
3313
|
|
3314 if (EXTENTP (extent))
|
|
3315 next = extent_next (decode_extent (extent, DE_MUST_BE_ATTACHED));
|
|
3316 else
|
|
3317 next = extent_first (decode_buffer_or_string (extent));
|
|
3318
|
|
3319 if (!next)
|
|
3320 return (Qnil);
|
|
3321 XSETEXTENT (val, next);
|
|
3322 return (val);
|
|
3323 }
|
|
3324
|
20
|
3325 DEFUN ("previous-extent", Fprevious_extent, 1, 1, 0, /*
|
0
|
3326 Find last extent before EXTENT.
|
|
3327 If EXTENT is a buffer return the last extent in the buffer; likewise
|
|
3328 for strings.
|
|
3329 This function is analogous to `next-extent'.
|
20
|
3330 */
|
|
3331 (extent))
|
0
|
3332 {
|
|
3333 Lisp_Object val;
|
|
3334 EXTENT prev;
|
|
3335
|
|
3336 if (EXTENTP (extent))
|
|
3337 prev = extent_previous (decode_extent (extent, DE_MUST_BE_ATTACHED));
|
|
3338 else
|
|
3339 prev = extent_last (decode_buffer_or_string (extent));
|
|
3340
|
|
3341 if (!prev)
|
|
3342 return (Qnil);
|
|
3343 XSETEXTENT (val, prev);
|
|
3344 return (val);
|
|
3345 }
|
|
3346
|
|
3347 #ifdef DEBUG_XEMACS
|
|
3348
|
20
|
3349 DEFUN ("next-e-extent", Fnext_e_extent, 1, 1, 0, /*
|
0
|
3350 Find next extent after EXTENT using the \"e\" order.
|
|
3351 If EXTENT is a buffer return the first extent in the buffer; likewise
|
|
3352 for strings.
|
20
|
3353 */
|
|
3354 (extent))
|
0
|
3355 {
|
|
3356 Lisp_Object val;
|
|
3357 EXTENT next;
|
|
3358
|
|
3359 if (EXTENTP (extent))
|
|
3360 next = extent_e_next (decode_extent (extent, DE_MUST_BE_ATTACHED));
|
|
3361 else
|
|
3362 next = extent_e_first (decode_buffer_or_string (extent));
|
|
3363
|
|
3364 if (!next)
|
|
3365 return (Qnil);
|
|
3366 XSETEXTENT (val, next);
|
|
3367 return (val);
|
|
3368 }
|
|
3369
|
20
|
3370 DEFUN ("previous-e-extent", Fprevious_e_extent, 1, 1, 0, /*
|
0
|
3371 Find last extent before EXTENT using the \"e\" order.
|
|
3372 If EXTENT is a buffer return the last extent in the buffer; likewise
|
|
3373 for strings.
|
|
3374 This function is analogous to `next-e-extent'.
|
20
|
3375 */
|
|
3376 (extent))
|
0
|
3377 {
|
|
3378 Lisp_Object val;
|
|
3379 EXTENT prev;
|
|
3380
|
|
3381 if (EXTENTP (extent))
|
|
3382 prev = extent_e_previous (decode_extent (extent, DE_MUST_BE_ATTACHED));
|
|
3383 else
|
|
3384 prev = extent_e_last (decode_buffer_or_string (extent));
|
|
3385
|
|
3386 if (!prev)
|
|
3387 return (Qnil);
|
|
3388 XSETEXTENT (val, prev);
|
|
3389 return (val);
|
|
3390 }
|
|
3391
|
|
3392 #endif
|
|
3393
|
20
|
3394 DEFUN ("next-extent-change", Fnext_extent_change, 1, 2, 0, /*
|
0
|
3395 Return the next position after POS where an extent begins or ends.
|
|
3396 If POS is at the end of the buffer or string, POS will be returned;
|
|
3397 otherwise a position greater than POS will always be returned.
|
|
3398 If BUFFER is nil, the current buffer is assumed.
|
20
|
3399 */
|
|
3400 (pos, object))
|
0
|
3401 {
|
|
3402 Lisp_Object obj = decode_buffer_or_string (object);
|
|
3403 Bytind bpos;
|
|
3404
|
|
3405 bpos = get_buffer_or_string_pos_byte (obj, pos, GB_ALLOW_PAST_ACCESSIBLE);
|
|
3406 bpos = extent_find_end_of_run (obj, bpos, 1);
|
|
3407 return make_int (buffer_or_string_bytind_to_bufpos (obj, bpos));
|
|
3408 }
|
|
3409
|
20
|
3410 DEFUN ("previous-extent-change", Fprevious_extent_change, 1, 2, 0, /*
|
0
|
3411 Return the last position before POS where an extent begins or ends.
|
|
3412 If POS is at the beginning of the buffer or string, POS will be returned;
|
|
3413 otherwise a position less than POS will always be returned.
|
|
3414 If OBJECT is nil, the current buffer is assumed.
|
20
|
3415 */
|
|
3416 (pos, object))
|
0
|
3417 {
|
|
3418 Lisp_Object obj = decode_buffer_or_string (object);
|
|
3419 Bytind bpos;
|
|
3420
|
|
3421 bpos = get_buffer_or_string_pos_byte (obj, pos, GB_ALLOW_PAST_ACCESSIBLE);
|
|
3422 bpos = extent_find_beginning_of_run (obj, bpos, 1);
|
|
3423 return make_int (buffer_or_string_bytind_to_bufpos (obj, bpos));
|
|
3424 }
|
|
3425
|
|
3426
|
|
3427 /************************************************************************/
|
|
3428 /* parent and children stuff */
|
|
3429 /************************************************************************/
|
|
3430
|
20
|
3431 DEFUN ("extent-parent", Fextent_parent, 1, 1, 0, /*
|
0
|
3432 Return the parent (if any) of EXTENT.
|
|
3433 If an extent has a parent, it derives all its properties from that extent
|
|
3434 and has no properties of its own. (The only \"properties\" that the
|
|
3435 extent keeps are the buffer/string it refers to and the start and end
|
|
3436 points.) It is possible for an extent's parent to itself have a parent.
|
20
|
3437 */
|
|
3438 (extent))
|
0
|
3439 /* do I win the prize for the strangest split infinitive? */
|
|
3440 {
|
|
3441 EXTENT e = decode_extent (extent, 0);
|
|
3442 return extent_parent (e);
|
|
3443 }
|
|
3444
|
20
|
3445 DEFUN ("extent-children", Fextent_children, 1, 1, 0, /*
|
0
|
3446 Return a list of the children (if any) of EXTENT.
|
|
3447 The children of an extent are all those extents whose parent is that extent.
|
|
3448 This function does not recursively trace children of children.
|
|
3449 \(To do that, use `extent-descendants'.)
|
20
|
3450 */
|
|
3451 (extent))
|
0
|
3452 {
|
|
3453 EXTENT e = decode_extent (extent, 0);
|
|
3454 Lisp_Object children = extent_children (e);
|
|
3455
|
|
3456 if (!NILP (children))
|
|
3457 return Fcopy_sequence (XWEAK_LIST_LIST (children));
|
|
3458 else
|
|
3459 return Qnil;
|
|
3460 }
|
|
3461
|
|
3462 static void
|
|
3463 remove_extent_from_children_list (EXTENT e, Lisp_Object child)
|
|
3464 {
|
|
3465 Lisp_Object children = extent_children (e);
|
|
3466
|
|
3467 #ifdef ERROR_CHECK_EXTENTS
|
|
3468 assert (!NILP (memq_no_quit (child, XWEAK_LIST_LIST (children))));
|
|
3469 #endif
|
|
3470 XWEAK_LIST_LIST (children) =
|
|
3471 delq_no_quit (child, XWEAK_LIST_LIST (children));
|
|
3472 }
|
|
3473
|
|
3474 static void
|
|
3475 add_extent_to_children_list (EXTENT e, Lisp_Object child)
|
|
3476 {
|
|
3477 Lisp_Object children = extent_children (e);
|
|
3478
|
|
3479 if (NILP (children))
|
|
3480 {
|
|
3481 children = make_weak_list (WEAK_LIST_SIMPLE);
|
|
3482 set_extent_no_chase_aux_field (e, children, children);
|
|
3483 }
|
|
3484
|
|
3485 #ifdef ERROR_CHECK_EXTENTS
|
|
3486 assert (NILP (memq_no_quit (child, XWEAK_LIST_LIST (children))));
|
|
3487 #endif
|
|
3488 XWEAK_LIST_LIST (children) = Fcons (child, XWEAK_LIST_LIST (children));
|
|
3489 }
|
|
3490
|
20
|
3491 DEFUN ("set-extent-parent", Fset_extent_parent, 2, 2, 0, /*
|
0
|
3492 Set the parent of EXTENT to PARENT (may be nil).
|
|
3493 See `extent-parent'.
|
20
|
3494 */
|
|
3495 (extent, parent))
|
0
|
3496 {
|
|
3497 EXTENT e = decode_extent (extent, 0);
|
|
3498 Lisp_Object cur_parent = extent_parent (e);
|
|
3499 Lisp_Object rest;
|
|
3500
|
|
3501 XSETEXTENT (extent, e);
|
|
3502 if (!NILP (parent))
|
|
3503 CHECK_LIVE_EXTENT (parent);
|
|
3504 if (EQ (parent, cur_parent))
|
|
3505 return Qnil;
|
|
3506 for (rest = parent; !NILP (rest); rest = extent_parent (XEXTENT (rest)))
|
|
3507 if (EQ (rest, extent))
|
|
3508 signal_simple_error ("Circular parent chain would result", extent);
|
|
3509 if (NILP (parent))
|
|
3510 {
|
|
3511 remove_extent_from_children_list (XEXTENT (cur_parent), extent);
|
|
3512 set_extent_no_chase_aux_field (e, parent, Qnil);
|
|
3513 e->flags.has_parent = 0;
|
|
3514 }
|
|
3515 else
|
|
3516 {
|
|
3517 add_extent_to_children_list (XEXTENT (parent), extent);
|
|
3518 set_extent_no_chase_aux_field (e, parent, parent);
|
|
3519 e->flags.has_parent = 1;
|
|
3520 }
|
|
3521 /* changing the parent also changes the properties of all children. */
|
32
|
3522 {
|
|
3523 int old_invis = (!NILP (cur_parent) &&
|
|
3524 !NILP (extent_invisible (XEXTENT (cur_parent))));
|
|
3525 int new_invis = (!NILP (parent) &&
|
|
3526 !NILP (extent_invisible (XEXTENT (parent))));
|
|
3527
|
|
3528 extent_maybe_changed_for_redisplay (e, 1, new_invis != old_invis);
|
|
3529 }
|
|
3530
|
0
|
3531 return Qnil;
|
|
3532 }
|
|
3533
|
|
3534
|
|
3535 /************************************************************************/
|
|
3536 /* basic extent mutators */
|
|
3537 /************************************************************************/
|
|
3538
|
|
3539 /* Note: If you track non-duplicable extents by undo, you'll get bogus
|
|
3540 undo records for transient extents via update-extent.
|
|
3541 For example, query-replace will do this.
|
|
3542 */
|
|
3543
|
|
3544 static void
|
|
3545 set_extent_endpoints_1 (EXTENT extent, Memind start, Memind end)
|
|
3546 {
|
|
3547 #ifdef ERROR_CHECK_EXTENTS
|
|
3548 Lisp_Object obj = extent_object (extent);
|
|
3549
|
|
3550 assert (start <= end);
|
|
3551 if (BUFFERP (obj))
|
|
3552 {
|
|
3553 assert (valid_memind_p (XBUFFER (obj), start));
|
|
3554 assert (valid_memind_p (XBUFFER (obj), end));
|
|
3555 }
|
|
3556 #endif
|
|
3557
|
|
3558 /* Optimization: if the extent is already where we want it to be,
|
|
3559 do nothing. */
|
|
3560 if (!extent_detached_p (extent) && extent_start (extent) == start &&
|
|
3561 extent_end (extent) == end)
|
|
3562 return;
|
|
3563
|
|
3564 if (extent_detached_p (extent))
|
|
3565 {
|
|
3566 if (extent_duplicable_p (extent))
|
|
3567 {
|
|
3568 Lisp_Object extent_obj;
|
|
3569 XSETEXTENT (extent_obj, extent);
|
|
3570 record_extent (extent_obj, 1);
|
|
3571 }
|
|
3572 }
|
|
3573 else
|
|
3574 extent_detach (extent);
|
|
3575
|
|
3576 set_extent_start (extent, start);
|
|
3577 set_extent_end (extent, end);
|
|
3578 extent_attach (extent);
|
|
3579 }
|
|
3580
|
|
3581 /* Set extent's endpoints to S and E, and put extent in buffer or string
|
|
3582 OBJECT. (If OBJECT is nil, do not change the extent's object.) */
|
|
3583
|
|
3584 void
|
|
3585 set_extent_endpoints (EXTENT extent, Bytind s, Bytind e, Lisp_Object object)
|
|
3586 {
|
|
3587 Memind start, end;
|
|
3588
|
|
3589 if (NILP (object))
|
|
3590 {
|
|
3591 object = extent_object (extent);
|
|
3592 assert (!NILP (object));
|
|
3593 }
|
|
3594 else if (!EQ (object, extent_object (extent)))
|
|
3595 {
|
|
3596 extent_detach (extent);
|
|
3597 extent_object (extent) = object;
|
|
3598 }
|
|
3599
|
|
3600 start = s < 0 ? extent_start (extent) :
|
|
3601 buffer_or_string_bytind_to_memind (object, s);
|
|
3602 end = e < 0 ? extent_end (extent) :
|
|
3603 buffer_or_string_bytind_to_memind (object, e);
|
|
3604 set_extent_endpoints_1 (extent, start, end);
|
|
3605 }
|
|
3606
|
|
3607 static void
|
|
3608 set_extent_openness (EXTENT extent, int start_open, int end_open)
|
|
3609 {
|
|
3610 if (start_open == -1)
|
|
3611 start_open = extent_start_open_p (extent);
|
|
3612 if (end_open == -1)
|
|
3613 end_open = extent_end_open_p (extent);
|
|
3614 extent_start_open_p (extent) = start_open;
|
|
3615 extent_end_open_p (extent) = end_open;
|
|
3616 /* changing the open/closedness of an extent does not affect
|
|
3617 redisplay. */
|
|
3618 }
|
|
3619
|
|
3620 static EXTENT
|
|
3621 make_extent_internal (Lisp_Object object, Bytind from, Bytind to)
|
|
3622 {
|
|
3623 EXTENT extent;
|
|
3624
|
|
3625 extent = make_extent_detached (object);
|
|
3626 set_extent_endpoints (extent, from, to, Qnil);
|
|
3627 return extent;
|
|
3628 }
|
|
3629
|
|
3630 static EXTENT
|
|
3631 copy_extent (EXTENT original, Bytind from, Bytind to, Lisp_Object object)
|
|
3632 {
|
|
3633 EXTENT e;
|
|
3634
|
|
3635 e = make_extent_detached (object);
|
|
3636 if (from >= 0)
|
|
3637 set_extent_endpoints (e, from, to, Qnil);
|
|
3638
|
|
3639 e->plist = Fcopy_sequence (original->plist);
|
|
3640 memcpy (&e->flags, &original->flags, sizeof (e->flags));
|
|
3641 if (e->flags.has_aux)
|
|
3642 {
|
|
3643 /* also need to copy the aux struct. It won't work for
|
|
3644 this extent to share the same aux struct as the original
|
|
3645 one. */
|
|
3646 struct extent_auxiliary *data =
|
|
3647 alloc_lcrecord (sizeof (struct extent_auxiliary),
|
|
3648 lrecord_extent_auxiliary);
|
|
3649
|
|
3650 copy_lcrecord (data, XEXTENT_AUXILIARY (XCAR (original->plist)));
|
|
3651 XSETEXTENT_AUXILIARY (XCAR (e->plist), data);
|
|
3652 }
|
|
3653
|
|
3654 {
|
|
3655 /* we may have just added another child to the parent extent. */
|
|
3656 Lisp_Object parent = extent_parent (e);
|
|
3657 if (!NILP (parent))
|
|
3658 {
|
|
3659 Lisp_Object extent;
|
|
3660 XSETEXTENT (extent, e);
|
|
3661 add_extent_to_children_list (XEXTENT (parent), extent);
|
|
3662 }
|
|
3663 }
|
|
3664
|
|
3665 /* #### it's still unclear to me that this Energize-specific junk
|
|
3666 needs to be in here. Just use the general mechanisms, or fix
|
|
3667 them up! --ben */
|
|
3668 #ifdef ENERGIZE
|
|
3669 if (energize_extent_data (original))
|
|
3670 {
|
|
3671 extent_plist_slot (e) = Qnil; /* slightly antisocial... */
|
|
3672 restore_energize_extent_state (e);
|
|
3673 }
|
|
3674 #endif
|
|
3675
|
|
3676 return e;
|
|
3677 }
|
|
3678
|
|
3679 static void
|
|
3680 destroy_extent (EXTENT extent)
|
|
3681 {
|
|
3682 Lisp_Object rest, nextrest, children;
|
|
3683 Lisp_Object extent_obj = Qnil;
|
|
3684
|
|
3685 if (!extent_detached_p (extent))
|
|
3686 extent_detach (extent);
|
|
3687 /* disassociate the extent from its children and parent */
|
|
3688 children = extent_children (extent);
|
|
3689 if (!NILP (children))
|
|
3690 {
|
|
3691 LIST_LOOP_DELETING (rest, nextrest, XWEAK_LIST_LIST (children))
|
|
3692 Fset_extent_parent (XCAR (rest), Qnil);
|
|
3693 }
|
|
3694 XSETEXTENT (extent_obj, extent);
|
|
3695 Fset_extent_parent (extent_obj, Qnil);
|
|
3696 /* mark the extent as destroyed */
|
|
3697 extent_object (extent) = Qt;
|
|
3698 }
|
|
3699
|
20
|
3700 DEFUN ("make-extent", Fmake_extent, 2, 3, 0, /*
|
0
|
3701 Make an extent for the range [FROM, TO) in BUFFER-OR-STRING.
|
|
3702 BUFFER-OR-STRING defaults to the current buffer. Insertions at point
|
|
3703 TO will be outside of the extent; insertions at FROM will be inside the
|
|
3704 extent, causing the extent to grow. (This is the same way that markers
|
|
3705 behave.) You can change the behavior of insertions at the endpoints
|
|
3706 using `set-extent-property'. The extent is initially detached if both
|
|
3707 FROM and TO are nil, and in this case BUFFER-OR-STRING defaults to nil,
|
|
3708 meaning the extent is in no buffer and no string.
|
20
|
3709 */
|
|
3710 (from, to, buffer_or_string))
|
0
|
3711 {
|
|
3712 Lisp_Object extent_obj = Qnil;
|
|
3713 Lisp_Object obj;
|
|
3714
|
|
3715 obj = decode_buffer_or_string (buffer_or_string);
|
|
3716 if (NILP (from) && NILP (to))
|
|
3717 {
|
|
3718 if (NILP (buffer_or_string))
|
|
3719 obj = Qnil;
|
|
3720 XSETEXTENT (extent_obj, make_extent_detached (obj));
|
|
3721 }
|
|
3722 else
|
|
3723 {
|
|
3724 Bytind start, end;
|
|
3725
|
|
3726 get_buffer_or_string_range_byte (obj, from, to, &start, &end,
|
|
3727 GB_ALLOW_PAST_ACCESSIBLE);
|
|
3728 XSETEXTENT (extent_obj, make_extent_internal (obj, start, end));
|
|
3729 }
|
|
3730 return extent_obj;
|
|
3731 }
|
|
3732
|
20
|
3733 DEFUN ("copy-extent", Fcopy_extent, 1, 2, 0, /*
|
0
|
3734 Make a copy of EXTENT. It is initially detached.
|
|
3735 Optional argument BUFFER-OR-STRING defaults to EXTENT's buffer or string.
|
20
|
3736 */
|
|
3737 (extent, buffer_or_string))
|
0
|
3738 {
|
|
3739 EXTENT ext = decode_extent (extent, 0);
|
|
3740
|
|
3741 if (NILP (buffer_or_string))
|
|
3742 buffer_or_string = extent_object (ext);
|
|
3743 else
|
|
3744 buffer_or_string = decode_buffer_or_string (buffer_or_string);
|
|
3745
|
|
3746 XSETEXTENT (extent, copy_extent (ext, -1, -1, buffer_or_string));
|
|
3747 return extent;
|
|
3748 }
|
|
3749
|
20
|
3750 DEFUN ("delete-extent", Fdelete_extent, 1, 1, 0, /*
|
0
|
3751 Remove EXTENT from its buffer and destroy it.
|
|
3752 This does not modify the buffer's text, only its display properties.
|
|
3753 The extent cannot be used thereafter.
|
20
|
3754 */
|
|
3755 (extent))
|
0
|
3756 {
|
|
3757 EXTENT ext;
|
|
3758
|
|
3759 /* We do not call decode_extent() here because already-destroyed
|
|
3760 extents are OK. */
|
|
3761 CHECK_EXTENT (extent);
|
|
3762 ext = XEXTENT (extent);
|
|
3763
|
|
3764 if (!EXTENT_LIVE_P (ext))
|
|
3765 return Qnil;
|
|
3766 destroy_extent (ext);
|
|
3767 return Qnil;
|
|
3768 }
|
|
3769
|
20
|
3770 DEFUN ("detach-extent", Fdetach_extent, 1, 1, 0, /*
|
0
|
3771 Remove EXTENT from its buffer in such a way that it can be re-inserted.
|
|
3772 An extent is also detached when all of its characters are all killed by a
|
|
3773 deletion, unless its `detachable' property has been unset.
|
|
3774
|
|
3775 Extents which have the `duplicable' attribute are tracked by the undo
|
|
3776 mechanism. Detachment via `detach-extent' and string deletion is recorded,
|
|
3777 as is attachment via `insert-extent' and string insertion. Extent motion,
|
|
3778 face changes, and attachment via `make-extent' and `set-extent-endpoints'
|
|
3779 are not recorded. This means that extent changes which are to be undo-able
|
|
3780 must be performed by character editing, or by insertion and detachment of
|
|
3781 duplicable extents.
|
20
|
3782 */
|
|
3783 (extent))
|
0
|
3784 {
|
|
3785 EXTENT ext = decode_extent (extent, 0);
|
|
3786
|
|
3787 if (extent_detached_p (ext))
|
|
3788 return extent;
|
|
3789 if (extent_duplicable_p (ext))
|
|
3790 record_extent (extent, 0);
|
|
3791 extent_detach (ext);
|
|
3792
|
|
3793 return extent;
|
|
3794 }
|
|
3795
|
20
|
3796 DEFUN ("set-extent-endpoints", Fset_extent_endpoints, 3, 4, 0, /*
|
0
|
3797 Set the endpoints of EXTENT to START, END.
|
|
3798 If START and END are null, call detach-extent on EXTENT.
|
|
3799 BUFFER-OR-STRING specifies the new buffer or string that the extent should
|
|
3800 be in, and defaults to EXTENT's buffer or string. (If nil, and EXTENT
|
|
3801 is in no buffer and no string, it defaults to the current buffer.)
|
|
3802 See documentation on `detach-extent' for a discussion of undo recording.
|
20
|
3803 */
|
|
3804 (extent, start, end, buffer_or_string))
|
0
|
3805 {
|
|
3806 EXTENT ext;
|
|
3807 Bytind s, e;
|
|
3808
|
|
3809 ext = decode_extent (extent, 0);
|
|
3810
|
|
3811 if (NILP (buffer_or_string))
|
|
3812 {
|
|
3813 buffer_or_string = extent_object (ext);
|
|
3814 if (NILP (buffer_or_string))
|
|
3815 buffer_or_string = Fcurrent_buffer ();
|
|
3816 }
|
|
3817 else
|
|
3818 buffer_or_string = decode_buffer_or_string (buffer_or_string);
|
|
3819
|
|
3820 if (NILP (start) && NILP (end))
|
|
3821 return Fdetach_extent (extent);
|
|
3822
|
|
3823 get_buffer_or_string_range_byte (buffer_or_string, start, end, &s, &e,
|
|
3824 GB_ALLOW_PAST_ACCESSIBLE);
|
|
3825
|
|
3826 set_extent_endpoints (ext, s, e, buffer_or_string);
|
|
3827 return extent;
|
|
3828 }
|
|
3829
|
|
3830
|
|
3831 /************************************************************************/
|
|
3832 /* mapping over extents */
|
|
3833 /************************************************************************/
|
|
3834
|
|
3835 static unsigned int
|
|
3836 decode_map_extents_flags (Lisp_Object flags)
|
|
3837 {
|
|
3838 unsigned int retval = 0;
|
|
3839 unsigned int all_extents_specified = 0;
|
|
3840 unsigned int in_region_specified = 0;
|
|
3841
|
|
3842 if (EQ (flags, Qt)) /* obsoleteness compatibility */
|
|
3843 return ME_END_CLOSED;
|
|
3844 if (NILP (flags))
|
|
3845 return 0;
|
|
3846 if (SYMBOLP (flags))
|
|
3847 flags = Fcons (flags, Qnil);
|
|
3848 while (!NILP (flags))
|
|
3849 {
|
|
3850 Lisp_Object sym;
|
|
3851 CHECK_CONS (flags);
|
|
3852 sym = XCAR (flags);
|
|
3853 CHECK_SYMBOL (sym);
|
|
3854 if (EQ (sym, Qall_extents_closed) || EQ (sym, Qall_extents_open) ||
|
|
3855 EQ (sym, Qall_extents_closed_open) ||
|
|
3856 EQ (sym, Qall_extents_open_closed))
|
|
3857 {
|
|
3858 if (all_extents_specified)
|
|
3859 error ("Only one `all-extents-*' flag may be specified");
|
|
3860 all_extents_specified = 1;
|
|
3861 }
|
|
3862 if (EQ (sym, Qstart_in_region) || EQ (sym, Qend_in_region) ||
|
|
3863 EQ (sym, Qstart_and_end_in_region) ||
|
|
3864 EQ (sym, Qstart_or_end_in_region))
|
|
3865 {
|
|
3866 if (in_region_specified)
|
|
3867 error ("Only one `*-in-region' flag may be specified");
|
|
3868 in_region_specified = 1;
|
|
3869 }
|
|
3870
|
|
3871 /* I do so love that conditional operator ... */
|
|
3872 retval |=
|
|
3873 EQ (sym, Qend_closed) ? ME_END_CLOSED :
|
|
3874 EQ (sym, Qstart_open) ? ME_START_OPEN :
|
|
3875 EQ (sym, Qall_extents_closed) ? ME_ALL_EXTENTS_CLOSED :
|
|
3876 EQ (sym, Qall_extents_open) ? ME_ALL_EXTENTS_OPEN :
|
|
3877 EQ (sym, Qall_extents_closed_open) ? ME_ALL_EXTENTS_CLOSED_OPEN :
|
|
3878 EQ (sym, Qall_extents_open_closed) ? ME_ALL_EXTENTS_OPEN_CLOSED :
|
|
3879 EQ (sym, Qstart_in_region) ? ME_START_IN_REGION :
|
|
3880 EQ (sym, Qend_in_region) ? ME_END_IN_REGION :
|
|
3881 EQ (sym, Qstart_and_end_in_region) ? ME_START_AND_END_IN_REGION :
|
|
3882 EQ (sym, Qstart_or_end_in_region) ? ME_START_OR_END_IN_REGION :
|
|
3883 EQ (sym, Qnegate_in_region) ? ME_NEGATE_IN_REGION :
|
|
3884 (signal_simple_error ("Invalid `map-extents' flag", sym), 0);
|
|
3885
|
|
3886 flags = XCDR (flags);
|
|
3887 }
|
|
3888 return retval;
|
|
3889 }
|
|
3890
|
20
|
3891 DEFUN ("extent-in-region-p", Fextent_in_region_p, 1, 4, 0, /*
|
0
|
3892 Return whether EXTENT overlaps a specified region.
|
|
3893 This is equivalent to whether `map-extents' would visit EXTENT when called
|
|
3894 with these args.
|
20
|
3895 */
|
|
3896 (extent, from, to, flags))
|
0
|
3897 {
|
|
3898 EXTENT ext;
|
|
3899 Lisp_Object obj;
|
|
3900 Bytind start, end;
|
|
3901
|
|
3902 ext = decode_extent (extent, DE_MUST_BE_ATTACHED);
|
|
3903 obj = extent_object (ext);
|
|
3904 get_buffer_or_string_range_byte (obj, from, to, &start, &end, GB_ALLOW_NIL |
|
|
3905 GB_ALLOW_PAST_ACCESSIBLE);
|
|
3906
|
|
3907 if (extent_in_region_p (ext, start, end, decode_map_extents_flags (flags)))
|
|
3908 return Qt;
|
|
3909 return Qnil;
|
|
3910 }
|
|
3911
|
|
3912 struct slow_map_extents_arg
|
|
3913 {
|
|
3914 Lisp_Object map_arg;
|
|
3915 Lisp_Object map_routine;
|
|
3916 Lisp_Object result;
|
|
3917 Lisp_Object property;
|
|
3918 Lisp_Object value;
|
|
3919 };
|
|
3920
|
|
3921 static int
|
|
3922 slow_map_extents_function (EXTENT extent, void *arg)
|
|
3923 {
|
|
3924 /* This function can GC */
|
|
3925 struct slow_map_extents_arg *closure = (struct slow_map_extents_arg *) arg;
|
|
3926 Lisp_Object extent_obj;
|
|
3927
|
|
3928 XSETEXTENT (extent_obj, extent);
|
|
3929
|
|
3930 /* make sure this extent qualifies according to the PROPERTY
|
|
3931 and VALUE args */
|
|
3932
|
|
3933 if (!NILP (closure->property))
|
|
3934 {
|
|
3935 Lisp_Object value = Fextent_property (extent_obj, closure->property,
|
|
3936 Qnil);
|
|
3937 if ((NILP (closure->value) && NILP (value)) ||
|
|
3938 (!NILP (closure->value) && !EQ (value, closure->value)))
|
|
3939 return 0;
|
|
3940 }
|
|
3941
|
|
3942 closure->result = call2 (closure->map_routine, extent_obj,
|
|
3943 closure->map_arg);
|
|
3944 if (NILP (closure->result))
|
|
3945 return 0;
|
|
3946 else
|
|
3947 return 1;
|
|
3948 }
|
|
3949
|
20
|
3950 DEFUN ("map-extents", Fmap_extents, 1, 8, 0, /*
|
0
|
3951 Map FUNCTION over the extents which overlap a region in OBJECT.
|
|
3952 OBJECT is normally a buffer or string but could be an extent (see below).
|
|
3953 The region is normally bounded by [FROM, TO) (i.e. the beginning of the
|
|
3954 region is closed and the end of the region is open), but this can be
|
|
3955 changed with the FLAGS argument (see below for a complete discussion).
|
|
3956
|
|
3957 FUNCTION is called with the arguments (extent, MAPARG). The arguments
|
|
3958 OBJECT, FROM, TO, MAPARG, and FLAGS are all optional and default to
|
|
3959 the current buffer, the beginning of OBJECT, the end of OBJECT, nil,
|
|
3960 and nil, respectively. `map-extents' returns the first non-nil result
|
|
3961 produced by FUNCTION, and no more calls to FUNCTION are made after it
|
|
3962 returns non-nil.
|
|
3963
|
|
3964 If OBJECT is an extent, FROM and TO default to the extent's endpoints,
|
|
3965 and the mapping omits that extent and its predecessors. This feature
|
|
3966 supports restarting a loop based on `map-extents'. Note: OBJECT must
|
|
3967 be attached to a buffer or string, and the mapping is done over that
|
|
3968 buffer or string.
|
|
3969
|
|
3970 An extent overlaps the region if there is any point in the extent that is
|
|
3971 also in the region. (For the purpose of overlap, zero-length extents and
|
|
3972 regions are treated as closed on both ends regardless of their endpoints'
|
|
3973 specified open/closedness.) Note that the endpoints of an extent or region
|
|
3974 are considered to be in that extent or region if and only if the
|
|
3975 corresponding end is closed. For example, the extent [5,7] overlaps the
|
|
3976 region [2,5] because 5 is in both the extent and the region. However, (5,7]
|
|
3977 does not overlap [2,5] because 5 is not in the extent, and neither [5,7] nor
|
|
3978 \(5,7] overlaps the region [2,5) because 5 is not in the region.
|
|
3979
|
|
3980 The optional FLAGS can be a symbol or a list of one or more symbols,
|
|
3981 modifying the behavior of `map-extents'. Allowed symbols are:
|
|
3982
|
|
3983 end-closed The region's end is closed.
|
|
3984
|
|
3985 start-open The region's start is open.
|
|
3986
|
|
3987 all-extents-closed Treat all extents as closed on both ends for the
|
|
3988 purpose of determining whether they overlap the
|
|
3989 region, irrespective of their actual open- or
|
|
3990 closedness.
|
|
3991 all-extents-open Treat all extents as open on both ends.
|
|
3992 all-extents-closed-open Treat all extents as start-closed, end-open.
|
|
3993 all-extents-open-closed Treat all extents as start-open, end-closed.
|
|
3994
|
|
3995 start-in-region In addition to the above conditions for extent
|
|
3996 overlap, the extent's start position must lie within
|
|
3997 the specified region. Note that, for this
|
|
3998 condition, open start positions are treated as if
|
|
3999 0.5 was added to the endpoint's value, and open
|
|
4000 end positions are treated as if 0.5 was subtracted
|
|
4001 from the endpoint's value.
|
|
4002 end-in-region The extent's end position must lie within the
|
|
4003 region.
|
|
4004 start-and-end-in-region Both the extent's start and end positions must lie
|
|
4005 within the region.
|
|
4006 start-or-end-in-region Either the extent's start or end position must lie
|
|
4007 within the region.
|
|
4008
|
|
4009 negate-in-region The condition specified by a `*-in-region' flag
|
|
4010 must NOT hold for the extent to be considered.
|
|
4011
|
|
4012
|
|
4013 At most one of `all-extents-closed', `all-extents-open',
|
|
4014 `all-extents-closed-open', and `all-extents-open-closed' may be specified.
|
|
4015
|
|
4016 At most one of `start-in-region', `end-in-region',
|
|
4017 `start-and-end-in-region', and `start-or-end-in-region' may be specified.
|
|
4018
|
|
4019 If optional arg PROPERTY is non-nil, only extents with that property set
|
|
4020 on them will be visited. If optional arg VALUE is non-nil, only extents
|
|
4021 whose value for that property is `eq' to VALUE will be visited.
|
20
|
4022 */
|
|
4023 (function, object, from, to, maparg, flags, property, value))
|
0
|
4024 {
|
|
4025 /* This function can GC */
|
|
4026 struct slow_map_extents_arg closure;
|
|
4027 unsigned int me_flags;
|
|
4028 Bytind start, end;
|
|
4029 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
|
4030 EXTENT after = 0;
|
|
4031
|
|
4032 if (EXTENTP (object))
|
|
4033 {
|
|
4034 after = decode_extent (object, DE_MUST_BE_ATTACHED);
|
|
4035 if (NILP (from))
|
|
4036 from = Fextent_start_position (object);
|
|
4037 if (NILP (to))
|
|
4038 to = Fextent_end_position (object);
|
|
4039 object = extent_object (after);
|
|
4040 }
|
|
4041 else
|
|
4042 object = decode_buffer_or_string (object);
|
|
4043
|
|
4044 get_buffer_or_string_range_byte (object, from, to, &start, &end,
|
|
4045 GB_ALLOW_NIL | GB_ALLOW_PAST_ACCESSIBLE);
|
|
4046
|
|
4047 me_flags = decode_map_extents_flags (flags);
|
|
4048
|
|
4049 if (!NILP (property))
|
|
4050 {
|
|
4051 CHECK_SYMBOL (property);
|
|
4052 if (!NILP (value))
|
|
4053 value = canonicalize_extent_property (property, value);
|
|
4054 }
|
|
4055
|
|
4056 GCPRO5 (function, maparg, object, property, value);
|
|
4057
|
|
4058 closure.map_arg = maparg;
|
|
4059 closure.map_routine = function;
|
|
4060 closure.result = Qnil;
|
|
4061 closure.property = property;
|
|
4062 closure.value = value;
|
|
4063
|
|
4064 map_extents_bytind (start, end, slow_map_extents_function,
|
|
4065 (void *) &closure, object, after,
|
|
4066 /* You never know what the user might do ... */
|
|
4067 me_flags | ME_MIGHT_CALL_ELISP);
|
|
4068
|
|
4069 UNGCPRO;
|
|
4070 return closure.result;
|
|
4071 }
|
|
4072
|
|
4073
|
|
4074 /************************************************************************/
|
|
4075 /* mapping over extents -- other functions */
|
|
4076 /************************************************************************/
|
|
4077
|
|
4078 /* ------------------------------- */
|
|
4079 /* map-extent-children */
|
|
4080 /* ------------------------------- */
|
|
4081
|
|
4082 struct slow_map_extent_children_arg
|
|
4083 {
|
|
4084 Lisp_Object map_arg;
|
|
4085 Lisp_Object map_routine;
|
|
4086 Lisp_Object result;
|
|
4087 Lisp_Object property;
|
|
4088 Lisp_Object value;
|
|
4089 Bytind start_min;
|
|
4090 Bytind prev_start;
|
|
4091 Bytind prev_end;
|
|
4092 };
|
|
4093
|
|
4094 static int
|
|
4095 slow_map_extent_children_function (EXTENT extent, void *arg)
|
|
4096 {
|
|
4097 /* This function can GC */
|
|
4098 struct slow_map_extent_children_arg *closure =
|
|
4099 (struct slow_map_extent_children_arg *) arg;
|
|
4100 Lisp_Object extent_obj;
|
|
4101 Bytind start = extent_endpoint_bytind (extent, 0);
|
|
4102 Bytind end = extent_endpoint_bytind (extent, 1);
|
|
4103 /* Make sure the extent starts inside the region of interest,
|
|
4104 rather than just overlaps it.
|
|
4105 */
|
|
4106 if (start < closure->start_min)
|
|
4107 return 0;
|
|
4108 /* Make sure the extent is not a child of a previous visited one.
|
|
4109 We know already, because of extent ordering,
|
|
4110 that start >= prev_start, and that if
|
|
4111 start == prev_start, then end <= prev_end.
|
|
4112 */
|
|
4113 if (start == closure->prev_start)
|
|
4114 {
|
|
4115 if (end < closure->prev_end)
|
|
4116 return 0;
|
|
4117 }
|
|
4118 else /* start > prev_start */
|
|
4119 {
|
|
4120 if (start < closure->prev_end)
|
|
4121 return 0;
|
|
4122 /* corner case: prev_end can be -1 if there is no prev */
|
|
4123 }
|
|
4124 XSETEXTENT (extent_obj, extent);
|
|
4125
|
|
4126 /* make sure this extent qualifies according to the PROPERTY
|
|
4127 and VALUE args */
|
|
4128
|
|
4129 if (!NILP (closure->property))
|
|
4130 {
|
|
4131 Lisp_Object value = Fextent_property (extent_obj, closure->property,
|
|
4132 Qnil);
|
|
4133 if ((NILP (closure->value) && NILP (value)) ||
|
|
4134 (!NILP (closure->value) && !EQ (value, closure->value)))
|
|
4135 return 0;
|
|
4136 }
|
|
4137
|
|
4138 closure->result = call2 (closure->map_routine, extent_obj,
|
|
4139 closure->map_arg);
|
|
4140
|
|
4141 /* Since the callback may change the buffer, compute all stored
|
|
4142 buffer positions here.
|
|
4143 */
|
|
4144 closure->start_min = -1; /* no need for this any more */
|
|
4145 closure->prev_start = extent_endpoint_bytind (extent, 0);
|
|
4146 closure->prev_end = extent_endpoint_bytind (extent, 1);
|
|
4147
|
|
4148 if (NILP (closure->result))
|
|
4149 return 0;
|
|
4150 else
|
|
4151 return 1;
|
|
4152 }
|
|
4153
|
20
|
4154 DEFUN ("map-extent-children", Fmap_extent_children, 1, 8, 0, /*
|
0
|
4155 Map FUNCTION over the extents in the region from FROM to TO.
|
|
4156 FUNCTION is called with arguments (extent, MAPARG). See `map-extents'
|
|
4157 for a full discussion of the arguments FROM, TO, and FLAGS.
|
|
4158
|
|
4159 The arguments are the same as for `map-extents', but this function differs
|
|
4160 in that it only visits extents which start in the given region, and also
|
|
4161 in that, after visiting an extent E, it skips all other extents which start
|
|
4162 inside E but end before E's end.
|
|
4163
|
|
4164 Thus, this function may be used to walk a tree of extents in a buffer:
|
|
4165 (defun walk-extents (buffer &optional ignore)
|
|
4166 (map-extent-children 'walk-extents buffer))
|
20
|
4167 */
|
|
4168 (function, object, from, to, maparg, flags, property, value))
|
0
|
4169 {
|
|
4170 /* This function can GC */
|
|
4171 struct slow_map_extent_children_arg closure;
|
|
4172 unsigned int me_flags;
|
|
4173 Bytind start, end;
|
|
4174 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
|
4175 EXTENT after = 0;
|
|
4176
|
|
4177 if (EXTENTP (object))
|
|
4178 {
|
|
4179 after = decode_extent (object, DE_MUST_BE_ATTACHED);
|
|
4180 if (NILP (from))
|
|
4181 from = Fextent_start_position (object);
|
|
4182 if (NILP (to))
|
|
4183 to = Fextent_end_position (object);
|
|
4184 object = extent_object (after);
|
|
4185 }
|
|
4186 else
|
|
4187 object = decode_buffer_or_string (object);
|
|
4188
|
|
4189 get_buffer_or_string_range_byte (object, from, to, &start, &end,
|
|
4190 GB_ALLOW_NIL | GB_ALLOW_PAST_ACCESSIBLE);
|
|
4191
|
|
4192 me_flags = decode_map_extents_flags (flags);
|
|
4193
|
|
4194 if (!NILP (property))
|
|
4195 {
|
|
4196 CHECK_SYMBOL (property);
|
|
4197 if (!NILP (value))
|
|
4198 value = canonicalize_extent_property (property, value);
|
|
4199 }
|
|
4200
|
|
4201 GCPRO5 (function, maparg, object, property, value);
|
|
4202
|
|
4203 closure.map_arg = maparg;
|
|
4204 closure.map_routine = function;
|
|
4205 closure.result = Qnil;
|
|
4206 closure.property = property;
|
|
4207 closure.value = value;
|
|
4208 closure.start_min = start;
|
|
4209 closure.prev_start = -1;
|
|
4210 closure.prev_end = -1;
|
|
4211 map_extents_bytind (start, end, slow_map_extent_children_function,
|
|
4212 (void *) &closure, object, after,
|
|
4213 /* You never know what the user might do ... */
|
|
4214 me_flags | ME_MIGHT_CALL_ELISP);
|
|
4215
|
|
4216 UNGCPRO;
|
|
4217 return closure.result;
|
|
4218 }
|
|
4219
|
|
4220 /* ------------------------------- */
|
|
4221 /* extent-at */
|
|
4222 /* ------------------------------- */
|
|
4223
|
|
4224 /* find "smallest" matching extent containing pos -- (flag == 0) means
|
|
4225 all extents match, else (EXTENT_FLAGS (extent) & flag) must be true;
|
|
4226 for more than one matching extent with precisely the same endpoints,
|
|
4227 we choose the last extent in the extents_list.
|
|
4228 The search stops just before "before", if that is non-null.
|
|
4229 */
|
|
4230
|
|
4231 struct extent_at_arg
|
|
4232 {
|
|
4233 EXTENT best_match;
|
|
4234 Memind best_start;
|
|
4235 Memind best_end;
|
|
4236 Lisp_Object prop;
|
|
4237 EXTENT before;
|
|
4238 };
|
|
4239
|
|
4240 enum extent_at_flag
|
|
4241 {
|
|
4242 EXTENT_AT_AFTER,
|
|
4243 EXTENT_AT_BEFORE,
|
|
4244 EXTENT_AT_AT
|
|
4245 };
|
|
4246
|
|
4247 static enum extent_at_flag
|
|
4248 decode_extent_at_flag (Lisp_Object at_flag)
|
|
4249 {
|
|
4250 enum extent_at_flag fl;
|
|
4251
|
|
4252 if (NILP (at_flag))
|
|
4253 fl = EXTENT_AT_AFTER;
|
|
4254 else
|
|
4255 {
|
|
4256 CHECK_SYMBOL (at_flag);
|
|
4257 if (EQ (at_flag, Qafter))
|
|
4258 fl = EXTENT_AT_AFTER;
|
|
4259 else if (EQ (at_flag, Qbefore))
|
|
4260 fl = EXTENT_AT_BEFORE;
|
|
4261 else if (EQ (at_flag, Qat))
|
|
4262 fl = EXTENT_AT_AT;
|
|
4263 else
|
|
4264 signal_simple_error ("Invalid AT-FLAG in `extent-at'", at_flag);
|
|
4265 }
|
|
4266
|
|
4267 return fl;
|
|
4268 }
|
|
4269
|
|
4270 static int
|
|
4271 extent_at_mapper (EXTENT e, void *arg)
|
|
4272 {
|
|
4273 struct extent_at_arg *closure = (struct extent_at_arg *) arg;
|
|
4274
|
|
4275 if (e == closure->before)
|
|
4276 return 1;
|
|
4277
|
|
4278 /* If closure->prop is non-nil, then the extent is only acceptable
|
|
4279 if it has a non-nil value for that property. */
|
|
4280 if (!NILP (closure->prop))
|
|
4281 {
|
|
4282 Lisp_Object extent;
|
|
4283 XSETEXTENT (extent, e);
|
|
4284 if (NILP (Fextent_property (extent, closure->prop, Qnil)))
|
|
4285 return 0;
|
|
4286 }
|
|
4287
|
|
4288 {
|
|
4289 EXTENT current = closure->best_match;
|
|
4290
|
|
4291 if (!current)
|
|
4292 goto accept;
|
|
4293 /* redundant but quick test */
|
|
4294 else if (extent_start (current) > extent_start (e))
|
|
4295 return 0;
|
|
4296
|
|
4297 /* we return the "last" best fit, instead of the first --
|
|
4298 this is because then the glyph closest to two equivalent
|
|
4299 extents corresponds to the "extent-at" the text just past
|
|
4300 that same glyph */
|
|
4301 else if (!EXTENT_LESS_VALS (e, closure->best_start,
|
|
4302 closure->best_end))
|
|
4303 goto accept;
|
|
4304 else
|
|
4305 return 0;
|
|
4306 accept:
|
|
4307 closure->best_match = e;
|
|
4308 closure->best_start = extent_start (e);
|
|
4309 closure->best_end = extent_end (e);
|
|
4310 }
|
|
4311
|
|
4312 return 0;
|
|
4313 }
|
|
4314
|
|
4315 static Lisp_Object
|
|
4316 extent_at_bytind (Bytind position, Lisp_Object object, Lisp_Object property,
|
|
4317 EXTENT before, enum extent_at_flag at_flag)
|
|
4318 {
|
|
4319 struct extent_at_arg closure;
|
|
4320 Lisp_Object extent_obj = Qnil;
|
|
4321
|
|
4322 /* it might be argued that invalid positions should cause
|
|
4323 errors, but the principle of least surprise dictates that
|
|
4324 nil should be returned (extent-at is often used in
|
|
4325 response to a mouse event, and in many cases previous events
|
|
4326 have changed the buffer contents).
|
|
4327
|
|
4328 Also, the openness stuff in the text-property code currently
|
|
4329 does not check its limits and might go off the end. */
|
|
4330 if ((at_flag == EXTENT_AT_BEFORE
|
|
4331 ? position <= buffer_or_string_absolute_begin_byte (object)
|
|
4332 : position < buffer_or_string_absolute_begin_byte (object))
|
|
4333 || (at_flag == EXTENT_AT_AFTER
|
|
4334 ? position >= buffer_or_string_absolute_end_byte (object)
|
|
4335 : position > buffer_or_string_absolute_end_byte (object)))
|
|
4336 return Qnil;
|
|
4337
|
|
4338 closure.best_match = 0;
|
|
4339 closure.prop = property;
|
|
4340 closure.before = before;
|
|
4341
|
|
4342 map_extents_bytind (at_flag == EXTENT_AT_BEFORE ? position - 1 : position,
|
|
4343 at_flag == EXTENT_AT_AFTER ? position + 1 : position,
|
|
4344 extent_at_mapper, (void *) &closure, object, 0,
|
|
4345 ME_START_OPEN | ME_ALL_EXTENTS_CLOSED);
|
|
4346
|
|
4347 if (!closure.best_match)
|
|
4348 return Qnil;
|
|
4349
|
|
4350 XSETEXTENT (extent_obj, closure.best_match);
|
|
4351 return extent_obj;
|
|
4352 }
|
|
4353
|
20
|
4354 DEFUN ("extent-at", Fextent_at, 1, 5, 0, /*
|
0
|
4355 Find \"smallest\" extent at POS in OBJECT having PROPERTY set.
|
|
4356 Normally, an extent is \"at\" POS if it overlaps the region (POS, POS+1);
|
|
4357 i.e. if it covers the character after POS. (However, see the definition
|
|
4358 of AT-FLAG.) \"Smallest\" means the extent that comes last in the display
|
|
4359 order; this normally means the extent whose start position is closest to
|
|
4360 POS. See `next-extent' for more information.
|
|
4361 OBJECT specifies a buffer or string and defaults to the current buffer.
|
|
4362 PROPERTY defaults to nil, meaning that any extent will do.
|
|
4363 Properties are attached to extents with `set-extent-property', which see.
|
|
4364 Returns nil if POS is invalid or there is no matching extent at POS.
|
|
4365 If the fourth argument BEFORE is not nil, it must be an extent; any returned
|
|
4366 extent will precede that extent. This feature allows `extent-at' to be
|
|
4367 used by a loop over extents.
|
|
4368 AT-FLAG controls how end cases are handled, and should be one of:
|
|
4369
|
|
4370 nil or `after' An extent is at POS if it covers the character
|
|
4371 after POS. This is consistent with the way
|
|
4372 that text properties work.
|
|
4373 `before' An extent is at POS if it covers the character
|
|
4374 before POS.
|
|
4375 `at' An extent is at POS if it overlaps or abuts POS.
|
|
4376 This includes all zero-length extents at POS.
|
|
4377
|
|
4378 Note that in all cases, the start-openness and end-openness of the extents
|
|
4379 considered is ignored. If you want to pay attention to those properties,
|
|
4380 you should use `map-extents', which gives you more control.
|
20
|
4381 */
|
|
4382 (pos, object, property, before, at_flag))
|
0
|
4383 {
|
|
4384 Bytind position;
|
|
4385 EXTENT before_extent;
|
|
4386 enum extent_at_flag fl;
|
|
4387
|
|
4388 object = decode_buffer_or_string (object);
|
|
4389 position = get_buffer_or_string_pos_byte (object, pos, GB_NO_ERROR_IF_BAD);
|
|
4390 CHECK_SYMBOL (property);
|
|
4391 if (NILP (before))
|
|
4392 before_extent = 0;
|
|
4393 else
|
|
4394 before_extent = decode_extent (before, DE_MUST_BE_ATTACHED);
|
|
4395 if (before_extent && !EQ (object, extent_object (before_extent)))
|
|
4396 signal_simple_error ("extent not in specified buffer or string", object);
|
|
4397 fl = decode_extent_at_flag (at_flag);
|
|
4398
|
|
4399 return extent_at_bytind (position, object, property, before_extent, fl);
|
|
4400 }
|
|
4401
|
|
4402 /* ------------------------------- */
|
|
4403 /* verify_extent_modification() */
|
|
4404 /* ------------------------------- */
|
|
4405
|
|
4406 /* verify_extent_modification() is called when a buffer or string is
|
|
4407 modified to check whether the modification is occuring inside a
|
|
4408 read-only extent.
|
|
4409 */
|
|
4410
|
|
4411 struct verify_extents_arg
|
|
4412 {
|
|
4413 Lisp_Object object;
|
|
4414 Memind start;
|
|
4415 Memind end;
|
|
4416 Lisp_Object iro; /* value of inhibit-read-only */
|
|
4417 };
|
|
4418
|
|
4419 static int
|
|
4420 verify_extent_mapper (EXTENT extent, void *arg)
|
|
4421 {
|
|
4422 struct verify_extents_arg *closure = (struct verify_extents_arg *) arg;
|
|
4423 Lisp_Object prop = extent_read_only (extent);
|
|
4424
|
|
4425 if (NILP (prop))
|
|
4426 return 0;
|
|
4427
|
|
4428 if (CONSP (closure->iro) && !NILP (Fmemq (prop, closure->iro)))
|
|
4429 return 0;
|
|
4430
|
24
|
4431 #if 0 /* Nobody seems to care for this any more -sb */
|
0
|
4432 /* Allow deletion if the extent is completely contained in
|
|
4433 the region being deleted.
|
|
4434 This is important for supporting tokens which are internally
|
|
4435 write-protected, but which can be killed and yanked as a whole.
|
|
4436 Ignore open/closed distinctions at this point.
|
|
4437 -- Rose
|
|
4438 */
|
|
4439 if (closure->start != closure->end &&
|
|
4440 extent_start (extent) >= closure->start &&
|
|
4441 extent_end (extent) <= closure->end)
|
|
4442 return 0;
|
24
|
4443 #endif
|
0
|
4444
|
|
4445 while (1)
|
|
4446 Fsignal (Qbuffer_read_only, (list1 (closure->object)));
|
|
4447
|
|
4448 RETURN_NOT_REACHED(0)
|
|
4449 }
|
|
4450
|
|
4451 /* Value of Vinhibit_read_only is precomputed and passed in for
|
|
4452 efficiency */
|
|
4453
|
|
4454 void
|
|
4455 verify_extent_modification (Lisp_Object object, Bytind from, Bytind to,
|
|
4456 Lisp_Object inhibit_read_only_value)
|
|
4457 {
|
|
4458 int closed;
|
|
4459 struct verify_extents_arg closure;
|
|
4460
|
|
4461 /* If insertion, visit closed-endpoint extents touching the insertion
|
|
4462 point because the text would go inside those extents. If deletion,
|
|
4463 treat the range as open on both ends so that touching extents are not
|
|
4464 visited. Note that we assume that an insertion is occurring if the
|
|
4465 changed range has zero length, and a deletion otherwise. This
|
|
4466 fails if a change (i.e. non-insertion, non-deletion) is happening.
|
|
4467 As far as I know, this doesn't currently occur in XEmacs. --ben */
|
|
4468 closed = (from==to);
|
|
4469 closure.object = object;
|
|
4470 closure.start = buffer_or_string_bytind_to_memind (object, from);
|
|
4471 closure.end = buffer_or_string_bytind_to_memind (object, to);
|
|
4472 closure.iro = inhibit_read_only_value;
|
|
4473
|
|
4474 map_extents_bytind (from, to, verify_extent_mapper, (void *) &closure,
|
|
4475 object, 0, closed ? ME_END_CLOSED : ME_START_OPEN);
|
|
4476 }
|
|
4477
|
|
4478 /* ------------------------------------ */
|
|
4479 /* process_extents_for_insertion() */
|
|
4480 /* ------------------------------------ */
|
|
4481
|
|
4482 struct process_extents_for_insertion_arg
|
|
4483 {
|
|
4484 Bytind opoint;
|
|
4485 int length;
|
|
4486 Lisp_Object object;
|
|
4487 };
|
|
4488
|
|
4489 /* A region of length LENGTH was just inserted at OPOINT. Modify all
|
|
4490 of the extents as required for the insertion, based on their
|
|
4491 start-open/end-open properties.
|
|
4492 */
|
|
4493
|
|
4494 static int
|
|
4495 process_extents_for_insertion_mapper (EXTENT extent, void *arg)
|
|
4496 {
|
|
4497 struct process_extents_for_insertion_arg *closure =
|
|
4498 (struct process_extents_for_insertion_arg *) arg;
|
|
4499 Memind indecks = buffer_or_string_bytind_to_memind (closure->object,
|
|
4500 closure->opoint);
|
|
4501
|
|
4502 /* When this function is called, one end of the newly-inserted text should
|
|
4503 be adjacent to some endpoint of the extent, or disjoint from it. If
|
|
4504 the insertion overlaps any existing extent, something is wrong.
|
|
4505 */
|
|
4506 #ifdef ERROR_CHECK_EXTENTS
|
|
4507 if (extent_start (extent) > indecks &&
|
|
4508 extent_start (extent) < indecks + closure->length)
|
|
4509 abort ();
|
|
4510 if (extent_end (extent) > indecks &&
|
|
4511 extent_end (extent) < indecks + closure->length)
|
|
4512 abort ();
|
|
4513 #endif
|
|
4514
|
|
4515 /* The extent-adjustment code adjusted the extent's endpoints as if
|
|
4516 they were markers -- endpoints at the gap (i.e. the insertion
|
|
4517 point) go to the left of the insertion point, which is correct
|
|
4518 for [) extents. We need to fix the other kinds of extents.
|
|
4519
|
|
4520 Note that both conditions below will hold for zero-length (]
|
|
4521 extents at the gap. Zero-length () extents would get adjusted
|
|
4522 such that their start is greater than their end; we treat them
|
|
4523 as [) extents. This is unfortunately an inelegant part of the
|
|
4524 extent model, but there is no way around it. */
|
|
4525
|
|
4526 {
|
|
4527 Memind new_start, new_end;
|
|
4528
|
|
4529 new_start = extent_start (extent);
|
|
4530 new_end = extent_end (extent);
|
|
4531 if (indecks == extent_start (extent) && extent_start_open_p (extent) &&
|
|
4532 /* coerce zero-length () extents to [) */
|
|
4533 new_start != new_end)
|
|
4534 new_start += closure->length;
|
|
4535 if (indecks == extent_end (extent) && !extent_end_open_p (extent))
|
|
4536 new_end += closure->length;
|
|
4537 set_extent_endpoints_1 (extent, new_start, new_end);
|
|
4538 }
|
|
4539
|
|
4540 return 0;
|
|
4541 }
|
|
4542
|
|
4543 void
|
|
4544 process_extents_for_insertion (Lisp_Object object, Bytind opoint,
|
|
4545 Bytecount length)
|
|
4546 {
|
|
4547 struct process_extents_for_insertion_arg closure;
|
|
4548
|
|
4549 closure.opoint = opoint;
|
|
4550 closure.length = length;
|
|
4551 closure.object = object;
|
|
4552
|
|
4553 map_extents_bytind (opoint, opoint + length,
|
|
4554 process_extents_for_insertion_mapper,
|
|
4555 (void *) &closure, object, 0,
|
|
4556 ME_END_CLOSED | ME_MIGHT_MODIFY_EXTENTS |
|
|
4557 ME_INCLUDE_INTERNAL);
|
|
4558 }
|
|
4559
|
|
4560 /* ------------------------------------ */
|
|
4561 /* process_extents_for_deletion() */
|
|
4562 /* ------------------------------------ */
|
|
4563
|
|
4564 struct process_extents_for_deletion_arg
|
|
4565 {
|
|
4566 Memind start, end;
|
|
4567 int destroy_included_extents;
|
|
4568 };
|
|
4569
|
|
4570 /* This function is called when we're about to delete the range [from, to].
|
|
4571 Detach all of the extents that are completely inside the range [from, to],
|
|
4572 if they're detachable or open-open. */
|
|
4573
|
|
4574 static int
|
|
4575 process_extents_for_deletion_mapper (EXTENT extent, void *arg)
|
|
4576 {
|
|
4577 struct process_extents_for_deletion_arg *closure =
|
|
4578 (struct process_extents_for_deletion_arg *) arg;
|
|
4579
|
|
4580 /* If the extent lies completely within the range that
|
|
4581 is being deleted, then nuke the extent if it's detachable
|
|
4582 (otherwise, it will become a zero-length extent). */
|
|
4583
|
|
4584 if (closure->start <= extent_start (extent) &&
|
|
4585 extent_end (extent) <= closure->end)
|
|
4586 {
|
|
4587 if (extent_detachable_p (extent))
|
|
4588 {
|
|
4589 if (closure->destroy_included_extents)
|
|
4590 destroy_extent (extent);
|
|
4591 else
|
|
4592 extent_detach (extent);
|
|
4593 }
|
|
4594 }
|
|
4595
|
|
4596 return 0;
|
|
4597 }
|
|
4598
|
|
4599 /* DESTROY_THEM means destroy the extents instead of just deleting them.
|
|
4600 It is unused currently, but perhaps might be used (there used to
|
|
4601 be a function process_extents_for_destruction(), #if 0'd out,
|
|
4602 that did the equivalent). */
|
|
4603 void
|
|
4604 process_extents_for_deletion (Lisp_Object object, Bytind from,
|
|
4605 Bytind to, int destroy_them)
|
|
4606 {
|
|
4607 struct process_extents_for_deletion_arg closure;
|
|
4608
|
|
4609 closure.start = buffer_or_string_bytind_to_memind (object, from);
|
|
4610 closure.end = buffer_or_string_bytind_to_memind (object, to);
|
|
4611 closure.destroy_included_extents = destroy_them;
|
|
4612
|
|
4613 map_extents_bytind (from, to, process_extents_for_deletion_mapper,
|
|
4614 (void *) &closure, object, 0,
|
|
4615 ME_END_CLOSED | ME_MIGHT_MODIFY_EXTENTS);
|
|
4616 }
|
|
4617
|
|
4618
|
|
4619 /************************************************************************/
|
|
4620 /* extent properties */
|
|
4621 /************************************************************************/
|
|
4622
|
|
4623 static void
|
|
4624 set_extent_invisible (EXTENT extent, Lisp_Object value)
|
|
4625 {
|
|
4626 if (!EQ (extent_invisible (extent), value))
|
|
4627 {
|
|
4628 set_extent_invisible_1 (extent, value);
|
32
|
4629 extent_changed_for_redisplay (extent, 1, 1);
|
0
|
4630 }
|
|
4631 }
|
|
4632
|
|
4633 /* This function does "memoization" -- similar to the interning
|
|
4634 that happens with symbols. Given a list of faces, an equivalent
|
|
4635 list is returned such that if this function is called twice with
|
|
4636 input that is `equal', the resulting outputs will be `eq'.
|
|
4637
|
|
4638 Note that the inputs and outputs are in general *not* `equal' --
|
|
4639 faces in symbol form become actual face objects in the output.
|
|
4640 This is necessary so that temporary faces stay around. */
|
|
4641
|
|
4642 static Lisp_Object
|
|
4643 memoize_extent_face_internal (Lisp_Object list)
|
|
4644 {
|
|
4645 int len;
|
|
4646 int thelen;
|
|
4647 Lisp_Object cons, thecons;
|
|
4648 Lisp_Object oldtail, tail;
|
|
4649 struct gcpro gcpro1;
|
|
4650
|
|
4651 if (NILP (list))
|
|
4652 return Qnil;
|
|
4653 if (!CONSP (list))
|
|
4654 return Fget_face (list);
|
|
4655
|
|
4656 /* To do the memoization, we use a hash table mapping from
|
|
4657 external lists to internal lists. We do `equal' comparisons
|
|
4658 on the keys so the memoization works correctly.
|
|
4659
|
|
4660 Note that we canonicalize things so that the keys in the
|
|
4661 hashtable (the external lists) always contain symbols and
|
|
4662 the values (the internal lists) always contain face objects.
|
|
4663
|
|
4664 We also maintain a "reverse" table that maps from the internal
|
|
4665 lists to the external equivalents. The idea here is twofold:
|
|
4666
|
|
4667 1) `extent-face' wants to return a list containing face symbols
|
|
4668 rather than face objects.
|
|
4669 2) We don't want things to get quite so messed up if the user
|
|
4670 maliciously side-effects the returned lists.
|
|
4671 */
|
|
4672
|
|
4673 len = XINT (Flength (list));
|
|
4674 thelen = XINT (Flength (Vextent_face_reusable_list));
|
|
4675 oldtail = Qnil;
|
|
4676 tail = Qnil;
|
|
4677 GCPRO1 (oldtail);
|
|
4678
|
|
4679 /* We canonicalize the given list into another list.
|
|
4680 We try to avoid consing except when necessary, so we have
|
|
4681 a reusable list.
|
|
4682 */
|
|
4683
|
|
4684 if (thelen < len)
|
|
4685 {
|
|
4686 cons = Vextent_face_reusable_list;
|
|
4687 while (!NILP (XCDR (cons)))
|
|
4688 cons = XCDR (cons);
|
|
4689 XCDR (cons) = Fmake_list (make_int (len - thelen), Qnil);
|
|
4690 }
|
|
4691 else if (thelen > len)
|
|
4692 {
|
|
4693 int i;
|
|
4694
|
|
4695 /* Truncate the list temporarily so it's the right length;
|
|
4696 remember the old tail. */
|
|
4697 cons = Vextent_face_reusable_list;
|
|
4698 for (i = 0; i < len - 1; i++)
|
|
4699 cons = XCDR (cons);
|
|
4700 tail = cons;
|
|
4701 oldtail = XCDR (cons);
|
|
4702 XCDR (cons) = Qnil;
|
|
4703 }
|
|
4704
|
|
4705 thecons = Vextent_face_reusable_list;
|
|
4706 EXTERNAL_LIST_LOOP (cons, list)
|
|
4707 {
|
|
4708 Lisp_Object face = Fget_face (XCAR (cons));
|
|
4709
|
|
4710 XCAR (thecons) = Fface_name (face);
|
|
4711 thecons = XCDR (thecons);
|
|
4712 }
|
|
4713
|
|
4714 list = Fgethash (Vextent_face_reusable_list, Vextent_face_memoize_hash_table,
|
|
4715 Qnil);
|
|
4716 if (NILP (list))
|
|
4717 {
|
|
4718 Lisp_Object symlist = Fcopy_sequence (Vextent_face_reusable_list);
|
|
4719 Lisp_Object facelist = Fcopy_sequence (Vextent_face_reusable_list);
|
|
4720
|
|
4721 LIST_LOOP (cons, facelist)
|
|
4722 {
|
|
4723 XCAR (cons) = Fget_face (XCAR (cons));
|
|
4724 }
|
|
4725 Fputhash (symlist, facelist, Vextent_face_memoize_hash_table);
|
|
4726 Fputhash (facelist, symlist, Vextent_face_reverse_memoize_hash_table);
|
|
4727 list = facelist;
|
|
4728 }
|
|
4729
|
|
4730 /* Now restore the truncated tail of the reusable list, if necessary. */
|
|
4731 if (!NILP (tail))
|
|
4732 XCDR (tail) = oldtail;
|
|
4733
|
|
4734 UNGCPRO;
|
|
4735 return list;
|
|
4736 }
|
|
4737
|
|
4738 static Lisp_Object
|
|
4739 external_of_internal_memoized_face (Lisp_Object face)
|
|
4740 {
|
|
4741 if (NILP (face))
|
|
4742 return Qnil;
|
|
4743 else if (!CONSP (face))
|
|
4744 return XFACE (face)->name;
|
|
4745 else
|
|
4746 {
|
|
4747 face = Fgethash (face, Vextent_face_reverse_memoize_hash_table,
|
|
4748 Qunbound);
|
|
4749 assert (!UNBOUNDP (face));
|
|
4750 return face;
|
|
4751 }
|
|
4752 }
|
|
4753
|
|
4754 static Lisp_Object
|
|
4755 canonicalize_extent_property (Lisp_Object prop, Lisp_Object value)
|
|
4756 {
|
|
4757 if (EQ (prop, Qface) || EQ (prop, Qmouse_face))
|
|
4758 value = (external_of_internal_memoized_face
|
|
4759 (memoize_extent_face_internal (value)));
|
|
4760 return value;
|
|
4761 }
|
|
4762
|
20
|
4763 DEFUN ("extent-face", Fextent_face, 1, 1, 0, /*
|
0
|
4764 Return the name of the face in which EXTENT is displayed, or nil
|
|
4765 if the extent's face is unspecified. This might also return a list
|
|
4766 of face names.
|
20
|
4767 */
|
|
4768 (extent))
|
0
|
4769 {
|
|
4770 Lisp_Object face;
|
|
4771
|
|
4772 CHECK_EXTENT (extent);
|
|
4773 face = extent_face (XEXTENT (extent));
|
|
4774
|
|
4775 return external_of_internal_memoized_face (face);
|
|
4776 }
|
|
4777
|
20
|
4778 DEFUN ("set-extent-face", Fset_extent_face, 2, 2, 0, /*
|
0
|
4779 Make the given EXTENT have the graphic attributes specified by FACE.
|
|
4780 FACE can also be a list of faces, and all faces listed will apply,
|
|
4781 with faces earlier in the list taking priority over those later in the
|
|
4782 list.
|
20
|
4783 */
|
|
4784 (extent, face))
|
0
|
4785 {
|
32
|
4786 EXTENT e = decode_extent(extent, 0);
|
0
|
4787 Lisp_Object orig_face = face;
|
|
4788
|
|
4789 /* retrieve the ancestor for efficiency and proper redisplay noting. */
|
|
4790 e = extent_ancestor (e);
|
|
4791
|
|
4792 face = memoize_extent_face_internal (face);
|
|
4793
|
|
4794 extent_face (e) = face;
|
32
|
4795 extent_changed_for_redisplay (e, 1, 0);
|
0
|
4796
|
|
4797 return orig_face;
|
|
4798 }
|
|
4799
|
|
4800
|
20
|
4801 DEFUN ("extent-mouse-face", Fextent_mouse_face, 1, 1, 0, /*
|
0
|
4802 Return the face used to highlight EXTENT when the mouse passes over it.
|
|
4803 The return value will be a face name, a list of face names, or nil
|
|
4804 if the extent's mouse face is unspecified.
|
20
|
4805 */
|
|
4806 (extent))
|
0
|
4807 {
|
|
4808 Lisp_Object face;
|
|
4809
|
|
4810 CHECK_EXTENT (extent);
|
|
4811 face = extent_mouse_face (XEXTENT (extent));
|
|
4812
|
|
4813 return external_of_internal_memoized_face (face);
|
|
4814 }
|
|
4815
|
20
|
4816 DEFUN ("set-extent-mouse-face", Fset_extent_mouse_face, 2, 2, 0, /*
|
0
|
4817 Set the face used to highlight EXTENT when the mouse passes over it.
|
|
4818 FACE can also be a list of faces, and all faces listed will apply,
|
|
4819 with faces earlier in the list taking priority over those later in the
|
|
4820 list.
|
20
|
4821 */
|
|
4822 (extent, face))
|
0
|
4823 {
|
|
4824 EXTENT e;
|
|
4825 Lisp_Object orig_face = face;
|
|
4826
|
|
4827 CHECK_EXTENT (extent);
|
|
4828 e = XEXTENT (extent);
|
|
4829 /* retrieve the ancestor for efficiency and proper redisplay noting. */
|
|
4830 e = extent_ancestor (e);
|
|
4831
|
|
4832 face = memoize_extent_face_internal (face);
|
|
4833
|
|
4834 set_extent_mouse_face (e, face);
|
32
|
4835 extent_changed_for_redisplay (e, 1, 0);
|
0
|
4836
|
|
4837 return orig_face;
|
|
4838 }
|
|
4839
|
|
4840 void
|
|
4841 set_extent_glyph (EXTENT extent, Lisp_Object glyph, int endp,
|
|
4842 unsigned int layout)
|
|
4843 {
|
|
4844 extent = extent_ancestor (extent);
|
|
4845
|
|
4846 if (!endp)
|
|
4847 {
|
|
4848 set_extent_begin_glyph (extent, glyph);
|
|
4849 extent_begin_glyph_layout (extent) = layout;
|
|
4850 }
|
|
4851 else
|
|
4852 {
|
|
4853 set_extent_end_glyph (extent, glyph);
|
|
4854 extent_end_glyph_layout (extent) = layout;
|
|
4855 }
|
|
4856
|
32
|
4857 extent_changed_for_redisplay (extent, 1, 0);
|
0
|
4858 }
|
|
4859
|
|
4860 static Lisp_Object
|
|
4861 glyph_layout_to_symbol (unsigned int layout)
|
|
4862 {
|
|
4863 switch (layout)
|
|
4864 {
|
|
4865 case GL_TEXT: return Qtext;
|
|
4866 case GL_OUTSIDE_MARGIN: return Qoutside_margin;
|
|
4867 case GL_INSIDE_MARGIN: return Qinside_margin;
|
|
4868 case GL_WHITESPACE: return Qwhitespace;
|
|
4869 default: abort ();
|
|
4870 }
|
|
4871 return Qnil; /* shut up compiler */
|
|
4872 }
|
|
4873
|
|
4874 static unsigned int
|
|
4875 symbol_to_glyph_layout (Lisp_Object layout_obj)
|
|
4876 {
|
|
4877 unsigned int layout = 0;
|
|
4878
|
|
4879 if (NILP (layout_obj))
|
|
4880 layout = GL_TEXT;
|
|
4881 else
|
|
4882 {
|
|
4883 CHECK_SYMBOL (layout_obj);
|
|
4884 if (EQ (Qoutside_margin, layout_obj))
|
|
4885 layout = GL_OUTSIDE_MARGIN;
|
|
4886 else if (EQ (Qinside_margin, layout_obj))
|
|
4887 layout = GL_INSIDE_MARGIN;
|
|
4888 else if (EQ (Qwhitespace, layout_obj))
|
|
4889 layout = GL_WHITESPACE;
|
|
4890 else if (EQ (Qtext, layout_obj))
|
|
4891 layout = GL_TEXT;
|
|
4892 else
|
|
4893 signal_simple_error ("unknown glyph layout type", layout_obj);
|
|
4894 }
|
|
4895 return layout;
|
|
4896 }
|
|
4897
|
|
4898 static Lisp_Object
|
|
4899 set_extent_glyph_1 (Lisp_Object extent_obj, Lisp_Object glyph, int endp,
|
|
4900 Lisp_Object layout_obj)
|
|
4901 {
|
|
4902 EXTENT extent = decode_extent (extent_obj, DE_MUST_HAVE_BUFFER);
|
|
4903 unsigned int layout = symbol_to_glyph_layout (layout_obj);
|
|
4904
|
|
4905 /* Make sure we've actually been given a glyph or it's nil (meaning
|
|
4906 we're deleting a glyph from an extent). */
|
|
4907 if (!NILP (glyph))
|
|
4908 CHECK_GLYPH (glyph);
|
|
4909
|
|
4910 set_extent_glyph (extent, glyph, endp, layout);
|
|
4911 return glyph;
|
|
4912 }
|
|
4913
|
20
|
4914 DEFUN ("set-extent-begin-glyph", Fset_extent_begin_glyph, 2, 3, 0, /*
|
0
|
4915 Display a bitmap, subwindow or string at the beginning of EXTENT.
|
|
4916 BEGIN-GLYPH must be a glyph object. The layout policy defaults to `text'.
|
20
|
4917 */
|
|
4918 (extent, begin_glyph, layout))
|
0
|
4919 {
|
|
4920 return set_extent_glyph_1 (extent, begin_glyph, 0, layout);
|
|
4921 }
|
|
4922
|
20
|
4923 DEFUN ("set-extent-end-glyph", Fset_extent_end_glyph, 2, 3, 0, /*
|
0
|
4924 Display a bitmap, subwindow or string at the end of the EXTENT.
|
|
4925 END-GLYPH must be a glyph object. The layout policy defaults to `text'.
|
20
|
4926 */
|
|
4927 (extent, end_glyph, layout))
|
0
|
4928 {
|
|
4929 return set_extent_glyph_1 (extent, end_glyph, 1, layout);
|
|
4930 }
|
|
4931
|
20
|
4932 DEFUN ("extent-begin-glyph", Fextent_begin_glyph, 1, 1, 0, /*
|
0
|
4933 Return the glyph object displayed at the beginning of EXTENT.
|
|
4934 If there is none, nil is returned.
|
20
|
4935 */
|
|
4936 (extent_obj))
|
0
|
4937 {
|
|
4938 return extent_begin_glyph (decode_extent (extent_obj, 0));
|
|
4939 }
|
|
4940
|
20
|
4941 DEFUN ("extent-end-glyph", Fextent_end_glyph, 1, 1, 0, /*
|
0
|
4942 Return the glyph object displayed at the end of EXTENT.
|
|
4943 If there is none, nil is returned.
|
20
|
4944 */
|
|
4945 (extent_obj))
|
0
|
4946 {
|
|
4947 return extent_end_glyph (decode_extent (extent_obj, 0));
|
|
4948 }
|
|
4949
|
20
|
4950 DEFUN ("set-extent-begin-glyph-layout", Fset_extent_begin_glyph_layout, 2, 2, 0, /*
|
0
|
4951 Set the layout policy of the given extent's begin glyph.
|
|
4952 Access this using the `extent-begin-glyph-layout' function.
|
20
|
4953 */
|
|
4954 (extent, layout))
|
0
|
4955 {
|
|
4956 EXTENT e = decode_extent (extent, 0);
|
|
4957 e = extent_ancestor (e);
|
|
4958 extent_begin_glyph_layout (e) = symbol_to_glyph_layout (layout);
|
32
|
4959 extent_maybe_changed_for_redisplay (e, 1, 0);
|
0
|
4960 return layout;
|
|
4961 }
|
|
4962
|
20
|
4963 DEFUN ("set-extent-end-glyph-layout", Fset_extent_end_glyph_layout, 2, 2, 0, /*
|
0
|
4964 Set the layout policy of the given extent's end glyph.
|
|
4965 Access this using the `extent-end-glyph-layout' function.
|
20
|
4966 */
|
|
4967 (extent, layout))
|
0
|
4968 {
|
|
4969 EXTENT e = decode_extent (extent, 0);
|
|
4970 e = extent_ancestor (e);
|
|
4971 extent_end_glyph_layout (e) = symbol_to_glyph_layout (layout);
|
32
|
4972 extent_maybe_changed_for_redisplay (e, 1, 0);
|
0
|
4973 return layout;
|
|
4974 }
|
|
4975
|
20
|
4976 DEFUN ("extent-begin-glyph-layout", Fextent_begin_glyph_layout, 1, 1, 0, /*
|
0
|
4977 Return the layout policy associated with the given extent's begin glyph.
|
|
4978 Set this using the `set-extent-begin-glyph-layout' function.
|
20
|
4979 */
|
|
4980 (extent))
|
0
|
4981 {
|
|
4982 EXTENT e = decode_extent (extent, 0);
|
|
4983 return glyph_layout_to_symbol (extent_begin_glyph_layout (e));
|
|
4984 }
|
|
4985
|
20
|
4986 DEFUN ("extent-end-glyph-layout", Fextent_end_glyph_layout, 1, 1, 0, /*
|
0
|
4987 Return the layout policy associated with the given extent's end glyph.
|
|
4988 Set this using the `set-extent-end-glyph-layout' function.
|
20
|
4989 */
|
|
4990 (extent))
|
0
|
4991 {
|
|
4992 EXTENT e = decode_extent (extent, 0);
|
|
4993 return glyph_layout_to_symbol (extent_end_glyph_layout (e));
|
|
4994 }
|
|
4995
|
20
|
4996 DEFUN ("set-extent-priority", Fset_extent_priority, 2, 2, 0, /*
|
0
|
4997 Changes the display priority of EXTENT.
|
|
4998 When the extent attributes are being merged for display, the priority
|
|
4999 is used to determine which extent takes precedence in the event of a
|
|
5000 conflict (two extents whose faces both specify font, for example: the
|
|
5001 font of the extent with the higher priority will be used).
|
|
5002 Extents are created with priority 0; priorities may be negative.
|
20
|
5003 */
|
|
5004 (extent, pri))
|
0
|
5005 {
|
|
5006 EXTENT e = decode_extent (extent, 0);
|
|
5007
|
|
5008 CHECK_INT (pri);
|
|
5009 e = extent_ancestor (e);
|
|
5010 set_extent_priority (e, XINT (pri));
|
32
|
5011 extent_maybe_changed_for_redisplay (e, 1, 0);
|
0
|
5012 return pri;
|
|
5013 }
|
|
5014
|
20
|
5015 DEFUN ("extent-priority", Fextent_priority, 1, 1, 0, /*
|
0
|
5016 Return the display priority of EXTENT; see `set-extent-priority'.
|
20
|
5017 */
|
|
5018 (extent))
|
0
|
5019 {
|
|
5020 EXTENT e = decode_extent (extent, 0);
|
|
5021 return make_int (extent_priority (e));
|
|
5022 }
|
|
5023
|
20
|
5024 DEFUN ("set-extent-property", Fset_extent_property, 3, 3, 0, /*
|
0
|
5025 Change a property of an extent.
|
|
5026 PROPERTY may be any symbol; the value stored may be accessed with
|
|
5027 the `extent-property' function.
|
|
5028 The following symbols have predefined meanings:
|
|
5029
|
|
5030 detached Removes the extent from its buffer; setting this is
|
|
5031 the same as calling `detach-extent'.
|
|
5032
|
|
5033 destroyed Removes the extent from its buffer, and makes it
|
|
5034 unusable in the future; this is the same calling
|
|
5035 `delete-extent'.
|
|
5036
|
|
5037 priority Change redisplay priority; same as `set-extent-priority'.
|
|
5038
|
|
5039 start-open Whether the set of characters within the extent is
|
|
5040 treated being open on the left, that is, whether
|
|
5041 the start position is an exclusive, rather than
|
|
5042 inclusive, boundary. If true, then characters
|
|
5043 inserted exactly at the beginning of the extent
|
|
5044 will remain outside of the extent; otherwise they
|
|
5045 will go into the extent, extending it.
|
|
5046
|
|
5047 end-open Whether the set of characters within the extent is
|
|
5048 treated being open on the right, that is, whether
|
|
5049 the end position is an exclusive, rather than
|
|
5050 inclusive, boundary. If true, then characters
|
|
5051 inserted exactly at the end of the extent will
|
|
5052 remain outside of the extent; otherwise they will
|
|
5053 go into the extent, extending it.
|
|
5054
|
|
5055 By default, extents have the `end-open' but not the
|
|
5056 `start-open' property set.
|
|
5057
|
|
5058 read-only Text within this extent will be unmodifiable.
|
|
5059
|
|
5060 detachable Whether the extent gets detached (as with
|
|
5061 `detach-extent') when all the text within the
|
|
5062 extent is deleted. This is true by default. If
|
|
5063 this property is not set, the extent becomes a
|
|
5064 zero-length extent when its text is deleted. (In
|
|
5065 such a case, the `start-open' property is
|
|
5066 automatically removed if both the `start-open' and
|
|
5067 `end-open' properties are set, since zero-length
|
|
5068 extents open on both ends are not allowed.)
|
|
5069
|
|
5070 face The face in which to display the text. Setting
|
|
5071 this is the same as calling `set-extent-face'.
|
|
5072
|
|
5073 mouse-face If non-nil, the extent will be highlighted in this
|
|
5074 face when the mouse moves over it.
|
|
5075
|
|
5076 pointer If non-nil, and a valid pointer glyph, this specifies
|
|
5077 the shape of the mouse pointer while over the extent.
|
|
5078
|
|
5079 highlight Obsolete: Setting this property is equivalent to
|
|
5080 setting a `mouse-face' property of `highlight'.
|
|
5081 Reading this property returns non-nil if
|
|
5082 the extent has a non-nil `mouse-face' property.
|
|
5083
|
|
5084 duplicable Whether this extent should be copied into strings,
|
|
5085 so that kill, yank, and undo commands will restore
|
|
5086 or copy it. `duplicable' extents are copied from
|
|
5087 an extent into a string when `buffer-substring' or
|
|
5088 a similar function creates a string. The extents
|
|
5089 in a string are copied into other strings created
|
|
5090 from the string using `concat' or `substring'.
|
|
5091 When `insert' or a similar function inserts the
|
|
5092 string into a buffer, the extents are copied back
|
|
5093 into the buffer.
|
|
5094
|
20
|
5095 unique Meaningful only in conjunction with `duplicable'.
|
|
5096 When this is set, there may be only one instance
|
|
5097 of this extent attached at a time: if it is copied
|
|
5098 to the kill ring and then yanked, the extent is
|
|
5099 not copied. If, however, it is killed (removed
|
|
5100 from the buffer) and then yanked, it will be
|
|
5101 re-attached at the new position.
|
0
|
5102
|
|
5103 invisible If the value is non-nil, text under this extent
|
|
5104 may be treated as not present for the purpose of
|
|
5105 redisplay, or may be displayed using an ellipsis
|
|
5106 or other marker; see `buffer-invisibility-spec'
|
|
5107 and `invisible-text-glyph'. In all cases,
|
|
5108 however, the text is still visible to other
|
|
5109 functions that examine a buffer's text.
|
|
5110
|
|
5111 keymap This keymap is consulted for mouse clicks on this
|
|
5112 extent, or keypresses made while point is within the
|
|
5113 extent.
|
|
5114
|
|
5115 copy-function This is a hook that is run when a duplicable extent
|
|
5116 is about to be copied from a buffer to a string (or
|
|
5117 the kill ring). It is called with three arguments,
|
|
5118 the extent, and the buffer-positions within it
|
|
5119 which are being copied. If this function returns
|
|
5120 nil, then the extent will not be copied; otherwise
|
|
5121 it will.
|
|
5122
|
|
5123 paste-function This is a hook that is run when a duplicable extent is
|
|
5124 about to be copied from a string (or the kill ring)
|
|
5125 into a buffer. It is called with three arguments,
|
|
5126 the original extent, and the buffer positions which
|
|
5127 the copied extent will occupy. (This hook is run
|
|
5128 after the corresponding text has already been
|
|
5129 inserted into the buffer.) Note that the extent
|
|
5130 argument may be detached when this function is run.
|
|
5131 If this function returns nil, no extent will be
|
|
5132 inserted. Otherwise, there will be an extent
|
|
5133 covering the range in question.
|
|
5134
|
|
5135 If the original extent is not attached to a buffer,
|
|
5136 then it will be re-attached at this range.
|
|
5137 Otherwise, a copy will be made, and that copy
|
|
5138 attached here.
|
|
5139
|
|
5140 The copy-function and paste-function are meaningful
|
|
5141 only for extents with the `duplicable' flag set,
|
|
5142 and if they are not specified, behave as if `t' was
|
|
5143 the returned value. When these hooks are invoked,
|
|
5144 the current buffer is the buffer which the extent
|
|
5145 is being copied from/to, respectively.
|
|
5146
|
|
5147 begin-glyph A glyph to be displayed at the beginning of the extent,
|
|
5148 or nil.
|
|
5149
|
|
5150 end-glyph A glyph to be displayed at the end of the extent,
|
|
5151 or nil.
|
|
5152
|
|
5153 begin-glyph-layout The layout policy (one of `text', `whitespace',
|
|
5154 `inside-margin', or `outside-margin') of the extent's
|
|
5155 begin glyph.
|
|
5156
|
22
|
5157 end-glyph-layout The layout policy of the extent's end glyph.
|
|
5158 */
|
20
|
5159 (extent, property, value))
|
0
|
5160 {
|
|
5161 /* This function can GC if property is `keymap' */
|
|
5162 EXTENT e = decode_extent (extent, 0);
|
|
5163 CHECK_SYMBOL (property);
|
|
5164
|
|
5165 if (EQ (property, Qread_only))
|
|
5166 set_extent_read_only (e, value);
|
|
5167 else if (EQ (property, Qunique))
|
|
5168 extent_unique_p (e) = !NILP (value);
|
|
5169 else if (EQ (property, Qduplicable))
|
|
5170 extent_duplicable_p (e) = !NILP (value);
|
|
5171 else if (EQ (property, Qinvisible))
|
|
5172 set_extent_invisible (e, value);
|
|
5173 else if (EQ (property, Qdetachable))
|
|
5174 extent_detachable_p (e) = !NILP (value);
|
|
5175
|
|
5176 else if (EQ (property, Qdetached))
|
|
5177 {
|
|
5178 if (NILP (value))
|
|
5179 error ("can only set `detached' to t");
|
|
5180 Fdetach_extent (extent);
|
|
5181 }
|
|
5182 else if (EQ (property, Qdestroyed))
|
|
5183 {
|
|
5184 if (NILP (value))
|
|
5185 error ("can only set `destroyed' to t");
|
|
5186 Fdelete_extent (extent);
|
|
5187 }
|
|
5188 else if (EQ (property, Qpriority))
|
|
5189 Fset_extent_priority (extent, value);
|
|
5190 else if (EQ (property, Qface))
|
|
5191 Fset_extent_face (extent, value);
|
|
5192 else if (EQ (property, Qmouse_face))
|
|
5193 Fset_extent_mouse_face (extent, value);
|
|
5194 /* Obsolete: */
|
|
5195 else if (EQ (property, Qhighlight))
|
|
5196 Fset_extent_mouse_face (extent, Qhighlight);
|
|
5197 else if (EQ (property, Qbegin_glyph_layout))
|
|
5198 Fset_extent_begin_glyph_layout (extent, value);
|
|
5199 else if (EQ (property, Qend_glyph_layout))
|
|
5200 Fset_extent_end_glyph_layout (extent, value);
|
|
5201 /* For backwards compatibility. We use begin glyph because it is by
|
|
5202 far the more used of the two. */
|
|
5203 else if (EQ (property, Qglyph_layout))
|
|
5204 Fset_extent_begin_glyph_layout (extent, value);
|
|
5205 else if (EQ (property, Qbegin_glyph))
|
|
5206 Fset_extent_begin_glyph (extent, value, Qnil);
|
|
5207 else if (EQ (property, Qend_glyph))
|
|
5208 Fset_extent_end_glyph (extent, value, Qnil);
|
|
5209 else if (EQ (property, Qstart_open) ||
|
|
5210 EQ (property, Qend_open) ||
|
|
5211 EQ (property, Qstart_closed) ||
|
|
5212 EQ (property, Qend_closed))
|
|
5213 {
|
|
5214 int start_open = -1, end_open = -1;
|
|
5215 if (EQ (property, Qstart_open))
|
|
5216 start_open = !NILP (value);
|
|
5217 else if (EQ (property, Qend_open))
|
|
5218 end_open = !NILP (value);
|
|
5219 /* Support (but don't document...) the obvious antonyms. */
|
|
5220 else if (EQ (property, Qstart_closed))
|
|
5221 start_open = NILP (value);
|
|
5222 else
|
|
5223 end_open = NILP (value);
|
|
5224 set_extent_openness (e, start_open, end_open);
|
|
5225 }
|
|
5226 else
|
|
5227 {
|
|
5228 if (EQ (property, Qkeymap))
|
|
5229 while (NILP (Fkeymapp (value)))
|
|
5230 value = wrong_type_argument (Qkeymapp, value);
|
|
5231
|
|
5232 external_plist_put (extent_plist_addr (e), property, value, 0, ERROR_ME);
|
|
5233 }
|
|
5234
|
|
5235 return value;
|
|
5236 }
|
|
5237
|
20
|
5238 DEFUN ("extent-property", Fextent_property, 2, 3, 0, /*
|
0
|
5239 Return EXTENT's value for property PROPERTY.
|
|
5240 See `set-extent-property' for the built-in property names.
|
20
|
5241 */
|
|
5242 (extent, property, defalt))
|
0
|
5243 {
|
|
5244 EXTENT e = decode_extent (extent, 0);
|
|
5245 CHECK_SYMBOL (property);
|
|
5246
|
|
5247 if (EQ (property, Qdetached))
|
|
5248 return (extent_detached_p (e) ? Qt : Qnil);
|
|
5249 else if (EQ (property, Qdestroyed))
|
|
5250 return (!EXTENT_LIVE_P (e) ? Qt : Qnil);
|
|
5251 #define RETURN_FLAG(flag) \
|
|
5252 return (extent_normal_field (e, flag) ? Qt : Qnil)
|
|
5253 else if (EQ (property, Qstart_open)) RETURN_FLAG (start_open);
|
|
5254 else if (EQ (property, Qend_open)) RETURN_FLAG (end_open);
|
|
5255 else if (EQ (property, Qunique)) RETURN_FLAG (unique);
|
|
5256 else if (EQ (property, Qduplicable)) RETURN_FLAG (duplicable);
|
|
5257 else if (EQ (property, Qdetachable)) RETURN_FLAG (detachable);
|
|
5258 #undef RETURN_FLAG
|
|
5259 /* Support (but don't document...) the obvious antonyms. */
|
|
5260 else if (EQ (property, Qstart_closed))
|
|
5261 return (extent_start_open_p (e) ? Qnil : Qt);
|
|
5262 else if (EQ (property, Qend_closed))
|
|
5263 return (extent_end_open_p (e) ? Qnil : Qt);
|
|
5264 else if (EQ (property, Qpriority))
|
|
5265 return make_int (extent_priority (e));
|
|
5266 else if (EQ (property, Qread_only))
|
|
5267 return extent_read_only (e);
|
|
5268 else if (EQ (property, Qinvisible))
|
|
5269 return extent_invisible (e);
|
|
5270 else if (EQ (property, Qface))
|
|
5271 return Fextent_face (extent);
|
|
5272 else if (EQ (property, Qmouse_face))
|
|
5273 return Fextent_mouse_face (extent);
|
|
5274 /* Obsolete: */
|
|
5275 else if (EQ (property, Qhighlight))
|
|
5276 return !NILP (Fextent_mouse_face (extent)) ? Qt : Qnil;
|
|
5277 else if (EQ (property, Qbegin_glyph_layout))
|
|
5278 return Fextent_begin_glyph_layout (extent);
|
|
5279 else if (EQ (property, Qend_glyph_layout))
|
|
5280 return Fextent_end_glyph_layout (extent);
|
|
5281 /* For backwards compatibility. We use begin glyph because it is by
|
|
5282 far the more used of the two. */
|
|
5283 else if (EQ (property, Qglyph_layout))
|
|
5284 return Fextent_begin_glyph_layout (extent);
|
|
5285 else if (EQ (property, Qbegin_glyph))
|
|
5286 return extent_begin_glyph (e);
|
|
5287 else if (EQ (property, Qend_glyph))
|
|
5288 return extent_end_glyph (e);
|
|
5289 else
|
|
5290 {
|
|
5291 Lisp_Object value;
|
|
5292
|
|
5293 value = external_plist_get (extent_plist_addr (e), property, 0,
|
|
5294 ERROR_ME);
|
|
5295 if (UNBOUNDP (value))
|
|
5296 return defalt;
|
|
5297 return value;
|
|
5298 }
|
|
5299 }
|
|
5300
|
20
|
5301 DEFUN ("extent-properties", Fextent_properties, 1, 1, 0, /*
|
0
|
5302 Return a property list of the attributes of the given extent.
|
|
5303 Do not modify this list; use `set-extent-property' instead.
|
20
|
5304 */
|
|
5305 (extent))
|
0
|
5306 {
|
|
5307 EXTENT e, anc;
|
|
5308 Lisp_Object result, face, anc_obj = Qnil;
|
|
5309
|
|
5310 CHECK_EXTENT (extent);
|
|
5311 e = XEXTENT (extent);
|
|
5312 if (!EXTENT_LIVE_P (e))
|
|
5313 return Fcons (Qdestroyed, Fcons (Qt, Qnil));
|
|
5314
|
|
5315 anc = extent_ancestor (e);
|
|
5316 XSETEXTENT (anc_obj, anc);
|
|
5317
|
|
5318 /* For efficiency, use the ancestor for all properties except detached */
|
|
5319
|
|
5320 result = extent_plist_slot (anc);
|
|
5321 face = Fextent_face (anc_obj);
|
|
5322 if (!NILP (face))
|
|
5323 result = Fcons (Qface, Fcons (face, result));
|
|
5324 face = Fextent_mouse_face (anc_obj);
|
|
5325 if (!NILP (face))
|
|
5326 result = Fcons (Qmouse_face, Fcons (face, result));
|
|
5327
|
|
5328 /* For now continue to include this for backwards compatibility. */
|
|
5329 if (extent_begin_glyph_layout (anc) != GL_TEXT)
|
|
5330 result = Fcons (Qglyph_layout,
|
|
5331 glyph_layout_to_symbol (extent_begin_glyph_layout (anc)));
|
|
5332
|
|
5333 if (extent_begin_glyph_layout (anc) != GL_TEXT)
|
|
5334 result = Fcons (Qbegin_glyph_layout,
|
|
5335 glyph_layout_to_symbol (extent_begin_glyph_layout (anc)));
|
|
5336 if (extent_end_glyph_layout (anc) != GL_TEXT)
|
|
5337 result = Fcons (Qend_glyph_layout,
|
|
5338 glyph_layout_to_symbol (extent_end_glyph_layout (anc)));
|
|
5339
|
|
5340 if (!NILP (extent_end_glyph (anc)))
|
|
5341 result = Fcons (Qend_glyph, Fcons (extent_end_glyph (anc), result));
|
|
5342 if (!NILP (extent_begin_glyph (anc)))
|
|
5343 result = Fcons (Qbegin_glyph, Fcons (extent_begin_glyph (anc), result));
|
|
5344
|
|
5345 if (extent_priority (anc) != 0)
|
|
5346 result = Fcons (Qpriority, Fcons (make_int (extent_priority (anc)),
|
|
5347 result));
|
|
5348
|
|
5349 if (!NILP (extent_invisible (anc)))
|
|
5350 result = Fcons (Qinvisible, Fcons (extent_invisible (anc), result));
|
|
5351
|
|
5352 if (!NILP (extent_read_only (anc)))
|
|
5353 result = Fcons (Qread_only, Fcons (extent_read_only (anc), result));
|
|
5354
|
|
5355 #define CONS_FLAG(flag, sym) if (extent_normal_field (anc, flag)) \
|
|
5356 result = Fcons (sym, Fcons (Qt, result))
|
|
5357 CONS_FLAG (end_open, Qend_open);
|
|
5358 CONS_FLAG (start_open, Qstart_open);
|
|
5359 CONS_FLAG (detachable, Qdetachable);
|
|
5360 CONS_FLAG (duplicable, Qduplicable);
|
|
5361 CONS_FLAG (unique, Qunique);
|
|
5362 #undef CONS_FLAG
|
|
5363
|
|
5364 /* detached is not an inherited property */
|
|
5365 if (extent_detached_p (e))
|
|
5366 result = Fcons (Qdetached, Fcons (Qt, result));
|
|
5367
|
|
5368 return result;
|
|
5369 }
|
|
5370
|
|
5371
|
|
5372 /************************************************************************/
|
|
5373 /* highlighting */
|
|
5374 /************************************************************************/
|
|
5375
|
|
5376 /* The display code looks into the Vlast_highlighted_extent variable to
|
|
5377 correctly display highlighted extents. This updates that variable,
|
|
5378 and marks the appropriate buffers as needing some redisplay.
|
|
5379 */
|
|
5380 static void
|
|
5381 do_highlight (Lisp_Object extent_obj, int highlight_p)
|
|
5382 {
|
|
5383 if (( highlight_p && (EQ (Vlast_highlighted_extent, extent_obj))) ||
|
|
5384 (!highlight_p && (EQ (Vlast_highlighted_extent, Qnil))))
|
|
5385 return;
|
|
5386 if (EXTENTP (Vlast_highlighted_extent) &&
|
|
5387 EXTENT_LIVE_P (XEXTENT (Vlast_highlighted_extent)))
|
|
5388 {
|
|
5389 /* do not recurse on descendants. Only one extent is highlighted
|
|
5390 at a time. */
|
32
|
5391 extent_changed_for_redisplay (XEXTENT (Vlast_highlighted_extent), 0, 0);
|
0
|
5392 }
|
|
5393 Vlast_highlighted_extent = Qnil;
|
|
5394 if (!NILP (extent_obj)
|
|
5395 && BUFFERP (extent_object (XEXTENT (extent_obj)))
|
|
5396 && highlight_p)
|
|
5397 {
|
32
|
5398 extent_changed_for_redisplay (XEXTENT (extent_obj), 0, 0);
|
0
|
5399 Vlast_highlighted_extent = extent_obj;
|
|
5400 }
|
|
5401 }
|
|
5402
|
20
|
5403 DEFUN ("force-highlight-extent", Fforce_highlight_extent, 1, 2, 0, /*
|
0
|
5404 Highlight or unhighlight the given extent.
|
|
5405 If the second arg is non-nil, it will be highlighted, else dehighlighted.
|
|
5406 This is the same as `highlight-extent', except that it will work even
|
|
5407 on extents without the `mouse-face' property.
|
20
|
5408 */
|
|
5409 (extent_obj, highlight_p))
|
0
|
5410 {
|
|
5411 if (NILP (extent_obj))
|
|
5412 highlight_p = Qnil;
|
|
5413 else
|
|
5414 XSETEXTENT (extent_obj, decode_extent (extent_obj, DE_MUST_BE_ATTACHED));
|
|
5415 do_highlight (extent_obj, !NILP (highlight_p));
|
|
5416 return Qnil;
|
|
5417 }
|
|
5418
|
20
|
5419 DEFUN ("highlight-extent", Fhighlight_extent, 1, 2, 0, /*
|
0
|
5420 Highlight the given extent, if it is highlightable
|
|
5421 \(that is, if it has the `mouse-face' property).
|
|
5422 If the second arg is non-nil, it will be highlighted, else dehighlighted.
|
|
5423 Highlighted extents are displayed as if they were merged with the face
|
|
5424 or faces specified by the `mouse-face' property.
|
20
|
5425 */
|
|
5426 (extent_obj, highlight_p))
|
0
|
5427 {
|
|
5428 if (EXTENTP (extent_obj) && NILP (extent_mouse_face (XEXTENT (extent_obj))))
|
|
5429 return Qnil;
|
|
5430 else
|
|
5431 return (Fforce_highlight_extent (extent_obj, highlight_p));
|
|
5432 }
|
|
5433
|
|
5434
|
|
5435 /************************************************************************/
|
|
5436 /* strings and extents */
|
|
5437 /************************************************************************/
|
|
5438
|
|
5439 /* copy/paste hooks */
|
|
5440
|
|
5441 static int
|
|
5442 run_extent_copy_paste_internal (EXTENT e, Bufpos from, Bufpos to,
|
|
5443 Lisp_Object object,
|
|
5444 Lisp_Object prop)
|
|
5445 {
|
|
5446 /* This function can GC */
|
|
5447 Lisp_Object extent;
|
|
5448 Lisp_Object copy_fn;
|
|
5449 XSETEXTENT (extent, e);
|
|
5450 copy_fn = Fextent_property (extent, prop, Qnil);
|
|
5451 if (!NILP (copy_fn))
|
|
5452 {
|
|
5453 Lisp_Object flag;
|
|
5454 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
5455 GCPRO3 (extent, copy_fn, object);
|
|
5456 if (BUFFERP (object))
|
|
5457 flag = call3_in_buffer (XBUFFER (object), copy_fn, extent,
|
|
5458 make_int (from), make_int (to));
|
|
5459 else
|
|
5460 flag = call3 (copy_fn, extent, make_int (from), make_int (to));
|
|
5461 UNGCPRO;
|
|
5462 if (NILP (flag) || !EXTENT_LIVE_P (XEXTENT (extent)))
|
|
5463 return 0;
|
|
5464 }
|
|
5465 return 1;
|
|
5466 }
|
|
5467
|
|
5468 static int
|
|
5469 run_extent_copy_function (EXTENT e, Bytind from, Bytind to)
|
|
5470 {
|
|
5471 Lisp_Object object = extent_object (e);
|
|
5472 /* This function can GC */
|
|
5473 return run_extent_copy_paste_internal
|
|
5474 (e, buffer_or_string_bytind_to_bufpos (object, from),
|
|
5475 buffer_or_string_bytind_to_bufpos (object, to), object,
|
|
5476 Qcopy_function);
|
|
5477 }
|
|
5478
|
|
5479 static int
|
|
5480 run_extent_paste_function (EXTENT e, Bytind from, Bytind to,
|
|
5481 Lisp_Object object)
|
|
5482 {
|
|
5483 /* This function can GC */
|
|
5484 return run_extent_copy_paste_internal
|
|
5485 (e, buffer_or_string_bytind_to_bufpos (object, from),
|
|
5486 buffer_or_string_bytind_to_bufpos (object, to), object,
|
|
5487 Qpaste_function);
|
|
5488 }
|
|
5489
|
|
5490 static void
|
|
5491 update_extent (EXTENT extent, Bytind from, Bytind to)
|
|
5492 {
|
|
5493 set_extent_endpoints (extent, from, to, Qnil);
|
|
5494 /* #### remove this crap */
|
|
5495 #ifdef ENERGIZE
|
|
5496 restore_energize_extent_state (extent);
|
|
5497 #endif
|
|
5498 }
|
|
5499
|
|
5500 /* Insert an extent, usually from the dup_list of a string which
|
|
5501 has just been inserted.
|
|
5502 This code does not handle the case of undo.
|
|
5503 */
|
|
5504 static Lisp_Object
|
|
5505 insert_extent (EXTENT extent, Bytind new_start, Bytind new_end,
|
|
5506 Lisp_Object object, int run_hooks)
|
|
5507 {
|
|
5508 /* This function can GC */
|
|
5509 Lisp_Object tmp;
|
|
5510
|
|
5511 if (!EQ (extent_object (extent), object))
|
|
5512 goto copy_it;
|
|
5513
|
|
5514 if (extent_detached_p (extent))
|
|
5515 {
|
|
5516 if (run_hooks &&
|
|
5517 !run_extent_paste_function (extent, new_start, new_end, object))
|
|
5518 /* The paste-function said don't re-attach this extent here. */
|
|
5519 return Qnil;
|
|
5520 else
|
|
5521 update_extent (extent, new_start, new_end);
|
|
5522 }
|
|
5523 else
|
|
5524 {
|
|
5525 Bytind exstart = extent_endpoint_bytind (extent, 0);
|
|
5526 Bytind exend = extent_endpoint_bytind (extent, 1);
|
|
5527
|
|
5528 if (exend < new_start || exstart > new_end)
|
|
5529 goto copy_it;
|
|
5530 else
|
|
5531 {
|
|
5532 new_start = min (exstart, new_start);
|
|
5533 new_end = max (exend, new_end);
|
|
5534 if (exstart != new_start || exend != new_end)
|
|
5535 update_extent (extent, new_start, new_end);
|
|
5536 }
|
|
5537 }
|
|
5538
|
|
5539 XSETEXTENT (tmp, extent);
|
|
5540 return tmp;
|
|
5541
|
|
5542 copy_it:
|
|
5543 if (run_hooks &&
|
|
5544 !run_extent_paste_function (extent, new_start, new_end, object))
|
|
5545 /* The paste-function said don't attach a copy of the extent here. */
|
|
5546 return Qnil;
|
|
5547 else
|
|
5548 {
|
|
5549 XSETEXTENT (tmp, copy_extent (extent, new_start, new_end, object));
|
|
5550 return tmp;
|
|
5551 }
|
|
5552 }
|
|
5553
|
20
|
5554 DEFUN ("insert-extent", Finsert_extent, 1, 5, 0, /*
|
0
|
5555 Insert EXTENT from START to END in BUFFER-OR-STRING.
|
|
5556 BUFFER-OR-STRING defaults to the current buffer if omitted.
|
|
5557 This operation does not insert any characters,
|
|
5558 but otherwise acts as if there were a replicating extent whose
|
|
5559 parent is EXTENT in some string that was just inserted.
|
|
5560 Returns the newly-inserted extent.
|
|
5561 The fourth arg, NO-HOOKS, can be used to inhibit the running of the
|
|
5562 extent's `paste-function' property if it has one.
|
|
5563 See documentation on `detach-extent' for a discussion of undo recording.
|
20
|
5564 */
|
|
5565 (extent, start, end, no_hooks, buffer_or_string))
|
0
|
5566 {
|
|
5567 EXTENT ext = decode_extent (extent, 0);
|
|
5568 Lisp_Object copy;
|
|
5569 Bytind s, e;
|
|
5570
|
|
5571 buffer_or_string = decode_buffer_or_string (buffer_or_string);
|
|
5572 get_buffer_or_string_range_byte (buffer_or_string, start, end, &s, &e,
|
|
5573 GB_ALLOW_PAST_ACCESSIBLE);
|
|
5574
|
|
5575 copy = insert_extent (ext, s, e, buffer_or_string, NILP (no_hooks));
|
|
5576 if (EXTENTP (copy))
|
|
5577 {
|
|
5578 if (extent_duplicable_p (XEXTENT (copy)))
|
|
5579 record_extent (copy, 1);
|
|
5580 }
|
|
5581 return copy;
|
|
5582 }
|
|
5583
|
|
5584
|
|
5585 /* adding buffer extents to a string */
|
|
5586
|
|
5587 struct add_string_extents_arg
|
|
5588 {
|
|
5589 Bytind from;
|
|
5590 Bytecount length;
|
|
5591 Lisp_Object string;
|
|
5592 };
|
|
5593
|
|
5594 static int
|
|
5595 add_string_extents_mapper (EXTENT extent, void *arg)
|
|
5596 {
|
|
5597 /* This function can GC */
|
|
5598 struct add_string_extents_arg *closure =
|
|
5599 (struct add_string_extents_arg *) arg;
|
|
5600 Bytecount start = extent_endpoint_bytind (extent, 0) - closure->from;
|
|
5601 Bytecount end = extent_endpoint_bytind (extent, 1) - closure->from;
|
|
5602
|
|
5603 if (extent_duplicable_p (extent))
|
|
5604 {
|
|
5605 EXTENT e;
|
|
5606
|
|
5607 start = max (start, 0);
|
|
5608 end = min (end, closure->length);
|
|
5609
|
|
5610 /* Run the copy-function to give an extent the option of
|
|
5611 not being copied into the string (or kill ring).
|
|
5612 */
|
|
5613 if (extent_duplicable_p (extent) &&
|
|
5614 !run_extent_copy_function (extent, start + closure->from,
|
|
5615 end + closure->from))
|
|
5616 return 0;
|
|
5617 e = copy_extent (extent, start, end, closure->string);
|
|
5618 }
|
|
5619
|
|
5620 return 0;
|
|
5621 }
|
|
5622
|
|
5623 /* Add the extents in buffer BUF from OPOINT to OPOINT+LENGTH to
|
|
5624 the string STRING. */
|
|
5625 void
|
|
5626 add_string_extents (Lisp_Object string, struct buffer *buf, Bytind opoint,
|
|
5627 Bytecount length)
|
|
5628 {
|
|
5629 /* This function can GC */
|
|
5630 struct add_string_extents_arg closure;
|
|
5631 struct gcpro gcpro1, gcpro2;
|
|
5632 Lisp_Object buffer;
|
|
5633
|
|
5634 closure.from = opoint;
|
|
5635 closure.length = length;
|
|
5636 closure.string = string;
|
|
5637 buffer = make_buffer (buf);
|
|
5638 GCPRO2 (buffer, string);
|
|
5639 map_extents_bytind (opoint, opoint + length, add_string_extents_mapper,
|
|
5640 (void *) &closure, buffer, 0,
|
|
5641 /* ignore extents that just abut the region */
|
|
5642 ME_END_CLOSED | ME_ALL_EXTENTS_OPEN |
|
|
5643 /* we are calling E-Lisp (the extent's copy function)
|
|
5644 so anything might happen */
|
|
5645 ME_MIGHT_CALL_ELISP);
|
|
5646 UNGCPRO;
|
|
5647 }
|
|
5648
|
|
5649 struct splice_in_string_extents_arg
|
|
5650 {
|
|
5651 Bytecount pos;
|
|
5652 Bytecount length;
|
|
5653 Bytind opoint;
|
|
5654 Lisp_Object buffer;
|
|
5655 };
|
|
5656
|
|
5657 static int
|
|
5658 splice_in_string_extents_mapper (EXTENT extent, void *arg)
|
|
5659 {
|
|
5660 /* This function can GC */
|
|
5661 struct splice_in_string_extents_arg *closure =
|
|
5662 (struct splice_in_string_extents_arg *) arg;
|
|
5663 /* BASE_START and BASE_END are the limits in the buffer of the string
|
|
5664 that was just inserted.
|
|
5665
|
|
5666 NEW_START and NEW_END are the prospective buffer positions of the
|
|
5667 extent that is going into the buffer. */
|
|
5668 Bytind base_start = closure->opoint;
|
|
5669 Bytind base_end = base_start + closure->length;
|
|
5670 Bytind new_start = (base_start + extent_endpoint_bytind (extent, 0) -
|
|
5671 closure->pos);
|
|
5672 Bytind new_end = (base_start + extent_endpoint_bytind (extent, 1) -
|
|
5673 closure->pos);
|
|
5674
|
|
5675 if (new_start < base_start)
|
|
5676 new_start = base_start;
|
|
5677 if (new_end > base_end)
|
|
5678 new_end = base_end;
|
|
5679 if (new_end <= new_start)
|
|
5680 return 0;
|
|
5681
|
|
5682 if (!extent_duplicable_p (extent))
|
|
5683 return 0;
|
|
5684
|
20
|
5685 if (!inside_undo &&
|
|
5686 !run_extent_paste_function (extent, new_start, new_end,
|
|
5687 closure->buffer))
|
|
5688 return 0;
|
|
5689 copy_extent (extent, new_start, new_end, closure->buffer);
|
|
5690
|
0
|
5691 return 0;
|
|
5692 }
|
|
5693
|
|
5694 /* We have just inserted a section of STRING (starting at POS, of
|
|
5695 length LENGTH) into buffer BUF at OPOINT. Do whatever is necessary
|
|
5696 to get the string's extents into the buffer. */
|
|
5697
|
|
5698 void
|
|
5699 splice_in_string_extents (Lisp_Object string, struct buffer *buf,
|
|
5700 Bytind opoint, Bytecount length, Bytecount pos)
|
|
5701 {
|
|
5702 struct splice_in_string_extents_arg closure;
|
|
5703 struct gcpro gcpro1, gcpro2;
|
|
5704 Lisp_Object buffer;
|
|
5705
|
|
5706 buffer = make_buffer (buf);
|
|
5707 closure.opoint = opoint;
|
|
5708 closure.pos = pos;
|
|
5709 closure.length = length;
|
|
5710 closure.buffer = buffer;
|
|
5711 GCPRO2 (buffer, string);
|
|
5712 map_extents_bytind (pos, pos + length,
|
|
5713 splice_in_string_extents_mapper,
|
|
5714 (void *) &closure, string, 0,
|
|
5715 /* ignore extents that just abut the region */
|
|
5716 ME_END_CLOSED | ME_ALL_EXTENTS_OPEN |
|
|
5717 /* we are calling E-Lisp (the extent's copy function)
|
|
5718 so anything might happen */
|
|
5719 ME_MIGHT_CALL_ELISP);
|
|
5720 UNGCPRO;
|
|
5721 }
|
|
5722
|
|
5723 struct copy_string_extents_arg
|
|
5724 {
|
|
5725 Bytecount new_pos;
|
|
5726 Bytecount old_pos;
|
|
5727 Bytecount length;
|
|
5728 Lisp_Object new_string;
|
|
5729 };
|
|
5730
|
|
5731 struct copy_string_extents_1_arg
|
|
5732 {
|
|
5733 Lisp_Object parent_in_question;
|
|
5734 EXTENT found_extent;
|
|
5735 };
|
|
5736
|
|
5737 static int
|
|
5738 copy_string_extents_1_mapper (EXTENT extent, void *arg)
|
|
5739 {
|
|
5740 struct copy_string_extents_1_arg *closure =
|
|
5741 (struct copy_string_extents_1_arg *) arg;
|
|
5742
|
|
5743 return 0;
|
|
5744 }
|
|
5745
|
|
5746 static int
|
|
5747 copy_string_extents_mapper (EXTENT extent, void *arg)
|
|
5748 {
|
|
5749 struct copy_string_extents_arg *closure =
|
|
5750 (struct copy_string_extents_arg *) arg;
|
|
5751 Bytecount old_start, old_end;
|
|
5752 Bytecount new_start, new_end;
|
|
5753
|
|
5754 old_start = extent_endpoint_bytind (extent, 0);
|
|
5755 old_end = extent_endpoint_bytind (extent, 1);
|
|
5756
|
|
5757 old_start = max (closure->old_pos, old_start);
|
|
5758 old_end = min (closure->old_pos + closure->length, old_end);
|
|
5759
|
|
5760 if (old_start >= old_end)
|
|
5761 return 0;
|
|
5762
|
|
5763 new_start = old_start + closure->new_pos - closure->old_pos;
|
|
5764 new_end = old_end + closure->new_pos - closure->old_pos;
|
|
5765
|
|
5766 copy_extent (extent,
|
|
5767 old_start + closure->new_pos - closure->old_pos,
|
|
5768 old_end + closure->new_pos - closure->old_pos,
|
|
5769 closure->new_string);
|
|
5770 return 0;
|
|
5771 }
|
|
5772
|
|
5773 /* The string NEW_STRING was partially constructed from OLD_STRING.
|
|
5774 In particular, the section of length LEN starting at NEW_POS in
|
|
5775 NEW_STRING came from the section of the same length starting at
|
|
5776 OLD_POS in OLD_STRING. Copy the extents as appropriate. */
|
|
5777
|
|
5778 void
|
|
5779 copy_string_extents (Lisp_Object new_string, Lisp_Object old_string,
|
|
5780 Bytecount new_pos, Bytecount old_pos,
|
|
5781 Bytecount length)
|
|
5782 {
|
|
5783 struct copy_string_extents_arg closure;
|
|
5784 struct gcpro gcpro1, gcpro2;
|
|
5785
|
|
5786 closure.new_pos = new_pos;
|
|
5787 closure.old_pos = old_pos;
|
|
5788 closure.new_string = new_string;
|
|
5789 closure.length = length;
|
|
5790 GCPRO2 (new_string, old_string);
|
|
5791 map_extents_bytind (old_pos, old_pos + length,
|
|
5792 copy_string_extents_mapper,
|
|
5793 (void *) &closure, old_string, 0,
|
|
5794 /* ignore extents that just abut the region */
|
|
5795 ME_END_CLOSED | ME_ALL_EXTENTS_OPEN |
|
|
5796 /* we are calling E-Lisp (the extent's copy function)
|
|
5797 so anything might happen */
|
|
5798 ME_MIGHT_CALL_ELISP);
|
|
5799 UNGCPRO;
|
|
5800 }
|
|
5801
|
|
5802 /* Checklist for sanity checking:
|
|
5803 - {kill, yank, copy} at {open, closed} {start, end} of {writable, read-only} extent
|
|
5804 - {kill, copy} & yank {once, repeatedly} duplicable extent in {same, different} buffer
|
|
5805 */
|
|
5806
|
|
5807
|
|
5808 /************************************************************************/
|
|
5809 /* text properties */
|
|
5810 /************************************************************************/
|
|
5811
|
|
5812 /* Text properties
|
|
5813 Originally this stuff was implemented in lisp (all of the functionality
|
|
5814 exists to make that possible) but speed was a problem.
|
|
5815 */
|
|
5816
|
|
5817 Lisp_Object Qtext_prop;
|
|
5818 Lisp_Object Qtext_prop_extent_paste_function;
|
|
5819
|
|
5820 static Lisp_Object
|
|
5821 get_text_property_bytind (Bytind position, Lisp_Object prop,
|
|
5822 Lisp_Object object, enum extent_at_flag fl,
|
|
5823 int text_props_only)
|
|
5824 {
|
|
5825 Lisp_Object extent;
|
|
5826
|
|
5827 /* text_props_only specifies whether we only consider text-property
|
|
5828 extents (those with the 'text-prop property set) or all extents. */
|
|
5829 if (!text_props_only)
|
|
5830 extent = extent_at_bytind (position, object, prop, 0, fl);
|
|
5831 else
|
|
5832 {
|
|
5833 EXTENT prior = 0;
|
|
5834 while (1)
|
|
5835 {
|
|
5836 extent = extent_at_bytind (position, object, Qtext_prop, prior,
|
|
5837 fl);
|
|
5838 if (NILP (extent))
|
|
5839 return Qnil;
|
|
5840 if (EQ (prop, Fextent_property (extent, Qtext_prop, Qnil)))
|
|
5841 break;
|
|
5842 prior = XEXTENT (extent);
|
|
5843 }
|
|
5844 }
|
|
5845
|
|
5846 if (!NILP (extent))
|
|
5847 return Fextent_property (extent, prop, Qnil);
|
|
5848 if (!NILP (Vdefault_text_properties))
|
|
5849 return Fplist_get (Vdefault_text_properties, prop, Qnil);
|
|
5850 return Qnil;
|
|
5851 }
|
|
5852
|
|
5853 static Lisp_Object
|
|
5854 get_text_property_1 (Lisp_Object pos, Lisp_Object prop, Lisp_Object object,
|
|
5855 Lisp_Object at_flag, int text_props_only)
|
|
5856 {
|
|
5857 Bytind position;
|
|
5858 int invert = 0;
|
|
5859
|
|
5860 object = decode_buffer_or_string (object);
|
|
5861 position = get_buffer_or_string_pos_byte (object, pos, GB_NO_ERROR_IF_BAD);
|
|
5862 CHECK_SYMBOL (prop);
|
|
5863
|
|
5864 /* We canonicalize the start/end-open/closed properties to the
|
|
5865 non-default version -- "adding" the default property really
|
|
5866 needs to remove the non-default one. See below for more
|
|
5867 on this. */
|
|
5868 if (EQ (prop, Qstart_closed))
|
|
5869 {
|
|
5870 prop = Qstart_open;
|
|
5871 invert = 1;
|
|
5872 }
|
|
5873
|
|
5874 if (EQ (prop, Qend_open))
|
|
5875 {
|
|
5876 prop = Qend_closed;
|
|
5877 invert = 1;
|
|
5878 }
|
|
5879
|
|
5880 {
|
|
5881 Lisp_Object val =
|
|
5882 get_text_property_bytind (position, prop, object,
|
|
5883 decode_extent_at_flag (at_flag),
|
|
5884 text_props_only);
|
|
5885 if (invert)
|
|
5886 val = NILP (val) ? Qt : Qnil;
|
|
5887 return val;
|
|
5888 }
|
|
5889 }
|
|
5890
|
20
|
5891 DEFUN ("get-text-property", Fget_text_property, 2, 4, 0, /*
|
0
|
5892 Returns the value of the PROP property at the given position.
|
|
5893 Optional arg OBJECT specifies the buffer or string to look in, and
|
|
5894 defaults to the current buffer.
|
|
5895 Optional arg AT-FLAG controls what it means for a property to be \"at\"
|
|
5896 a position, and has the same meaning as in `extent-at'.
|
|
5897 This examines only those properties added with `put-text-property'.
|
|
5898 See also `get-char-property'.
|
20
|
5899 */
|
|
5900 (pos, prop, object, at_flag))
|
0
|
5901 {
|
|
5902 return get_text_property_1 (pos, prop, object, at_flag, 1);
|
|
5903 }
|
|
5904
|
20
|
5905 DEFUN ("get-char-property", Fget_char_property, 2, 4, 0, /*
|
0
|
5906 Returns the value of the PROP property at the given position.
|
|
5907 Optional arg OBJECT specifies the buffer or string to look in, and
|
|
5908 defaults to the current buffer.
|
|
5909 Optional arg AT-FLAG controls what it means for a property to be \"at\"
|
|
5910 a position, and has the same meaning as in `extent-at'.
|
|
5911 This examines properties on all extents.
|
|
5912 See also `get-text-property'.
|
20
|
5913 */
|
|
5914 (pos, prop, object, at_flag))
|
0
|
5915 {
|
|
5916 return get_text_property_1 (pos, prop, object, at_flag, 0);
|
|
5917 }
|
|
5918
|
|
5919 /* About start/end-open/closed:
|
|
5920
|
|
5921 These properties have to be handled specially because of their
|
|
5922 strange behavior. If I put the "start-open" property on a region,
|
|
5923 then *all* text-property extents in the region have to have their
|
|
5924 start be open. This is unlike all other properties, which don't
|
|
5925 affect the extents of text properties other than their own.
|
|
5926
|
|
5927 So:
|
|
5928
|
|
5929 1) We have to map start-closed to (not start-open) and end-open
|
|
5930 to (not end-closed) -- i.e. adding the default is really the
|
|
5931 same as remove the non-default property. It won't work, for
|
|
5932 example, to have both "start-open" and "start-closed" on
|
|
5933 the same region.
|
|
5934 2) Whenever we add one of these properties, we go through all
|
|
5935 text-property extents in the region and set the appropriate
|
|
5936 open/closedness on them.
|
|
5937 3) Whenever we change a text-property extent for a property,
|
|
5938 we have to make sure we set the open/closedness properly.
|
|
5939
|
|
5940 (2) and (3) together rely on, and maintain, the invariant
|
|
5941 that the open/closedness of text-property extents is correct
|
|
5942 at the beginning and end of each operation.
|
|
5943 */
|
|
5944
|
|
5945 struct put_text_prop_arg
|
|
5946 {
|
|
5947 Lisp_Object prop, value; /* The property and value we are storing */
|
|
5948 Bytind start, end; /* The region into which we are storing it */
|
|
5949 Lisp_Object object;
|
|
5950 Lisp_Object the_extent; /* Our chosen extent; this is used for
|
|
5951 communication between subsequent passes. */
|
|
5952 int changed_p; /* Output: whether we have modified anything */
|
|
5953 };
|
|
5954
|
|
5955 static int
|
|
5956 put_text_prop_mapper (EXTENT e, void *arg)
|
|
5957 {
|
|
5958 struct put_text_prop_arg *closure = (struct put_text_prop_arg *) arg;
|
|
5959
|
|
5960 Lisp_Object object = closure->object;
|
|
5961 Lisp_Object value = closure->value;
|
|
5962 Bytind e_start, e_end;
|
|
5963 Bytind start = closure->start;
|
|
5964 Bytind end = closure->end;
|
|
5965 Lisp_Object extent, e_val;
|
|
5966 int is_eq;
|
|
5967
|
|
5968 XSETEXTENT (extent, e);
|
|
5969
|
|
5970 /* Note: in some cases when the property itself is 'start-open
|
|
5971 or 'end-closed, the checks to set the openness may do a bit
|
|
5972 of extra work; but it won't hurt because we then fix up the
|
2
|
5973 openness later on in put_text_prop_openness_mapper(). */
|
0
|
5974 if (!EQ (Fextent_property (extent, Qtext_prop, Qnil), closure->prop))
|
|
5975 /* It's not for this property; do nothing. */
|
|
5976 return 0;
|
|
5977
|
|
5978 e_start = extent_endpoint_bytind (e, 0);
|
|
5979 e_end = extent_endpoint_bytind (e, 1);
|
|
5980 e_val = Fextent_property (extent, closure->prop, Qnil);
|
|
5981 is_eq = EQ (value, e_val);
|
|
5982
|
|
5983 if (!NILP (value) && NILP (closure->the_extent) && is_eq)
|
|
5984 {
|
|
5985 /* We want there to be an extent here at the end, and we haven't picked
|
|
5986 one yet, so use this one. Extend it as necessary. We only reuse an
|
|
5987 extent which has an EQ value for the prop in question to avoid
|
|
5988 side-effecting the kill ring (that is, we never change the property
|
|
5989 on an extent after it has been created.)
|
|
5990 */
|
|
5991 if (e_start != start || e_end != end)
|
|
5992 {
|
|
5993 Bytind new_start = min (e_start, start);
|
|
5994 Bytind new_end = max (e_end, end);
|
|
5995 set_extent_endpoints (e, new_start, new_end, Qnil);
|
|
5996 /* If we changed the endpoint, then we need to set its
|
|
5997 openness. */
|
|
5998 set_extent_openness (e, new_start != e_start
|
|
5999 ? !NILP (get_text_property_bytind
|
|
6000 (start, Qstart_open, object,
|
|
6001 EXTENT_AT_AFTER, 1)) : -1,
|
|
6002 new_end != e_end
|
|
6003 ? NILP (get_text_property_bytind
|
|
6004 (end - 1, Qend_closed, object,
|
|
6005 EXTENT_AT_AFTER, 1))
|
|
6006 : -1);
|
|
6007 closure->changed_p = 1;
|
|
6008 }
|
|
6009 closure->the_extent = extent;
|
|
6010 }
|
|
6011
|
|
6012 /* Even if we're adding a prop, at this point, we want all other extents of
|
|
6013 this prop to go away (as now they overlap). So the theory here is that,
|
|
6014 when we are adding a prop to a region that has multiple (disjoint)
|
2
|
6015 occurrences of that prop in it already, we pick one of those and extend
|
0
|
6016 it, and remove the others.
|
|
6017 */
|
|
6018
|
|
6019 else if (EQ (extent, closure->the_extent))
|
|
6020 {
|
|
6021 /* just in case map-extents hits it again (does that happen?) */
|
|
6022 ;
|
|
6023 }
|
|
6024 else if (e_start >= start && e_end <= end)
|
|
6025 {
|
|
6026 /* Extent is contained in region; remove it. Don't destroy or modify
|
|
6027 it, because we don't want to change the attributes pointed to by the
|
|
6028 duplicates in the kill ring.
|
|
6029 */
|
|
6030 extent_detach (e);
|
|
6031 closure->changed_p = 1;
|
|
6032 }
|
|
6033 else if (!NILP (closure->the_extent) &&
|
|
6034 is_eq &&
|
|
6035 e_start <= end &&
|
|
6036 e_end >= start)
|
|
6037 {
|
|
6038 EXTENT te = XEXTENT (closure->the_extent);
|
|
6039 /* This extent overlaps, and has the same prop/value as the extent we've
|
|
6040 decided to reuse, so we can remove this existing extent as well (the
|
|
6041 whole thing, even the part outside of the region) and extend
|
|
6042 the-extent to cover it, resulting in the minimum number of extents in
|
|
6043 the buffer.
|
|
6044 */
|
|
6045 Bytind the_start = extent_endpoint_bytind (te, 0);
|
|
6046 Bytind the_end = extent_endpoint_bytind (te, 1);
|
|
6047 if (e_start != the_start && /* note AND not OR -- hmm, why is this
|
|
6048 the case? I think it's because the
|
|
6049 assumption that the text-property
|
|
6050 extents don't overlap makes it
|
|
6051 OK; changing it to an OR would
|
|
6052 result in changed_p sometimes getting
|
|
6053 falsely marked. Is this bad? */
|
|
6054 e_end != the_end)
|
|
6055 {
|
|
6056 Bytind new_start = min (e_start, the_start);
|
|
6057 Bytind new_end = max (e_end, the_end);
|
|
6058 set_extent_endpoints (te, new_start, new_end, Qnil);
|
|
6059 /* If we changed the endpoint, then we need to set its
|
|
6060 openness. We are setting the endpoint to be the same as
|
|
6061 that of the extent we're about to remove, and we assume
|
|
6062 (the invariant mentioned above) that extent has the
|
|
6063 proper endpoint setting, so we just use it. */
|
|
6064 set_extent_openness (te, new_start != e_start ?
|
|
6065 extent_start_open_p (e) : -1,
|
|
6066 new_end != e_end ?
|
|
6067 extent_end_open_p (e) : -1);
|
|
6068 closure->changed_p = 1;
|
|
6069 }
|
|
6070 extent_detach (e);
|
|
6071 }
|
|
6072 else if (e_end <= end)
|
|
6073 {
|
|
6074 /* Extent begins before start but ends before end, so we can just
|
|
6075 decrease its end position.
|
|
6076 */
|
|
6077 if (e_end != start)
|
|
6078 {
|
|
6079 set_extent_endpoints (e, e_start, start, Qnil);
|
|
6080 set_extent_openness (e, -1, NILP (get_text_property_bytind
|
|
6081 (start - 1, Qend_closed, object,
|
|
6082 EXTENT_AT_AFTER, 1)));
|
|
6083 closure->changed_p = 1;
|
|
6084 }
|
|
6085 }
|
|
6086 else if (e_start >= start)
|
|
6087 {
|
|
6088 /* Extent ends after end but begins after start, so we can just
|
|
6089 increase its start position.
|
|
6090 */
|
|
6091 if (e_start != end)
|
|
6092 {
|
|
6093 set_extent_endpoints (e, end, e_end, Qnil);
|
|
6094 set_extent_openness (e, !NILP (get_text_property_bytind
|
|
6095 (end, Qstart_open, object,
|
|
6096 EXTENT_AT_AFTER, 1)), -1);
|
|
6097 closure->changed_p = 1;
|
|
6098 }
|
|
6099 }
|
|
6100 else
|
|
6101 {
|
|
6102 /* Otherwise, `extent' straddles the region. We need to split it.
|
|
6103 */
|
|
6104 set_extent_endpoints (e, e_start, start, Qnil);
|
|
6105 set_extent_openness (e, -1, NILP (get_text_property_bytind
|
|
6106 (start - 1, Qend_closed, object,
|
|
6107 EXTENT_AT_AFTER, 1)));
|
|
6108 set_extent_openness (copy_extent (e, end, e_end, extent_object (e)),
|
|
6109 !NILP (get_text_property_bytind
|
|
6110 (end, Qstart_open, object,
|
|
6111 EXTENT_AT_AFTER, 1)), -1);
|
|
6112 closure->changed_p = 1;
|
|
6113 }
|
|
6114
|
|
6115 return 0; /* to continue mapping. */
|
|
6116 }
|
|
6117
|
|
6118 static int
|
|
6119 put_text_prop_openness_mapper (EXTENT e, void *arg)
|
|
6120 {
|
|
6121 struct put_text_prop_arg *closure = (struct put_text_prop_arg *) arg;
|
|
6122 Bytind e_start, e_end;
|
|
6123 Bytind start = closure->start;
|
|
6124 Bytind end = closure->end;
|
|
6125 Lisp_Object extent;
|
|
6126 XSETEXTENT (extent, e);
|
|
6127 e_start = extent_endpoint_bytind (e, 0);
|
|
6128 e_end = extent_endpoint_bytind (e, 1);
|
|
6129
|
|
6130 if (NILP (Fextent_property (extent, Qtext_prop, Qnil)))
|
|
6131 {
|
|
6132 /* It's not a text-property extent; do nothing. */
|
|
6133 ;
|
|
6134 }
|
|
6135 /* Note end conditions and NILP/!NILP's carefully. */
|
|
6136 else if (EQ (closure->prop, Qstart_open)
|
|
6137 && e_start >= start && e_start < end)
|
|
6138 set_extent_openness (e, !NILP (closure->value), -1);
|
|
6139 else if (EQ (closure->prop, Qend_closed)
|
|
6140 && e_end > start && e_end <= end)
|
|
6141 set_extent_openness (e, -1, NILP (closure->value));
|
|
6142
|
|
6143 return 0; /* to continue mapping. */
|
|
6144 }
|
|
6145
|
|
6146 static int
|
|
6147 put_text_prop (Bytind start, Bytind end, Lisp_Object object,
|
|
6148 Lisp_Object prop, Lisp_Object value,
|
|
6149 int duplicable_p)
|
|
6150 {
|
|
6151 /* This function can GC */
|
|
6152 struct put_text_prop_arg closure;
|
|
6153
|
|
6154 if (start == end) /* There are no characters in the region. */
|
|
6155 return 0;
|
|
6156
|
|
6157 /* convert to the non-default versions, since a nil property is
|
|
6158 the same as it not being present. */
|
|
6159 if (EQ (prop, Qstart_closed))
|
|
6160 {
|
|
6161 prop = Qstart_open;
|
|
6162 value = NILP (value) ? Qt : Qnil;
|
|
6163 }
|
|
6164 else if (EQ (prop, Qend_open))
|
|
6165 {
|
|
6166 prop = Qend_closed;
|
|
6167 value = NILP (value) ? Qt : Qnil;
|
|
6168 }
|
|
6169
|
|
6170 value = canonicalize_extent_property (prop, value);
|
|
6171
|
|
6172 closure.prop = prop;
|
|
6173 closure.value = value;
|
|
6174 closure.start = start;
|
|
6175 closure.end = end;
|
|
6176 closure.object = object;
|
|
6177 closure.changed_p = 0;
|
|
6178 closure.the_extent = Qnil;
|
|
6179
|
|
6180 map_extents_bytind (start, end,
|
|
6181 put_text_prop_mapper,
|
|
6182 (void *) &closure, object, 0,
|
|
6183 /* get all extents that abut the region */
|
|
6184 ME_ALL_EXTENTS_CLOSED | ME_END_CLOSED |
|
|
6185 /* it might QUIT or error if the user has
|
|
6186 fucked with the extent plist. */
|
48
|
6187 /* #### dmoore - I think this should include
|
|
6188 ME_MIGHT_MOVE_SOE, since the callback function
|
|
6189 might recurse back into map_extents_bytind. */
|
0
|
6190 ME_MIGHT_THROW |
|
|
6191 ME_MIGHT_MODIFY_EXTENTS);
|
|
6192
|
|
6193 /* If we made it through the loop without reusing an extent
|
|
6194 (and we want there to be one) make it now.
|
|
6195 */
|
|
6196 if (!NILP (value) && NILP (closure.the_extent))
|
|
6197 {
|
|
6198 Lisp_Object extent = Qnil;
|
|
6199
|
|
6200 XSETEXTENT (extent, make_extent_internal (object, start, end));
|
|
6201 closure.changed_p = 1;
|
|
6202 Fset_extent_property (extent, Qtext_prop, prop);
|
|
6203 Fset_extent_property (extent, prop, value);
|
|
6204 if (duplicable_p)
|
|
6205 {
|
|
6206 extent_duplicable_p (XEXTENT (extent)) = 1;
|
|
6207 Fset_extent_property (extent, Qpaste_function,
|
|
6208 Qtext_prop_extent_paste_function);
|
|
6209 }
|
|
6210 set_extent_openness (XEXTENT (extent),
|
|
6211 !NILP (get_text_property_bytind
|
|
6212 (start, Qstart_open, object,
|
|
6213 EXTENT_AT_AFTER, 1)),
|
|
6214 NILP (get_text_property_bytind
|
|
6215 (end - 1, Qend_closed, object,
|
|
6216 EXTENT_AT_AFTER, 1)));
|
|
6217 }
|
|
6218
|
|
6219 if (EQ (prop, Qstart_open) || EQ (prop, Qend_closed))
|
|
6220 {
|
|
6221 map_extents_bytind (start, end,
|
|
6222 put_text_prop_openness_mapper,
|
|
6223 (void *) &closure, object, 0,
|
|
6224 /* get all extents that abut the region */
|
|
6225 ME_ALL_EXTENTS_CLOSED | ME_END_CLOSED |
|
|
6226 ME_MIGHT_MODIFY_EXTENTS);
|
|
6227 }
|
|
6228
|
|
6229 return closure.changed_p;
|
|
6230 }
|
|
6231
|
20
|
6232 DEFUN ("put-text-property", Fput_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. The properties are copied when the characters are copied/pasted.
|
|
6236 Fifth argument OBJECT is the buffer or string containing the text, and
|
|
6237 defaults to the current buffer.
|
20
|
6238 */
|
|
6239 (start, end, prop, value, object))
|
0
|
6240 {
|
|
6241 /* This function can GC */
|
|
6242 Bytind s, e;
|
|
6243
|
|
6244 object = decode_buffer_or_string (object);
|
|
6245 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0);
|
|
6246 CHECK_SYMBOL (prop);
|
|
6247 put_text_prop (s, e, object, prop, value, 1);
|
|
6248 return prop;
|
|
6249 }
|
|
6250
|
20
|
6251 DEFUN ("put-nonduplicable-text-property",
|
|
6252 Fput_nonduplicable_text_property, 4, 5, 0, /*
|
0
|
6253 Adds the given property/value to all characters in the specified region.
|
|
6254 The property is conceptually attached to the characters rather than the
|
|
6255 region, however the properties will not be copied when the characters
|
|
6256 are copied.
|
|
6257 Fifth argument OBJECT is the buffer or string containing the text, and
|
|
6258 defaults to the current buffer.
|
20
|
6259 */
|
|
6260 (start, end, prop, value, object))
|
0
|
6261 {
|
|
6262 /* This function can GC */
|
|
6263 Bytind s, e;
|
|
6264
|
|
6265 object = decode_buffer_or_string (object);
|
|
6266 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0);
|
|
6267 CHECK_SYMBOL (prop);
|
|
6268 put_text_prop (s, e, object, prop, value, 0);
|
|
6269 return prop;
|
|
6270 }
|
|
6271
|
20
|
6272 DEFUN ("add-text-properties", Fadd_text_properties, 3, 4, 0, /*
|
0
|
6273 Add properties to the characters from START to END.
|
|
6274 The third argument PROPS is a property list specifying the property values
|
|
6275 to add. The optional fourth argument, OBJECT, is the buffer or string
|
|
6276 containing the text and defaults to the current buffer. Returns t if
|
|
6277 any property was changed, nil otherwise.
|
20
|
6278 */
|
|
6279 (start, end, props, object))
|
0
|
6280 {
|
|
6281 /* This function can GC */
|
|
6282 int changed = 0;
|
|
6283 Bytind s, e;
|
|
6284
|
|
6285 object = decode_buffer_or_string (object);
|
|
6286 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0);
|
|
6287 CHECK_LIST (props);
|
|
6288 for (; !NILP (props); props = Fcdr (Fcdr (props)))
|
|
6289 {
|
|
6290 Lisp_Object prop = XCAR (props);
|
|
6291 Lisp_Object value = Fcar (XCDR (props));
|
|
6292 CHECK_SYMBOL (prop);
|
|
6293 changed |= put_text_prop (s, e, object, prop, value, 1);
|
|
6294 }
|
|
6295 return (changed ? Qt : Qnil);
|
|
6296 }
|
|
6297
|
|
6298
|
|
6299 DEFUN ("add-nonduplicable-text-properties",
|
20
|
6300 Fadd_nonduplicable_text_properties, 3, 4, 0, /*
|
0
|
6301 Add nonduplicable properties to the characters from START to END.
|
|
6302 (The properties will not be copied when the characters are copied.)
|
|
6303 The third argument PROPS is a property list specifying the property values
|
|
6304 to add. The optional fourth argument, OBJECT, is the buffer or string
|
|
6305 containing the text and defaults to the current buffer. Returns t if
|
|
6306 any property was changed, nil otherwise.
|
20
|
6307 */
|
|
6308 (start, end, props, object))
|
0
|
6309 {
|
|
6310 /* This function can GC */
|
|
6311 int changed = 0;
|
|
6312 Bytind s, e;
|
|
6313
|
|
6314 object = decode_buffer_or_string (object);
|
|
6315 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0);
|
|
6316 CHECK_LIST (props);
|
|
6317 for (; !NILP (props); props = Fcdr (Fcdr (props)))
|
|
6318 {
|
|
6319 Lisp_Object prop = XCAR (props);
|
|
6320 Lisp_Object value = Fcar (XCDR (props));
|
|
6321 CHECK_SYMBOL (prop);
|
|
6322 changed |= put_text_prop (s, e, object, prop, value, 0);
|
|
6323 }
|
|
6324 return (changed ? Qt : Qnil);
|
|
6325 }
|
|
6326
|
20
|
6327 DEFUN ("remove-text-properties", Fremove_text_properties, 3, 4, 0, /*
|
0
|
6328 Remove the given properties from all characters in the specified region.
|
|
6329 PROPS should be a plist, but the values in that plist are ignored (treated
|
|
6330 as nil). Returns t if any property was changed, nil otherwise.
|
|
6331 Fourth argument OBJECT is the buffer or string containing the text, and
|
|
6332 defaults to the current buffer.
|
20
|
6333 */
|
|
6334 (start, end, props, object))
|
0
|
6335 {
|
|
6336 /* This function can GC */
|
|
6337 int changed = 0;
|
|
6338 Bytind s, e;
|
|
6339
|
|
6340 object = decode_buffer_or_string (object);
|
|
6341 get_buffer_or_string_range_byte (object, start, end, &s, &e, 0);
|
|
6342 CHECK_LIST (props);
|
|
6343 for (; !NILP (props); props = Fcdr (Fcdr (props)))
|
|
6344 {
|
|
6345 Lisp_Object prop = XCAR (props);
|
|
6346 CHECK_SYMBOL (prop);
|
|
6347 changed |= put_text_prop (s, e, object, prop, Qnil, 1);
|
|
6348 }
|
|
6349 return (changed ? Qt : Qnil);
|
|
6350 }
|
|
6351
|
|
6352 /* Whenever a text-prop extent is pasted into a buffer (via `yank' or `insert'
|
|
6353 or whatever) we attach the properties to the buffer by calling
|
|
6354 `put-text-property' instead of by simply allowing the extent to be copied or
|
|
6355 re-attached. Then we return nil, telling the extents code not to attach it
|
|
6356 again. By handing the insertion hackery in this way, we make kill/yank
|
|
6357 behave consistently with put-text-property and not fragment the extents
|
|
6358 (since text-prop extents must partition, not overlap).
|
|
6359
|
|
6360 The lisp implementation of this was probably fast enough, but since I moved
|
|
6361 the rest of the put-text-prop code here, I moved this as well for
|
|
6362 completeness.
|
|
6363 */
|
20
|
6364 DEFUN ("text-prop-extent-paste-function",
|
|
6365 Ftext_prop_extent_paste_function, 3, 3, 0, /*
|
0
|
6366 Used as the `paste-function' property of `text-prop' extents.
|
20
|
6367 */
|
|
6368 (extent, from, to))
|
0
|
6369 {
|
|
6370 /* This function can GC */
|
|
6371 Lisp_Object prop, val;
|
|
6372
|
|
6373 prop = Fextent_property (extent, Qtext_prop, Qnil);
|
|
6374 if (NILP (prop))
|
|
6375 signal_simple_error ("internal error: no text-prop", extent);
|
|
6376 val = Fextent_property (extent, prop, Qnil);
|
20
|
6377 #if 0
|
|
6378 /* removed by bill perry, 2/9/97
|
|
6379 ** This little bit of code would not allow you to have a text property
|
|
6380 ** with a value of Qnil. This is bad bad bad.
|
|
6381 */
|
0
|
6382 if (NILP (val))
|
|
6383 signal_simple_error_2 ("internal error: no text-prop",
|
|
6384 extent, prop);
|
20
|
6385 #endif
|
0
|
6386 Fput_text_property (from, to, prop, val, Qnil);
|
|
6387 return Qnil; /* important! */
|
|
6388 }
|
|
6389
|
|
6390 /* This function could easily be written in Lisp but the C code wants
|
|
6391 to use it in connection with invisible extents (at least currently).
|
|
6392 If this changes, consider moving this back into Lisp. */
|
|
6393
|
20
|
6394 DEFUN ("next-single-property-change", Fnext_single_property_change, 2, 4, 0, /*
|
0
|
6395 Return the position of next property change for a specific property.
|
|
6396 Scans characters forward from POS till it finds a change in the PROP
|
|
6397 property, then returns the position of the change. The optional third
|
|
6398 argument OBJECT is the buffer or string to scan (defaults to the current
|
|
6399 buffer).
|
|
6400 The property values are compared with `eq'.
|
|
6401 Return nil if the property is constant all the way to the end of BUFFER.
|
|
6402 If the value is non-nil, it is a position greater than POS, never equal.
|
|
6403
|
|
6404 If the optional fourth argument LIMIT is non-nil, don't search
|
|
6405 past position LIMIT; return LIMIT if nothing is found before LIMIT.
|
|
6406 If two or more extents with conflicting non-nil values for PROP overlap
|
|
6407 a particular character, it is undefined which value is considered to be
|
|
6408 the value of PROP. (Note that this situation will not happen if you always
|
|
6409 use the text-property primitives.)
|
20
|
6410 */
|
|
6411 (pos, prop, object, limit))
|
0
|
6412 {
|
|
6413 Bufpos bpos;
|
|
6414 Bufpos blim;
|
|
6415 Lisp_Object extent, value;
|
|
6416 int limit_was_nil;
|
|
6417
|
|
6418 object = decode_buffer_or_string (object);
|
|
6419 bpos = get_buffer_or_string_pos_char (object, pos, 0);
|
|
6420 if (NILP (limit))
|
|
6421 {
|
|
6422 blim = buffer_or_string_accessible_end_char (object);
|
|
6423 limit_was_nil = 1;
|
|
6424 }
|
|
6425 else
|
|
6426 {
|
|
6427 blim = get_buffer_or_string_pos_char (object, limit, 0);
|
|
6428 limit_was_nil = 0;
|
|
6429 }
|
|
6430 CHECK_SYMBOL (prop);
|
|
6431
|
|
6432 extent = Fextent_at (make_int (bpos), object, prop, Qnil, Qnil);
|
|
6433 if (!NILP (extent))
|
|
6434 value = Fextent_property (extent, prop, Qnil);
|
|
6435 else
|
|
6436 value = Qnil;
|
|
6437
|
|
6438 while (1)
|
|
6439 {
|
|
6440 bpos = XINT (Fnext_extent_change (make_int (bpos), object));
|
|
6441 if (bpos >= blim)
|
|
6442 break; /* property is the same all the way to the end */
|
|
6443 extent = Fextent_at (make_int (bpos), object, prop, Qnil, Qnil);
|
|
6444 if ((NILP (extent) && !NILP (value)) ||
|
|
6445 (!NILP (extent) && !EQ (value,
|
|
6446 Fextent_property (extent, prop, Qnil))))
|
|
6447 return make_int (bpos);
|
|
6448 }
|
|
6449
|
|
6450 /* I think it's more sensible for this function to return nil always
|
|
6451 in this situation and it used to do it this way, but it's been changed
|
|
6452 for FSF compatibility. */
|
|
6453 if (limit_was_nil)
|
|
6454 return Qnil;
|
|
6455 else
|
|
6456 return make_int (blim);
|
|
6457 }
|
|
6458
|
|
6459 /* See comment on previous function about why this is written in C. */
|
|
6460
|
20
|
6461 DEFUN ("previous-single-property-change",
|
|
6462 Fprevious_single_property_change, 2, 4, 0, /*
|
0
|
6463 Return the position of next property change for a specific property.
|
|
6464 Scans characters backward from POS till it finds a change in the PROP
|
|
6465 property, then returns the position of the change. The optional third
|
|
6466 argument OBJECT is the buffer or string to scan (defaults to the current
|
|
6467 buffer).
|
|
6468 The property values are compared with `eq'.
|
|
6469 Return nil if the property is constant all the way to the start of BUFFER.
|
|
6470 If the value is non-nil, it is a position less than POS, never equal.
|
|
6471
|
|
6472 If the optional fourth argument LIMIT is non-nil, don't search back
|
|
6473 past position LIMIT; return LIMIT if nothing is found until LIMIT.
|
|
6474 If two or more extents with conflicting non-nil values for PROP overlap
|
|
6475 a particular character, it is undefined which value is considered to be
|
|
6476 the value of PROP. (Note that this situation will not happen if you always
|
|
6477 use the text-property primitives.)
|
20
|
6478 */
|
|
6479 (pos, prop, object, limit))
|
0
|
6480 {
|
|
6481 Bufpos bpos;
|
|
6482 Bufpos blim;
|
|
6483 Lisp_Object extent, value;
|
|
6484 int limit_was_nil;
|
|
6485
|
|
6486 object = decode_buffer_or_string (object);
|
|
6487 bpos = get_buffer_or_string_pos_char (object, pos, 0);
|
|
6488 if (NILP (limit))
|
|
6489 {
|
|
6490 blim = buffer_or_string_accessible_begin_char (object);
|
|
6491 limit_was_nil = 1;
|
|
6492 }
|
|
6493 else
|
|
6494 {
|
|
6495 blim = get_buffer_or_string_pos_char (object, limit, 0);
|
|
6496 limit_was_nil = 0;
|
|
6497 }
|
|
6498
|
|
6499 CHECK_SYMBOL (prop);
|
|
6500
|
|
6501 /* extent-at refers to the character AFTER bpos, but we want the
|
|
6502 character before bpos. Thus the - 1. extent-at simply
|
|
6503 returns nil on bogus positions, so not to worry. */
|
|
6504 extent = Fextent_at (make_int (bpos - 1), object, prop, Qnil, Qnil);
|
|
6505 if (!NILP (extent))
|
|
6506 value = Fextent_property (extent, prop, Qnil);
|
|
6507 else
|
|
6508 value = Qnil;
|
|
6509
|
|
6510 while (1)
|
|
6511 {
|
|
6512 bpos = XINT (Fprevious_extent_change (make_int (bpos), object));
|
|
6513 if (bpos <= blim)
|
|
6514 break; /* property is the same all the way to the beginning */
|
|
6515 extent = Fextent_at (make_int (bpos - 1), object, prop, Qnil, Qnil);
|
|
6516 if ((NILP (extent) && !NILP (value)) ||
|
|
6517 (!NILP (extent) && !EQ (value,
|
|
6518 Fextent_property (extent, prop, Qnil))))
|
|
6519 return make_int (bpos);
|
|
6520 }
|
|
6521
|
|
6522 /* I think it's more sensible for this function to return nil always
|
|
6523 in this situation and it used to do it this way, but it's been changed
|
|
6524 for FSF compatibility. */
|
|
6525 if (limit_was_nil)
|
|
6526 return Qnil;
|
|
6527 else
|
|
6528 return make_int (blim);
|
|
6529 }
|
|
6530
|
|
6531 #ifdef MEMORY_USAGE_STATS
|
|
6532
|
|
6533 int
|
|
6534 compute_buffer_extent_usage (struct buffer *b, struct overhead_stats *ovstats)
|
|
6535 {
|
|
6536 /* #### not yet written */
|
|
6537 return 0;
|
|
6538 }
|
|
6539
|
|
6540 #endif /* MEMORY_USAGE_STATS */
|
|
6541
|
|
6542
|
|
6543 /************************************************************************/
|
|
6544 /* initialization */
|
|
6545 /************************************************************************/
|
|
6546
|
|
6547 void
|
|
6548 syms_of_extents (void)
|
|
6549 {
|
|
6550 defsymbol (&Qextentp, "extentp");
|
|
6551 defsymbol (&Qextent_live_p, "extent-live-p");
|
|
6552
|
|
6553 defsymbol (&Qend_closed, "end-closed");
|
|
6554 defsymbol (&Qstart_open, "start-open");
|
|
6555 defsymbol (&Qall_extents_closed, "all-extents-closed");
|
|
6556 defsymbol (&Qall_extents_open, "all-extents-open");
|
|
6557 defsymbol (&Qall_extents_closed_open, "all-extents-closed-open");
|
|
6558 defsymbol (&Qall_extents_open_closed, "all-extents-open-closed");
|
|
6559 defsymbol (&Qstart_in_region, "start-in-region");
|
|
6560 defsymbol (&Qend_in_region, "end-in-region");
|
|
6561 defsymbol (&Qstart_and_end_in_region, "start-and-end-in-region");
|
|
6562 defsymbol (&Qstart_or_end_in_region, "start-or-end-in-region");
|
|
6563 defsymbol (&Qnegate_in_region, "negate-in-region");
|
|
6564
|
|
6565 defsymbol (&Qdetached, "detached");
|
|
6566 defsymbol (&Qdestroyed, "destroyed");
|
|
6567 defsymbol (&Qbegin_glyph, "begin-glyph");
|
|
6568 defsymbol (&Qend_glyph, "end-glyph");
|
|
6569 defsymbol (&Qstart_open, "start-open");
|
|
6570 defsymbol (&Qend_open, "end-open");
|
|
6571 defsymbol (&Qstart_closed, "start-closed");
|
|
6572 defsymbol (&Qend_closed, "end-closed");
|
|
6573 defsymbol (&Qread_only, "read-only");
|
|
6574 /* defsymbol (&Qhighlight, "highlight"); in faces.c */
|
|
6575 defsymbol (&Qunique, "unique");
|
|
6576 defsymbol (&Qduplicable, "duplicable");
|
|
6577 defsymbol (&Qdetachable, "detachable");
|
|
6578 defsymbol (&Qpriority, "priority");
|
|
6579 defsymbol (&Qmouse_face, "mouse-face");
|
|
6580
|
|
6581 defsymbol (&Qglyph_layout, "glyph-layout"); /* backwards compatibility */
|
|
6582 defsymbol (&Qbegin_glyph_layout, "begin-glyph-layout");
|
|
6583 defsymbol (&Qbegin_glyph_layout, "end-glyph-layout");
|
|
6584 defsymbol (&Qoutside_margin, "outside-margin");
|
|
6585 defsymbol (&Qinside_margin, "inside-margin");
|
|
6586 defsymbol (&Qwhitespace, "whitespace");
|
|
6587 /* Qtext defined in general.c */
|
|
6588
|
|
6589 defsymbol (&Qglyph_invisible, "glyph-invisible");
|
|
6590
|
|
6591 defsymbol (&Qpaste_function, "paste-function");
|
|
6592 defsymbol (&Qcopy_function, "copy-function");
|
|
6593
|
|
6594 defsymbol (&Qtext_prop, "text-prop");
|
|
6595 defsymbol (&Qtext_prop_extent_paste_function,
|
|
6596 "text-prop-extent-paste-function");
|
|
6597
|
20
|
6598 DEFSUBR (Fextentp);
|
|
6599 DEFSUBR (Fextent_live_p);
|
|
6600 DEFSUBR (Fextent_detached_p);
|
|
6601 DEFSUBR (Fextent_start_position);
|
|
6602 DEFSUBR (Fextent_end_position);
|
|
6603 DEFSUBR (Fextent_object);
|
|
6604 DEFSUBR (Fextent_length);
|
0
|
6605 #if 0
|
20
|
6606 DEFSUBR (Fstack_of_extents);
|
0
|
6607 #endif
|
|
6608
|
20
|
6609 DEFSUBR (Fmake_extent);
|
|
6610 DEFSUBR (Fcopy_extent);
|
|
6611 DEFSUBR (Fdelete_extent);
|
|
6612 DEFSUBR (Fdetach_extent);
|
|
6613 DEFSUBR (Fset_extent_endpoints);
|
|
6614 DEFSUBR (Fnext_extent);
|
|
6615 DEFSUBR (Fprevious_extent);
|
0
|
6616 #if DEBUG_XEMACS
|
20
|
6617 DEFSUBR (Fnext_e_extent);
|
|
6618 DEFSUBR (Fprevious_e_extent);
|
0
|
6619 #endif
|
20
|
6620 DEFSUBR (Fnext_extent_change);
|
|
6621 DEFSUBR (Fprevious_extent_change);
|
|
6622
|
|
6623 DEFSUBR (Fextent_parent);
|
|
6624 DEFSUBR (Fextent_children);
|
|
6625 DEFSUBR (Fset_extent_parent);
|
|
6626
|
|
6627 DEFSUBR (Fextent_in_region_p);
|
|
6628 DEFSUBR (Fmap_extents);
|
|
6629 DEFSUBR (Fmap_extent_children);
|
|
6630 DEFSUBR (Fextent_at);
|
|
6631
|
|
6632 DEFSUBR (Fextent_face);
|
|
6633 DEFSUBR (Fset_extent_face);
|
|
6634 DEFSUBR (Fextent_mouse_face);
|
|
6635 DEFSUBR (Fset_extent_mouse_face);
|
|
6636 DEFSUBR (Fset_extent_begin_glyph);
|
|
6637 DEFSUBR (Fset_extent_end_glyph);
|
|
6638 DEFSUBR (Fextent_begin_glyph);
|
|
6639 DEFSUBR (Fextent_end_glyph);
|
|
6640 DEFSUBR (Fset_extent_begin_glyph_layout);
|
|
6641 DEFSUBR (Fset_extent_end_glyph_layout);
|
|
6642 DEFSUBR (Fextent_begin_glyph_layout);
|
|
6643 DEFSUBR (Fextent_end_glyph_layout);
|
|
6644 DEFSUBR (Fset_extent_priority);
|
|
6645 DEFSUBR (Fextent_priority);
|
|
6646 DEFSUBR (Fset_extent_property);
|
|
6647 DEFSUBR (Fextent_property);
|
|
6648 DEFSUBR (Fextent_properties);
|
|
6649
|
|
6650 DEFSUBR (Fhighlight_extent);
|
|
6651 DEFSUBR (Fforce_highlight_extent);
|
|
6652
|
|
6653 DEFSUBR (Finsert_extent);
|
|
6654
|
|
6655 DEFSUBR (Fget_text_property);
|
|
6656 DEFSUBR (Fget_char_property);
|
|
6657 DEFSUBR (Fput_text_property);
|
|
6658 DEFSUBR (Fput_nonduplicable_text_property);
|
|
6659 DEFSUBR (Fadd_text_properties);
|
|
6660 DEFSUBR (Fadd_nonduplicable_text_properties);
|
|
6661 DEFSUBR (Fremove_text_properties);
|
|
6662 DEFSUBR (Ftext_prop_extent_paste_function);
|
|
6663 DEFSUBR (Fnext_single_property_change);
|
|
6664 DEFSUBR (Fprevious_single_property_change);
|
0
|
6665 }
|
|
6666
|
|
6667 void
|
|
6668 vars_of_extents (void)
|
|
6669 {
|
|
6670 DEFVAR_INT ("mouse-highlight-priority", &mouse_highlight_priority /*
|
|
6671 The priority to use for the mouse-highlighting pseudo-extent
|
|
6672 that is used to highlight extents with the `mouse-face' attribute set.
|
|
6673 See `set-extent-priority'.
|
|
6674 */ );
|
|
6675 /* Set mouse-highlight-priority (which ends up being used both for the
|
|
6676 mouse-highlighting pseudo-extent and the primary selection extent)
|
|
6677 to a very high value because very few extents should override it.
|
|
6678 1000 gives lots of room below it for different-prioritied extents.
|
|
6679 10 doesn't. ediff, for example, likes to use priorities around 100.
|
|
6680 --ben */
|
|
6681 mouse_highlight_priority = /* 10 */ 1000;
|
|
6682
|
|
6683 DEFVAR_LISP ("default-text-properties", &Vdefault_text_properties /*
|
|
6684 Property list giving default values for text properties.
|
|
6685 Whenever a character does not specify a value for a property, the value
|
|
6686 stored in this list is used instead. This only applies when the
|
|
6687 functions `get-text-property' or `get-char-property' are called.
|
|
6688 */ );
|
|
6689 Vdefault_text_properties = Qnil;
|
|
6690
|
|
6691 staticpro (&Vlast_highlighted_extent);
|
|
6692 Vlast_highlighted_extent = Qnil;
|
|
6693
|
|
6694 Vextent_face_reusable_list = Fcons (Qnil, Qnil);
|
|
6695 staticpro (&Vextent_face_reusable_list);
|
|
6696
|
|
6697 extent_auxiliary_defaults.begin_glyph = Qnil;
|
|
6698 extent_auxiliary_defaults.end_glyph = Qnil;
|
|
6699 extent_auxiliary_defaults.parent = Qnil;
|
|
6700 extent_auxiliary_defaults.children = Qnil;
|
|
6701 extent_auxiliary_defaults.priority = 0;
|
|
6702 extent_auxiliary_defaults.invisible = Qnil;
|
|
6703 extent_auxiliary_defaults.read_only = Qnil;
|
|
6704 extent_auxiliary_defaults.mouse_face = Qnil;
|
|
6705 }
|
|
6706
|
|
6707 void
|
|
6708 complex_vars_of_extents (void)
|
|
6709 {
|
|
6710 staticpro (&Vextent_face_memoize_hash_table);
|
|
6711 /* The memoize hash-table maps from lists of symbols to lists of
|
|
6712 faces. It needs to be `equal' to implement the memoization.
|
|
6713 The reverse table maps in the other direction and just needs
|
|
6714 to do `eq' comparison because the lists of faces are already
|
|
6715 memoized. */
|
|
6716 Vextent_face_memoize_hash_table =
|
|
6717 make_lisp_hashtable (100, HASHTABLE_VALUE_WEAK, HASHTABLE_EQUAL);
|
|
6718 staticpro (&Vextent_face_reverse_memoize_hash_table);
|
|
6719 Vextent_face_reverse_memoize_hash_table =
|
|
6720 make_lisp_hashtable (100, HASHTABLE_KEY_WEAK, HASHTABLE_EQ);
|
|
6721 }
|