From: Stefan Monnier Date: Fri, 18 Nov 2011 16:00:40 +0000 (-0500) Subject: * src/intervals.c: Fix grafting over the whole buffer. X-Git-Tag: emacs-pretest-24.0.92~144 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b50a28de8707794ff4b4b755af3173cd19004976;p=emacs.git * src/intervals.c: Fix grafting over the whole buffer. (graft_intervals_into_buffer): Simplify. Fixes: debbugs:10071 --- diff --git a/src/ChangeLog b/src/ChangeLog index 9af953b08b1..199f20817ea 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2011-11-18 Stefan Monnier + + * intervals.c: Fix grafting over the whole buffer (bug#10071). + (graft_intervals_into_buffer): Simplify. + 2011-11-18 Eli Zaretskii * dispnew.c (swap_glyph_pointers): Swap the used[] arrays and the @@ -394,7 +399,7 @@ Fix the `xbytecode' command. * .gdbinit (xprintbytestr): New command. - (xwhichsymbols): Renamed from `which'; all callers changed. + (xwhichsymbols): Rename from `which'; all callers changed. (xbytecode): Print the byte-code string as well. 2011-10-29 Kim Storm diff --git a/src/insdel.c b/src/insdel.c index 01e5c57b2b0..e39a362eac7 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -1316,7 +1316,7 @@ replace_range (EMACS_INT from, EMACS_INT to, Lisp_Object new, UNGCPRO; - /* Make args be valid */ + /* Make args be valid. */ if (from < BEGV) from = BEGV; if (to > ZV) diff --git a/src/intervals.c b/src/intervals.c index a78c7f07f6c..35d05d021f0 100644 --- a/src/intervals.c +++ b/src/intervals.c @@ -1317,7 +1317,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from, if (NULL_INTERVAL_P (tree)) return 0; - /* Left branch */ + /* Left branch. */ if (relative_position < LEFT_TOTAL_LENGTH (tree)) { EMACS_INT subtract = interval_deletion_adjustment (tree->left, @@ -1327,7 +1327,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from, CHECK_TOTAL_LENGTH (tree); return subtract; } - /* Right branch */ + /* Right branch. */ else if (relative_position >= (TOTAL_LENGTH (tree) - RIGHT_TOTAL_LENGTH (tree))) { @@ -1699,54 +1699,37 @@ graft_intervals_into_buffer (INTERVAL source, EMACS_INT position, Qnil, buf, 0); } if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) - /* Shouldn't be necessary. -stef */ + /* Shouldn't be necessary. --Stef */ BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); return; } - if (NULL_INTERVAL_P (tree)) - { - /* The inserted text constitutes the whole buffer, so + 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. */ - if ((BUF_Z (buffer) - BUF_BEG (buffer)) == TOTAL_LENGTH (source)) - { Lisp_Object buf; XSETBUFFER (buf, buffer); BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf); - BUF_INTERVALS (buffer)->position = BEG; - BUF_INTERVALS (buffer)->up_obj = 1; - + BUF_INTERVALS (buffer)->position = BUF_BEG (buffer); + eassert (BUF_INTERVALS (buffer)->up_obj == 1); return; } - - /* Create an interval tree in which to place a copy + else if (NULL_INTERVAL_P (tree)) + { /* Create an interval tree in which to place a copy of the intervals of the inserted string. */ - { Lisp_Object buf; XSETBUFFER (buf, buffer); tree = create_root_interval (buf); } - } - else if (TOTAL_LENGTH (tree) == TOTAL_LENGTH (source)) - /* If the buffer contains only the new string, but - there was already some interval tree there, then it may be - some zero length intervals. Eventually, do something clever - about inserting properly. For now, just waste the old intervals. */ - { - BUF_INTERVALS (buffer) = reproduce_tree (source, INTERVAL_PARENT (tree)); - BUF_INTERVALS (buffer)->position = BEG; - BUF_INTERVALS (buffer)->up_obj = 1; - /* Explicitly free the old tree here. */ - - return; - } /* Paranoia -- the text has already been added, so this buffer should be of non-zero length. */ else if (TOTAL_LENGTH (tree) == 0) abort (); this = under = find_interval (tree, position); - if (NULL_INTERVAL_P (under)) /* Paranoia */ + if (NULL_INTERVAL_P (under)) /* Paranoia. */ abort (); over = find_interval (source, interval_start_pos (source)); diff --git a/src/intervals.h b/src/intervals.h index 720598fe7a6..977f3d965a4 100644 --- a/src/intervals.h +++ b/src/intervals.h @@ -64,71 +64,71 @@ struct interval Lisp_Object plist; }; -/* These are macros for dealing with the interval tree. */ +/* These are macros for dealing with the interval tree. */ -/* Size of the structure used to represent an interval */ +/* Size of the structure used to represent an interval. */ #define INTERVAL_SIZE (sizeof (struct interval)) -/* Size of a pointer to an interval structure */ +/* Size of a pointer to an interval structure. */ #define INTERVAL_PTR_SIZE (sizeof (struct interval *)) #define NULL_INTERVAL_P(i) ((i) == NULL_INTERVAL) -/* True if this interval has no right child. */ +/* True if this interval has no right child. */ #define NULL_RIGHT_CHILD(i) ((i)->right == NULL_INTERVAL) -/* True if this interval has no left child. */ +/* True if this interval has no left child. */ #define NULL_LEFT_CHILD(i) ((i)->left == NULL_INTERVAL) -/* True if this interval has no parent. */ +/* True if this interval has no parent. */ #define NULL_PARENT(i) ((i)->up_obj || (i)->up.interval == 0) -/* True if this interval is the left child of some other interval. */ +/* True if this interval is the left child of some other interval. */ #define AM_LEFT_CHILD(i) (! NULL_PARENT (i) \ && INTERVAL_PARENT (i)->left == (i)) -/* True if this interval is the right child of some other interval. */ +/* True if this interval is the right child of some other interval. */ #define AM_RIGHT_CHILD(i) (! NULL_PARENT (i) \ && INTERVAL_PARENT (i)->right == (i)) -/* True if this interval has no children. */ +/* True if this interval has no children. */ #define LEAF_INTERVAL_P(i) ((i)->left == NULL_INTERVAL \ && (i)->right == NULL_INTERVAL) -/* True if this interval has no parent and is therefore the root. */ +/* True if this interval has no parent and is therefore the root. */ #define ROOT_INTERVAL_P(i) (NULL_PARENT (i)) -/* True if this interval is the only interval in the interval tree. */ +/* True if this interval is the only interval in the interval tree. */ #define ONLY_INTERVAL_P(i) (ROOT_INTERVAL_P ((i)) && LEAF_INTERVAL_P ((i))) -/* True if this interval has both left and right children. */ +/* True if this interval has both left and right children. */ #define BOTH_KIDS_P(i) ((i)->left != NULL_INTERVAL \ && (i)->right != NULL_INTERVAL) /* The total size of all text represented by this interval and all its - children in the tree. This is zero if the interval is null. */ + children in the tree. This is zero if the interval is null. */ #define TOTAL_LENGTH(i) ((i) == NULL_INTERVAL ? 0 : (i)->total_length) -/* The size of text represented by this interval alone. */ +/* The size of text represented by this interval alone. */ #define LENGTH(i) ((i) == NULL_INTERVAL ? 0 : (TOTAL_LENGTH ((i)) \ - TOTAL_LENGTH ((i)->right) \ - TOTAL_LENGTH ((i)->left))) /* The position of the character just past the end of I. Note that - the position cache i->position must be valid for this to work. */ + the position cache i->position must be valid for this to work. */ #define INTERVAL_LAST_POS(i) ((i)->position + LENGTH ((i))) -/* The total size of the left subtree of this interval. */ +/* The total size of the left subtree of this interval. */ #define LEFT_TOTAL_LENGTH(i) ((i)->left ? (i)->left->total_length : 0) -/* The total size of the right subtree of this interval. */ +/* The total size of the right subtree of this interval. */ #define RIGHT_TOTAL_LENGTH(i) ((i)->right ? (i)->right->total_length : 0) -/* These macros are for dealing with the interval properties. */ +/* These macros are for dealing with the interval properties. */ /* True if this is a default interval, which is the same as being null - or having no properties. */ + or having no properties. */ #define DEFAULT_INTERVAL_P(i) (NULL_INTERVAL_P (i) || EQ ((i)->plist, Qnil)) /* Test what type of parent we have. Three possibilities: another @@ -169,7 +169,7 @@ struct interval } \ while (0) -/* Reset this interval to its vanilla, or no-property state. */ +/* Reset this interval to its vanilla, or no-property state. */ #define RESET_INTERVAL(i) \ { \ (i)->total_length = (i)->position = 0; \ @@ -181,7 +181,7 @@ struct interval (i)->plist = Qnil; \ } -/* Copy the cached property values of interval FROM to interval TO. */ +/* Copy the cached property values of interval FROM to interval TO. */ #define COPY_INTERVAL_CACHE(from,to) \ { \ (to)->write_protect = (from)->write_protect; \ @@ -190,7 +190,7 @@ struct interval (to)->rear_sticky = (from)->rear_sticky; \ } -/* Copy only the set bits of FROM's cache. */ +/* Copy only the set bits of FROM's cache. */ #define MERGE_INTERVAL_CACHE(from,to) \ { \ if ((from)->write_protect) (to)->write_protect = 1; \ @@ -201,18 +201,18 @@ struct interval /* Macro determining whether the properties of an interval being inserted should be merged with the properties of the text where - they are being inserted. */ + they are being inserted. */ #define MERGE_INSERTIONS(i) 1 /* Macro determining if an invisible interval should be displayed - as a special glyph, or not at all. */ + as a special glyph, or not at all. */ #define DISPLAY_INVISIBLE_GLYPH(i) 0 -/* Is this interval visible? Replace later with cache access */ +/* Is this interval visible? Replace later with cache access. */ #define INTERVAL_VISIBLE_P(i) \ (! NULL_INTERVAL_P (i) && NILP (textget ((i)->plist, Qinvisible))) -/* Is this interval writable? Replace later with cache access */ +/* Is this interval writable? Replace later with cache access. */ #define INTERVAL_WRITABLE_P(i) \ (! NULL_INTERVAL_P (i) \ && (NILP (textget ((i)->plist, Qread_only)) \ @@ -222,7 +222,7 @@ struct interval : !NILP (Vinhibit_read_only))))) \ /* Macros to tell whether insertions before or after this interval - should stick to it. */ + should stick to it. */ /* Replace later with cache access */ /*#define FRONT_STICKY_P(i) ((i)->front_sticky != 0) #define END_STICKY_P(i) ((i)->rear_sticky != 0)*/ @@ -245,11 +245,11 @@ struct interval ? !NILP (prop) \ : invisible_p (prop, BVAR (current_buffer, invisibility_spec))) -/* Declared in alloc.c */ +/* Declared in alloc.c. */ extern INTERVAL make_interval (void); -/* Declared in intervals.c */ +/* Declared in intervals.c. */ extern INTERVAL create_root_interval (Lisp_Object); extern void copy_properties (INTERVAL, INTERVAL); @@ -288,12 +288,12 @@ extern INTERVAL validate_interval_range (Lisp_Object, Lisp_Object *, Lisp_Object *, int); extern INTERVAL interval_of (EMACS_INT, Lisp_Object); -/* Defined in xdisp.c */ +/* Defined in xdisp.c. */ extern int invisible_p (Lisp_Object, Lisp_Object); -/* Declared in textprop.c */ +/* Declared in textprop.c. */ -/* Types of hooks. */ +/* Types of hooks. */ extern Lisp_Object Qpoint_left; extern Lisp_Object Qpoint_entered; extern Lisp_Object Qmodification_hooks; @@ -301,11 +301,11 @@ extern Lisp_Object Qcategory; extern Lisp_Object Qlocal_map; extern Lisp_Object Qkeymap; -/* Visual properties text (including strings) may have. */ +/* Visual properties text (including strings) may have. */ extern Lisp_Object Qfont; extern Lisp_Object Qinvisible, Qintangible; -/* Sticky properties */ +/* Sticky properties. */ extern Lisp_Object Qfront_sticky, Qrear_nonsticky; EXFUN (Fget_char_property, 3);