Saving files automatically every few seconds

Hi I am new to emacs. I am only using it for org-mode. I use it on multiple computers and I am syncing my .org files with dropbox. I have 26.2

I would like the behavior of emacs to be like workflowy or google drive (everything is saved). So I would like an auto-save with the existing file name at minimum every 5-10 seconds, regardless of keystrokes, large deletes, etc...

I tried real-auto-save and I don't see that it saves files using the same name, it is still using #filename#.

Then I tried auto-save-visited-mode. That seems to work.

Questions:

  1. Do I need both auto-save-visited-mode and real-auto-save? Whats the difference? I read that auto-save-visited-mode is a global save for all buffers.

  2. Can I enable auto-save-visited-mode in the .emacs file? I tried (setq auto-save-visited-mode t) Is that correct?

  3. How can I verify that the mode is enabled? I tried M-x auto-save-visited-mode and it toggles. I just want to check the value.

  4. Can I have a save regardless of idle time?

Posted Aug 21, 2019, 2:44 PM UTC · edited

34
elmonada•

I use (add-hook 'focus-out-hook (lambda () (save-some-buffers t))) which saves the buffers whenever emacs loses the window focus.

4
kcin•

Haven't actually tried it, but this should save everything every 10 seconds:

(run-with-timer 10 10 (lambda () (save-some-buffers t)))
2
[deleted]•

To answer question 3, you want to do `C-h m` to get information on active modes.

​

edit: fixed shortcut

1
github-alphapapa•

I use real-auto-save-mode for just my main Org files, since I want to think of them as a persistent notebook or database that I don't have to remember to save. (I also store them in git and automatically commit changes periodically and when the Emacs window is minimized/restored.)

So I just use this in my org-mode-hook:

(when (s-prefix? (expand-file-name "~/org/")
                 (buffer-file-name (current-buffer)))
  (real-auto-save-mode))
1