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