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 #11 received at 58937 <at> debbugs.gnu.org (full text, mbox):

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




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

Previous Next


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