Closed benthamite closed 4 years ago
Hey!
Thanks for reporting this issue. I hadn't considered this before.
Which version of Emacs are you using? After having a quick look it appears that setting auto-save-visited-file-name
and the related mode just don't call save-buffer
or the likes, but write-region
instead. Emacs also tells me that auto-save-visited-file-name
has been obsolete since Emacs 26.1 and you should use auto-save-visited-mode
instead. If this is an option for you, could you check to see if this might work for you?
If using auto-save-visited-mode
doesn't help or isn't an option, I'll see if I can make it work.
Hi, thank you for the quick and helpful reply.
I replaced (setq auto-save-visited-file-name t)
with (setq auto-save-visited-mode t)
but the issue persists. To make sure the buffer was being saved to the same file, I killed it after having modified it, and Emacs didn't ask for confirmation. When I revisited the file, the modifications I had made were present, confirming that the buffer had been auto-saved. I'm not sure what explains this behavior, since the relevant section of the Emacs manual reads:
If you want auto-saving to be done in the visited file rather than in a separate auto-save file, enable the global minor mode auto-save-visited-mode. In this mode, auto-saving is identical to explicit saving.
In this respect, at least, auto-saving and explicit saving are not behaving identically.
I'm using Emacs 27.1 (Spacemacs v.0.300.0) on macOS.
Hmmm, I've tried to reproduce this. I've tested on both Emacs 28.0.50 and 27.1. I use plain Emacs and Archlinux however, though I'd be surprised if that made a difference because I didn't notice any special cases for either in the auto save code. I also use M-x auto-save-visited-mode
or (auto-save-visited-mode)
instead of (setq auto-save-visited-mode t)
. When I use the latter it doesn't automatically save at all for me, but I don't usually set minor mode variables, but call the procedures, so perhaps I'm doing that wrong.
When it does automatically save the file it also commits the change for me. I also really don't know why it wouldn't because auto-save-visited-mode
ends up calling save-some-buffers
, which ends up calling save-buffer
, which calls basic-save-buffer
, which calls (run-hooks 'after-save-hook)
, which is the hook that this project uses to commit changes to git.
I'm sorry to ask this, I'm sure it's a dumb question, but did you restart Emacs when you changed from auto-save-visited-file-name
to auto-save-visited-mode
? And did you disable auto-save-mode
? This would all make sense if it was auto-save-mode
sticking around with auto-save-visited-file-name
still accidentally being t
. But I'm sure that would be too easy :)
Thanks again for your detailed answer.
I am happy to report that I managed to resolve the issue. As you hinted, part of the problem was that I was using (setq auto-save-visited-mode t)
rather than '(auto-save-visited-mode)
(I only started using Emacs two months ago and am still very confused, as you can tell.) In addition, Spacemacs has a default setting, dotspacemacs-auto-save-file-location
, which, if set to 'original
, will set the value of the obsolete auto-save-visited-file-name
to t
. So it's plausible that this was interfering with auto-save-visited-mode
.
Anyway, I appreciate your help, and kudos for developing such a useful package!
Excellent :D
And thank you, I'm glad it's useful to you.
As far as I can tell, git-auto-commit-mode does not automatically commit when Emacs auto-saves a buffer to the same file (this will happen if
auto-save-visited-file-name
is set to true). Moreover, once the buffer is so saved, it ceases to be possible to commit even when attempting to save manually, since Emacs will refuse to save the buffer as there are no new changes to save. Is there a way to configure git-auto-commit-mode to resolve this issue?