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 18:56:20 +0200 Message-ID: <831qqmd363.fsf@gnu.org> References: <87bkpqr57e.fsf@graner.name> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22770"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, 58937@debbugs.gnu.org To: Nicolas Graner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 01 18:22: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 1opuyI-0005k2-Nq for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 01 Nov 2022 18:22:42 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opuZW-00018d-Of; Tue, 01 Nov 2022 12:57:06 -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 1opuZT-00018F-EL for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 12:57: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 1opuZS-0004xq-P0 for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 12:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1opuZS-0001P3-HJ for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 12:57: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 16:57: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.16673218065368 (code B ref 58937); Tue, 01 Nov 2022 16:57:02 +0000 Original-Received: (at 58937) by debbugs.gnu.org; 1 Nov 2022 16:56:46 +0000 Original-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 Original-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 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 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==; 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 1opuYx-0001iH-Ua; Tue, 01 Nov 2022 12:56:34 -0400 In-Reply-To: <87bkpqr57e.fsf@graner.name> (message from Nicolas Graner on Tue, 01 Nov 2022 17:48:37 +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@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246787 Archived-At: > 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)