X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/82e2a1f054cc0306494d1194036af4c5d7301caf..a3fab1ec17f05e2782dcde814018fc48a3bbebb9:/src/intervals.c diff --git a/src/intervals.c b/src/intervals.c index 807bbbfaa3..0e3b684f57 100644 --- a/src/intervals.c +++ b/src/intervals.c @@ -1,5 +1,6 @@ /* Code for doing intervals. - Copyright (C) 1993-1995, 1997-1998, 2001-2012 Free Software Foundation, Inc. + Copyright (C) 1993-1995, 1997-1998, 2001-2013 Free Software + Foundation, Inc. This file is part of GNU Emacs. @@ -39,8 +40,6 @@ along with GNU Emacs. If not, see . */ #include -#define INTERVALS_INLINE EXTERN_INLINE - #include #include "lisp.h" #include "intervals.h" @@ -109,14 +108,14 @@ create_root_interval (Lisp_Object parent) { new->total_length = (BUF_Z (XBUFFER (parent)) - BUF_BEG (XBUFFER (parent))); - eassert (0 <= TOTAL_LENGTH (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)); + eassert (TOTAL_LENGTH (new) >= 0); set_string_intervals (parent, new); new->position = 0; } @@ -370,11 +369,11 @@ rotate_right (INTERVAL interval) /* 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)); + eassert (TOTAL_LENGTH (interval) >= 0); /* B must have the same total length of A. */ B->total_length = old_total; - eassert (0 <= TOTAL_LENGTH (B)); + eassert (TOTAL_LENGTH (B) >= 0); return B; } @@ -417,11 +416,11 @@ rotate_left (INTERVAL interval) /* 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)); + eassert (TOTAL_LENGTH (interval) >= 0); /* B must have the same total length of A. */ B->total_length = old_total; - eassert (0 <= TOTAL_LENGTH (B)); + eassert (TOTAL_LENGTH (B) >= 0); return B; } @@ -555,7 +554,7 @@ split_interval_right (INTERVAL interval, ptrdiff_t offset) { set_interval_right (interval, new); new->total_length = new_length; - eassert (0 <= TOTAL_LENGTH (new)); + eassert (TOTAL_LENGTH (new) >= 0); } else { @@ -564,7 +563,7 @@ split_interval_right (INTERVAL interval, ptrdiff_t offset) 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)); + eassert (TOTAL_LENGTH (new) >= 0); balance_an_interval (new); } @@ -600,7 +599,7 @@ split_interval_left (INTERVAL interval, ptrdiff_t offset) { set_interval_left (interval, new); new->total_length = new_length; - eassert (0 <= TOTAL_LENGTH (new)); + eassert (TOTAL_LENGTH (new) >= 0); } else { @@ -609,7 +608,7 @@ split_interval_left (INTERVAL interval, ptrdiff_t offset) 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)); + eassert (TOTAL_LENGTH (new) >= 0); balance_an_interval (new); } @@ -959,7 +958,7 @@ adjust_intervals_for_insertion (INTERVAL tree, for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) { temp->total_length += length; - eassert (0 <= TOTAL_LENGTH (temp)); + eassert (TOTAL_LENGTH (temp) >= 0); temp = balance_possible_root_interval (temp); } @@ -1015,7 +1014,7 @@ adjust_intervals_for_insertion (INTERVAL tree, for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) { temp->total_length += length; - eassert (0 <= TOTAL_LENGTH (temp)); + eassert (TOTAL_LENGTH (temp) >= 0); temp = balance_possible_root_interval (temp); } } @@ -1217,7 +1216,7 @@ delete_node (register INTERVAL i) this = this->left; this->total_length += migrate_amt; } - eassert (0 <= TOTAL_LENGTH (this)); + eassert (TOTAL_LENGTH (this) >= 0); set_interval_left (this, migrate); set_interval_parent (migrate, this); @@ -1299,7 +1298,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, relative_position, amount); tree->total_length -= subtract; - eassert (0 <= TOTAL_LENGTH (tree)); + eassert (TOTAL_LENGTH (tree) >= 0); return subtract; } /* Right branch. */ @@ -1314,7 +1313,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, relative_position, amount); tree->total_length -= subtract; - eassert (0 <= TOTAL_LENGTH (tree)); + eassert (TOTAL_LENGTH (tree) >= 0); return subtract; } /* Here -- this node. */ @@ -1329,7 +1328,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, amount = my_amount; tree->total_length -= amount; - eassert (0 <= TOTAL_LENGTH (tree)); + eassert (TOTAL_LENGTH (tree) >= 0); if (LENGTH (tree) == 0) delete_interval (tree); @@ -1371,7 +1370,7 @@ adjust_intervals_for_deletion (struct buffer *buffer, if (ONLY_INTERVAL_P (tree)) { tree->total_length -= length; - eassert (0 <= TOTAL_LENGTH (tree)); + eassert (TOTAL_LENGTH (tree) >= 0); return; } @@ -1405,10 +1404,7 @@ offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length) adjust_intervals_for_insertion (buffer_intervals (buffer), start, length); else - { - lint_assume (- TYPE_MAXIMUM (ptrdiff_t) <= length); - adjust_intervals_for_deletion (buffer, start, -length); - } + adjust_intervals_for_deletion (buffer, start, -length); } /* Merge interval I with its lexicographic successor. The resulting @@ -1434,19 +1430,19 @@ merge_interval_right (register INTERVAL i) while (! NULL_LEFT_CHILD (successor)) { successor->total_length += absorb; - eassert (0 <= TOTAL_LENGTH (successor)); + eassert (TOTAL_LENGTH (successor) >= 0); successor = successor->left; } successor->total_length += absorb; - eassert (0 <= TOTAL_LENGTH (successor)); + eassert (TOTAL_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 @@ -1461,7 +1457,7 @@ merge_interval_right (register INTERVAL i) successor = INTERVAL_PARENT (successor); successor->total_length -= absorb; - eassert (0 <= TOTAL_LENGTH (successor)); + eassert (TOTAL_LENGTH (successor) >= 0); } /* This must be the rightmost or last interval and cannot @@ -1490,19 +1486,19 @@ merge_interval_left (register INTERVAL i) while (! NULL_RIGHT_CHILD (predecessor)) { predecessor->total_length += absorb; - eassert (0 <= TOTAL_LENGTH (predecessor)); + eassert (TOTAL_LENGTH (predecessor) >= 0); predecessor = predecessor->right; } predecessor->total_length += absorb; - eassert (0 <= TOTAL_LENGTH (predecessor)); + eassert (TOTAL_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, @@ -1517,7 +1513,7 @@ merge_interval_left (register INTERVAL i) predecessor = INTERVAL_PARENT (predecessor); predecessor->total_length -= absorb; - eassert (0 <= TOTAL_LENGTH (predecessor)); + eassert (TOTAL_LENGTH (predecessor) >= 0); } /* This must be the leftmost or first interval and cannot @@ -1793,8 +1789,7 @@ temp_set_point_both (struct buffer *buffer, 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); @@ -1820,6 +1815,18 @@ set_point (ptrdiff_t 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, @@ -2195,20 +2202,15 @@ get_property_and_range (ptrdiff_t pos, Lisp_Object prop, Lisp_Object *val, /* 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)) - emacs_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. */ @@ -2230,7 +2232,7 @@ get_local_map (register ptrdiff_t position, register struct buffer *buffer, 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); @@ -2271,7 +2273,7 @@ copy_intervals (INTERVAL tree, ptrdiff_t start, ptrdiff_t length) 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; @@ -2354,7 +2356,7 @@ set_intervals_multibyte_1 (INTERVAL i, bool multi_flag, 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) {