+/* If text at position POS has property PROP, set *VAL to the property
+ value, *START and *END to the beginning and end of a region that
+ has the same property, and return 1. Otherwise return 0.
+
+ OBJECT is the string or buffer to look for the property in;
+ nil means the current buffer. */
+
+int
+get_property_and_range (pos, prop, val, start, end, object)
+ int pos;
+ Lisp_Object prop, *val;
+ int *start, *end;
+ Lisp_Object object;
+{
+ INTERVAL i, prev, next;
+
+ if (NILP (object))
+ i = find_interval (BUF_INTERVALS (current_buffer), pos);
+ else if (BUFFERP (object))
+ i = find_interval (BUF_INTERVALS (XBUFFER (object)), pos);
+ else if (STRINGP (object))
+ i = find_interval (XSTRING (object)->intervals, pos);
+ else
+ abort ();
+
+ if (NULL_INTERVAL_P (i) || (i->position + LENGTH (i) <= pos))
+ return 0;
+ *val = textget (i->plist, prop);
+ if (NILP (*val))
+ return 0;
+
+ next = i; /* remember it in advance */
+ prev = previous_interval (i);
+ while (! NULL_INTERVAL_P (prev)
+ && EQ (*val, textget (prev->plist, prop)))
+ i = prev, prev = previous_interval (prev);
+ *start = i->position;
+
+ next = next_interval (i);
+ while (! NULL_INTERVAL_P (next)
+ && EQ (*val, textget (next->plist, prop)))
+ i = next, next = next_interval (next);
+ *end = i->position + LENGTH (i);
+
+ return 1;
+}
+\f