From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Nicolas Graner Newsgroups: gmane.emacs.bugs Subject: bug#58937: text-property-search-backward misses one-character regions Date: Thu, 03 Nov 2022 00:40:43 +0100 Message-ID: <87o7tpdix0.fsf@graner.name> References: <874jvjh95x.fsf@graner.name> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19884"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, 58937@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 03 00:41:20 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 1oqNMF-00050h-GY for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Nov 2022 00:41:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqNM0-00014p-I1; Wed, 02 Nov 2022 19:41:04 -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 1oqNLy-00012Q-JN for bug-gnu-emacs@gnu.org; Wed, 02 Nov 2022 19:41: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 1oqNLy-0002pB-AJ for bug-gnu-emacs@gnu.org; Wed, 02 Nov 2022 19:41:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oqNLx-0007WC-V3 for bug-gnu-emacs@gnu.org; Wed, 02 Nov 2022 19:41:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Nicolas Graner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 02 Nov 2022 23:41:01 +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.166743245028874 (code B ref 58937); Wed, 02 Nov 2022 23:41:01 +0000 Original-Received: (at 58937) by debbugs.gnu.org; 2 Nov 2022 23:40:50 +0000 Original-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 Original-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 Original-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) Original-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) In-Reply-To: <83wn8ebo62.fsf@gnu.org> (message from Eli Zaretskii on Tue, 01 Nov 2022 19:05:41 +0200) 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@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246900 Archived-At: > 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