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