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