From: Eric Michael Timmons <etimmons@mit.edu>
To: 38867@debbugs.gnu.org
Subject: bug#38867: 27.0.60; fileloop-initialize-replace misses occurrences to be replaced
Date: Thu, 2 Jan 2020 05:08:25 +0000 [thread overview]
Message-ID: <1577941704945.15167@mit.edu> (raw)
[-- Attachment #1: Type: text/plain, Size: 1143 bytes --]
Severity: normal
Tags: patch
When using fileloop-initialize-replace on files that already have open
buffers and points in arbitrary locations, occurrences of the regex to
replace can be missed. This appears to happen on my setup when
switch-to-buffer-preserve-window-point is non-nil. The call to
switch-buffer between the invocation of the scan- and operate-functions
can then cause the point to change to a different location than the
scan-function left it.
This can manifest itself by either missing occurrences of the regex in
the open files where point is beyond some occurrences or it can
completely miss files if some file early on in the iteration has its
point beyond all occurrences of the regex, causing the operate-function
to return nil, aborting the rest of the operation.
In GNU Emacs 27.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.13, cairo version 1.16.0)
of 2019-12-27 built on rocinante
Repository revision: 8224ed7d406e8654a163b05c0c647a5d44c090ed
Repository branch: emacs-27
Windowing system distributor 'The X.Org Foundation', version 11.0.12006000
System Description: Gentoo/Linux
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-fileloop-initialize-replace-with-buffers-that-ar.patch --]
[-- Type: text/x-patch; name="0001-Fix-fileloop-initialize-replace-with-buffers-that-ar.patch", Size: 1810 bytes --]
From 74ec2867aa21b3128e2600048f98f3e7782fe0ad Mon Sep 17 00:00:00 2001
From: Eric Timmons <etimmons@mit.edu>
Date: Wed, 1 Jan 2020 22:33:47 -0600
Subject: [PATCH] Fix fileloop-initialize-replace with buffers that are already
open
The operate-function used in fileloop-initialize-replace assumed that
the point does not change between the invocation of the scan-function
and operate-function. This assumption is violated, however, if the
file being operated on has already been opened in a window and
`switch-to-buffer-preserve-window-point' is non-nil.
Fix by telling `perform-replace' to operate over the entire
buffer. Could potentially be further be optimized by saving the point
in the scan-function and using it as the start point in the
operate-function.
---
lisp/fileloop.el | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/lisp/fileloop.el b/lisp/fileloop.el
index 543963feaf..0c8ec5b8e0 100644
--- a/lisp/fileloop.el
+++ b/lisp/fileloop.el
@@ -205,13 +205,11 @@ DELIMITED if non-nil means replace only word-delimited matches."
(lambda ()
(let ((case-fold-search
(if (memql case-fold '(nil t)) case-fold case-fold-search)))
- (if (re-search-forward from nil t)
- ;; When we find a match, move back
- ;; to the beginning of it so perform-replace
- ;; will see it.
- (goto-char (match-beginning 0)))))
+ (re-search-forward from nil t)))
(lambda ()
- (perform-replace from to t t delimited nil multi-query-replace-map))))
+ ;; We provide START and END because the buffer is not guaranteed
+ ;; to be at any particular point when this is called.
+ (perform-replace from to t t delimited nil multi-query-replace-map (point-min) (point-max)))))
(provide 'fileloop)
;;; fileloop.el ends here
--
2.24.1
next reply other threads:[~2020-01-02 5:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-02 5:08 Eric Michael Timmons [this message]
2020-03-24 10:00 ` bug#38867: 27.0.60; fileloop-initialize-replace misses occurrences to be replaced Noam Postavsky
2020-03-24 14:08 ` Eli Zaretskii
2020-03-31 22:23 ` Noam Postavsky
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=1577941704945.15167@mit.edu \
--to=etimmons@mit.edu \
--cc=38867@debbugs.gnu.org \
/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).