Function: auto-save-mode
auto-save-mode is an interactive and byte-compiled function defined in
simple.el.gz.
Signature
(auto-save-mode &optional ARG)
Documentation
Toggle auto-saving in the current buffer (Auto Save mode).
When this mode is enabled, Emacs periodically saves each file-visiting buffer in a separate "auto-save file". This is a safety measure to prevent you from losing more than a limited amount of work if the system crashes.
Auto-saving does not alter the file visited by the buffer: the visited
file is changed only when you request saving it explicitly (such as
with C-x C-s (save-buffer)). If you want to save the buffer into its
visited files automatically, use M-x auto-save-visited-mode (auto-save-visited-mode)).
For more details, see Info node (emacs) Auto Save.
This is a minor mode. If called interactively, toggle the Auto-Save
mode mode. If the prefix argument is positive, enable the mode, and if
it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is toggle. Enable the
mode if ARG is nil, omitted, or is a positive number. Disable the mode
if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate (and buffer-auto-save-file-name (>= buffer-saved-size 0)).
The mode's hook is called both when the mode is enabled and when it is disabled.
Probably introduced at or before Emacs version 1.6.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/simple.el.gz
(define-minor-mode auto-save-mode
"Toggle auto-saving in the current buffer (Auto Save mode).
When this mode is enabled, Emacs periodically saves each file-visiting
buffer in a separate \"auto-save file\". This is a safety measure to
prevent you from losing more than a limited amount of work if the
system crashes.
Auto-saving does not alter the file visited by the buffer: the visited
file is changed only when you request saving it explicitly (such as
with \\[save-buffer]). If you want to save the buffer into its
visited files automatically, use \\[auto-save-visited-mode]).
For more details, see Info node `(emacs) Auto Save'."
:variable ((and buffer-auto-save-file-name
;; If auto-save is off because buffer has shrunk,
;; then toggling should turn it on.
(>= buffer-saved-size 0))
. (lambda (val)
(setq buffer-auto-save-file-name
(cond
((null val) nil)
((and buffer-file-name remote-file-name-inhibit-auto-save
(file-remote-p buffer-file-name))
nil)
((and buffer-file-name auto-save-visited-file-name
(not buffer-read-only))
buffer-file-name)
(t (make-auto-save-file-name))))))
;; If -1 was stored here, to temporarily turn off saving,
;; turn it back on.
(and (< buffer-saved-size 0)
(setq buffer-saved-size 0)))