Subject: Re: bug#65854: Multi-file replacement diff

From: Eshel Yaron <[email-masked]>
Date: Sun, 10 Sep 2023 19:58:10 +0200

Hi there,

Juri Linkov <[email-masked]> writes:

> +(defun multi-file-replace-as-diff (files-or-buffers from-string replacements regexp-flag delimited-flag)
> +  (require 'diff)
> +  (let ((inhibit-message t)
> +        (diff-buffer (get-buffer-create "*replace-diff*")))
> +    (with-current-buffer diff-buffer
> +      (buffer-disable-undo (current-buffer))
> +      (let ((inhibit-read-only t))
> +        (erase-buffer))
> +      (diff-mode))
> +    (dolist (file-or-buffer files-or-buffers)
> +      (let ((file-name (if (bufferp file-or-buffer) buffer-file-name file-or-buffer)))
> +        (when file-name
> +          (with-temp-buffer
> +            (if (bufferp file-or-buffer)
> +                (insert-buffer-substring file-or-buffer)
> +              (insert-file-contents file-or-buffer))

I wonder what happens if I call `multi-file-replace-regexp-as-diff` and
select a file `foo.txt`, that I already have open and modified in a
buffer.  IIUC, this will generate the diff based on the contents of the
file on disk, not the buffer, so it might not match when I subsequently
try to apply the diff to the buffer.  WDYT?

Eshel