keymaps.texi small fix for bug#13684
[emacs.git] / src / intervals.h
blobcded8c0abb271227e7c434ea03fba04fa593b118
1 /* Definitions and global variables for intervals.
2 Copyright (C) 1993-1994, 2000-2013 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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.
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.
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/>. */
19 #include "dispextern.h"
21 INLINE_HEADER_BEGIN
22 #ifndef INTERVALS_INLINE
23 # define INTERVALS_INLINE INLINE
24 #endif
26 /* Basic data type for use of intervals. */
28 struct interval
30 /* The first group of entries deal with the tree structure. */
32 ptrdiff_t total_length; /* Length of myself and both children. */
33 ptrdiff_t position; /* Cache of interval's character position. */
34 /* This field is usually updated
35 simultaneously with an interval
36 traversal, there is no guarantee
37 that it is valid for a random
38 interval. */
39 struct interval *left; /* Intervals which precede me. */
40 struct interval *right; /* Intervals which succeed me. */
42 /* Parent in the tree, or the Lisp_Object containing this interval tree. */
43 union
45 struct interval *interval;
46 Lisp_Object obj;
47 } up;
48 unsigned int up_obj : 1;
50 unsigned gcmarkbit : 1;
52 /* The remaining components are `properties' of the interval.
53 The first four are duplicates for things which can be on the list,
54 for purposes of speed. */
56 unsigned int write_protect : 1; /* Non-zero means can't modify. */
57 unsigned int visible : 1; /* Zero means don't display. */
58 unsigned int front_sticky : 1; /* Non-zero means text inserted just
59 before this interval goes into it. */
60 unsigned int rear_sticky : 1; /* Likewise for just after it. */
61 Lisp_Object plist; /* Other properties. */
64 /* These are macros for dealing with the interval tree. */
66 /* True if this interval has no right child. */
67 #define NULL_RIGHT_CHILD(i) ((i)->right == NULL)
69 /* True if this interval has no left child. */
70 #define NULL_LEFT_CHILD(i) ((i)->left == NULL)
72 /* True if this interval has no parent. */
73 #define NULL_PARENT(i) ((i)->up_obj || (i)->up.interval == 0)
75 /* True if this interval is the left child of some other interval. */
76 #define AM_LEFT_CHILD(i) \
77 (! NULL_PARENT (i) && INTERVAL_PARENT (i)->left == (i))
79 /* True if this interval is the right child of some other interval. */
80 #define AM_RIGHT_CHILD(i) \
81 (! NULL_PARENT (i) && INTERVAL_PARENT (i)->right == (i))
83 /* True if this interval has no children. */
84 #define LEAF_INTERVAL_P(i) ((i)->left == NULL && (i)->right == NULL)
86 /* True if this interval has no parent and is therefore the root. */
87 #define ROOT_INTERVAL_P(i) (NULL_PARENT (i))
89 /* True if this interval is the only interval in the interval tree. */
90 #define ONLY_INTERVAL_P(i) (ROOT_INTERVAL_P ((i)) && LEAF_INTERVAL_P ((i)))
92 /* True if this interval has both left and right children. */
93 #define BOTH_KIDS_P(i) ((i)->left != NULL && (i)->right != NULL)
95 /* The total size of all text represented by this interval and all its
96 children in the tree. This is zero if the interval is null. */
97 #define TOTAL_LENGTH(i) ((i) == NULL ? 0 : (i)->total_length)
99 /* The size of text represented by this interval alone. */
100 #define LENGTH(i) ((i) == NULL ? 0 : (TOTAL_LENGTH ((i)) \
101 - TOTAL_LENGTH ((i)->right) \
102 - TOTAL_LENGTH ((i)->left)))
104 /* The position of the character just past the end of I. Note that
105 the position cache i->position must be valid for this to work. */
106 #define INTERVAL_LAST_POS(i) ((i)->position + LENGTH ((i)))
108 /* The total size of the left subtree of this interval. */
109 #define LEFT_TOTAL_LENGTH(i) ((i)->left ? (i)->left->total_length : 0)
111 /* The total size of the right subtree of this interval. */
112 #define RIGHT_TOTAL_LENGTH(i) ((i)->right ? (i)->right->total_length : 0)
114 /* These macros are for dealing with the interval properties. */
116 /* True if this is a default interval, which is the same as being null
117 or having no properties. */
118 #define DEFAULT_INTERVAL_P(i) (!i || EQ ((i)->plist, Qnil))
120 /* Test what type of parent we have. Three possibilities: another
121 interval, a buffer or string object, or NULL. */
122 #define INTERVAL_HAS_PARENT(i) ((i)->up_obj == 0 && (i)->up.interval != 0)
123 #define INTERVAL_HAS_OBJECT(i) ((i)->up_obj)
125 /* Use these macros to get parent of an interval.
127 The choice of macros is dependent on the type needed. Don't add
128 casts to get around this, it will break some development work in
129 progress. */
131 #define INTERVAL_PARENT(i) \
132 (eassert ((i) != 0 && (i)->up_obj == 0), (i)->up.interval)
134 #define GET_INTERVAL_OBJECT(d,s) (eassert ((s)->up_obj == 1), (d) = (s)->up.obj)
136 /* Use these functions to set Lisp_Object
137 or pointer slots of struct interval. */
139 INTERVALS_INLINE void
140 set_interval_parent (INTERVAL i, INTERVAL parent)
142 i->up_obj = 0;
143 i->up.interval = parent;
146 INTERVALS_INLINE void
147 set_interval_plist (INTERVAL i, Lisp_Object plist)
149 i->plist = plist;
152 /* Get the parent interval, if any, otherwise a null pointer. Useful
153 for walking up to the root in a "for" loop; use this to get the
154 "next" value, and test the result to see if it's NULL. */
155 #define INTERVAL_PARENT_OR_NULL(i) \
156 (INTERVAL_HAS_PARENT (i) ? INTERVAL_PARENT (i) : 0)
158 /* Reset this interval to its vanilla, or no-property state. */
159 #define RESET_INTERVAL(i) \
161 (i)->total_length = (i)->position = 0; \
162 (i)->left = (i)->right = NULL; \
163 set_interval_parent (i, NULL); \
164 (i)->write_protect = 0; \
165 (i)->visible = 0; \
166 (i)->front_sticky = (i)->rear_sticky = 0; \
167 set_interval_plist (i, Qnil); \
170 /* Copy the cached property values of interval FROM to interval TO. */
171 #define COPY_INTERVAL_CACHE(from,to) \
173 (to)->write_protect = (from)->write_protect; \
174 (to)->visible = (from)->visible; \
175 (to)->front_sticky = (from)->front_sticky; \
176 (to)->rear_sticky = (from)->rear_sticky; \
179 /* Copy only the set bits of FROM's cache. */
180 #define MERGE_INTERVAL_CACHE(from,to) \
182 if ((from)->write_protect) (to)->write_protect = 1; \
183 if ((from)->visible) (to)->visible = 1; \
184 if ((from)->front_sticky) (to)->front_sticky = 1; \
185 if ((from)->rear_sticky) (to)->rear_sticky = 1; \
188 /* Is this interval visible? Replace later with cache access. */
189 #define INTERVAL_VISIBLE_P(i) \
190 (i && NILP (textget ((i)->plist, Qinvisible)))
192 /* Is this interval writable? Replace later with cache access. */
193 #define INTERVAL_WRITABLE_P(i) \
194 (i && (NILP (textget ((i)->plist, Qread_only)) \
195 || ((CONSP (Vinhibit_read_only) \
196 ? !NILP (Fmemq (textget ((i)->plist, Qread_only), \
197 Vinhibit_read_only)) \
198 : !NILP (Vinhibit_read_only))))) \
200 /* Macros to tell whether insertions before or after this interval
201 should stick to it. Now we have Vtext_property_default_nonsticky,
202 so these macros are unreliable now and never used. */
204 #if 0
205 #define FRONT_STICKY_P(i) \
206 (i && ! NILP (textget ((i)->plist, Qfront_sticky)))
207 #define END_NONSTICKY_P(i) \
208 (i && ! NILP (textget ((i)->plist, Qrear_nonsticky)))
209 #define FRONT_NONSTICKY_P(i) \
210 (i && ! EQ (Qt, textget ((i)->plist, Qfront_sticky)))
211 #endif
213 /* If PROP is the `invisible' property of a character,
214 this is 1 if the character should be treated as invisible,
215 and 2 if it is invisible but with an ellipsis. */
217 #define TEXT_PROP_MEANS_INVISIBLE(prop) \
218 (EQ (BVAR (current_buffer, invisibility_spec), Qt) \
219 ? !NILP (prop) \
220 : invisible_p (prop, BVAR (current_buffer, invisibility_spec)))
222 /* Declared in alloc.c. */
224 extern INTERVAL make_interval (void);
226 /* Declared in intervals.c. */
228 extern INTERVAL create_root_interval (Lisp_Object);
229 extern void copy_properties (INTERVAL, INTERVAL);
230 extern bool intervals_equal (INTERVAL, INTERVAL);
231 extern void traverse_intervals (INTERVAL, ptrdiff_t,
232 void (*) (INTERVAL, Lisp_Object),
233 Lisp_Object);
234 extern void traverse_intervals_noorder (INTERVAL,
235 void (*) (INTERVAL, Lisp_Object),
236 Lisp_Object);
237 extern INTERVAL split_interval_right (INTERVAL, ptrdiff_t);
238 extern INTERVAL split_interval_left (INTERVAL, ptrdiff_t);
239 extern INTERVAL find_interval (INTERVAL, ptrdiff_t);
240 extern INTERVAL next_interval (INTERVAL);
241 extern INTERVAL previous_interval (INTERVAL);
242 extern INTERVAL merge_interval_left (INTERVAL);
243 extern void offset_intervals (struct buffer *, ptrdiff_t, ptrdiff_t);
244 extern void graft_intervals_into_buffer (INTERVAL, ptrdiff_t, ptrdiff_t,
245 struct buffer *, bool);
246 extern void verify_interval_modification (struct buffer *,
247 ptrdiff_t, ptrdiff_t);
248 extern INTERVAL balance_intervals (INTERVAL);
249 extern void copy_intervals_to_string (Lisp_Object, struct buffer *,
250 ptrdiff_t, ptrdiff_t);
251 extern INTERVAL copy_intervals (INTERVAL, ptrdiff_t, ptrdiff_t);
252 extern bool compare_string_intervals (Lisp_Object, Lisp_Object);
253 extern Lisp_Object textget (Lisp_Object, Lisp_Object);
254 extern Lisp_Object lookup_char_property (Lisp_Object, Lisp_Object, bool);
255 extern void move_if_not_intangible (ptrdiff_t);
256 extern bool get_property_and_range (ptrdiff_t, Lisp_Object, Lisp_Object *,
257 ptrdiff_t *, ptrdiff_t *, Lisp_Object);
258 extern Lisp_Object get_local_map (ptrdiff_t, struct buffer *, Lisp_Object);
259 extern INTERVAL update_interval (INTERVAL, ptrdiff_t);
260 extern void set_intervals_multibyte (bool);
261 extern INTERVAL validate_interval_range (Lisp_Object, Lisp_Object *,
262 Lisp_Object *, int);
263 extern INTERVAL interval_of (ptrdiff_t, Lisp_Object);
265 /* Defined in xdisp.c. */
266 extern int invisible_p (Lisp_Object, Lisp_Object);
268 /* Declared in textprop.c. */
270 /* Types of hooks. */
271 extern Lisp_Object Qpoint_left;
272 extern Lisp_Object Qpoint_entered;
273 extern Lisp_Object Qmodification_hooks;
274 extern Lisp_Object Qcategory;
275 extern Lisp_Object Qlocal_map;
276 extern Lisp_Object Qkeymap;
278 /* Visual properties text (including strings) may have. */
279 extern Lisp_Object Qfont;
280 extern Lisp_Object Qinvisible, Qintangible;
282 /* Sticky properties. */
283 extern Lisp_Object Qfront_sticky, Qrear_nonsticky;
285 extern Lisp_Object copy_text_properties (Lisp_Object, Lisp_Object,
286 Lisp_Object, Lisp_Object,
287 Lisp_Object, Lisp_Object);
288 extern Lisp_Object set_text_properties (Lisp_Object, Lisp_Object,
289 Lisp_Object, Lisp_Object,
290 Lisp_Object);
291 extern void set_text_properties_1 (Lisp_Object, Lisp_Object,
292 Lisp_Object, Lisp_Object, INTERVAL);
294 Lisp_Object text_property_list (Lisp_Object, Lisp_Object, Lisp_Object,
295 Lisp_Object);
296 int add_text_properties_from_list (Lisp_Object, Lisp_Object, Lisp_Object);
297 Lisp_Object extend_property_ranges (Lisp_Object, Lisp_Object);
298 Lisp_Object get_char_property_and_overlay (Lisp_Object, Lisp_Object,
299 Lisp_Object, Lisp_Object*);
300 extern int text_property_stickiness (Lisp_Object prop, Lisp_Object pos,
301 Lisp_Object buffer);
302 extern Lisp_Object get_pos_property (Lisp_Object pos, Lisp_Object prop,
303 Lisp_Object object);
305 extern void syms_of_textprop (void);
307 #include "composite.h"
309 INLINE_HEADER_END