Function: get-pos-property

get-pos-property is a function defined in editfns.c.

Signature

(get-pos-property POSITION PROP &optional OBJECT)

Documentation

Return the value of POSITION's property PROP, in OBJECT.

Almost identical to get-char-property except for the following difference: Whereas get-char-property returns the property of the char at (i.e. right after) POSITION, this pays attention to properties's stickiness and overlays's advancement settings, in order to find the property of POSITION itself, i.e. the property that a char would inherit if it were inserted at POSITION.

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

View in manual

Probably introduced at or before Emacs version 24.4.

Shortdoc

;; text-properties
(get-pos-property 0 'foo (propertize "x" 'foo t))
    => t

Source Code

// Defined in /usr/src/emacs/src/editfns.c
{
  CHECK_FIXNUM_COERCE_MARKER (position);

  if (NILP (object))
    XSETBUFFER (object, current_buffer);
  else if (WINDOWP (object))
    object = XWINDOW (object)->contents;

  if (!BUFFERP (object))
    /* pos-property only makes sense in buffers right now, since strings
       have no overlays and no notion of insertion for which stickiness
       could be obeyed.  */
    return Fget_text_property (position, prop, object);
  else
    {
      EMACS_INT posn = XFIXNUM (position);
      Lisp_Object tem;
      struct buffer *obuf = current_buffer;
      struct itree_node *node;
      struct sortvec items[2];
      struct buffer *b = XBUFFER (object);
      struct sortvec *result = NULL;
      Lisp_Object res = Qnil;

      set_buffer_temp (b);

      ITREE_FOREACH (node, b->overlays, posn - 1, posn + 1, ASCENDING)
	{
	  Lisp_Object ol = node->data;
	  tem = Foverlay_get (ol, prop);
	  if (NILP (tem)
	      /* Check the overlay is indeed active at point.  */
	      || ((node->begin == posn
		   && OVERLAY_FRONT_ADVANCE_P (ol))
		  || (node->end == posn
		      && ! OVERLAY_REAR_ADVANCE_P (ol))
		  || node->begin > posn
		  || node->end < posn))
	    /* The overlay will not cover a char inserted at point.  */
	    continue;

	  struct sortvec *this = (result == items ? items + 1 : items);
          if (NILP (res)
              || (make_sortvec_item (this, node->data),
                  compare_overlays (result, this) < 0))
            {
              result = this;
              res = tem;
            }
	}
      set_buffer_temp (obuf);

      if (!NILP (res))
        return res;

      { /* Now check the text properties.  */
	int stickiness = text_property_stickiness (prop, position, object);
	if (stickiness > 0)
	  return Fget_text_property (position, prop, object);
	else if (stickiness < 0
		 && XFIXNUM (position) > BUF_BEGV (XBUFFER (object)))
	  return Fget_text_property (make_fixnum (XFIXNUM (position) - 1),
				     prop, object);
	else
	  return Qnil;
      }
    }
}