9

I want Emacs to auto-save a buffer or buffers so that I don't have to press C-x C-s each time.

With auto-save turned on, I see the label "Auto-saving.... Done", which appears once in 30 seconds or so. But why is the document still not saved?

After the label "Auto-saving.... Done" appears, there are still ** which means the buffer I am working on has not been saved. If so, then what is "Auto-saving.... Done" really saving?

enter image description here

4
  • Now that I notice it, how does this question differ from the other one you asked ten days ago?
    – Drew
    Commented May 21, 2016 at 15:31
  • @Drew, now that I notice it, why do you think I have to answer it in the 1st place? I can ask however many question similar questions I wish. Any problems?
    – Oskar K.
    Commented May 21, 2016 at 15:55
  • 1
    @OskarK.: if this question is a duplicate of the other question, then we should close it as per the site's rules. That's why he's asking how this question is different from the other one.
    – Dan
    Commented May 21, 2016 at 16:10
  • 4
    @OskarK.: please stop rolling back the edits to this post. They are intended to make it easier to read, and to remove the "24.4" part. This question has nothing to do with Emacs 24.4 specifically.
    – Dan
    Commented May 21, 2016 at 16:11

2 Answers 2

9

So how to make it save a file?

Put this in your init file

(setq auto-save-visited-file-name t)

so the saved file and the buffer file are the same. But this increases the risk of losing the file due to failures in autosave. You negate the redundancy gained from autosave.

5

From the Emacs manual:

Auto-saving does not normally save in the files that you visited, because it can be very undesirable to save a change that you did not want to make permanent. Instead, auto-saving is done in a different file called the "auto-save file", and the visited file is changed only when you request saving explicitly (such as with ‘C-x C-s’).

In other words, auto-saving saves a copy of your work (your buffer), under a different file name. It does not save the buffer you are editing to the disk file it is visiting.

Read the sections of the manual about this to understand more, starting with node Auto Save.

You can find this information yourself, by asking Emacs:

C-h r opens the Emacs manual. Then i searches the index, using completion, for index entries you type.

In this case, i auto save RET takes you directly to node Auto Save. But i auto TAB shows you all of the index entries that start with auto. Besides the entry Auto Save Mode (and some entries that have nothing to do with auto-saving) you see several entries that start with auto-save:

auto-save for remote files
auto-save-default
auto-save-file-name-transforms 
auto-save-interval
auto-save-list-file-prefix
auto-save-mode
auto-save-timeout 
auto-save-visited-file-name

Choose any of them to visit the relevant manual node.

Experiment a bit to get familiar with using i. You can also search the entire manual using C-s (incremental search).

7
  • so how to make it save a file?
    – Oskar K.
    Commented May 21, 2016 at 6:00
  • 1
    It does save a file - a copy of your work, with a different file name. Read the documentation to understand better. To save your work to the original file you must use C-x C-s to save it manually. This is by design, and is as it should be.
    – Drew
    Commented May 21, 2016 at 6:03
  • 1
    Please read what I wrote. Read the first sentence of the text I quoted. There is a good reason why auto-save does not save the file you are editing. And read the manual about auto-saving, if you want to understand more about Emacs auto-saving.
    – Drew
    Commented May 21, 2016 at 6:13
  • 3
    You are asking the wrong question. But if you really want to do what you are asking, which both Emacs and I advise you against, then you can do that by invoking save-buffer on a timer. You should know what you are doing if you choose to do that, and in that case you already know enough Emacs Lisp to code it.
    – Drew
    Commented May 21, 2016 at 6:16
  • 1
    @OskarK.: this post answers the question you asked in your original post about auto-save. If you want an answer to a different question instead, then please edit your post or make a new post.
    – Dan
    Commented May 21, 2016 at 12:07

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.