From b78be2bf7a9ac8b71d25529d5736373f51852c36 Mon Sep 17 00:00:00 2001 From: Matt Armstrong Date: Sat, 22 Oct 2022 20:48:10 -0700 Subject: [PATCH 3/3] Fix `get-pos-property' for the new overlay implementation. Some of the trickier edge cases weren't handled properly. See bug#58706. * src/editfns.c (overlays_around): Extend the search range past POS by one to fetch overlays beginning at POS. Fetch empty overlays, as they may be extended by an insertion and thus be relevant to `get-pos-property'. Make a note that the function now, unfortunately, may return out of range overlays. (Fget_pos_property): Deal with 'overlays_around' returning out of range overlays. --- src/editfns.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/editfns.c b/src/editfns.c index 00380175859..c892c02927d 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -265,12 +265,20 @@ DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0, /* Find all the overlays in the current buffer that touch position POS. Return the number found, and store them in a vector in VEC - of length LEN. */ + of length LEN. + + Note: this can return overlays that do not touch POS. The caller + should filter these out. */ static ptrdiff_t overlays_around (ptrdiff_t pos, Lisp_Object *vec, ptrdiff_t len) { - return overlays_in (pos - 1, pos, false, &vec, &len, false, false, NULL); + /* Find all potentially rear-advance overlays at (POS - 1). Find + all overlays at POS, so end at (POS + 1). Find even empty + overlays, which due to the way 'overlays-in' works implies that + we might also fetch empty overlays starting at (POS + 1). */ + return overlays_in (pos - 1, pos + 1, false, &vec, &len, + true, false, NULL); } DEFUN ("get-pos-property", Fget_pos_property, Sget_pos_property, 2, 3, 0, @@ -333,7 +341,9 @@ DEFUN ("get-pos-property", Fget_pos_property, Sget_pos_property, 2, 3, 0, if ((OVERLAY_START (ol) == posn && OVERLAY_FRONT_ADVANCE_P (ol)) || (OVERLAY_END (ol) == posn - && ! OVERLAY_REAR_ADVANCE_P (ol))) + && ! OVERLAY_REAR_ADVANCE_P (ol)) + || OVERLAY_START (ol) > posn + || OVERLAY_END (ol) < posn) ; /* The overlay will not cover a char inserted at point. */ else { -- 2.35.1