It only takes one unfortunate program crash where you lose a lot of work to teach you the importance of saving often. I use emacs most of the time, and I had developed a nearly subconscious, paranoid habit of hitting c-x c-s every 5 seconds or so while working. I was starting to catch myself before hitting that save-buffer shortcut even when I was typing in other applications: instant messenging, web page forms, you name it. Meanwhile, I also started noticing applications that didn't require me to tell them to save my precious work. Gmail and blogger come to mind right a way. "Why couldn't emacs do the same?" I wondered. After hashing it out in that blog entry and on the emacs wiki, I added the following to my .emacs file, and I am happy to report that my twitch is gone:
(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))) ;; This causes files that I'm editing to be saved automatically by the ;; emacs auto-save functionality. I'm hoping to break myself of the ;; c-x c-s twitch. (add-hook 'auto-save-hook 'save-buffer-if-visiting-file) ;; save every 20 characters typed (this is the minimum) (setq auto-save-interval 20) ;; save after 1 second of idle time (default is 30) (setq auto-save-timeout 1)
Now emacs automatically saves my work for me, without me having to ask, and I love it. It makes me a little nervous when I'm working on a file that's not under revision control, but with modern revision control being so easy to set up and use1, that is happening less and less.
If you see any way to improve this, or if you just want to tell me why it's dumb, please comment. My emacs lisp skil1z are pretty feeble.
1 Just type
bzr init, or
git init in the directory where the file lives and you are up and running.