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 19:05:41 +0200 Message-ID: <83wn8ebo62.fsf@gnu.org> References: <87bkpqr57e.fsf@graner.name> <83zgdaboer.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37115"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, 58937@debbugs.gnu.org To: nicolas@graner.name Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 01 18:10:41 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 1opumf-0009QL-1v for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 01 Nov 2022 18:10:41 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opujA-0002bA-3w; Tue, 01 Nov 2022 13:07: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 1opuj8-0002W3-TU for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 13:07: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 1opuj8-0000r5-Kg for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 13:07:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1opuj8-0001kT-5U for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 13:07: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 17:07: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.16673223666654 (code B ref 58937); Tue, 01 Nov 2022 17:07:02 +0000 Original-Received: (at 58937) by debbugs.gnu.org; 1 Nov 2022 17:06:06 +0000 Original-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 Original-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 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 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==; 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 1opui2-0007zr-TE; Tue, 01 Nov 2022 13:05:56 -0400 In-Reply-To: <83zgdaboer.fsf@gnu.org> (message from Eli Zaretskii on Tue, 01 Nov 2022 19:00:28 +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:246781 Archived-At: > 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)