From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 31 19:21:11 2022 Received: (at submit) by debbugs.gnu.org; 31 Oct 2022 23:21:11 +0000 Received: from localhost ([127.0.0.1]:42242 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ope5f-0005lu-CV for submit@debbugs.gnu.org; Mon, 31 Oct 2022 19:21:11 -0400 Received: from lists.gnu.org ([209.51.188.17]:43424) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ope5d-0005lm-BC for submit@debbugs.gnu.org; Mon, 31 Oct 2022 19:21:10 -0400 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 1ope5d-00070u-6L for bug-gnu-emacs@gnu.org; Mon, 31 Oct 2022 19:21:09 -0400 Received: from ouvsmtp1.octopuce.fr ([194.36.166.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ope5b-0004rz-DN for bug-gnu-emacs@gnu.org; Mon, 31 Oct 2022 19:21:08 -0400 Received: from panel.vitry.ouvaton.coop (unknown [194.36.166.20]) by ouvsmtp1.octopuce.fr (Postfix) with ESMTPS id 29F3B126 for ; Tue, 1 Nov 2022 00:20:59 +0100 (CET) Received: from hypra-graner (215.124.67.86.rev.sfr.net [86.67.124.215]) by panel.vitry.ouvaton.coop (Postfix) with ESMTPSA id C64965E2090 for ; Tue, 1 Nov 2022 00:20:58 +0100 (CET) From: Nicolas Graner To: bug-gnu-emacs@gnu.org Subject: text-property-search-backward misses one-character regions Date: Tue, 01 Nov 2022 00:20:58 +0100 Message-ID: <874jvjh95x.fsf@graner.name> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=194.36.166.50; envelope-from=nicolas@graner.name; helo=ouvsmtp1.octopuce.fr X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) In Emacs 29.0.50, when a single character has a text property and you try to find it with text-property-search-backward, the result incorrectly includes previous characters without the property. Example: (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. Hope this helps, Nicolas From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 01 06:25:22 2022 Received: (at 58937) by debbugs.gnu.org; 1 Nov 2022 10:25:22 +0000 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 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 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==; 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 Date: Tue, 01 Nov 2022 12:24:49 +0200 Message-Id: <83k04fc6q6.fsf@gnu.org> From: Eli Zaretskii To: Nicolas Graner , Lars Ingebrigtsen In-Reply-To: <874jvjh95x.fsf@graner.name> (message from Nicolas Graner on Tue, 01 Nov 2022 00:20:58 +0100) Subject: Re: bug#58937: text-property-search-backward misses one-character regions References: <874jvjh95x.fsf@graner.name> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 58937 Cc: 58937@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > 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) From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 01 12:48:44 2022 Received: (at 58937) by debbugs.gnu.org; 1 Nov 2022 16:48:44 +0000 Received: from localhost ([127.0.0.1]:44088 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opuRP-0001Cf-PM for submit@debbugs.gnu.org; Tue, 01 Nov 2022 12:48:44 -0400 Received: from ouvsmtp1.octopuce.fr ([194.36.166.50]:38432) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opuRM-0001CU-EI for 58937@debbugs.gnu.org; Tue, 01 Nov 2022 12:48:42 -0400 Received: from panel.vitry.ouvaton.coop (unknown [194.36.166.20]) by ouvsmtp1.octopuce.fr (Postfix) with ESMTPS id 7705A148B; Tue, 1 Nov 2022 17:48:38 +0100 (CET) Received: from hypra-graner (215.124.67.86.rev.sfr.net [86.67.124.215]) by panel.vitry.ouvaton.coop (Postfix) with ESMTPSA id E68E45E0428; Tue, 1 Nov 2022 17:48:37 +0100 (CET) From: Nicolas Graner To: Eli Zaretskii Subject: Re: bug#58937: text-property-search-backward misses one-character regions In-Reply-To: <83k04fc6q6.fsf@gnu.org> (message from Eli Zaretskii on Tue, 01 Nov 2022 12:24:49 +0200) Date: Tue, 01 Nov 2022 17:48:37 +0100 Message-ID: <87bkpqr57e.fsf@graner.name> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 58937 Cc: larsi@gnus.org, 58937@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > Date: Tue, 01 Nov 2022 12:24:49 +0200 > From: Eli Zaretskii > > Please try the patch below and see if it gives good results. > > 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) It fixes the bug in all the cases I've tested so far, but also introduces a new one: (with-current-buffer (generate-new-buffer "test") (insert "123456789") (put-text-property 2 4 'foo 'bar) (goto-char 3) (text-property-search-backward 'foo nil t)) Debugger entered--Lisp error: (args-out-of-range 0 0) get-text-property(0 foo) (text-property--match-p value (get-text-property (1- (point)) property) predicate) (if (text-property--match-p value (get-text-property (1- (point)) property) predicate) (previous-single-property-change (point) property nil (point-min)) (point)) (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))) (if (and value (null predicate)) (let ((ended nil)) (while (not ended) (setq end (previous-single-property-change (point) property)) (if (not end) (progn (goto-char (point-min)) (progn (setq end (point)) (setq ended t))) (goto-char (1- end)) (if (text-property--match-p value (get-text-property (point) property) predicate) nil (goto-char end) (setq ended t))))) (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)) (let (end) (if (and value (null predicate)) (let ((ended nil)) (while (not ended) (setq end (previous-single-property-change (point) property)) (if (not end) (progn (goto-char (point-min)) (progn (setq end ...) (setq ended t))) (goto-char (1- end)) (if (text-property--match-p value (get-text-property ... property) predicate) nil (goto-char end) (setq ended t))))) (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) :value (get-text-property end property))) text-property--find-end-backward(1 foo nil t) text-property-search-backward(foo nil t) (save-current-buffer (set-buffer (generate-new-buffer "test")) (insert "123456789") (put-text-property 2 4 'foo 'bar) (goto-char 3) (text-property-search-backward 'foo nil t)) eval((save-current-buffer (set-buffer (generate-new-buffer "test")) (insert "123456789") (put-text-property 2 4 'foo 'bar) (goto-char 3) (text-property-search-backward 'foo nil t)) nil) elisp--eval-last-sexp(nil) eval-last-sexp(nil) From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 01 12:56:46 2022 Received: (at 58937) by debbugs.gnu.org; 1 Nov 2022 16:56:46 +0000 Received: from localhost ([127.0.0.1]:44102 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opuZB-0001OV-Lb for submit@debbugs.gnu.org; Tue, 01 Nov 2022 12:56:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40642) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opuZ6-0001OG-6s for 58937@debbugs.gnu.org; Tue, 01 Nov 2022 12:56:43 -0400 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 1opuZ0-0004dg-Ax; Tue, 01 Nov 2022 12:56:34 -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=7IcMGskhS8J6VvE8dCQ4t0FnZ+O7ohycwsPgZdcKoDs=; b=dmRHAC6BkAYI ddV8zRzWxZkvXt3fCJiLSRN4j/dWGpW5KYjrRvrRsxQLID054cqcGNuWOQfYNr8zTZ8Xeau0VWpII Fo8b2VROiCGozhiaMIP0hGUzXtmmnYtNVpCRu9L0dkDuQu1P407f94Px2As+VSAHjIJgDMxkZ2lTr uESnWt9jGf4GDuWQCBnmrrkTyPvY+TOWJ7JT8skh7bLV6Up3z5+5Pp+KEQ3VBWG6fKSu730sDa6t2 pu2Rkbozpk3dCH3DRNT0yTOZpc9easegDXyFhnOucuvs6i3TzzDeoZ4iW5Ojbz5478tGiv7hOTtlm mvylURd6Jf1u/uFTxAM20w==; 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 1opuYx-0001iH-Ua; Tue, 01 Nov 2022 12:56:34 -0400 Date: Tue, 01 Nov 2022 18:56:20 +0200 Message-Id: <831qqmd363.fsf@gnu.org> From: Eli Zaretskii To: Nicolas Graner In-Reply-To: <87bkpqr57e.fsf@graner.name> (message from Nicolas Graner on Tue, 01 Nov 2022 17:48:37 +0100) Subject: Re: bug#58937: text-property-search-backward misses one-character regions References: <87bkpqr57e.fsf@graner.name> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 58937 Cc: larsi@gnus.org, 58937@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Nicolas Graner > Cc: larsi@gnus.org, 58937@debbugs.gnu.org > Date: Tue, 01 Nov 2022 17:48:37 +0100 > > > Date: Tue, 01 Nov 2022 12:24:49 +0200 > > From: Eli Zaretskii > > > > Please try the patch below and see if it gives good results. > > > > 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) > > It fixes the bug in all the cases I've tested so far, but also > introduces a new one: > > (with-current-buffer (generate-new-buffer "test") > (insert "123456789") > (put-text-property 2 4 'foo 'bar) > (goto-char 3) > (text-property-search-backward 'foo nil t)) > > Debugger entered--Lisp error: (args-out-of-range 0 0) > get-text-property(0 foo) Thanks for testing, how about the following patch instead? diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/text-property-search.el index d11980f..f7ef84a 100644 --- a/lisp/emacs-lisp/text-property-search.el +++ b/lisp/emacs-lisp/text-property-search.el @@ -208,8 +208,13 @@ 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 (or (= (point) (point-min)) + (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) From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 01 13:00:54 2022 Received: (at 58937) by debbugs.gnu.org; 1 Nov 2022 17:00:55 +0000 Received: from localhost ([127.0.0.1]:44107 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opudC-0001ZO-JG for submit@debbugs.gnu.org; Tue, 01 Nov 2022 13:00:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51386) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opud5-0001Z7-Nf for 58937@debbugs.gnu.org; Tue, 01 Nov 2022 13:00:51 -0400 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 1opucz-0006Wm-Tj; Tue, 01 Nov 2022 13:00:41 -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=x6ZRc42H1mF0iiod4MZirayFAt2d9jo+nQ6BMocGZOg=; b=nnlJcKyAVbuU 8wH6SOKULI0+ilDWJVyLxlLmq4oIqL5Ng8HsPQsiQk+8jvnaUGbJ1fDO79OrmHd+fs4l2cuJD4wO2 IauFbi6q15pJoqxT4KFzlx9LXRc1GsfIaIcEd1BtyUFsxqVCeKH3h2EluB0BgiHLOjB4FHXqkn32x kafsrLg3GVMMcb9cmtLe+IZVkAHqdelgc+ZoeadjIeO4sZ6G2FkNcR2xqmsc6fSwk7rAgBoUCwPcw 6tvNZaXSxr6R/RA8TjZEj+trTUejBkPsHOkgm38OA7FD1I77S93s7SO0EAmIk8m4lLJV+FaBCYhrO xsuttyYhDWv7+isCgERi6A==; 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 1opucz-0007mk-6w; Tue, 01 Nov 2022 13:00:41 -0400 Date: Tue, 01 Nov 2022 19:00:28 +0200 Message-Id: <83zgdaboer.fsf@gnu.org> From: Eli Zaretskii To: Nicolas Graner In-Reply-To: <87bkpqr57e.fsf@graner.name> (message from Nicolas Graner on Tue, 01 Nov 2022 17:48:37 +0100) Subject: Re: bug#58937: text-property-search-backward misses one-character regions References: <87bkpqr57e.fsf@graner.name> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 58937 Cc: larsi@gnus.org, 58937@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Nicolas Graner > Cc: larsi@gnus.org, 58937@debbugs.gnu.org > Date: Tue, 01 Nov 2022 17:48:37 +0100 > > > Date: Tue, 01 Nov 2022 12:24:49 +0200 > > From: Eli Zaretskii > > > > Please try the patch below and see if it gives good results. > > > > 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) > > It fixes the bug in all the cases I've tested so far, but also > introduces a new one: > > (with-current-buffer (generate-new-buffer "test") > (insert "123456789") > (put-text-property 2 4 'foo 'bar) > (goto-char 3) > (text-property-search-backward 'foo nil t)) > > Debugger entered--Lisp error: (args-out-of-range 0 0) > get-text-property(0 foo) Sorry, please disregard the previous message and use the patch below instead: diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/text-property-search.el index d11980f..1e7f346 100644 --- a/lisp/emacs-lisp/text-property-search.el +++ b/lisp/emacs-lisp/text-property-search.el @@ -208,8 +208,13 @@ 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 (and (> (point) (point-min)) + (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) From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 01 13:06:06 2022 Received: (at 58937) by debbugs.gnu.org; 1 Nov 2022 17:06:06 +0000 Received: from localhost ([127.0.0.1]:44125 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opuiE-0001jF-DA for submit@debbugs.gnu.org; Tue, 01 Nov 2022 13:06:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50110) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opuiC-0001ik-Ir for 58937@debbugs.gnu.org; Tue, 01 Nov 2022 13:06:04 -0400 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 1opui5-0008U0-8g; Tue, 01 Nov 2022 13:05:57 -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=RkKPey25DKfIUD+d3fV0AB9zwixojszJ111pgwpBOsA=; b=bJa/SNfeQNOa o/oyUQEI6Z5S+heJBl09I40yB4yWRJ5kOc/IyWIKTfqizXw2UxGKPu+0J0AvFne7K14BaTRwjFEnh 8dvNN8F3ZOPC3SYLB/aqdOhZ2ovhUkP0dKujNAKfmdkp3i5WtD035zeerw3S7/HWnkvnIlX7Oraxt eEWhnlpl8yq515BaE0dyLDS1hVVKMQ/Iqe9TWPKdRfGePZU8l7eC2G10lPWCdJHs/mmEcMxc76wBI kcjuY5/ZjP0uZaUAlqYBO8umGY4WvCN11stcZBIK5KONiewqtNVoy4h6cSQo/u6OWPNhL5C92H35r DCZEuMYlYH3JhoKdWiEG/Q==; 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 1opui2-0007zr-TE; Tue, 01 Nov 2022 13:05:56 -0400 Date: Tue, 01 Nov 2022 19:05:41 +0200 Message-Id: <83wn8ebo62.fsf@gnu.org> From: Eli Zaretskii To: nicolas@graner.name In-Reply-To: <83zgdaboer.fsf@gnu.org> (message from Eli Zaretskii on Tue, 01 Nov 2022 19:00:28 +0200) Subject: Re: bug#58937: text-property-search-backward misses one-character regions References: <87bkpqr57e.fsf@graner.name> <83zgdaboer.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 58937 Cc: larsi@gnus.org, 58937@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Tue, 01 Nov 2022 19:00:28 +0200 > From: Eli Zaretskii > Cc: larsi@gnus.org, 58937@debbugs.gnu.org > > > From: Nicolas Graner > > Cc: larsi@gnus.org, 58937@debbugs.gnu.org > > Date: Tue, 01 Nov 2022 17:48:37 +0100 > > > > > Date: Tue, 01 Nov 2022 12:24:49 +0200 > > > From: Eli Zaretskii > > > > > > Please try the patch below and see if it gives good results. > > > > > > 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) > > > > It fixes the bug in all the cases I've tested so far, but also > > introduces a new one: > > > > (with-current-buffer (generate-new-buffer "test") > > (insert "123456789") > > (put-text-property 2 4 'foo 'bar) > > (goto-char 3) > > (text-property-search-backward 'foo nil t)) > > > > Debugger entered--Lisp error: (args-out-of-range 0 0) > > get-text-property(0 foo) > > Sorry, please disregard the previous message and use the patch below > instead: Not my best day, I guess. Please use this patch instead of the previous two: diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/text-property-search.el index d11980f..d41222b 100644 --- a/lisp/emacs-lisp/text-property-search.el +++ b/lisp/emacs-lisp/text-property-search.el @@ -208,8 +208,14 @@ 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 (and (> (point) (point-min)) + (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) From debbugs-submit-bounces@debbugs.gnu.org Wed Nov 02 19:40:50 2022 Received: (at 58937) by debbugs.gnu.org; 2 Nov 2022 23:40:50 +0000 Received: from localhost ([127.0.0.1]:47360 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oqNLm-0007Ve-5C for submit@debbugs.gnu.org; Wed, 02 Nov 2022 19:40:50 -0400 Received: from ouvsmtp1.octopuce.fr ([194.36.166.50]:46496) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oqNLj-0007VU-Se for 58937@debbugs.gnu.org; Wed, 02 Nov 2022 19:40:49 -0400 Received: from panel.vitry.ouvaton.coop (unknown [194.36.166.20]) by ouvsmtp1.octopuce.fr (Postfix) with ESMTPS id ED4951236; Thu, 3 Nov 2022 00:40:45 +0100 (CET) Received: from hypra-graner (215.124.67.86.rev.sfr.net [86.67.124.215]) by panel.vitry.ouvaton.coop (Postfix) with ESMTPSA id 341075E28EE; Thu, 3 Nov 2022 00:40:44 +0100 (CET) From: Nicolas Graner To: Eli Zaretskii Subject: Re: bug#58937: text-property-search-backward misses one-character regions In-Reply-To: <83wn8ebo62.fsf@gnu.org> (message from Eli Zaretskii on Tue, 01 Nov 2022 19:05:41 +0200) Date: Thu, 03 Nov 2022 00:40:43 +0100 Message-ID: <87o7tpdix0.fsf@graner.name> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 58937 Cc: larsi@gnus.org, 58937@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > Date: Tue, 01 Nov 2022 19:05:41 +0200 > From: Eli Zaretskii > To: nicolas@graner.name > CC: larsi@gnus.org, 58937@debbugs.gnu.org > diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/te= xt-property-search.el > index d11980f..d41222b 100644 > --- a/lisp/emacs-lisp/text-property-search.el > +++ b/lisp/emacs-lisp/text-property-search.el > @@ -208,8 +208,14 @@ 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 (and (> (point) (point-min)) > + (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 This works fine in all the cases I have tested, although I don't claim to have tested all relevant combinations of arguments and region lengths and positions... In the process, I think I uncovered another bug common to text-property-search-forward and -backward. Before filing a bug report I'd like to make sure my understanding is correct. It may also be a documentation error. Here, the PREDICATE argument is a function, not the usual t or nil: (with-current-buffer (generate-new-buffer "test") (insert "123456789") (put-text-property 2 4 'foo "abcd") (put-text-property 4 6 'foo "efgh") (goto-char 1) (text-property-search-forward 'foo 4 (lambda (l str) (=3D l (length str))= ))) This returns: #s(prop-match 2 4 "abcd") but I think it should be: #s(prop-match 2 6 "abcd") since both the (2 4) and the (4 6) regions satisfy the predicate. The docstring for text-property-search-forward says: If PREDICATE is nil (which is the default value), a value will match if is not =E2=80=98equal=E2=80=99 to VALUE. Furthermore, a nil P= REDICATE means that the match region is ended if the value changes. This implies that when PREDICATE is not nil, the match region should not end when the value changes, but only when the predicate is no longer satisfied. Is this correct? Nicolas From debbugs-submit-bounces@debbugs.gnu.org Thu Nov 03 05:36:03 2022 Received: (at 58937-done) by debbugs.gnu.org; 3 Nov 2022 09:36:03 +0000 Received: from localhost ([127.0.0.1]:48010 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oqWdn-0001Ev-G6 for submit@debbugs.gnu.org; Thu, 03 Nov 2022 05:36:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49962) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oqWdi-0001EO-Ak for 58937-done@debbugs.gnu.org; Thu, 03 Nov 2022 05:36:02 -0400 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 1oqWdZ-0004ET-Ps; Thu, 03 Nov 2022 05:35:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=tbbPZN38MQh9i8Wj7bhls9uyEIgpisTGkGOqmmzXjJg=; b=gFMU0716s0lq4hvqLd5L 9SDwBq9fumnZcuM9TkptMMmWPaKelv8MX4foAERXJcYc7UU6rP6NIbINETzQCLkZGTWnvnX7G09Sy NyxqVOjOnnlLHioajuawPTGWg2MDogO9QP0fE1cYbLuEkQJkkwgHfQf3u62c7xhyqZQdL6crGRplm UUCKBX3UzuOJqcp17LhCaXrpfJwhCqW+GkJ0Br/rERmSty9bfavTvp1miqx6VYyej24uL9dDmeXUg ofiA5ebT5xmCcxjG0d9vuFDeGXxr/Lwi16V9ZVguSF42AAtTSE/9j9vDONNgOy7PqM1bGq8hPg9wX DZ55JV3zNXysOg==; 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 1oqWdY-00042x-3w; Thu, 03 Nov 2022 05:35:49 -0400 Date: Thu, 03 Nov 2022 11:35:40 +0200 Message-Id: <835yfw8jo3.fsf@gnu.org> From: Eli Zaretskii To: Nicolas Graner In-Reply-To: <87o7tpdix0.fsf@graner.name> (message from Nicolas Graner on Thu, 03 Nov 2022 00:40:43 +0100) Subject: Re: bug#58937: text-property-search-backward misses one-character regions References: <87o7tpdix0.fsf@graner.name> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 58937-done Cc: larsi@gnus.org, 58937-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Nicolas Graner > Cc: larsi@gnus.org, 58937@debbugs.gnu.org > Date: Thu, 03 Nov 2022 00:40:43 +0100 > > This works fine in all the cases I have tested, although I don't claim > to have tested all relevant combinations of arguments and region lengths > and positions... Thanks, I installed the change. > Here, the PREDICATE argument is a function, not the usual t or nil: > > (with-current-buffer (generate-new-buffer "test") > (insert "123456789") > (put-text-property 2 4 'foo "abcd") > (put-text-property 4 6 'foo "efgh") > (goto-char 1) > (text-property-search-forward 'foo 4 (lambda (l str) (= l (length str))))) ??? The documentation says PREDICATE is called with 2 arguments: the VALUE argument to text-property-search-forward and the actual value of the text property to examine. There's no property value of 4 in this example, so it sounds like you are (ab)using the feature in some way that we didn't really intend to support. More to the point, Emacs always considers segments of characters whose values of the same property are different as distinct segments. You seem to expect that Emacs would join these two segments because you supplied PREDICATE that returns t for both, but Emacs cannot do that, because the underlying text-property machinery doesn't even look at the next segment before it processes the first one. And no PREDICATE in this API can ever change that basic fact. So your expectations are incorrect, and cannot be met by this API, which specifically meant to examine the text segments one by one and subject each one of them to PREDICATE, separately. > The docstring for text-property-search-forward says: > If PREDICATE is nil (which is the default value), a value will > match if is not ‘equal’ to VALUE. Furthermore, a nil PREDICATE > means that the match region is ended if the value changes. > > This implies that when PREDICATE is not nil, the match region should not > end when the value changes, but only when the predicate is no longer > satisfied. Is this correct? No, it isn't. The region always ends where the property changes value, regardless of what PREDICATE thinks. From unknown Sun Aug 17 00:59:37 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 01 Dec 2022 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator