From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#65854: Multi-file replacement diff Date: Mon, 25 Sep 2023 21:18:49 +0300 Organization: LINKOV.NET Message-ID: <86r0mmxf5a.fsf@mail.linkov.net> References: <86sf7mgd54.fsf@mail.linkov.net> <86bke943tp.fsf@mail.linkov.net> <83jzswrios.fsf@gnu.org> <86o7i7oo9t.fsf@mail.linkov.net> <86sf7g548a.fsf@mail.linkov.net> <83pm2jkhsg.fsf@gnu.org> <86msxeu1q3.fsf@mail.linkov.net> <83zg1e7jq3.fsf@gnu.org> <86o7hunqyu.fsf@mail.linkov.net> <83jzsi5h1n.fsf@gnu.org> <86r0movlkt.fsf@mail.linkov.net> <83h6nk4t32.fsf@gnu.org> <86ttrkvx65.fsf@mail.linkov.net> <831qeo3s70.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31159"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: me@eshelyaron.com, 65854@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 25 20:52:03 2023 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 1qkqgd-0007xD-9f for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 25 Sep 2023 20:52:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqgR-0007dP-34; Mon, 25 Sep 2023 14:51:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkqgQ-0007dC-80 for bug-gnu-emacs@gnu.org; Mon, 25 Sep 2023 14:51:50 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqgP-0003ai-W7 for bug-gnu-emacs@gnu.org; Mon, 25 Sep 2023 14:51:50 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qkqgc-00020H-G9 for bug-gnu-emacs@gnu.org; Mon, 25 Sep 2023 14:52:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 25 Sep 2023 18:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65854 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65854-submit@debbugs.gnu.org id=B65854.16956678857653 (code B ref 65854); Mon, 25 Sep 2023 18:52:02 +0000 Original-Received: (at 65854) by debbugs.gnu.org; 25 Sep 2023 18:51:25 +0000 Original-Received: from localhost ([127.0.0.1]:46670 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkqg1-0001zN-7J for submit@debbugs.gnu.org; Mon, 25 Sep 2023 14:51:25 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:32901) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkqfy-0001z8-0c for 65854@debbugs.gnu.org; Mon, 25 Sep 2023 14:51:23 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id AAFF61C0004; Mon, 25 Sep 2023 18:51:01 +0000 (UTC) In-Reply-To: <831qeo3s70.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 24 Sep 2023 11:12:51 +0300") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:271349 Archived-At: --=-=-= Content-Type: text/plain >> >> >> >> + However, when the file >> >> >> >> +is not visited in a buffer, or the buffer is not modified, still read >> >> >> >> +contents from the file." >> >> >> > >> >> >> > Seems to describe an implementation detail, and I don't think it >> >> >> > should be there. E.g., what if the file visited by the buffer no >> >> >> > longer exists? >> >> >> >> >> >> If the file visited by the buffer no longer exists, then >> >> >> the standard error is signaled. >> >> > >> >> > Which means in that case it is better to use the buffer text, no? >> >> >> >> Since replacement diffs are not supported in non-file buffers, >> >> better to signal an error for heads up. >> > >> > But it _is_ a file-visiting buffer. It's just that its file was >> > deleted meanwhile. >> >> The generated diff could not be applied to the deleted file. >> So generating a diff to the deleted file makes no sense anyway. > > I suggest not to second-guess what the user wants to do with the > generated diffs. What if they just want to email it or something? > > The basic rule of the least surprise is pertinent here: we have the > data, so why not generate the diffs when we can? > > But if you feel strongly about signaling an error in that case, I > won't object. I don't disagree. My only concern was extra complexity and performance of file-exists-p for such rare case. But if this is not a problem, here is a patch over the previous patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=multi-file-replace-as-diff.patch diff --git a/lisp/misearch.el b/lisp/misearch.el index 25d1b115af8..06bb6f57777 100644 --- a/lisp/misearch.el +++ b/lisp/misearch.el @@ -427,17 +427,24 @@ multi-file-replace-as-diff (setq buffer-read-only t) (diff-mode)) (dolist (file-name files) - (let ((file-buffer (when (eq multi-file-diff-unsaved 'use-modified-buffer) - (find-buffer-visiting file-name)))) + (let* ((file-exists (file-exists-p file-name)) + (file-buffer + (when (or (not file-exists) + (eq multi-file-diff-unsaved 'use-modified-buffer)) + (find-buffer-visiting file-name)))) (when file-name (with-temp-buffer - (if (and file-buffer (buffer-modified-p file-buffer)) + (if (and file-buffer + (or (not file-exists) + (buffer-modified-p file-buffer))) (insert-buffer-substring file-buffer) (insert-file-contents file-name)) (goto-char (point-min)) (perform-replace from-string replacements nil regexp-flag delimited-flag) - (multi-file-diff-no-select file-name (current-buffer) nil diff-buffer - (concat file-name "~") file-name))))) + (multi-file-diff-no-select + (if file-exists file-name file-buffer) + (current-buffer) nil diff-buffer + (concat file-name "~") file-name))))) (with-current-buffer diff-buffer (diff-setup-whitespace) (diff-setup-buffer-type) --=-=-=--