]> code.delx.au - gnu-emacs/blobdiff - src/textprop.c
Merge from emacs-24; up to 2012-12-17T11:17:34Z!rgm@gnu.org
[gnu-emacs] / src / textprop.c
index 5366249be89b1893859ef4b7040f8d4aa332f0f1..c1f6e59bf2e9bc16b0061250595e2fd2084927b6 100644 (file)
@@ -1,5 +1,6 @@
 /* Interface code for dealing with text properties.
-   Copyright (C) 1993-1995, 1997, 1999-2012 Free Software Foundation, Inc.
+   Copyright (C) 1993-1995, 1997, 1999-2013 Free Software Foundation,
+   Inc.
 
 This file is part of GNU Emacs.
 
@@ -17,7 +18,7 @@ You should have received a copy of the GNU General Public License
 along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
-#include <setjmp.h>
+
 #include "lisp.h"
 #include "intervals.h"
 #include "character.h"
@@ -85,8 +86,18 @@ text_read_only (Lisp_Object propval)
   xsignal0 (Qtext_read_only);
 }
 
+/* Prepare to modify the region of BUFFER from START to END.  */
+
+static void
+modify_region (Lisp_Object buffer, Lisp_Object start, Lisp_Object end)
+{
+  struct buffer *buf = XBUFFER (buffer), *old = current_buffer;
+
+  set_buffer_internal (buf);
+  modify_region_1 (XINT (start), XINT (end), true);
+  set_buffer_internal (old);
+}
 
-\f
 /* Extract the interval at the position pointed to by BEGIN from
    OBJECT, a string or buffer.  Additionally, check that the positions
    pointed to by BEGIN and END are within the bounds of OBJECT, and
@@ -143,7 +154,7 @@ validate_interval_range (Lisp_Object object, Lisp_Object *begin, Lisp_Object *en
       if (!(BUF_BEGV (b) <= XINT (*begin) && XINT (*begin) <= XINT (*end)
            && XINT (*end) <= BUF_ZV (b)))
        args_out_of_range (*begin, *end);
-      i = BUF_INTERVALS (b);
+      i = buffer_intervals (b);
 
       /* If there's no text, there are no properties.  */
       if (BUF_BEGV (b) == BUF_ZV (b))
@@ -161,7 +172,7 @@ validate_interval_range (Lisp_Object object, Lisp_Object *begin, Lisp_Object *en
       XSETFASTINT (*begin, XFASTINT (*begin));
       if (begin != end)
        XSETFASTINT (*end, XFASTINT (*end));
-      i = string_get_intervals (object);
+      i = string_intervals (object);
 
       if (len == 0)
        return NULL;
@@ -241,7 +252,7 @@ interval_has_all_properties (Lisp_Object plist, INTERVAL i)
 /* Return nonzero if the plist of interval I has any of the
    properties of PLIST, regardless of their values.  */
 
-static inline int
+static int
 interval_has_some_properties (Lisp_Object plist, INTERVAL i)
 {
   register Lisp_Object tail1, tail2, sym;
@@ -263,7 +274,7 @@ interval_has_some_properties (Lisp_Object plist, INTERVAL i)
 /* Return nonzero if the plist of interval I has any of the
    property names in LIST, regardless of their values.  */
 
-static inline int
+static int
 interval_has_some_properties_list (Lisp_Object list, INTERVAL i)
 {
   register Lisp_Object tail1, tail2, sym;
@@ -338,7 +349,7 @@ set_properties (Lisp_Object properties, INTERVAL interval, Lisp_Object object)
     }
 
   /* Store new properties.  */
-  interval_set_plist (interval, Fcopy_sequence (properties));
+  set_interval_plist (interval, Fcopy_sequence (properties));
 }
 
 /* Add the properties of PLIST to the interval I, or set
@@ -411,7 +422,7 @@ add_properties (Lisp_Object plist, INTERVAL i, Lisp_Object object)
              record_property_change (i->position, LENGTH (i),
                                      sym1, Qnil, object);
            }
-         interval_set_plist (i, Fcons (sym1, Fcons (val1, i->plist)));
+         set_interval_plist (i, Fcons (sym1, Fcons (val1, i->plist)));
          changed++;
        }
     }
@@ -484,7 +495,7 @@ remove_properties (Lisp_Object plist, Lisp_Object list, INTERVAL i, Lisp_Object
     }
 
   if (changed)
-    interval_set_plist (i, current_plist);
+    set_interval_plist (i, current_plist);
   return changed;
 }
 \f
@@ -510,13 +521,13 @@ interval_of (ptrdiff_t position, Lisp_Object object)
 
       beg = BUF_BEGV (b);
       end = BUF_ZV (b);
-      i = BUF_INTERVALS (b);
+      i = buffer_intervals (b);
     }
   else
     {
       beg = 0;
       end = SCHARS (object);
-      i = string_get_intervals (object);
+      i = string_intervals (object);
     }
 
   if (!(beg <= position && position <= end))
@@ -556,7 +567,8 @@ If POSITION is at the end of OBJECT, the value is nil.  */)
 
 DEFUN ("get-text-property", Fget_text_property, Sget_text_property, 2, 3, 0,
        doc: /* Return the value of POSITION's property PROP, in OBJECT.
-OBJECT is optional and defaults to the current buffer.
+OBJECT should be a buffer or a string; if omitted or nil, it defaults
+to the current buffer.
 If POSITION is at the end of OBJECT, the value is nil.  */)
   (Lisp_Object position, Lisp_Object prop, Lisp_Object object)
 {
@@ -760,7 +772,7 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT.  */)
 
       if (BUFFERP (object) && current_buffer != XBUFFER (object))
        {
-         record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
+         record_unwind_current_buffer ();
          Fset_buffer (object);
        }
 
