]> code.delx.au - gnu-emacs/blobdiff - src/textprop.c
* character.h (CHAR_PRINTABLE_P): Reparenthesize to avoid warning.
[gnu-emacs] / src / textprop.c
index f7952e30d2f77aa621767807b637ea55c2f4fc71..83d09cce5584ff4c3348613456ac2d0eed0ca3f9 100644 (file)
@@ -1,6 +1,6 @@
 /* Interface code for dealing with text properties.
    Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -2030,24 +2030,41 @@ add_text_properties_from_list (object, list, delta)
 
 
 
-/* Modify end-points of ranges in LIST destructively.  LIST is a list
-   as returned from text_property_list.  Change end-points equal to
-   OLD_END to NEW_END.  */
+/* Modify end-points of ranges in LIST destructively, and return the
+   new list.  LIST is a list as returned from text_property_list.
+   Discard properties that begin at or after NEW_END, and limit
+   end-points to NEW_END.  */
 
-void
-extend_property_ranges (list, old_end, new_end)
-     Lisp_Object list, old_end, new_end;
+Lisp_Object
+extend_property_ranges (list, new_end)
+     Lisp_Object list, new_end;
 {
-  for (; CONSP (list); list = XCDR (list))
+  Lisp_Object prev = Qnil, head = list;
+  int max = XINT (new_end);
+
+  for (; CONSP (list); prev = list, list = XCDR (list))
     {
-      Lisp_Object item, end;
+      Lisp_Object item, beg, end;
 
       item = XCAR (list);
+      beg = XCAR (item);
       end = XCAR (XCDR (item));
 
-      if (EQ (end, old_end))
+      if (XINT (beg) >= max)
+       {
+         /* The start-point is past the end of the new string.
+            Discard this property.  */
+         if (EQ (head, list))
+           head = XCDR (list);
+         else
+           XSETCDR (prev, XCDR (list));
+       }
+      else if (XINT (end) > max)
+       /* The end-point is past the end of the new string.  */
        XSETCAR (XCDR (item), new_end);
     }
+
+  return head;
 }