GNU bug report logs - #49124
Wdired doesn't like re-search-forward/replace-match

Previous Next

Package: emacs;

Reported by: Eduardo Ochs <eduardoochs <at> gmail.com>

Date: Sun, 20 Jun 2021 00:34:02 UTC

Severity: normal

Tags: moreinfo, patch

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eduardo Ochs <eduardoochs <at> gmail.com>
Cc: 49124 <at> debbugs.gnu.org
Subject: bug#49124: Wdired doesn't like re-search-forward/replace-match
Date: Sun, 20 Jun 2021 03:28:56 +0200
Eduardo Ochs <eduardoochs <at> gmail.com> writes:

> Here's how to see the bug in action. Define `foo' by executing this
> defun:
>
>   (defun foo (s e)
>     "Replace all `a's by `b's in the region."
>     (interactive "r")
>     (save-excursion
>       (save-restriction
>         (narrow-to-region s e)
>         (goto-char (point-min))
>         (while (re-search-forward "a" nil 'noerror)
>           (replace-match "b" 'fixedcase 'literal)))))
> [...]

I can reproduce the issue.  The culprit seems to be `narrow-to-region'
which seems to confuse the functions wdired now installs in the before
and/or after change hooks (they expect at least complete lines) --
because this version:

(defun foo (s e)
  "Replace all `a's by `b's in the region."
  (interactive "r")
  (save-excursion
    (save-restriction
      ;; (narrow-to-region s e)
      (goto-char s)
      (while (re-search-forward "a" e 'noerror)
        (replace-match "b" 'fixedcase 'literal)))))

works as expected.

I guess we should just temporarily `widen' in these functions.

Michael.




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

Previous Next


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