annotate lispref/backups.texi @ 6581:3a0db3b2366c

(vc-checkin): Undo previous change.
author Richard M. Stallman <rms@gnu.org>
date Wed, 30 Mar 1994 02:14:11 +0000
parents d9652e184eec
children cf60a8adeadd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6564
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 @c -*-texinfo-*-
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 @c This is part of the GNU Emacs Lisp Reference Manual.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 @c See the file elisp.texi for copying conditions.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 @setfilename ../info/backups
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 @node Backups and Auto-Saving, Buffers, Files, Top
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 @chapter Backups and Auto-Saving
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 Backup files and auto-save files are two methods by which Emacs tries
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 to protect the user from the consequences of crashes or of the user's
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 own errors. Auto-saving preserves the text from earlier in the current
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 editing session; backup files preserve file contents prior to the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 current session.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 @menu
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 * Backup Files:: How backup files are made; how their names are chosen.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 * Auto-Saving:: How auto-save files are made; how their names are chosen.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 * Reverting:: @code{revert-buffer}, and how to customize what it does.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 @end menu
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 @node Backup Files, Auto-Saving, Backups and Auto-Saving, Backups and Auto-Saving
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 @section Backup Files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 @cindex backup file
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 A @dfn{backup file} is a copy of the old contents of a file you are
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 editing. Emacs makes a backup file the first time you save a buffer
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 into its visited file. Normally, this means that the backup file
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 contains the contents of the file as it was before the current editing
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 session. The contents of the backup file normally remain unchanged once
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 it exists.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 Backups are usually made by renaming the visited file to a new name.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 Optionally, you can specify that backup files should be made by copying
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 the visited file. This choice makes a difference for files with
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 multiple names; it also can affect whether the edited file remains owned
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 by the original owner or becomes owned by the user editing it.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 By default, Emacs makes a single backup file for each file edited.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 You can alternatively request numbered backups; then each new backup
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 file gets a new name. You can delete old numbered backups when you
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 don't want them any more, or Emacs can delete them automatically.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 @menu
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 * Making Backups:: How Emacs makes backup files, and when.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 * Rename or Copy:: Two alternatives: renaming the old file or copying it.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 * Numbered Backups:: Keeping multiple backups for each source file.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 * Backup Names:: How backup file names are computed; customization.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 @end menu
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 @node Making Backups, Rename or Copy, Backup Files, Backup Files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 @subsection Making Backup Files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 @defun backup-buffer
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 This function makes a backup of the file visited by the current
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 buffer, if appropriate. It is called by @code{save-buffer} before
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 saving the buffer the first time.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 @defvar buffer-backed-up
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 This buffer-local variable indicates whether this buffer's file has
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 been backed up on account of this buffer. If it is non-@code{nil}, then
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 the backup file has been written. Otherwise, the file should be backed
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 up when it is next saved (if backup files are enabled). This is a
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 permanent local; @code{kill-local-variables} does not alter it.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 @defopt make-backup-files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 This variable determines whether or not to make backup files. If it
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 is non-@code{nil}, then Emacs creates a backup of each file when it is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 saved for the first time.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 The following example shows how to change the @code{make-backup-files}
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 variable only in the @file{RMAIL} buffer and not elsewhere. Setting it
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 @code{nil} stops Emacs from making backups of the @file{RMAIL} file,
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 which may save disk space. (You would put this code in your
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 @file{.emacs} file.)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 @smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (add-hook 'rmail-mode-hook
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (function (lambda ()
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (make-local-variable
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 'make-backup-files)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (setq make-backup-files nil))))
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 @end smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 @end defopt
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 @defvar backup-enable-predicate filename
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 This variable's value is a function to be called on certain occasions to
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 decide whether a there should be backup files for file name
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 @var{filename}. If it returns @code{nil}, backups are disabled.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 Otherwise, the other variables in this section say whether and how to
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 make backups.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 The default value is this:
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 @example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (lambda (name)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (or (< (length name) 5)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (not (string-equal "/tmp/"
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (substring name 0 5)))))
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 @end example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 @defvar backup-inhibited
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 If this variable is non-@code{nil}, backups are inhibited. It records
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 the result of testing @code{backup-enable-predicate} on the visited file
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 name. It can also coherently be used by other mechanisms that inhibit
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 backups based on which file is visited. Major modes should not set this
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 variable.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 @node Rename or Copy, Numbered Backups, Making Backups, Backup Files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 @subsection Backup by Renaming or by Copying?
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 @cindex backup files, how to make them
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 There are two ways that Emacs can make a backup file:
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 @itemize @bullet
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 @item
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 Emacs can rename the original file so that it becomes a backup file, and
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 then write the buffer being saved into a new file. After this
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 procedure, any other names (i.e., hard links) of the original file now
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 refer to the backup file. The new file is owned by the user doing the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 editing, and its group is the default for new files written by the user
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 in that directory.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 @item
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 Emacs can copy the original file into a backup file, and then overwrite
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 the original file with new contents. After this procedure, any other
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 names (i.e., hard links) of the original file still refer to the current
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 version of the file. The file's owner and group will be unchanged.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 @end itemize
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 The first method, renaming, is the default.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 The variable @code{backup-by-copying}, if non-@code{nil}, says to use
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 the second method, which is to copy the original file and overwrite it
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 with the new buffer contents. The variable @code{file-precious-flag},
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 if non-@code{nil}, also has this effect (as a sideline of its main
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 significance). @xref{Saving Buffers}.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 @defvar backup-by-copying
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 If this variable is non-@code{nil}, Emacs always makes backup files by
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 copying.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 The following two variables, when non-@code{nil}, cause the second
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 method to be used in certain special cases. They have no effect on the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 treatment of files that don't fall into the special cases.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 @defvar backup-by-copying-when-linked
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 If this variable is non-@code{nil}, Emacs makes backups by copying for
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 files with multiple names (hard links).
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 This variable is significant only if @code{backup-by-copying} is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 @code{nil}, since copying is always used when that variable is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 non-@code{nil}.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 @defvar backup-by-copying-when-mismatch
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 If this variable is non-@code{nil}, Emacs makes backups by copying in cases
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 where renaming would change either the owner or the group of the file.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 The value has no effect when renaming would not alter the owner or
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 group of the file; that is, for files which are owned by the user and
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 whose group matches the default for a new file created there by the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 user.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 This variable is significant only if @code{backup-by-copying} is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 @code{nil}, since copying is always used when that variable is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 non-@code{nil}.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 @node Numbered Backups, Backup Names, Rename or Copy, Backup Files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 @subsection Making and Deleting Numbered Backup Files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 If a file's name is @file{foo}, the names of its numbered backup
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 versions are @file{foo.~@var{v}~}, for various integers @var{v}, like
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 this: @file{foo.~1~}, @file{foo.~2~}, @file{foo.~3~}, @dots{},
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 @file{foo.~259~}, and so on.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 @defopt version-control
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 This variable controls whether to make a single non-numbered backup
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 file or multiple numbered backups.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 @table @asis
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 @item @code{nil}
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 Make numbered backups if the visited file already has numbered backups;
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 otherwise, do not.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 @item @code{never}
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 Do not make numbered backups.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 @item @var{anything else}
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 Do make numbered backups.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 @end table
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 @end defopt
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 The use of numbered backups ultimately leads to a large number of
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 backup versions, which must then be deleted. Emacs can do this
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 automatically.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 @defopt kept-new-versions
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 The value of this variable is the number of oldest versions to keep
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 when a new numbered backup is made. The newly made backup is included
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 in the count. The default value is 2.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 @end defopt
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 @defopt kept-old-versions
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 The value of this variable is the number of oldest versions to keep
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 when a new numbered backup is made. The default value is 2.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 @end defopt
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 If there are backups numbered 1, 2, 3, 5, and 7, and both of these
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 variables have the value 2, then the backups numbered 1 and 2 are kept
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 as old versions and those numbered 5 and 7 are kept as new versions;
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 backup version 3 is deleted. The function @code{find-backup-file-name}
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (@pxref{Backup Names}) is responsible for determining which backup
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 versions to delete, but does not delete them itself.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 @defopt trim-versions-without-asking
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 If this variable is non-@code{nil}, then saving a file deletes excess
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 backup versions silently. Otherwise, it asks the user whether to delete
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 them.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 @end defopt
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 @defopt dired-kept-versions
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 This variable specifies how many of the newest backup versions to keep
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 in the Dired command @kbd{.} (@code{dired-clean-directory}). That's the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 same thing @code{kept-new-versions} does when you make a new backup
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 file. The default value is 2.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 @end defopt
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 @node Backup Names, , Numbered Backups, Backup Files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 @subsection Naming Backup Files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 The functions in this section are documented mainly because you can
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 customize the naming conventions for backup files by redefining them.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 If you change one, you probably need to change the rest.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 @defun backup-file-name-p filename
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 This function returns a non-@code{nil} value if @var{filename} is a
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 possible name for a backup file. A file with the name @var{filename}
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 need not exist; the function just checks the name.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 @smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (backup-file-name-p "foo")
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 @result{} nil
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (backup-file-name-p "foo~")
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 @result{} 3
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 @end smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 The standard definition of this function is as follows:
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 @smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (defun backup-file-name-p (file)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 "Return non-nil if FILE is a backup file \
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 name (numeric or not)..."
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (string-match "~$" file))
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 @end smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 @noindent
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 Thus, the function returns a non-@code{nil} value if the file name ends
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 with a @samp{~}. (We use a backslash to split the documentation
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 string's first line into two lines in the text, but produce just one
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 line in the string itself.)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 This simple expression is placed in a separate function to make it easy
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 to redefine for customization.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 @defun make-backup-file-name filename
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 This function returns a string which is the name to use for a
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 non-numbered backup file for file @var{filename}. On Unix, this is just
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 @var{filename} with a tilde appended.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 The standard definition of this function is as follows:
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 @smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (defun make-backup-file-name (file)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 "Create the non-numeric backup file name for FILE.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 @dots{}"
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (concat file "~"))
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 @end smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 You can change the backup file naming convention by redefining this
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 function. The following example redefines @code{make-backup-file-name}
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 to prepend a @samp{.} as well as appending a tilde:
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 @smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (defun make-backup-file-name (filename)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (concat "." filename "~"))
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (make-backup-file-name "backups.texi")
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 @result{} ".backups.texi~"
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 @end smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 @defun find-backup-file-name filename
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 This function computes the file name for a new backup file for
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 @var{filename}. It may also propose certain existing backup files for
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 deletion. @code{find-backup-file-name} returns a list whose @sc{car} is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 the name for the new backup file and whose @sc{cdr} is a list of backup
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 files whose deletion is proposed.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 Two variables, @code{kept-old-versions} and @code{kept-new-versions},
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 determine which backup versions should be kept. This function keeps
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 those versions by excluding them from the @sc{cdr} of the value.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 @xref{Numbered Backups}.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 In this example, the value says that @file{~rms/foo.~5~} is the name
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 to use for the new backup file, and @file{~rms/foo.~3~} is an ``excess''
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 version that the caller should consider deleting now.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 @smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (find-backup-file-name "~rms/foo")
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 @result{} ("~rms/foo.~5~" "~rms/foo.~3~")
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 @end smallexample
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 @c Emacs 19 feature
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 @defun file-newest-backup filename
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 This function returns the name of the most recent backup file for
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 @var{filename}, or @code{nil} that file has no backup files.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 Some file comparison commands use this function in order to compare
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 a file by default with its most recent backup.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 @node Auto-Saving, Reverting, Backup Files, Backups and Auto-Saving
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 @section Auto-Saving
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 @cindex auto-saving
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 Emacs periodically saves all files that you are visiting; this is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 called @dfn{auto-saving}. Auto-saving prevents you from losing more
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 than a limited amount of work if the system crashes. By default,
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 auto-saves happen every 300 keystrokes, or after around 30 seconds of
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 idle time. @xref{Auto-Save, Auto-Save, Auto-Saving: Protection Against
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 Disasters, emacs, The GNU Emacs Manual}, for information on auto-save
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 for users. Here we describe the functions used to implement auto-saving
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 and the variables that control them.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 @defvar buffer-auto-save-file-name
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 This buffer-local variable is the name of the file used for
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 auto-saving the current buffer. It is @code{nil} if the buffer
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 should not be auto-saved.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 @example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 buffer-auto-save-file-name
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 => "/xcssun/users/rms/lewis/#files.texi#"
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 @end example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 @deffn Command auto-save-mode arg
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 When used interactively without an argument, this command is a toggle
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 switch: it turns on auto-saving of the current buffer if it is off, and
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 vice-versa. With an argument @var{arg}, the command turns auto-saving
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 on if the value of @var{arg} is @code{t}, a nonempty list, or a positive
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 integer. Otherwise, it turns auto-saving off.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 @end deffn
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 @defun auto-save-file-name-p filename
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 This function returns a non-@code{nil} value if @var{filename} is a
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 string that could be the name of an auto-save file. It works based on
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 knowledge of the naming convention for auto-save files: a name that
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 begins and ends with hash marks (@samp{#}) is a possible auto-save file
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 name. The argument @var{filename} should not contain a directory part.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 @example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (make-auto-save-file-name)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 @result{} "/xcssun/users/rms/lewis/#files.texi#"
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (auto-save-file-name-p "#files.texi#")
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 @result{} 0
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (auto-save-file-name-p "files.texi")
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 @result{} nil
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 @end example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 The standard definition of this function is as follows:
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 @example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (defun auto-save-file-name-p (filename)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 "Return non-nil if FILENAME can be yielded by..."
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (string-match "^#.*#$" filename))
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 @end example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 This function exists so that you can customize it if you wish to
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 change the naming convention for auto-save files. If you redefine it,
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 be sure to redefine the function @code{make-auto-save-file-name}
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 correspondingly.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 @defun make-auto-save-file-name
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 This function returns the file name to use for auto-saving the current
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 buffer. This is just the file name with hash marks (@samp{#}) appended
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 and prepended to it. This function does not look at the variable
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 @code{auto-save-visited-file-name}; you should check that before calling
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 this function.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 @example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (make-auto-save-file-name)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 @result{} "/xcssun/users/rms/lewis/#backup.texi#"
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 @end example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 The standard definition of this function is as follows:
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 @example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (defun make-auto-save-file-name ()
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 "Return file name to use for auto-saves \
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 of current buffer.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 @dots{}"
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (if buffer-file-name
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 @group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (concat
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (file-name-directory buffer-file-name)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 "#"
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (file-name-nondirectory buffer-file-name)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 "#")
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (expand-file-name
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (concat "#%" (buffer-name) "#"))))
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 @end group
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 @end example
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 This exists as a separate function so that you can redefine it to
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 customize the naming convention for auto-save files. Be sure to
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 change @code{auto-save-file-name-p} in a corresponding way.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 @defvar auto-save-visited-file-name
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 If this variable is non-@code{nil}, Emacs auto-saves buffers in
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 the files they are visiting. That is, the auto-save is done in the same
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 file which you are editing. Normally, this variable is @code{nil}, so
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 auto-save files have distinct names that are created by
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 @code{make-auto-save-file-name}.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 When you change the value of this variable, the value does not take
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 effect until the next time auto-save mode is reenabled in any given
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 buffer. If auto-save mode is already enabled, auto-saves continue to go
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 in the same file name until @code{auto-save-mode} is called again.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 @defun recent-auto-save-p
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 This function returns @code{t} if the current buffer has been
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 auto-saved since the last time it was read in or saved.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 @defun set-buffer-auto-saved
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 This function marks the current buffer as auto-saved. The buffer will
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 not be auto-saved again until the buffer text is changed again. The
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 function returns @code{nil}.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 @defopt auto-save-interval
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 The value of this variable is the number of characters that Emacs
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 reads from the keyboard between auto-saves. Each time this many more
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 characters are read, auto-saving is done for all buffers in which it is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 enabled.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 @end defopt
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 @defopt auto-save-timeout
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 The value of this variable is the number of seconds of idle time that
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 should cause auto-saving. Each time the user pauses for this long,
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 Emacs auto-saves any buffers that need it. (Actually, the specified
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 timeout is multiplied by a factor depending on the size of the current
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 buffer.)
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 @end defopt
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 @defvar auto-save-hook
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 This normal hook is run whenever an auto-save is about to happen.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 @defopt auto-save-default
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 If this variable is non-@code{nil}, buffers that are visiting files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 have auto-saving enabled by default. Otherwise, they do not.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 @end defopt
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 @deffn Command do-auto-save &optional no-message
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 This function auto-saves all buffers that need to be auto-saved. It
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 saves all buffers for which auto-saving is enabled and that have been
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 changed since the previous auto-save.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 Normally, if any buffers are auto-saved, a message that says
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 @samp{Auto-saving...} is displayed in the echo area while auto-saving is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 going on. However, if @var{no-message} is non-@code{nil}, the message
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 is inhibited.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 @end deffn
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 @defun delete-auto-save-file-if-necessary
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 This function deletes the current buffer's auto-save file if
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 @code{delete-auto-save-files} is non-@code{nil}. It is called every
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 time a buffer is saved.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 @defvar delete-auto-save-files
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 This variable is used by the function
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 @code{delete-auto-save-file-if-necessary}. If it is non-@code{nil},
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 Emacs deletes auto-save files when a true save is done (in the visited
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 file). This saves disk space and unclutters your directory.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 @defun rename-auto-save-file
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 This function adjusts the current buffer's auto-save file name if the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 visited file name has changed. It also renames an existing auto-save
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 file. If the visited file name has not changed, this function does
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 nothing.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 @end defun
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 @node Reverting, , Auto-Saving, Backups and Auto-Saving
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 @section Reverting
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 If you have made extensive changes to a file and then change your mind
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 about them, you can get rid of them by reading in the previous version
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 of the file with the @code{revert-buffer} command. @xref{Reverting, ,
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 Reverting a Buffer, emacs, The GNU Emacs Manual}.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 @deffn Command revert-buffer &optional check-auto-save noconfirm
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 This command replaces the buffer text with the text of the visited
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 file on disk. This action undoes all changes since the file was visited
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 or saved.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 If the argument @var{check-auto-save} is non-@code{nil}, and the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 latest auto-save file is more recent than the visited file,
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 @code{revert-buffer} asks the user whether to use that instead.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 Otherwise, it always uses the text of the visited file itself.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 Interactively, @var{check-auto-save} is set if there is a numeric prefix
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 argument.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 Normally, @code{revert-buffer} asks for confirmation before it changes
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 the buffer; but if the argument @var{noconfirm} is non-@code{nil},
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 @code{revert-buffer} does not ask for confirmation.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 Reverting tries to preserve marker positions in the buffer by using the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 replacement feature of @code{insert-file-contents}. If there is no
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 actual difference between the buffer and the file, before reversion,
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 this preserves all the markers. If reversion does change the buffer,
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 this preserves the markers in the unchanged text (if any) at the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 beginning and end of the buffer. Preserving any additional markers
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 would be problematical.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 If the value of the @code{revert-buffer-function} variable is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 non-@code{nil}, it is called as a function with no arguments to do the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 work.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 @end deffn
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 @defvar revert-buffer-function
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 The value of this variable is the function to use to revert this
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 buffer; but if the value of this variable is @code{nil}, then the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 @code{revert-buffer} function carries out its default action. Modes
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 such as Dired mode, in which the text being edited does not consist of a
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 file's contents but can be regenerated in some other fashion, give this
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 variable a buffer-local value that is a function to regenerate the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 contents.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 @defvar revert-buffer-insert-file-contents-function
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 The value of this variable, if non-@code{nil}, is the function to use
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 to insert contents when reverting this buffer. The function receives
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 two arguments, first the file name to use, and second, @code{t} if the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 user has asked to read the auto-save file.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 @defvar before-revert-hook
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 This normal hook is run by @code{revert-buffer} before actually
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 inserting the modified contents---but only if
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 @code{revert-buffer-function} is @code{nil}.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 Font Lock mode uses this hook to record that the buffer contents are no
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 longer fontified.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 @defvar after-revert-hook
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 This normal hook is run by @code{revert-buffer} after actually inserting
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 the modified contents---but only if @code{revert-buffer-function} is
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 @code{nil}.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 Font Lock mode uses this hook to recompute the fonts for the updated
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 buffer contents.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 @end defvar
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 @deffn Command recover-file filename
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 This function visits @var{filename}, but gets the contents from its
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 last auto-save file. This is useful after the system has crashed, to
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 resume editing the same file without losing all the work done in the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 previous session.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 An error is signaled if there is no auto-save file for @var{filename},
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 or if @var{filename} is newer than its auto-save file. If
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 @var{filename} does not exist, but its auto-save file does, then the
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 auto-save file is read as usual. This last situation may occur if you
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 visited a nonexistent file and never actually saved it.
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 @end deffn
d9652e184eec Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621