I have been suffering this issue for a few months, unable to reproduce it until now.
In short, the issue is that when creating a new file, editing it, and then deciding to rename the file, the buffer's file is replaced by the lockfile location and not the original file location.
I do not have a minimal config which reliably reproduces the issue, but I may have a sufficient cross-section to get close.
I have the following changes to lockfiles and auto-save:
(defconst --lockfile-directory (concat user-emacs-directory "lockfiles/")
(setq auto-save-file-name-transforms `((".*" ,--lockfile-directory t)))
(setq auto-save-default t)
(setq auto-save-timeout 20)
(setq auto-save-interval 200)
Steps to reproduce:
Create new file and add some text
Save the file
Rename the file with
write-file
Make some changes to the file
The buffer is now in the lockfile.
Since there's a pause, I suspect a timer is at play, but listing my timers, I don't see anything that stands out except maybe the auto-revert-buffers
timer.
List of timers:
6.0s 5.0s auto-revert-buffers
8.8s - undo-auto--boundary-timer
* 0.0s t jit-lock-deferred-fontify
* 0.1s t show-paren-function
* 0.2s t ggtags-highlight-tag-at-point
* 0.5s :repeat blink-cursor-start
* 0.5s t #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_14>
* 0.5s t #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_12>
* 0.5s t posframe-hidehandler-daemon-function
* 1.0s repeat ess--idle-timer-function
* 1.0s t semantic-idle-scheduler-function
* 1.2s t reftex-view-crossref-when-idle
* 30.0s t js-gc
* 1m 0.0s t semantic-idle-scheduler-work-function
* 1m 0.0s t bibtex-parse-buffers-stealthily
dotfiles mostly up to date, but the backups configuration has been disabled, but I haven't pushed the changes.
Because it probably matters, here is the version information:
GNU Emacs 28.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.16.0)
GNU Guix SD @ 207a1625e937f916506d00ba1407c5baf27791b6
For further clarity, this is the native elisp compiled Emacs, though that doesn't matter, I've seen this issue before I switched to native branch.
Related Questions
How to autosave a buffer to the original file on disk?
I see from here, that perhaps the issue is that I change the location of the auto-save file and, therefore, when explicitly saving the file, emacs doesn't know how to find the original file being visited?
Related, I see the down sides of toggling
auto-save-visited-file-name
, so if possible, avoiding that "solution" is desirable.
Minimal Config (emacs -Q
)
I have paired down the configuration to the following to reproduce the issue with the above steps.
(setq auto-save-visited-file-name t)
(setq auto-save-default t)
(setq auto-save-timeout 20)
(setq auto-save-interval 20)
The timeout and interval value are likely not contributing, but usefully small for reproducing the issue.
I forgot I am in fact setting auto-save-visited-file-name
which turns out to be the issue. If I disable this, the issue goes away.
Now, it remains to be said if changing the buffer to the lockfile location is the correct behavior for auto-save-visited-file-name
.
M-x report-emacs-bug
emacs -Q
+ "some config" I would likely report that if it is indeed a bug.emacs -Q
would help a lot, though.auto-save-visited-file-name
. Turning that off seems to correct the behavior.