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