Subject: bug#77323: [PATCH] Allow temp buffer cleanup in ediff-current-file

From: "Paul D. Nelson" <[email-masked]>
Date: Mon, 31 Mar 2025 09:07:07 +0200

> Apart from that, this case doesn't really fit into any other case that
> handles automatically created buffers.  Although -
> `ediff-dispose-of-variant-according-to-user' is not only about indirect
> buffers, right?  We could marry this case with this existing mechanism.
> Would that make some sense?

Currently, ediff-dispose-of-variant-according-to-user

- kills any indirect buffers with ediff-temp-indirect-buffer non-nil
  (used by region/window comparison), and

- if ediff-keep-variants is nil, asks about killing any unmodified
  buffers.

It's not clear to me how best to fit modified non-file buffers (such as
the FILE=... buffer produced by ediff-current-file) into this picture.
And, as you point out, the user might wish to keep such buffers around.

> And apart from that, adding a STARTUP-HOOKS argument to
> `ediff-current-file' looks acceptable to me, although it would have no
> direct uses in Emacs currently.  I don't like it when users are forced
> to use really bad hacks to change the behavior of such cases.

That indeed seems like the simplest way to allow customization that
doesn't resort to hacks or simply overwriting the function, so please
see the attached patch.

>From fd9b5d248fb8112be8dc4ff6db5bd2bc04c4f588 Mon Sep 17 00:00:00 2001
From: Paul Nelson <[email-masked]>
Date: Mon, 31 Mar 2025 08:31:23 +0200
Subject: [PATCH] ediff-current-file: Add optional startup-hooks arg

* lisp/vc/ediff.el (ediff-current-file): Add optional
startup-hooks argument, so that the user can write wrapper
commands with more finely customized behavior.
---
 lisp/vc/ediff.el | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lisp/vc/ediff.el b/lisp/vc/ediff.el
index 36580c73d6b..bc89b2025ff 100644
--- a/lisp/vc/ediff.el
+++ b/lisp/vc/ediff.el
@@ -360,10 +360,13 @@ ediff-files-internal
 (defalias 'ediff #'ediff-files)
 
 ;;;###autoload
-(defun ediff-current-file ()
+(defun ediff-current-file (&optional startup-hooks)
   "Start ediff between current buffer and its file on disk.
 This command can be used instead of `revert-buffer'.  If there is
-nothing to revert then this command fails."
+nothing to revert then this command fails.
+
+Non-interactively, STARTUP-HOOKS is a list of functions that Emacs calls
+without arguments after setting up the Ediff buffers."
   (interactive)
   ;; This duplicates code from menu-bar.el.
   (unless (or (not (eq revert-buffer-function 'revert-buffer--default))
@@ -395,7 +398,7 @@ ediff-current-file
       (insert-file-contents file-name)
       ;; Assume same modes:
       (funcall current-major))
-    (ediff-buffers revert-buf (current-buffer))))
+    (ediff-buffers revert-buf (current-buffer) startup-hooks)))

 ;;;###autoload
-- 
2.39.3 (Apple Git-145)