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