How can I get emacs to save the buffer automatically every time I switch to another buffer?

(This is similar to this question, where the buffer is saved automatically when Emacs loses focus.)

  • 2
    The defadvice lines in accepted answer on the thread to which you linked does what you're asking to do. However, I should point out that it's probably a very dangerous thing to have Emacs save your stuff automatically -- that's what auto-save is for, and it doesn't overwrite your files without your explicit permission.
    – Dan
    Commented Mar 3, 2015 at 15:59

1 Answer 1


Here's what I'm using:

(defun ora-save-and-switch-buffer ()
  (when (and (buffer-file-name)
             (not (bound-and-true-p archive-subfile-mode)))

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.