Subject: [PATCH] Pass dired default filenames via defaults argument

From: Spencer Baugh <[email-masked]>
Date: Fri, 22 Aug 2025 17:20:13 -0400

Tags: patch

Rather than using minibuffer-with-setup-hook and
minibuffer-default-add-function, just pass the list of default
file names as a regular argument to read-file-name.  This
behaves better with various customizations, and also allows the
normal abbreviate-file-name logic in read-file-name to run.

In GNU Emacs 30.1.90 (build 9, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.15.12, Xaw scroll bars) of 2025-08-14 built on
 igm-qws-u22796a
Repository revision: 6adc26ffa74aedbd1cfa9a1ee72073ebccea2b96
Repository branch: emacs-30
Windowing system distributor 'The X.Org Foundation', version 11.0.12101016
System Description: Rocky Linux 8.10 (Green Obsidian)

Configured using:
 'configure --with-x-toolkit=lucid --without-gpm --without-gconf
 --without-selinux --without-imagemagick --with-modules --with-gif=no
 --with-cairo --with-rsvg --without-compress-install --with-tree-sitter
 --with-native-compilation=aot
 PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/'

>From d031ccb5df9984930cf6e5bd06fa1ed572ff6359 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Fri, 22 Aug 2025 17:19:09 -0400
Subject: [PATCH] Pass dired default filenames via defaults argument

Rather than using minibuffer-with-setup-hook and
minibuffer-default-add-function, just pass the list of default
file names as a regular argument to read-file-name.  This
behaves better with various customizations, and also allows the
normal abbreviate-file-name logic in read-file-name to run.

* lisp/dired-aux.el (dired-do-create-files): Pass default file
names as an argument.
---
 lisp/dired-aux.el | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 049d200f590..92513b8c72f 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -2673,22 +2673,18 @@ dired-do-create-files
 		         (expand-file-name (file-name-nondirectory
                                             (car fn-list))
 					   target-dir)))
-	   (defaults (dired-dwim-target-defaults fn-list target-dir))
+	   (defaults (cons default (dired-dwim-target-defaults fn-list target-dir)))
 	   (target (expand-file-name ; fluid variable inside dired-create-files
-		    (minibuffer-with-setup-hook
-		        (lambda ()
-                          (setq-local minibuffer-default-add-function nil)
-			  (setq minibuffer-default defaults))
-		      (dired-mark-read-file-name
-                       (format "%s %%s %s: "
-                               (if dired-one-file op1 operation)
-                               (if (memq op-symbol '(symlink hardlink))
-                                   ;; Linking operations create links
-                                   ;; from the prompted file name; the
-                                   ;; other operations copy (etc) to the
-                                   ;; prompted file name.
-                                   "from" "to"))
-		       target-dir op-symbol arg rfn-list default))))
+		    (dired-mark-read-file-name
+                     (format "%s %%s %s: "
+                             (if dired-one-file op1 operation)
+                             (if (memq op-symbol '(symlink hardlink))
+                                 ;; Linking operations create links
+                                 ;; from the prompted file name; the
+                                 ;; other operations copy (etc) to the
+                                 ;; prompted file name.
+                                 "from" "to"))
+		     target-dir op-symbol arg rfn-list defaults)))
 	   (into-dir
             (progn
               (when
-- 
2.43.7