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