summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1993-11-20 09:44:27 +0000
committerRichard M. Stallman <rms@gnu.org>1993-11-20 09:44:27 +0000
commitfe6876dad2a483956778ca19fd833f04788e803b (patch)
treeba1e3c1c06f252564cdbcfeb2922dfb4d2864f0d
parenta4c1b691d971a93d9271163c81f8d00ef6570d51 (diff)
downloademacs-fe6876dad2a483956778ca19fd833f04788e803b.tar.gz
(Ftext_property_not_all): Swap t and nil values in
the case where there are no intervals. (Fprevious_single_property_change, Fprevious_property_change) Extra arg LIMIT. Return value was off by 1. (Fnext_single_property_change, Fnext_property_change): Extra arg LIMIT. (Fnext_single_property_change): Require at least 2 args.
-rw-r--r--src/textprop.c86
1 files changed, 55 insertions, 31 deletions
diff --git a/src/textprop.c b/src/textprop.c
index f4adb23b31b..a95b9a9af5d 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -520,15 +520,17 @@ If POSITION is at the end of OBJECT, the value is nil.")
}
DEFUN ("next-property-change", Fnext_property_change,
- Snext_property_change, 1, 2, 0,
+ Snext_property_change, 1, 3, 0,
"Return the position of next property change.\n\
Scans characters forward from POS in OBJECT till it finds\n\
a change in some text property, then returns the position of the change.\n\
The optional second argument OBJECT is the string or buffer to scan.\n\
Return nil if the property is constant all the way to the end of OBJECT.\n\
-If the value is non-nil, it is a position greater than POS, never equal.")
- (pos, object)
- Lisp_Object pos, object;
+If the value is non-nil, it is a position greater than POS, never equal.\n\n\
+If the optional third argument LIMIT is non-nil, don't search\n\
+past position LIMIT; return LIMIT if nothing is found before LIMIT.")
+ (pos, object, limit)
+ Lisp_Object pos, object, limit;
{
register INTERVAL i, next;
@@ -537,14 +539,17 @@ If the value is non-nil, it is a position greater than POS, never equal.")
i = validate_interval_range (object, &pos, &pos, soft);
if (NULL_INTERVAL_P (i))
- return Qnil;
+ return limit;
next = next_interval (i);
- while (! NULL_INTERVAL_P (next) && intervals_equal (i, next))
+ while (! NULL_INTERVAL_P (next) && intervals_equal (i, next)
+ && (NILP (limit) || next->position < XFASTINT (limit)))
next = next_interval (next);
if (NULL_INTERVAL_P (next))
- return Qnil;
+ return limit;
+ if (! NILP (limit) && !(next->position < XFASTINT (limit)))
+ return limit;
return next->position - (XTYPE (object) == Lisp_String);
}
@@ -582,16 +587,18 @@ property_change_between_p (beg, end)
}
DEFUN ("next-single-property-change", Fnext_single_property_change,
- Snext_single_property_change, 1, 3, 0,
+ Snext_single_property_change, 2, 4, 0,
"Return the position of next property change for a specific property.\n\
Scans characters forward from POS till it finds\n\
a change in the PROP property, then returns the position of the change.\n\
The optional third argument OBJECT is the string or buffer to scan.\n\
The property values are compared with `eq'.\n\
Return nil if the property is constant all the way to the end of OBJECT.\n\
-If the value is non-nil, it is a position greater than POS, never equal.")
- (pos, prop, object)
- Lisp_Object pos, prop, object;
+If the value is non-nil, it is a position greater than POS, never equal.\n\n\
+If the optional fourth argument LIMIT is non-nil, don't search\n\
+past position LIMIT; fail if nothing is found before LIMIT.")
+ (pos, prop, object, limit)
+ Lisp_Object pos, prop, object, limit;
{
register INTERVAL i, next;
register Lisp_Object here_val;
@@ -601,30 +608,35 @@ If the value is non-nil, it is a position greater than POS, never equal.")
i = validate_interval_range (object, &pos, &pos, soft);
if (NULL_INTERVAL_P (i))
- return Qnil;
+ return limit;
here_val = textget (i->plist, prop);
next = next_interval (i);
while (! NULL_INTERVAL_P (next)
- && EQ (here_val, textget (next->plist, prop)))
+ && EQ (here_val, textget (next->plist, prop))
+ && (NILP (limit) || next->position < XFASTINT (limit)))
next = next_interval (next);
if (NULL_INTERVAL_P (next))
- return Qnil;
+ return limit;
+ if (! NILP (limit) && !(next->position < XFASTINT (limit)))
+ return limit;
return next->position - (XTYPE (object) == Lisp_String);
}
DEFUN ("previous-property-change", Fprevious_property_change,
- Sprevious_property_change, 1, 2, 0,
+ Sprevious_property_change, 1, 3, 0,
"Return the position of previous property change.\n\
Scans characters backwards from POS in OBJECT till it finds\n\
a change in some text property, then returns the position of the change.\n\
The optional second argument OBJECT is the string or buffer to scan.\n\
Return nil if the property is constant all the way to the start of OBJECT.\n\
-If the value is non-nil, it is a position less than POS, never equal.")
- (pos, object)
- Lisp_Object pos, object;
+If the value is non-nil, it is a position less than POS, never equal.\n\n\
+If the optional third argument LIMIT is non-nil, don't search\n\
+back past position LIMIT; fail if nothing is found before LIMIT.")
+ (pos, object, limit)
+ Lisp_Object pos, object, limit;
{
register INTERVAL i, previous;
@@ -633,29 +645,36 @@ If the value is non-nil, it is a position less than POS, never equal.")
i = validate_interval_range (object, &pos, &pos, soft);
if (NULL_INTERVAL_P (i))
- return Qnil;
+ return limit;
previous = previous_interval (i);
- while (! NULL_INTERVAL_P (previous) && intervals_equal (previous, i))
+ while (! NULL_INTERVAL_P (previous) && intervals_equal (previous, i)
+ && (NILP (limit)
+ || previous->position + LENGTH (previous) > XFASTINT (limit)))
previous = previous_interval (previous);
if (NULL_INTERVAL_P (previous))
- return Qnil;
+ return limit;
+ if (!NILP (limit)
+ && !(previous->position + LENGTH (previous) > XFASTINT (limit)))
+ return limit;
- return (previous->position + LENGTH (previous) - 1
+ return (previous->position + LENGTH (previous)
- (XTYPE (object) == Lisp_String));
}
DEFUN ("previous-single-property-change", Fprevious_single_property_change,
- Sprevious_single_property_change, 2, 3, 0,
+ Sprevious_single_property_change, 2, 4, 0,
"Return the position of previous property change for a specific property.\n\
Scans characters backward from POS till it finds\n\
a change in the PROP property, then returns the position of the change.\n\
The optional third argument OBJECT is the string or buffer to scan.\n\
The property values are compared with `eq'.\n\
Return nil if the property is constant all the way to the start of OBJECT.\n\
-If the value is non-nil, it is a position less than POS, never equal.")
- (pos, prop, object)
- Lisp_Object pos, prop, object;
+If the value is non-nil, it is a position less than POS, never equal.\n\n\
+If the optional fourth argument LIMIT is non-nil, don't search\n\
+back past position LIMIT; fail if nothing is found before LIMIT.")
+ (pos, prop, object, limit)
+ Lisp_Object pos, prop, object, limit;
{
register INTERVAL i, previous;
register Lisp_Object here_val;
@@ -665,17 +684,22 @@ If the value is non-nil, it is a position less than POS, never equal.")
i = validate_interval_range (object, &pos, &pos, soft);
if (NULL_INTERVAL_P (i))
- return Qnil;
+ return limit;
here_val = textget (i->plist, prop);
previous = previous_interval (i);
while (! NULL_INTERVAL_P (previous)
- && EQ (here_val, textget (previous->plist, prop)))
+ && EQ (here_val, textget (previous->plist, prop))
+ && (NILP (limit)
+ || previous->position + LENGTH (previous) > XFASTINT (limit)))
previous = previous_interval (previous);
if (NULL_INTERVAL_P (previous))
- return Qnil;
+ return limit;
+ if (!NILP (limit)
+ && !(previous->position + LENGTH (previous) > XFASTINT (limit)))
+ return limit;
- return (previous->position + LENGTH (previous) - 1
+ return (previous->position + LENGTH (previous)
- (XTYPE (object) == Lisp_String));
}
@@ -986,7 +1010,7 @@ containing the text.")
XSET (object, Lisp_Buffer, current_buffer);
i = validate_interval_range (object, &start, &end, soft);
if (NULL_INTERVAL_P (i))
- return (NILP (value) || EQ (start, end)) ? Qt : Qnil;
+ return (NILP (value) || EQ (start, end)) ? Qnil : Qt;
s = XINT (start);
e = XINT (end);