Fix last change of grow_mini_window.
[bpt/emacs.git] / src / intervals.h
CommitLineData
90ba40fc 1/* Definitions and global variables for intervals.
ab422c4d 2 Copyright (C) 1993-1994, 2000-2013 Free Software Foundation, Inc.
90ba40fc
JA
3
4This file is part of GNU Emacs.
5
b9b1cc14 6GNU Emacs is free software: you can redistribute it and/or modify
90ba40fc 7it under the terms of the GNU General Public License as published by
b9b1cc14
GM
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
90ba40fc
JA
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
b9b1cc14 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
90ba40fc 18
90ba40fc
JA
19#include "dispextern.h"
20
6a3d20cc
DA
21INLINE_HEADER_BEGIN
22
4a6a76d9
SM
23/* Basic data type for use of intervals. */
24
25struct interval
26{
27 /* The first group of entries deal with the tree structure. */
28
d311d28c
PE
29 ptrdiff_t total_length; /* Length of myself and both children. */
30 ptrdiff_t position; /* Cache of interval's character position. */
4a6a76d9
SM
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;
96c06863 45 bool_bf up_obj : 1;
4a6a76d9 46
96c06863 47 bool_bf gcmarkbit : 1;
4a6a76d9
SM
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
96c06863
PE
53 bool_bf write_protect : 1; /* True means can't modify. */
54 bool_bf visible : 1; /* False means don't display. */
55 bool_bf front_sticky : 1; /* True means text inserted just
4a6a76d9 56 before this interval goes into it. */
96c06863 57 bool_bf rear_sticky : 1; /* Likewise for just after it. */
cce7fefc 58 Lisp_Object plist; /* Other properties. */
4a6a76d9
SM
59};
60
b50a28de 61/* These are macros for dealing with the interval tree. */
90ba40fc 62
b50a28de 63/* True if this interval has no right child. */
77c7bcb1 64#define NULL_RIGHT_CHILD(i) ((i)->right == NULL)
90ba40fc 65
b50a28de 66/* True if this interval has no left child. */
77c7bcb1 67#define NULL_LEFT_CHILD(i) ((i)->left == NULL)
90ba40fc 68
b50a28de 69/* True if this interval has no parent. */
e0b8c689 70#define NULL_PARENT(i) ((i)->up_obj || (i)->up.interval == 0)
90ba40fc 71
b50a28de 72/* True if this interval is the left child of some other interval. */
77c7bcb1
DA
73#define AM_LEFT_CHILD(i) \
74 (! NULL_PARENT (i) && INTERVAL_PARENT (i)->left == (i))
90ba40fc 75
b50a28de 76/* True if this interval is the right child of some other interval. */
77c7bcb1
DA
77#define AM_RIGHT_CHILD(i) \
78 (! NULL_PARENT (i) && INTERVAL_PARENT (i)->right == (i))
90ba40fc 79
b50a28de 80/* True if this interval has no children. */
77c7bcb1 81#define LEAF_INTERVAL_P(i) ((i)->left == NULL && (i)->right == NULL)
90ba40fc 82
b50a28de 83/* True if this interval has no parent and is therefore the root. */
90ba40fc
JA
84#define ROOT_INTERVAL_P(i) (NULL_PARENT (i))
85
b50a28de 86/* True if this interval is the only interval in the interval tree. */
7ac78c9a 87#define ONLY_INTERVAL_P(i) (ROOT_INTERVAL_P ((i)) && LEAF_INTERVAL_P ((i)))
90ba40fc 88
b50a28de 89/* True if this interval has both left and right children. */
77c7bcb1 90#define BOTH_KIDS_P(i) ((i)->left != NULL && (i)->right != NULL)
90ba40fc
JA
91
92/* The total size of all text represented by this interval and all its
b50a28de 93 children in the tree. This is zero if the interval is null. */
77c7bcb1 94#define TOTAL_LENGTH(i) ((i) == NULL ? 0 : (i)->total_length)
90ba40fc 95
b50a28de 96/* The size of text represented by this interval alone. */
77c7bcb1
DA
97#define LENGTH(i) ((i) == NULL ? 0 : (TOTAL_LENGTH ((i)) \
98 - TOTAL_LENGTH ((i)->right) \
99 - TOTAL_LENGTH ((i)->left)))
90ba40fc 100
3fc86d4b 101/* The position of the character just past the end of I. Note that
b50a28de 102 the position cache i->position must be valid for this to work. */
3fc86d4b 103#define INTERVAL_LAST_POS(i) ((i)->position + LENGTH ((i)))
90ba40fc 104
b50a28de 105/* The total size of the left subtree of this interval. */
90ba40fc
JA
106#define LEFT_TOTAL_LENGTH(i) ((i)->left ? (i)->left->total_length : 0)
107
b50a28de 108/* The total size of the right subtree of this interval. */
90ba40fc
JA
109#define RIGHT_TOTAL_LENGTH(i) ((i)->right ? (i)->right->total_length : 0)
110
b50a28de 111/* These macros are for dealing with the interval properties. */
90ba40fc
JA
112
113/* True if this is a default interval, which is the same as being null
b50a28de 114 or having no properties. */
77c7bcb1 115#define DEFAULT_INTERVAL_P(i) (!i || EQ ((i)->plist, Qnil))
90ba40fc 116
439d5cb4 117/* Test what type of parent we have. Three possibilities: another
77c7bcb1 118 interval, a buffer or string object, or NULL. */
96c06863 119#define INTERVAL_HAS_PARENT(i) (! (i)->up_obj && (i)->up.interval != 0)
e0b8c689 120#define INTERVAL_HAS_OBJECT(i) ((i)->up_obj)
439d5cb4 121
6a3d20cc 122/* Use these macros to get parent of an interval.
439d5cb4
KR
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. */
6a3d20cc
DA
127
128#define INTERVAL_PARENT(i) \
96c06863 129 (eassert ((i) != 0 && ! (i)->up_obj), (i)->up.interval)
6a3d20cc 130
96c06863 131#define GET_INTERVAL_OBJECT(d,s) (eassert ((s)->up_obj), (d) = (s)->up.obj)
6a3d20cc
DA
132
133/* Use these functions to set Lisp_Object
134 or pointer slots of struct interval. */
135
00382e8b 136INLINE void
0c94c8d6 137set_interval_parent (INTERVAL i, INTERVAL parent)
6a3d20cc 138{
96c06863 139 i->up_obj = false;
6a3d20cc
DA
140 i->up.interval = parent;
141}
142
00382e8b 143INLINE void
0c94c8d6 144set_interval_plist (INTERVAL i, Lisp_Object plist)
6a3d20cc
DA
145{
146 i->plist = plist;
6a3d20cc 147}
439d5cb4
KR
148
149/* Get the parent interval, if any, otherwise a null pointer. Useful
150 for walking up to the root in a "for" loop; use this to get the
77c7bcb1 151 "next" value, and test the result to see if it's NULL. */
4a6a76d9
SM
152#define INTERVAL_PARENT_OR_NULL(i) \
153 (INTERVAL_HAS_PARENT (i) ? INTERVAL_PARENT (i) : 0)
439d5cb4 154
b50a28de 155/* Reset this interval to its vanilla, or no-property state. */
6a3d20cc 156#define RESET_INTERVAL(i) \
96c06863 157 do { \
6a3d20cc 158 (i)->total_length = (i)->position = 0; \
77c7bcb1 159 (i)->left = (i)->right = NULL; \
0c94c8d6 160 set_interval_parent (i, NULL); \
96c06863
PE
161 (i)->write_protect = false; \
162 (i)->visible = false; \
163 (i)->front_sticky = (i)->rear_sticky = false; \
0c94c8d6 164 set_interval_plist (i, Qnil); \
96c06863 165 } while (false)
90ba40fc 166
b50a28de 167/* Copy the cached property values of interval FROM to interval TO. */
6a3d20cc 168#define COPY_INTERVAL_CACHE(from,to) \
96c06863 169 do { \
6a3d20cc
DA
170 (to)->write_protect = (from)->write_protect; \
171 (to)->visible = (from)->visible; \
172 (to)->front_sticky = (from)->front_sticky; \
173 (to)->rear_sticky = (from)->rear_sticky; \
96c06863 174 } while (false)
90ba40fc 175
b50a28de 176/* Copy only the set bits of FROM's cache. */
96c06863
PE
177#define MERGE_INTERVAL_CACHE(from,to) \
178 do { \
179 if ((from)->write_protect) (to)->write_protect = true; \
180 if ((from)->visible) (to)->visible = true; \
181 if ((from)->front_sticky) (to)->front_sticky = true; \
182 if ((from)->rear_sticky) (to)->rear_sticky = true; \
183 } while (false)
90ba40fc 184
b50a28de 185/* Is this interval visible? Replace later with cache access. */
90ba40fc 186#define INTERVAL_VISIBLE_P(i) \
77c7bcb1 187 (i && NILP (textget ((i)->plist, Qinvisible)))
90ba40fc 188
b50a28de 189/* Is this interval writable? Replace later with cache access. */
5f8a398a 190#define INTERVAL_WRITABLE_P(i) \
77c7bcb1
DA
191 (i && (NILP (textget ((i)->plist, Qread_only)) \
192 || ((CONSP (Vinhibit_read_only) \
193 ? !NILP (Fmemq (textget ((i)->plist, Qread_only), \
194 Vinhibit_read_only)) \
195 : !NILP (Vinhibit_read_only))))) \
90ba40fc
JA
196
197/* Macros to tell whether insertions before or after this interval
77c7bcb1
DA
198 should stick to it. Now we have Vtext_property_default_nonsticky,
199 so these macros are unreliable now and never used. */
200
96c06863 201#if false
77c7bcb1
DA
202#define FRONT_STICKY_P(i) \
203 (i && ! NILP (textget ((i)->plist, Qfront_sticky)))
204#define END_NONSTICKY_P(i) \
205 (i && ! NILP (textget ((i)->plist, Qrear_nonsticky)))
206#define FRONT_NONSTICKY_P(i) \
207 (i && ! EQ (Qt, textget ((i)->plist, Qfront_sticky)))
208#endif
90ba40fc 209
47b4c04d 210/* If PROP is the `invisible' property of a character,
99776d43
SM
211 this is 1 if the character should be treated as invisible,
212 and 2 if it is invisible but with an ellipsis. */
47b4c04d 213
77c7bcb1 214#define TEXT_PROP_MEANS_INVISIBLE(prop) \
4b4deea2 215 (EQ (BVAR (current_buffer, invisibility_spec), Qt) \
77c7bcb1 216 ? !NILP (prop) \
4b4deea2 217 : invisible_p (prop, BVAR (current_buffer, invisibility_spec)))
47b4c04d 218
b50a28de 219/* Declared in alloc.c. */
90ba40fc 220
383e0970 221extern INTERVAL make_interval (void);
90ba40fc 222
b50a28de 223/* Declared in intervals.c. */
90ba40fc 224
383e0970
J
225extern INTERVAL create_root_interval (Lisp_Object);
226extern void copy_properties (INTERVAL, INTERVAL);
a08d4ba7 227extern bool intervals_equal (INTERVAL, INTERVAL);
d311d28c 228extern void traverse_intervals (INTERVAL, ptrdiff_t,
383e0970
J
229 void (*) (INTERVAL, Lisp_Object),
230 Lisp_Object);
231extern void traverse_intervals_noorder (INTERVAL,
232 void (*) (INTERVAL, Lisp_Object),
233 Lisp_Object);
d311d28c
PE
234extern INTERVAL split_interval_right (INTERVAL, ptrdiff_t);
235extern INTERVAL split_interval_left (INTERVAL, ptrdiff_t);
236extern INTERVAL find_interval (INTERVAL, ptrdiff_t);
383e0970
J
237extern INTERVAL next_interval (INTERVAL);
238extern INTERVAL previous_interval (INTERVAL);
239extern INTERVAL merge_interval_left (INTERVAL);
d311d28c
PE
240extern void offset_intervals (struct buffer *, ptrdiff_t, ptrdiff_t);
241extern void graft_intervals_into_buffer (INTERVAL, ptrdiff_t, ptrdiff_t,
a08d4ba7 242 struct buffer *, bool);
d1dfb56c 243extern void verify_interval_modification (struct buffer *,
d311d28c 244 ptrdiff_t, ptrdiff_t);
383e0970 245extern INTERVAL balance_intervals (INTERVAL);
b7982059 246extern void copy_intervals_to_string (Lisp_Object, struct buffer *,
d311d28c
PE
247 ptrdiff_t, ptrdiff_t);
248extern INTERVAL copy_intervals (INTERVAL, ptrdiff_t, ptrdiff_t);
a08d4ba7 249extern bool compare_string_intervals (Lisp_Object, Lisp_Object);
383e0970 250extern Lisp_Object textget (Lisp_Object, Lisp_Object);
a08d4ba7 251extern Lisp_Object lookup_char_property (Lisp_Object, Lisp_Object, bool);
d311d28c 252extern void move_if_not_intangible (ptrdiff_t);
a08d4ba7
PE
253extern bool get_property_and_range (ptrdiff_t, Lisp_Object, Lisp_Object *,
254 ptrdiff_t *, ptrdiff_t *, Lisp_Object);
d311d28c
PE
255extern Lisp_Object get_local_map (ptrdiff_t, struct buffer *, Lisp_Object);
256extern INTERVAL update_interval (INTERVAL, ptrdiff_t);
a08d4ba7 257extern void set_intervals_multibyte (bool);
383e0970 258extern INTERVAL validate_interval_range (Lisp_Object, Lisp_Object *,
81c23309 259 Lisp_Object *, bool);
d311d28c 260extern INTERVAL interval_of (ptrdiff_t, Lisp_Object);
d748a3db 261
b50a28de 262/* Defined in xdisp.c. */
383e0970 263extern int invisible_p (Lisp_Object, Lisp_Object);
90ba40fc 264
b50a28de 265/* Declared in textprop.c. */
90ba40fc 266
b50a28de 267/* Types of hooks. */
90ba40fc
JA
268extern Lisp_Object Qpoint_left;
269extern Lisp_Object Qpoint_entered;
1a7c673b
RS
270extern Lisp_Object Qmodification_hooks;
271extern Lisp_Object Qcategory;
272extern Lisp_Object Qlocal_map;
b4030d7b 273extern Lisp_Object Qkeymap;
90ba40fc 274
b50a28de 275/* Visual properties text (including strings) may have. */
955cbe7b
PE
276extern Lisp_Object Qfont;
277extern Lisp_Object Qinvisible, Qintangible;
90ba40fc 278
b50a28de 279/* Sticky properties. */
58943db0
RS
280extern Lisp_Object Qfront_sticky, Qrear_nonsticky;
281
383e0970
J
282extern Lisp_Object copy_text_properties (Lisp_Object, Lisp_Object,
283 Lisp_Object, Lisp_Object,
284 Lisp_Object, Lisp_Object);
285extern Lisp_Object set_text_properties (Lisp_Object, Lisp_Object,
286 Lisp_Object, Lisp_Object,
287 Lisp_Object);
288extern void set_text_properties_1 (Lisp_Object, Lisp_Object,
289 Lisp_Object, Lisp_Object, INTERVAL);
290
291Lisp_Object text_property_list (Lisp_Object, Lisp_Object, Lisp_Object,
292 Lisp_Object);
ecc0fdd4 293void add_text_properties_from_list (Lisp_Object, Lisp_Object, Lisp_Object);
383e0970
J
294Lisp_Object extend_property_ranges (Lisp_Object, Lisp_Object);
295Lisp_Object get_char_property_and_overlay (Lisp_Object, Lisp_Object,
296 Lisp_Object, Lisp_Object*);
297extern int text_property_stickiness (Lisp_Object prop, Lisp_Object pos,
298 Lisp_Object buffer);
383e0970
J
299
300extern void syms_of_textprop (void);
a5ecc8a3
KH
301
302#include "composite.h"
6a3d20cc
DA
303
304INLINE_HEADER_END