@@ -843,7 +855,7 @@ position LIMIT; return LIMIT if nothing is found before reaching LIMIT.  */)
 
       if (BUFFERP (object) && current_buffer != XBUFFER (object))
        {
-         record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
+         record_unwind_current_buffer ();
          Fset_buffer (object);
        }
 
@@ -1163,7 +1175,7 @@ Return t if any property value actually changed, nil otherwise.  */)
     }
 
   if (BUFFERP (object))
-    modify_region (XBUFFER (object), XINT (start), XINT (end), 1);
+    modify_region (object, start, end);
 
   /* We are at the beginning of interval I, with LEN chars to scan.  */
   for (;;)
@@ -1274,10 +1286,10 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
       && XFASTINT (start) == 0
       && XFASTINT (end) == SCHARS (object))
     {
-      if (!string_get_intervals (object))
+      if (!string_intervals (object))
        return Qnil;
 
-      string_set_intervals (object, NULL);
+      set_string_intervals (object, NULL);
       return Qt;
     }
 
@@ -1301,7 +1313,7 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
     }
 
   if (BUFFERP (object) && !NILP (coherent_change_p))
-    modify_region (XBUFFER (object), XINT (start), XINT (end), 1);
+    modify_region (object, start, end);
 
   set_text_properties_1 (start, end, properties, object, i);
 
@@ -1312,14 +1324,13 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
 }
 
 /* Replace properties of text from START to END with new list of
-   properties PROPERTIES.  BUFFER is the buffer containing
+   properties PROPERTIES.  OBJECT is the buffer or string containing
    the text.  This does not obey any hooks.
-   You can provide the interval that START is located in as I,
-   or pass NULL for I and this function will find it.
+   You should provide the interval that START is located in as I.
    START and END can be in any order.  */
 
 void
-set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object buffer, INTERVAL i)
+set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object object, INTERVAL i)
 {
   register INTERVAL prev_changed = NULL;
   register ptrdiff_t s, len;
@@ -1338,8 +1349,7 @@ set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object propertie
   else
     return;
 
-  if (i == 0)
-    i = find_interval (BUF_INTERVALS (XBUFFER (buffer)), s);
+  eassert (i);
 
   if (i->position != s)
     {
@@ -1350,11 +1360,11 @@ set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object propertie
        {
          copy_properties (unchanged, i);
          i = split_interval_left (i, len);
-         set_properties (properties, i, buffer);
+         set_properties (properties, i, object);
          return;
        }
 
-      set_properties (properties, i, buffer);
+      set_properties (properties, i, object);
 
       if (LENGTH (i) == len)
        return;
@@ -1377,7 +1387,7 @@ set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object propertie
          /* We have to call set_properties even if we are going to
             merge the intervals, so as to make the undo records
             and cause redisplay to happen.  */
-         set_properties (properties, i, buffer);
+         set_properties (properties, i, object);
          if (prev_changed)
            merge_interval_left (i);
          return;
@@ -1388,7 +1398,7 @@ set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object propertie
       /* We have to call set_properties even if we are going to
         merge the intervals, so as to make the undo records
         and cause redisplay to happen.  */
-      set_properties (properties, i, buffer);
+      set_properties (properties, i, object);
       if (!prev_changed)
        prev_changed = i;
       else
@@ -1450,7 +1460,7 @@ Use `set-text-properties' if you want to remove all text properties.  */)
     }
 
   if (BUFFERP (object))
-    modify_region (XBUFFER (object), XINT (start), XINT (end), 1);
+    modify_region (object, start, end);
 
   /* We are at the beginning of an interval, with len to scan */
   for (;;)
@@ -1564,7 +1574,7 @@ Return t if any property was actually removed, nil otherwise.  */)
          else if (LENGTH (i) == len)
            {
              if (!modified && BUFFERP (object))
-               modify_region (XBUFFER (object), XINT (start), XINT (end), 1);
+               modify_region (object, start, end);
              remove_properties (Qnil, properties, i, object);
              if (BUFFERP (object))
                signal_after_change (XINT (start), XINT (end) - XINT (start),
@@ -1577,7 +1587,7 @@ Return t if any property was actually removed, nil otherwise.  */)
              i = split_interval_left (i, len);
              copy_properties (unchanged, i);
              if (!modified && BUFFERP (object))
-               modify_region (XBUFFER (object), XINT (start), XINT (end), 1);
+               modify_region (object, start, end);
              remove_properties (Qnil, properties, i, object);
              if (BUFFERP (object))
                signal_after_change (XINT (start), XINT (end) - XINT (start),
@@ -1588,7 +1598,7 @@ Return t if any property was actually removed, nil otherwise.  */)
       if (interval_has_some_properties_list (properties, i))
        {
          if (!modified && BUFFERP (object))
-           modify_region (XBUFFER (object), XINT (start), XINT (end), 1);
+           modify_region (object, start, end);
          remove_properties (Qnil, properties, i, object);
          modified = 1;
        }
@@ -1993,10 +2003,10 @@ void
 verify_interval_modification (struct buffer *buf,
                              ptrdiff_t start, ptrdiff_t end)
 {
-  register INTERVAL intervals = BUF_INTERVALS (buf);
-  register INTERVAL i;
+  INTERVAL intervals = buffer_intervals (buf);
+  INTERVAL i;
   Lisp_Object hooks;
-  register Lisp_Object prev_mod_hooks;
+  Lisp_Object prev_mod_hooks;
   Lisp_Object mod_hooks;
   struct gcpro gcpro1;