Subject: Option 'file-precious-flag' creates unrelatable/untrackable temporary filenames

From: "R. Diez" <[email-masked]>
Date: Fri, 15 Aug 2025 21:14:17 +0200

Hi all:

Some time ago, I enabled option 'file-precious-flag' after getting file corruption when editing remote files over unstable links.

The trouble is, 'file-precious-flag' generates cryptic temporary filenames like "tmp1eghjG". If there is a network problem while saving, such files are left scattered behind, and when you (or some other sysadmin) realise about those orphaned files next month (or even later), such filenames make it hard to know exactly was caused the problem and what file it was related to.

In the past months, I have increasingly suffered this orphaned file problem due to a Tramp issue described here:

Please change the naming template for temporary files
https://lists.gnu.org/archive/html/tramp-devel/2025-08/msg00007.html

After some struggling (I am no Emacs guru), I finally tracked down the related code in my Emacs 29. Function basic-save-buffer-2 in files.el builds the temporary filename like this:

(setq tempname
   (make-temp-file
    (expand-file-name "tmp" dir)))

That is where those tmpXXXX filenames are coming from.

In contrast, function make-auto-save-file-name in the same file (files.el) uses the buffer's filename to construct the temporary filename:

(make-temp-file
  (let ((fname
     (expand-file-name
      (format "#%s#" buffer-name)

Could you modify the first make-temp-file call, so that it is clear what file the temporary file relates to? It would also be best if the word "Emacs" were part or the temporary filename, like Tramp does, so that you know what piece of software caused the littering.

Thanks in advance,
   rdiez