]> code.delx.au - gnu-emacs/blobdiff - src/textprop.c
Update years in copyright notice; nfc.
[gnu-emacs] / src / textprop.c
index a243eb6c9177044c074638ecfd9ee80c171a188a..fa9b0e498c5bbd0ff785db7a2dde0f8397728e3d 100644 (file)
@@ -1,6 +1,6 @@
 /* Interface code for dealing with text properties.
-   Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003
-   Free Software Foundation, Inc.
+   Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
+                 2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -16,8 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #include <config.h>
 #include "lisp.h"
@@ -637,30 +637,13 @@ get_char_property_and_overlay (position, prop, object, overlay)
     }
   if (BUFFERP (object))
     {
-      int posn = XINT (position);
       int noverlays;
-      Lisp_Object *overlay_vec, tem;
-      int len;
+      Lisp_Object *overlay_vec;
       struct buffer *obuf = current_buffer;
 
       set_buffer_temp (XBUFFER (object));
 
-      /* First try with room for 40 overlays.  */
-      len = 40;
-      overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
-
-      noverlays = overlays_at (posn, 0, &overlay_vec, &len,
-                              NULL, NULL, 0);
-
-      /* If there are more than 40,
-        make enough space for all, and try again.  */
-      if (noverlays > len)
-       {
-         len = noverlays;
-         overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
-         noverlays = overlays_at (posn, 0, &overlay_vec, &len,
-                                  NULL, NULL, 0);
-       }
+      GET_OVERLAYS_AT (XINT (position), overlay_vec, noverlays, NULL, 0);
       noverlays = sort_overlays (overlay_vec, noverlays, w);
 
       set_buffer_temp (obuf);
@@ -668,7 +651,7 @@ get_char_property_and_overlay (position, prop, object, overlay)
       /* Now check the overlays in order of decreasing priority.  */
       while (--noverlays >= 0)
        {
-         tem = Foverlay_get (overlay_vec[noverlays], prop);
+         Lisp_Object tem = Foverlay_get (overlay_vec[noverlays], prop);
          if (!NILP (tem))
            {
              if (overlay)
@@ -703,6 +686,30 @@ overlays are considered only if they are associated with OBJECT.  */)
 {
   return get_char_property_and_overlay (position, prop, object, 0);
 }
+
+DEFUN ("get-char-property-and-overlay", Fget_char_property_and_overlay,
+       Sget_char_property_and_overlay, 2, 3, 0,
+       doc: /* Like `get-char-property', but with extra overlay information.
+Return a cons whose car is the return value of `get-char-property'
+with the same arguments, that is, the value of POSITION's property
+PROP in OBJECT, and whose cdr is the overlay in which the property was
+found, or nil, if it was found as a text property or not found at all.
+OBJECT is optional and defaults to the current buffer.  OBJECT may be
+a string, a buffer or a window.  For strings, the cdr of the return
+value is always nil, since strings do not have overlays.  If OBJECT is
+a window, then that window's buffer is used, but window-specific
+overlays are considered only if they are associated with OBJECT.  If
+POSITION is at the end of OBJECT, both car and cdr are nil.  */)
+     (position, prop, object)
+     Lisp_Object position, object;
+     register Lisp_Object prop;
+{
+  Lisp_Object overlay;
+  Lisp_Object val
+    = get_char_property_and_overlay (position, prop, object, &overlay);
+  return Fcons(val, overlay);
+}
+
 \f
 DEFUN ("next-char-property-change", Fnext_char_property_change,
        Snext_char_property_change, 1, 2, 0,
@@ -712,7 +719,7 @@ it finds a change in some text property, or the beginning or end of an
 overlay, and returns the position of that.
 If none is found, the function returns (point-max).
 
-If the optional third argument LIMIT is non-nil, don't search
+If the optional second argument LIMIT is non-nil, don't search
 past position LIMIT; return LIMIT if nothing is found before LIMIT.  */)
      (position, limit)
      Lisp_Object position, limit;
@@ -722,7 +729,7 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT.  */)
   temp = Fnext_overlay_change (position);
   if (! NILP (limit))
     {
-      CHECK_NUMBER (limit);
+      CHECK_NUMBER_COERCE_MARKER (limit);
       if (XINT (limit) < XINT (temp))
        temp = limit;
     }
@@ -737,7 +744,7 @@ finds a change in some text property, or the beginning or end of an
 overlay, and returns the position of that.
 If none is found, the function returns (point-max).
 
-If the optional third argument LIMIT is non-nil, don't search
+If the optional second argument LIMIT is non-nil, don't search
 past position LIMIT; return LIMIT if nothing is found before LIMIT.  */)
      (position, limit)
      Lisp_Object position, limit;
@@ -747,7 +754,7 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT.  */)
   temp = Fprevious_overlay_change (position);
   if (! NILP (limit))
     {
-      CHECK_NUMBER (limit);
+      CHECK_NUMBER_COERCE_MARKER (limit);
       if (XINT (limit) > XINT (temp))
        temp = limit;
     }
@@ -780,7 +787,10 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT.  */)
          if (NILP (limit))
            position = make_number (SCHARS (object));
          else
-           position = limit;
+           {
+             CHECK_NUMBER (limit);
+             position = limit;
+           }
        }
     }
   else
@@ -797,6 +807,8 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT.  */)
          Fset_buffer (object);
        }
 
+      CHECK_NUMBER_COERCE_MARKER (position);
+
       initial_value = Fget_char_property (position, prop, object);
 
       if (NILP (limit))
@@ -849,7 +861,10 @@ back past position LIMIT; return LIMIT if nothing is found before LIMIT.  */)
          if (NILP (limit))
            position = make_number (SCHARS (object));
          else
-           position = limit;
+           {
+             CHECK_NUMBER (limit);
+             position = limit;
+           }
        }
     }
   else
@@ -865,6 +880,8 @@ back past position LIMIT; return LIMIT if nothing is found before LIMIT.  */)
          Fset_buffer (object);
        }
 
+      CHECK_NUMBER_COERCE_MARKER (position);
+
       if (NILP (limit))
        XSETFASTINT (limit, BUF_BEGV (current_buffer));
       else
@@ -2226,7 +2243,9 @@ If a character in a buffer has PROPERTY, new text inserted adjacent to
 the character doesn't inherit PROPERTY if NONSTICKINESS is non-nil,
 inherits it if NONSTICKINESS is nil.  The front-sticky and
 rear-nonsticky properties of the character overrides NONSTICKINESS.  */);
-  Vtext_property_default_nonsticky = Qnil;
+  /* Text property `syntax-table' should be nonsticky by default.  */
+  Vtext_property_default_nonsticky
+    = Fcons (Fcons (intern ("syntax-table"), Qt), Qnil);
 
   staticpro (&interval_insert_behind_hooks);
   staticpro (&interval_insert_in_front_hooks);
@@ -2277,6 +2296,7 @@ rear-nonsticky properties of the character overrides NONSTICKINESS.  */);
   defsubr (&Stext_properties_at);
   defsubr (&Sget_text_property);
   defsubr (&Sget_char_property);
+  defsubr (&Sget_char_property_and_overlay);
   defsubr (&Snext_char_property_change);
   defsubr (&Sprevious_char_property_change);
   defsubr (&Snext_single_char_property_change);