diff src/fns.c @ 54373:9685a42b7c56

(internal_equal): New arg PROPS controls comparing text properties. All callers changed. (Fequal_including_properties): New function. (syms_of_fns): defsubr it.
author Richard M. Stallman <rms@gnu.org>
date Fri, 12 Mar 2004 10:07:36 +0000
parents 7848629711b6
children 1b818fd4a373
line wrap: on
line diff
--- a/src/fns.c	Thu Mar 11 22:56:19 2004 +0000
+++ b/src/fns.c	Fri Mar 12 10:07:36 2004 +0000
@@ -2146,13 +2146,27 @@
      (o1, o2)
      register Lisp_Object o1, o2;
 {
-  return internal_equal (o1, o2, 0) ? Qt : Qnil;
+  return internal_equal (o1, o2, 0, 0) ? Qt : Qnil;
 }
 
+DEFUN ("equal-including-properties", Fequal_including_properties, Sequal_including_properties, 2, 2, 0,
+       doc: /* Return t if two Lisp objects have similar structure and contents.
+This is like `equal' except that it compares the text properties
+of strings.  (`equal' ignores text properties.)  */)
+     (o1, o2)
+     register Lisp_Object o1, o2;
+{
+  return internal_equal (o1, o2, 0, 1) ? Qt : Qnil;
+}
+
+/* DEPTH is current depth of recursion.  Signal an error if it
+   gets too deep.
+   PROPS, if non-nil, means compare string text properties too.  */
+
 static int
-internal_equal (o1, o2, depth)
+internal_equal (o1, o2, depth, props)
      register Lisp_Object o1, o2;
-     int depth;
+     int depth, props;
 {
   if (depth > 200)
     error ("Stack overflow in equal");
@@ -2178,7 +2192,7 @@
       }
 
     case Lisp_Cons:
-      if (!internal_equal (XCAR (o1), XCAR (o2), depth + 1))
+      if (!internal_equal (XCAR (o1), XCAR (o2), depth + 1, props))
 	return 0;
       o1 = XCDR (o1);
       o2 = XCDR (o2);
@@ -2190,7 +2204,7 @@
       if (OVERLAYP (o1))
 	{
 	  if (!internal_equal (OVERLAY_START (o1), OVERLAY_START (o2),
-			       depth + 1)
+			       depth + 1, props)
 	      || !internal_equal (OVERLAY_END (o1), OVERLAY_END (o2),
 				  depth + 1))
 	    return 0;
@@ -2244,7 +2258,7 @@
 	    Lisp_Object v1, v2;
 	    v1 = XVECTOR (o1)->contents [i];
 	    v2 = XVECTOR (o2)->contents [i];
-	    if (!internal_equal (v1, v2, depth + 1))
+	    if (!internal_equal (v1, v2, depth + 1, props))
 	      return 0;
 	  }
 	return 1;
@@ -2259,6 +2273,8 @@
       if (bcmp (SDATA (o1), SDATA (o2),
 		SBYTES (o1)))
 	return 0;
+      if (props && !compare_string_intervals (o1, o2))
+	return 0;
       return 1;
 
     case Lisp_Int:
@@ -5725,6 +5741,7 @@
   defsubr (&Slax_plist_get);
   defsubr (&Slax_plist_put);
   defsubr (&Sequal);
+  defsubr (&Sequal_including_properties);
   defsubr (&Sfillarray);
   defsubr (&Sclear_string);
   defsubr (&Schar_table_subtype);