aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2008-10-12 00:40:49 +0000
committerChong Yidong2008-10-12 00:40:49 +0000
commit02223edd5e2dc2db3caaaef7d00a6ef6784da43e (patch)
treedd3213f7e70c36da1806ec1723ecc1b7c572dacb
parentab58114f8a8c974cb7530fb05326ee7d7b915d83 (diff)
downloademacs-02223edd5e2dc2db3caaaef7d00a6ef6784da43e.tar.gz
emacs-02223edd5e2dc2db3caaaef7d00a6ef6784da43e.zip
(File Names): Reorganize description.
(Visiting): Add xref to Mode Line. Copyedits. (Save Commands): Mention prefix behavior of C-x C-s. (Numbered Backups): Node deleted. (Backup Names): Contents of Numbered Backups moved here. State default of version-control variable. (Reverting): Copyedits. (Version Control): Add additional version control systems.
-rw-r--r--doc/emacs/files.texi600
1 files changed, 277 insertions, 323 deletions
diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index 3227a71386c..b21947619cf 100644
--- a/doc/emacs/files.texi
+++ b/doc/emacs/files.texi
@@ -48,106 +48,82 @@ on file directories.
48@section File Names 48@section File Names
49@cindex file names 49@cindex file names
50 50
51 Most Emacs commands that operate on a file require you to specify the 51 Many Emacs commands that operate on a file require you to specify
52file name. (Saving and reverting are exceptions; the buffer knows which 52the file name, using the minibuffer (@pxref{Minibuffer}). You can use
53file name to use for them.) You enter the file name using the 53@dfn{completion} to specify long file names (@pxref{Completion}).
54minibuffer (@pxref{Minibuffer}). @dfn{Completion} is available 54Note that file name completion ignores file names whose extensions
55(@pxref{Completion}) to make it easier to specify long file names. When 55appear in the variable @code{completion-ignored-extensions}
56completing file names, Emacs ignores those whose file-name extensions 56(@pxref{Completion Options}).
57appear in the variable @code{completion-ignored-extensions}; see 57
58@ref{Completion Options}. 58 For most operations, there is a @dfn{default file name} which is
59 59used if you type just @key{RET} to enter an empty argument. Normally,
60 For most operations, there is a @dfn{default file name} which is used 60the default file name is the name of the file visited in the current
61if you type just @key{RET} to enter an empty argument. Normally the 61buffer.
62default file name is the name of the file visited in the current buffer;
63this makes it easy to operate on that file with any of the Emacs file
64commands.
65 62
66@vindex default-directory 63@vindex default-directory
67 Each buffer has a default directory which is normally the same as the 64@vindex insert-default-directory
68directory of the file visited in that buffer. When you enter a file 65 Each buffer has a @dfn{default directory} which is normally the same
69name without a directory, the default directory is used. If you specify 66as the directory of the file visited in that buffer. For example, if
70a directory in a relative fashion, with a name that does not start with 67the default file name is @file{/u/rms/gnu/gnu.tasks}, the default
71a slash, it is interpreted with respect to the default directory. The 68directory is normally @file{/u/rms/gnu/}. The default directory is
72default directory is kept in the variable @code{default-directory}, 69kept in the variable @code{default-directory}, which has a separate
73which has a separate value in every buffer. 70value in every buffer. When a command reads a file name using the
71minibuffer, the default directory usually serves as the initial
72contents of the minibuffer. To inhibit the insertion of the default
73directory, set the variable @code{insert-default-directory} to
74@code{nil}.
74 75
75@findex cd 76 If you enter a file name without a directory, that specifies a file
76@findex pwd 77in the default directory. If you specify a directory in a relative
77 The command @kbd{M-x pwd} displays the current buffer's default 78fashion, with a name that does not start with a slash, it is
78directory, and the command @kbd{M-x cd} sets it (to a value read using 79interpreted with respect to the default directory. For example,
79the minibuffer). A buffer's default directory changes only when the 80suppose the default directory is @file{/u/rms/gnu/}. Entering just
80@code{cd} command is used. A file-visiting buffer's default directory 81@samp{foo} in the minibuffer, with a directory omitted, specifies the
81is initialized to the directory of the file it visits. If you create 82file @file{/u/rms/gnu/foo}; entering @samp{../.login} specifies
82a buffer with @kbd{C-x b}, its default directory is copied from that 83@file{/u/rms/.login}; and entering @samp{new/foo} specifies
83of the buffer that was current at the time.
84
85 For example, if the default file name is @file{/u/rms/gnu/gnu.tasks}
86then the default directory is normally @file{/u/rms/gnu/}. If you
87type just @samp{foo}, which does not specify a directory, it is short
88for @file{/u/rms/gnu/foo}. @samp{../.login} would stand for
89@file{/u/rms/.login}. @samp{new/foo} would stand for the file name
90@file{/u/rms/gnu/new/foo}. 84@file{/u/rms/gnu/new/foo}.
91 85
92@vindex insert-default-directory 86 When typing a file name into the minibuffer, you can make use of a
93 The default directory actually appears in the minibuffer when the 87couple of shortcuts: a double slash is interpreted as ``ignore
94minibuffer becomes active to read a file name. This serves two 88everything before the second slash in the pair,'' and @samp{~/} is
95purposes: it @emph{shows} you what the default is, so that you can type 89interpreted as your home directory. @xref{Minibuffer File}, for more
96a relative file name and know with certainty what it will mean, and it 90information about these shortcuts.
97allows you to @emph{edit} the default to specify a different directory. 91
98This insertion of the default directory is inhibited if the variable 92@findex cd
99@code{insert-default-directory} is set to @code{nil}. 93@findex pwd
100 94 The command @kbd{M-x pwd} displays the default directory, and the
101 Note that it is legitimate to type an absolute file name after you 95command @kbd{M-x cd} sets it to a value read using the minibuffer. A
102enter the minibuffer, ignoring the presence of the default directory 96buffer's default directory changes only when the @code{cd} command is
103name as part of the text. The final minibuffer contents may look 97used. A file-visiting buffer's default directory is initialized to
104invalid, but that is not so. For example, if the minibuffer starts out 98the directory of the file it visits. If you create a buffer with
105with @samp{/usr/tmp/} and you add @samp{/x1/rms/foo}, you get 99@kbd{C-x b}, its default directory is copied from that of the buffer
106@samp{/usr/tmp//x1/rms/foo}; but Emacs ignores everything through the 100that was current at the time (@pxref{Select Buffer}).
107first slash in the double slash; the result is @samp{/x1/rms/foo}.
108@xref{Minibuffer File}.
109
110@cindex home directory shorthand
111 You can use @file{~/} in a file name to mean your home directory,
112or @file{~@var{user-id}/} to mean the home directory of a user whose
113login name is @code{user-id}@footnote{
114On MS-Windows and MS-DOS systems, where a user doesn't have a home
115directory, Emacs replaces @file{~/} with the value of the
116environment variable @code{HOME}; see @ref{General Variables}. On
117these systems, the @file{~@var{user-id}/} construct is supported only
118for the current user, i.e., only if @var{user-id} is the current
119user's login name.}.
120 101
121@cindex environment variables in file names 102@cindex environment variables in file names
122@cindex expansion of environment variables 103@cindex expansion of environment variables
123@cindex @code{$} in file names 104@cindex @code{$} in file names
124 @anchor{File Names with $}@samp{$} in a file name is used to 105 @anchor{File Names with $}The character @samp{$} is used to
125substitute an environment variable. The environment variable name 106substitute an environment variable into a file name. The name of the
126consists of all the alphanumeric characters after the @samp{$}; 107environment variable consists of all the alphanumeric characters after
127alternatively, it can be enclosed in braces after the @samp{$}. For 108the @samp{$}; alternatively, it can be enclosed in braces after the
128example, if you have used the shell command @command{export 109@samp{$}. For example, if you have used the shell command
129FOO=rms/hacks} to set up an environment variable named @env{FOO}, then 110@command{export FOO=rms/hacks} to set up an environment variable named
130you can use @file{/u/$FOO/test.c} or @file{/u/$@{FOO@}/test.c} as an 111@env{FOO}, then both @file{/u/$FOO/test.c} and
131abbreviation for @file{/u/rms/hacks/test.c}. If the environment 112@file{/u/$@{FOO@}/test.c} are abbreviations for
132variable is not defined, no substitution occurs: @file{/u/$notdefined} 113@file{/u/rms/hacks/test.c}. If the environment variable is not
133stands for itself (assuming the environment variable @env{notdefined} 114defined, no substitution occurs, so that the character @samp{$} stands
134is not defined). 115for itself.
135 116
136 Note that shell commands to set environment variables affect Emacs 117 Note that environment variables affect Emacs only if they are
137only when done before Emacs is started. 118applied before Emacs is started.
138 119
139 To access a file with @samp{$} in its name, if the @samp{$} causes 120 To access a file with @samp{$} in its name, if the @samp{$} causes
140expansion, type @samp{$$}. This pair is converted to a single 121expansion, type @samp{$$}. This pair is converted to a single
141@samp{$} at the same time as variable substitution is performed for a 122@samp{$} at the same time that variable substitution is performed for
142single @samp{$}. Alternatively, quote the whole file name with 123a single @samp{$}. Alternatively, quote the whole file name with
143@samp{/:} (@pxref{Quoted File Names}). File names which begin with a 124@samp{/:} (@pxref{Quoted File Names}). File names which begin with a
144literal @samp{~} should also be quoted with @samp{/:}. 125literal @samp{~} should also be quoted with @samp{/:}.
145 126
146@findex substitute-in-file-name
147 The Lisp function that performs the @samp{$}-substitution is called
148@code{substitute-in-file-name}. The substitution is performed only on
149file names read as such using the minibuffer.
150
151 You can include non-@acronym{ASCII} characters in file names if you set the 127 You can include non-@acronym{ASCII} characters in file names if you set the
152variable @code{file-name-coding-system} to a non-@code{nil} value. 128variable @code{file-name-coding-system} to a non-@code{nil} value.
153@xref{File Name Coding}. 129@xref{File Name Coding}.
@@ -180,48 +156,44 @@ Visit a file with no conversion of the contents.
180@cindex saving files 156@cindex saving files
181 @dfn{Visiting} a file means reading its contents into an Emacs 157 @dfn{Visiting} a file means reading its contents into an Emacs
182buffer so you can edit them. Emacs makes a new buffer for each file 158buffer so you can edit them. Emacs makes a new buffer for each file
183that you visit. We often say that this buffer ``is visiting'' that 159that you visit.
184file, or that the buffer's ``visited file'' is that file. Emacs 160
185constructs the buffer name from the file name by throwing away the 161 Emacs normally constructs the buffer name from the file name,
186directory, keeping just the name proper. For example, a file named 162omitting the directory name. For example, a file named
187@file{/usr/rms/emacs.tex} would get a buffer named @samp{emacs.tex}. 163@file{/usr/rms/emacs.tex} is visited in a buffer named
188If there is already a buffer with that name, Emacs constructs a unique 164@samp{emacs.tex}. If there is already a buffer with that name, Emacs
189name---the normal method is to append @samp{<2>}, @samp{<3>}, and so 165constructs a unique name; the normal method is to append @samp{<2>},
190on, but you can select other methods (@pxref{Uniquify}). 166@samp{<3>}, and so on, but you can select other methods.
191 167@xref{Uniquify}.
192 Each window's mode line shows the name of the buffer that is being displayed 168
193in that window, so you can always tell what buffer you are editing. 169 Each window's mode line shows the name of the buffer that is being
170displayed in that window, so you can always tell what buffer you are
171editing. @pxref{Mode Line}.
194 172
195 The changes you make with editing commands are made in the Emacs 173 The changes you make with editing commands are made in the Emacs
196buffer. They do not take effect in the file that you visited, or any 174buffer. They do not take effect in the file that you visited, or any
197permanent place, until you @dfn{save} the buffer. Saving the buffer 175permanent place, until you @dfn{save} the buffer (@pxref{Saving}).
198means that Emacs writes the current contents of the buffer into its
199visited file. @xref{Saving}.
200 176
201@cindex modified (buffer) 177@cindex modified (buffer)
202 If a buffer contains changes that have not been saved, we say the 178 If a buffer contains changes that have not been saved, we say the
203buffer is @dfn{modified}. This is important because it implies that 179buffer is @dfn{modified}. This implies that some changes will be lost
204some changes will be lost if the buffer is not saved. The mode line 180if the buffer is not saved. The mode line displays two stars near the
205displays two stars near the left margin to indicate that the buffer is 181left margin to indicate that the buffer is modified.
206modified.
207 182
208@kindex C-x C-f 183@kindex C-x C-f
209@findex find-file 184@findex find-file
210 To visit a file, use the command @kbd{C-x C-f} (@code{find-file}). Follow 185 To visit a file, type @kbd{C-x C-f} (@code{find-file}) and use the
211the command with the name of the file you wish to visit, terminated by a 186minibuffer to enter the name of the desired file. The usual
212@key{RET}. 187defaulting and completion behavior is available in this minibuffer
213 188(@pxref{Minibuffer File}). Note, also, that completion ignores
214 The file name is read using the minibuffer (@pxref{Minibuffer}), with 189certain file names (@pxref{Completion Options}). While in the
215defaulting and completion in the standard manner (@pxref{File Names}). 190minibuffer, you can abort @kbd{C-x C-f} by typing @kbd{C-g}.
216While in the minibuffer, you can abort @kbd{C-x C-f} by typing 191
217@kbd{C-g}. File-name completion ignores certain file names; for more 192 Your can tell that @kbd{C-x C-f} has completed successfully by the
218about this, see @ref{Completion Options}. 193appearance of new text on the screen and a new buffer name in the mode
219 194line. If the specified file does not exist and you could not create
220 Your confirmation that @kbd{C-x C-f} has completed successfully is 195it, or exists but you can't read it, an error message is displayed in
221the appearance of new text on the screen and a new buffer name in the 196the echo area.
222mode line. If the specified file does not exist and you could not
223create it, or exists but you can't read it, then you get an error,
224with an error message displayed in the echo area.
225 197
226 If you visit a file that is already in Emacs, @kbd{C-x C-f} does not make 198 If you visit a file that is already in Emacs, @kbd{C-x C-f} does not make
227another copy. It selects the existing buffer containing that file. 199another copy. It selects the existing buffer containing that file.
@@ -233,72 +205,70 @@ to reread it.
233@cindex maximum buffer size exceeded, error message 205@cindex maximum buffer size exceeded, error message
234 If you try to visit a file larger than 206 If you try to visit a file larger than
235@code{large-file-warning-threshold} (the default is 10000000, which is 207@code{large-file-warning-threshold} (the default is 10000000, which is
236about 10 megabytes), Emacs will ask you for confirmation first. You 208about 10 megabytes), Emacs asks you for confirmation first. You can
237can answer @kbd{y} to proceed with visiting the file. Note, however, 209answer @kbd{y} to proceed with visiting the file. Note, however, that
238that Emacs cannot visit files that are larger than the maximum Emacs 210Emacs cannot visit files that are larger than the maximum Emacs buffer
239buffer size, which is around 256 megabytes on 32-bit machines 211size, which is around 256 megabytes on 32-bit machines
240(@pxref{Buffers}). If you try, Emacs will display an error message 212(@pxref{Buffers}). If you try, Emacs will display an error message
241saying that the maximum buffer size has been exceeded. 213saying that the maximum buffer size has been exceeded.
242 214
215@cindex wildcard characters in file names
216@vindex find-file-wildcards
217 If the file name you specify contains shell-style wildcard
218characters, Emacs visits all the files that match it. (On
219case-insensitive filesystems, Emacs matches the wildcards disregarding
220the letter case.) Wildcards include @samp{?}, @samp{*}, and
221@samp{[@dots{}]} sequences. To enter the wild card @samp{?} in a file
222name in the minibuffer, you need to type @kbd{C-q ?}. @xref{Quoted
223File Names}, for information on how to visit a file whose name
224actually contains wildcard characters. You can disable the wildcard
225feature by customizing @code{find-file-wildcards}.
226
243@cindex file selection dialog 227@cindex file selection dialog
244 On graphical displays there are two additional methods for 228 On graphical displays, there are two additional methods for visiting
245visiting files. Firstly, when Emacs is built with a suitable GUI 229files. Firstly, when Emacs is built with a suitable GUI toolkit,
246toolkit, commands invoked with the mouse (by clicking on the menu bar 230commands invoked with the mouse (by clicking on the menu bar or tool
247or tool bar) use the toolkit's standard File Selection dialog instead 231bar) use the toolkit's standard ``File Selection'' dialog instead of
248of prompting for the file name in the minibuffer. On Unix and 232prompting for the file name in the minibuffer. On GNU/Linux and Unix
249GNU/Linux platforms, Emacs does that when built with GTK, LessTif, and 233platforms, Emacs does this when built with GTK, LessTif, and Motif
250Motif toolkits; on MS-Windows and Mac, the GUI version does that by default. 234toolkits; on MS-Windows and Mac, the GUI version does that by default.
251For information on how to customize this, see @ref{Dialog Boxes}. 235For information on how to customize this, see @ref{Dialog Boxes}.
252 236
253 Secondly, Emacs supports ``drag and drop''; dropping a file into an 237 Secondly, Emacs supports ``drag and drop'': dropping a file into an
254ordinary Emacs window visits the file using that window. However, 238ordinary Emacs window visits the file using that window. As an
255dropping a file into a window displaying a Dired buffer moves or 239exception, dropping a file into a window displaying a Dired buffer
256copies the file into the displayed directory. For details, see 240moves or copies the file into the displayed directory. For details,
257@ref{Drag and Drop}, and @ref{Misc Dired Features}. 241see @ref{Drag and Drop}, and @ref{Misc Dired Features}.
258 242
259@cindex creating files 243@cindex creating files
260 What if you want to create a new file? Just visit it. Emacs displays 244 What if you want to create a new file? Just visit it. Emacs
261@samp{(New file)} in the echo area, but in other respects behaves as if 245displays @samp{(New file)} in the echo area, but in other respects
262you had visited an existing empty file. If you make any changes and 246behaves as if you had visited an existing empty file. If you make
263save them, the file is created. 247changes and save them, the file is created.
264 248
265 Emacs recognizes from the contents of a file which end-of-line 249@kindex C-x C-v
266convention it uses to separate lines---newline (used on GNU/Linux and 250@findex find-alternate-file
267on Unix), carriage-return linefeed (used on Microsoft systems), or 251 If you visit a nonexistent file unintentionally (because you typed
268just carriage-return (used on the Macintosh)---and automatically 252the wrong file name), type @kbd{C-x C-v} (@code{find-alternate-file})
269converts the contents to the normal Emacs convention, which is that 253to visit the file you really wanted. @kbd{C-x C-v} is similar to
270the newline character separates lines. This is a part of the general 254@kbd{C-x C-f}, but it kills the current buffer (after first offering
271feature of coding system conversion (@pxref{Coding Systems}), and 255to save it if it is modified). When @kbd{C-x C-v} reads the file name
272makes it possible to edit files imported from different operating 256to visit, it inserts the entire default file name in the buffer, with
273systems with equal convenience. If you change the text and save the 257point just after the directory part; this is convenient if you made a
274file, Emacs performs the inverse conversion, changing newlines back 258slight error in typing the name.
275into carriage-return linefeed or just carriage-return if appropriate.
276 259
277@vindex find-file-run-dired 260@vindex find-file-run-dired
278 If the file you specify is actually a directory, @kbd{C-x C-f} invokes 261 If you ``visit'' a file that is actually a directory, Emacs invokes
279Dired, the Emacs directory browser, so that you can ``edit'' the contents 262Dired, the Emacs directory browser; this lets you you ``edit'' the
280of the directory (@pxref{Dired}). Dired is a convenient way to view, delete, 263contents of the directory. @xref{Dired}. You can disable this
281or operate on the files in the directory. However, if the variable 264behavior by setting the variable @code{find-file-run-dired} to
282@code{find-file-run-dired} is @code{nil}, then it is an error to try 265@code{nil}; in that case, it is an error to try to visit a directory.
283to visit a directory.
284 266
285 Files which are actually collections of other files, or @dfn{file 267 Files which are actually collections of other files, or @dfn{file
286archives}, are visited in special modes which invoke a Dired-like 268archives}, are visited in special modes which invoke a Dired-like
287environment to allow operations on archive members. @xref{File 269environment to allow operations on archive members. @xref{File
288Archives}, for more about these features. 270Archives}, for more about these features.
289 271
290@cindex wildcard characters in file names
291@vindex find-file-wildcards
292 If the file name you specify contains shell-style wildcard
293characters, Emacs visits all the files that match it. (On
294case-insensitive filesystems, Emacs matches the wildcards disregarding
295the letter case.) Wildcards include @samp{?}, @samp{*}, and
296@samp{[@dots{}]} sequences. To enter the wild card @samp{?} in a file
297name in the minibuffer, you need to type @kbd{C-q ?}. @xref{Quoted
298File Names}, for information on how to visit a file whose name
299actually contains wildcard characters. You can disable the wildcard
300feature by customizing @code{find-file-wildcards}.
301
302 If you visit a file that the operating system won't let you modify, 272 If you visit a file that the operating system won't let you modify,
303or that is marked read-only, Emacs makes the buffer read-only too, so 273or that is marked read-only, Emacs makes the buffer read-only too, so
304that you won't go ahead and make changes that you'll have trouble 274that you won't go ahead and make changes that you'll have trouble
@@ -311,17 +281,6 @@ saving afterward. You can make the buffer writable with @kbd{C-x C-q}
311yourself from entering changes accidentally, visit it with the command 281yourself from entering changes accidentally, visit it with the command
312@kbd{C-x C-r} (@code{find-file-read-only}) instead of @kbd{C-x C-f}. 282@kbd{C-x C-r} (@code{find-file-read-only}) instead of @kbd{C-x C-f}.
313 283
314@kindex C-x C-v
315@findex find-alternate-file
316 If you visit a nonexistent file unintentionally (because you typed the
317wrong file name), use the @kbd{C-x C-v} command
318(@code{find-alternate-file}) to visit the file you really wanted.
319@kbd{C-x C-v} is similar to @kbd{C-x C-f}, but it kills the current
320buffer (after first offering to save it if it is modified). When
321@kbd{C-x C-v} reads the file name to visit, it inserts the entire
322default file name in the buffer, with point just after the directory
323part; this is convenient if you made a slight error in typing the name.
324
325@kindex C-x 4 f 284@kindex C-x 4 f
326@findex find-file-other-window 285@findex find-file-other-window
327 @kbd{C-x 4 f} (@code{find-file-other-window}) is like @kbd{C-x C-f} 286 @kbd{C-x 4 f} (@code{find-file-other-window}) is like @kbd{C-x C-f}
@@ -339,15 +298,28 @@ new frame, or makes visible any existing frame showing the file you
339seek. This feature is available only when you are using a window 298seek. This feature is available only when you are using a window
340system. @xref{Frames}. 299system. @xref{Frames}.
341 300
301 Emacs recognizes from the contents of a file which end-of-line
302convention it uses to separate lines---newline (used on GNU/Linux and
303on Unix), carriage-return linefeed (used on Microsoft systems), or
304just carriage-return (used on the Macintosh)---and automatically
305converts the contents to the normal Emacs convention, which is that
306the newline character separates lines. This is a part of the general
307feature of coding system conversion (@pxref{Coding Systems}), and
308makes it possible to edit files imported from different operating
309systems with equal convenience. If you change the text and save the
310file, Emacs performs the inverse conversion, changing newlines back
311into carriage-return linefeed or just carriage-return if appropriate.
312
342@findex find-file-literally 313@findex find-file-literally
343 If you wish to edit a file as a sequence of @acronym{ASCII} characters with no special 314 If you wish to edit a file as a sequence of @acronym{ASCII}
344encoding or conversion, use the @kbd{M-x find-file-literally} command. 315characters with no special encoding or conversion, use the @kbd{M-x
345It visits a file, like @kbd{C-x C-f}, but does not do format conversion 316find-file-literally} command. This visits a file, like @kbd{C-x C-f},
346(@pxref{Formatted Text}), character code conversion (@pxref{Coding 317but does not do format conversion (@pxref{Formatted Text}), character
347Systems}), or automatic uncompression (@pxref{Compressed Files}), and 318code conversion (@pxref{Coding Systems}), or automatic uncompression
348does not add a final newline because of @code{require-final-newline}. 319(@pxref{Compressed Files}), and does not add a final newline because
349If you already have visited the same file in the usual (non-literal) 320of @code{require-final-newline} (@pxref{Customize Save}). If you have
350manner, this command asks you whether to visit it literally instead. 321already visited the same file in the usual (non-literal) manner, this
322command asks you whether to visit it literally instead.
351 323
352@vindex find-file-hook 324@vindex find-file-hook
353@vindex find-file-not-found-functions 325@vindex find-file-not-found-functions
@@ -423,6 +395,9 @@ like this in the echo area:
423(No changes need to be saved) 395(No changes need to be saved)
424@end example 396@end example
425 397
398With a prefix argument, @kbd{C-u C-x C-s}, Emacs also marks the buffer
399to be backed up when the next save is done. @xref{Backup}.
400
426@kindex C-x s 401@kindex C-x s
427@findex save-some-buffers 402@findex save-some-buffers
428 The command @kbd{C-x s} (@code{save-some-buffers}) offers to save any 403 The command @kbd{C-x s} (@code{save-some-buffers}) offers to save any
@@ -458,21 +433,19 @@ Display a help message about these options.
458 433
459@kindex M-~ 434@kindex M-~
460@findex not-modified 435@findex not-modified
461 If you have changed a buffer but you do not want to save the changes, 436 If you have changed a buffer but do not wish to save the changes,
462you should take some action to prevent it. Otherwise, each time you use 437you should take some action to prevent it. Otherwise, each time you
463@kbd{C-x s} or @kbd{C-x C-c}, you are liable to save this buffer by 438use @kbd{C-x s} or @kbd{C-x C-c}, you are liable to save this buffer
464mistake. One thing you can do is type @kbd{M-~} (@code{not-modified}), 439by mistake. One thing you can do is type @kbd{M-~}
465which clears out the indication that the buffer is modified. If you do 440(@code{not-modified}), which clears out the indication that the buffer
466this, none of the save commands will believe that the buffer needs to be 441is modified. If you do this, none of the save commands will believe
467saved. (@samp{~} is often used as a mathematical symbol for `not'; thus 442that the buffer needs to be saved. (@samp{~} is often used as a
468@kbd{M-~} is `not', metafied.) You could also use 443mathematical symbol for `not'; thus @kbd{M-~} is `not', metafied.)
469@code{set-visited-file-name} (see below) to mark the buffer as visiting
470a different file name, one which is not in use for anything important.
471Alternatively, you can cancel all the changes made since the file was 444Alternatively, you can cancel all the changes made since the file was
472visited or saved, by reading the text from the file again. This is 445visited or saved, by reading the text from the file again. This is
473called @dfn{reverting}. @xref{Reverting}. (You could also undo all the 446called @dfn{reverting}. @xref{Reverting}. (You could also undo all
474changes by repeating the undo command @kbd{C-x u} until you have undone 447the changes by repeating the undo command @kbd{C-x u} until you have
475all the changes; but reverting is easier.) You can also kill the buffer. 448undone all the changes; but reverting is easier.)
476 449
477@findex set-visited-file-name 450@findex set-visited-file-name
478 @kbd{M-x set-visited-file-name} alters the name of the file that the 451 @kbd{M-x set-visited-file-name} alters the name of the file that the
@@ -486,15 +459,15 @@ buffer as ``modified'' so that @kbd{C-x C-s} in that buffer
486 459
487@kindex C-x C-w 460@kindex C-x C-w
488@findex write-file 461@findex write-file
489 If you wish to mark the buffer as visiting a different file and save it 462 If you wish to mark the buffer as visiting a different file and save
490right away, use @kbd{C-x C-w} (@code{write-file}). It is 463it right away, use @kbd{C-x C-w} (@code{write-file}). This is
491equivalent to @code{set-visited-file-name} followed by @kbd{C-x C-s} 464equivalent to @code{set-visited-file-name} followed by @kbd{C-x C-s},
492(except that @kbd{C-x C-w} asks for confirmation if the file exists). 465except that @kbd{C-x C-w} asks for confirmation if the file exists.
493@kbd{C-x C-s} used on a buffer that is not visiting a file has the 466@kbd{C-x C-s} used on a buffer that is not visiting a file has the
494same effect as @kbd{C-x C-w}; that is, it reads a file name, marks the 467same effect as @kbd{C-x C-w}; that is, it reads a file name, marks the
495buffer as visiting that file, and saves it there. The default file name in 468buffer as visiting that file, and saves it there. The default file
496a buffer that is not visiting a file is made by combining the buffer name 469name in a buffer that is not visiting a file is made by combining the
497with the buffer's default directory (@pxref{File Names}). 470buffer name with the buffer's default directory (@pxref{File Names}).
498 471
499 If the new file name implies a major mode, then @kbd{C-x C-w} switches 472 If the new file name implies a major mode, then @kbd{C-x C-w} switches
500to that major mode, in most cases. The command 473to that major mode, in most cases. The command
@@ -518,6 +491,11 @@ throws away the old contents of the file---or it would, except that
518Emacs carefully copies the old contents to another file, called the 491Emacs carefully copies the old contents to another file, called the
519@dfn{backup} file, before actually saving. 492@dfn{backup} file, before actually saving.
520 493
494 Emacs makes a backup for a file only the first time the file is
495saved from a buffer. No matter how many times you subsequently save
496the file, its backup remains unchanged. However, if you kill the
497buffer and then visit the file again, a new backup file will be made.
498
521 For most files, the variable @code{make-backup-files} determines 499 For most files, the variable @code{make-backup-files} determines
522whether to make backup files. On most operating systems, its default 500whether to make backup files. On most operating systems, its default
523value is @code{t}, so that Emacs does write backup files. 501value is @code{t}, so that Emacs does write backup files.
@@ -534,9 +512,9 @@ control system.
534@xref{General VC Options}. 512@xref{General VC Options}.
535@end ifnottex 513@end ifnottex
536 514
537
538 At your option, Emacs can keep either a single backup for each file, 515 At your option, Emacs can keep either a single backup for each file,
539or make a series of numbered backup files for each file that you edit. 516or make a series of numbered backup files for each file that you edit.
517@xref{Backup Names}.
540 518
541@vindex backup-enable-predicate 519@vindex backup-enable-predicate
542@vindex temporary-file-directory 520@vindex temporary-file-directory
@@ -546,43 +524,50 @@ prevents backup files being written for files in the directories used
546for temporary files, specified by @code{temporary-file-directory} or 524for temporary files, specified by @code{temporary-file-directory} or
547@code{small-temporary-file-directory}. 525@code{small-temporary-file-directory}.
548 526
549 Emacs makes a backup for a file only the first time the file is saved 527 You can explicitly tell Emacs to make another backup file from a
550from one buffer. No matter how many times you save a file, its backup file 528buffer, even though that buffer has been saved before. If you save
551continues to contain the contents from before the file was visited.
552Normally this means that the backup file contains the contents from before
553the current editing session; however, if you kill the buffer and then visit
554the file again, a new backup file will be made by the next save.
555
556 You can also explicitly request making another backup file from a
557buffer even though it has already been saved at least once. If you save
558the buffer with @kbd{C-u C-x C-s}, the version thus saved will be made 529the buffer with @kbd{C-u C-x C-s}, the version thus saved will be made
559into a backup file if you save the buffer again. @kbd{C-u C-u C-x C-s} 530into a backup file if you save the buffer again. @kbd{C-u C-u C-x
560saves the buffer, but first makes the previous file contents into a new 531C-s} saves the buffer, but first makes the previous file contents into
561backup file. @kbd{C-u C-u C-u C-x C-s} does both things: it makes a 532a new backup file. @kbd{C-u C-u C-u C-x C-s} does both things: it
562backup from the previous contents, and arranges to make another from the 533makes a backup from the previous contents, and arranges to make
563newly saved contents if you save again. 534another from the newly saved contents if you save again.
564 535
565@menu 536@menu
566* One or Many: Numbered Backups. Whether to make one backup file or many.
567* Names: Backup Names. How backup files are named. 537* Names: Backup Names. How backup files are named.
568* Deletion: Backup Deletion. Emacs deletes excess numbered backups. 538* Deletion: Backup Deletion. Emacs deletes excess numbered backups.
569* Copying: Backup Copying. Backups can be made by copying or renaming. 539* Copying: Backup Copying. Backups can be made by copying or renaming.
570@end menu 540@end menu
571 541
572@node Numbered Backups 542@node Backup Names
573@subsubsection Numbered Backups 543@subsubsection Single or Numbered Backups
544
545 When Emacs makes a backup file, its name is normally constructed by
546appending @samp{~} to the file name being edited; thus, the backup
547file for @file{eval.c} would be @file{eval.c~}.
548
549 If access control stops Emacs from writing backup files under the usual
550names, it writes the backup file as @file{%backup%~} in your home
551directory. Only one such file can exist, so only the most recently
552made such backup is available.
553
554 Emacs can also make @dfn{numbered backup files}. Numbered backup
555file names contain @samp{.~}, the number, and another @samp{~} after
556the original file name. Thus, the backup files of @file{eval.c} would
557be called @file{eval.c.~1~}, @file{eval.c.~2~}, and so on, all the way
558through names like @file{eval.c.~259~} and beyond.
574 559
575@vindex version-control 560@vindex version-control
576 The choice of single backup file or multiple numbered backup files 561 The variable @code{version-control} determines whether to make
577is controlled by the variable @code{version-control}. Its possible 562single backup files or multiple numbered backup files. Its possible
578values are: 563values are:
579 564
580@table @code 565@table @code
581@item t
582Make numbered backups.
583@item nil 566@item nil
584Make numbered backups for files that have numbered backups already. 567Make numbered backups for files that have numbered backups already.
585Otherwise, make single backups. 568Otherwise, make single backups. This is the default.
569@item t
570Make numbered backups.
586@item never 571@item never
587Never make numbered backups; always make single backups. 572Never make numbered backups; always make single backups.
588@end table 573@end table
@@ -606,41 +591,23 @@ value is @samp{nil} or @samp{existing}, then @code{version-control}
606becomes @code{nil}; if it is @samp{never} or @samp{simple}, then 591becomes @code{nil}; if it is @samp{never} or @samp{simple}, then
607@code{version-control} becomes @code{never}. 592@code{version-control} becomes @code{never}.
608 593
609@node Backup Names
610@subsubsection Single or Numbered Backups
611
612 When Emacs makes a single backup file, its name is normally
613constructed by appending @samp{~} to the file name being edited; thus,
614the backup file for @file{eval.c} would be @file{eval.c~}.
615
616@vindex make-backup-file-name-function
617@vindex backup-directory-alist 594@vindex backup-directory-alist
618 You can change this behavior by defining the variable 595 You can customize the variable @code{backup-directory-alist} to
619@code{make-backup-file-name-function} to a suitable function. 596specify that files matching certain patterns should be backed up in
620Alternatively you can customize the variable 597specific directories. This variable applies to both single and
621@code{backup-directory-alist} to specify that files matching certain 598numbered backups. A typical use is to add an element @code{("."
622patterns should be backed up in specific directories. 599. @var{dir})} to make all backups in the directory with absolute name
623 600@var{dir}; Emacs modifies the backup file names to avoid clashes
624 A typical use is to add an element @code{("." . @var{dir})} to make 601between files with the same names originating in different
625all backups in the directory with absolute name @var{dir}; Emacs 602directories. Alternatively, adding, @code{("." . ".~")} would make
626modifies the backup file names to avoid clashes between files with the 603backups in the invisible subdirectory @file{.~} of the original file's
627same names originating in different directories. Alternatively, 604directory. Emacs creates the directory, if necessary, to make the
628adding, say, @code{("." . ".~")} would make backups in the invisible 605backup.
629subdirectory @file{.~} of the original file's directory. Emacs
630creates the directory, if necessary, to make the backup.
631 606
632 If access control stops Emacs from writing backup files under the usual 607@vindex make-backup-file-name-function
633names, it writes the backup file as @file{%backup%~} in your home 608 If you define the variable @code{make-backup-file-name-function} to
634directory. Only one such file can exist, so only the most recently 609a suitable Lisp function, that overrides the usual way Emacs
635made such backup is available. 610constructs backup file names.
636
637 If you choose to have a series of numbered backup files, backup file
638names contain @samp{.~}, the number, and another @samp{~} after the
639original file name. Thus, the backup files of @file{eval.c} would be
640called @file{eval.c.~1~}, @file{eval.c.~2~}, and so on, all the way
641through names like @file{eval.c.~259~} and beyond. The variable
642@code{backup-directory-alist} applies to numbered backups just as
643usual.
644 611
645@node Backup Deletion 612@node Backup Deletion
646@subsubsection Automatic Deletion of Backups 613@subsubsection Automatic Deletion of Backups
@@ -778,10 +745,10 @@ file.
778@cindex locking files 745@cindex locking files
779 When you make the first modification in an Emacs buffer that is 746 When you make the first modification in an Emacs buffer that is
780visiting a file, Emacs records that the file is @dfn{locked} by you. 747visiting a file, Emacs records that the file is @dfn{locked} by you.
781(It does this by creating a symbolic link in the same directory with a 748(It does this by creating a specially-named symbolic link in the same
782different name.) Emacs removes the lock when you save the changes. The 749directory.) Emacs removes the lock when you save the changes. The
783idea is that the file is locked whenever an Emacs buffer visiting it has 750idea is that the file is locked whenever an Emacs buffer visiting it
784unsaved changes. 751has unsaved changes.
785 752
786@cindex collision 753@cindex collision
787 If you begin to modify the buffer while the visited file is locked by 754 If you begin to modify the buffer while the visited file is locked by
@@ -813,23 +780,22 @@ editing of new files that will not really exist until they are saved.
813there are cases where lock files cannot be written. In these cases, 780there are cases where lock files cannot be written. In these cases,
814Emacs cannot detect trouble in advance, but it still can detect the 781Emacs cannot detect trouble in advance, but it still can detect the
815collision when you try to save a file and overwrite someone else's 782collision when you try to save a file and overwrite someone else's
816changes. 783changes. Every time Emacs saves a buffer, it first checks the
784last-modification date of the existing file on disk to verify that it
785has not changed since the file was last visited or saved. If the date
786does not match, it implies that changes were made in the file in some
787other way, and these changes are about to be lost if Emacs actually
788does save. To prevent this, Emacs displays a warning message and asks
789for confirmation before saving. Occasionally you will know why the
790file was changed and know that it does not matter; then you can answer
791@kbd{yes} and proceed. Otherwise, you should cancel the save with
792@kbd{C-g} and investigate the situation.
817 793
818 If Emacs or the operating system crashes, this may leave behind lock 794 If Emacs or the operating system crashes, this may leave behind lock
819files which are stale, so you may occasionally get warnings about 795files which are stale, so you may occasionally get warnings about
820spurious collisions. When you determine that the collision is spurious, 796spurious collisions. When you determine that the collision is spurious,
821just use @kbd{p} to tell Emacs to go ahead anyway. 797just use @kbd{p} to tell Emacs to go ahead anyway.
822 798
823 Every time Emacs saves a buffer, it first checks the last-modification
824date of the existing file on disk to verify that it has not changed since the
825file was last visited or saved. If the date does not match, it implies
826that changes were made in the file in some other way, and these changes are
827about to be lost if Emacs actually does save. To prevent this, Emacs
828displays a warning message and asks for confirmation before saving.
829Occasionally you will know why the file was changed and know that it does
830not matter; then you can answer @kbd{yes} and proceed. Otherwise, you should
831cancel the save with @kbd{C-g} and investigate the situation.
832
833 The first thing you should do when notified that simultaneous editing 799 The first thing you should do when notified that simultaneous editing
834has already taken place is to list the directory with @kbd{C-u C-x C-d} 800has already taken place is to list the directory with @kbd{C-u C-x C-d}
835(@pxref{Directories}). This shows the file's current author. You 801(@pxref{Directories}). This shows the file's current author. You
@@ -933,23 +899,20 @@ the file was edited only slightly, you will be at approximately the
933same piece of text after reverting as before. However, if you have made 899same piece of text after reverting as before. However, if you have made
934drastic changes, point may wind up in a totally different piece of text. 900drastic changes, point may wind up in a totally different piece of text.
935 901
936 Reverting marks the buffer as ``not modified'' until another change is 902 Reverting marks the buffer as ``not modified''.
937made.
938 903
939 Some kinds of buffers whose contents reflect data bases other than files, 904 Some kinds of buffers that are not associated with files, such as
940such as Dired buffers, can also be reverted. For them, reverting means 905Dired buffers, can also be reverted. For them, reverting means
941recalculating their contents from the appropriate data base. Buffers 906recalculating their contents. Buffers created explicitly with
942created explicitly with @kbd{C-x b} cannot be reverted; @code{revert-buffer} 907@kbd{C-x b} cannot be reverted; @code{revert-buffer} reports an error
943reports an error when asked to do so. 908if you try.
944 909
945@vindex revert-without-query 910@vindex revert-without-query
946 When you edit a file that changes automatically and frequently---for 911 When you edit a file that changes automatically and frequently---for
947example, a log of output from a process that continues to run---it may be 912example, a log of output from a process that continues to run---it may
948useful for Emacs to revert the file without querying you, whenever you 913be useful for Emacs to revert the file without querying you. To
949visit the file again with @kbd{C-x C-f}. 914request this behavior, set the variable @code{revert-without-query} to
950 915a list of regular expressions. When a file name matches one of these
951 To request this behavior, set the variable @code{revert-without-query}
952to a list of regular expressions. When a file name matches one of these
953regular expressions, @code{find-file} and @code{revert-buffer} will 916regular expressions, @code{find-file} and @code{revert-buffer} will
954revert it automatically if it has changed---provided the buffer itself 917revert it automatically if it has changed---provided the buffer itself
955is not modified. (If you have edited the text, it would be wrong to 918is not modified. (If you have edited the text, it would be wrong to
@@ -962,17 +925,18 @@ discard your changes.)
962@findex global-auto-revert-mode 925@findex global-auto-revert-mode
963@findex auto-revert-mode 926@findex auto-revert-mode
964@findex auto-revert-tail-mode 927@findex auto-revert-tail-mode
928@vindex auto-revert-interval
965 929
966 You may find it useful to have Emacs revert files automatically when 930 In addition, you can tell Emacs to periodically revert a buffer by
967they change. Three minor modes are available to do this. 931typing @kbd{M-x auto-revert-mode}. This turns on Auto-Revert mode, a
968 932minor mode that makes Emacs automatically revert the current buffer
969 @kbd{M-x global-auto-revert-mode} enables Global Auto-Revert mode, 933every five seconds. You can change this interval through the variable
970which periodically checks all file buffers and reverts when the 934@code{auto-revert-interval}. Typing @kbd{M-x global-auto-revert-mode}
971corresponding file has changed. @kbd{M-x auto-revert-mode} enables a 935enables Global Auto-Revert mode, which does the same for all file
972local version, Auto-Revert mode, which applies only to the current 936buffers. Auto-Revert mode and Global Auto-Revert modes do not check
973buffer. 937or revert remote files, because that is usually too slow.
974 938
975 You can use Auto-Revert mode to ``tail'' a file such as a system 939 One use of Auto-Revert mode is to ``tail'' a file such as a system
976log, so that changes made to that file by other programs are 940log, so that changes made to that file by other programs are
977continuously displayed. To do this, just move the point to the end of 941continuously displayed. To do this, just move the point to the end of
978the buffer, and it will stay there as the file contents change. 942the buffer, and it will stay there as the file contents change.
@@ -980,11 +944,6 @@ However, if you are sure that the file will only change by growing at
980the end, use Auto-Revert Tail mode instead 944the end, use Auto-Revert Tail mode instead
981(@code{auto-revert-tail-mode}). It is more efficient for this. 945(@code{auto-revert-tail-mode}). It is more efficient for this.
982 946
983@vindex auto-revert-interval
984 The variable @code{auto-revert-interval} controls how often to check
985for a changed file. Since checking a remote file is too slow, these
986modes do not check or revert remote files.
987
988 @xref{VC Mode Line}, for Auto Revert peculiarities in buffers that 947 @xref{VC Mode Line}, for Auto Revert peculiarities in buffers that
989visit files under version control. 948visit files under version control.
990 949
@@ -998,11 +957,10 @@ visit files under version control.
998@cindex mode, Auto Save 957@cindex mode, Auto Save
999@cindex crashes 958@cindex crashes
1000 959
1001 Emacs saves all the visited files from time to time (based on 960 From time to time, Emacs automatically saves each visited file in a
1002counting your keystrokes) without being asked, in separate files so as 961separate file, without altering the file you actually use. This is
1003not to alter the files you actually use. This is called 962called @dfn{auto-saving}. It prevents you from losing more than a
1004@dfn{auto-saving}. It prevents you from losing more than a limited 963limited amount of work if the system crashes.
1005amount of work if the system crashes.
1006 964
1007 When Emacs determines that it is time for auto-saving, it considers 965 When Emacs determines that it is time for auto-saving, it considers
1008each buffer, and each is auto-saved if auto-saving is enabled for it 966each buffer, and each is auto-saved if auto-saving is enabled for it
@@ -1022,12 +980,11 @@ execution of commands you have been typing.
1022@node Auto Save Files 980@node Auto Save Files
1023@subsection Auto-Save Files 981@subsection Auto-Save Files
1024 982
1025 Auto-saving does not normally save in the files that you visited, because 983 Auto-saving does not normally save in the files that you visited,
1026it can be very undesirable to save a program that is in an inconsistent 984because it can be very undesirable to save a change that you did not
1027state when you have made half of a planned change. Instead, auto-saving 985want to make permanent. Instead, auto-saving is done in a different
1028is done in a different file called the @dfn{auto-save file}, and the 986file called the @dfn{auto-save file}, and the visited file is changed
1029visited file is changed only when you request saving explicitly (such as 987only when you request saving explicitly (such as with @kbd{C-x C-s}).
1030with @kbd{C-x C-s}).
1031 988
1032 Normally, the auto-save file name is made by appending @samp{#} to the 989 Normally, the auto-save file name is made by appending @samp{#} to the
1033front and rear of the visited file name. Thus, a buffer visiting file 990front and rear of the visited file name. Thus, a buffer visiting file
@@ -1157,9 +1114,9 @@ this---saving them---updates the files themselves.
1157@vindex auto-save-list-file-prefix 1114@vindex auto-save-list-file-prefix
1158 Emacs records information about interrupted sessions for later 1115 Emacs records information about interrupted sessions for later
1159recovery in files named 1116recovery in files named
1160@file{~/.emacs.d/auto-save-list/.saves-@var{pid}-@var{hostname}}. All 1117@file{~/.emacs.d/auto-save-list/.saves-@var{pid}-@var{hostname}}. The
1161of this name except the @file{@var{pid}-@var{hostname}} part comes 1118directory used, @file{~/.emacs.d/auto-save-list/}, is determined by
1162from the value of @code{auto-save-list-file-prefix}. You can record 1119the variable @code{auto-save-list-file-prefix}. You can record
1163sessions in a different place by customizing that variable. If you 1120sessions in a different place by customizing that variable. If you
1164set @code{auto-save-list-file-prefix} to @code{nil} in your 1121set @code{auto-save-list-file-prefix} to @code{nil} in your
1165@file{.emacs} file, sessions are not recorded for recovery. 1122@file{.emacs} file, sessions are not recorded for recovery.
@@ -1214,11 +1171,8 @@ description of what was changed in that version.
1214 1171
1215 The Emacs version control interface is called VC. Its commands work 1172 The Emacs version control interface is called VC. Its commands work
1216with different version control systems---currently, it supports CVS, 1173with different version control systems---currently, it supports CVS,
1217GNU Arch, RCS, Subversion, and SCCS. Of these, the GNU 1174GNU Arch, RCS, Subversion, SCCS, Mercurial, Monotone, Bazaar, and Git.
1218project distributes CVS, GNU Arch, and RCS. We also have free 1175Of these, the GNU project distributes CVS, GNU Arch, RCS, and Bazaar.
1219software to replace SCCS, known as CSSC; if you are using SCCS and
1220don't want to make the incompatible change to RCS or CVS, you can
1221switch to CSSC.
1222 1176
1223 VC is enabled by default in Emacs. To disable it, set the 1177 VC is enabled by default in Emacs. To disable it, set the
1224customizable variable @code{vc-handled-backends} to @code{nil} 1178customizable variable @code{vc-handled-backends} to @code{nil}