]> code.delx.au - gnu-emacs/blob - src/intervals.h
Remove unused macros from intervals.h.
[gnu-emacs] / src / intervals.h
1 /* Definitions and global variables for intervals.
2 Copyright (C) 1993-1994, 2000-2012 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19 #include "dispextern.h"
20
21 INLINE_HEADER_BEGIN
22
23 /* Basic data type for use of intervals. */
24
25 struct interval
26 {
27 /* The first group of entries deal with the tree structure. */
28
29 ptrdiff_t total_length; /* Length of myself and both children. */
30 ptrdiff_t position; /* Cache of interval's character position. */
31 /* This field is usually updated
32 simultaneously with an interval
33 traversal, there is no guarantee
34 that it is valid for a random
35 interval. */
36 struct interval *left; /* Intervals which precede me. */
37 struct interval *right; /* Intervals which succeed me. */
38
39 /* Parent in the tree, or the Lisp_Object containing this interval tree. */
40 union
41 {
42 struct interval *interval;
43 Lisp_Object obj;
44 } up;
45 unsigned int up_obj : 1;
46
47 unsigned gcmarkbit : 1;
48
49 /* The remaining components are `properties' of the interval.
50 The first four are duplicates for things which can be on the list,
51 for purposes of speed. */
52
53 unsigned int write_protect : 1; /* Non-zero means can't modify. */
54 unsigned int visible : 1; /* Zero means don't display. */
55 unsigned int front_sticky : 1; /* Non-zero means text inserted just
56 before this interval goes into it. */
57 unsigned int rear_sticky : 1; /* Likewise for just after it. */
58 Lisp_Object plist; /* Other properties. */
59 };
60
61 /* These are macros for dealing with the interval tree. */
62
63 /* True if this interval has no right child. */
64 #define NULL_RIGHT_CHILD(i) ((i)->right == NULL)
65
66 /* True if this interval has no left child. */
67 #define NULL_LEFT_CHILD(i) ((i)->left == NULL)
68
69 /* True if this interval has no parent. */
70 #define NULL_PARENT(i) ((i)->up_obj || (i)->up.interval == 0)
71
72 /* True if this interval is the left child of some other interval. */
73 #define AM_LEFT_CHILD(i) \
74 (! NULL_PARENT (i) && INTERVAL_PARENT (i)->left == (i))
75
76 /* True if this interval is the right child of some other interval. */
77 #define AM_RIGHT_CHILD(i) \
78 (! NULL_PARENT (i) && INTERVAL_PARENT (i)->right == (i))
79
80 /* True if this interval has no children. */
81 #define LEAF_INTERVAL_P(i) ((i)->left == NULL && (i)->right == NULL)
82
83 /* True if this interval has no parent and is therefore the root. */
84 #define ROOT_INTERVAL_P(i) (NULL_PARENT (i))
85
86 /* True if this interval is the only interval in the interval tree. */
87 #define ONLY_INTERVAL_P(i) (ROOT_INTERVAL_P ((i)) && LEAF_INTERVAL_P ((i)))
88
89 /* True if this interval has both left and right children. */
90 #define BOTH_KIDS_P(i) ((i)->left != NULL && (i)->right != NULL)
91
92 /* The total size of all text represented by this interval and all its
93 children in the tree. This is zero if the interval is null. */
94 #define TOTAL_LENGTH(i) ((i) == NULL ? 0 : (i)->total_length)
95
96 /* The size of text represented by this interval alone. */
97 #define LENGTH(i) ((i) == NULL ? 0 : (TOTAL_LENGTH ((i)) \
98 - TOTAL_LENGTH ((i)->right) \
99 - TOTAL_LENGTH ((i)->left)))
100
101 /* The position of the character just past the end of I. Note that
102 the position cache i->position must be valid for this to work. */
103 #define INTERVAL_LAST_POS(i) ((i)->position + LENGTH ((i)))
104
105 /* The total size of the left subtree of this interval. */
106 #define LEFT_TOTAL_LENGTH(i) ((i)->left ? (i)->left->total_length : 0)
107
108 /* The total size of the right subtree of this interval. */
109 #define RIGHT_TOTAL_LENGTH(i) ((i)->right ? (i)->right->total_length : 0)
110
111 /* These macros are for dealing with the interval properties. */
112
113 /* True if this is a default interval, which is the same as being null
114 or having no properties. */
115 #define DEFAULT_INTERVAL_P(i) (!i || EQ ((i)->plist, Qnil))
116
117 /* Test what type of parent we have. Three possibilities: another
118 interval, a buffer or string object, or NULL. */
119 #define INTERVAL_HAS_PARENT(i) ((i)->up_obj == 0 && (i)->up.interval != 0)
120 #define INTERVAL_HAS_OBJECT(i) ((i)->up_obj)
121
122 /* Use these macros to get parent of an interval.
123
124 The choice of macros is dependent on the type needed. Don't add
125 casts to get around this, it will break some development work in
126 progress. */
127
128 #define INTERVAL_PARENT(i) \
129 (eassert ((i) != 0 && (i)->up_obj == 0), (i)->up.interval)
130
131 #define GET_INTERVAL_OBJECT(d,s) (eassert ((s)->up_obj == 1), (d) = (s)->up.obj)
132
133 /* Use these functions to set Lisp_Object
134 or pointer slots of struct interval. */
135
136 LISP_INLINE void
137 interval_set_parent (INTERVAL i, INTERVAL parent)
138 {
139 i->up_obj = 0;
140 i->up.interval = parent;
141 }
142
143 LISP_INLINE void
144 interval_set_object (INTERVAL i, Lisp_Object obj)
145 {
146 eassert (BUFFERP (obj) || STRINGP (obj));
147 i->up_obj = 1;
148 i->up.obj = obj;
149 }
150
151 LISP_INLINE void
152 interval_set_left (INTERVAL i, INTERVAL left)
153 {
154 i->left = left;
155 }
156
157 LISP_INLINE void
158 interval_set_right (INTERVAL i, INTERVAL right)
159 {
160 i->right = right;
161 }
162
163 LISP_INLINE Lisp_Object
164 interval_set_plist (INTERVAL i, Lisp_Object plist)
165 {
166 i->plist = plist;
167 return plist;
168 }
169
170 /* Make the parent of D be whatever the parent of S is, regardless
171 of the type. This is used when balancing an interval tree. */
172
173 LISP_INLINE void
174 interval_copy_parent (INTERVAL d, INTERVAL s)
175 {
176 d->up = s->up;
177 d->up_obj = s->up_obj;
178 }
179
180 /* Get the parent interval, if any, otherwise a null pointer. Useful
181 for walking up to the root in a "for" loop; use this to get the
182 "next" value, and test the result to see if it's NULL. */
183 #define INTERVAL_PARENT_OR_NULL(i) \
184 (INTERVAL_HAS_PARENT (i) ? INTERVAL_PARENT (i) : 0)
185
186 /* Reset this interval to its vanilla, or no-property state. */
187 #define RESET_INTERVAL(i) \
188 { \
189 (i)->total_length = (i)->position = 0; \
190 (i)->left = (i)->right = NULL; \
191 interval_set_parent (i, NULL); \
192 (i)->write_protect = 0; \
193 (i)->visible = 0; \
194 (i)->front_sticky = (i)->rear_sticky = 0; \
195 interval_set_plist (i, Qnil); \
196 }
197
198 /* Copy the cached property values of interval FROM to interval TO. */
199 #define COPY_INTERVAL_CACHE(from,to) \
200 { \
201 (to)->write_protect = (from)->write_protect; \
202 (to)->visible = (from)->visible; \
203 (to)->front_sticky = (from)->front_sticky; \
204 (to)->rear_sticky = (from)->rear_sticky; \
205 }
206
207 /* Copy only the set bits of FROM's cache. */
208 #define MERGE_INTERVAL_CACHE(from,to) \
209 { \
210 if ((from)->write_protect) (to)->write_protect = 1; \
211 if ((from)->visible) (to)->visible = 1; \
212 if ((from)->front_sticky) (to)->front_sticky = 1; \
213 if ((from)->rear_sticky) (to)->rear_sticky = 1; \
214 }
215
216 /* Is this interval visible? Replace later with cache access. */
217 #define INTERVAL_VISIBLE_P(i) \
218 (i && NILP (textget ((i)->plist, Qinvisible)))
219
220 /* Is this interval writable? Replace later with cache access. */
221 #define INTERVAL_WRITABLE_P(i) \
222 (i && (NILP (textget ((i)->plist, Qread_only)) \
223 || ((CONSP (Vinhibit_read_only) \
224 ? !NILP (Fmemq (textget ((i)->plist, Qread_only), \
225 Vinhibit_read_only)) \
226 : !NILP (Vinhibit_read_only))))) \
227
228 /* Macros to tell whether insertions before or after this interval
229 should stick to it. Now we have Vtext_property_default_nonsticky,
230 so these macros are unreliable now and never used. */
231
232 #if 0
233 #define FRONT_STICKY_P(i) \
234 (i && ! NILP (textget ((i)->plist, Qfront_sticky)))
235 #define END_NONSTICKY_P(i) \
236 (i && ! NILP (textget ((i)->plist, Qrear_nonsticky)))
237 #define FRONT_NONSTICKY_P(i) \
238 (i && ! EQ (Qt, textget ((i)->plist, Qfront_sticky)))
239 #endif
240
241 /* If PROP is the `invisible' property of a character,
242 this is 1 if the character should be treated as invisible,
243 and 2 if it is invisible but with an ellipsis. */
244
245 #define TEXT_PROP_MEANS_INVISIBLE(prop) \
246 (EQ (BVAR (current_buffer, invisibility_spec), Qt) \
247 ? !NILP (prop) \
248 : invisible_p (prop, BVAR (current_buffer, invisibility_spec)))
249
250 /* Declared in alloc.c. */
251
252 extern INTERVAL make_interval (void);
253
254 /* Declared in intervals.c. */
255
256 extern INTERVAL create_root_interval (Lisp_Object);
257 extern void copy_properties (INTERVAL, INTERVAL);
258 extern int intervals_equal (INTERVAL, INTERVAL);
259 extern void traverse_intervals (INTERVAL, ptrdiff_t,
260 void (*) (INTERVAL, Lisp_Object),
261 Lisp_Object);
262 extern void traverse_intervals_noorder (INTERVAL,
263 void (*) (INTERVAL, Lisp_Object),
264 Lisp_Object);
265 extern INTERVAL split_interval_right (INTERVAL, ptrdiff_t);
266 extern INTERVAL split_interval_left (INTERVAL, ptrdiff_t);
267 extern INTERVAL find_interval (INTERVAL, ptrdiff_t);
268 extern INTERVAL next_interval (INTERVAL);
269 extern INTERVAL previous_interval (INTERVAL);
270 extern INTERVAL merge_interval_left (INTERVAL);
271 extern void offset_intervals (struct buffer *, ptrdiff_t, ptrdiff_t);
272 extern void graft_intervals_into_buffer (INTERVAL, ptrdiff_t, ptrdiff_t,
273 struct buffer *, int);
274 extern void verify_interval_modification (struct buffer *,
275 ptrdiff_t, ptrdiff_t);
276 extern INTERVAL balance_intervals (INTERVAL);
277 extern void copy_intervals_to_string (Lisp_Object, struct buffer *,
278 ptrdiff_t, ptrdiff_t);
279 extern INTERVAL copy_intervals (INTERVAL, ptrdiff_t, ptrdiff_t);
280 extern int compare_string_intervals (Lisp_Object, Lisp_Object);
281 extern Lisp_Object textget (Lisp_Object, Lisp_Object);
282 extern Lisp_Object lookup_char_property (Lisp_Object, Lisp_Object, int);
283 extern void move_if_not_intangible (ptrdiff_t);
284 extern int get_property_and_range (ptrdiff_t, Lisp_Object, Lisp_Object *,
285 ptrdiff_t *, ptrdiff_t *, Lisp_Object);
286 extern Lisp_Object get_local_map (ptrdiff_t, struct buffer *, Lisp_Object);
287 extern INTERVAL update_interval (INTERVAL, ptrdiff_t);
288 extern void set_intervals_multibyte (int);
289 extern INTERVAL validate_interval_range (Lisp_Object, Lisp_Object *,
290 Lisp_Object *, int);
291 extern INTERVAL interval_of (ptrdiff_t, Lisp_Object);
292
293 /* Defined in xdisp.c. */
294 extern int invisible_p (Lisp_Object, Lisp_Object);
295
296 /* Declared in textprop.c. */
297
298 /* Types of hooks. */
299 extern Lisp_Object Qpoint_left;
300 extern Lisp_Object Qpoint_entered;
301 extern Lisp_Object Qmodification_hooks;
302 extern Lisp_Object Qcategory;
303 extern Lisp_Object Qlocal_map;
304 extern Lisp_Object Qkeymap;
305
306 /* Visual properties text (including strings) may have. */
307 extern Lisp_Object Qfont;
308 extern Lisp_Object Qinvisible, Qintangible;
309
310 /* Sticky properties. */
311 extern Lisp_Object Qfront_sticky, Qrear_nonsticky;
312
313 extern Lisp_Object copy_text_properties (Lisp_Object, Lisp_Object,
314 Lisp_Object, Lisp_Object,
315 Lisp_Object, Lisp_Object);
316 extern Lisp_Object set_text_properties (Lisp_Object, Lisp_Object,
317 Lisp_Object, Lisp_Object,
318 Lisp_Object);
319 extern void set_text_properties_1 (Lisp_Object, Lisp_Object,
320 Lisp_Object, Lisp_Object, INTERVAL);
321
322 Lisp_Object text_property_list (Lisp_Object, Lisp_Object, Lisp_Object,
323 Lisp_Object);
324 int add_text_properties_from_list (Lisp_Object, Lisp_Object, Lisp_Object);
325 Lisp_Object extend_property_ranges (Lisp_Object, Lisp_Object);
326 Lisp_Object get_char_property_and_overlay (Lisp_Object, Lisp_Object,
327 Lisp_Object, Lisp_Object*);
328 extern int text_property_stickiness (Lisp_Object prop, Lisp_Object pos,
329 Lisp_Object buffer);
330 extern Lisp_Object get_pos_property (Lisp_Object pos, Lisp_Object prop,
331 Lisp_Object object);
332
333 extern void syms_of_textprop (void);
334
335 #include "composite.h"
336
337 INLINE_HEADER_END