4

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:

  1. Create new file and add some text

  2. Save the file

  3. Rename the file with write-file

  4. Make some changes to the file

  5. 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.

4
  • If you've found a bug then you need to M-x report-emacs-bug
    – phils
    Commented Mar 9, 2022 at 3:52
  • @phils, do you think this is a bug? I'm hesitant, but if I can figure out a minimal emacs -Q + "some config" I would likely report that if it is indeed a bug.
    – kballou
    Commented Mar 9, 2022 at 18:59
  • I haven't tried to work through this in any detail, but it sure sounds like super-surprising behaviour. A recipe to reproduce from emacs -Q would help a lot, though.
    – phils
    Commented Mar 9, 2022 at 22:14
  • 1
    @phils: I have paired down the configuration to a minimal set. It does look like the issue is specifically with auto-save-visited-file-name. Turning that off seems to correct the behavior.
    – kballou
    Commented Mar 10, 2022 at 1:28

1 Answer 1

3

It helps to read the fine variable descriptions.

Namely, the following about auto-save-visited-file-name:

This variable is obsolete since Emacs 26.1; use `auto-save-visited-mode' instead. You can customize this variable. Probably introduced at or before Emacs version 26.1.

Changing the above minimal example to the following, the issue goes away:

(auto-save-visited-mode)
(setq auto-save-default t)
(setq auto-save-timeout 20)
(setq auto-save-interval 20)

So it may in fact be a "bug". However, I don't expect it to be fixed given that the "proper" way to set this behavior is through the minor mode auto-save-visited-mode.

1
  • 1
    I suggest reporting it anyway with your findings. 26.1 isn't very old, so I suspect plenty of people use that. The maintainers may see fit to update the documentation, or set stronger warnings about using the older variable.
    – phils
    Commented Mar 10, 2022 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.