/* Code for doing intervals.
- Copyright (C) 1993-1995, 1997-1998, 2001-2012 Free Software Foundation, Inc.
+ Copyright (C) 1993-1995, 1997-1998, 2001-2015 Free Software
+ Foundation, Inc.
This file is part of GNU Emacs.
#include <config.h>
-#define INTERVALS_INLINE EXTERN_INLINE
-
-#include <setjmp.h>
#include <intprops.h>
#include "lisp.h"
#include "intervals.h"
static Lisp_Object merge_properties_sticky (Lisp_Object, Lisp_Object);
static INTERVAL merge_interval_right (INTERVAL);
static INTERVAL reproduce_tree (INTERVAL, INTERVAL);
-static INTERVAL reproduce_tree_obj (INTERVAL, Lisp_Object);
\f
/* Utility functions for intervals. */
+/* Use these functions to set pointer slots of struct interval. */
+
+static void
+set_interval_left (INTERVAL i, INTERVAL left)
+{
+ i->left = left;
+}
+
+static void
+set_interval_right (INTERVAL i, INTERVAL right)
+{
+ i->right = right;
+}
+
+/* Make the parent of D be whatever the parent of S is, regardless
+ of the type. This is used when balancing an interval tree. */
+
+static void
+copy_interval_parent (INTERVAL d, INTERVAL s)
+{
+ d->up = s->up;
+ d->up_obj = s->up_obj;
+}
/* Create the root interval of some object, a buffer or string. */
{
new->total_length = (BUF_Z (XBUFFER (parent))
- BUF_BEG (XBUFFER (parent)));
- eassert (0 <= TOTAL_LENGTH (new));
- buffer_set_intervals (XBUFFER (parent), new);
+ eassert (TOTAL_LENGTH (new) >= 0);
+ set_buffer_intervals (XBUFFER (parent), new);
new->position = BEG;
}
else if (STRINGP (parent))
{
new->total_length = SCHARS (parent);
- eassert (0 <= TOTAL_LENGTH (new));
- string_set_intervals (parent, new);
+ eassert (TOTAL_LENGTH (new) >= 0);
+ set_string_intervals (parent, new);
new->position = 0;
}
-
- interval_set_object (new, parent);
+ eassert (LENGTH (new) > 0);
+
+ set_interval_object (new, parent);
return new;
}
-/* Make the interval TARGET have exactly the properties of SOURCE */
+/* Make the interval TARGET have exactly the properties of SOURCE. */
void
copy_properties (register INTERVAL source, register INTERVAL target)
return;
COPY_INTERVAL_CACHE (source, target);
- interval_set_plist (target, Fcopy_sequence (source->plist));
+ set_interval_plist (target, Fcopy_sequence (source->plist));
}
/* Merge the properties of interval SOURCE into the properties
if (NILP (val))
{
val = XCAR (o);
- interval_set_plist (target, Fcons (sym, Fcons (val, target->plist)));
+ set_interval_plist (target, Fcons (sym, Fcons (val, target->plist)));
}
o = XCDR (o);
}
}
-/* Return 1 if the two intervals have the same properties,
- 0 otherwise. */
+/* Return true if the two intervals have the same properties. */
-int
+bool
intervals_equal (INTERVAL i0, INTERVAL i1)
{
- register Lisp_Object i0_cdr, i0_sym;
- register Lisp_Object i1_cdr, i1_val;
+ Lisp_Object i0_cdr, i0_sym;
+ Lisp_Object i1_cdr, i1_val;
if (DEFAULT_INTERVAL_P (i0) && DEFAULT_INTERVAL_P (i1))
- return 1;
+ return true;
if (DEFAULT_INTERVAL_P (i0) || DEFAULT_INTERVAL_P (i1))
- return 0;
+ return false;
i0_cdr = i0->plist;
i1_cdr = i1->plist;
i0_sym = XCAR (i0_cdr);
i0_cdr = XCDR (i0_cdr);
if (!CONSP (i0_cdr))
- return 0; /* abort (); */
+ return false;
i1_val = i1->plist;
while (CONSP (i1_val) && !EQ (XCAR (i1_val), i0_sym))
{
i1_val = XCDR (i1_val);
if (!CONSP (i1_val))
- return 0; /* abort (); */
+ return false;
i1_val = XCDR (i1_val);
}
/* i0 has something i1 doesn't. */
if (EQ (i1_val, Qnil))
- return 0;
+ return false;
/* i0 and i1 both have sym, but it has different values in each. */
if (!CONSP (i1_val)
|| (i1_val = XCDR (i1_val), !CONSP (i1_val))
|| !EQ (XCAR (i1_val), XCAR (i0_cdr)))
- return 0;
+ return false;
i0_cdr = XCDR (i0_cdr);
i1_cdr = XCDR (i1_cdr);
if (!CONSP (i1_cdr))
- return 0; /* abort (); */
+ return false;
i1_cdr = XCDR (i1_cdr);
}
c c
*/
-static inline INTERVAL
-rotate_right (INTERVAL interval)
+static INTERVAL
+rotate_right (INTERVAL A)
{
- INTERVAL i;
- INTERVAL B = interval->left;
- ptrdiff_t old_total = interval->total_length;
+ INTERVAL B = A->left;
+ INTERVAL c = B->right;
+ ptrdiff_t old_total = A->total_length;
+
+ eassert (old_total > 0);
+ eassert (LENGTH (A) > 0);
+ eassert (LENGTH (B) > 0);
/* Deal with any Parent of A; make it point to B. */
- if (! ROOT_INTERVAL_P (interval))
+ if (! ROOT_INTERVAL_P (A))
{
- if (AM_LEFT_CHILD (interval))
- interval_set_left (INTERVAL_PARENT (interval), B);
+ if (AM_LEFT_CHILD (A))
+ set_interval_left (INTERVAL_PARENT (A), B);
else
- interval_set_right (INTERVAL_PARENT (interval), B);
+ set_interval_right (INTERVAL_PARENT (A), B);
}
- interval_copy_parent (B, interval);
+ copy_interval_parent (B, A);
- /* Make B the parent of A */
- i = B->right;
- interval_set_right (B, interval);
- interval_set_parent (interval, B);
+ /* Make B the parent of A. */
+ set_interval_right (B, A);
+ set_interval_parent (A, B);
- /* Make A point to c */
- interval_set_left (interval, i);
- if (i)
- interval_set_parent (i, interval);
+ /* Make A point to c. */
+ set_interval_left (A, c);
+ if (c)
+ set_interval_parent (c, A);
/* A's total length is decreased by the length of B and its left child. */
- interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval);
- eassert (0 <= TOTAL_LENGTH (interval));
+ A->total_length -= B->total_length - TOTAL_LENGTH (c);
+ eassert (TOTAL_LENGTH (A) > 0);
+ eassert (LENGTH (A) > 0);
/* B must have the same total length of A. */
B->total_length = old_total;
- eassert (0 <= TOTAL_LENGTH (B));
+ eassert (LENGTH (B) > 0);
return B;
}
c c
*/
-static inline INTERVAL
-rotate_left (INTERVAL interval)
+static INTERVAL
+rotate_left (INTERVAL A)
{
- INTERVAL i;
- INTERVAL B = interval->right;
- ptrdiff_t old_total = interval->total_length;
+ INTERVAL B = A->right;
+ INTERVAL c = B->left;
+ ptrdiff_t old_total = A->total_length;
+
+ eassert (old_total > 0);
+ eassert (LENGTH (A) > 0);
+ eassert (LENGTH (B) > 0);
/* Deal with any parent of A; make it point to B. */
- if (! ROOT_INTERVAL_P (interval))
+ if (! ROOT_INTERVAL_P (A))
{
- if (AM_LEFT_CHILD (interval))
- interval_set_left (INTERVAL_PARENT (interval), B);
+ if (AM_LEFT_CHILD (A))
+ set_interval_left (INTERVAL_PARENT (A), B);
else
- interval_set_right (INTERVAL_PARENT (interval), B);
+ set_interval_right (INTERVAL_PARENT (A), B);
}
- interval_copy_parent (B, interval);
+ copy_interval_parent (B, A);
- /* Make B the parent of A */
- i = B->left;
- interval_set_left (B, interval);
- interval_set_parent (interval, B);
+ /* Make B the parent of A. */
+ set_interval_left (B, A);
+ set_interval_parent (A, B);
- /* Make A point to c */
- interval_set_right (interval, i);
- if (i)
- interval_set_parent (i, interval);
+ /* Make A point to c. */
+ set_interval_right (A, c);
+ if (c)
+ set_interval_parent (c, A);
/* A's total length is decreased by the length of B and its right child. */
- interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval);
- eassert (0 <= TOTAL_LENGTH (interval));
+ A->total_length -= B->total_length - TOTAL_LENGTH (c);
+ eassert (TOTAL_LENGTH (A) > 0);
+ eassert (LENGTH (A) > 0);
/* B must have the same total length of A. */
B->total_length = old_total;
- eassert (0 <= TOTAL_LENGTH (B));
+ eassert (LENGTH (B) > 0);
return B;
}
{
register ptrdiff_t old_diff, new_diff;
+ eassert (LENGTH (i) > 0);
+ eassert (TOTAL_LENGTH (i) >= LENGTH (i));
+
while (1)
{
old_diff = LEFT_TOTAL_LENGTH (i) - RIGHT_TOTAL_LENGTH (i);
/* Balance INTERVAL, potentially stuffing it back into its parent
Lisp Object. */
-static inline INTERVAL
-balance_possible_root_interval (register INTERVAL interval)
+static INTERVAL
+balance_possible_root_interval (INTERVAL interval)
{
Lisp_Object parent;
- int have_parent = 0;
-
- if (!INTERVAL_HAS_OBJECT (interval) && !INTERVAL_HAS_PARENT (interval))
- return interval;
+ bool have_parent = false;
if (INTERVAL_HAS_OBJECT (interval))
{
- have_parent = 1;
+ have_parent = true;
GET_INTERVAL_OBJECT (parent, interval);
}
+ else if (!INTERVAL_HAS_PARENT (interval))
+ return interval;
+
interval = balance_an_interval (interval);
if (have_parent)
{
if (BUFFERP (parent))
- buffer_set_intervals (XBUFFER (parent), interval);
+ set_buffer_intervals (XBUFFER (parent), interval);
else if (STRINGP (parent))
- string_set_intervals (parent, interval);
+ set_string_intervals (parent, interval);
}
return interval;
INTERVAL i;
eassert (b != NULL);
- i = buffer_get_intervals (b);
+ i = buffer_intervals (b);
if (i)
- buffer_set_intervals (b, balance_an_interval (i));
+ set_buffer_intervals (b, balance_an_interval (i));
}
/* Split INTERVAL into two pieces, starting the second piece at
ptrdiff_t new_length = LENGTH (interval) - offset;
new->position = position + offset;
- interval_set_parent (new, interval);
+ set_interval_parent (new, interval);
if (NULL_RIGHT_CHILD (interval))
{
- interval_set_right (interval, new);
+ set_interval_right (interval, new);
new->total_length = new_length;
- eassert (0 <= TOTAL_LENGTH (new));
+ eassert (LENGTH (new) > 0);
}
else
{
/* Insert the new node between INTERVAL and its right child. */
- interval_set_right (new, interval->right);
- interval_set_parent (interval->right, new);
- interval_set_right (interval, new);
+ set_interval_right (new, interval->right);
+ set_interval_parent (interval->right, new);
+ set_interval_right (interval, new);
new->total_length = new_length + new->right->total_length;
- eassert (0 <= TOTAL_LENGTH (new));
balance_an_interval (new);
}
new->position = interval->position;
interval->position = interval->position + offset;
- interval_set_parent (new, interval);
+ set_interval_parent (new, interval);
if (NULL_LEFT_CHILD (interval))
{
- interval_set_left (interval, new);
+ set_interval_left (interval, new);
new->total_length = new_length;
- eassert (0 <= TOTAL_LENGTH (new));
+ eassert (LENGTH (new) > 0);
}
else
{
/* Insert the new node between INTERVAL and its left child. */
- interval_set_left (new, interval->left);
- interval_set_parent (new->left, new);
- interval_set_left (interval, new);
+ set_interval_left (new, interval->left);
+ set_interval_parent (new->left, new);
+ set_interval_left (interval, new);
new->total_length = new_length + new->left->total_length;
- eassert (0 <= TOTAL_LENGTH (new));
balance_an_interval (new);
}
eassert (relative_position <= TOTAL_LENGTH (tree));
- if (!handling_signal)
- tree = balance_possible_root_interval (tree);
+ tree = balance_possible_root_interval (tree);
while (1)
{
+ eassert (tree);
if (relative_position < LEFT_TOTAL_LENGTH (tree))
{
tree = tree->left;
{
if (pos < i->position)
{
- /* Move left. */
+ /* Move left. */
if (pos >= i->position - TOTAL_LENGTH (i->left))
{
i->left->position = i->position - TOTAL_LENGTH (i->left)
+ LEFT_TOTAL_LENGTH (i->left);
- i = i->left; /* Move to the left child */
+ i = i->left; /* Move to the left child. */
}
else if (NULL_PARENT (i))
error ("Point before start of properties");
}
else if (pos >= INTERVAL_LAST_POS (i))
{
- /* Move right. */
+ /* Move right. */
if (pos < INTERVAL_LAST_POS (i) + TOTAL_LENGTH (i->right))
{
i->right->position = INTERVAL_LAST_POS (i)
+ LEFT_TOTAL_LENGTH (i->right);
- i = i->right; /* Move to the right child */
+ i = i->right; /* Move to the right child. */
}
else if (NULL_PARENT (i))
error ("Point %"pD"d after end of properties", pos);
adjust_intervals_for_insertion (INTERVAL tree,
ptrdiff_t position, ptrdiff_t length)
{
- register INTERVAL i;
- register INTERVAL temp;
- int eobp = 0;
+ INTERVAL i;
+ INTERVAL temp;
+ bool eobp = 0;
Lisp_Object parent;
ptrdiff_t offset;
for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp))
{
temp->total_length += length;
- eassert (0 <= TOTAL_LENGTH (temp));
temp = balance_possible_root_interval (temp);
}
RESET_INTERVAL (&newi);
pleft = prev ? prev->plist : Qnil;
pright = i ? i->plist : Qnil;
- interval_set_plist (&newi, merge_properties_sticky (pleft, pright));
+ set_interval_plist (&newi, merge_properties_sticky (pleft, pright));
if (! prev) /* i.e. position == BEG */
{
if (! intervals_equal (i, &newi))
{
i = split_interval_left (i, length);
- interval_set_plist (i, newi.plist);
+ set_interval_plist (i, newi.plist);
}
}
else if (! intervals_equal (prev, &newi))
{
prev = split_interval_right (prev, position - prev->position);
- interval_set_plist (prev, newi.plist);
+ set_interval_plist (prev, newi.plist);
if (i && intervals_equal (prev, i))
merge_interval_right (prev);
}
for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp))
{
temp->total_length += length;
- eassert (0 <= TOTAL_LENGTH (temp));
temp = balance_possible_root_interval (temp);
}
}
static Lisp_Object
merge_properties_sticky (Lisp_Object pleft, Lisp_Object pright)
{
- register Lisp_Object props, front, rear;
+ Lisp_Object props, front, rear;
Lisp_Object lfront, lrear, rfront, rrear;
- register Lisp_Object tail1, tail2, sym, lval, rval, cat;
- int use_left, use_right;
- int lpresent;
+ Lisp_Object tail1, tail2, sym, lval, rval, cat;
+ bool use_left, use_right, lpresent;
props = Qnil;
front = Qnil;
this = this->left;
this->total_length += migrate_amt;
}
- eassert (0 <= TOTAL_LENGTH (this));
- interval_set_left (this, migrate);
- interval_set_parent (migrate, this);
+ set_interval_left (this, migrate);
+ set_interval_parent (migrate, this);
+ eassert (LENGTH (this) > 0);
+ eassert (LENGTH (i->right) > 0);
return i->right;
}
GET_INTERVAL_OBJECT (owner, i);
parent = delete_node (i);
if (parent)
- interval_set_object (parent, owner);
+ set_interval_object (parent, owner);
if (BUFFERP (owner))
- buffer_set_intervals (XBUFFER (owner), parent);
+ set_buffer_intervals (XBUFFER (owner), parent);
else if (STRINGP (owner))
- string_set_intervals (owner, parent);
+ set_string_intervals (owner, parent);
else
- abort ();
+ emacs_abort ();
return;
}
parent = INTERVAL_PARENT (i);
if (AM_LEFT_CHILD (i))
{
- interval_set_left (parent, delete_node (i));
+ set_interval_left (parent, delete_node (i));
if (parent->left)
- interval_set_parent (parent->left, parent);
+ set_interval_parent (parent->left, parent);
}
else
{
- interval_set_right (parent, delete_node (i));
+ set_interval_right (parent, delete_node (i));
if (parent->right)
- interval_set_parent (parent->right, parent);
+ set_interval_parent (parent->right, parent);
}
}
\f
relative_position,
amount);
tree->total_length -= subtract;
- eassert (0 <= TOTAL_LENGTH (tree));
+ eassert (LENGTH (tree) > 0);
return subtract;
}
/* Right branch. */
relative_position,
amount);
tree->total_length -= subtract;
- eassert (0 <= TOTAL_LENGTH (tree));
+ eassert (LENGTH (tree) > 0);
return subtract;
}
/* Here -- this node. */
amount = my_amount;
tree->total_length -= amount;
- eassert (0 <= TOTAL_LENGTH (tree));
+ eassert (LENGTH (tree) >= 0);
if (LENGTH (tree) == 0)
delete_interval (tree);
adjust_intervals_for_deletion (struct buffer *buffer,
ptrdiff_t start, ptrdiff_t length)
{
- register ptrdiff_t left_to_delete = length;
- register INTERVAL tree = buffer_get_intervals (buffer);
+ ptrdiff_t left_to_delete = length;
+ INTERVAL tree = buffer_intervals (buffer);
Lisp_Object parent;
ptrdiff_t offset;
if (length == TOTAL_LENGTH (tree))
{
- buffer_set_intervals (buffer, NULL);
+ set_buffer_intervals (buffer, NULL);
return;
}
if (ONLY_INTERVAL_P (tree))
{
tree->total_length -= length;
- eassert (0 <= TOTAL_LENGTH (tree));
+ eassert (LENGTH (tree) > 0);
return;
}
{
left_to_delete -= interval_deletion_adjustment (tree, start - offset,
left_to_delete);
- tree = buffer_get_intervals (buffer);
+ tree = buffer_intervals (buffer);
if (left_to_delete == tree->total_length)
{
- buffer_set_intervals (buffer, NULL);
+ set_buffer_intervals (buffer, NULL);
return;
}
}
/* Make the adjustments necessary to the interval tree of BUFFER to
represent an addition or deletion of LENGTH characters starting
at position START. Addition or deletion is indicated by the sign
- of LENGTH.
-
- The two inline functions (one static) pacify Sun C 5.8, a pre-C99
- compiler that does not allow calling a static function (here,
- adjust_intervals_for_deletion) from a non-static inline function. */
+ of LENGTH. */
void
offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length)
{
- if (!buffer_get_intervals (buffer) || length == 0)
+ if (!buffer_intervals (buffer) || length == 0)
return;
if (length > 0)
- adjust_intervals_for_insertion (buffer_get_intervals (buffer),
+ adjust_intervals_for_insertion (buffer_intervals (buffer),
start, length);
else
- {
- IF_LINT (if (length < - TYPE_MAXIMUM (ptrdiff_t)) abort ();)
- adjust_intervals_for_deletion (buffer, start, -length);
- }
+ adjust_intervals_for_deletion (buffer, start, -length);
}
\f
/* Merge interval I with its lexicographic successor. The resulting
while (! NULL_LEFT_CHILD (successor))
{
successor->total_length += absorb;
- eassert (0 <= TOTAL_LENGTH (successor));
+ eassert (LENGTH (successor) > 0);
successor = successor->left;
}
successor->total_length += absorb;
- eassert (0 <= TOTAL_LENGTH (successor));
+ eassert (LENGTH (successor) > 0);
delete_interval (i);
return successor;
}
/* Zero out this interval. */
i->total_length -= absorb;
- eassert (0 <= TOTAL_LENGTH (i));
+ eassert (TOTAL_LENGTH (i) >= 0);
successor = i;
while (! NULL_PARENT (successor)) /* It's above us. Subtract as
successor = INTERVAL_PARENT (successor);
successor->total_length -= absorb;
- eassert (0 <= TOTAL_LENGTH (successor));
+ eassert (LENGTH (successor) > 0);
}
/* This must be the rightmost or last interval and cannot
be merged right. The caller should have known. */
- abort ();
+ emacs_abort ();
}
\f
/* Merge interval I with its lexicographic predecessor. The resulting
while (! NULL_RIGHT_CHILD (predecessor))
{
predecessor->total_length += absorb;
- eassert (0 <= TOTAL_LENGTH (predecessor));
+ eassert (LENGTH (predecessor) > 0);
predecessor = predecessor->right;
}
predecessor->total_length += absorb;
- eassert (0 <= TOTAL_LENGTH (predecessor));
+ eassert (LENGTH (predecessor) > 0);
delete_interval (i);
return predecessor;
}
/* Zero out this interval. */
i->total_length -= absorb;
- eassert (0 <= TOTAL_LENGTH (i));
+ eassert (TOTAL_LENGTH (i) >= 0);
predecessor = i;
while (! NULL_PARENT (predecessor)) /* It's above us. Go up,
predecessor = INTERVAL_PARENT (predecessor);
predecessor->total_length -= absorb;
- eassert (0 <= TOTAL_LENGTH (predecessor));
+ eassert (LENGTH (predecessor) > 0);
}
/* This must be the leftmost or first interval and cannot
be merged left. The caller should have known. */
- abort ();
+ emacs_abort ();
}
\f
+/* Create a copy of SOURCE but with the default value of UP. */
+
+static INTERVAL
+reproduce_interval (INTERVAL source)
+{
+ register INTERVAL target = make_interval ();
+
+ eassert (LENGTH (source) > 0);
+
+ target->total_length = source->total_length;
+ target->position = source->position;
+
+ copy_properties (source, target);
+
+ if (! NULL_LEFT_CHILD (source))
+ set_interval_left (target, reproduce_tree (source->left, target));
+ if (! NULL_RIGHT_CHILD (source))
+ set_interval_right (target, reproduce_tree (source->right, target));
+
+ eassert (LENGTH (target) > 0);
+ return target;
+}
+
/* Make an exact copy of interval tree SOURCE which descends from
PARENT. This is done by recursing through SOURCE, copying
the current interval and its properties, and then adjusting
static INTERVAL
reproduce_tree (INTERVAL source, INTERVAL parent)
{
- register INTERVAL t = make_interval ();
-
- memcpy (t, source, sizeof *t);
- copy_properties (source, t);
- interval_set_parent (t, parent);
- if (! NULL_LEFT_CHILD (source))
- interval_set_left (t, reproduce_tree (source->left, t));
- if (! NULL_RIGHT_CHILD (source))
- interval_set_right (t, reproduce_tree (source->right, t));
-
- return t;
+ INTERVAL target = reproduce_interval (source);
+ set_interval_parent (target, parent);
+ return target;
}
static INTERVAL
reproduce_tree_obj (INTERVAL source, Lisp_Object parent)
{
- register INTERVAL t = make_interval ();
-
- memcpy (t, source, sizeof *t);
- copy_properties (source, t);
- interval_set_object (t, parent);
- if (! NULL_LEFT_CHILD (source))
- interval_set_left (t, reproduce_tree (source->left, t));
- if (! NULL_RIGHT_CHILD (source))
- interval_set_right (t, reproduce_tree (source->right, t));
-
- return t;
+ INTERVAL target = reproduce_interval (source);
+ set_interval_object (target, parent);
+ return target;
}
\f
/* Insert the intervals of SOURCE into BUFFER at POSITION.
void
graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position,
ptrdiff_t length, struct buffer *buffer,
- int inherit)
+ bool inherit)
{
- register INTERVAL under, over, this;
- register INTERVAL tree;
+ INTERVAL tree = buffer_intervals (buffer);
+ INTERVAL under, over, this;
ptrdiff_t over_used;
- tree = buffer_get_intervals (buffer);
-
/* If the new text has no properties, then with inheritance it
becomes part of whatever interval it was inserted into.
To prevent inheritance, we must clear out the properties
XSETBUFFER (buf, buffer);
set_text_properties_1 (make_number (position),
make_number (position + length),
- Qnil, buf, 0);
+ Qnil, buf,
+ find_interval (tree, position));
}
/* Shouldn't be necessary. --Stef */
buffer_balance_intervals (buffer);
eassert (length == TOTAL_LENGTH (source));
if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length)
- {
+ {
/* The inserted text constitutes the whole buffer, so
simply copy over the interval structure. */
Lisp_Object buf;
XSETBUFFER (buf, buffer);
- buffer_set_intervals (buffer, reproduce_tree_obj (source, buf));
- buffer_get_intervals (buffer)->position = BUF_BEG (buffer);
- eassert (buffer_get_intervals (buffer)->up_obj == 1);
+ set_buffer_intervals (buffer, reproduce_tree_obj (source, buf));
+ buffer_intervals (buffer)->position = BUF_BEG (buffer);
+ eassert (buffer_intervals (buffer)->up_obj == 1);
return;
}
else if (!tree)
}
Lisp_Object
-lookup_char_property (Lisp_Object plist, register Lisp_Object prop, int textprop)
+lookup_char_property (Lisp_Object plist, Lisp_Object prop, bool textprop)
{
- register Lisp_Object tail, fallback = Qnil;
+ Lisp_Object tail, fallback = Qnil;
for (tail = plist; CONSP (tail); tail = Fcdr (XCDR (tail)))
{
if (! NILP (fallback))
return fallback;
- /* Check for alternative properties */
+ /* Check for alternative properties. */
tail = Fassq (prop, Vchar_property_alias_alist);
if (! NILP (tail))
{
ptrdiff_t charpos, ptrdiff_t bytepos)
{
/* In a single-byte buffer, the two positions must be equal. */
- if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer))
- eassert (charpos == bytepos);
+ eassert (BUF_ZV (buffer) != BUF_ZV_BYTE (buffer) || charpos == bytepos);
eassert (charpos <= bytepos);
eassert (charpos <= BUF_ZV (buffer) || BUF_BEGV (buffer) <= charpos);
set_point_both (charpos, buf_charpos_to_bytepos (current_buffer, charpos));
}
+/* Set PT from MARKER's clipped position. */
+
+void
+set_point_from_marker (Lisp_Object marker)
+{
+ if (XMARKER (marker)->buffer != current_buffer)
+ signal_error ("Marker points into wrong buffer", marker);
+ set_point_both
+ (clip_to_bounds (BEGV, marker_position (marker), ZV),
+ clip_to_bounds (BEGV_BYTE, marker_byte_position (marker), ZV_BYTE));
+}
+
/* If there's an invisible character at position POS + TEST_OFFS in the
current buffer, and the invisible property has a `stickiness' such that
inserting a character at position POS would inherit the property it,
- return POS + ADJ, otherwise return POS. If TEST_INTANG is non-zero,
- then intangibility is required as well as invisibility.
+ return POS + ADJ, otherwise return POS. If TEST_INTANG, intangibility
+ is required as well as invisibility.
TEST_OFFS should be either 0 or -1, and ADJ should be either 1 or -1.
static ptrdiff_t
adjust_for_invis_intang (ptrdiff_t pos, ptrdiff_t test_offs, ptrdiff_t adj,
- int test_intang)
+ bool test_intang)
{
Lisp_Object invis_propval, invis_overlay;
Lisp_Object test_pos;
initial position is the same as the destination, in the rare
instances where this is important, e.g. in line-move-finish
(simple.el). */
- int backwards = (charpos < old_position ? 1 : 0);
- int have_overlays;
+ bool backwards = charpos < old_position;
+ bool have_overlays;
ptrdiff_t original_position;
- BVAR (current_buffer, point_before_scroll) = Qnil;
+ bset_point_before_scroll (current_buffer, Qnil);
if (charpos == PT)
return;
/* If we have no text properties and overlays,
then we can do it quickly. */
- if (!buffer_get_intervals (current_buffer) && ! have_overlays)
+ if (!buffer_intervals (current_buffer) && ! have_overlays)
{
temp_set_point_both (current_buffer, charpos, bytepos);
return;
/* Set TO to the interval containing the char after CHARPOS,
and TOPREV to the interval containing the char before CHARPOS.
Either one may be null. They may be equal. */
- to = find_interval (buffer_get_intervals (current_buffer), charpos);
+ to = find_interval (buffer_intervals (current_buffer), charpos);
if (charpos == BEGV)
toprev = 0;
else if (to && to->position == charpos)
and FROMPREV to the interval containing the char before PT.
Either one may be null. They may be equal. */
/* We could cache this and save time. */
- from = find_interval (buffer_get_intervals (current_buffer), buffer_point);
+ from = find_interval (buffer_intervals (current_buffer), buffer_point);
if (buffer_point == BEGV)
fromprev = 0;
else if (from && from->position == PT)
/* Set TO to the interval containing the char after CHARPOS,
and TOPREV to the interval containing the char before CHARPOS.
Either one may be null. They may be equal. */
- to = find_interval (buffer_get_intervals (current_buffer), charpos);
+ to = find_interval (buffer_intervals (current_buffer), charpos);
if (charpos == BEGV)
toprev = 0;
else if (to && to->position == charpos)
\f
/* If text at position POS has property PROP, set *VAL to the property
value, *START and *END to the beginning and end of a region that
- has the same property, and return 1. Otherwise return 0.
+ has the same property, and return true. Otherwise return false.
OBJECT is the string or buffer to look for the property in;
nil means the current buffer. */
-int
+bool
get_property_and_range (ptrdiff_t pos, Lisp_Object prop, Lisp_Object *val,
ptrdiff_t *start, ptrdiff_t *end, Lisp_Object object)
{
INTERVAL i, prev, next;
if (NILP (object))
- i = find_interval (buffer_get_intervals (current_buffer), pos);
+ i = find_interval (buffer_intervals (current_buffer), pos);
else if (BUFFERP (object))
- i = find_interval (buffer_get_intervals (XBUFFER (object)), pos);
+ i = find_interval (buffer_intervals (XBUFFER (object)), pos);
else if (STRINGP (object))
- i = find_interval (string_get_intervals (object), pos);
+ i = find_interval (string_intervals (object), pos);
else
- abort ();
+ emacs_abort ();
if (!i || (i->position + LENGTH (i) <= pos))
return 0;
/* Return the proper local keymap TYPE for position POSITION in
BUFFER; TYPE should be one of `keymap' or `local-map'. Use the map
specified by the PROP property, if any. Otherwise, if TYPE is
- `local-map' use BUFFER's local map.
-
- POSITION must be in the accessible part of BUFFER. */
+ `local-map' use BUFFER's local map. */
Lisp_Object
-get_local_map (register ptrdiff_t position, register struct buffer *buffer,
- Lisp_Object type)
+get_local_map (ptrdiff_t position, struct buffer *buffer, Lisp_Object type)
{
Lisp_Object prop, lispy_position, lispy_buffer;
ptrdiff_t old_begv, old_zv, old_begv_byte, old_zv_byte;
- /* Perhaps we should just change `position' to the limit. */
- if (position > BUF_ZV (buffer) || position < BUF_BEGV (buffer))
- abort ();
+ position = clip_to_bounds (BUF_BEGV (buffer), position, BUF_ZV (buffer));
/* Ignore narrowing, so that a local map continues to be valid even if
the visible region contains no characters and hence no properties. */
editing a field with a `local-map' property, we want insertion at the end
to obey the `local-map' property. */
if (NILP (prop))
- prop = get_pos_property (lispy_position, type, lispy_buffer);
+ prop = Fget_pos_property (lispy_position, type, lispy_buffer);
SET_BUF_BEGV_BOTH (buffer, old_begv, old_begv_byte);
SET_BUF_ZV_BOTH (buffer, old_zv, old_zv_byte);
new->position = 0;
got = (LENGTH (i) - (start - i->position));
new->total_length = length;
- eassert (0 <= TOTAL_LENGTH (new));
+ eassert (TOTAL_LENGTH (new) >= 0);
copy_properties (i, new);
t = new;
copy_intervals_to_string (Lisp_Object string, struct buffer *buffer,
ptrdiff_t position, ptrdiff_t length)
{
- INTERVAL interval_copy = copy_intervals (buffer_get_intervals (buffer),
+ INTERVAL interval_copy = copy_intervals (buffer_intervals (buffer),
position, length);
if (!interval_copy)
return;
- interval_set_object (interval_copy, string);
- string_set_intervals (string, interval_copy);
+ set_interval_object (interval_copy, string);
+ set_string_intervals (string, interval_copy);
}
\f
-/* Return 1 if strings S1 and S2 have identical properties; 0 otherwise.
+/* Return true if strings S1 and S2 have identical properties.
Assume they have identical characters. */
-int
+bool
compare_string_intervals (Lisp_Object s1, Lisp_Object s2)
{
INTERVAL i1, i2;
ptrdiff_t pos = 0;
ptrdiff_t end = SCHARS (s1);
- i1 = find_interval (string_get_intervals (s1), 0);
- i2 = find_interval (string_get_intervals (s2), 0);
+ i1 = find_interval (string_intervals (s1), 0);
+ i2 = find_interval (string_intervals (s2), 0);
while (pos < end)
{
START_BYTE ... END_BYTE in bytes. */
static void
-set_intervals_multibyte_1 (INTERVAL i, int multi_flag,
+set_intervals_multibyte_1 (INTERVAL i, bool multi_flag,
ptrdiff_t start, ptrdiff_t start_byte,
ptrdiff_t end, ptrdiff_t end_byte)
{
i->total_length = end - start;
else
i->total_length = end_byte - start_byte;
- eassert (0 <= TOTAL_LENGTH (i));
+ eassert (TOTAL_LENGTH (i) >= 0);
if (TOTAL_LENGTH (i) == 0)
{
end, end_byte);
}
- /* Rounding to char boundaries can theoretically ake this interval
+ /* Rounding to char boundaries can theoretically make this interval
spurious. If so, delete one child, and copy its property list
to this interval. */
if (LEFT_TOTAL_LENGTH (i) + RIGHT_TOTAL_LENGTH (i) >= TOTAL_LENGTH (i))
{
if ((i)->left)
{
- interval_set_plist (i, i->left->plist);
+ set_interval_plist (i, i->left->plist);
(i)->left->total_length = 0;
delete_interval ((i)->left);
}
else
{
- interval_set_plist (i, i->right->plist);
+ set_interval_plist (i, i->right->plist);
(i)->right->total_length = 0;
delete_interval ((i)->right);
}
}
/* Update the intervals of the current buffer
- to fit the contents as multibyte (if MULTI_FLAG is 1)
- or to fit them as non-multibyte (if MULTI_FLAG is 0). */
+ to fit the contents as multibyte (if MULTI_FLAG)
+ or to fit them as non-multibyte (if not MULTI_FLAG). */
void
-set_intervals_multibyte (int multi_flag)
+set_intervals_multibyte (bool multi_flag)
{
- INTERVAL i = buffer_get_intervals (current_buffer);
+ INTERVAL i = buffer_intervals (current_buffer);
if (i)
set_intervals_multibyte_1 (i, multi_flag, BEG, BEG_BYTE, Z, Z_BYTE);