mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-28 10:56:36 +00:00
Reimplement auto-saving to visited files
This reacts to confusing behavior of 'auto-save-visited-file-name', cf. Bug#25478. * lisp/files.el (auto-save-visited-interval): New customization option. (auto-save-visited-mode): New global minor mode. (auto-save-visited-file-name): Make obsolete. (auto-save--timer): New internal helper variable. * doc/emacs/files.texi (Auto Save Files): Document 'auto-save-visited-mode' instead of obsolete 'auto-save-visited-file-name'. (Auto Save Control): Document customization option 'auto-save-visited-interval'.
This commit is contained in:
parent
e20ad449de
commit
4db844a453
@ -1040,14 +1040,23 @@ useful if it contains the deleted text. To reenable auto-saving after
|
||||
this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x
|
||||
auto-save-mode}.
|
||||
|
||||
@vindex auto-save-visited-file-name
|
||||
@vindex auto-save-visited-mode
|
||||
If you want auto-saving to be done in the visited file rather than
|
||||
in a separate auto-save file, set the variable
|
||||
@code{auto-save-visited-file-name} to a non-@code{nil} value. In this
|
||||
mode, auto-saving is very similar to explicit saving. However,
|
||||
differences still exist, in particular for modes which modify the
|
||||
buffer-saving process in non-trivial ways via various hooks
|
||||
(@pxref{Saving Buffers,,, elisp, The Emacs Lisp Reference Manual}).
|
||||
in a separate auto-save file, enable the global minor mode
|
||||
@code{auto-save-visited-mode}. In this mode, auto-saving is identical
|
||||
to explicit saving. Note that this mode is orthogonal to the
|
||||
@code{auto-save} mode described above; you can enable both at the same
|
||||
time. However, if @code{auto-save} mode is active in some buffer and
|
||||
the obsolete @code{auto-save-visited-file-name} variable is set to a
|
||||
non-@code{nil} value, that buffer won't be affected by
|
||||
@code{auto-save-visited-mode}.
|
||||
|
||||
You can use the variable @code{auto-save-visited-interval} to
|
||||
customize the interval between auto-save operations in
|
||||
@code{auto-save-visited-mode}; by default it's five seconds.
|
||||
@code{auto-save-interval} and @code{auto-save-timeout} have no effect
|
||||
on @code{auto-save-visited-mode}. @xref{Auto Save Control} for
|
||||
details on these variables.
|
||||
|
||||
@vindex delete-auto-save-files
|
||||
A buffer's auto-save file is deleted when you save the buffer in its
|
||||
@ -1091,6 +1100,12 @@ makes sure all your work is saved if you go away from the terminal for
|
||||
a while; second, it may avoid some auto-saving while you are actually
|
||||
typing.
|
||||
|
||||
@vindex auto-save-visited-interval
|
||||
When @code{auto-save-visited-mode} is enabled, Emacs will auto-save
|
||||
file-visiting buffers after five seconds of idle time. You can
|
||||
customize the variable @code{auto-save-visited-interval} to change the
|
||||
idle time interval.
|
||||
|
||||
Emacs also does auto-saving whenever it gets a fatal error. This
|
||||
includes killing the Emacs job with a shell command such as @samp{kill
|
||||
%emacs}, or disconnecting a phone line or network connection.
|
||||
|
6
etc/NEWS
6
etc/NEWS
@ -383,6 +383,12 @@ Strings such as ΌΣΟΣ are now correctly converted to Όσος when
|
||||
capitalized instead of incorrect Όσοσ (compare lowercase sigma at the
|
||||
end of the word).
|
||||
|
||||
** Emacs can now auto-save buffers to visited files in a more robust
|
||||
manner via the new mode 'auto-save-visited-mode'. Unlike
|
||||
'auto-save-visited-file-name', this mode uses the normal saving
|
||||
procedure and therefore obeys saving hooks.
|
||||
'auto-save-visited-file-name' is now obsolete.
|
||||
|
||||
|
||||
* Changes in Specialized Modes and Packages in Emacs 26.1
|
||||
|
||||
|
@ -393,6 +393,46 @@ ignored."
|
||||
:initialize 'custom-initialize-delay
|
||||
:version "21.1")
|
||||
|
||||
(defvar auto-save--timer nil "Timer for `auto-save-visited-mode'.")
|
||||
|
||||
(defcustom auto-save-visited-interval 5
|
||||
"Interval in seconds for `auto-save-visited-mode'.
|
||||
If `auto-save-visited-mode' is enabled, Emacs will save all
|
||||
buffers visiting a file to the visited file after it has been
|
||||
idle for `auto-save-visited-interval' seconds."
|
||||
:group 'auto-save
|
||||
:type 'number
|
||||
:version "26.1"
|
||||
:set (lambda (symbol value)
|
||||
(set-default symbol value)
|
||||
(when auto-save--timer
|
||||
(timer-set-idle-time auto-save--timer value :repeat))))
|
||||
|
||||
(define-minor-mode auto-save-visited-mode
|
||||
"Toggle automatic saving to file-visiting buffers on or off.
|
||||
With a prefix argument ARG, enable regular saving of all buffers
|
||||
visiting a file if ARG is positive, and disable it otherwise.
|
||||
Unlike `auto-save-mode', this mode will auto-save buffer contents
|
||||
to the visited files directly and will also run all save-related
|
||||
hooks. See Info node `Saving' for details of the save process.
|
||||
|
||||
If called from Lisp, enable the mode if ARG is omitted or nil,
|
||||
and toggle it if ARG is `toggle'."
|
||||
:group 'auto-save
|
||||
:global t
|
||||
(when auto-save--timer (kill-timer auto-save--timer))
|
||||
(setq auto-save--timer
|
||||
(when auto-save-visited-mode
|
||||
(run-with-idle-timer
|
||||
auto-save-visited-interval :repeat
|
||||
#'save-some-buffers :no-prompt
|
||||
(lambda ()
|
||||
(not (and buffer-auto-save-file-name
|
||||
auto-save-visited-file-name)))))))
|
||||
|
||||
(make-obsolete-variable 'auto-save-visited-file-name 'auto-save-visited-mode
|
||||
"Emacs 26.1")
|
||||
|
||||
(defcustom save-abbrevs t
|
||||
"Non-nil means save word abbrevs too when files are saved.
|
||||
If `silently', don't ask the user before saving."
|
||||
|
Loading…
Reference in New Issue
Block a user