Mercurial > emacs
annotate src/intervals.c @ 5169:d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
If source has no intervals, set dest properties to nil.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Thu, 25 Nov 1993 06:28:03 +0000 |
| parents | 99edf052bfa0 |
| children | d48ba25b35bf |
| rev | line source |
|---|---|
| 1157 | 1 /* Code for doing intervals. |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
2 Copyright (C) 1993 Free Software Foundation, Inc. |
| 1157 | 3 |
| 4 This file is part of GNU Emacs. | |
| 5 | |
| 6 GNU Emacs is free software; you can redistribute it and/or modify | |
| 7 it under the terms of the GNU General Public License as published by | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
| 1157 | 9 any later version. |
| 10 | |
| 11 GNU Emacs is distributed in the hope that it will be useful, | |
| 12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 GNU General Public License for more details. | |
| 15 | |
| 16 You should have received a copy of the GNU General Public License | |
| 17 along with GNU Emacs; see the file COPYING. If not, write to | |
| 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
| 19 | |
| 20 | |
| 21 /* NOTES: | |
| 22 | |
| 23 Have to ensure that we can't put symbol nil on a plist, or some | |
| 24 functions may work incorrectly. | |
| 25 | |
| 26 An idea: Have the owner of the tree keep count of splits and/or | |
| 27 insertion lengths (in intervals), and balance after every N. | |
| 28 | |
| 29 Need to call *_left_hook when buffer is killed. | |
| 30 | |
| 31 Scan for zero-length, or 0-length to see notes about handling | |
| 32 zero length interval-markers. | |
| 33 | |
| 34 There are comments around about freeing intervals. It might be | |
| 35 faster to explicitly free them (put them on the free list) than | |
| 36 to GC them. | |
| 37 | |
| 38 */ | |
| 39 | |
| 40 | |
|
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4638
diff
changeset
|
41 #include <config.h> |
| 1157 | 42 #include "lisp.h" |
| 43 #include "intervals.h" | |
| 44 #include "buffer.h" | |
| 4962 | 45 #include "puresize.h" |
| 1157 | 46 |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
47 /* The rest of the file is within this conditional. */ |
|
1301
5a27062b8b7f
* intervals.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1288
diff
changeset
|
48 #ifdef USE_TEXT_PROPERTIES |
|
5a27062b8b7f
* intervals.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1288
diff
changeset
|
49 |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
50 /* Factor for weight-balancing interval trees. */ |
| 1157 | 51 Lisp_Object interval_balance_threshold; |
| 52 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
53 /* Utility functions for intervals. */ |
| 1157 | 54 |
| 55 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
56 /* Create the root interval of some object, a buffer or string. */ |
| 1157 | 57 |
| 58 INTERVAL | |
| 59 create_root_interval (parent) | |
| 60 Lisp_Object parent; | |
| 61 { | |
| 4962 | 62 INTERVAL new; |
| 63 | |
| 64 CHECK_IMPURE (parent); | |
| 65 | |
| 66 new = make_interval (); | |
| 1157 | 67 |
| 68 if (XTYPE (parent) == Lisp_Buffer) | |
| 69 { | |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
70 new->total_length = (BUF_Z (XBUFFER (parent)) |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
71 - BUF_BEG (XBUFFER (parent))); |
| 1157 | 72 XBUFFER (parent)->intervals = new; |
| 73 } | |
| 74 else if (XTYPE (parent) == Lisp_String) | |
| 75 { | |
| 76 new->total_length = XSTRING (parent)->size; | |
| 77 XSTRING (parent)->intervals = new; | |
| 78 } | |
| 79 | |
| 80 new->parent = (INTERVAL) parent; | |
| 81 new->position = 1; | |
| 82 | |
| 83 return new; | |
| 84 } | |
| 85 | |
| 86 /* Make the interval TARGET have exactly the properties of SOURCE */ | |
| 87 | |
| 88 void | |
| 89 copy_properties (source, target) | |
| 90 register INTERVAL source, target; | |
| 91 { | |
| 92 if (DEFAULT_INTERVAL_P (source) && DEFAULT_INTERVAL_P (target)) | |
| 93 return; | |
| 94 | |
| 95 COPY_INTERVAL_CACHE (source, target); | |
| 96 target->plist = Fcopy_sequence (source->plist); | |
| 97 } | |
| 98 | |
| 99 /* Merge the properties of interval SOURCE into the properties | |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
100 of interval TARGET. That is to say, each property in SOURCE |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
101 is added to TARGET if TARGET has no such property as yet. */ |
| 1157 | 102 |
| 103 static void | |
| 104 merge_properties (source, target) | |
| 105 register INTERVAL source, target; | |
| 106 { | |
| 107 register Lisp_Object o, sym, val; | |
| 108 | |
| 109 if (DEFAULT_INTERVAL_P (source) && DEFAULT_INTERVAL_P (target)) | |
| 110 return; | |
| 111 | |
| 112 MERGE_INTERVAL_CACHE (source, target); | |
| 113 | |
| 114 o = source->plist; | |
| 115 while (! EQ (o, Qnil)) | |
| 116 { | |
| 117 sym = Fcar (o); | |
| 118 val = Fmemq (sym, target->plist); | |
| 119 | |
| 120 if (NILP (val)) | |
| 121 { | |
| 122 o = Fcdr (o); | |
| 123 val = Fcar (o); | |
| 124 target->plist = Fcons (sym, Fcons (val, target->plist)); | |
| 125 o = Fcdr (o); | |
| 126 } | |
| 127 else | |
| 128 o = Fcdr (Fcdr (o)); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 /* Return 1 if the two intervals have the same properties, | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
133 0 otherwise. */ |
| 1157 | 134 |
| 135 int | |
| 136 intervals_equal (i0, i1) | |
| 137 INTERVAL i0, i1; | |
| 138 { | |
| 139 register Lisp_Object i0_cdr, i0_sym, i1_val; | |
| 140 register i1_len; | |
| 141 | |
| 142 if (DEFAULT_INTERVAL_P (i0) && DEFAULT_INTERVAL_P (i1)) | |
| 143 return 1; | |
| 144 | |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
145 if (DEFAULT_INTERVAL_P (i0) || DEFAULT_INTERVAL_P (i1)) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
146 return 0; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
147 |
| 1157 | 148 i1_len = XFASTINT (Flength (i1->plist)); |
| 149 if (i1_len & 0x1) /* Paranoia -- plists are always even */ | |
| 150 abort (); | |
| 151 i1_len /= 2; | |
| 152 i0_cdr = i0->plist; | |
| 153 while (!NILP (i0_cdr)) | |
| 154 { | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
155 /* Lengths of the two plists were unequal. */ |
| 1157 | 156 if (i1_len == 0) |
| 157 return 0; | |
| 158 | |
| 159 i0_sym = Fcar (i0_cdr); | |
| 160 i1_val = Fmemq (i0_sym, i1->plist); | |
| 161 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
162 /* i0 has something i1 doesn't. */ |
| 1157 | 163 if (EQ (i1_val, Qnil)) |
| 164 return 0; | |
| 165 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
166 /* i0 and i1 both have sym, but it has different values in each. */ |
| 1157 | 167 i0_cdr = Fcdr (i0_cdr); |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
168 if (! EQ (Fcar (Fcdr (i1_val)), Fcar (i0_cdr))) |
| 1157 | 169 return 0; |
| 170 | |
| 171 i0_cdr = Fcdr (i0_cdr); | |
| 172 i1_len--; | |
| 173 } | |
| 174 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
175 /* Lengths of the two plists were unequal. */ |
| 1157 | 176 if (i1_len > 0) |
| 177 return 0; | |
| 178 | |
| 179 return 1; | |
| 180 } | |
| 181 | |
| 182 static int icount; | |
| 183 static int idepth; | |
| 184 static int zero_length; | |
| 185 | |
| 186 /* Traverse an interval tree TREE, performing FUNCTION on each node. | |
|
1958
8bc716df45e3
(traverse_intervals): New arg ARG.
Richard M. Stallman <rms@gnu.org>
parents:
1412
diff
changeset
|
187 Pass FUNCTION two args: an interval, and ARG. */ |
| 1157 | 188 |
| 189 void | |
|
1958
8bc716df45e3
(traverse_intervals): New arg ARG.
Richard M. Stallman <rms@gnu.org>
parents:
1412
diff
changeset
|
190 traverse_intervals (tree, position, depth, function, arg) |
| 1157 | 191 INTERVAL tree; |
|
1412
6097878fbd46
* intervals.c (traverse_intervals): New parameter `depth'.
Joseph Arceneaux <jla@gnu.org>
parents:
1316
diff
changeset
|
192 int position, depth; |
| 1157 | 193 void (* function) (); |
|
1958
8bc716df45e3
(traverse_intervals): New arg ARG.
Richard M. Stallman <rms@gnu.org>
parents:
1412
diff
changeset
|
194 Lisp_Object arg; |
| 1157 | 195 { |
| 196 if (NULL_INTERVAL_P (tree)) | |
| 197 return; | |
| 198 | |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
199 traverse_intervals (tree->left, position, depth + 1, function, arg); |
| 1157 | 200 position += LEFT_TOTAL_LENGTH (tree); |
| 201 tree->position = position; | |
|
1958
8bc716df45e3
(traverse_intervals): New arg ARG.
Richard M. Stallman <rms@gnu.org>
parents:
1412
diff
changeset
|
202 (*function) (tree, arg); |
| 1157 | 203 position += LENGTH (tree); |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
204 traverse_intervals (tree->right, position, depth + 1, function, arg); |
| 1157 | 205 } |
| 206 | |
| 207 #if 0 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
208 /* These functions are temporary, for debugging purposes only. */ |
| 1157 | 209 |
| 210 INTERVAL search_interval, found_interval; | |
| 211 | |
| 212 void | |
| 213 check_for_interval (i) | |
| 214 register INTERVAL i; | |
| 215 { | |
| 216 if (i == search_interval) | |
| 217 { | |
| 218 found_interval = i; | |
| 219 icount++; | |
| 220 } | |
| 221 } | |
| 222 | |
| 223 INTERVAL | |
| 224 search_for_interval (i, tree) | |
| 225 register INTERVAL i, tree; | |
| 226 { | |
| 227 icount = 0; | |
| 228 search_interval = i; | |
| 229 found_interval = NULL_INTERVAL; | |
|
1958
8bc716df45e3
(traverse_intervals): New arg ARG.
Richard M. Stallman <rms@gnu.org>
parents:
1412
diff
changeset
|
230 traverse_intervals (tree, 1, 0, &check_for_interval, Qnil); |
| 1157 | 231 return found_interval; |
| 232 } | |
| 233 | |
| 234 static void | |
| 235 inc_interval_count (i) | |
| 236 INTERVAL i; | |
| 237 { | |
| 238 icount++; | |
| 239 if (LENGTH (i) == 0) | |
| 240 zero_length++; | |
| 241 if (depth > idepth) | |
| 242 idepth = depth; | |
| 243 } | |
| 244 | |
| 245 int | |
| 246 count_intervals (i) | |
| 247 register INTERVAL i; | |
| 248 { | |
| 249 icount = 0; | |
| 250 idepth = 0; | |
| 251 zero_length = 0; | |
|
1958
8bc716df45e3
(traverse_intervals): New arg ARG.
Richard M. Stallman <rms@gnu.org>
parents:
1412
diff
changeset
|
252 traverse_intervals (i, 1, 0, &inc_interval_count, Qnil); |
| 1157 | 253 |
| 254 return icount; | |
| 255 } | |
| 256 | |
| 257 static INTERVAL | |
| 258 root_interval (interval) | |
| 259 INTERVAL interval; | |
| 260 { | |
| 261 register INTERVAL i = interval; | |
| 262 | |
| 263 while (! ROOT_INTERVAL_P (i)) | |
| 264 i = i->parent; | |
| 265 | |
| 266 return i; | |
| 267 } | |
| 268 #endif | |
| 269 | |
| 270 /* Assuming that a left child exists, perform the following operation: | |
| 271 | |
| 272 A B | |
| 273 / \ / \ | |
| 274 B => A | |
| 275 / \ / \ | |
| 276 c c | |
| 277 */ | |
| 278 | |
| 279 static INTERVAL | |
| 280 rotate_right (interval) | |
| 281 INTERVAL interval; | |
| 282 { | |
| 283 INTERVAL i; | |
| 284 INTERVAL B = interval->left; | |
| 285 int len = LENGTH (interval); | |
| 286 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
287 /* Deal with any Parent of A; make it point to B. */ |
| 1157 | 288 if (! ROOT_INTERVAL_P (interval)) |
| 289 if (AM_LEFT_CHILD (interval)) | |
| 290 interval->parent->left = interval->left; | |
| 291 else | |
| 292 interval->parent->right = interval->left; | |
| 293 interval->left->parent = interval->parent; | |
| 294 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
295 /* B gets the same length as A, since it get A's position in the tree. */ |
| 1157 | 296 interval->left->total_length = interval->total_length; |
| 297 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
298 /* B becomes the parent of A. */ |
| 1157 | 299 i = interval->left->right; |
| 300 interval->left->right = interval; | |
| 301 interval->parent = interval->left; | |
| 302 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
303 /* A gets c as left child. */ |
| 1157 | 304 interval->left = i; |
| 305 if (! NULL_INTERVAL_P (i)) | |
| 306 i->parent = interval; | |
| 307 interval->total_length = (len + LEFT_TOTAL_LENGTH (interval) | |
| 308 + RIGHT_TOTAL_LENGTH (interval)); | |
| 309 | |
| 310 return B; | |
| 311 } | |
| 312 | |
| 313 /* Assuming that a right child exists, perform the following operation: | |
| 314 | |
| 315 A B | |
| 316 / \ / \ | |
| 317 B => A | |
| 318 / \ / \ | |
| 319 c c | |
| 320 */ | |
| 321 | |
| 322 static INTERVAL | |
| 323 rotate_left (interval) | |
| 324 INTERVAL interval; | |
| 325 { | |
| 326 INTERVAL i; | |
| 327 INTERVAL B = interval->right; | |
| 328 int len = LENGTH (interval); | |
| 329 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
330 /* Deal with the parent of A. */ |
| 1157 | 331 if (! ROOT_INTERVAL_P (interval)) |
| 332 if (AM_LEFT_CHILD (interval)) | |
| 333 interval->parent->left = interval->right; | |
| 334 else | |
| 335 interval->parent->right = interval->right; | |
| 336 interval->right->parent = interval->parent; | |
| 337 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
338 /* B must have the same total length of A. */ |
| 1157 | 339 interval->right->total_length = interval->total_length; |
| 340 | |
| 341 /* Make B the parent of A */ | |
| 342 i = interval->right->left; | |
| 343 interval->right->left = interval; | |
| 344 interval->parent = interval->right; | |
| 345 | |
| 346 /* Make A point to c */ | |
| 347 interval->right = i; | |
| 348 if (! NULL_INTERVAL_P (i)) | |
| 349 i->parent = interval; | |
| 350 interval->total_length = (len + LEFT_TOTAL_LENGTH (interval) | |
| 351 + RIGHT_TOTAL_LENGTH (interval)); | |
| 352 | |
| 353 return B; | |
| 354 } | |
| 355 | |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
356 /* Split INTERVAL into two pieces, starting the second piece at |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
357 character position OFFSET (counting from 0), relative to INTERVAL. |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
358 INTERVAL becomes the left-hand piece, and the right-hand piece |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
359 (second, lexicographically) is returned. |
| 1164 | 360 |
| 361 The size and position fields of the two intervals are set based upon | |
| 362 those of the original interval. The property list of the new interval | |
| 363 is reset, thus it is up to the caller to do the right thing with the | |
| 364 result. | |
| 1157 | 365 |
| 366 Note that this does not change the position of INTERVAL; if it is a root, | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
367 it is still a root after this operation. */ |
| 1157 | 368 |
| 369 INTERVAL | |
| 1164 | 370 split_interval_right (interval, offset) |
| 1157 | 371 INTERVAL interval; |
| 1164 | 372 int offset; |
| 1157 | 373 { |
| 374 INTERVAL new = make_interval (); | |
| 375 int position = interval->position; | |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
376 int new_length = LENGTH (interval) - offset; |
| 1157 | 377 |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
378 new->position = position + offset; |
| 1157 | 379 new->parent = interval; |
| 380 | |
| 381 if (LEAF_INTERVAL_P (interval) || NULL_RIGHT_CHILD (interval)) | |
| 382 { | |
| 383 interval->right = new; | |
| 384 new->total_length = new_length; | |
| 385 | |
| 386 return new; | |
| 387 } | |
| 388 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
389 /* Insert the new node between INTERVAL and its right child. */ |
| 1157 | 390 new->right = interval->right; |
| 391 interval->right->parent = new; | |
| 392 interval->right = new; | |
| 393 | |
| 394 new->total_length = new_length + new->right->total_length; | |
| 395 | |
| 396 return new; | |
| 397 } | |
| 398 | |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
399 /* Split INTERVAL into two pieces, starting the second piece at |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
400 character position OFFSET (counting from 0), relative to INTERVAL. |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
401 INTERVAL becomes the right-hand piece, and the left-hand piece |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
402 (first, lexicographically) is returned. |
| 1157 | 403 |
| 1164 | 404 The size and position fields of the two intervals are set based upon |
| 405 those of the original interval. The property list of the new interval | |
| 406 is reset, thus it is up to the caller to do the right thing with the | |
| 407 result. | |
| 408 | |
| 409 Note that this does not change the position of INTERVAL; if it is a root, | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
410 it is still a root after this operation. */ |
| 1157 | 411 |
| 412 INTERVAL | |
| 1164 | 413 split_interval_left (interval, offset) |
| 1157 | 414 INTERVAL interval; |
| 1164 | 415 int offset; |
| 1157 | 416 { |
| 417 INTERVAL new = make_interval (); | |
| 418 int position = interval->position; | |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
419 int new_length = offset; |
| 1157 | 420 |
| 421 new->position = interval->position; | |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
422 interval->position = interval->position + offset; |
| 1157 | 423 new->parent = interval; |
| 424 | |
| 425 if (NULL_LEFT_CHILD (interval)) | |
| 426 { | |
| 427 interval->left = new; | |
| 428 new->total_length = new_length; | |
| 429 | |
| 430 return new; | |
| 431 } | |
| 432 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
433 /* Insert the new node between INTERVAL and its left child. */ |
| 1157 | 434 new->left = interval->left; |
| 435 new->left->parent = new; | |
| 436 interval->left = new; | |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
437 new->total_length = new_length + LEFT_TOTAL_LENGTH (new); |
| 1157 | 438 |
| 439 return new; | |
| 440 } | |
| 441 | |
| 1164 | 442 /* Find the interval containing text position POSITION in the text |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
443 represented by the interval tree TREE. POSITION is a buffer |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
444 position; the earliest position is 1. If POSITION is at the end of |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
445 the buffer, return the interval containing the last character. |
| 1157 | 446 |
| 1164 | 447 The `position' field, which is a cache of an interval's position, |
| 448 is updated in the interval found. Other functions (e.g., next_interval) | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
449 will update this cache based on the result of find_interval. */ |
| 1164 | 450 |
| 451 INLINE INTERVAL | |
| 1157 | 452 find_interval (tree, position) |
| 453 register INTERVAL tree; | |
| 454 register int position; | |
| 455 { | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
456 /* The distance from the left edge of the subtree at TREE |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
457 to POSITION. */ |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
458 register int relative_position = position - BEG; |
| 1157 | 459 |
| 460 if (NULL_INTERVAL_P (tree)) | |
| 461 return NULL_INTERVAL; | |
| 462 | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
463 if (relative_position > TOTAL_LENGTH (tree)) |
| 1157 | 464 abort (); /* Paranoia */ |
| 465 | |
| 466 while (1) | |
| 467 { | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
468 if (relative_position < LEFT_TOTAL_LENGTH (tree)) |
| 1157 | 469 { |
| 470 tree = tree->left; | |
| 471 } | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
472 else if (! NULL_RIGHT_CHILD (tree) |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
473 && relative_position >= (TOTAL_LENGTH (tree) |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
474 - RIGHT_TOTAL_LENGTH (tree))) |
| 1157 | 475 { |
| 476 relative_position -= (TOTAL_LENGTH (tree) | |
| 477 - RIGHT_TOTAL_LENGTH (tree)); | |
| 478 tree = tree->right; | |
| 479 } | |
| 480 else | |
| 481 { | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
482 tree->position = |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
483 (position - relative_position /* the left edge of *tree */ |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
484 + LEFT_TOTAL_LENGTH (tree)); /* the left edge of this interval */ |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
485 |
| 1157 | 486 return tree; |
| 487 } | |
| 488 } | |
| 489 } | |
| 490 | |
| 491 /* Find the succeeding interval (lexicographically) to INTERVAL. | |
| 1164 | 492 Sets the `position' field based on that of INTERVAL (see |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
493 find_interval). */ |
| 1157 | 494 |
| 495 INTERVAL | |
| 496 next_interval (interval) | |
| 497 register INTERVAL interval; | |
| 498 { | |
| 499 register INTERVAL i = interval; | |
| 500 register int next_position; | |
| 501 | |
| 502 if (NULL_INTERVAL_P (i)) | |
| 503 return NULL_INTERVAL; | |
| 504 next_position = interval->position + LENGTH (interval); | |
| 505 | |
| 506 if (! NULL_RIGHT_CHILD (i)) | |
| 507 { | |
| 508 i = i->right; | |
| 509 while (! NULL_LEFT_CHILD (i)) | |
| 510 i = i->left; | |
| 511 | |
| 512 i->position = next_position; | |
| 513 return i; | |
| 514 } | |
| 515 | |
| 516 while (! NULL_PARENT (i)) | |
| 517 { | |
| 518 if (AM_LEFT_CHILD (i)) | |
| 519 { | |
| 520 i = i->parent; | |
| 521 i->position = next_position; | |
| 522 return i; | |
| 523 } | |
| 524 | |
| 525 i = i->parent; | |
| 526 } | |
| 527 | |
| 528 return NULL_INTERVAL; | |
| 529 } | |
| 530 | |
| 531 /* Find the preceding interval (lexicographically) to INTERVAL. | |
| 1164 | 532 Sets the `position' field based on that of INTERVAL (see |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
533 find_interval). */ |
| 1157 | 534 |
| 535 INTERVAL | |
| 536 previous_interval (interval) | |
| 537 register INTERVAL interval; | |
| 538 { | |
| 539 register INTERVAL i; | |
| 540 register position_of_previous; | |
| 541 | |
| 542 if (NULL_INTERVAL_P (interval)) | |
| 543 return NULL_INTERVAL; | |
| 544 | |
| 545 if (! NULL_LEFT_CHILD (interval)) | |
| 546 { | |
| 547 i = interval->left; | |
| 548 while (! NULL_RIGHT_CHILD (i)) | |
| 549 i = i->right; | |
| 550 | |
| 551 i->position = interval->position - LENGTH (i); | |
| 552 return i; | |
| 553 } | |
| 554 | |
| 555 i = interval; | |
| 556 while (! NULL_PARENT (i)) | |
| 557 { | |
| 558 if (AM_RIGHT_CHILD (i)) | |
| 559 { | |
| 560 i = i->parent; | |
| 561 | |
| 562 i->position = interval->position - LENGTH (i); | |
| 563 return i; | |
| 564 } | |
| 565 i = i->parent; | |
| 566 } | |
| 567 | |
| 568 return NULL_INTERVAL; | |
| 569 } | |
| 570 | |
| 1164 | 571 #if 0 |
| 1157 | 572 /* Traverse a path down the interval tree TREE to the interval |
| 573 containing POSITION, adjusting all nodes on the path for | |
| 574 an addition of LENGTH characters. Insertion between two intervals | |
| 575 (i.e., point == i->position, where i is second interval) means | |
| 576 text goes into second interval. | |
| 577 | |
| 578 Modifications are needed to handle the hungry bits -- after simply | |
| 579 finding the interval at position (don't add length going down), | |
| 580 if it's the beginning of the interval, get the previous interval | |
| 581 and check the hugry bits of both. Then add the length going back up | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
582 to the root. */ |
| 1157 | 583 |
| 584 static INTERVAL | |
| 585 adjust_intervals_for_insertion (tree, position, length) | |
| 586 INTERVAL tree; | |
| 587 int position, length; | |
| 588 { | |
| 589 register int relative_position; | |
| 590 register INTERVAL this; | |
| 591 | |
| 592 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */ | |
| 593 abort (); | |
| 594 | |
| 595 /* If inserting at point-max of a buffer, that position | |
| 596 will be out of range */ | |
| 597 if (position > TOTAL_LENGTH (tree)) | |
| 598 position = TOTAL_LENGTH (tree); | |
| 599 relative_position = position; | |
| 600 this = tree; | |
| 601 | |
| 602 while (1) | |
| 603 { | |
| 604 if (relative_position <= LEFT_TOTAL_LENGTH (this)) | |
| 605 { | |
| 606 this->total_length += length; | |
| 607 this = this->left; | |
| 608 } | |
| 609 else if (relative_position > (TOTAL_LENGTH (this) | |
| 610 - RIGHT_TOTAL_LENGTH (this))) | |
| 611 { | |
| 612 relative_position -= (TOTAL_LENGTH (this) | |
| 613 - RIGHT_TOTAL_LENGTH (this)); | |
| 614 this->total_length += length; | |
| 615 this = this->right; | |
| 616 } | |
| 617 else | |
| 618 { | |
| 619 /* If we are to use zero-length intervals as buffer pointers, | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
620 then this code will have to change. */ |
| 1157 | 621 this->total_length += length; |
| 622 this->position = LEFT_TOTAL_LENGTH (this) | |
| 623 + position - relative_position + 1; | |
| 624 return tree; | |
| 625 } | |
| 626 } | |
| 627 } | |
| 1164 | 628 #endif |
| 629 | |
| 630 /* Effect an adjustment corresponding to the addition of LENGTH characters | |
| 631 of text. Do this by finding the interval containing POSITION in the | |
| 632 interval tree TREE, and then adjusting all of it's ancestors by adding | |
| 633 LENGTH to them. | |
| 634 | |
| 635 If POSITION is the first character of an interval, meaning that point | |
| 636 is actually between the two intervals, make the new text belong to | |
| 637 the interval which is "sticky". | |
| 638 | |
| 1189 | 639 If both intervals are "sticky", then make them belong to the left-most |
| 1164 | 640 interval. Another possibility would be to create a new interval for |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
641 this text, and make it have the merged properties of both ends. */ |
| 1164 | 642 |
| 643 static INTERVAL | |
| 644 adjust_intervals_for_insertion (tree, position, length) | |
| 645 INTERVAL tree; | |
| 646 int position, length; | |
| 647 { | |
| 648 register INTERVAL i; | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
649 register INTERVAL temp; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
650 int eobp = 0; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
651 |
| 1164 | 652 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */ |
| 653 abort (); | |
| 654 | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
655 /* If inserting at point-max of a buffer, that position will be out |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
656 of range. Remember that buffer positions are 1-based. */ |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
657 if (position >= BEG + TOTAL_LENGTH (tree)){ |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
658 position = BEG + TOTAL_LENGTH (tree); |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
659 eobp = 1; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
660 } |
| 1164 | 661 |
| 662 i = find_interval (tree, position); | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
663 |
|
4638
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
664 /* If in middle of an interval which is not sticky either way, |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
665 we must not just give its properties to the insertion. |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
666 So split this interval at the insertion point. */ |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
667 if (! (position == i->position || eobp) |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
668 && END_NONSTICKY_P (i) |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
669 && ! FRONT_STICKY_P (i)) |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
670 { |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
671 temp = split_interval_right (i, position - i->position); |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
672 copy_properties (i, temp); |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
673 i = temp; |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
674 } |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
675 |
| 1164 | 676 /* If we are positioned between intervals, check the stickiness of |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
677 both of them. We have to do this too, if we are at BEG or Z. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
678 if (position == i->position || eobp) |
| 1164 | 679 { |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
680 register INTERVAL prev; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
681 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
682 if (position == BEG) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
683 prev = 0; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
684 else if (eobp) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
685 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
686 prev = i; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
687 i = 0; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
688 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
689 else |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
690 prev = previous_interval (i); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
691 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
692 /* Even if we are positioned between intervals, we default |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
693 to the left one if it exists. We extend it now and split |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
694 off a part later, if stickyness demands it. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
695 for (temp = prev ? prev : i; ! NULL_INTERVAL_P (temp); temp = temp->parent) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
696 temp->total_length += length; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
697 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
698 /* If at least one interval has sticky properties, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
699 we check the stickyness property by property. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
700 if (END_NONSTICKY_P (prev) || FRONT_STICKY_P (i)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
701 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
702 Lisp_Object pleft = NULL_INTERVAL_P (prev) ? Qnil : prev->plist; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
703 Lisp_Object pright = NULL_INTERVAL_P (i) ? Qnil : i->plist; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
704 struct interval newi; |
| 1164 | 705 |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
706 newi.plist = merge_properties_sticky (pleft, pright); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
707 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
708 if(! prev) /* i.e. position == BEG */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
709 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
710 if (! intervals_equal (i, &newi)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
711 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
712 i = split_interval_left (i, length); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
713 i->plist = newi.plist; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
714 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
715 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
716 else if (! intervals_equal (prev, &newi)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
717 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
718 prev = split_interval_right (prev, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
719 position - prev->position); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
720 prev->plist = newi.plist; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
721 if (! NULL_INTERVAL_P (i) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
722 && intervals_equal (prev, i)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
723 merge_interval_right (prev); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
724 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
725 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
726 /* We will need to update the cache here later. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
727 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
728 else if (! prev && ! NILP (i->plist)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
729 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
730 /* Just split off a new interval at the left. |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
731 Since I wasn't front-sticky, the empty plist is ok. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
732 i = split_interval_left (i, length); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
733 } |
| 1164 | 734 } |
| 735 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
736 /* Otherwise just extend the interval. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
737 else |
| 1164 | 738 { |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
739 for (temp = i; ! NULL_INTERVAL_P (temp); temp = temp->parent) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
740 temp->total_length += length; |
| 1164 | 741 } |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
742 |
| 1164 | 743 return tree; |
| 744 } | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
745 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
746 Lisp_Object |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
747 merge_properties_sticky (pleft, pright) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
748 Lisp_Object pleft, pright; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
749 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
750 register Lisp_Object props = Qnil, front = Qnil, rear = Qnil; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
751 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
752 Lisp_Object lfront = textget (pleft, Qfront_sticky); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
753 Lisp_Object lrear = textget (pleft, Qrear_nonsticky); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
754 Lisp_Object rfront = textget (pright, Qfront_sticky); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
755 Lisp_Object rrear = textget (pright, Qrear_nonsticky); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
756 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
757 register Lisp_Object tail1, tail2, sym; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
758 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
759 /* Go through each element of PLEFT. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
760 for (tail1 = pleft; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
761 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
762 sym = Fcar (tail1); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
763 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
764 /* Sticky properties get special treatment. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
765 if (EQ (sym, Qrear_nonsticky) || EQ (sym, Qfront_sticky)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
766 continue; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
767 |
|
4638
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
768 if (CONSP (lrear) ? NILP (Fmemq (sym, lrear)) : NILP (lrear)) |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
769 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
770 /* rear-sticky is dominant, we needn't search in PRIGHT. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
771 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
772 props = Fcons (sym, Fcons (Fcar (Fcdr (tail1)), props)); |
|
4638
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
773 if ((CONSP (lfront) || NILP (lfront)) |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
774 && ! NILP (Fmemq (sym, lfront))) |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
775 front = Fcons (sym, front); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
776 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
777 else |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
778 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
779 /* Go through PRIGHT, looking for sym. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
780 for (tail2 = pright; ! NILP (tail2); tail2 = Fcdr (Fcdr (tail2))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
781 if (EQ (sym, Fcar (tail2))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
782 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
783 |
|
4638
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
784 if (CONSP (rfront) |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
785 ? ! NILP (Fmemq (sym, rfront)) : ! NILP (rfront)) |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
786 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
787 /* Nonsticky at the left and sticky at the right, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
788 so take the right one. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
789 props = Fcons (sym, Fcons (Fcar (Fcdr (tail2)), props)); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
790 front = Fcons (sym, front); |
|
4638
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
791 if ((CONSP (rrear) || NILP (rrear)) |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
792 && ! NILP (Fmemq (sym, rrear))) |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
793 rear = Fcons (sym, rear); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
794 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
795 break; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
796 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
797 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
798 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
799 /* Now let's see what to keep from PRIGHT. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
800 for (tail2 = pright; ! NILP (tail2); tail2 = Fcdr (Fcdr (tail2))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
801 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
802 sym = Fcar (tail2); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
803 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
804 /* Sticky properties get special treatment. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
805 if (EQ (sym, Qrear_nonsticky) || EQ (sym, Qfront_sticky)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
806 continue; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
807 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
808 /* If it ain't sticky, we don't take it. */ |
|
4638
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
809 if (CONSP (rfront) |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
810 ? NILP (Fmemq (sym, rfront)) : NILP (rfront)) |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
811 continue; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
812 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
813 /* If sym is in PLEFT we already got it. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
814 for (tail1 = pleft; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
815 if (EQ (sym, Fcar (tail1))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
816 break; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
817 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
818 if (NILP (tail1)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
819 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
820 props = Fcons (sym, Fcons (Fcar (Fcdr (tail2)), props)); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
821 front = Fcons (sym, front); |
|
4638
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
822 if ((CONSP (rrear) || NILP (rrear)) |
|
3872f91770fc
(adjust_intervals_for_insertion): If inserting in middle
Richard M. Stallman <rms@gnu.org>
parents:
4383
diff
changeset
|
823 && ! NILP (Fmemq (sym, rrear))) |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
824 rear = Fcons (sym, rear); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
825 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
826 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
827 if (! NILP (front)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
828 props = Fcons (Qfront_sticky, Fcons (front, props)); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
829 if (! NILP (rear)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
830 props = Fcons (Qrear_nonsticky, Fcons (rear, props)); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
831 return props; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
832 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
833 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
834 |
| 1157 | 835 |
| 1164 | 836 /* Delete an node I from its interval tree by merging its subtrees |
| 837 into one subtree which is then returned. Caller is responsible for | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
838 storing the resulting subtree into its parent. */ |
| 1157 | 839 |
| 840 static INTERVAL | |
| 841 delete_node (i) | |
| 842 register INTERVAL i; | |
| 843 { | |
| 844 register INTERVAL migrate, this; | |
| 845 register int migrate_amt; | |
| 846 | |
| 847 if (NULL_INTERVAL_P (i->left)) | |
| 848 return i->right; | |
| 849 if (NULL_INTERVAL_P (i->right)) | |
| 850 return i->left; | |
| 851 | |
| 852 migrate = i->left; | |
| 853 migrate_amt = i->left->total_length; | |
| 854 this = i->right; | |
| 855 this->total_length += migrate_amt; | |
| 856 while (! NULL_INTERVAL_P (this->left)) | |
| 857 { | |
| 858 this = this->left; | |
| 859 this->total_length += migrate_amt; | |
| 860 } | |
| 861 this->left = migrate; | |
| 862 migrate->parent = this; | |
| 863 | |
| 864 return i->right; | |
| 865 } | |
| 866 | |
| 867 /* Delete interval I from its tree by calling `delete_node' | |
| 868 and properly connecting the resultant subtree. | |
| 869 | |
| 870 I is presumed to be empty; that is, no adjustments are made | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
871 for the length of I. */ |
| 1157 | 872 |
| 873 void | |
| 874 delete_interval (i) | |
| 875 register INTERVAL i; | |
| 876 { | |
| 877 register INTERVAL parent; | |
| 878 int amt = LENGTH (i); | |
| 879 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
880 if (amt > 0) /* Only used on zero-length intervals now. */ |
| 1157 | 881 abort (); |
| 882 | |
| 883 if (ROOT_INTERVAL_P (i)) | |
| 884 { | |
| 885 Lisp_Object owner = (Lisp_Object) i->parent; | |
| 886 parent = delete_node (i); | |
| 887 if (! NULL_INTERVAL_P (parent)) | |
| 888 parent->parent = (INTERVAL) owner; | |
| 889 | |
| 890 if (XTYPE (owner) == Lisp_Buffer) | |
| 891 XBUFFER (owner)->intervals = parent; | |
| 892 else if (XTYPE (owner) == Lisp_String) | |
| 893 XSTRING (owner)->intervals = parent; | |
| 894 else | |
| 895 abort (); | |
| 896 | |
| 897 return; | |
| 898 } | |
| 899 | |
| 900 parent = i->parent; | |
| 901 if (AM_LEFT_CHILD (i)) | |
| 902 { | |
| 903 parent->left = delete_node (i); | |
| 904 if (! NULL_INTERVAL_P (parent->left)) | |
| 905 parent->left->parent = parent; | |
| 906 } | |
| 907 else | |
| 908 { | |
| 909 parent->right = delete_node (i); | |
| 910 if (! NULL_INTERVAL_P (parent->right)) | |
| 911 parent->right->parent = parent; | |
| 912 } | |
| 913 } | |
| 914 | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
915 /* Find the interval in TREE corresponding to the relative position |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
916 FROM and delete as much as possible of AMOUNT from that interval. |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
917 Return the amount actually deleted, and if the interval was |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
918 zeroed-out, delete that interval node from the tree. |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
919 |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
920 Note that FROM is actually origin zero, aka relative to the |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
921 leftmost edge of tree. This is appropriate since we call ourselves |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
922 recursively on subtrees. |
| 1157 | 923 |
| 1189 | 924 Do this by recursing down TREE to the interval in question, and |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
925 deleting the appropriate amount of text. */ |
| 1157 | 926 |
| 927 static int | |
| 928 interval_deletion_adjustment (tree, from, amount) | |
| 929 register INTERVAL tree; | |
| 930 register int from, amount; | |
| 931 { | |
| 932 register int relative_position = from; | |
| 933 | |
| 934 if (NULL_INTERVAL_P (tree)) | |
| 935 return 0; | |
| 936 | |
| 937 /* Left branch */ | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
938 if (relative_position < LEFT_TOTAL_LENGTH (tree)) |
| 1157 | 939 { |
| 940 int subtract = interval_deletion_adjustment (tree->left, | |
| 941 relative_position, | |
| 942 amount); | |
| 943 tree->total_length -= subtract; | |
| 944 return subtract; | |
| 945 } | |
| 946 /* Right branch */ | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
947 else if (relative_position >= (TOTAL_LENGTH (tree) |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
948 - RIGHT_TOTAL_LENGTH (tree))) |
| 1157 | 949 { |
| 950 int subtract; | |
| 951 | |
| 952 relative_position -= (tree->total_length | |
| 953 - RIGHT_TOTAL_LENGTH (tree)); | |
| 954 subtract = interval_deletion_adjustment (tree->right, | |
| 955 relative_position, | |
| 956 amount); | |
| 957 tree->total_length -= subtract; | |
| 958 return subtract; | |
| 959 } | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
960 /* Here -- this node. */ |
| 1157 | 961 else |
| 962 { | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
963 /* How much can we delete from this interval? */ |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
964 int my_amount = ((tree->total_length |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
965 - RIGHT_TOTAL_LENGTH (tree)) |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
966 - relative_position); |
| 1157 | 967 |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
968 if (amount > my_amount) |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
969 amount = my_amount; |
| 1157 | 970 |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
971 tree->total_length -= amount; |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
972 if (LENGTH (tree) == 0) |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
973 delete_interval (tree); |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
974 |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
975 return amount; |
| 1157 | 976 } |
| 977 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
978 /* Never reach here. */ |
| 1157 | 979 } |
| 980 | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
981 /* Effect the adjustments necessary to the interval tree of BUFFER to |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
982 correspond to the deletion of LENGTH characters from that buffer |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
983 text. The deletion is effected at position START (which is a |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
984 buffer position, i.e. origin 1). */ |
| 1189 | 985 |
| 1157 | 986 static void |
| 987 adjust_intervals_for_deletion (buffer, start, length) | |
| 988 struct buffer *buffer; | |
| 989 int start, length; | |
| 990 { | |
| 991 register int left_to_delete = length; | |
| 992 register INTERVAL tree = buffer->intervals; | |
| 993 register int deleted; | |
| 994 | |
| 995 if (NULL_INTERVAL_P (tree)) | |
| 996 return; | |
| 997 | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
998 if (start > BEG + TOTAL_LENGTH (tree) |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
999 || start + length > BEG + TOTAL_LENGTH (tree)) |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1000 abort (); |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1001 |
| 1157 | 1002 if (length == TOTAL_LENGTH (tree)) |
| 1003 { | |
| 1004 buffer->intervals = NULL_INTERVAL; | |
| 1005 return; | |
| 1006 } | |
| 1007 | |
| 1008 if (ONLY_INTERVAL_P (tree)) | |
| 1009 { | |
| 1010 tree->total_length -= length; | |
| 1011 return; | |
| 1012 } | |
| 1013 | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1014 if (start > BEG + TOTAL_LENGTH (tree)) |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1015 start = BEG + TOTAL_LENGTH (tree); |
| 1157 | 1016 while (left_to_delete > 0) |
| 1017 { | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1018 left_to_delete -= interval_deletion_adjustment (tree, start - 1, |
| 1157 | 1019 left_to_delete); |
| 1020 tree = buffer->intervals; | |
| 1021 if (left_to_delete == tree->total_length) | |
| 1022 { | |
| 1023 buffer->intervals = NULL_INTERVAL; | |
| 1024 return; | |
| 1025 } | |
| 1026 } | |
| 1027 } | |
| 1028 | |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3490
diff
changeset
|
1029 /* Make the adjustments necessary to the interval tree of BUFFER to |
| 1189 | 1030 represent an addition or deletion of LENGTH characters starting |
| 1031 at position START. Addition or deletion is indicated by the sign | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1032 of LENGTH. */ |
| 1157 | 1033 |
| 1034 INLINE void | |
| 1035 offset_intervals (buffer, start, length) | |
| 1036 struct buffer *buffer; | |
| 1037 int start, length; | |
| 1038 { | |
| 1039 if (NULL_INTERVAL_P (buffer->intervals) || length == 0) | |
| 1040 return; | |
| 1041 | |
| 1042 if (length > 0) | |
| 1043 adjust_intervals_for_insertion (buffer->intervals, start, length); | |
| 1044 else | |
| 1045 adjust_intervals_for_deletion (buffer, start, -length); | |
| 1046 } | |
| 1211 | 1047 |
| 1048 /* Merge interval I with its lexicographic successor. The resulting | |
| 1049 interval is returned, and has the properties of the original | |
| 1050 successor. The properties of I are lost. I is removed from the | |
| 1051 interval tree. | |
| 1157 | 1052 |
| 1211 | 1053 IMPORTANT: |
| 1054 The caller must verify that this is not the last (rightmost) | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1055 interval. */ |
| 1211 | 1056 |
| 1057 INTERVAL | |
| 1058 merge_interval_right (i) | |
| 1059 register INTERVAL i; | |
| 1060 { | |
| 1061 register int absorb = LENGTH (i); | |
| 1062 register INTERVAL successor; | |
| 1063 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1064 /* Zero out this interval. */ |
| 1211 | 1065 i->total_length -= absorb; |
| 1066 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1067 /* Find the succeeding interval. */ |
| 1211 | 1068 if (! NULL_RIGHT_CHILD (i)) /* It's below us. Add absorb |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1069 as we descend. */ |
| 1211 | 1070 { |
| 1071 successor = i->right; | |
| 1072 while (! NULL_LEFT_CHILD (successor)) | |
| 1073 { | |
| 1074 successor->total_length += absorb; | |
| 1075 successor = successor->left; | |
| 1076 } | |
| 1077 | |
| 1078 successor->total_length += absorb; | |
| 1079 delete_interval (i); | |
| 1080 return successor; | |
| 1081 } | |
| 1082 | |
| 1083 successor = i; | |
| 1084 while (! NULL_PARENT (successor)) /* It's above us. Subtract as | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1085 we ascend. */ |
| 1211 | 1086 { |
| 1087 if (AM_LEFT_CHILD (successor)) | |
| 1088 { | |
| 1089 successor = successor->parent; | |
| 1090 delete_interval (i); | |
| 1091 return successor; | |
| 1092 } | |
| 1093 | |
| 1094 successor = successor->parent; | |
| 1095 successor->total_length -= absorb; | |
| 1096 } | |
| 1097 | |
| 1098 /* This must be the rightmost or last interval and cannot | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1099 be merged right. The caller should have known. */ |
| 1211 | 1100 abort (); |
| 1101 } | |
| 1102 | |
| 1103 /* Merge interval I with its lexicographic predecessor. The resulting | |
| 1104 interval is returned, and has the properties of the original predecessor. | |
| 1105 The properties of I are lost. Interval node I is removed from the tree. | |
| 1106 | |
| 1107 IMPORTANT: | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1108 The caller must verify that this is not the first (leftmost) interval. */ |
| 1211 | 1109 |
| 1110 INTERVAL | |
| 1111 merge_interval_left (i) | |
| 1112 register INTERVAL i; | |
| 1113 { | |
| 1114 register int absorb = LENGTH (i); | |
| 1115 register INTERVAL predecessor; | |
| 1116 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1117 /* Zero out this interval. */ |
| 1211 | 1118 i->total_length -= absorb; |
| 1119 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1120 /* Find the preceding interval. */ |
| 1211 | 1121 if (! NULL_LEFT_CHILD (i)) /* It's below us. Go down, |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1122 adding ABSORB as we go. */ |
| 1211 | 1123 { |
| 1124 predecessor = i->left; | |
| 1125 while (! NULL_RIGHT_CHILD (predecessor)) | |
| 1126 { | |
| 1127 predecessor->total_length += absorb; | |
| 1128 predecessor = predecessor->right; | |
| 1129 } | |
| 1130 | |
| 1131 predecessor->total_length += absorb; | |
| 1132 delete_interval (i); | |
| 1133 return predecessor; | |
| 1134 } | |
| 1135 | |
| 1136 predecessor = i; | |
| 1137 while (! NULL_PARENT (predecessor)) /* It's above us. Go up, | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1138 subtracting ABSORB. */ |
| 1211 | 1139 { |
| 1140 if (AM_RIGHT_CHILD (predecessor)) | |
| 1141 { | |
| 1142 predecessor = predecessor->parent; | |
| 1143 delete_interval (i); | |
| 1144 return predecessor; | |
| 1145 } | |
| 1146 | |
| 1147 predecessor = predecessor->parent; | |
| 1148 predecessor->total_length -= absorb; | |
| 1149 } | |
| 1150 | |
| 1151 /* This must be the leftmost or first interval and cannot | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1152 be merged left. The caller should have known. */ |
| 1211 | 1153 abort (); |
| 1154 } | |
| 1155 | |
| 1189 | 1156 /* Make an exact copy of interval tree SOURCE which descends from |
| 1157 PARENT. This is done by recursing through SOURCE, copying | |
| 1158 the current interval and its properties, and then adjusting | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1159 the pointers of the copy. */ |
| 1189 | 1160 |
| 1157 | 1161 static INTERVAL |
| 1162 reproduce_tree (source, parent) | |
| 1163 INTERVAL source, parent; | |
| 1164 { | |
| 1165 register INTERVAL t = make_interval (); | |
| 1166 | |
| 1167 bcopy (source, t, INTERVAL_SIZE); | |
| 1168 copy_properties (source, t); | |
| 1169 t->parent = parent; | |
| 1170 if (! NULL_LEFT_CHILD (source)) | |
| 1171 t->left = reproduce_tree (source->left, t); | |
| 1172 if (! NULL_RIGHT_CHILD (source)) | |
| 1173 t->right = reproduce_tree (source->right, t); | |
| 1174 | |
| 1175 return t; | |
| 1176 } | |
| 1177 | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1178 #if 0 |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1179 /* Nobody calls this. Perhaps it's a vestige of an earlier design. */ |
|
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1180 |
| 1189 | 1181 /* Make a new interval of length LENGTH starting at START in the |
| 1182 group of intervals INTERVALS, which is actually an interval tree. | |
| 1183 Returns the new interval. | |
| 1184 | |
| 1185 Generate an error if the new positions would overlap an existing | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1186 interval. */ |
| 1189 | 1187 |
| 1157 | 1188 static INTERVAL |
| 1189 make_new_interval (intervals, start, length) | |
| 1190 INTERVAL intervals; | |
| 1191 int start, length; | |
| 1192 { | |
| 1193 INTERVAL slot; | |
| 1194 | |
| 1195 slot = find_interval (intervals, start); | |
| 1196 if (start + length > slot->position + LENGTH (slot)) | |
| 1197 error ("Interval would overlap"); | |
| 1198 | |
| 1199 if (start == slot->position && length == LENGTH (slot)) | |
| 1200 return slot; | |
| 1201 | |
| 1202 if (slot->position == start) | |
| 1203 { | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1204 /* New right node. */ |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1205 split_interval_right (slot, length); |
| 1157 | 1206 return slot; |
| 1207 } | |
| 1208 | |
| 1209 if (slot->position + LENGTH (slot) == start + length) | |
| 1210 { | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1211 /* New left node. */ |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1212 split_interval_left (slot, LENGTH (slot) - length); |
| 1157 | 1213 return slot; |
| 1214 } | |
| 1215 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1216 /* Convert interval SLOT into three intervals. */ |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1217 split_interval_left (slot, start - slot->position); |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1218 split_interval_right (slot, length); |
| 1157 | 1219 return slot; |
| 1220 } | |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1221 #endif |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1222 |
| 1211 | 1223 /* Insert the intervals of SOURCE into BUFFER at POSITION. |
|
5169
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1224 LENGTH is the length of the text in SOURCE. |
| 1157 | 1225 |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1226 This is used in insdel.c when inserting Lisp_Strings into the |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1227 buffer. The text corresponding to SOURCE is already in the buffer |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1228 when this is called. The intervals of new tree are a copy of those |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1229 belonging to the string being inserted; intervals are never |
|
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1230 shared. |
| 1157 | 1231 |
|
5169
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1232 If the inserted text had no intervals associated, and we don't |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1233 want to inherit the surrounding text's properties, this function |
| 1157 | 1234 simply returns -- offset_intervals should handle placing the |
| 1164 | 1235 text in the correct interval, depending on the sticky bits. |
| 1157 | 1236 |
| 1237 If the inserted text had properties (intervals), then there are two | |
| 1238 cases -- either insertion happened in the middle of some interval, | |
| 1239 or between two intervals. | |
| 1240 | |
| 1241 If the text goes into the middle of an interval, then new | |
| 1242 intervals are created in the middle with only the properties of | |
| 1243 the new text, *unless* the macro MERGE_INSERTIONS is true, in | |
| 1244 which case the new text has the union of its properties and those | |
| 1245 of the text into which it was inserted. | |
| 1246 | |
| 1247 If the text goes between two intervals, then if neither interval | |
| 1164 | 1248 had its appropriate sticky property set (front_sticky, rear_sticky), |
| 1249 the new text has only its properties. If one of the sticky properties | |
| 1157 | 1250 is set, then the new text "sticks" to that region and its properties |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3490
diff
changeset
|
1251 depend on merging as above. If both the preceding and succeeding |
| 1164 | 1252 intervals to the new text are "sticky", then the new text retains |
| 1253 only its properties, as if neither sticky property were set. Perhaps | |
| 1157 | 1254 we should consider merging all three sets of properties onto the new |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1255 text... */ |
| 1157 | 1256 |
| 1257 void | |
|
5169
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1258 graft_intervals_into_buffer (source, position, length, buffer, inherit) |
| 1211 | 1259 INTERVAL source; |
|
5169
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1260 int position, length; |
| 1211 | 1261 struct buffer *buffer; |
|
4718
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1262 int inherit; |
| 1157 | 1263 { |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1264 register INTERVAL under, over, this, prev; |
| 1211 | 1265 register INTERVAL tree = buffer->intervals; |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1266 int middle; |
| 1157 | 1267 |
| 1268 /* If the new text has no properties, it becomes part of whatever | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1269 interval it was inserted into. */ |
| 1211 | 1270 if (NULL_INTERVAL_P (source)) |
|
5169
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1271 { |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1272 Lisp_Object buf; |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1273 if (!inherit) |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1274 { |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1275 XSET (buf, Lisp_Buffer, buffer); |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1276 Fset_text_properties (make_number (position), |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1277 make_number (position + length), |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1278 Qnil, buf); |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1279 } |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1280 return; |
|
d040c1a8ccbe
(graft_intervals_into_buffer): New arg LENGTH.
Richard M. Stallman <rms@gnu.org>
parents:
4962
diff
changeset
|
1281 } |
| 1157 | 1282 |
| 1283 if (NULL_INTERVAL_P (tree)) | |
| 1284 { | |
| 1285 /* The inserted text constitutes the whole buffer, so | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1286 simply copy over the interval structure. */ |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1287 if ((BUF_Z (buffer) - BUF_BEG (buffer)) == TOTAL_LENGTH (source)) |
| 1157 | 1288 { |
|
4223
b044f6d3c4cb
(graft_intervals_into_buffer): When TREE is null,
Richard M. Stallman <rms@gnu.org>
parents:
4135
diff
changeset
|
1289 Lisp_Object buf; |
|
b044f6d3c4cb
(graft_intervals_into_buffer): When TREE is null,
Richard M. Stallman <rms@gnu.org>
parents:
4135
diff
changeset
|
1290 XSET (buf, Lisp_Buffer, buffer); |
|
b044f6d3c4cb
(graft_intervals_into_buffer): When TREE is null,
Richard M. Stallman <rms@gnu.org>
parents:
4135
diff
changeset
|
1291 buffer->intervals = reproduce_tree (source, buf); |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1292 /* Explicitly free the old tree here. */ |
| 1157 | 1293 |
| 1294 return; | |
| 1295 } | |
| 1296 | |
| 1297 /* Create an interval tree in which to place a copy | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1298 of the intervals of the inserted string. */ |
| 1157 | 1299 { |
| 1307 | 1300 Lisp_Object buf; |
| 1301 XSET (buf, Lisp_Buffer, buffer); | |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1302 tree = create_root_interval (buf); |
| 1157 | 1303 } |
| 1304 } | |
|
4718
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1305 else if (TOTAL_LENGTH (tree) == TOTAL_LENGTH (source)) |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1306 /* If the buffer contains only the new string, but |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1307 there was already some interval tree there, then it may be |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1308 some zero length intervals. Eventually, do something clever |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1309 about inserting properly. For now, just waste the old intervals. */ |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1310 { |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1311 buffer->intervals = reproduce_tree (source, tree->parent); |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1312 /* Explicitly free the old tree here. */ |
| 1157 | 1313 |
|
4718
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1314 return; |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1315 } |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1316 /* Paranoia -- the text has already been added, so this buffer |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1317 should be of non-zero length. */ |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1318 else if (TOTAL_LENGTH (tree) == 0) |
|
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1319 abort (); |
| 1157 | 1320 |
| 1321 this = under = find_interval (tree, position); | |
| 1322 if (NULL_INTERVAL_P (under)) /* Paranoia */ | |
| 1323 abort (); | |
| 1211 | 1324 over = find_interval (source, 1); |
| 1157 | 1325 |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1326 /* Here for insertion in the middle of an interval. |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1327 Split off an equivalent interval to the right, |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1328 then don't bother with it any more. */ |
| 1157 | 1329 |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1330 if (position > under->position) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1331 { |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1332 INTERVAL end_unchanged |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1333 = split_interval_left (this, position - under->position); |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1334 copy_properties (under, end_unchanged); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1335 under->position = position; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1336 prev = 0; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1337 middle = 1; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1338 } |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1339 else |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1340 { |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1341 prev = previous_interval (under); |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1342 if (prev && !END_NONSTICKY_P (prev)) |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1343 prev = 0; |
| 1157 | 1344 } |
| 1345 | |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1346 /* Insertion is now at beginning of UNDER. */ |
| 1157 | 1347 |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1348 /* The inserted text "sticks" to the interval `under', |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1349 which means it gets those properties. |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1350 The properties of under are the result of |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1351 adjust_intervals_for_insertion, so stickyness has |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1352 already been taken care of. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1353 |
| 1157 | 1354 while (! NULL_INTERVAL_P (over)) |
| 1355 { | |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1356 if (LENGTH (over) + 1 < LENGTH (under)) |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1357 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1358 this = split_interval_left (under, LENGTH (over)); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1359 copy_properties (under, this); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1360 } |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1361 else |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1362 this = under; |
| 1157 | 1363 copy_properties (over, this); |
|
4718
a05b833e61c4
(graft_intervals_into_buffer): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1364 if (inherit) |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1365 merge_properties (over, this); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1366 else |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1367 copy_properties (over, this); |
| 1157 | 1368 over = next_interval (over); |
| 1369 } | |
| 1370 | |
| 1211 | 1371 buffer->intervals = balance_intervals (buffer->intervals); |
| 1157 | 1372 return; |
| 1373 } | |
| 1374 | |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1375 /* Get the value of property PROP from PLIST, |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1376 which is the plist of an interval. |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1377 We check for direct properties and for categories with property PROP. */ |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1378 |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1379 Lisp_Object |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1380 textget (plist, prop) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1381 Lisp_Object plist; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1382 register Lisp_Object prop; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1383 { |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1384 register Lisp_Object tail, fallback; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1385 fallback = Qnil; |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1386 |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1387 for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail))) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1388 { |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1389 register Lisp_Object tem; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1390 tem = Fcar (tail); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1391 if (EQ (prop, tem)) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1392 return Fcar (Fcdr (tail)); |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1393 if (EQ (tem, Qcategory)) |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1394 fallback = Fget (Fcar (Fcdr (tail)), prop); |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1395 } |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1396 |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1397 return fallback; |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1398 } |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1399 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1400 /* Get the value of property PROP from PLIST, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1401 which is the plist of an interval. |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1402 We check for direct properties only! */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1403 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1404 Lisp_Object |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1405 textget_direct (plist, prop) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1406 Lisp_Object plist; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1407 register Lisp_Object prop; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1408 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1409 register Lisp_Object tail; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1410 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1411 for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1412 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1413 if (EQ (prop, Fcar (tail))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1414 return Fcar (Fcdr (tail)); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1415 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1416 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1417 return Qnil; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1418 } |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1419 |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1420 /* Set point in BUFFER to POSITION. If the target position is |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1421 before an invisible character which is not displayed with a special glyph, |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1422 move back to an ok place to display. */ |
| 1157 | 1423 |
| 1424 void | |
| 1425 set_point (position, buffer) | |
| 1426 register int position; | |
| 1427 register struct buffer *buffer; | |
| 1428 { | |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1429 register INTERVAL to, from, toprev, fromprev, target; |
| 1157 | 1430 int buffer_point; |
| 1431 register Lisp_Object obj; | |
| 1432 int backwards = (position < BUF_PT (buffer)) ? 1 : 0; | |
| 1211 | 1433 int old_position = buffer->text.pt; |
| 1157 | 1434 |
| 1435 if (position == buffer->text.pt) | |
| 1436 return; | |
| 1437 | |
|
2779
857bb0f59668
* intervals.c (set_point): Check for point out of bounds before
Jim Blandy <jimb@redhat.com>
parents:
2090
diff
changeset
|
1438 /* Check this now, before checking if the buffer has any intervals. |
|
857bb0f59668
* intervals.c (set_point): Check for point out of bounds before
Jim Blandy <jimb@redhat.com>
parents:
2090
diff
changeset
|
1439 That way, we can catch conditions which break this sanity check |
|
857bb0f59668
* intervals.c (set_point): Check for point out of bounds before
Jim Blandy <jimb@redhat.com>
parents:
2090
diff
changeset
|
1440 whether or not there are intervals in the buffer. */ |
|
857bb0f59668
* intervals.c (set_point): Check for point out of bounds before
Jim Blandy <jimb@redhat.com>
parents:
2090
diff
changeset
|
1441 if (position > BUF_Z (buffer) || position < BUF_BEG (buffer)) |
|
857bb0f59668
* intervals.c (set_point): Check for point out of bounds before
Jim Blandy <jimb@redhat.com>
parents:
2090
diff
changeset
|
1442 abort (); |
|
857bb0f59668
* intervals.c (set_point): Check for point out of bounds before
Jim Blandy <jimb@redhat.com>
parents:
2090
diff
changeset
|
1443 |
| 1157 | 1444 if (NULL_INTERVAL_P (buffer->intervals)) |
| 1445 { | |
| 1446 buffer->text.pt = position; | |
| 1447 return; | |
| 1448 } | |
| 1449 | |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1450 /* Set TO to the interval containing the char after POSITION, |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1451 and TOPREV to the interval containing the char before POSITION. |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1452 Either one may be null. They may be equal. */ |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1453 to = find_interval (buffer->intervals, position); |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1454 if (position == BUF_BEGV (buffer)) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1455 toprev = 0; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1456 else if (to->position == position) |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1457 toprev = previous_interval (to); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1458 else |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1459 toprev = to; |
| 1211 | 1460 |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1461 buffer_point = (BUF_PT (buffer) == BUF_ZV (buffer) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1462 ? BUF_ZV (buffer) - 1 |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1463 : BUF_PT (buffer)); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1464 |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1465 /* Set FROM to the interval containing the char after PT, |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1466 and FROMPREV to the interval containing the char before PT. |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1467 Either one may be null. They may be equal. */ |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1468 /* We could cache this and save time. */ |
| 1157 | 1469 from = find_interval (buffer->intervals, buffer_point); |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1470 if (buffer_point == BUF_BEGV (buffer)) |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1471 fromprev = 0; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1472 else if (from->position == BUF_PT (buffer)) |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1473 fromprev = previous_interval (from); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1474 else if (buffer_point != BUF_PT (buffer)) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1475 fromprev = from, from = 0; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1476 else |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1477 fromprev = from; |
| 1157 | 1478 |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1479 /* Moving within an interval. */ |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1480 if (to == from && toprev == fromprev && INTERVAL_VISIBLE_P (to)) |
| 1157 | 1481 { |
| 1482 buffer->text.pt = position; | |
| 1483 return; | |
| 1484 } | |
| 1485 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1486 /* If the new position is before an invisible character |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1487 that has an `invisible' property of value `hidden', |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1488 move forward over all such. */ |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1489 while (! NULL_INTERVAL_P (to) |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1490 && EQ (textget (to->plist, Qinvisible), Qhidden) |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1491 && ! DISPLAY_INVISIBLE_GLYPH (to)) |
| 1157 | 1492 { |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1493 toprev = to; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1494 to = next_interval (to); |
|
3734
5ada670e1fd8
(set_point): When moving over invis chars,
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1495 if (NULL_INTERVAL_P (to)) |
|
5ada670e1fd8
(set_point): When moving over invis chars,
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1496 position = BUF_ZV (buffer); |
|
5ada670e1fd8
(set_point): When moving over invis chars,
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1497 else |
|
5ada670e1fd8
(set_point): When moving over invis chars,
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1498 position = to->position; |
| 1157 | 1499 } |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1500 |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1501 buffer->text.pt = position; |
| 1157 | 1502 |
| 1288 | 1503 /* We run point-left and point-entered hooks here, iff the |
| 1504 two intervals are not equivalent. These hooks take | |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1505 (old_point, new_point) as arguments. */ |
|
4243
23fe7f6c9ae4
(set_point): Test Vinhibit_point_motion_hooks.
Richard M. Stallman <rms@gnu.org>
parents:
4223
diff
changeset
|
1506 if (NILP (Vinhibit_point_motion_hooks) |
|
23fe7f6c9ae4
(set_point): Test Vinhibit_point_motion_hooks.
Richard M. Stallman <rms@gnu.org>
parents:
4223
diff
changeset
|
1507 && (! intervals_equal (from, to) |
|
23fe7f6c9ae4
(set_point): Test Vinhibit_point_motion_hooks.
Richard M. Stallman <rms@gnu.org>
parents:
4223
diff
changeset
|
1508 || ! intervals_equal (fromprev, toprev))) |
| 1211 | 1509 { |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1510 Lisp_Object leave_after, leave_before, enter_after, enter_before; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1511 |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1512 if (fromprev) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1513 leave_after = textget (fromprev->plist, Qpoint_left); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1514 else |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1515 leave_after = Qnil; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1516 if (from) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1517 leave_before = textget (from->plist, Qpoint_left); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1518 else |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1519 leave_before = Qnil; |
| 1211 | 1520 |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1521 if (toprev) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1522 enter_after = textget (toprev->plist, Qpoint_entered); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1523 else |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1524 enter_after = Qnil; |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1525 if (to) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1526 enter_before = textget (to->plist, Qpoint_entered); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1527 else |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1528 enter_before = Qnil; |
| 1211 | 1529 |
|
1964
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1530 if (! EQ (leave_before, enter_before) && !NILP (leave_before)) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1531 call2 (leave_before, old_position, position); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1532 if (! EQ (leave_after, enter_after) && !NILP (leave_after)) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1533 call2 (leave_after, old_position, position); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1534 |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1535 if (! EQ (enter_before, leave_before) && !NILP (enter_before)) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1536 call2 (enter_before, old_position, position); |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1537 if (! EQ (enter_after, leave_after) && !NILP (enter_after)) |
|
e6c49ff3a53c
(intervals_equal): Handle one arg null and other not.
Richard M. Stallman <rms@gnu.org>
parents:
1958
diff
changeset
|
1538 call2 (enter_after, old_position, position); |
| 1211 | 1539 } |
| 1157 | 1540 } |
| 1541 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1542 /* Set point temporarily, without checking any text properties. */ |
| 1157 | 1543 |
| 1211 | 1544 INLINE void |
| 1545 temp_set_point (position, buffer) | |
| 1546 int position; | |
| 1547 struct buffer *buffer; | |
| 1548 { | |
| 1549 buffer->text.pt = position; | |
| 1550 } | |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1551 |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1552 /* Return the proper local map for position POSITION in BUFFER. |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1553 Use the map specified by the local-map property, if any. |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1554 Otherwise, use BUFFER's local map. */ |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1555 |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1556 Lisp_Object |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1557 get_local_map (position, buffer) |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1558 register int position; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1559 register struct buffer *buffer; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1560 { |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1561 register INTERVAL interval; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1562 Lisp_Object prop, tem; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1563 |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1564 if (NULL_INTERVAL_P (buffer->intervals)) |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1565 return current_buffer->keymap; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1566 |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1567 /* Perhaps we should just change `position' to the limit. */ |
|
2090
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1568 if (position > BUF_Z (buffer) || position < BUF_BEG (buffer)) |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1569 abort (); |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1570 |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1571 interval = find_interval (buffer->intervals, position); |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1572 prop = textget (interval->plist, Qlocal_map); |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1573 if (NILP (prop)) |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1574 return current_buffer->keymap; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1575 |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1576 /* Use the local map only if it is valid. */ |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1577 tem = Fkeymapp (prop); |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1578 if (!NILP (tem)) |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1579 return prop; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1580 |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1581 return current_buffer->keymap; |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1582 } |
|
c7e1308a7184
(set_point): Check invisibility of following character, not previous character.
Richard M. Stallman <rms@gnu.org>
parents:
2052
diff
changeset
|
1583 |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1584 /* Call the modification hook functions in LIST, each with START and END. */ |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1585 |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1586 static void |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1587 call_mod_hooks (list, start, end) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1588 Lisp_Object list, start, end; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1589 { |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1590 struct gcpro gcpro1; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1591 GCPRO1 (list); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1592 while (!NILP (list)) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1593 { |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1594 call2 (Fcar (list), start, end); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1595 list = Fcdr (list); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1596 } |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1597 UNGCPRO; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1598 } |
| 1211 | 1599 |
| 1600 /* Check for read-only intervals and signal an error if we find one. | |
| 1601 Then check for any modification hooks in the range START up to | |
| 1602 (but not including) TO. Create a list of all these hooks in | |
| 1603 lexicographic order, eliminating consecutive extra copies of the | |
| 1604 same hook. Then call those hooks in order, with START and END - 1 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1605 as arguments. */ |
| 1157 | 1606 |
| 1607 void | |
| 1608 verify_interval_modification (buf, start, end) | |
| 1609 struct buffer *buf; | |
| 1610 int start, end; | |
| 1611 { | |
| 1612 register INTERVAL intervals = buf->intervals; | |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1613 register INTERVAL i, prev; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1614 Lisp_Object hooks; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1615 register Lisp_Object prev_mod_hooks; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1616 Lisp_Object mod_hooks; |
| 1211 | 1617 struct gcpro gcpro1; |
| 1157 | 1618 |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1619 hooks = Qnil; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1620 prev_mod_hooks = Qnil; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1621 mod_hooks = Qnil; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1622 |
| 1157 | 1623 if (NULL_INTERVAL_P (intervals)) |
| 1624 return; | |
| 1625 | |
| 1626 if (start > end) | |
| 1627 { | |
| 1628 int temp = start; | |
| 1629 start = end; | |
| 1630 end = temp; | |
| 1631 } | |
| 1632 | |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1633 /* For an insert operation, check the two chars around the position. */ |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1634 if (start == end) |
| 1157 | 1635 { |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1636 INTERVAL prev; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1637 Lisp_Object before, after; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1638 |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1639 /* Set I to the interval containing the char after START, |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1640 and PREV to the interval containing the char before START. |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1641 Either one may be null. They may be equal. */ |
|
4005
da8962f65741
* intervals.c (find_interval): Doc fixes, computation of
Jim Blandy <jimb@redhat.com>
parents:
3998
diff
changeset
|
1642 i = find_interval (intervals, start); |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1643 |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1644 if (start == BUF_BEGV (buf)) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1645 prev = 0; |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1646 else if (i->position == start) |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1647 prev = previous_interval (i); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1648 else if (i->position < start) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1649 prev = i; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1650 if (start == BUF_ZV (buf)) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1651 i = 0; |
| 1157 | 1652 |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1653 /* If Vinhibit_read_only is set and is not a list, we can |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1654 skip the read_only checks. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1655 if (NILP (Vinhibit_read_only) || CONSP (Vinhibit_read_only)) |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1656 { |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1657 /* If I and PREV differ we need to check for the read-only |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1658 property together with its stickyness. If either I or |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1659 PREV are 0, this check is all we need. |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1660 We have to take special care, since read-only may be |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1661 indirectly defined via the category property. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1662 if (i != prev) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1663 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1664 if (! NULL_INTERVAL_P (i)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1665 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1666 after = textget (i->plist, Qread_only); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1667 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1668 /* If interval I is read-only and read-only is |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1669 front-sticky, inhibit insertion. |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1670 Check for read-only as well as category. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1671 if (! NILP (after) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1672 && NILP (Fmemq (after, Vinhibit_read_only)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1673 && (! NILP (Fmemq (Qread_only, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1674 textget (i->plist, Qfront_sticky))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1675 || (NILP (textget_direct (i->plist, Qread_only)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1676 && ! NILP (Fmemq (Qcategory, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1677 textget (i->plist, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1678 Qfront_sticky)))))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1679 error ("Attempt to insert within read-only text"); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1680 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1681 else |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1682 after = Qnil; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1683 if (! NULL_INTERVAL_P (prev)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1684 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1685 before = textget (prev->plist, Qread_only); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1686 |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1687 /* If interval PREV is read-only and read-only isn't |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1688 rear-nonsticky, inhibit insertion. |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1689 Check for read-only as well as category. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1690 if (! NILP (before) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1691 && NILP (Fmemq (before, Vinhibit_read_only)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1692 && NILP (Fmemq (Qread_only, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1693 textget (prev->plist, Qrear_nonsticky))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1694 && (! NILP (textget_direct (prev->plist,Qread_only)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1695 || NILP (Fmemq (Qcategory, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1696 textget (prev->plist, |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1697 Qrear_nonsticky))))) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1698 error ("Attempt to insert within read-only text"); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1699 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1700 else |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1701 before = Qnil; |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1702 } |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1703 else if (! NULL_INTERVAL_P (i)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1704 before = after = textget (i->plist, Qread_only); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1705 if (! NULL_INTERVAL_P (i) && ! NULL_INTERVAL_P (prev)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1706 { |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1707 /* If I and PREV differ, neither of them has a sticky |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1708 read-only property. It only remains to check, whether |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1709 they have a common read-only property. */ |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1710 if (! NILP (before) && EQ (before, after)) |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1711 error ("Attempt to insert within read-only text"); |
|
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1712 } |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1713 } |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1714 |
|
4066
bb9478383bde
(verify_interval_modification):
Richard M. Stallman <rms@gnu.org>
parents:
4005
diff
changeset
|
1715 /* Run both insert hooks (just once if they're the same). */ |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1716 if (!NULL_INTERVAL_P (prev)) |
|
4080
8200d631e3f3
(verify_interval_modification): Use Qinsert_in_front_hooks and
Richard M. Stallman <rms@gnu.org>
parents:
4066
diff
changeset
|
1717 prev_mod_hooks = textget (prev->plist, Qinsert_behind_hooks); |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1718 if (!NULL_INTERVAL_P (i)) |
|
4080
8200d631e3f3
(verify_interval_modification): Use Qinsert_in_front_hooks and
Richard M. Stallman <rms@gnu.org>
parents:
4066
diff
changeset
|
1719 mod_hooks = textget (i->plist, Qinsert_in_front_hooks); |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1720 GCPRO1 (mod_hooks); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1721 if (! NILP (prev_mod_hooks)) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1722 call_mod_hooks (prev_mod_hooks, make_number (start), |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1723 make_number (end)); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1724 UNGCPRO; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1725 if (! NILP (mod_hooks) && ! EQ (mod_hooks, prev_mod_hooks)) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1726 call_mod_hooks (mod_hooks, make_number (start), make_number (end)); |
| 1157 | 1727 } |
| 1728 else | |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1729 { |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1730 /* Loop over intervals on or next to START...END, |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1731 collecting their hooks. */ |
| 1157 | 1732 |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1733 i = find_interval (intervals, start); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1734 do |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1735 { |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1736 if (! INTERVAL_WRITABLE_P (i)) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1737 error ("Attempt to modify read-only text"); |
| 1211 | 1738 |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1739 mod_hooks = textget (i->plist, Qmodification_hooks); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1740 if (! NILP (mod_hooks) && ! EQ (mod_hooks, prev_mod_hooks)) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1741 { |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1742 hooks = Fcons (mod_hooks, hooks); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1743 prev_mod_hooks = mod_hooks; |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1744 } |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1745 |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1746 i = next_interval (i); |
| 1211 | 1747 } |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1748 /* Keep going thru the interval containing the char before END. */ |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1749 while (! NULL_INTERVAL_P (i) && i->position < end); |
| 1157 | 1750 |
|
2052
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1751 GCPRO1 (hooks); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1752 hooks = Fnreverse (hooks); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1753 while (! EQ (hooks, Qnil)) |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1754 { |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1755 call_mod_hooks (Fcar (hooks), make_number (start), |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1756 make_number (end)); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1757 hooks = Fcdr (hooks); |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1758 } |
|
48c83a34c005
(verify_interval_modification): Handle insertions
Richard M. Stallman <rms@gnu.org>
parents:
1964
diff
changeset
|
1759 UNGCPRO; |
| 1211 | 1760 } |
| 1157 | 1761 } |
| 1762 | |
| 1763 /* Balance an interval node if the amount of text in its left and right | |
| 1764 subtrees differs by more than the percentage specified by | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1765 `interval-balance-threshold'. */ |
| 1157 | 1766 |
| 1767 static INTERVAL | |
| 1768 balance_an_interval (i) | |
| 1769 INTERVAL i; | |
| 1770 { | |
| 1771 register int total_children_size = (LEFT_TOTAL_LENGTH (i) | |
| 1772 + RIGHT_TOTAL_LENGTH (i)); | |
| 1773 register int threshold = (XFASTINT (interval_balance_threshold) | |
| 1774 * (total_children_size / 100)); | |
| 1775 | |
|
3490
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1776 /* Balance within each side. */ |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1777 balance_intervals (i->left); |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1778 balance_intervals (i->right); |
| 1157 | 1779 |
| 1780 if (LEFT_TOTAL_LENGTH (i) > RIGHT_TOTAL_LENGTH (i) | |
| 1781 && (LEFT_TOTAL_LENGTH (i) - RIGHT_TOTAL_LENGTH (i)) > threshold) | |
|
3490
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1782 { |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1783 i = rotate_right (i); |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1784 /* If that made it unbalanced the other way, take it back. */ |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1785 if (RIGHT_TOTAL_LENGTH (i) > LEFT_TOTAL_LENGTH (i) |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1786 && (RIGHT_TOTAL_LENGTH (i) - LEFT_TOTAL_LENGTH (i)) > threshold) |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1787 return rotate_left (i); |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1788 return i; |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1789 } |
| 1157 | 1790 |
|
3490
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1791 if (RIGHT_TOTAL_LENGTH (i) > LEFT_TOTAL_LENGTH (i) |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1792 && (RIGHT_TOTAL_LENGTH (i) - LEFT_TOTAL_LENGTH (i)) > threshold) |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1793 { |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1794 i = rotate_left (i); |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1795 if (LEFT_TOTAL_LENGTH (i) > RIGHT_TOTAL_LENGTH (i) |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1796 && (LEFT_TOTAL_LENGTH (i) - RIGHT_TOTAL_LENGTH (i)) > threshold) |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1797 return rotate_right (i); |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1798 return i; |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1799 } |
| 1157 | 1800 |
| 1801 return i; | |
| 1802 } | |
| 1803 | |
| 1804 /* Balance the interval tree TREE. Balancing is by weight | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1805 (the amount of text). */ |
| 1157 | 1806 |
| 1807 INTERVAL | |
| 1808 balance_intervals (tree) | |
| 1809 register INTERVAL tree; | |
| 1810 { | |
| 1811 register INTERVAL new_tree; | |
| 1812 | |
| 1813 if (NULL_INTERVAL_P (tree)) | |
| 1814 return NULL_INTERVAL; | |
| 1815 | |
| 1816 new_tree = tree; | |
| 1817 do | |
| 1818 { | |
| 1819 tree = new_tree; | |
| 1820 new_tree = balance_an_interval (new_tree); | |
| 1821 } | |
| 1822 while (new_tree != tree); | |
| 1823 | |
| 1824 return new_tree; | |
| 1825 } | |
| 1826 | |
| 1211 | 1827 /* Produce an interval tree reflecting the intervals in |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1828 TREE from START to START + LENGTH. */ |
| 1157 | 1829 |
|
1316
f09c5c6563b8
* intervals.c: `copy_intervals()' no longer static.
Joseph Arceneaux <jla@gnu.org>
parents:
1307
diff
changeset
|
1830 INTERVAL |
| 1157 | 1831 copy_intervals (tree, start, length) |
| 1832 INTERVAL tree; | |
| 1833 int start, length; | |
| 1834 { | |
| 1835 register INTERVAL i, new, t; | |
|
3490
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1836 register int got, prevlen; |
| 1157 | 1837 |
| 1838 if (NULL_INTERVAL_P (tree) || length <= 0) | |
| 1839 return NULL_INTERVAL; | |
| 1840 | |
| 1841 i = find_interval (tree, start); | |
| 1842 if (NULL_INTERVAL_P (i) || LENGTH (i) == 0) | |
| 1843 abort (); | |
| 1844 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1845 /* If there is only one interval and it's the default, return nil. */ |
| 1157 | 1846 if ((start - i->position + 1 + length) < LENGTH (i) |
| 1847 && DEFAULT_INTERVAL_P (i)) | |
| 1848 return NULL_INTERVAL; | |
| 1849 | |
| 1850 new = make_interval (); | |
| 1851 new->position = 1; | |
| 1852 got = (LENGTH (i) - (start - i->position)); | |
| 1211 | 1853 new->total_length = length; |
| 1157 | 1854 copy_properties (i, new); |
| 1855 | |
| 1856 t = new; | |
|
3490
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1857 prevlen = got; |
| 1157 | 1858 while (got < length) |
| 1859 { | |
| 1860 i = next_interval (i); | |
|
4135
84ea8ebc9858
* intervals.c (split_interval_left, split_interval_right): Change
Jim Blandy <jimb@redhat.com>
parents:
4080
diff
changeset
|
1861 t = split_interval_right (t, prevlen); |
| 1157 | 1862 copy_properties (i, t); |
|
3490
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1863 prevlen = LENGTH (i); |
|
07b454ddc666
(copy_intervals): Don't adjust total_length at the end.
Richard M. Stallman <rms@gnu.org>
parents:
3333
diff
changeset
|
1864 got += prevlen; |
| 1157 | 1865 } |
| 1866 | |
| 1867 return balance_intervals (new); | |
| 1868 } | |
| 1869 | |
|
4383
d4a36c1669e6
(adjust_intervals_for_insertion): Handle insertion
Richard M. Stallman <rms@gnu.org>
parents:
4243
diff
changeset
|
1870 /* Give STRING the properties of BUFFER from POSITION to LENGTH. */ |
| 1157 | 1871 |
| 1288 | 1872 INLINE void |
| 1157 | 1873 copy_intervals_to_string (string, buffer, position, length) |
| 1874 Lisp_Object string, buffer; | |
| 1875 int position, length; | |
| 1876 { | |
| 1877 INTERVAL interval_copy = copy_intervals (XBUFFER (buffer)->intervals, | |
| 1878 position, length); | |
| 1879 if (NULL_INTERVAL_P (interval_copy)) | |
| 1880 return; | |
| 1881 | |
| 1882 interval_copy->parent = (INTERVAL) string; | |
| 1883 XSTRING (string)->intervals = interval_copy; | |
| 1884 } | |
|
1301
5a27062b8b7f
* intervals.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1288
diff
changeset
|
1885 |
|
5a27062b8b7f
* intervals.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1288
diff
changeset
|
1886 #endif /* USE_TEXT_PROPERTIES */ |
