From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#58937: text-property-search-backward misses one-character regions Date: Tue, 01 Nov 2022 12:24:49 +0200 Message-ID: <83k04fc6q6.fsf@gnu.org> References: <874jvjh95x.fsf@graner.name> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2680"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58937@debbugs.gnu.org To: Nicolas Graner , Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 01 11:26:53 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 1opoTs-0000WU-S7 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 01 Nov 2022 11:26:53 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opoTS-0000v6-Qq; Tue, 01 Nov 2022 06:26:26 -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 1opoT4-0000rw-SA for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 06:26:02 -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 1opoT4-0004Dg-JD for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 06:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1opoT4-0002t6-EI for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 06:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Nov 2022 10:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58937 X-GNU-PR-Package: emacs Original-Received: via spool by 58937-submit@debbugs.gnu.org id=B58937.166729832211017 (code B ref 58937); Tue, 01 Nov 2022 10:26:02 +0000 Original-Received: (at 58937) by debbugs.gnu.org; 1 Nov 2022 10:25:22 +0000 Original-Received: from localhost ([127.0.0.1]:42811 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opoSQ-0002rd-AZ for submit@debbugs.gnu.org; Tue, 01 Nov 2022 06:25:22 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56988) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opoSN-0002m2-VS for 58937@debbugs.gnu.org; Tue, 01 Nov 2022 06:25:20 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opoS9-0003H6-54; Tue, 01 Nov 2022 06:25:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=/PfmbGxNbeYqWRhsoO1T2+qgsBmgU309cBxUCNJr/tk=; b=b7F5QkMmGnS5 FEgl1G5Mbo7NZJ+CtnOFGtgJ9mHPzP2ecYtakek98OHrlxmowRbGMDhHLX/kOR4IjiC+AlljykbCm TDp0wSx6PMyP1uS6NFDZvx40VOTtkEh3UKRseDyZQGEXkiwV/q7QfOeiUHRpWiCrifUfnPJsKi3PS vfMwZFJc/L9FCMaQ9lv/2y4+y57n0TgopG1J9xM9Cxue4sJvkZQXaAbNqm3sqAC4xbssA/FDhNYxH 78JXgxa0+55tXNEUkdhB7NbDMqlvTS43t2w73osVqtZOKJO3hhsyyNHONaKynIcdFQ7gYwkNEgyvF aQKGdL/Zb27FHlXgMR6d6g==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opoS7-0003ph-Hc; Tue, 01 Nov 2022 06:25:04 -0400 In-Reply-To: <874jvjh95x.fsf@graner.name> (message from Nicolas Graner on Tue, 01 Nov 2022 00:20:58 +0100) 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: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246759 Archived-At: > From: Nicolas Graner > Date: Tue, 01 Nov 2022 00:20:58 +0100 > > (with-current-buffer (generate-new-buffer "test") > (insert "123456789") > (put-text-property 3 4 'foo 'bar) > (goto-char 6) > (text-property-search-backward 'foo)) > > The returned value is > #s(prop-match 1 4 nil) > instead of > #s(prop-match 3 4 bar) > and the point in the test buffer is moved to position 1 instead of 3. > > This incorrect behavior is the same if you replace (goto-char 6) with > (goto-char 5) or any other value greater than 4. However, the result is > correct with (goto-char 4), i.e. when the backward search starts one > position after the target character. This suggests an off-by-one error > in the code. It isn't due to an off-by-one error, AFAICT, it's because search for changes in text properties starts from character _before_ point. Please try the patch below and see if it gives good results. Lars, any comments? diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/text-property-search.el index d11980f..69bbbd2 100644 --- a/lisp/emacs-lisp/text-property-search.el +++ b/lisp/emacs-lisp/text-property-search.el @@ -208,8 +208,12 @@ text-property--find-end-backward (goto-char end) (setq ended t))))) ;; End this at the first place the property changes value. - (setq end (previous-single-property-change - (point) property nil (point-min))) + (setq end + (if (text-property--match-p + value (get-text-property (1- (point)) property) predicate) + (previous-single-property-change (point) + property nil (point-min)) + (point))) (goto-char end)) (make-prop-match :beginning end :end (1+ start)