GNU bug report logs - #58937
text-property-search-backward misses one-character regions

Previous Next

Package: emacs;

Reported by: Nicolas Graner <nicolas <at> graner.name>

Date: Mon, 31 Oct 2022 23:22:02 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 58937 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Nicolas Graner <nicolas <at> graner.name>, Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 58937 <at> debbugs.gnu.org
Subject: Re: bug#58937: text-property-search-backward misses one-character
 regions
Date: Tue, 01 Nov 2022 12:24:49 +0200
> From: Nicolas Graner <nicolas <at> graner.name>
> 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)




This bug report was last modified 2 years and 259 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.