Function: previous-single-property-change

previous-single-property-change is a function defined in textprop.c.

Signature

(previous-single-property-change POSITION PROP &optional OBJECT LIMIT)

Documentation

Return the position of previous property 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. The property values are compared with eq. Return nil if LIMIT is nil or omitted, and the property is constant all the way to the start of OBJECT; if the value is non-nil, it is a position less than POSITION, never equal.

If the optional fourth argument LIMIT is non-nil, don't search back past position LIMIT; return LIMIT if nothing is found until LIMIT.

Other relevant functions are documented in the text-properties group.

View in manual

Probably introduced at or before Emacs version 19.23.

Shortdoc

;; text-properties
(previous-single-property-change (point) 'face (current-buffer))

Aliases

kproperty:previous-single-change

Source Code

// Defined in /usr/src/emacs/src/textprop.c
{
  register INTERVAL i, previous;
  register Lisp_Object here_val;

  if (NILP (object))
    XSETBUFFER (object, current_buffer);

  if (!NILP (limit))
    CHECK_FIXNUM_COERCE_MARKER (limit);

  i = validate_interval_range (object, &position, &position, soft);

  /* Start with the interval containing the char before point.  */
  if (i && i->position == XFIXNAT (position))
    i = previous_interval (i);

  if (!i)
    return limit;

  here_val = textget (i->plist, prop);
  previous = previous_interval (i);
  while (previous
	 && EQ (here_val, textget (previous->plist, prop))
	 && (NILP (limit)
	     || (previous->position + LENGTH (previous) > XFIXNUM (limit))))
    previous = previous_interval (previous);

  if (!previous
      || (previous->position + LENGTH (previous)
	  <= (FIXNUMP (limit)
	      ? XFIXNUM (limit)
	      : (STRINGP (object) ? 0 : BUF_BEGV (XBUFFER (object))))))
    return limit;
  else
    return make_fixnum (previous->position + LENGTH (previous));
}