Function: previous-single-char-property-change
previous-single-char-property-change is a function defined in
textprop.c.
Signature
(previous-single-char-property-change POSITION PROP &optional OBJECT LIMIT)
Documentation
Return the position of previous text property or overlay change for a specific property.
Scans characters backward from POSITION till it finds a change in the PROP property, then returns the position of the change. If the optional third argument OBJECT is a buffer (or nil, which means the current buffer), POSITION is a buffer position (integer or marker). If OBJECT is a string, POSITION is a 0-based index into it.
In a string, scan runs to the start of the string, unless LIMIT is non-nil. In a buffer, if LIMIT is nil or omitted, it runs to (point-min), and the value cannot be less than that. If the optional fourth argument LIMIT is non-nil, don't search back past position LIMIT; return LIMIT if nothing is found before reaching LIMIT.
The property values are compared with eq.
If the property is constant all the way to the start of OBJECT, return the
first valid position in OBJECT.
Aliases
allout-previous-single-char-property-change (obsolete since 28.1)
Source Code
// Defined in /usr/src/emacs/src/textprop.c
{
if (STRINGP (object))
{
position = Fprevious_single_property_change (position, prop, object, limit);
if (NILP (position))
{
if (NILP (limit))
position = make_fixnum (0);
else
{
CHECK_FIXNUM (limit);
position = limit;
}
}
}
else
{
ptrdiff_t count = SPECPDL_INDEX ();
if (! NILP (object))
CHECK_BUFFER (object);
if (BUFFERP (object) && current_buffer != XBUFFER (object))
{
record_unwind_current_buffer ();
Fset_buffer (object);
}
CHECK_FIXNUM_COERCE_MARKER (position);
if (NILP (limit))
XSETFASTINT (limit, BEGV);
else
CHECK_FIXNUM_COERCE_MARKER (limit);
if (XFIXNUM (position) <= XFIXNUM (limit))
{
position = limit;
if (XFIXNUM (position) < BEGV)
XSETFASTINT (position, BEGV);
}
else
{
Lisp_Object initial_value
= Fget_char_property (make_fixnum (XFIXNUM (position)
- (0 <= XFIXNUM (position))),
prop, object);
while (true)
{
position = Fprevious_char_property_change (position, limit);
if (XFIXNAT (position) <= XFIXNAT (limit))
{
position = limit;
break;
}
else
{
Lisp_Object value
= Fget_char_property (make_fixnum (XFIXNAT (position) - 1),
prop, object);
if (!EQ (value, initial_value))
break;
}
}
}
position = unbind_to (count, position);
}
return position;
}