From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Armstrong Newsgroups: gmane.emacs.bugs Subject: bug#58706: 29.0.50; [noverlay] `get-pos-property' misses overlay start Date: Sat, 22 Oct 2022 21:05:24 -0700 Message-ID: <878rl7422j.fsf@rfc20.org> References: <87edv04gt9.fsf@rfc20.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36511"; mail-complaints-to="usenet@ciao.gmane.io" Cc: stefan monnier To: 58706@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 24 04:37:43 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1omnLT-0009LF-8Y for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 24 Oct 2022 04:37:43 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1omkNN-0001tm-Eh for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 23 Oct 2022 19:27:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1omSFP-0004R0-2K for bug-gnu-emacs@gnu.org; Sun, 23 Oct 2022 00:06:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1omSFO-00012J-HD for bug-gnu-emacs@gnu.org; Sun, 23 Oct 2022 00:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1omSFO-00022Z-5P for bug-gnu-emacs@gnu.org; Sun, 23 Oct 2022 00:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Matt Armstrong Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 23 Oct 2022 04:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58706 X-GNU-PR-Package: emacs Original-Received: via spool by 58706-submit@debbugs.gnu.org id=B58706.16664979427815 (code B ref 58706); Sun, 23 Oct 2022 04:06:02 +0000 Original-Received: (at 58706) by debbugs.gnu.org; 23 Oct 2022 04:05:42 +0000 Original-Received: from localhost ([127.0.0.1]:42735 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1omSF3-00021y-UH for submit@debbugs.gnu.org; Sun, 23 Oct 2022 00:05:42 -0400 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:51497) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1omSEy-00021h-Ff for 58706@debbugs.gnu.org; Sun, 23 Oct 2022 00:05:40 -0400 Original-Received: (Authenticated sender: matt@rfc20.org) by mail.gandi.net (Postfix) with ESMTPSA id 576E120002; Sun, 23 Oct 2022 04:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rfc20.org; s=gm1; t=1666497929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8n3bmcga/IxQ7O6FwYWD8CIVHdEMFs2Sr8btfRMVioY=; b=UnrF9v5gztbsVV/7whkxnIdvnF5eQ4nsDtN0v2pO7ecFscELGyN8zD1e+eJ8K+aUnsNP4s vz2dpxFNTnacVeb4fuT/2Sub6zh3WEy7OM2zjrEsDbjpVuxpDcHUpClX5tCfOubeYrJ6CD x5P+Psm98V3gnWqFHLwNWGOkmzOnYtUM+iCOpiKEOXNVoV63MC7KKAOKaDX92h83s2Fw+h ZCixLSCGhrSuIc/H0LKIBFV+7O3qtdm86QJxmMYf79dqRoet9WUQkG/6fjbVQFFVWWUXys PtxYw36CaSSm0pF3gvvZtlmX9T8ElMzgz9MUIWsWTTEtyM7ezi0xufHQsacF3w== Original-Received: from matt by naz with local (Exim 4.96) (envelope-from ) id 1omSEm-0026dU-0I; Sat, 22 Oct 2022 21:05:24 -0700 In-Reply-To: <87edv04gt9.fsf@rfc20.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:246054 Archived-At: --=-=-= Content-Type: text/plain Matt Armstrong writes: > X-Debbugs-CC: Stefan Monnier > > The following test passes on mainline but doesn't on feature/noverlay. > On the noverlay branch `get-pos-property' returns nil. > > (ert-deftest test-get-pos-property-overlay-beg () > "Test `get-pos-property' at the beginning of an overlay." > (with-temp-buffer > (insert (make-string 10 ?x)) > (let ((overlay (make-overlay 5 7))) > (overlay-put overlay 'forty-two 42)) > (should (equal 42 (get-pos-property 5 'forty-two))))) Tests and a fix. Also up on the scratch/matta/for_stefan branch of https://git.sr.ht/~matta/emacs --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Add-get-pos-property-tests-covering-bug-58706.patch >From 555bc1f8b3ed8b02fb5acb013ed24073b0666585 Mon Sep 17 00:00:00 2001 From: Matt Armstrong Date: Sat, 22 Oct 2022 20:46:30 -0700 Subject: [PATCH 2/3] Add `get-pos-property' tests covering bug#58706 * test/src/buffer-tests.el (get-pos-property-overlay-beg): New test. (get-pos-property-overlay-empty-rear-advance): ditto. (get-pos-property-overlay-past-rear-advance): ditto. (get-pos-property-overlay-at-narrowed-end): ditto. --- test/src/buffer-tests.el | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index c6d176cc171..e0207325241 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el @@ -1108,6 +1108,49 @@ test-delete-all-overlay-1 (should-not (delete-all-overlays)))) +;; +==========================================================================+ +;; | get-pos-property +;; +==========================================================================+ + +(ert-deftest get-pos-property-overlay-beg () + "Test `get-pos-property' at the beginning of an overlay. +Regression test for bug#58706." + (with-temp-buffer + (insert (make-string 10000 ?x)) + (let ((overlay (make-overlay 9999 10001))) + (overlay-put overlay 'forty-two 42)) + (should (equal 42 (get-pos-property 9999 'forty-two))))) + +(ert-deftest get-pos-property-overlay-empty-rear-advance () + "Test `get-pos-property' at the end of an empty rear-advance overlay. +Regression test for bug#58706." + (with-temp-buffer + (insert (make-string 10000 ?x)) + (let ((overlay (make-overlay 9999 9999 nil nil t))) + (overlay-put overlay 'forty-two 42)) + (should (equal 42 (get-pos-property 9999 'forty-two))))) + +(ert-deftest get-pos-property-overlay-past-rear-advance () + "Test `get-pos-property' past the end of an empty rear-advance overlay. +Regression test for bug#58706." + (with-temp-buffer + (insert (make-string 10000 ?x)) + (let ((overlay (make-overlay 9998 9998 nil nil t))) + (overlay-put overlay 'forty-two 42)) + (should (equal nil (get-pos-property 9999 'forty-two))))) + +(ert-deftest get-pos-property-overlay-at-narrowed-end () + "Test `get-pos-property' at the end of a narrowed region. +Regression test for bug#58706." + (with-temp-buffer + (insert (make-string 11000 ?x)) + (narrow-to-region 9998 10000) + (let ((overlay (make-overlay 10000 10000 nil t nil))) + (overlay-put overlay 'forty-two 42)) + (should (equal nil (get-pos-property 9999 'forty-two))))) + +;; FIXME: add more `get-pos-property' tests + ;; +==========================================================================+ ;; | get-char-property(-and-overlay) ;; +==========================================================================+ -- 2.35.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0003-Fix-get-pos-property-for-the-new-overlay-implementat.patch >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 --=-=-=--