annotate src/intervals.c @ 5353:6389ed5b45ac

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