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.
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);
ptrdiff_t noverlays;
Lisp_Object *overlay_vec, tem;
struct buffer *obuf = current_buffer;
USE_SAFE_ALLOCA;
set_buffer_temp (XBUFFER (object));
/* First try with room for 40 overlays. */
Lisp_Object overlay_vecbuf[40];
noverlays = ARRAYELTS (overlay_vecbuf);
overlay_vec = overlay_vecbuf;
noverlays = overlays_around (posn, overlay_vec, noverlays);
/* If there are more than 40,
make enough space for all, and try again. */
if (ARRAYELTS (overlay_vecbuf) < noverlays)
{
SAFE_ALLOCA_LISP (overlay_vec, noverlays);
noverlays = overlays_around (posn, overlay_vec, noverlays);
}
noverlays = sort_overlays (overlay_vec, noverlays, NULL);
set_buffer_temp (obuf);
/* Now check the overlays in order of decreasing priority. */
while (--noverlays >= 0)
{
Lisp_Object ol = overlay_vec[noverlays];
tem = Foverlay_get (ol, prop);
if (!NILP (tem))
{
/* Check the overlay is indeed active at point. */
Lisp_Object start = OVERLAY_START (ol), finish = OVERLAY_END (ol);
if ((OVERLAY_POSITION (start) == posn
&& XMARKER (start)->insertion_type == 1)
|| (OVERLAY_POSITION (finish) == posn
&& XMARKER (finish)->insertion_type == 0))
; /* The overlay will not cover a char inserted at point. */
else
{
SAFE_FREE ();
return tem;
}
}
}
SAFE_FREE ();
{ /* 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;
}
}
}