From: Juri Linkov <juri@linkov.net>
To: Eshel Yaron <me@eshelyaron.com>
Cc: 65854@debbugs.gnu.org
Subject: bug#65854: Multi-file replacement diff
Date: Tue, 12 Sep 2023 09:49:17 +0300 [thread overview]
Message-ID: <86bke7q34y.fsf@mail.linkov.net> (raw)
In-Reply-To: <86zg1t2m7j.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 11 Sep 2023 10:38:56 +0300")
>> Yes, but what is the use case for generating the diff based on the
>> contents on disk when the file is modified in Emacs? Basically, my
>> suggestion is to check in `multi-file-replace-regexp-as-diff` if any of
>> the matching files are visited by some buffer, and if so simply pass the
>> buffer instead of the file name for that file to
>> `multi-file-replace-as-diff`. That way you always get an up-to-date
>> diff, and you don't need to manually check that you don't have any of
>> the matching files open by any chance. Does that make sense?
>
> Thanks for the idea, this makes sense and will help to
> reduce the number of commands from 2 to 1 by merging
> multi-buffer-replace-regexp-as-diff with
> multi-file-replace-regexp-as-diff.
Actually, separate commands are still needed when we will add
a command to show replacement diffs on the buffers marked on
the buffer list from M-x list-buffers.
But it seems we can't avoid the limitation that such buffers
should be file-visiting. I see no way to generate a diff
for non-file buffers because 'C-c C-a' from diff-mode needs
a file name to apply the hunk to the file buffer.
Also another useful command that probably will be used the
most often is to show a replacement diff for the current buffer
as a counterpart of query-replace:
```
diff --git a/lisp/misearch.el b/lisp/misearch.el
index da70d708a9e..9aa639af5fe 100644
--- a/lisp/misearch.el
+++ b/lisp/misearch.el
@@ -500,6 +501,22 @@ multi-buffer-replace-regexp-as-diff
(list buffers (nth 0 common) (nth 1 common) (nth 2 common))))
(multi-file-replace-as-diff buffers regexp to-string t delimited))
+;;;###autoload
+(defun replace-regexp-as-diff (regexp to-string &optional delimited)
+ "Show replacements in the current file buffer matching REGEXP with TO-STRING as diff.
+With a prefix argument, ask for a regexp, and replace in file buffers
+whose names match the specified regexp."
+ (interactive
+ (let ((common
+ (query-replace-read-args
+ (concat "Replace"
+ (if current-prefix-arg " word" "")
+ " regexp as diff in buffers")
+ t t)))
+ (list (nth 0 common) (nth 1 common) (nth 2 common))))
+ (multi-file-replace-as-diff
+ (list (current-buffer)) regexp to-string t delimited))
+
\f
(defvar unload-function-defs-list)
```
next prev parent reply other threads:[~2023-09-12 6:49 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-10 17:18 bug#65854: Multi-file replacement diff Juri Linkov
2023-09-10 17:58 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-11 6:33 ` Juri Linkov
2023-09-11 7:23 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-11 7:38 ` Juri Linkov
2023-09-12 6:49 ` Juri Linkov [this message]
2023-09-11 12:35 ` Eli Zaretskii
2023-09-12 6:52 ` Juri Linkov
2023-09-15 6:40 ` Juri Linkov
2023-09-15 7:02 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-15 7:38 ` Eli Zaretskii
2023-09-22 6:55 ` Juri Linkov
2023-09-22 7:25 ` Eli Zaretskii
2023-09-22 16:02 ` Juri Linkov
2023-09-22 16:06 ` Eli Zaretskii
2023-09-23 17:36 ` Juri Linkov
2023-09-23 18:56 ` Eli Zaretskii
2023-09-24 7:37 ` Juri Linkov
2023-09-24 8:12 ` Eli Zaretskii
2023-09-25 18:18 ` Juri Linkov
2023-09-24 1:43 ` Dmitry Gutov
2023-09-24 7:36 ` Juri Linkov
2023-09-24 11:09 ` Dmitry Gutov
2023-09-25 17:58 ` Juri Linkov
2023-09-26 21:39 ` Dmitry Gutov
2023-09-27 17:21 ` Juri Linkov
2023-09-30 17:42 ` Juri Linkov
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86bke7q34y.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=65854@debbugs.gnu.org \
--cc=me@eshelyaron.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.