Subject: Re: bug#35119: 26.1; narrow-to-region loses word-start/symbol-start information at end

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 01 Sep 2021 11:08:41 +0200

Sam Halliday <[email-masked]> 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