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: Tue, 01 Nov 2022 17:48:37 +0100 Message-ID: <87bkpqr57e.fsf@graner.name> References: <874jvjh95x.fsf@graner.name> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20950"; 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 Tue Nov 01 18:22:24 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 1opuxz-0005Aa-0F for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 01 Nov 2022 18:22:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opuRk-0000Ir-R7; Tue, 01 Nov 2022 12:49: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 1opuRj-0000Ih-87 for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 12:49: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 1opuRi-0001Lk-RC for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 12:49:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1opuRh-0001DD-JJ for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 12:49: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: Tue, 01 Nov 2022 16:49: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.16673213244633 (code B ref 58937); Tue, 01 Nov 2022 16:49:01 +0000 Original-Received: (at 58937) by debbugs.gnu.org; 1 Nov 2022 16:48:44 +0000 Original-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 Original-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 Original-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) 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 E68E45E0428; Tue, 1 Nov 2022 17:48:37 +0100 (CET) In-Reply-To: <83k04fc6q6.fsf@gnu.org> (message from Eli Zaretskii on Tue, 01 Nov 2022 12:24:49 +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:246786 Archived-At: > 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)