From 74ec2867aa21b3128e2600048f98f3e7782fe0ad Mon Sep 17 00:00:00 2001 From: Eric Timmons 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