My c-x c-s Muscles Are Getting Tired.

I've used some of the online office apps a bit, such as Google Docs, and I really like that you don't have to continually save your work. They take care of that for you. The blogger web interface that I'm using to type this entry does the same thing. A few people I work with are big Microsoft One Note fans, and it doesn't even have a save button.

I believe it's time for emacs to save my files for me. I have a c-x c-s twitch that I'd like to get rid of. I hunted around a bit, thinking that I couldn't have been the first emacs user to think of this, but I didn't have much luck. It turns out that Emacs does save your work for you automatically, but it's not quite what I'm looking for. It saves to separate back up files that you have to use special commands to recover information from, and it still bugs you about saving whenever you do things like compile or exit. Of course I want to save my work!

Is there really no good auto-save feature for emacs?

Comments

Anonymous said…
Yeah, I have been wanting this for a long time too. I finally decided to do something about it, and found the auto-save-visited-file-name variable which is claimed to work but doesn't in any usable way, and decided to use (add-hook 'auto-save-hook 'save-buffer). It seems to work fine.
Bryan said…
I tried the auto-save-visited-file-name route too, and yes, that just doesn't work. The auto-save-hook does the trick though. Thanks!!
Bryan said…
Hmm, I might have spoken a little too soon. If you are in, say, your *scratch* buffer and you have modified it (just type something there), when auto-save time comes, it asks you what file you want to save in. Is there some way to tell it to only save buffers that are visiting files?
Anonymous said…
Yeah, I think I spoke too soon too :)

This solution is *terrible*, sorry.

I think there might be a way to check buffer-file-name and run the hook only then; I'll have to try. I'll tell you if I find a solution!
Bryan said…
I didn't think your solution was *terrible*. Just needed a little tweaking (unless I'm missing something...am I?).

I'm trying this out for now (also posted on the wiki):

(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)

Seems to do the trick so far.

I haven't tried the run-with-idle-timer suggested on the wiki. Seems like, since auto-save is already running on a timer that piggy-backing off of that is better. I could be wrong.
Anonymous said…
Thanks a lot; I have tried your solution for a while now and it seems to work perfectly.

[It was "terrible" without the (if (buffer-file-name), where it would start prompting on scratch buffers, completion buffers, even the minibuffer. With your modification, it works well.]

Popular posts from this blog

SystemVerilog Fork Disable "Gotchas"

'git revert' Is Not Equivalent To 'svn revert'

Put /etc Under Revision Control (with git)