From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#38867: 27.0.60; fileloop-initialize-replace misses occurrences to be replaced Date: Tue, 24 Mar 2020 06:00:05 -0400 Message-ID: <87a746jcnu.fsf@gmail.com> References: <1577941704945.15167@mit.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="51299"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.90 (gnu/linux) Cc: 38867@debbugs.gnu.org To: Eric Michael Timmons Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 24 11:01:12 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jGgMy-000DAA-Ik for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Mar 2020 11:01:12 +0100 Original-Received: from localhost ([::1]:45256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgMx-000402-GL for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Mar 2020 06:01:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49155) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgMp-0003zw-PZ for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2020 06:01:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGgMo-00080Q-9g for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2020 06:01:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47936) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGgMo-00080H-2d for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2020 06:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jGgMn-0002IX-VQ for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2020 06:01:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Mar 2020 10:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38867 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 38867-submit@debbugs.gnu.org id=B38867.15850440168754 (code B ref 38867); Tue, 24 Mar 2020 10:01:01 +0000 Original-Received: (at 38867) by debbugs.gnu.org; 24 Mar 2020 10:00:16 +0000 Original-Received: from localhost ([127.0.0.1]:53909 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jGgM3-0002H8-PP for submit@debbugs.gnu.org; Tue, 24 Mar 2020 06:00:16 -0400 Original-Received: from mail-qt1-f171.google.com ([209.85.160.171]:45541) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jGgM1-0002Gs-Ev for 38867@debbugs.gnu.org; Tue, 24 Mar 2020 06:00:14 -0400 Original-Received: by mail-qt1-f171.google.com with SMTP id t17so4269123qtn.12 for <38867@debbugs.gnu.org>; Tue, 24 Mar 2020 03:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=3nbH65eQf4nlxpKdkoUGr6jUDRbsATtXUouTQyxTHSQ=; b=AyZEKWMOOGwP1KLEaVkvDrG/ufLMp3z0HHeuzSpPtjiAzhMGnF52hihdunvGrvA4On O/mqfhqTW2kmXbPTjJqVO9f2s0dLG7yakOWlMpe0QBJfzA/0FTiiEDYa2dMMoU5+XQTh HBgPAqGxj95OoLxVqWuCmwPSrdlk3+HDKF8SMFZj0hsIEMn7vo5TmfnYnp4lF3Bm+GJh /a/d6aeg+6OA4PUuP9R59z1QNaU9b+0xSNiOFOKll6pqRQ8mvzR8xV0m+2W/TIYl9kwx rTyYO0D0IAYjIzF3vS1+LOpU6SLIRngmiEoPA0R0cCxUpiiJDjlc5ieMOLnV+Ha8k8My 92Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=3nbH65eQf4nlxpKdkoUGr6jUDRbsATtXUouTQyxTHSQ=; b=jC5L+8f4neezZbbf9jHZUnyttgFcv/pdqrut+mR2lZ/FSd48BhZAJhwYUnq8WftNta VYV96FWLRSfiGXore4aVYiMqnpSGQ4UEpSO6ZlDRF6hO/Fyozk0br4dfYdQyxxFNFGhW K4oJB2nLoq4AVg6ojCxPlns/ynpPtvSdF5RGu3A+XzdHR9itO0c58CwXz0nXxIX1K/fY 5V7k+w9o3hD6CuiYNiXGueOKG8a2/dWnz+GdHAgTq2r2Y43DJLSu+HRkAQnrYL3Snkll eXrABBEtemgAD/li/pQRNCzNeBJARdh8uuIGLMFNVCwkEcuWuqwFG5m6tHsob+Pj0t2+ kpjQ== X-Gm-Message-State: ANhLgQ0gsEi3zh9rEPDFhQCcPplIKXgFFBiJBCSpvRIKENK0N2jStLHq If4926NIsdQWYgcB7W53e6DtjLPD X-Google-Smtp-Source: ADFU+vvwq1ay//aCCAHBSAbQUSIh6MAk+hGTgRmbaQJfQ5qPwJ/ovIMSz8iukz0phBjv9bL2n/nw4w== X-Received: by 2002:ac8:6697:: with SMTP id d23mr16344108qtp.8.1585044007648; Tue, 24 Mar 2020 03:00:07 -0700 (PDT) Original-Received: from minid (cbl-45-2-119-47.yyz.frontiernetworks.ca. [45.2.119.47]) by smtp.gmail.com with ESMTPSA id p191sm13076909qke.6.2020.03.24.03.00.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Mar 2020 03:00:06 -0700 (PDT) In-Reply-To: <1577941704945.15167@mit.edu> (Eric Michael Timmons's message of "Thu, 2 Jan 2020 05:08:25 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:177675 Archived-At: --=-=-= Content-Type: text/plain Eric Michael Timmons writes: > 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. Since the current code is trying to save the point in the scan function, it's better to keep that optimization. See patch below. Should this go to emacs-27 or master? The assumption that point would be preserved seems to be long-standing, but I guess the change in the default of switch-to-buffer-preserve-window-point is what surfaces the bug and makes it more recent... --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Don-t-lose-point-during-fileloop-replace-Bug-38867.patch Content-Description: patch >From 033564127065e213868f034f08b32d14ad3d1c74 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Tue, 24 Mar 2020 05:39:03 -0400 Subject: [PATCH] Don't lose point during fileloop replace (Bug#38867) Suggested by Eric Michael Timmons . * lisp/fileloop.el (fileloop-initialize-replace): Save the match-beginning position in a variable instead of the buffer's point. The point may be changed by the time perform-replace is called, e.g., due to switch-to-buffer-preserve-window-point. --- lisp/fileloop.el | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lisp/fileloop.el b/lisp/fileloop.el index 543963feaf..8f4911638e 100644 --- a/lisp/fileloop.el +++ b/lisp/fileloop.el @@ -200,18 +200,22 @@ fileloop-initialize-replace DELIMITED if non-nil means replace only word-delimited matches." ;; FIXME: Not sure how the delimited-flag interacts with the regexp-flag in ;; `perform-replace', so I just try to mimic the old code. - (fileloop-initialize - files - (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))))) - (lambda () - (perform-replace from to t t delimited nil multi-query-replace-map)))) + (let ((mstart (make-hash-table :test 'eq))) + (fileloop-initialize + files + (lambda () + (let ((case-fold-search + (if (memql case-fold '(nil t)) case-fold case-fold-search))) + (when (re-search-forward from nil t) + ;; When we find a match, save its beginning for + ;; `perform-replace' (we used to just set point, but this + ;; is unreliable in the face of + ;; `switch-to-buffer-preserve-window-point'). + (puthash (current-buffer) (match-beginning 0) mstart)))) + (lambda () + (perform-replace from to t t delimited nil multi-query-replace-map + (gethash (current-buffer) mstart (point-min)) + (point-max)))))) (provide 'fileloop) ;;; fileloop.el ends here -- 2.11.0 --=-=-=--