GNU bug report logs - #35119
Zero-length regexp matches at point when doing re-search-backward

Previous Next

Package: emacs;

Reported by: Sam Halliday <sam.halliday <at> gmail.com>

Date: Wed, 3 Apr 2019 11:20:01 UTC

Severity: normal

Found in version 26.1

Full log


View this message in rfc822 format

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Sam Halliday <sam.halliday <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 35119 <at> debbugs.gnu.org
Subject: bug#35119: 26.1; narrow-to-region loses word-start/symbol-start information at end
Date: Wed, 01 Sep 2021 11:08:41 +0200
Sam Halliday <sam.halliday <at> gmail.com> writes:

> This impacts me in `looking-back'. Here's an interactive snippet to
> demonstrate the problem (not minimised to`narrow-to-region'):
>
> (defun look-for-35119 ()
>   (interactive)
>   (if (looking-back
>        (rx (: word-end ":" word-start))
>        ;;(rx (: word-end ":"))
>        (- (point) 1) 't)
>       (message "hit")
>     (message "miss")))
>
> in emacs-lisp-mode, which defines : as non-word, interactively
> evaluate look-for-35119 when the point is just after the colon in this
> example text
>
>   wibble:wobble

Here's a simpler test case:

(with-temp-buffer
  (emacs-lisp-mode)
  (insert "wibble:wobble")
  (goto-char (point-min))
  (search-forward ":")
  (if (looking-back "\\>:\\<" nil t)
      (message "hit")
    (message "miss")))

And, indeed, that fails because

(re-search-backward "\\(?:\\>:\\<\\)\\=" nil t)

fails.  There seems to be a general problem with re-search-backward and
these zero-length matches (as you said in a later message).

Here's the test case:

(with-temp-buffer
  (emacs-lisp-mode)
  (insert "wibble:wobble")
  (goto-char (point-min))
  (search-forward ":")
  (if (re-search-backward ":\\<" nil t)
      (message "hit")
    (message "miss")))

That is, if we're at the point where this zero-length match should
match, it doesn't.  This succeeds:

(with-temp-buffer
  (emacs-lisp-mode)
  (insert "wibble:wobble")
  (goto-char (point-min))
  (search-forward ":")
  (forward-char 1)
  (if (re-search-backward ":\\<" nil t)
      (message "hit")
    (message "miss")))

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




This bug report was last modified 3 years and 311 days ago.

Previous Next


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