- if (NILP (merge_at_boundary) && XFASTINT (pos) > BEGV)
- /* See if we need to handle the case where POS is at beginning of a
- field, which can also be interpreted as the end of the previous
- field. We decide which one by seeing which field the `field'
- property sticks to. The case where if MERGE_AT_BOUNDARY is
- non-nil (see function comment) is actually the more natural one;
- then we avoid treating the beginning of a field specially. */
- {
- /* First see if POS is actually *at* a boundary. */
- Lisp_Object after_field, before_field;
-
- after_field = Fget_text_property (pos, Qfield, Qnil);
- before_field = Fget_text_property (make_number (XINT (pos) - 1),
- Qfield, Qnil);
-
- if (! EQ (after_field, before_field))
- /* We are at a boundary, see which direction is inclusive. */
+ after_field
+ = get_char_property_and_overlay (pos, Qfield, Qnil, &after_overlay);
+ before_field
+ = (XFASTINT (pos) > BEGV
+ ? get_char_property_and_overlay (make_number (XINT (pos) - 1),
+ Qfield, Qnil,
+ &before_overlay)
+ : Qnil);
+
+ /* See if we need to handle the case where MERGE_AT_BOUNDARY is nil
+ and POS is at beginning of a field, which can also be interpreted
+ as the end of the previous field. Note that the case where if
+ MERGE_AT_BOUNDARY is non-nil (see function comment) is actually the
+ more natural one; then we avoid treating the beginning of a field
+ specially. */
+ if (NILP (merge_at_boundary) && !EQ (after_field, before_field))
+ /* We are at a boundary, see which direction is inclusive. We
+ decide by seeing which field the `field' property sticks to. */
+ {
+ /* -1 means insertions go into before_field, 1 means they go
+ into after_field, 0 means neither. */
+ int stickiness;
+ /* Whether the before/after_field come from overlays. */
+ int bop = !NILP (before_overlay);
+ int aop = !NILP (after_overlay);
+
+ if (bop && XMARKER (OVERLAY_END (before_overlay))->insertion_type == 1)
+ /* before_field is from an overlay, which expands upon
+ end-insertions. Note that it's possible for after_overlay to
+ also eat insertions here, but then they will overlap, and
+ there's not much we can do. */
+ stickiness = -1;
+ else if (aop
+ && XMARKER (OVERLAY_START (after_overlay))->insertion_type == 0)
+ /* after_field is from an overlay, which expand to contain
+ start-insertions. */
+ stickiness = 1;
+ else if (bop && aop)
+ /* Both fields come from overlays, but neither will contain any
+ insertion here. */
+ stickiness = 0;
+ else if (bop)
+ /* before_field is an overlay that won't eat any insertion, but
+ after_field is from a text-property. Assume that the
+ text-property continues underneath the overlay, and so will
+ be inherited by any insertion, regardless of any stickiness
+ settings. */
+ stickiness = 1;
+ else if (aop)
+ /* Similarly, when after_field is the overlay. */
+ stickiness = -1;
+ else
+ /* Both fields come from text-properties. Look for explicit
+ stickiness properties. */
+ stickiness = text_property_stickiness (Qfield, pos);
+
+ if (stickiness > 0)
+ at_field_start = 1;
+ else if (stickiness < 0)
+ at_field_end = 1;
+ else
+ /* STICKINESS == 0 means that any inserted text will get a
+ `field' char-property of nil, so check to see if that
+ matches either of the adjacent characters (this being a
+ kind of "stickiness by default"). */