In my ~/.emacs.d/init.el, I have auto-save-file-name-transforms set so that auto-save files are saved at paths such as /home/[user]/.emacs.d/auto-saves/#!home![user]!path!to!file#. This works fine.
In a directory ~/foo/bar version-controlled in Git, I would like to have auto-saves of files in that directory instead be saved into ~/foo/bar/.emacs.d/auto-saves, so I try to set auto-save-file-name-transforms in ~/foo/bar/.dir-locals.el, but this does not seem to work.
As a minimal reproduction, I make a new directory ~/tmp/test, run git init inside it, and put the following as ~/tmp/test/.dir-locals.el:
;;; Directory Local Variables -*- no-byte-compile: t -*-
;;; For more information see (info "(emacs) Directory Variables")
((nil . ((eval . (let* ((root (project-root (project-current)))
(dir (file-name-concat root ".emacs.d/auto-saves/")))
(make-directory dir t)
(setq-local auto-save-file-name-transforms
`((".*" ,dir t))))))))
After I C-x C-c and reopen Emacs and reopen this .dir-locals.el file, I know Emacs is reading this file because it prompts me to confirm that I would like to run the code in the file. However, the setting of auto-save-file-name-transforms does not seem to work:
~/tmp/test/.emacs.d/auto-saves/is created as desired,for the
.dir-locals.elfile,auto-save-file-name-transformsis((".*" "~/tmp/test/.emacs.d/auto-saves/" t)), which looks right, and(make-auto-save-file-name)returns"/home/[user]/tmp/test/.emacs.d/auto-saves/#!home![user]!tmp!test!.dir-locals.el#", which is indeed the path at which I would like the file to be auto-saved,but
buffer-auto-save-file-nameis"/home/[user]/.emacs.d/auto-saves/#!home![user]!tmp!test!.dir-locals.el#", which is the same as it would be if this.dir-locals.eldid nothing,- and, indeed, if I edit the file, it is auto-saved at that unwanted path.
In the manual node "(emacs)Top > Files > Auto Save > Auto Save Files", I see "The file name to be used for auto-saving in a buffer is calculated when auto-saving is turned on in that buffer". I guess that buffer-auto-save-file-name is being set too early, before the .dir-locals.el file locally overwrites auto-save-file-name-transforms.
How, if at all, can I make the files in the Git-versioned directory be auto-saved into a .emacs.d/auto-saves/ in that same Git-versioned directory rather than to the .emacs.d/auto-saves/ in my home directory?
(emacs-version) gives "GNU Emacs 30.1 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.18.2, Xaw3d scroll bars)".