unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Eduardo Ochs <eduardoochs@gmail.com>
Cc: 49124@debbugs.gnu.org
Subject: bug#49124: Wdired doesn't like re-search-forward/replace-match
Date: Sun, 20 Jun 2021 03:28:56 +0200	[thread overview]
Message-ID: <87o8c1b9yf.fsf@web.de> (raw)
In-Reply-To: <CADs++6imWzL9TV79NAbd92QDZSan9jYK2uGvx8iE3XGv2qNQeg@mail.gmail.com> (Eduardo Ochs's message of "Sat, 19 Jun 2021 21:33:37 -0300")

Eduardo Ochs <eduardoochs@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.





  reply	other threads:[~2021-06-20  1:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-20  0:33 bug#49124: Wdired doesn't like re-search-forward/replace-match Eduardo Ochs
2021-06-20  1:28 ` Michael Heerdegen [this message]
2021-06-20  1:45   ` Eduardo Ochs
2021-06-20  2:12     ` Michael Heerdegen
2021-06-21 13:11       ` Lars Ingebrigtsen
2021-06-21 21:59         ` Michael Heerdegen
2021-07-19 17:04           ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o8c1b9yf.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=49124@debbugs.gnu.org \
    --cc=eduardoochs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).