Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A *real* auto-save-mode?

25 views
Skip to first unread message

shreevatsa

unread,
Jan 23, 2008, 1:21:06 AM1/23/08
to
Hello,

Emacs has an auto-save-mode, which comes useful on rare occasions such
as crashes. However, what I (and apparently, many others) would like
is a feature that automatically saves your files for you -- not to
another file but to the one your buffer is visiting, and such that you
will not be prompted to save your file on exit.

There appears to be a variable auto-save-visited-file-name which is
documented as
"Non-nil says auto-save a buffer in the file it is visiting, when
practical.
Normally auto-save files are written under other names."
but setting it does not make for a very usable Emacs -- each time one
tries to edit the buffer after it is (auto-)saved, one is prompted
with a
"file changed on disk; really edit the buffer? (y, n, r, or C-h)"
message, which gets annoying. [I guess I could turn on auto-revert-
mode to fix this, but I don't want auto-revert for changes from
external sources; I only want auto-save to work.]

I have also tried
(add-hook 'auto-save-hook 'save-buffer)
but that seems to take effect on all buffers, even completion buffers
and the minibuffer! (Why does auto-save act on these buffers anyway?)

Thanks for any advice on what to do,
Shreevatsa

David Kastrup

unread,
Jan 23, 2008, 3:15:48 AM1/23/08
to
shreevatsa <shreevat...@gmail.com> writes:

> Hello,
>
> Emacs has an auto-save-mode, which comes useful on rare occasions such
> as crashes. However, what I (and apparently, many others) would like
> is a feature that automatically saves your files for you -- not to
> another file but to the one your buffer is visiting, and such that you
> will not be prompted to save your file on exit.
>
> There appears to be a variable auto-save-visited-file-name which is
> documented as
> "Non-nil says auto-save a buffer in the file it is visiting, when
> practical.
> Normally auto-save files are written under other names."
> but setting it does not make for a very usable Emacs -- each time one
> tries to edit the buffer after it is (auto-)saved, one is prompted
> with a
> "file changed on disk; really edit the buffer? (y, n, r, or C-h)"
> message, which gets annoying. [I guess I could turn on auto-revert-
> mode to fix this, but I don't want auto-revert for changes from
> external sources; I only want auto-save to work.]

You could try reporting this bug with
M-x report-emacs-bug RET
or the Help/Send Bug Report menu.

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum

Rupert Swarbrick

unread,
Jan 23, 2008, 8:01:51 AM1/23/08
to
On Tue, 22 Jan 2008 22:21:06 -0800, shreevatsa wrote:

> Hello,
>
> Emacs has an auto-save-mode, which comes useful on rare occasions such
> as crashes. However, what I (and apparently, many others) would like is
> a feature that automatically saves your files for you -- not to another
> file but to the one your buffer is visiting, and such that you will not
> be prompted to save your file on exit.

No doubt one could hack together some elisp using run-at-time and saving
or something.

However, you might want to consider that one often writes a few lines,
then looks at it, then decides whether it should be saved or not. I find
this useful as a sort of "1st stage quality control check".

Imagine you were hacking on a program, and your (rubbish) changes got
saved automatically and invisibly. You then get bored of trying to fix
something that isn't working and navigate to other buffers, forgetting
about the original file, exiting emacs and losing any undo info that may
have existed. Then you're back to the last checkout from version control.
A bit of a disaster, no?

Rupert

martin rudalics

unread,
Jan 23, 2008, 5:37:26 PM1/23/08
to shreevat...@gmail.com, help-gn...@gnu.org
> Emacs has an auto-save-mode, which comes useful on rare occasions such
> as crashes. However, what I (and apparently, many others) would like
> is a feature that automatically saves your files for you -- not to
> another file but to the one your buffer is visiting, and such that you
> will not be prompted to save your file on exit.

`auto-save-mode' is based on a timer. There's no guarantee that the
timer has completed its latest round when you "exit".

> There appears to be a variable auto-save-visited-file-name which is
> documented as
> "Non-nil says auto-save a buffer in the file it is visiting, when
> practical.
> Normally auto-save files are written under other names."
> but setting it does not make for a very usable Emacs -- each time one
> tries to edit the buffer after it is (auto-)saved, one is prompted
> with a
> "file changed on disk; really edit the buffer? (y, n, r, or C-h)"
> message, which gets annoying. [I guess I could turn on auto-revert-
> mode to fix this, but I don't want auto-revert for changes from
> external sources; I only want auto-save to work.]

Setting `auto-save-visited-file-name' can be harmful. See, for example,

http://lists.gnu.org/archive/html/emacs-devel/2003-10/msg00306.html

and

http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-11/msg00077.html

If these threads do not convince you feel free to send a bug report.

Better yet: Help us find out why and how it doesn't work ;-)

martin rudalics

unread,
Jan 24, 2008, 4:59:23 PM1/24/08
to
pressed upon
them, to do as this person had done. And many who seemed to be under no
melancholy, some pious persons who had no special darkness or doubts
about the goodness of their state-nor were under any special trouble or
concern of mind about any thing spiritual or temporal-had it urged upon
them as if somebody had spoke to them, Cut your throat, now is a good
opportunity. Now! now! So that they were obliged to fight with all their
might to resist it, and yet no reason suggested to them why they should
do it.

About the same time, there were two remarkable instances of persons led
away with strange enthusiastic delusions; one at Suffield, and another
at South Hadley. That which has made the greatest noise in the country
was the conduct of the man at South Hadley, whose delusion was, that he
thought himself divinely instructed to direct a poor man in melancholy
and despairing circumstances, to say certain words in prayer to God, as
recorded in Psalm cxvi. 4, for his own relief. The man is esteemed a
pious man. I have seen this error of his, had a particular acquaintan


shreevatsa

unread,
Feb 1, 2008, 12:28:44 AM2/1/08
to
On Jan 23, 5:37 pm, martin rudalics <rudal...@gmx.at> wrote:
> > Emacs has an auto-save-mode, which comes useful on rare occasions such
> > as crashes. However, what I (and apparently, many others) would like
> > is a feature that automatically saves your files for you -- not to
> > another file but to the one your buffer is visiting, and such that you
> > will not be prompted to save your file on exit.
>
[...]

>
> Setting `auto-save-visited-file-name' can be harmful. See, for example,
>
> http://lists.gnu.org/archive/html/emacs-devel/2003-10/msg00306.html
>
> and
>
> http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-11/msg00077.html
>
> If these threads do not convince you feel free to send a bug report.
>
> Better yet: Help us find out why and how it doesn't work ;-)

Thanks for those. I was planning to post a detailed post summarising
those two threads and the issues that still exist (I'm convinced
setting `auto-save-visited-file-name' is harmful, not that the bugs
have been fixed), but I no longer feel as interested... I think that
feature should be removed if it's buggy; that's all I can say.

Anyway, for completeness, stating that this is the solution I'm using
now, and it seems to do what I want:

(defun save-buffer-if-visiting-file (&optional args)
"Save the current buffer only if it is visiting a file"
(interactive)
(if (buffer-file-name)
(save-buffer args)))

(add-hook 'auto-save-hook 'save-buffer-if-visiting-file)

Thanks for your help,
I'm sorry I'm not using a "standard" Emacs so I can't submit a bug
report,

-S

0 new messages