| 1 | @c This is part of the Emacs manual. |
| 2 | @c Copyright (C) 1985,86,87,93,94,95,97,99, 2000 Free Software Foundation, Inc. |
| 3 | @c See file emacs.texi for copying conditions. |
| 4 | @node Files, Buffers, Fixit, Top |
| 5 | @chapter File Handling |
| 6 | @cindex files |
| 7 | |
| 8 | The operating system stores data permanently in named @dfn{files}. So |
| 9 | most of the text you edit with Emacs comes from a file and is ultimately |
| 10 | stored in a file. |
| 11 | |
| 12 | To edit a file, you must tell Emacs to read the file and prepare a |
| 13 | buffer containing a copy of the file's text. This is called |
| 14 | @dfn{visiting} the file. Editing commands apply directly to text in the |
| 15 | buffer; that is, to the copy inside Emacs. Your changes appear in the |
| 16 | file itself only when you @dfn{save} the buffer back into the file. |
| 17 | |
| 18 | In addition to visiting and saving files, Emacs can delete, copy, |
| 19 | rename, and append to files, keep multiple versions of them, and operate |
| 20 | on file directories. |
| 21 | |
| 22 | @menu |
| 23 | * File Names:: How to type and edit file-name arguments. |
| 24 | * Visiting:: Visiting a file prepares Emacs to edit the file. |
| 25 | * Saving:: Saving makes your changes permanent. |
| 26 | * Reverting:: Reverting cancels all the changes not saved. |
| 27 | * Auto Save:: Auto Save periodically protects against loss of data. |
| 28 | * File Aliases:: Handling multiple names for one file. |
| 29 | * Version Control:: Version control systems (RCS, CVS and SCCS). |
| 30 | * Directories:: Creating, deleting, and listing file directories. |
| 31 | * Comparing Files:: Finding where two files differ. |
| 32 | * Misc File Ops:: Other things you can do on files. |
| 33 | * Compressed Files:: Accessing compressed files. |
| 34 | * File Archives:: Operating on tar, zip, jar etc. archive files. |
| 35 | * Remote Files:: Accessing files on other sites. |
| 36 | * Quoted File Names:: Quoting special characters in file names. |
| 37 | @end menu |
| 38 | |
| 39 | @node File Names |
| 40 | @section File Names |
| 41 | @cindex file names |
| 42 | |
| 43 | Most Emacs commands that operate on a file require you to specify the |
| 44 | file name. (Saving and reverting are exceptions; the buffer knows which |
| 45 | file name to use for them.) You enter the file name using the |
| 46 | minibuffer (@pxref{Minibuffer}). @dfn{Completion} is available, to make |
| 47 | it easier to specify long file names. @xref{Completion}. |
| 48 | |
| 49 | For most operations, there is a @dfn{default file name} which is used |
| 50 | if you type just @key{RET} to enter an empty argument. Normally the |
| 51 | default file name is the name of the file visited in the current buffer; |
| 52 | this makes it easy to operate on that file with any of the Emacs file |
| 53 | commands. |
| 54 | |
| 55 | @vindex default-directory |
| 56 | Each buffer has a default directory, normally the same as the |
| 57 | directory of the file visited in that buffer. When you enter a file |
| 58 | name without a directory, the default directory is used. If you specify |
| 59 | a directory in a relative fashion, with a name that does not start with |
| 60 | a slash, it is interpreted with respect to the default directory. The |
| 61 | default directory is kept in the variable @code{default-directory}, |
| 62 | which has a separate value in every buffer. |
| 63 | |
| 64 | For example, if the default file name is @file{/u/rms/gnu/gnu.tasks} then |
| 65 | the default directory is @file{/u/rms/gnu/}. If you type just @samp{foo}, |
| 66 | which does not specify a directory, it is short for @file{/u/rms/gnu/foo}. |
| 67 | @samp{../.login} would stand for @file{/u/rms/.login}. @samp{new/foo} |
| 68 | would stand for the file name @file{/u/rms/gnu/new/foo}. |
| 69 | |
| 70 | @findex cd |
| 71 | @findex pwd |
| 72 | The command @kbd{M-x pwd} prints the current buffer's default |
| 73 | directory, and the command @kbd{M-x cd} sets it (to a value read using |
| 74 | the minibuffer). A buffer's default directory changes only when the |
| 75 | @code{cd} command is used. A file-visiting buffer's default directory |
| 76 | is initialized to the directory of the file that is visited there. If |
| 77 | you create a buffer with @kbd{C-x b}, its default directory is copied |
| 78 | from that of the buffer that was current at the time. |
| 79 | |
| 80 | @vindex insert-default-directory |
| 81 | The default directory actually appears in the minibuffer when the |
| 82 | minibuffer becomes active to read a file name. This serves two |
| 83 | purposes: it @emph{shows} you what the default is, so that you can type |
| 84 | a relative file name and know with certainty what it will mean, and it |
| 85 | allows you to @emph{edit} the default to specify a different directory. |
| 86 | This insertion of the default directory is inhibited if the variable |
| 87 | @code{insert-default-directory} is set to @code{nil}. |
| 88 | |
| 89 | Note that it is legitimate to type an absolute file name after you |
| 90 | enter the minibuffer, ignoring the presence of the default directory |
| 91 | name as part of the text. The final minibuffer contents may look |
| 92 | invalid, but that is not so. For example, if the minibuffer starts out |
| 93 | with @samp{/usr/tmp/} and you add @samp{/x1/rms/foo}, you get |
| 94 | @samp{/usr/tmp//x1/rms/foo}; but Emacs ignores everything through the |
| 95 | first slash in the double slash; the result is @samp{/x1/rms/foo}. |
| 96 | @xref{Minibuffer File}. |
| 97 | |
| 98 | @samp{$} in a file name is used to substitute environment variables. |
| 99 | For example, if you have used the shell command @samp{export |
| 100 | FOO=rms/hacks} to set up an environment variable named @code{FOO}, then |
| 101 | you can use @file{/u/$FOO/test.c} or @file{/u/$@{FOO@}/test.c} as an |
| 102 | abbreviation for @file{/u/rms/hacks/test.c}. The environment variable |
| 103 | name consists of all the alphanumeric characters after the @samp{$}; |
| 104 | alternatively, it may be enclosed in braces after the @samp{$}. Note |
| 105 | that shell commands to set environment variables affect Emacs only if |
| 106 | done before Emacs is started. |
| 107 | |
| 108 | To access a file with @samp{$} in its name, type @samp{$$}. This pair |
| 109 | is converted to a single @samp{$} at the same time as variable |
| 110 | substitution is performed for single @samp{$}. Alternatively, quote the |
| 111 | whole file name with @samp{/:} (@pxref{Quoted File Names}). |
| 112 | |
| 113 | @findex substitute-in-file-name |
| 114 | The Lisp function that performs the substitution is called |
| 115 | @code{substitute-in-file-name}. The substitution is performed only on |
| 116 | file names read as such using the minibuffer. |
| 117 | |
| 118 | You can include non-ASCII characters in file names if you set the |
| 119 | variable @code{file-name-coding-system} to a non-@code{nil} value. |
| 120 | @xref{Specify Coding}. |
| 121 | |
| 122 | @node Visiting |
| 123 | @section Visiting Files |
| 124 | @cindex visiting files |
| 125 | |
| 126 | @c WideCommands |
| 127 | @table @kbd |
| 128 | @item C-x C-f |
| 129 | Visit a file (@code{find-file}). |
| 130 | @item C-x C-r |
| 131 | Visit a file for viewing, without allowing changes to it |
| 132 | (@code{find-file-read-only}). |
| 133 | @item C-x C-v |
| 134 | Visit a different file instead of the one visited last |
| 135 | (@code{find-alternate-file}). |
| 136 | @item C-x 4 f |
| 137 | Visit a file, in another window (@code{find-file-other-window}). Don't |
| 138 | alter what is displayed in the selected window. |
| 139 | @item C-x 5 f |
| 140 | Visit a file, in a new frame (@code{find-file-other-frame}). Don't |
| 141 | alter what is displayed in the selected frame. |
| 142 | @item M-x find-file-literally |
| 143 | Visit a file with no conversion of the contents. |
| 144 | @end table |
| 145 | |
| 146 | @cindex files, visiting and saving |
| 147 | @cindex visiting files |
| 148 | @cindex saving files |
| 149 | @dfn{Visiting} a file means copying its contents into an Emacs buffer |
| 150 | so you can edit them. Emacs makes a new buffer for each file that you |
| 151 | visit. We say that this buffer is visiting the file that it was created |
| 152 | to hold. Emacs constructs the buffer name from the file name by |
| 153 | throwing away the directory, keeping just the name proper. For example, |
| 154 | a file named @file{/usr/rms/emacs.tex} would get a buffer named |
| 155 | @samp{emacs.tex}. If there is already a buffer with that name, a unique |
| 156 | name is constructed by appending @samp{<2>}, @samp{<3>}, or so on, using |
| 157 | the lowest number that makes a name that is not already in use. |
| 158 | |
| 159 | Each window's mode line shows the name of the buffer that is being displayed |
| 160 | in that window, so you can always tell what buffer you are editing. |
| 161 | |
| 162 | The changes you make with editing commands are made in the Emacs |
| 163 | buffer. They do not take effect in the file that you visited, or any |
| 164 | place permanent, until you @dfn{save} the buffer. Saving the buffer |
| 165 | means that Emacs writes the current contents of the buffer into its |
| 166 | visited file. @xref{Saving}. |
| 167 | |
| 168 | @cindex modified (buffer) |
| 169 | If a buffer contains changes that have not been saved, we say the |
| 170 | buffer is @dfn{modified}. This is important because it implies that |
| 171 | some changes will be lost if the buffer is not saved. The mode line |
| 172 | displays two stars near the left margin to indicate that the buffer is |
| 173 | modified. |
| 174 | |
| 175 | @kindex C-x C-f |
| 176 | @findex find-file |
| 177 | To visit a file, use the command @kbd{C-x C-f} (@code{find-file}). Follow |
| 178 | the command with the name of the file you wish to visit, terminated by a |
| 179 | @key{RET}. |
| 180 | |
| 181 | The file name is read using the minibuffer (@pxref{Minibuffer}), with |
| 182 | defaulting and completion in the standard manner (@pxref{File Names}). |
| 183 | While in the minibuffer, you can abort @kbd{C-x C-f} by typing @kbd{C-g}. |
| 184 | |
| 185 | Your confirmation that @kbd{C-x C-f} has completed successfully is the |
| 186 | appearance of new text on the screen and a new buffer name in the mode |
| 187 | line. If the specified file does not exist and could not be created, or |
| 188 | cannot be read, then you get an error, with an error message displayed |
| 189 | in the echo area. |
| 190 | |
| 191 | If you visit a file that is already in Emacs, @kbd{C-x C-f} does not make |
| 192 | another copy. It selects the existing buffer containing that file. |
| 193 | However, before doing so, it checks that the file itself has not changed |
| 194 | since you visited or saved it last. If the file has changed, a warning |
| 195 | message is printed. @xref{Interlocking,,Simultaneous Editing}. |
| 196 | |
| 197 | @cindex creating files |
| 198 | What if you want to create a new file? Just visit it. Emacs prints |
| 199 | @samp{(New File)} in the echo area, but in other respects behaves as if |
| 200 | you had visited an existing empty file. If you make any changes and |
| 201 | save them, the file is created. |
| 202 | |
| 203 | Emacs recognizes from the contents of a file which convention it uses |
| 204 | to separate lines---newline (used on GNU/Linux and on Unix), |
| 205 | carriage-return linefeed (used on Microsoft systems), or just |
| 206 | carriage-return (used on the Macintosh)---and automatically converts the |
| 207 | contents to the normal Emacs convention, which is that the newline |
| 208 | character separates lines. This is a part of the general feature of |
| 209 | coding system conversion (@pxref{Coding Systems}), and makes it possible |
| 210 | to edit files imported from various different operating systems with |
| 211 | equal convenience. If you change the text and save the file, Emacs |
| 212 | performs the inverse conversion, changing newlines back into |
| 213 | carriage-return linefeed or just carriage-return if appropriate. |
| 214 | |
| 215 | @vindex find-file-run-dired |
| 216 | If the file you specify is actually a directory, @kbd{C-x C-f} invokes |
| 217 | Dired, the Emacs directory browser, so that you can ``edit'' the contents |
| 218 | of the directory (@pxref{Dired}). Dired is a convenient way to delete, |
| 219 | look at, or operate on the files in the directory. However, if the |
| 220 | variable @code{find-file-run-dired} is @code{nil}, then it is an error |
| 221 | to try to visit a directory. |
| 222 | |
| 223 | @cindex wildcard characters in file names |
| 224 | @vindex find-file-wildcards |
| 225 | If the file name you specify contains @code{sh}-style wildcard |
| 226 | characters, Emacs visits all the files that match it. @xref{Quoted File |
| 227 | Names}, if you want to visit a file whose name actually contains |
| 228 | wildcard characters. Wildcards comprise @samp{?}, @samp{*} and |
| 229 | @samp{[@dots{}]} sequences. The wildcard feature can be disabled by |
| 230 | customizing @code{find-file-wildcards}. |
| 231 | |
| 232 | If you visit a file that the operating system won't let you modify, |
| 233 | Emacs makes the buffer read-only, so that you won't go ahead and make |
| 234 | changes that you'll have trouble saving afterward. You can make the |
| 235 | buffer writable with @kbd{C-x C-q} (@code{vc-toggle-read-only}). |
| 236 | @xref{Misc Buffer}. |
| 237 | |
| 238 | @kindex C-x C-r |
| 239 | @findex find-file-read-only |
| 240 | Occasionally you might want to visit a file as read-only in order to |
| 241 | protect yourself from entering changes accidentally; do so by visiting |
| 242 | the file with the command @kbd{C-x C-r} (@code{find-file-read-only}). |
| 243 | |
| 244 | @kindex C-x C-v |
| 245 | @findex find-alternate-file |
| 246 | If you visit a nonexistent file unintentionally (because you typed the |
| 247 | wrong file name), use the @kbd{C-x C-v} command |
| 248 | (@code{find-alternate-file}) to visit the file you really wanted. |
| 249 | @kbd{C-x C-v} is similar to @kbd{C-x C-f}, but it kills the current |
| 250 | buffer (after first offering to save it if it is modified). When it |
| 251 | reads the file name to visit, it inserts the entire default file name in |
| 252 | the buffer, with point just after the directory part; this is convenient |
| 253 | if you made a slight error in typing the name. |
| 254 | |
| 255 | If you find a file which exists but cannot be read, @kbd{C-x C-f} |
| 256 | signals an error. |
| 257 | |
| 258 | @kindex C-x 4 f |
| 259 | @findex find-file-other-window |
| 260 | @kbd{C-x 4 f} (@code{find-file-other-window}) is like @kbd{C-x C-f} |
| 261 | except that the buffer containing the specified file is selected in another |
| 262 | window. The window that was selected before @kbd{C-x 4 f} continues to |
| 263 | show the same buffer it was already showing. If this command is used when |
| 264 | only one window is being displayed, that window is split in two, with one |
| 265 | window showing the same buffer as before, and the other one showing the |
| 266 | newly requested file. @xref{Windows}. |
| 267 | |
| 268 | @kindex C-x 5 f |
| 269 | @findex find-file-other-frame |
| 270 | @kbd{C-x 5 f} (@code{find-file-other-frame}) is similar, but opens a |
| 271 | new frame, or makes visible any existing frame showing the file you |
| 272 | seek. This feature is available only when you are using a window |
| 273 | system. @xref{Frames}. |
| 274 | |
| 275 | @findex find-file-literally |
| 276 | If you wish to edit a file as a sequence of characters with no special |
| 277 | encoding or conversion, use the @kbd{M-x find-file-literally} command. |
| 278 | It visits a file, like @kbd{C-x C-f}, but does not do format conversion |
| 279 | (@pxref{Formatted Text}), character code conversion (@pxref{Coding |
| 280 | Systems}), or automatic uncompression (@pxref{Compressed Files}). |
| 281 | If you already have visited the same file in the usual (non-literal) |
| 282 | manner, this command asks you whether to visit it literally instead. |
| 283 | |
| 284 | @vindex find-file-hooks |
| 285 | @vindex find-file-not-found-hooks |
| 286 | Two special hook variables allow extensions to modify the operation of |
| 287 | visiting files. Visiting a file that does not exist runs the functions |
| 288 | in the list @code{find-file-not-found-hooks}; this variable holds a list |
| 289 | of functions, and the functions are called one by one (with no |
| 290 | arguments) until one of them returns non-@code{nil}. This is not a |
| 291 | normal hook, and the name ends in @samp{-hooks} rather than @samp{-hook} |
| 292 | to indicate that fact. |
| 293 | |
| 294 | Any visiting of a file, whether extant or not, expects |
| 295 | @code{find-file-hooks} to contain a list of functions, and calls them |
| 296 | all, one by one, with no arguments. This variable is really a normal |
| 297 | hook, but it has an abnormal name for historical compatibility. In the |
| 298 | case of a nonexistent file, the @code{find-file-not-found-hooks} are run |
| 299 | first. @xref{Hooks}. |
| 300 | |
| 301 | There are several ways to specify automatically the major mode for |
| 302 | editing the file (@pxref{Choosing Modes}), and to specify local |
| 303 | variables defined for that file (@pxref{File Variables}). |
| 304 | |
| 305 | @node Saving |
| 306 | @section Saving Files |
| 307 | |
| 308 | @dfn{Saving} a buffer in Emacs means writing its contents back into the file |
| 309 | that was visited in the buffer. |
| 310 | |
| 311 | @table @kbd |
| 312 | @item C-x C-s |
| 313 | Save the current buffer in its visited file (@code{save-buffer}). |
| 314 | @item C-x s |
| 315 | Save any or all buffers in their visited files (@code{save-some-buffers}). |
| 316 | @item M-~ |
| 317 | Forget that the current buffer has been changed (@code{not-modified}). |
| 318 | @item C-x C-w |
| 319 | Save the current buffer in a specified file (@code{write-file}). |
| 320 | @item M-x set-visited-file-name |
| 321 | Change file the name under which the current buffer will be saved. |
| 322 | @end table |
| 323 | |
| 324 | @kindex C-x C-s |
| 325 | @findex save-buffer |
| 326 | When you wish to save the file and make your changes permanent, type |
| 327 | @kbd{C-x C-s} (@code{save-buffer}). After saving is finished, @kbd{C-x C-s} |
| 328 | displays a message like this: |
| 329 | |
| 330 | @example |
| 331 | Wrote /u/rms/gnu/gnu.tasks |
| 332 | @end example |
| 333 | |
| 334 | @noindent |
| 335 | If the selected buffer is not modified (no changes have been made in it |
| 336 | since the buffer was created or last saved), saving is not really done, |
| 337 | because it would have no effect. Instead, @kbd{C-x C-s} displays a message |
| 338 | like this in the echo area: |
| 339 | |
| 340 | @example |
| 341 | (No changes need to be saved) |
| 342 | @end example |
| 343 | |
| 344 | @kindex C-x s |
| 345 | @findex save-some-buffers |
| 346 | The command @kbd{C-x s} (@code{save-some-buffers}) offers to save any |
| 347 | or all modified buffers. It asks you what to do with each buffer. The |
| 348 | possible responses are analogous to those of @code{query-replace}: |
| 349 | |
| 350 | @table @kbd |
| 351 | @item y |
| 352 | Save this buffer and ask about the rest of the buffers. |
| 353 | @item n |
| 354 | Don't save this buffer, but ask about the rest of the buffers. |
| 355 | @item ! |
| 356 | Save this buffer and all the rest with no more questions. |
| 357 | @c following generates acceptable underfull hbox |
| 358 | @item @key{RET} |
| 359 | Terminate @code{save-some-buffers} without any more saving. |
| 360 | @item . |
| 361 | Save this buffer, then exit @code{save-some-buffers} without even asking |
| 362 | about other buffers. |
| 363 | @item C-r |
| 364 | View the buffer that you are currently being asked about. When you exit |
| 365 | View mode, you get back to @code{save-some-buffers}, which asks the |
| 366 | question again. |
| 367 | @item C-h |
| 368 | Display a help message about these options. |
| 369 | @end table |
| 370 | |
| 371 | @kbd{C-x C-c}, the key sequence to exit Emacs, invokes |
| 372 | @code{save-some-buffers} and therefore asks the same questions. |
| 373 | |
| 374 | @kindex M-~ |
| 375 | @findex not-modified |
| 376 | If you have changed a buffer but you do not want to save the changes, |
| 377 | you should take some action to prevent it. Otherwise, each time you use |
| 378 | @kbd{C-x s} or @kbd{C-x C-c}, you are liable to save this buffer by |
| 379 | mistake. One thing you can do is type @kbd{M-~} (@code{not-modified}), |
| 380 | which clears out the indication that the buffer is modified. If you do |
| 381 | this, none of the save commands will believe that the buffer needs to be |
| 382 | saved. (@samp{~} is often used as a mathematical symbol for `not'; thus |
| 383 | @kbd{M-~} is `not', metafied.) You could also use |
| 384 | @code{set-visited-file-name} (see below) to mark the buffer as visiting |
| 385 | a different file name, one which is not in use for anything important. |
| 386 | Alternatively, you can cancel all the changes made since the file was |
| 387 | visited or saved, by reading the text from the file again. This is |
| 388 | called @dfn{reverting}. @xref{Reverting}. You could also undo all the |
| 389 | changes by repeating the undo command @kbd{C-x u} until you have undone |
| 390 | all the changes; but reverting is easier. |
| 391 | |
| 392 | @findex set-visited-file-name |
| 393 | @kbd{M-x set-visited-file-name} alters the name of the file that the |
| 394 | current buffer is visiting. It reads the new file name using the |
| 395 | minibuffer. Then it specifies the visited file name and changes the |
| 396 | buffer name correspondingly (as long as the new name is not in use). |
| 397 | @code{set-visited-file-name} does not save the buffer in the newly |
| 398 | visited file; it just alters the records inside Emacs in case you do |
| 399 | save later. It also marks the buffer as ``modified'' so that @kbd{C-x |
| 400 | C-s} in that buffer @emph{will} save. |
| 401 | |
| 402 | @kindex C-x C-w |
| 403 | @findex write-file |
| 404 | If you wish to mark the buffer as visiting a different file and save it |
| 405 | right away, use @kbd{C-x C-w} (@code{write-file}). It is precisely |
| 406 | equivalent to @code{set-visited-file-name} followed by @kbd{C-x C-s}. |
| 407 | @kbd{C-x C-s} used on a buffer that is not visiting a file has the |
| 408 | same effect as @kbd{C-x C-w}; that is, it reads a file name, marks the |
| 409 | buffer as visiting that file, and saves it there. The default file name in |
| 410 | a buffer that is not visiting a file is made by combining the buffer name |
| 411 | with the buffer's default directory. |
| 412 | |
| 413 | If the new file name implies a major mode, then @kbd{C-x C-w} switches |
| 414 | to that major mode, in most cases. The command |
| 415 | @code{set-visited-file-name} also does this. @xref{Choosing Modes}. |
| 416 | |
| 417 | If Emacs is about to save a file and sees that the date of the latest |
| 418 | version on disk does not match what Emacs last read or wrote, Emacs |
| 419 | notifies you of this fact, because it probably indicates a problem caused |
| 420 | by simultaneous editing and requires your immediate attention. |
| 421 | @xref{Interlocking,, Simultaneous Editing}. |
| 422 | |
| 423 | @vindex require-final-newline |
| 424 | If the variable @code{require-final-newline} is non-@code{nil}, Emacs |
| 425 | puts a newline at the end of any file that doesn't already end in one, |
| 426 | every time a file is saved or written. The default is @code{nil}. |
| 427 | |
| 428 | @menu |
| 429 | * Backup:: How Emacs saves the old version of your file. |
| 430 | * Interlocking:: How Emacs protects against simultaneous editing |
| 431 | of one file by two users. |
| 432 | @end menu |
| 433 | |
| 434 | @node Backup |
| 435 | @subsection Backup Files |
| 436 | @cindex backup file |
| 437 | @vindex make-backup-files |
| 438 | @vindex vc-make-backup-files |
| 439 | @vindex backup-enable-predicate |
| 440 | |
| 441 | On most operating systems, rewriting a file automatically destroys all |
| 442 | record of what the file used to contain. Thus, saving a file from Emacs |
| 443 | throws away the old contents of the file---or it would, except that |
| 444 | Emacs carefully copies the old contents to another file, called the |
| 445 | @dfn{backup} file, before actually saving. |
| 446 | |
| 447 | For most files, the variable @code{make-backup-files} determines |
| 448 | whether to make backup files. On most operating systems, its default |
| 449 | value is @code{t}, so that Emacs does write backup files. |
| 450 | |
| 451 | For files managed by a version control system (@pxref{Version |
| 452 | Control}), the variable @code{vc-make-backup-files} determines whether |
| 453 | to make backup files. By default, it is @code{nil}, since backup files |
| 454 | are redundant when you store all the previous versions in a version |
| 455 | control system. @xref{VC Workfile Handling}. |
| 456 | |
| 457 | The default value of the @code{backup-enable-predicate} variable |
| 458 | prevents backup files being written for files in @file{/tmp}. |
| 459 | |
| 460 | At your option, Emacs can keep either a single backup file or a series of |
| 461 | numbered backup files for each file that you edit. |
| 462 | |
| 463 | Emacs makes a backup for a file only the first time the file is saved |
| 464 | from one buffer. No matter how many times you save a file, its backup file |
| 465 | continues to contain the contents from before the file was visited. |
| 466 | Normally this means that the backup file contains the contents from before |
| 467 | the current editing session; however, if you kill the buffer and then visit |
| 468 | the file again, a new backup file will be made by the next save. |
| 469 | |
| 470 | You can also explicitly request making another backup file from a |
| 471 | buffer even though it has already been saved at least once. If you save |
| 472 | the buffer with @kbd{C-u C-x C-s}, the version thus saved will be made |
| 473 | into a backup file if you save the buffer again. @kbd{C-u C-u C-x C-s} |
| 474 | saves the buffer, but first makes the previous file contents into a new |
| 475 | backup file. @kbd{C-u C-u C-u C-x C-s} does both things: it makes a |
| 476 | backup from the previous contents, and arranges to make another from the |
| 477 | newly saved contents, if you save again. |
| 478 | |
| 479 | @menu |
| 480 | * Names: Backup Names. How backup files are named; |
| 481 | choosing single or numbered backup files. |
| 482 | * Deletion: Backup Deletion. Emacs deletes excess numbered backups. |
| 483 | * Copying: Backup Copying. Backups can be made by copying or renaming. |
| 484 | @end menu |
| 485 | |
| 486 | @node Backup Names |
| 487 | @subsubsection Single or Numbered Backups |
| 488 | |
| 489 | If you choose to have a single backup file (this is the default), |
| 490 | the backup file's name is constructed by appending @samp{~} to the |
| 491 | file name being edited; thus, the backup file for @file{eval.c} would |
| 492 | be @file{eval.c~}. |
| 493 | |
| 494 | If you choose to have a series of numbered backup files, backup file |
| 495 | names are made by appending @samp{.~}, the number, and another @samp{~} to |
| 496 | the original file name. Thus, the backup files of @file{eval.c} would be |
| 497 | called @file{eval.c.~1~}, @file{eval.c.~2~}, and so on, through names |
| 498 | like @file{eval.c.~259~} and beyond. |
| 499 | |
| 500 | If protection stops you from writing backup files under the usual names, |
| 501 | the backup file is written as @file{%backup%~} in your home directory. |
| 502 | Only one such file can exist, so only the most recently made such backup is |
| 503 | available. |
| 504 | |
| 505 | @vindex version-control |
| 506 | The choice of single backup or numbered backups is controlled by the |
| 507 | variable @code{version-control}. Its possible values are |
| 508 | |
| 509 | @table @code |
| 510 | @item t |
| 511 | Make numbered backups. |
| 512 | @item nil |
| 513 | Make numbered backups for files that have numbered backups already. |
| 514 | Otherwise, make single backups. |
| 515 | @item never |
| 516 | Do not in any case make numbered backups; always make single backups. |
| 517 | @end table |
| 518 | |
| 519 | @noindent |
| 520 | You can set @code{version-control} locally in an individual buffer to |
| 521 | control the making of backups for that buffer's file. For example, |
| 522 | Rmail mode locally sets @code{version-control} to @code{never} to make sure |
| 523 | that there is only one backup for an Rmail file. @xref{Locals}. |
| 524 | |
| 525 | @cindex @code{VERSION_CONTROL} environment variable |
| 526 | If you set the environment variable @code{VERSION_CONTROL}, to tell |
| 527 | various GNU utilities what to do with backup files, Emacs also obeys the |
| 528 | environment variable by setting the Lisp variable @code{version-control} |
| 529 | accordingly at startup. If the environment variable's value is @samp{t} |
| 530 | or @samp{numbered}, then @code{version-control} becomes @code{t}; if the |
| 531 | value is @samp{nil} or @samp{existing}, then @code{version-control} |
| 532 | becomes @code{nil}; if it is @samp{never} or @samp{simple}, then |
| 533 | @code{version-control} becomes @code{never}. |
| 534 | |
| 535 | @node Backup Deletion |
| 536 | @subsubsection Automatic Deletion of Backups |
| 537 | |
| 538 | To prevent unlimited consumption of disk space, Emacs can delete numbered |
| 539 | backup versions automatically. Generally Emacs keeps the first few backups |
| 540 | and the latest few backups, deleting any in between. This happens every |
| 541 | time a new backup is made. |
| 542 | |
| 543 | @vindex kept-old-versions |
| 544 | @vindex kept-new-versions |
| 545 | The two variables @code{kept-old-versions} and |
| 546 | @code{kept-new-versions} control this deletion. Their values are, |
| 547 | respectively the number of oldest (lowest-numbered) backups to keep and |
| 548 | the number of newest (highest-numbered) ones to keep, each time a new |
| 549 | backup is made. Recall that these values are used just after a new |
| 550 | backup version is made; that newly made backup is included in the count |
| 551 | in @code{kept-new-versions}. By default, both variables are 2. |
| 552 | |
| 553 | @vindex delete-old-versions |
| 554 | If @code{delete-old-versions} is non-@code{nil}, the excess |
| 555 | middle versions are deleted without a murmur. If it is @code{nil}, the |
| 556 | default, then you are asked whether the excess middle versions should |
| 557 | really be deleted. |
| 558 | |
| 559 | Dired's @kbd{.} (Period) command can also be used to delete old versions. |
| 560 | @xref{Dired Deletion}. |
| 561 | |
| 562 | @node Backup Copying |
| 563 | @subsubsection Copying vs.@: Renaming |
| 564 | |
| 565 | Backup files can be made by copying the old file or by renaming it. This |
| 566 | makes a difference when the old file has multiple names. If the old file |
| 567 | is renamed into the backup file, then the alternate names become names for |
| 568 | the backup file. If the old file is copied instead, then the alternate |
| 569 | names remain names for the file that you are editing, and the contents |
| 570 | accessed by those names will be the new contents. |
| 571 | |
| 572 | The method of making a backup file may also affect the file's owner |
| 573 | and group. If copying is used, these do not change. If renaming is used, |
| 574 | you become the file's owner, and the file's group becomes the default |
| 575 | (different operating systems have different defaults for the group). |
| 576 | |
| 577 | Having the owner change is usually a good idea, because then the owner |
| 578 | always shows who last edited the file. Also, the owners of the backups |
| 579 | show who produced those versions. Occasionally there is a file whose |
| 580 | owner should not change; it is a good idea for such files to contain |
| 581 | local variable lists to set @code{backup-by-copying-when-mismatch} |
| 582 | locally (@pxref{File Variables}). |
| 583 | |
| 584 | @vindex backup-by-copying |
| 585 | @vindex backup-by-copying-when-linked |
| 586 | @vindex backup-by-copying-when-mismatch |
| 587 | The choice of renaming or copying is controlled by three variables. |
| 588 | Renaming is the default choice. If the variable |
| 589 | @code{backup-by-copying} is non-@code{nil}, copying is used. Otherwise, |
| 590 | if the variable @code{backup-by-copying-when-linked} is non-@code{nil}, |
| 591 | then copying is used for files that have multiple names, but renaming |
| 592 | may still be used when the file being edited has only one name. If the |
| 593 | variable @code{backup-by-copying-when-mismatch} is non-@code{nil}, then |
| 594 | copying is used if renaming would cause the file's owner or group to |
| 595 | change. @code{backup-by-copying-when-mismatch} is @code{t} by default |
| 596 | if you start Emacs as the superuser. |
| 597 | |
| 598 | When a file is managed with a version control system (@pxref{Version |
| 599 | Control}), Emacs does not normally make backups in the usual way for |
| 600 | that file. But check-in and check-out are similar in some ways to |
| 601 | making backups. One unfortunate similarity is that these operations |
| 602 | typically break hard links, disconnecting the file name you visited from |
| 603 | any alternate names for the same file. This has nothing to do with |
| 604 | Emacs---the version control system does it. |
| 605 | |
| 606 | @node Interlocking |
| 607 | @subsection Protection against Simultaneous Editing |
| 608 | |
| 609 | @cindex file dates |
| 610 | @cindex simultaneous editing |
| 611 | Simultaneous editing occurs when two users visit the same file, both |
| 612 | make changes, and then both save them. If nobody were informed that |
| 613 | this was happening, whichever user saved first would later find that his |
| 614 | changes were lost. |
| 615 | |
| 616 | On some systems, Emacs notices immediately when the second user starts |
| 617 | to change the file, and issues an immediate warning. On all systems, |
| 618 | Emacs checks when you save the file, and warns if you are about to |
| 619 | overwrite another user's changes. You can prevent loss of the other |
| 620 | user's work by taking the proper corrective action instead of saving the |
| 621 | file. |
| 622 | |
| 623 | @findex ask-user-about-lock |
| 624 | @cindex locking files |
| 625 | When you make the first modification in an Emacs buffer that is |
| 626 | visiting a file, Emacs records that the file is @dfn{locked} by you. |
| 627 | (It does this by creating a symbolic link in the same directory with a |
| 628 | different name.) Emacs removes the lock when you save the changes. The |
| 629 | idea is that the file is locked whenever an Emacs buffer visiting it has |
| 630 | unsaved changes. |
| 631 | |
| 632 | @cindex collision |
| 633 | If you begin to modify the buffer while the visited file is locked by |
| 634 | someone else, this constitutes a @dfn{collision}. When Emacs detects a |
| 635 | collision, it asks you what to do, by calling the Lisp function |
| 636 | @code{ask-user-about-lock}. You can redefine this function for the sake |
| 637 | of customization. The standard definition of this function asks you a |
| 638 | question and accepts three possible answers: |
| 639 | |
| 640 | @table @kbd |
| 641 | @item s |
| 642 | Steal the lock. Whoever was already changing the file loses the lock, |
| 643 | and you gain the lock. |
| 644 | @item p |
| 645 | Proceed. Go ahead and edit the file despite its being locked by someone else. |
| 646 | @item q |
| 647 | Quit. This causes an error (@code{file-locked}) and the modification you |
| 648 | were trying to make in the buffer does not actually take place. |
| 649 | @end table |
| 650 | |
| 651 | Note that locking works on the basis of a file name; if a file has |
| 652 | multiple names, Emacs does not realize that the two names are the same file |
| 653 | and cannot prevent two users from editing it simultaneously under different |
| 654 | names. However, basing locking on names means that Emacs can interlock the |
| 655 | editing of new files that will not really exist until they are saved. |
| 656 | |
| 657 | Some systems are not configured to allow Emacs to make locks, and |
| 658 | there are cases where lock files cannot be written. In these cases, |
| 659 | Emacs cannot detect trouble in advance, but it still can detect the |
| 660 | collision when you try to save a file and overwrite someone else's |
| 661 | changes. |
| 662 | |
| 663 | If Emacs or the operating system crashes, this may leave behind lock |
| 664 | files which are stale. So you may occasionally get warnings about |
| 665 | spurious collisions. When you determine that the collision is spurious, |
| 666 | just use @kbd{p} to tell Emacs to go ahead anyway. |
| 667 | |
| 668 | Every time Emacs saves a buffer, it first checks the last-modification |
| 669 | date of the existing file on disk to verify that it has not changed since the |
| 670 | file was last visited or saved. If the date does not match, it implies |
| 671 | that changes were made in the file in some other way, and these changes are |
| 672 | about to be lost if Emacs actually does save. To prevent this, Emacs |
| 673 | prints a warning message and asks for confirmation before saving. |
| 674 | Occasionally you will know why the file was changed and know that it does |
| 675 | not matter; then you can answer @kbd{yes} and proceed. Otherwise, you should |
| 676 | cancel the save with @kbd{C-g} and investigate the situation. |
| 677 | |
| 678 | The first thing you should do when notified that simultaneous editing |
| 679 | has already taken place is to list the directory with @kbd{C-u C-x C-d} |
| 680 | (@pxref{Directories}). This shows the file's current author. You |
| 681 | should attempt to contact him to warn him not to continue editing. |
| 682 | Often the next step is to save the contents of your Emacs buffer under a |
| 683 | different name, and use @code{diff} to compare the two files.@refill |
| 684 | |
| 685 | @node Reverting |
| 686 | @section Reverting a Buffer |
| 687 | @findex revert-buffer |
| 688 | @cindex drastic changes |
| 689 | |
| 690 | If you have made extensive changes to a file and then change your mind |
| 691 | about them, you can get rid of them by reading in the previous version |
| 692 | of the file. To do this, use @kbd{M-x revert-buffer}, which operates on |
| 693 | the current buffer. Since reverting a buffer unintentionally could lose |
| 694 | a lot of work, you must confirm this command with @kbd{yes}. |
| 695 | |
| 696 | @code{revert-buffer} keeps point at the same distance (measured in |
| 697 | characters) from the beginning of the file. If the file was edited only |
| 698 | slightly, you will be at approximately the same piece of text after |
| 699 | reverting as before. If you have made drastic changes, the same value of |
| 700 | point in the old file may address a totally different piece of text. |
| 701 | |
| 702 | Reverting marks the buffer as ``not modified'' until another change is |
| 703 | made. |
| 704 | |
| 705 | Some kinds of buffers whose contents reflect data bases other than files, |
| 706 | such as Dired buffers, can also be reverted. For them, reverting means |
| 707 | recalculating their contents from the appropriate data base. Buffers |
| 708 | created explicitly with @kbd{C-x b} cannot be reverted; @code{revert-buffer} |
| 709 | reports an error when asked to do so. |
| 710 | |
| 711 | @vindex revert-without-query |
| 712 | When you edit a file that changes automatically and frequently---for |
| 713 | example, a log of output from a process that continues to run---it may be |
| 714 | useful for Emacs to revert the file without querying you, whenever you |
| 715 | visit the file again with @kbd{C-x C-f}. |
| 716 | |
| 717 | To request this behavior, set the variable @code{revert-without-query} |
| 718 | to a list of regular expressions. When a file name matches one of these |
| 719 | regular expressions, @code{find-file} and @code{revert-buffer} will |
| 720 | revert it automatically if it has changed---provided the buffer itself |
| 721 | is not modified. (If you have edited the text, it would be wrong to |
| 722 | discard your changes.) |
| 723 | |
| 724 | @node Auto Save |
| 725 | @section Auto-Saving: Protection Against Disasters |
| 726 | @cindex Auto Save mode |
| 727 | @cindex mode, Auto Save |
| 728 | @cindex crashes |
| 729 | |
| 730 | Emacs saves all the visited files from time to time (based on counting |
| 731 | your keystrokes) without being asked. This is called @dfn{auto-saving}. |
| 732 | It prevents you from losing more than a limited amount of work if the |
| 733 | system crashes. |
| 734 | |
| 735 | When Emacs determines that it is time for auto-saving, each buffer is |
| 736 | considered, and is auto-saved if auto-saving is turned on for it and it |
| 737 | has been changed since the last time it was auto-saved. The message |
| 738 | @samp{Auto-saving...} is displayed in the echo area during auto-saving, |
| 739 | if any files are actually auto-saved. Errors occurring during |
| 740 | auto-saving are caught so that they do not interfere with the execution |
| 741 | of commands you have been typing. |
| 742 | |
| 743 | @menu |
| 744 | * Files: Auto Save Files. The file where auto-saved changes are |
| 745 | actually made until you save the file. |
| 746 | * Control: Auto Save Control. Controlling when and how often to auto-save. |
| 747 | * Recover:: Recovering text from auto-save files. |
| 748 | @end menu |
| 749 | |
| 750 | @node Auto Save Files |
| 751 | @subsection Auto-Save Files |
| 752 | |
| 753 | Auto-saving does not normally save in the files that you visited, because |
| 754 | it can be very undesirable to save a program that is in an inconsistent |
| 755 | state when you have made half of a planned change. Instead, auto-saving |
| 756 | is done in a different file called the @dfn{auto-save file}, and the |
| 757 | visited file is changed only when you request saving explicitly (such as |
| 758 | with @kbd{C-x C-s}). |
| 759 | |
| 760 | Normally, the auto-save file name is made by appending @samp{#} to the |
| 761 | front and rear of the visited file name. Thus, a buffer visiting file |
| 762 | @file{foo.c} is auto-saved in a file @file{#foo.c#}. Most buffers that |
| 763 | are not visiting files are auto-saved only if you request it explicitly; |
| 764 | when they are auto-saved, the auto-save file name is made by appending |
| 765 | @samp{#%} to the front and @samp{#} to the rear of buffer name. For |
| 766 | example, the @samp{*mail*} buffer in which you compose messages to be |
| 767 | sent is auto-saved in a file named @file{#%*mail*#}. Auto-save file |
| 768 | names are made this way unless you reprogram parts of Emacs to do |
| 769 | something different (the functions @code{make-auto-save-file-name} and |
| 770 | @code{auto-save-file-name-p}). The file name to be used for auto-saving |
| 771 | in a buffer is calculated when auto-saving is turned on in that buffer. |
| 772 | |
| 773 | When you delete a substantial part of the text in a large buffer, auto |
| 774 | save turns off temporarily in that buffer. This is because if you |
| 775 | deleted the text unintentionally, you might find the auto-save file more |
| 776 | useful if it contains the deleted text. To reenable auto-saving after |
| 777 | this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x |
| 778 | auto-save}. |
| 779 | |
| 780 | @vindex auto-save-visited-file-name |
| 781 | If you want auto-saving to be done in the visited file, set the variable |
| 782 | @code{auto-save-visited-file-name} to be non-@code{nil}. In this mode, |
| 783 | there is really no difference between auto-saving and explicit saving. |
| 784 | |
| 785 | @vindex delete-auto-save-files |
| 786 | A buffer's auto-save file is deleted when you save the buffer in its |
| 787 | visited file. To inhibit this, set the variable @code{delete-auto-save-files} |
| 788 | to @code{nil}. Changing the visited file name with @kbd{C-x C-w} or |
| 789 | @code{set-visited-file-name} renames any auto-save file to go with |
| 790 | the new visited name. |
| 791 | |
| 792 | @node Auto Save Control |
| 793 | @subsection Controlling Auto-Saving |
| 794 | |
| 795 | @vindex auto-save-default |
| 796 | @findex auto-save-mode |
| 797 | Each time you visit a file, auto-saving is turned on for that file's |
| 798 | buffer if the variable @code{auto-save-default} is non-@code{nil} (but not |
| 799 | in batch mode; @pxref{Entering Emacs}). The default for this variable is |
| 800 | @code{t}, so auto-saving is the usual practice for file-visiting buffers. |
| 801 | Auto-saving can be turned on or off for any existing buffer with the |
| 802 | command @kbd{M-x auto-save-mode}. Like other minor mode commands, @kbd{M-x |
| 803 | auto-save-mode} turns auto-saving on with a positive argument, off with a |
| 804 | zero or negative argument; with no argument, it toggles. |
| 805 | |
| 806 | @vindex auto-save-interval |
| 807 | Emacs does auto-saving periodically based on counting how many characters |
| 808 | you have typed since the last time auto-saving was done. The variable |
| 809 | @code{auto-save-interval} specifies how many characters there are between |
| 810 | auto-saves. By default, it is 300. |
| 811 | |
| 812 | @vindex auto-save-timeout |
| 813 | Auto-saving also takes place when you stop typing for a while. The |
| 814 | variable @code{auto-save-timeout} says how many seconds Emacs should |
| 815 | wait before it does an auto save (and perhaps also a garbage |
| 816 | collection). (The actual time period is longer if the current buffer is |
| 817 | long; this is a heuristic which aims to keep out of your way when you |
| 818 | are editing long buffers, in which auto-save takes an appreciable amount |
| 819 | of time.) Auto-saving during idle periods accomplishes two things: |
| 820 | first, it makes sure all your work is saved if you go away from the |
| 821 | terminal for a while; second, it may avoid some auto-saving while you |
| 822 | are actually typing. |
| 823 | |
| 824 | Emacs also does auto-saving whenever it gets a fatal error. This |
| 825 | includes killing the Emacs job with a shell command such as @samp{kill |
| 826 | %emacs}, or disconnecting a phone line or network connection. |
| 827 | |
| 828 | @findex do-auto-save |
| 829 | You can request an auto-save explicitly with the command @kbd{M-x |
| 830 | do-auto-save}. |
| 831 | |
| 832 | @node Recover |
| 833 | @subsection Recovering Data from Auto-Saves |
| 834 | |
| 835 | @findex recover-file |
| 836 | You can use the contents of an auto-save file to recover from a loss |
| 837 | of data with the command @kbd{M-x recover-file @key{RET} @var{file} |
| 838 | @key{RET}}. This visits @var{file} and then (after your confirmation) |
| 839 | restores the contents from its auto-save file @file{#@var{file}#}. |
| 840 | You can then save with @kbd{C-x C-s} to put the recovered text into |
| 841 | @var{file} itself. For example, to recover file @file{foo.c} from its |
| 842 | auto-save file @file{#foo.c#}, do:@refill |
| 843 | |
| 844 | @example |
| 845 | M-x recover-file @key{RET} foo.c @key{RET} |
| 846 | yes @key{RET} |
| 847 | C-x C-s |
| 848 | @end example |
| 849 | |
| 850 | Before asking for confirmation, @kbd{M-x recover-file} displays a |
| 851 | directory listing describing the specified file and the auto-save file, |
| 852 | so you can compare their sizes and dates. If the auto-save file |
| 853 | is older, @kbd{M-x recover-file} does not offer to read it. |
| 854 | |
| 855 | @findex recover-session |
| 856 | If Emacs or the computer crashes, you can recover all the files you |
| 857 | were editing from their auto save files with the command @kbd{M-x |
| 858 | recover-session}. This first shows you a list of recorded interrupted |
| 859 | sessions. Move point to the one you choose, and type @kbd{C-c C-c}. |
| 860 | |
| 861 | Then @code{recover-session} asks about each of the files that were |
| 862 | being edited during that session, asking whether to recover that file. |
| 863 | If you answer @kbd{y}, it calls @code{recover-file}, which works in its |
| 864 | normal fashion. It shows the dates of the original file and its |
| 865 | auto-save file, and asks once again whether to recover that file. |
| 866 | |
| 867 | When @code{recover-session} is done, the files you've chosen to |
| 868 | recover are present in Emacs buffers. You should then save them. Only |
| 869 | this---saving them---updates the files themselves. |
| 870 | |
| 871 | @vindex auto-save-list-file-prefix |
| 872 | Interrupted sessions are recorded for later recovery in files named |
| 873 | @file{~/.saves-@var{pid}-@var{hostname}}. The @samp{~/.saves} portion of |
| 874 | these names comes from the value of @code{auto-save-list-file-prefix}. |
| 875 | You can arrange to record sessions in a different place by setting that |
| 876 | variable in your @file{.emacs} file, but you'll have to redefine |
| 877 | @code{recover-session} as well to make it look in the new place. If you |
| 878 | set @code{auto-save-list-file-prefix} to @code{nil} in your |
| 879 | @file{.emacs} file, sessions are not recorded for recovery. |
| 880 | |
| 881 | @node File Aliases |
| 882 | @section File Name Aliases |
| 883 | |
| 884 | Symbolic links and hard links both make it possible for several file |
| 885 | names to refer to the same file. Hard links are alternate names that |
| 886 | refer directly to the file; all the names are equally valid, and no one |
| 887 | of them is preferred. By contrast, a symbolic link is a kind of defined |
| 888 | alias: when @file{foo} is a symbolic link to @file{bar}, you can use |
| 889 | either name to refer to the file, but @file{bar} is the real name, while |
| 890 | @file{foo} is just an alias. More complex cases occur when symbolic |
| 891 | links point to directories. |
| 892 | |
| 893 | If you visit two names for the same file, normally Emacs makes |
| 894 | two different buffers, but it warns you about the situation. |
| 895 | |
| 896 | @vindex find-file-existing-other-name |
| 897 | If you wish to avoid visiting the same file in two buffers under |
| 898 | different names, set the variable @code{find-file-existing-other-name} |
| 899 | to a non-@code{nil} value. Then @code{find-file} uses the existing |
| 900 | buffer visiting the file, no matter which of the file's names you |
| 901 | specify. |
| 902 | |
| 903 | @vindex find-file-visit-truename |
| 904 | @cindex truenames of files |
| 905 | @cindex file truenames |
| 906 | If the variable @code{find-file-visit-truename} is non-@code{nil}, |
| 907 | then the file name recorded for a buffer is the file's @dfn{truename} |
| 908 | (made by replacing all symbolic links with their target names), rather |
| 909 | than the name you specify. Setting @code{find-file-visit-truename} also |
| 910 | implies the effect of @code{find-file-existing-other-name}. |
| 911 | |
| 912 | @node Version Control |
| 913 | @section Version Control |
| 914 | @cindex version control |
| 915 | |
| 916 | @dfn{Version control systems} are packages that can record multiple |
| 917 | versions of a source file, usually storing the unchanged parts of the |
| 918 | file just once. Version control systems also record history information |
| 919 | such as the creation time of each version, who created it, and a |
| 920 | description of what was changed in that version. |
| 921 | |
| 922 | The Emacs version control interface is called VC. Its commands work |
| 923 | with three version control systems---RCS, CVS and SCCS. The GNU project |
| 924 | recommends RCS and CVS, which are free software and available from the |
| 925 | Free Software Foundation. |
| 926 | |
| 927 | @menu |
| 928 | * Introduction to VC:: How version control works in general. |
| 929 | * VC Mode Line:: How the mode line shows version control status. |
| 930 | * Basic VC Editing:: How to edit a file under version control. |
| 931 | * Old Versions:: Examining and comparing old versions. |
| 932 | * Secondary VC Commands:: The commands used a little less frequently. |
| 933 | * Branches:: Multiple lines of development. |
| 934 | * Snapshots:: Sets of file versions treated as a unit. |
| 935 | * Miscellaneous VC:: Various other commands and features of VC. |
| 936 | * Customizing VC:: Variables that change VC's behavior. |
| 937 | @end menu |
| 938 | |
| 939 | @node Introduction to VC |
| 940 | @subsection Introduction to Version Control |
| 941 | |
| 942 | VC allows you to use a version control system from within Emacs, |
| 943 | integrating the version control operations smoothly with editing. VC |
| 944 | provides a uniform interface to version control, so that regardless of |
| 945 | which version control system is in use, you can use it the same way. |
| 946 | |
| 947 | This section provides a general overview of version control, and |
| 948 | describes the version control systems that VC supports. You can skip |
| 949 | this section if you are already familiar with the version control system |
| 950 | you want to use. |
| 951 | |
| 952 | @menu |
| 953 | * Version Systems:: Supported version control back-end systems. |
| 954 | * VC Concepts:: Words and concepts related to version control. |
| 955 | @end menu |
| 956 | |
| 957 | @node Version Systems |
| 958 | @subsubsection Supported Version Control Systems |
| 959 | |
| 960 | @cindex RCS |
| 961 | @cindex back end (version control) |
| 962 | VC currently works with three different version control systems or |
| 963 | ``back ends'': RCS, CVS, and SCCS. |
| 964 | |
| 965 | RCS is a free version control system that is available from the Free |
| 966 | Software Foundation. It is perhaps the most mature of the supported |
| 967 | back ends, and the VC commands are conceptually closest to RCS. Almost |
| 968 | everything you can do with RCS can be done through VC. |
| 969 | |
| 970 | @cindex CVS |
| 971 | CVS is built on top of RCS, and extends the features of RCS, allowing |
| 972 | for more sophisticated release management, and concurrent multi-user |
| 973 | development. VC supports basic editing operations under CVS, but for |
| 974 | some less common tasks you still need to call CVS from the command line. |
| 975 | Note also that before using CVS you must set up a repository, which is a |
| 976 | subject too complex to treat here. |
| 977 | |
| 978 | @cindex SCCS |
| 979 | SCCS is a proprietary but widely used version control system. In |
| 980 | terms of capabilities, it is the weakest of the three that VC |
| 981 | supports. VC compensates for certain features missing in SCCS |
| 982 | (snapshots, for example) by implementing them itself, but some other VC |
| 983 | features, such as multiple branches, are not available with SCCS. You |
| 984 | should use SCCS only if for some reason you cannot use RCS. |
| 985 | |
| 986 | @node VC Concepts |
| 987 | @subsubsection Concepts of Version Control |
| 988 | |
| 989 | @cindex master file |
| 990 | @cindex registered file |
| 991 | When a file is under version control, we also say that it is |
| 992 | @dfn{registered} in the version control system. Each registered file |
| 993 | has a corresponding @dfn{master file} which represents the file's |
| 994 | present state plus its change history---enough to reconstruct the |
| 995 | current version or any earlier version. Usually the master file also |
| 996 | records a @dfn{log entry} for each version, describing in words what was |
| 997 | changed in that version. |
| 998 | |
| 999 | @cindex work file |
| 1000 | @cindex checking out files |
| 1001 | The file that is maintained under version control is sometimes called |
| 1002 | the @dfn{work file} corresponding to its master file. You edit the work |
| 1003 | file and make changes in it, as you would with an ordinary file. (With |
| 1004 | SCCS and RCS, you must @dfn{lock} the file before you start to edit it.) |
| 1005 | After you are done with a set of changes, you @dfn{check the file in}, |
| 1006 | which records the changes in the master file, along with a log entry for |
| 1007 | them. |
| 1008 | |
| 1009 | With CVS, there are usually multiple work files corresponding to a |
| 1010 | single master file---often each user has his own copy. It is also |
| 1011 | possible to use RCS in this way, but this is not the usual way to use |
| 1012 | RCS. |
| 1013 | |
| 1014 | @cindex locking and version control |
| 1015 | A version control system typically has some mechanism to coordinate |
| 1016 | between users who want to change the same file. One method is |
| 1017 | @dfn{locking} (analogous to the locking that Emacs uses to detect |
| 1018 | simultaneous editing of a file, but distinct from it). The other method |
| 1019 | is to merge your changes with other people's changes when you check them |
| 1020 | in. |
| 1021 | |
| 1022 | With version control locking, work files are normally read-only so |
| 1023 | that you cannot change them. You ask the version control system to make |
| 1024 | a work file writable for you by locking it; only one user can do |
| 1025 | this at any given time. When you check in your changes, that unlocks |
| 1026 | the file, making the work file read-only again. This allows other users |
| 1027 | to lock the file to make further changes. SCCS always uses locking, and |
| 1028 | RCS normally does. |
| 1029 | |
| 1030 | The other alternative for RCS is to let each user modify the work file |
| 1031 | at any time. In this mode, locking is not required, but it is |
| 1032 | permitted; check-in is still the way to record a new version. |
| 1033 | |
| 1034 | CVS normally allows each user to modify his own copy of the work file |
| 1035 | at any time, but requires merging with changes from other users at |
| 1036 | check-in time. However, CVS can also be set up to require locking. |
| 1037 | (@pxref{Backend Options}). |
| 1038 | |
| 1039 | @node VC Mode Line |
| 1040 | @subsection Version Control and the Mode Line |
| 1041 | |
| 1042 | When you visit a file that is under version control, Emacs indicates |
| 1043 | this on the mode line. For example, @samp{RCS-1.3} says that RCS is |
| 1044 | used for that file, and the current version is 1.3. |
| 1045 | |
| 1046 | The character between the back-end name and the version number |
| 1047 | indicates the version control status of the file. @samp{-} means that |
| 1048 | the work file is not locked (if locking is in use), or not modified (if |
| 1049 | locking is not in use). @samp{:} indicates that the file is locked, or |
| 1050 | that it is modified. If the file is locked by some other user (for |
| 1051 | instance, @samp{jim}), that is displayed as @samp{RCS:jim:1.3}. |
| 1052 | |
| 1053 | @node Basic VC Editing |
| 1054 | @subsection Basic Editing under Version Control |
| 1055 | |
| 1056 | The principal VC command is an all-purpose command that performs |
| 1057 | either locking or check-in, depending on the situation. |
| 1058 | |
| 1059 | @table @kbd |
| 1060 | @item C-x C-q |
| 1061 | @itemx C-x v v |
| 1062 | Perform the next logical version control operation on this file. |
| 1063 | @end table |
| 1064 | |
| 1065 | @findex vc-next-action |
| 1066 | @findex vc-toggle-read-only |
| 1067 | @kindex C-x v v |
| 1068 | @kindex C-x C-q @r{(Version Control)} |
| 1069 | Strictly speaking, the command for this job is @code{vc-next-action}, |
| 1070 | bound to @kbd{C-x v v}. However, the normal meaning of @kbd{C-x C-q} is |
| 1071 | to make a read-only buffer writable, or vice versa; we have extended it |
| 1072 | to do the same job properly for files managed by version control, by |
| 1073 | performing the appropriate version control operations. When you type |
| 1074 | @kbd{C-x C-q} on a registered file, it acts like @kbd{C-x v v}. |
| 1075 | |
| 1076 | The precise action of this command depends on the state of the file, |
| 1077 | and whether the version control system uses locking or not. SCCS and |
| 1078 | RCS normally use locking; CVS normally does not use locking. |
| 1079 | |
| 1080 | @menu |
| 1081 | * VC with Locking:: RCS in its default mode, SCCS, and optionally CVS. |
| 1082 | * Without Locking:: Without locking: default mode for CVS. |
| 1083 | * Log Buffer:: Features available in log entry buffers. |
| 1084 | @end menu |
| 1085 | |
| 1086 | @node VC with Locking |
| 1087 | @subsubsection Basic Version Control with Locking |
| 1088 | |
| 1089 | If locking is used for the file (as with SCCS, and RCS in its default |
| 1090 | mode), @kbd{C-x C-q} can either lock a file or check it in: |
| 1091 | |
| 1092 | @itemize @bullet |
| 1093 | @item |
| 1094 | If the file is not locked, @kbd{C-x C-q} locks it, and |
| 1095 | makes it writable so that you can change it. |
| 1096 | |
| 1097 | @item |
| 1098 | If the file is locked by you, and contains changes, @kbd{C-x C-q} checks |
| 1099 | in the changes. In order to do this, it first reads the log entry |
| 1100 | for the new version. @xref{Log Buffer}. |
| 1101 | |
| 1102 | @item |
| 1103 | If the file is locked by you, but you have not changed it since you |
| 1104 | locked it, @kbd{C-x C-q} releases the lock and makes the file read-only |
| 1105 | again. |
| 1106 | |
| 1107 | @item |
| 1108 | If the file is locked by some other user, @kbd{C-x C-q} asks you whether |
| 1109 | you want to ``steal the lock'' from that user. If you say yes, the file |
| 1110 | becomes locked by you, but a message is sent to the person who had |
| 1111 | formerly locked the file, to inform him of what has happened. |
| 1112 | @end itemize |
| 1113 | |
| 1114 | These rules also apply when you use CVS in locking mode, except |
| 1115 | that there is no such thing as stealing a lock. |
| 1116 | |
| 1117 | @node Without Locking |
| 1118 | @subsubsection Basic Version Control without Locking |
| 1119 | |
| 1120 | When there is no locking---the default for CVS---work files are always |
| 1121 | writable; you do not need to do anything before you begin to edit a |
| 1122 | file. The status indicator on the mode line is @samp{-} if the file is |
| 1123 | unmodified; it flips to @samp{:} as soon as you save any changes in the |
| 1124 | work file. |
| 1125 | |
| 1126 | Here is what @kbd{C-x C-q} does when using CVS: |
| 1127 | |
| 1128 | @itemize @bullet |
| 1129 | @item |
| 1130 | If some other user has checked in changes into the master file, |
| 1131 | Emacs asks you whether you want to merge those changes into your own |
| 1132 | work file (@pxref{Merging}). You must do this before you can check in |
| 1133 | your own changes. |
| 1134 | |
| 1135 | @item |
| 1136 | If there are no new changes in the master file, but you have made |
| 1137 | modifications in your work file, @kbd{C-x C-q} checks in your changes. |
| 1138 | In order to do this, it first reads the log entry for the new version. |
| 1139 | @xref{Log Buffer}. |
| 1140 | |
| 1141 | @item |
| 1142 | If the file is not modified, the @kbd{C-x C-q} does nothing. |
| 1143 | @end itemize |
| 1144 | |
| 1145 | These rules also apply when you use RCS in the mode that does not |
| 1146 | require locking, except that automatic merging of changes from the |
| 1147 | master file is not implemented. Unfortunately, this means that nothing |
| 1148 | informs you if another user has checked in changes in the same file |
| 1149 | since you began editing it, and when this happens, his changes will be |
| 1150 | effectively removed when you check in your version (though they will |
| 1151 | remain in the master file, so they will not be entirely lost). You must |
| 1152 | therefore verify the current version is unchanged, before you check in your |
| 1153 | changes. We hope to eliminate this risk and provide automatic merging |
| 1154 | with RCS in a future Emacs version. |
| 1155 | |
| 1156 | In addition, locking is possible with RCS even in this mode, although |
| 1157 | it is not required; @kbd{C-x C-q} with an unmodified file locks the |
| 1158 | file, just as it does with RCS in its normal (locking) mode. |
| 1159 | |
| 1160 | @node Log Buffer |
| 1161 | @subsubsection Features of the Log Entry Buffer |
| 1162 | |
| 1163 | When you check in changes, @kbd{C-x C-q} first reads a log entry. It |
| 1164 | pops up a buffer called @samp{*VC-Log*} for you to enter the log entry. |
| 1165 | When you are finished, type @kbd{C-c C-c} in the @samp{*VC-Log*} buffer. |
| 1166 | That is when check-in really happens. |
| 1167 | |
| 1168 | To abort check-in, just @strong{don't} type @kbd{C-c C-c} in that |
| 1169 | buffer. You can switch buffers and do other editing. As long as you |
| 1170 | don't try to check in another file, the entry you were editing remains |
| 1171 | in the @samp{*VC-Log*} buffer, and you can go back to that buffer at any |
| 1172 | time to complete the check-in. |
| 1173 | |
| 1174 | If you change several source files for the same reason, it is often |
| 1175 | convenient to specify the same log entry for many of the files. To do |
| 1176 | this, use the history of previous log entries. The commands @kbd{M-n}, |
| 1177 | @kbd{M-p}, @kbd{M-s} and @kbd{M-r} for doing this work just like the |
| 1178 | minibuffer history commands (except that these versions are used outside |
| 1179 | the minibuffer). |
| 1180 | |
| 1181 | @vindex vc-log-mode-hook |
| 1182 | Each time you check in a file, the log entry buffer is put into VC Log |
| 1183 | mode, which involves running two hooks: @code{text-mode-hook} and |
| 1184 | @code{vc-log-mode-hook}. @xref{Hooks}. |
| 1185 | |
| 1186 | @node Old Versions |
| 1187 | @subsection Examining And Comparing Old Versions |
| 1188 | |
| 1189 | One of the convenient features of version control is the ability |
| 1190 | to examine any version of a file, or compare two versions. |
| 1191 | |
| 1192 | @table @kbd |
| 1193 | @item C-x v ~ @var{version} @key{RET} |
| 1194 | Examine version @var{version} of the visited file, in a buffer of its |
| 1195 | own. |
| 1196 | |
| 1197 | @item C-x v = |
| 1198 | Compare the current buffer contents with the latest checked-in version |
| 1199 | of the file. |
| 1200 | |
| 1201 | @item C-u C-x v = @var{file} @key{RET} @var{oldvers} @key{RET} @var{newvers} @key{RET} |
| 1202 | Compare the specified two versions of @var{file}. |
| 1203 | |
| 1204 | @item C-x v g |
| 1205 | Display the result of the CVS annotate command using colors. |
| 1206 | @end table |
| 1207 | |
| 1208 | @findex vc-version-other-window |
| 1209 | @kindex C-x v ~ |
| 1210 | To examine an old version in toto, visit the file and then type |
| 1211 | @kbd{C-x v ~ @var{version} @key{RET}} (@code{vc-version-other-window}). |
| 1212 | This puts the text of version @var{version} in a file named |
| 1213 | @file{@var{filename}.~@var{version}~}, and visits it in its own buffer |
| 1214 | in a separate window. (In RCS, you can also select an old version |
| 1215 | and create a branch from it. @xref{Branches}.) |
| 1216 | |
| 1217 | @findex vc-diff |
| 1218 | @kindex C-x v = |
| 1219 | But usually it is more convenient to compare two versions of the file, |
| 1220 | with the command @kbd{C-x v =} (@code{vc-diff}). Plain @kbd{C-x v =} |
| 1221 | compares the current buffer contents (saving them in the file if |
| 1222 | necessary) with the last checked-in version of the file. @kbd{C-u C-x v |
| 1223 | =}, with a numeric argument, reads a file name and two version numbers, |
| 1224 | then compares those versions of the specified file. |
| 1225 | |
| 1226 | If you supply a directory name instead of the name of a registered |
| 1227 | file, this command compares the two specified versions of all registered |
| 1228 | files in that directory and its subdirectories. |
| 1229 | |
| 1230 | You can specify a checked-in version by its number; an empty input |
| 1231 | specifies the current contents of the work file (which may be different |
| 1232 | from all the checked-in versions). You can also specify a snapshot name |
| 1233 | (@pxref{Snapshots}) instead of one or both version numbers. |
| 1234 | |
| 1235 | This command works by running the @code{diff} utility, getting the |
| 1236 | options from the variable @code{diff-switches}. It displays the output |
| 1237 | in a special buffer in another window. Unlike the @kbd{M-x diff} |
| 1238 | command, @kbd{C-x v =} does not try to locate the changes in the old and |
| 1239 | new versions. This is because normally one or both versions do not |
| 1240 | exist as files when you compare them; they exist only in the records of |
| 1241 | the master file. @xref{Comparing Files}, for more information about |
| 1242 | @kbd{M-x diff}. |
| 1243 | |
| 1244 | @findex vc-annotate |
| 1245 | @kindex C-x v g |
| 1246 | For CVS-controlled files, you can display the result of the CVS |
| 1247 | annotate command, using colors to enhance the visual appearance. Use |
| 1248 | the command @kbd{M-x vc-annotate} to do this. Red means new, blue means |
| 1249 | old, and intermediate colors indicate intermediate ages. A prefix |
| 1250 | argument @var{n} specifies a stretch factor for the time scale; it makes |
| 1251 | each color cover a period @var{n} times as long. |
| 1252 | |
| 1253 | @node Secondary VC Commands |
| 1254 | @subsection The Secondary Commands of VC |
| 1255 | |
| 1256 | This section explains the secondary commands of VC; those that you might |
| 1257 | use once a day. |
| 1258 | |
| 1259 | @menu |
| 1260 | * Registering:: Putting a file under version control. |
| 1261 | * VC Status:: Viewing the VC status of files. |
| 1262 | * VC Undo:: Cancelling changes before or after check-in. |
| 1263 | * VC Dired Mode:: Listing files managed by version control. |
| 1264 | * VC Dired Commands:: Commands to use in a VC Dired buffer. |
| 1265 | @end menu |
| 1266 | |
| 1267 | @node Registering |
| 1268 | @subsubsection Registering a File for Version Control |
| 1269 | |
| 1270 | @kindex C-x v i |
| 1271 | @findex vc-register |
| 1272 | You can put any file under version control by simply visiting it, and |
| 1273 | then typing @w{@kbd{C-x v i}} (@code{vc-register}). |
| 1274 | |
| 1275 | @table @kbd |
| 1276 | @item C-x v i |
| 1277 | Register the visited file for version control. |
| 1278 | @end table |
| 1279 | |
| 1280 | @vindex vc-default-back-end |
| 1281 | To register the file, Emacs must choose which version control system |
| 1282 | to use for it. You can specify your choice explicitly by setting |
| 1283 | @code{vc-default-back-end} to @code{RCS}, @code{CVS} or @code{SCCS}. |
| 1284 | Otherwise, if there is a subdirectory named @file{RCS}, @file{SCCS}, or |
| 1285 | @file{CVS}, Emacs uses the corresponding version control system. In the |
| 1286 | absence of any specification, the default choice is RCS if RCS is |
| 1287 | installed, otherwise SCCS. |
| 1288 | |
| 1289 | If locking is in use, @kbd{C-x v i} leaves the file unlocked and |
| 1290 | read-only. Type @kbd{C-x C-q} if you wish to start editing it. After |
| 1291 | registering a file with CVS, you must subsequently commit the initial |
| 1292 | version by typing @kbd{C-x C-q}. |
| 1293 | |
| 1294 | @vindex vc-default-init-version |
| 1295 | The initial version number for a newly registered file is 1.1, by |
| 1296 | default. You can specify a different default by setting the variable |
| 1297 | @code{vc-default-init-version}, or you can give @kbd{C-x v i} a numeric |
| 1298 | argument; then it reads the initial version number for this particular |
| 1299 | file using the minibuffer. |
| 1300 | |
| 1301 | @vindex vc-initial-comment |
| 1302 | If @code{vc-initial-comment} is non-@code{nil}, @kbd{C-x v i} reads an |
| 1303 | initial comment to describe the purpose of this source file. Reading |
| 1304 | the initial comment works like reading a log entry (@pxref{Log Buffer}). |
| 1305 | |
| 1306 | @node VC Status |
| 1307 | @subsubsection VC Status Commands |
| 1308 | |
| 1309 | @table @kbd |
| 1310 | @item C-x v l |
| 1311 | Display version control state and change history. |
| 1312 | @end table |
| 1313 | |
| 1314 | @kindex C-x v l |
| 1315 | @findex vc-print-log |
| 1316 | To view the detailed version control status and history of a file, |
| 1317 | type @kbd{C-x v l} (@code{vc-print-log}). It displays the history of |
| 1318 | changes to the current file, including the text of the log entries. The |
| 1319 | output appears in a separate window. |
| 1320 | |
| 1321 | @node VC Undo |
| 1322 | @subsubsection Undoing Version Control Actions |
| 1323 | |
| 1324 | @table @kbd |
| 1325 | @item C-x v u |
| 1326 | Revert the buffer and the file to the last checked-in version. |
| 1327 | |
| 1328 | @item C-x v c |
| 1329 | Remove the last-entered change from the master for the visited file. |
| 1330 | This undoes your last check-in. |
| 1331 | @end table |
| 1332 | |
| 1333 | @kindex C-x v u |
| 1334 | @findex vc-revert-buffer |
| 1335 | If you want to discard your current set of changes and revert to the |
| 1336 | last version checked in, use @kbd{C-x v u} (@code{vc-revert-buffer}). |
| 1337 | This leaves the file unlocked; if locking is in use, you must first lock |
| 1338 | the file again before you change it again. @kbd{C-x v u} requires |
| 1339 | confirmation, unless it sees that you haven't made any changes since the |
| 1340 | last checked-in version. |
| 1341 | |
| 1342 | @kbd{C-x v u} is also the command to unlock a file if you lock it and |
| 1343 | then decide not to change it. |
| 1344 | |
| 1345 | @kindex C-x v c |
| 1346 | @findex vc-cancel-version |
| 1347 | To cancel a change that you already checked in, use @kbd{C-x v c} |
| 1348 | (@code{vc-cancel-version}). This command discards all record of the |
| 1349 | most recent checked-in version. @kbd{C-x v c} also offers to revert |
| 1350 | your work file and buffer to the previous version (the one that precedes |
| 1351 | the version that is deleted). |
| 1352 | |
| 1353 | If you answer @kbd{no}, VC keeps your changes in the buffer, and locks |
| 1354 | the file. The no-revert option is useful when you have checked in a |
| 1355 | change and then discover a trivial error in it; you can cancel the |
| 1356 | erroneous check-in, fix the error, and check the file in again. |
| 1357 | |
| 1358 | When @kbd{C-x v c} does not revert the buffer, it unexpands all |
| 1359 | version control headers in the buffer instead (@pxref{Version Headers}). |
| 1360 | This is because the buffer no longer corresponds to any existing |
| 1361 | version. If you check it in again, the check-in process will expand the |
| 1362 | headers properly for the new version number. |
| 1363 | |
| 1364 | However, it is impossible to unexpand the RCS @samp{@w{$}Log$} header |
| 1365 | automatically. If you use that header feature, you have to unexpand it |
| 1366 | by hand---by deleting the entry for the version that you just canceled. |
| 1367 | |
| 1368 | Be careful when invoking @kbd{C-x v c}, as it is easy to lose a lot of |
| 1369 | work with it. To help you be careful, this command always requires |
| 1370 | confirmation with @kbd{yes}. Note also that this command is disabled |
| 1371 | under CVS, because canceling versions is very dangerous and discouraged |
| 1372 | with CVS. |
| 1373 | |
| 1374 | @node VC Dired Mode |
| 1375 | @subsubsection Dired under VC |
| 1376 | |
| 1377 | @kindex C-x v d |
| 1378 | @findex vc-directory |
| 1379 | When you are working on a large program, it is often useful to find |
| 1380 | out which files have changed within an entire directory tree, or to view |
| 1381 | the status of all files under version control at once, and to perform |
| 1382 | version control operations on collections of files. You can use the |
| 1383 | command @kbd{C-x v d} (@code{vc-directory}) to make a directory listing |
| 1384 | that includes only files relevant for version control. |
| 1385 | |
| 1386 | @vindex vc-dired-terse-display |
| 1387 | @kbd{C-x v d} creates a buffer which uses VC Dired Mode. This looks |
| 1388 | much like an ordinary Dired buffer (@pxref{Dired}); however, normally it |
| 1389 | shows only the noteworthy files (those locked or not up-to-date). This |
| 1390 | is called @dfn{terse display}. If you set the variable |
| 1391 | @code{vc-dired-terse-display} to @code{nil}, then VC Dired shows all |
| 1392 | relevant files---those managed under version control, plus all |
| 1393 | subdirectories (@dfn{full display}). The command @kbd{v t} in a VC |
| 1394 | Dired buffer toggles between terse display and full display (@pxref{VC |
| 1395 | Dired Commands}). |
| 1396 | |
| 1397 | @vindex vc-dired-recurse |
| 1398 | By default, VC Dired produces a recursive listing of noteworthy or |
| 1399 | relevant files at or below the given directory. You can change this by |
| 1400 | setting the variable @code{vc-dired-recurse} to @code{nil}; then VC |
| 1401 | Dired shows only the files in the given directory. |
| 1402 | |
| 1403 | The line for an individual file shows the version control state in the |
| 1404 | place of the hard link count, owner, group, and size of the file. If |
| 1405 | the file is unmodified, in sync with the master file, the version |
| 1406 | control state shown is blank. Otherwise it consists of text in |
| 1407 | parentheses. Under RCS and SCCS, the name of the user locking the file |
| 1408 | is shown; under CVS, an abbreviated version of the @samp{cvs status} |
| 1409 | output is used. Here is an example using RCS: |
| 1410 | |
| 1411 | @smallexample |
| 1412 | @group |
| 1413 | /home/jim/project: |
| 1414 | |
| 1415 | -rw-r--r-- (jim) Apr 2 23:39 file1 |
| 1416 | -r--r--r-- Apr 5 20:21 file2 |
| 1417 | @end group |
| 1418 | @end smallexample |
| 1419 | |
| 1420 | @noindent |
| 1421 | The files @samp{file1} and @samp{file2} are under version control, |
| 1422 | @samp{file1} is locked by user jim, and @samp{file2} is unlocked. |
| 1423 | |
| 1424 | Here is an example using CVS: |
| 1425 | |
| 1426 | @smallexample |
| 1427 | @group |
| 1428 | /home/joe/develop: |
| 1429 | |
| 1430 | -rw-r--r-- (modified) Aug 2 1997 file1.c |
| 1431 | -rw-r--r-- Apr 4 20:09 file2.c |
| 1432 | -rw-r--r-- (merge) Sep 13 1996 file3.c |
| 1433 | @end group |
| 1434 | @end smallexample |
| 1435 | |
| 1436 | Here @samp{file1.c} is modified with respect to the repository, and |
| 1437 | @samp{file2.c} is not. @samp{file3.c} is modified, but other changes |
| 1438 | have also been checked in to the repository---you need to merge them |
| 1439 | with the work file before you can check it in. |
| 1440 | |
| 1441 | @vindex vc-directory-exclusion-list |
| 1442 | When VC Dired displays subdirectories (in the ``full'' display mode), |
| 1443 | it omits some that should never contain any files under version control. |
| 1444 | By default, this includes Version Control subdirectories such as |
| 1445 | @samp{RCS} and @samp{CVS}; you can customize this by setting the |
| 1446 | variable @code{vc-directory-exclusion-list}. |
| 1447 | |
| 1448 | You can fine-tune VC Dired's format by typing @kbd{C-u C-x v d}---as in |
| 1449 | ordinary Dired, that allows you to specify additional switches for the |
| 1450 | @samp{ls} command. |
| 1451 | |
| 1452 | @node VC Dired Commands |
| 1453 | @subsubsection VC Dired Commands |
| 1454 | |
| 1455 | All the usual Dired commands work normally in VC Dired mode, except |
| 1456 | for @kbd{v}, which is redefined as the version control prefix. You can |
| 1457 | invoke VC commands such as @code{vc-diff} and @code{vc-print-log} by |
| 1458 | typing @kbd{v =}, or @kbd{v l}, and so on. Most of these commands apply |
| 1459 | to the file name on the current line. |
| 1460 | |
| 1461 | The command @kbd{v v} (@code{vc-next-action}) operates on all the |
| 1462 | marked files, so that you can lock or check in several files at once. |
| 1463 | If it operates on more than one file, it handles each file according to |
| 1464 | its current state; thus, it might lock one file, but check in another |
| 1465 | file. This could be confusing; it is up to you to avoid confusing |
| 1466 | behavior by marking a set of files that are in a similar state. |
| 1467 | |
| 1468 | If any files call for check-in, @kbd{v v} reads a single log entry, |
| 1469 | then uses it for all the files being checked in. This is convenient for |
| 1470 | registering or checking in several files at once, as part of the same |
| 1471 | change. |
| 1472 | |
| 1473 | @findex vc-dired-toggle-terse-mode |
| 1474 | @findex vc-dired-mark-locked |
| 1475 | You can toggle between terse display (only locked files, or files not |
| 1476 | up-to-date) and full display at any time by typing @kbd{v t} |
| 1477 | @code{vc-dired-toggle-terse-mode}. There is also a special command |
| 1478 | @kbd{* l} (@code{vc-dired-mark-locked}), which marks all files currently |
| 1479 | locked (or, with CVS, all files not up-to-date). Thus, typing @kbd{* l |
| 1480 | t k} is another way to delete from the buffer all files except those |
| 1481 | currently locked. |
| 1482 | |
| 1483 | @node Branches |
| 1484 | @subsection Multiple Branches of a File |
| 1485 | @cindex branch (version control) |
| 1486 | @cindex trunk (version control) |
| 1487 | |
| 1488 | One use of version control is to maintain multiple ``current'' |
| 1489 | versions of a file. For example, you might have different versions of a |
| 1490 | program in which you are gradually adding various unfinished new |
| 1491 | features. Each such independent line of development is called a |
| 1492 | @dfn{branch}. VC allows you to create branches, switch between |
| 1493 | different branches, and merge changes from one branch to another. |
| 1494 | Please note, however, that branches are only supported for RCS at the |
| 1495 | moment. |
| 1496 | |
| 1497 | A file's main line of development is usually called the @dfn{trunk}. |
| 1498 | The versions on the trunk are normally numbered 1.1, 1.2, 1.3, etc. At |
| 1499 | any such version, you can start an independent branch. A branch |
| 1500 | starting at version 1.2 would have version number 1.2.1.1, and consecutive |
| 1501 | versions on this branch would have numbers 1.2.1.2, 1.2.1.3, 1.2.1.4, |
| 1502 | and so on. If there is a second branch also starting at version 1.2, it |
| 1503 | would consist of versions 1.2.2.1, 1.2.2.2, 1.2.2.3, etc. |
| 1504 | |
| 1505 | @cindex head version |
| 1506 | If you omit the final component of a version number, that is called a |
| 1507 | @dfn{branch number}. It refers to the highest existing version on that |
| 1508 | branch---the @dfn{head version} of that branch. The branches in the |
| 1509 | example above have branch numbers 1.2.1 and 1.2.2. |
| 1510 | |
| 1511 | @menu |
| 1512 | * Switching Branches:: How to get to another existing branch. |
| 1513 | * Creating Branches:: How to start a new branch. |
| 1514 | * Merging:: Transferring changes between branches. |
| 1515 | * Multi-User Branching:: Multiple users working at multiple branches |
| 1516 | in parallel. |
| 1517 | @end menu |
| 1518 | |
| 1519 | @node Switching Branches |
| 1520 | @subsubsection Switching between Branches |
| 1521 | |
| 1522 | To switch between branches, type @kbd{C-u C-x C-q} and specify the |
| 1523 | version number you want to select. This version is then visited |
| 1524 | @emph{unlocked} (write-protected), so you can examine it before locking |
| 1525 | it. Switching branches in this way is allowed only when the file is not |
| 1526 | locked. |
| 1527 | |
| 1528 | You can omit the minor version number, thus giving only the branch |
| 1529 | number; this takes you to the head version on the chosen branch. If you |
| 1530 | only type @key{RET}, Emacs goes to the highest version on the trunk. |
| 1531 | |
| 1532 | After you have switched to any branch (including the main branch), you |
| 1533 | stay on it for subsequent VC commands, until you explicitly select some |
| 1534 | other branch. |
| 1535 | |
| 1536 | @node Creating Branches |
| 1537 | @subsubsection Creating New Branches |
| 1538 | |
| 1539 | To create a new branch from a head version (one that is the latest in |
| 1540 | the branch that contains it), first select that version if necessary, |
| 1541 | lock it with @kbd{C-x C-q}, and make whatever changes you want. Then, |
| 1542 | when you check in the changes, use @kbd{C-u C-x C-q}. This lets you |
| 1543 | specify the version number for the new version. You should specify a |
| 1544 | suitable branch number for a branch starting at the current version. |
| 1545 | For example, if the current version is 2.5, the branch number should be |
| 1546 | 2.5.1, 2.5.2, and so on, depending on the number of existing branches at |
| 1547 | that point. |
| 1548 | |
| 1549 | To create a new branch at an older version (one that is no longer the |
| 1550 | head of a branch), first select that version (@pxref{Switching |
| 1551 | Branches}), then lock it with @kbd{C-x C-q}. You'll be asked to |
| 1552 | confirm, when you lock the old version, that you really mean to create a |
| 1553 | new branch---if you say no, you'll be offered a chance to lock the |
| 1554 | latest version instead. |
| 1555 | |
| 1556 | Then make your changes and type @kbd{C-x C-q} again to check in a new |
| 1557 | version. This automatically creates a new branch starting from the |
| 1558 | selected version. You need not specially request a new branch, because |
| 1559 | that's the only way to add a new version at a point that is not the head |
| 1560 | of a branch. |
| 1561 | |
| 1562 | After the branch is created, you ``stay'' on it. That means that |
| 1563 | subsequent check-ins create new versions on that branch. To leave the |
| 1564 | branch, you must explicitly select a different version with @kbd{C-u C-x |
| 1565 | C-q}. To transfer changes from one branch to another, use the merge |
| 1566 | command, described in the next section. |
| 1567 | |
| 1568 | @node Merging |
| 1569 | @subsubsection Merging Branches |
| 1570 | |
| 1571 | @cindex merging changes |
| 1572 | When you have finished the changes on a certain branch, you will |
| 1573 | often want to incorporate them into the file's main line of development |
| 1574 | (the trunk). This is not a trivial operation, because development might |
| 1575 | also have proceeded on the trunk, so that you must @dfn{merge} the |
| 1576 | changes into a file that has already been changed otherwise. VC allows |
| 1577 | you to do this (and other things) with the @code{vc-merge} command. |
| 1578 | |
| 1579 | @table @kbd |
| 1580 | @item C-x v m (vc-merge) |
| 1581 | Merge changes into the work file. |
| 1582 | @end table |
| 1583 | |
| 1584 | @kindex C-x v m |
| 1585 | @findex vc-merge |
| 1586 | @kbd{C-x v m} (@code{vc-merge}) takes a set of changes and merges it |
| 1587 | into the current version of the work file. It first asks you for a |
| 1588 | branch number or a pair of version numbers in the minibuffer. Then it |
| 1589 | finds the changes from that branch, or between the two versions you |
| 1590 | specified, and merges them into the current version of the current file. |
| 1591 | |
| 1592 | As an example, suppose that you have finished a certain feature on |
| 1593 | branch 1.3.1. In the meantime, development on the trunk has proceeded |
| 1594 | to version 1.5. To merge the changes from the branch to the trunk, |
| 1595 | first go to the head version of the trunk, by typing @kbd{C-u C-x C-q |
| 1596 | RET}. Version 1.5 is now current. If locking is used for the file, |
| 1597 | type @kbd{C-x C-q} to lock version 1.5 so that you can change it. Next, |
| 1598 | type @kbd{C-x v m 1.3.1 RET}. This takes the entire set of changes on |
| 1599 | branch 1.3.1 (relative to version 1.3, where the branch started, up to |
| 1600 | the last version on the branch) and merges it into the current version |
| 1601 | of the work file. You can now check in the changed file, thus creating |
| 1602 | version 1.6 containing the changes from the branch. |
| 1603 | |
| 1604 | It is possible to do further editing after merging the branch, before |
| 1605 | the next check-in. But it is usually wiser to check in the merged |
| 1606 | version, then lock it and make the further changes. This will keep |
| 1607 | a better record of the history of changes. |
| 1608 | |
| 1609 | @cindex conflicts |
| 1610 | @cindex resolving conflicts |
| 1611 | When you merge changes into a file that has itself been modified, the |
| 1612 | changes might overlap. We call this situation a @dfn{conflict}, and |
| 1613 | reconciling the conflicting changes is called @dfn{resolving a |
| 1614 | conflict}. |
| 1615 | |
| 1616 | Whenever conflicts occur during merging, VC detects them, tells you |
| 1617 | about them in the echo area, and asks whether you want help in merging. |
| 1618 | If you say yes, it starts an Ediff session (@pxref{Top, |
| 1619 | Ediff, Ediff, ediff, The Ediff Manual}). |
| 1620 | |
| 1621 | If you say no, the conflicting changes are both inserted into the |
| 1622 | file, surrounded by @dfn{conflict markers}. The example below shows how |
| 1623 | a conflict region looks; the file is called @samp{name} and the current |
| 1624 | master file version with user B's changes in it is 1.11. |
| 1625 | |
| 1626 | @c @w here is so CVS won't think this is a conflict. |
| 1627 | @smallexample |
| 1628 | @group |
| 1629 | @w{<}<<<<<< name |
| 1630 | @var{User A's version} |
| 1631 | ======= |
| 1632 | @var{User B's version} |
| 1633 | @w{>}>>>>>> 1.11 |
| 1634 | @end group |
| 1635 | @end smallexample |
| 1636 | |
| 1637 | @cindex vc-resolve-conflicts |
| 1638 | Then you can resolve the conflicts by editing the file manually. Or |
| 1639 | you can type @code{M-x vc-resolve-conflicts} after visiting the file. |
| 1640 | This starts an Ediff session, as described above. |
| 1641 | |
| 1642 | @node Multi-User Branching |
| 1643 | @subsubsection Multi-User Branching |
| 1644 | |
| 1645 | It is often useful for multiple developers to work simultaneously on |
| 1646 | different branches of a file. CVS allows this by default; for RCS, it |
| 1647 | is possible if you create multiple source directories. Each source |
| 1648 | directory should have a link named @file{RCS} which points to a common |
| 1649 | directory of RCS master files. Then each source directory can have its |
| 1650 | own choice of selected versions, but all share the same common RCS |
| 1651 | records. |
| 1652 | |
| 1653 | This technique works reliably and automatically, provided that the |
| 1654 | source files contain RCS version headers (@pxref{Version Headers}). The |
| 1655 | headers enable Emacs to be sure, at all times, which version number is |
| 1656 | present in the work file. |
| 1657 | |
| 1658 | If the files do not have version headers, you must instead tell Emacs |
| 1659 | explicitly in each session which branch you are working on. To do this, |
| 1660 | first find the file, then type @kbd{C-u C-x C-q} and specify the correct |
| 1661 | branch number. This ensures that Emacs knows which branch it is using |
| 1662 | during this particular editing session. |
| 1663 | |
| 1664 | @node Snapshots |
| 1665 | @subsection Snapshots |
| 1666 | @cindex snapshots and version control |
| 1667 | |
| 1668 | A @dfn{snapshot} is a named set of file versions (one for each |
| 1669 | registered file) that you can treat as a unit. One important kind of |
| 1670 | snapshot is a @dfn{release}, a (theoretically) stable version of the |
| 1671 | system that is ready for distribution to users. |
| 1672 | |
| 1673 | @menu |
| 1674 | * Making Snapshots:: The snapshot facilities. |
| 1675 | * Snapshot Caveats:: Things to be careful of when using snapshots. |
| 1676 | @end menu |
| 1677 | |
| 1678 | @node Making Snapshots |
| 1679 | @subsubsection Making and Using Snapshots |
| 1680 | |
| 1681 | There are two basic commands for snapshots; one makes a |
| 1682 | snapshot with a given name, the other retrieves a named snapshot. |
| 1683 | |
| 1684 | @table @code |
| 1685 | @kindex C-x v s |
| 1686 | @findex vc-create-snapshot |
| 1687 | @item C-x v s @var{name} @key{RET} |
| 1688 | Define the last saved versions of every registered file in or under the |
| 1689 | current directory as a snapshot named @var{name} |
| 1690 | (@code{vc-create-snapshot}). |
| 1691 | |
| 1692 | @kindex C-x v r |
| 1693 | @findex vc-retrieve-snapshot |
| 1694 | @item C-x v r @var{name} @key{RET} |
| 1695 | For all registered files at or below the current directory level, select |
| 1696 | whatever versions correspond to the snapshot @var{name} |
| 1697 | (@code{vc-retrieve-snapshot}). |
| 1698 | |
| 1699 | This command reports an error if any files are locked at or below the |
| 1700 | current directory, without changing anything; this is to avoid |
| 1701 | overwriting work in progress. |
| 1702 | @end table |
| 1703 | |
| 1704 | A snapshot uses a very small amount of resources---just enough to record |
| 1705 | the list of file names and which version belongs to the snapshot. Thus, |
| 1706 | you need not hesitate to create snapshots whenever they are useful. |
| 1707 | |
| 1708 | You can give a snapshot name as an argument to @kbd{C-x v =} or |
| 1709 | @kbd{C-x v ~} (@pxref{Old Versions}). Thus, you can use it to compare a |
| 1710 | snapshot against the current files, or two snapshots against each other, |
| 1711 | or a snapshot against a named version. |
| 1712 | |
| 1713 | @node Snapshot Caveats |
| 1714 | @subsubsection Snapshot Caveats |
| 1715 | |
| 1716 | @cindex named configurations (RCS) |
| 1717 | VC's snapshot facilities are modeled on RCS's named-configuration |
| 1718 | support. They use RCS's native facilities for this, so under VC |
| 1719 | snapshots made using RCS are visible even when you bypass VC. |
| 1720 | |
| 1721 | @c worded verbosely to avoid overfull hbox. |
| 1722 | For SCCS, VC implements snapshots itself. The files it uses contain |
| 1723 | name/file/version-number triples. These snapshots are visible only |
| 1724 | through VC. |
| 1725 | |
| 1726 | A snapshot is a set of checked-in versions. So make sure that all the |
| 1727 | files are checked in and not locked when you make a snapshot. |
| 1728 | |
| 1729 | File renaming and deletion can create some difficulties with snapshots. |
| 1730 | This is not a VC-specific problem, but a general design issue in version |
| 1731 | control systems that no one has solved very well yet. |
| 1732 | |
| 1733 | If you rename a registered file, you need to rename its master along |
| 1734 | with it (the command @code{vc-rename-file} does this automatically). If |
| 1735 | you are using SCCS, you must also update the records of the snapshot, to |
| 1736 | mention the file by its new name (@code{vc-rename-file} does this, |
| 1737 | too). An old snapshot that refers to a master file that no longer |
| 1738 | exists under the recorded name is invalid; VC can no longer retrieve |
| 1739 | it. It would be beyond the scope of this manual to explain enough about |
| 1740 | RCS and SCCS to explain how to update the snapshots by hand. |
| 1741 | |
| 1742 | Using @code{vc-rename-file} makes the snapshot remain valid for |
| 1743 | retrieval, but it does not solve all problems. For example, some of the |
| 1744 | files in the program probably refer to others by name. At the very |
| 1745 | least, the makefile probably mentions the file that you renamed. If you |
| 1746 | retrieve an old snapshot, the renamed file is retrieved under its new |
| 1747 | name, which is not the name that the makefile expects. So the program |
| 1748 | won't really work as retrieved. |
| 1749 | |
| 1750 | @node Miscellaneous VC |
| 1751 | @subsection Miscellaneous Commands and Features of VC |
| 1752 | |
| 1753 | This section explains the less-frequently-used features of VC. |
| 1754 | |
| 1755 | @menu |
| 1756 | * Change Logs and VC:: Generating a change log file from log entries. |
| 1757 | * Renaming and VC:: A command to rename both the source and master |
| 1758 | file correctly. |
| 1759 | * Version Headers:: Inserting version control headers into working files. |
| 1760 | @end menu |
| 1761 | |
| 1762 | @node Change Logs and VC |
| 1763 | @subsubsection Change Logs and VC |
| 1764 | |
| 1765 | If you use RCS or CVS for a program and also maintain a change log |
| 1766 | file for it (@pxref{Change Log}), you can generate change log entries |
| 1767 | automatically from the version control log entries: |
| 1768 | |
| 1769 | @table @kbd |
| 1770 | @item C-x v a |
| 1771 | @kindex C-x v a |
| 1772 | @findex vc-update-change-log |
| 1773 | Visit the current directory's change log file and, for registered files |
| 1774 | in that directory, create new entries for versions checked in since the |
| 1775 | most recent entry in the change log file. |
| 1776 | (@code{vc-update-change-log}). |
| 1777 | |
| 1778 | This command works with RCS or CVS only, not with SCCS. |
| 1779 | |
| 1780 | @item C-u C-x v a |
| 1781 | As above, but only find entries for the current buffer's file. |
| 1782 | |
| 1783 | @item M-1 C-x v a |
| 1784 | As above, but find entries for all the currently visited files that are |
| 1785 | maintained with version control. This works only with RCS, and it puts |
| 1786 | all entries in the log for the default directory, which may not be |
| 1787 | appropriate. |
| 1788 | @end table |
| 1789 | |
| 1790 | For example, suppose the first line of @file{ChangeLog} is dated |
| 1791 | 1999-04-10, and that the only check-in since then was by Nathaniel |
| 1792 | Bowditch to @file{rcs2log} on 1999-05-22 with log text @samp{Ignore log |
| 1793 | messages that start with `#'.}. Then @kbd{C-x v a} visits |
| 1794 | @file{ChangeLog} and inserts text like this: |
| 1795 | |
| 1796 | @iftex |
| 1797 | @medbreak |
| 1798 | @end iftex |
| 1799 | @smallexample |
| 1800 | @group |
| 1801 | 1999-05-22 Nathaniel Bowditch <nat@@apn.org> |
| 1802 | |
| 1803 | * rcs2log: Ignore log messages that start with `#'. |
| 1804 | @end group |
| 1805 | @end smallexample |
| 1806 | @iftex |
| 1807 | @medbreak |
| 1808 | @end iftex |
| 1809 | |
| 1810 | @noindent |
| 1811 | You can then edit the new change log entry further as you wish. |
| 1812 | |
| 1813 | Unfortunately, timestamps in ChangeLog files are only dates, so some |
| 1814 | of the new change log entry may duplicate what's already in ChangeLog. |
| 1815 | You will have to remove these duplicates by hand. |
| 1816 | |
| 1817 | Normally, the log entry for file @file{foo} is displayed as @samp{* |
| 1818 | foo: @var{text of log entry}}. The @samp{:} after @file{foo} is omitted |
| 1819 | if the text of the log entry starts with @w{@samp{(@var{functionname}): |
| 1820 | }}. For example, if the log entry for @file{vc.el} is |
| 1821 | @samp{(vc-do-command): Check call-process status.}, then the text in |
| 1822 | @file{ChangeLog} looks like this: |
| 1823 | |
| 1824 | @iftex |
| 1825 | @medbreak |
| 1826 | @end iftex |
| 1827 | @smallexample |
| 1828 | @group |
| 1829 | 1999-05-06 Nathaniel Bowditch <nat@@apn.org> |
| 1830 | |
| 1831 | * vc.el (vc-do-command): Check call-process status. |
| 1832 | @end group |
| 1833 | @end smallexample |
| 1834 | @iftex |
| 1835 | @medbreak |
| 1836 | @end iftex |
| 1837 | |
| 1838 | When @kbd{C-x v a} adds several change log entries at once, it groups |
| 1839 | related log entries together if they all are checked in by the same |
| 1840 | author at nearly the same time. If the log entries for several such |
| 1841 | files all have the same text, it coalesces them into a single entry. |
| 1842 | For example, suppose the most recent check-ins have the following log |
| 1843 | entries: |
| 1844 | |
| 1845 | @flushleft |
| 1846 | @bullet{} For @file{vc.texinfo}: @samp{Fix expansion typos.} |
| 1847 | @bullet{} For @file{vc.el}: @samp{Don't call expand-file-name.} |
| 1848 | @bullet{} For @file{vc-hooks.el}: @samp{Don't call expand-file-name.} |
| 1849 | @end flushleft |
| 1850 | |
| 1851 | @noindent |
| 1852 | They appear like this in @file{ChangeLog}: |
| 1853 | |
| 1854 | @iftex |
| 1855 | @medbreak |
| 1856 | @end iftex |
| 1857 | @smallexample |
| 1858 | @group |
| 1859 | 1999-04-01 Nathaniel Bowditch <nat@@apn.org> |
| 1860 | |
| 1861 | * vc.texinfo: Fix expansion typos. |
| 1862 | |
| 1863 | * vc.el, vc-hooks.el: Don't call expand-file-name. |
| 1864 | @end group |
| 1865 | @end smallexample |
| 1866 | @iftex |
| 1867 | @medbreak |
| 1868 | @end iftex |
| 1869 | |
| 1870 | Normally, @kbd{C-x v a} separates log entries by a blank line, but you |
| 1871 | can mark several related log entries to be clumped together (without an |
| 1872 | intervening blank line) by starting the text of each related log entry |
| 1873 | with a label of the form @w{@samp{@{@var{clumpname}@} }}. The label |
| 1874 | itself is not copied to @file{ChangeLog}. For example, suppose the log |
| 1875 | entries are: |
| 1876 | |
| 1877 | @flushleft |
| 1878 | @bullet{} For @file{vc.texinfo}: @samp{@{expand@} Fix expansion typos.} |
| 1879 | @bullet{} For @file{vc.el}: @samp{@{expand@} Don't call expand-file-name.} |
| 1880 | @bullet{} For @file{vc-hooks.el}: @samp{@{expand@} Don't call expand-file-name.} |
| 1881 | @end flushleft |
| 1882 | |
| 1883 | @noindent |
| 1884 | Then the text in @file{ChangeLog} looks like this: |
| 1885 | |
| 1886 | @iftex |
| 1887 | @medbreak |
| 1888 | @end iftex |
| 1889 | @smallexample |
| 1890 | @group |
| 1891 | 1999-04-01 Nathaniel Bowditch <nat@@apn.org> |
| 1892 | |
| 1893 | * vc.texinfo: Fix expansion typos. |
| 1894 | * vc.el, vc-hooks.el: Don't call expand-file-name. |
| 1895 | @end group |
| 1896 | @end smallexample |
| 1897 | @iftex |
| 1898 | @medbreak |
| 1899 | @end iftex |
| 1900 | |
| 1901 | A log entry whose text begins with @samp{#} is not copied to |
| 1902 | @file{ChangeLog}. For example, if you merely fix some misspellings in |
| 1903 | comments, you can log the change with an entry beginning with @samp{#} |
| 1904 | to avoid putting such trivia into @file{ChangeLog}. |
| 1905 | |
| 1906 | @node Renaming and VC |
| 1907 | @subsubsection Renaming VC Work Files and Master Files |
| 1908 | |
| 1909 | @findex vc-rename-file |
| 1910 | When you rename a registered file, you must also rename its master |
| 1911 | file correspondingly to get proper results. Use @code{vc-rename-file} |
| 1912 | to rename the source file as you specify, and rename its master file |
| 1913 | accordingly. It also updates any snapshots (@pxref{Snapshots}) that |
| 1914 | mention the file, so that they use the new name; despite this, the |
| 1915 | snapshot thus modified may not completely work (@pxref{Snapshot |
| 1916 | Caveats}). |
| 1917 | |
| 1918 | You cannot use @code{vc-rename-file} on a file that is locked by |
| 1919 | someone else. |
| 1920 | |
| 1921 | @node Version Headers |
| 1922 | @subsubsection Inserting Version Control Headers |
| 1923 | |
| 1924 | Sometimes it is convenient to put version identification strings |
| 1925 | directly into working files. Certain special strings called |
| 1926 | @dfn{version headers} are replaced in each successive version by the |
| 1927 | number of that version. |
| 1928 | |
| 1929 | If you are using RCS, and version headers are present in your working |
| 1930 | files, Emacs can use them to determine the current version and the |
| 1931 | locking state of the files. This is more reliable than referring to the |
| 1932 | master files, which is done when there are no version headers. Note |
| 1933 | that in a multi-branch environment, version headers are necessary to |
| 1934 | make VC behave correctly (@pxref{Multi-User Branching}). |
| 1935 | |
| 1936 | Searching for version headers is controlled by the variable |
| 1937 | @code{vc-consult-headers}. If it is non-@code{nil}, Emacs searches for |
| 1938 | headers to determine the version number you are editing. Setting it to |
| 1939 | @code{nil} disables this feature. |
| 1940 | |
| 1941 | @kindex C-x v h |
| 1942 | @findex vc-insert-headers |
| 1943 | You can use the @kbd{C-x v h} command (@code{vc-insert-headers}) to |
| 1944 | insert a suitable header string. |
| 1945 | |
| 1946 | @table @kbd |
| 1947 | @item C-x v h |
| 1948 | Insert headers in a file for use with your version-control system. |
| 1949 | @end table |
| 1950 | |
| 1951 | @vindex vc-header-alist |
| 1952 | The default header string is @samp{@w{$}Id$} for RCS and |
| 1953 | @samp{@w{%}W%} for SCCS. You can specify other headers to insert by |
| 1954 | setting the variable @code{vc-header-alist}. Its value is a list of |
| 1955 | elements of the form @code{(@var{program} . @var{string})} where |
| 1956 | @var{program} is @code{RCS} or @code{SCCS} and @var{string} is the |
| 1957 | string to use. |
| 1958 | |
| 1959 | Instead of a single string, you can specify a list of strings; then |
| 1960 | each string in the list is inserted as a separate header on a line of |
| 1961 | its own. |
| 1962 | |
| 1963 | It is often necessary to use ``superfluous'' backslashes when writing |
| 1964 | the strings that you put in this variable. This is to prevent the |
| 1965 | string in the constant from being interpreted as a header itself if the |
| 1966 | Emacs Lisp file containing it is maintained with version control. |
| 1967 | |
| 1968 | @vindex vc-comment-alist |
| 1969 | Each header is inserted surrounded by tabs, inside comment delimiters, |
| 1970 | on a new line at point. Normally the ordinary comment |
| 1971 | start and comment end strings of the current mode are used, but for |
| 1972 | certain modes, there are special comment delimiters for this purpose; |
| 1973 | the variable @code{vc-comment-alist} specifies them. Each element of |
| 1974 | this list has the form @code{(@var{mode} @var{starter} @var{ender})}. |
| 1975 | |
| 1976 | @vindex vc-static-header-alist |
| 1977 | The variable @code{vc-static-header-alist} specifies further strings |
| 1978 | to add based on the name of the buffer. Its value should be a list of |
| 1979 | elements of the form @code{(@var{regexp} . @var{format})}. Whenever |
| 1980 | @var{regexp} matches the buffer name, @var{format} is inserted as part |
| 1981 | of the header. A header line is inserted for each element that matches |
| 1982 | the buffer name, and for each string specified by |
| 1983 | @code{vc-header-alist}. The header line is made by processing the |
| 1984 | string from @code{vc-header-alist} with the format taken from the |
| 1985 | element. The default value for @code{vc-static-header-alist} is as follows: |
| 1986 | |
| 1987 | @example |
| 1988 | @group |
| 1989 | (("\\.c$" . |
| 1990 | "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n\ |
| 1991 | #endif /* lint */\n")) |
| 1992 | @end group |
| 1993 | @end example |
| 1994 | |
| 1995 | @noindent |
| 1996 | It specifies insertion of text of this form: |
| 1997 | |
| 1998 | @example |
| 1999 | @group |
| 2000 | |
| 2001 | #ifndef lint |
| 2002 | static char vcid[] = "@var{string}"; |
| 2003 | #endif /* lint */ |
| 2004 | @end group |
| 2005 | @end example |
| 2006 | |
| 2007 | @noindent |
| 2008 | Note that the text above starts with a blank line. |
| 2009 | |
| 2010 | If you use more than one version header in a file, put them close |
| 2011 | together in the file. The mechanism in @code{revert-buffer} that |
| 2012 | preserves markers may not handle markers positioned between two version |
| 2013 | headers. |
| 2014 | |
| 2015 | @node Customizing VC |
| 2016 | @subsection Customizing VC |
| 2017 | |
| 2018 | There are many ways of customizing VC. The options you can set fall |
| 2019 | into four categories, described in the following sections. |
| 2020 | |
| 2021 | @vindex vc-ignore-vc-files |
| 2022 | @cindex Version control, deactivating |
| 2023 | In addition, it is possible to turn VC on and off generally by setting |
| 2024 | the variable @code{vc-ignore-vc-files}. Normally VC will notice the |
| 2025 | presence of version control on a file you visit and automatically invoke |
| 2026 | the relevant program to check the file's state. Change |
| 2027 | @code{vc-ignore-vc-files} if this isn't the right thing, for instance, |
| 2028 | if you edit files under version control but don't have the relevant |
| 2029 | version control programs available. |
| 2030 | |
| 2031 | @menu |
| 2032 | * Backend Options:: Customizing the back-end to your needs. |
| 2033 | * VC Workfile Handling:: Various options concerning working files. |
| 2034 | * VC Status Retrieval:: How VC finds the version control status of a file, |
| 2035 | and how to customize this. |
| 2036 | * VC Command Execution:: Which commands VC should run, and how. |
| 2037 | @end menu |
| 2038 | |
| 2039 | @node Backend Options |
| 2040 | @subsubsection Options for VC Backends |
| 2041 | |
| 2042 | @cindex backend options (VC) |
| 2043 | @cindex locking under version control |
| 2044 | You can tell RCS and CVS whether to use locking for a file or not |
| 2045 | (@pxref{VC Concepts}, for a description of locking). VC automatically |
| 2046 | recognizes what you have chosen, and behaves accordingly. |
| 2047 | |
| 2048 | @cindex non-strict locking (RCS) |
| 2049 | @cindex locking, non-strict (RCS) |
| 2050 | For RCS, the default is to use locking, but there is a mode called |
| 2051 | @dfn{non-strict locking} in which you can check-in changes without |
| 2052 | locking the file first. Use @samp{rcs -U} to switch to non-strict |
| 2053 | locking for a particular file, see the @samp{rcs} manpage for details. |
| 2054 | |
| 2055 | @cindex locking (CVS) |
| 2056 | Under CVS, the default is not to use locking; anyone can change a work |
| 2057 | file at any time. However, there are ways to restrict this, resulting |
| 2058 | in behavior that resembles locking. |
| 2059 | |
| 2060 | @cindex CVSREAD environment variable (CVS) |
| 2061 | For one thing, you can set the @code{CVSREAD} environment variable to |
| 2062 | an arbitrary value. If this variable is defined, CVS makes your work |
| 2063 | files read-only by default. In Emacs, you must type @kbd{C-x C-q} to |
| 2064 | make the file writeable, so that editing works in fact similar as if |
| 2065 | locking was used. Note however, that no actual locking is performed, so |
| 2066 | several users can make their files writeable at the same time. When |
| 2067 | setting @code{CVSREAD} for the first time, make sure to check out all |
| 2068 | your modules anew, so that the file protections are set correctly. |
| 2069 | |
| 2070 | @cindex cvs watch feature |
| 2071 | @cindex watching files (CVS) |
| 2072 | Another way to achieve something similar to locking is to use the |
| 2073 | @dfn{watch} feature of CVS. If a file is being watched, CVS makes it |
| 2074 | read-only by default, and you must also use @kbd{C-x C-q} in Emacs to |
| 2075 | make it writable. VC calls @code{cvs edit} to make the file writeable, |
| 2076 | and CVS takes care to notify other developers of the fact that you |
| 2077 | intend to change the file. See the CVS documentation for details on |
| 2078 | using the watch feature. |
| 2079 | |
| 2080 | @vindex vc-handle-cvs |
| 2081 | You can turn off use of VC for CVS-managed files by setting the |
| 2082 | variable @code{vc-handle-cvs} to @code{nil}. If you do this, Emacs |
| 2083 | treats these files as if they were not registered, and the VC commands |
| 2084 | are not available for them. You must do all CVS operations manually. |
| 2085 | |
| 2086 | @node VC Workfile Handling |
| 2087 | @subsubsection VC Workfile Handling |
| 2088 | |
| 2089 | @vindex vc-make-backup-files |
| 2090 | Emacs normally does not save backup files for source files that are |
| 2091 | maintained with version control. If you want to make backup files even |
| 2092 | for files that use version control, set the variable |
| 2093 | @code{vc-make-backup-files} to a non-@code{nil} value. |
| 2094 | |
| 2095 | @vindex vc-keep-workfiles |
| 2096 | Normally the work file exists all the time, whether it is locked or |
| 2097 | not. If you set @code{vc-keep-workfiles} to @code{nil}, then checking |
| 2098 | in a new version with @kbd{C-x C-q} deletes the work file; but any |
| 2099 | attempt to visit the file with Emacs creates it again. (With CVS, work |
| 2100 | files are always kept.) |
| 2101 | |
| 2102 | @vindex vc-follow-symlinks |
| 2103 | Editing a version-controlled file through a symbolic link can be |
| 2104 | dangerous. It bypasses the version control system---you can edit the |
| 2105 | file without locking it, and fail to check your changes in. Also, |
| 2106 | your changes might overwrite those of another user. To protect against |
| 2107 | this, VC checks each symbolic link that you visit, to see if it points |
| 2108 | to a file under version control. |
| 2109 | |
| 2110 | The variable @code{vc-follow-symlinks} controls what to do when a |
| 2111 | symbolic link points to a version-controlled file. If it is @code{nil}, |
| 2112 | VC only displays a warning message. If it is @code{t}, VC automatically |
| 2113 | follows the link, and visits the real file instead, telling you about |
| 2114 | this in the echo area. If the value is @code{ask} (the default), VC |
| 2115 | asks you each time whether to follow the link. |
| 2116 | |
| 2117 | @node VC Status Retrieval |
| 2118 | @subsubsection VC Status Retrieval |
| 2119 | @c There is no need to tell users about vc-master-templates. |
| 2120 | |
| 2121 | When deducing the locked/unlocked state of a file, VC first looks for |
| 2122 | an RCS version header string in the file (@pxref{Version Headers}). If |
| 2123 | there is no header string, or if you are using SCCS, VC normally looks |
| 2124 | at the file permissions of the work file; this is fast. But there might |
| 2125 | be situations when the file permissions cannot be trusted. In this case |
| 2126 | the master file has to be consulted, which is rather expensive. Also |
| 2127 | the master file can only tell you @emph{if} there's any lock on the |
| 2128 | file, but not whether your work file really contains that locked |
| 2129 | version. |
| 2130 | |
| 2131 | @vindex vc-consult-headers |
| 2132 | You can tell VC not to use version headers to determine lock status by |
| 2133 | setting @code{vc-consult-headers} to @code{nil}. VC then always uses |
| 2134 | the file permissions (if it can trust them), or else checks the master |
| 2135 | file. |
| 2136 | |
| 2137 | @vindex vc-mistrust-permissions |
| 2138 | You can specify the criterion for whether to trust the file |
| 2139 | permissions by setting the variable @code{vc-mistrust-permissions}. Its |
| 2140 | value can be @code{t} (always mistrust the file permissions and check |
| 2141 | the master file), @code{nil} (always trust the file permissions), or a |
| 2142 | function of one argument which makes the decision. The argument is the |
| 2143 | directory name of the @file{RCS}, @file{CVS} or @file{SCCS} |
| 2144 | subdirectory. A non-@code{nil} value from the function says to mistrust |
| 2145 | the file permissions. If you find that the file permissions of work |
| 2146 | files are changed erroneously, set @code{vc-mistrust-permissions} to |
| 2147 | @code{t}. Then VC always checks the master file to determine the file's |
| 2148 | status. |
| 2149 | |
| 2150 | @node VC Command Execution |
| 2151 | @subsubsection VC Command Execution |
| 2152 | |
| 2153 | @vindex vc-suppress-confirm |
| 2154 | If @code{vc-suppress-confirm} is non-@code{nil}, then @kbd{C-x C-q} |
| 2155 | and @kbd{C-x v i} can save the current buffer without asking, and |
| 2156 | @kbd{C-x v u} also operates without asking for confirmation. (This |
| 2157 | variable does not affect @kbd{C-x v c}; that operation is so drastic |
| 2158 | that it should always ask for confirmation.) |
| 2159 | |
| 2160 | @vindex vc-command-messages |
| 2161 | VC mode does much of its work by running the shell commands for RCS, |
| 2162 | CVS and SCCS. If @code{vc-command-messages} is non-@code{nil}, VC |
| 2163 | displays messages to indicate which shell commands it runs, and |
| 2164 | additional messages when the commands finish. |
| 2165 | |
| 2166 | @vindex vc-path |
| 2167 | You can specify additional directories to search for version control |
| 2168 | programs by setting the variable @code{vc-path}. These directories are |
| 2169 | searched before the usual search path. But the proper files are usually |
| 2170 | found automatically. |
| 2171 | |
| 2172 | @node Directories |
| 2173 | @section File Directories |
| 2174 | |
| 2175 | @cindex file directory |
| 2176 | @cindex directory listing |
| 2177 | The file system groups files into @dfn{directories}. A @dfn{directory |
| 2178 | listing} is a list of all the files in a directory. Emacs provides |
| 2179 | commands to create and delete directories, and to make directory |
| 2180 | listings in brief format (file names only) and verbose format (sizes, |
| 2181 | dates, and authors included). There is also a directory browser called |
| 2182 | Dired; see @ref{Dired}. |
| 2183 | |
| 2184 | @table @kbd |
| 2185 | @item C-x C-d @var{dir-or-pattern} @key{RET} |
| 2186 | Display a brief directory listing (@code{list-directory}). |
| 2187 | @item C-u C-x C-d @var{dir-or-pattern} @key{RET} |
| 2188 | Display a verbose directory listing. |
| 2189 | @item M-x make-directory @key{RET} @var{dirname} @key{RET} |
| 2190 | Create a new directory named @var{dirname}. |
| 2191 | @item M-x delete-directory @key{RET} @var{dirname} @key{RET} |
| 2192 | Delete the directory named @var{dirname}. It must be empty, |
| 2193 | or you get an error. |
| 2194 | @end table |
| 2195 | |
| 2196 | @findex list-directory |
| 2197 | @kindex C-x C-d |
| 2198 | The command to display a directory listing is @kbd{C-x C-d} |
| 2199 | (@code{list-directory}). It reads using the minibuffer a file name |
| 2200 | which is either a directory to be listed or a wildcard-containing |
| 2201 | pattern for the files to be listed. For example, |
| 2202 | |
| 2203 | @example |
| 2204 | C-x C-d /u2/emacs/etc @key{RET} |
| 2205 | @end example |
| 2206 | |
| 2207 | @noindent |
| 2208 | lists all the files in directory @file{/u2/emacs/etc}. Here is an |
| 2209 | example of specifying a file name pattern: |
| 2210 | |
| 2211 | @example |
| 2212 | C-x C-d /u2/emacs/src/*.c @key{RET} |
| 2213 | @end example |
| 2214 | |
| 2215 | Normally, @kbd{C-x C-d} prints a brief directory listing containing |
| 2216 | just file names. A numeric argument (regardless of value) tells it to |
| 2217 | make a verbose listing including sizes, dates, and authors (like |
| 2218 | @samp{ls -l}). |
| 2219 | |
| 2220 | @vindex list-directory-brief-switches |
| 2221 | @vindex list-directory-verbose-switches |
| 2222 | The text of a directory listing is obtained by running @code{ls} in an |
| 2223 | inferior process. Two Emacs variables control the switches passed to |
| 2224 | @code{ls}: @code{list-directory-brief-switches} is a string giving the |
| 2225 | switches to use in brief listings (@code{"-CF"} by default), and |
| 2226 | @code{list-directory-verbose-switches} is a string giving the switches to |
| 2227 | use in a verbose listing (@code{"-l"} by default). |
| 2228 | |
| 2229 | @node Comparing Files |
| 2230 | @section Comparing Files |
| 2231 | @cindex comparing files |
| 2232 | |
| 2233 | @findex diff |
| 2234 | @vindex diff-switches |
| 2235 | The command @kbd{M-x diff} compares two files, displaying the |
| 2236 | differences in an Emacs buffer named @samp{*Diff*}. It works by running |
| 2237 | the @code{diff} program, using options taken from the variable |
| 2238 | @code{diff-switches}, whose value should be a string. |
| 2239 | |
| 2240 | The buffer @samp{*Diff*} has Compilation mode as its major mode, so |
| 2241 | you can use @kbd{C-x `} to visit successive changed locations in the two |
| 2242 | source files. You can also move to a particular hunk of changes and |
| 2243 | type @key{RET} or @kbd{C-c C-c}, or click @kbd{Mouse-2} on it, to move |
| 2244 | to the corresponding source location. You can also use the other |
| 2245 | special commands of Compilation mode: @key{SPC} and @key{DEL} for |
| 2246 | scrolling, and @kbd{M-p} and @kbd{M-n} for cursor motion. |
| 2247 | @xref{Compilation}. |
| 2248 | |
| 2249 | @findex diff-backup |
| 2250 | The command @kbd{M-x diff-backup} compares a specified file with its most |
| 2251 | recent backup. If you specify the name of a backup file, |
| 2252 | @code{diff-backup} compares it with the source file that it is a backup |
| 2253 | of. |
| 2254 | |
| 2255 | @findex compare-windows |
| 2256 | The command @kbd{M-x compare-windows} compares the text in the current |
| 2257 | window with that in the next window. Comparison starts at point in each |
| 2258 | window, and each starting position is pushed on the mark ring in its |
| 2259 | respective buffer. Then point moves forward in each window, a character |
| 2260 | at a time, until a mismatch between the two windows is reached. Then |
| 2261 | the command is finished. For more information about windows in Emacs, |
| 2262 | @ref{Windows}. |
| 2263 | |
| 2264 | @vindex compare-ignore-case |
| 2265 | With a numeric argument, @code{compare-windows} ignores changes in |
| 2266 | whitespace. If the variable @code{compare-ignore-case} is |
| 2267 | non-@code{nil}, it ignores differences in case as well. |
| 2268 | |
| 2269 | See also @ref{Emerge}, for convenient facilities for merging two |
| 2270 | similar files. |
| 2271 | |
| 2272 | @node Misc File Ops |
| 2273 | @section Miscellaneous File Operations |
| 2274 | |
| 2275 | Emacs has commands for performing many other operations on files. |
| 2276 | All operate on one file; they do not accept wildcard file names. |
| 2277 | |
| 2278 | @findex view-file |
| 2279 | @cindex viewing |
| 2280 | @cindex View mode |
| 2281 | @cindex mode, View |
| 2282 | @kbd{M-x view-file} allows you to scan or read a file by sequential |
| 2283 | screenfuls. It reads a file name argument using the minibuffer. After |
| 2284 | reading the file into an Emacs buffer, @code{view-file} displays the |
| 2285 | beginning. You can then type @key{SPC} to scroll forward one windowful, |
| 2286 | or @key{DEL} to scroll backward. Various other commands are provided |
| 2287 | for moving around in the file, but none for changing it; type @kbd{?} |
| 2288 | while viewing for a list of them. They are mostly the same as normal |
| 2289 | Emacs cursor motion commands. To exit from viewing, type @kbd{q}. |
| 2290 | The commands for viewing are defined by a special major mode called View |
| 2291 | mode. |
| 2292 | |
| 2293 | A related command, @kbd{M-x view-buffer}, views a buffer already present |
| 2294 | in Emacs. @xref{Misc Buffer}. |
| 2295 | |
| 2296 | @findex insert-file |
| 2297 | @kbd{M-x insert-file} inserts a copy of the contents of the specified |
| 2298 | file into the current buffer at point, leaving point unchanged before the |
| 2299 | contents and the mark after them. |
| 2300 | |
| 2301 | @findex write-region |
| 2302 | @kbd{M-x write-region} is the inverse of @kbd{M-x insert-file}; it |
| 2303 | copies the contents of the region into the specified file. @kbd{M-x |
| 2304 | append-to-file} adds the text of the region to the end of the specified |
| 2305 | file. @xref{Accumulating Text}. |
| 2306 | |
| 2307 | @findex delete-file |
| 2308 | @cindex deletion (of files) |
| 2309 | @kbd{M-x delete-file} deletes the specified file, like the @code{rm} |
| 2310 | command in the shell. If you are deleting many files in one directory, it |
| 2311 | may be more convenient to use Dired (@pxref{Dired}). |
| 2312 | |
| 2313 | @findex rename-file |
| 2314 | @kbd{M-x rename-file} reads two file names @var{old} and @var{new} using |
| 2315 | the minibuffer, then renames file @var{old} as @var{new}. If a file named |
| 2316 | @var{new} already exists, you must confirm with @kbd{yes} or renaming is not |
| 2317 | done; this is because renaming causes the old meaning of the name @var{new} |
| 2318 | to be lost. If @var{old} and @var{new} are on different file systems, the |
| 2319 | file @var{old} is copied and deleted. |
| 2320 | |
| 2321 | @findex add-name-to-file |
| 2322 | The similar command @kbd{M-x add-name-to-file} is used to add an |
| 2323 | additional name to an existing file without removing its old name. |
| 2324 | The new name must belong on the same file system that the file is on. |
| 2325 | |
| 2326 | @findex copy-file |
| 2327 | @cindex copying files |
| 2328 | @kbd{M-x copy-file} reads the file @var{old} and writes a new file named |
| 2329 | @var{new} with the same contents. Confirmation is required if a file named |
| 2330 | @var{new} already exists, because copying has the consequence of overwriting |
| 2331 | the old contents of the file @var{new}. |
| 2332 | |
| 2333 | @findex make-symbolic-link |
| 2334 | @kbd{M-x make-symbolic-link} reads two file names @var{target} and |
| 2335 | @var{linkname}, then creates a symbolic link named @var{linkname} and |
| 2336 | pointing at @var{target}. The effect is that future attempts to open file |
| 2337 | @var{linkname} will refer to whatever file is named @var{target} at the |
| 2338 | time the opening is done, or will get an error if the name @var{target} is |
| 2339 | not in use at that time. This command does not expand the argument |
| 2340 | @var{target}, so that it allows you to specify a relative name |
| 2341 | as the target of the link. |
| 2342 | |
| 2343 | Confirmation is required when creating the link if @var{linkname} is |
| 2344 | in use. Note that not all systems support symbolic links. |
| 2345 | |
| 2346 | @node Compressed Files |
| 2347 | @section Accessing Compressed Files |
| 2348 | @cindex compression |
| 2349 | @cindex uncompression |
| 2350 | @cindex Auto Compression mode |
| 2351 | @cindex mode, Auto Compression |
| 2352 | @pindex gzip |
| 2353 | |
| 2354 | @findex auto-compression-mode |
| 2355 | @vindex auto-compression-mode |
| 2356 | Emacs comes with a library that can automatically uncompress |
| 2357 | compressed files when you visit them, and automatically recompress them |
| 2358 | if you alter them and save them. To enable this feature, type the |
| 2359 | command @kbd{M-x auto-compression-mode}. You can enable it permanently |
| 2360 | by customizing the option @var{auto-compression-mode}. |
| 2361 | |
| 2362 | When automatic compression (which implies automatic uncompression as |
| 2363 | well) is enabled, Emacs recognizes compressed files by their file names. |
| 2364 | File names ending in @samp{.gz} indicate a file compressed with |
| 2365 | @code{gzip}. Other endings indicate other compression programs. |
| 2366 | |
| 2367 | Automatic uncompression and compression apply to all the operations in |
| 2368 | which Emacs uses the contents of a file. This includes visiting it, |
| 2369 | saving it, inserting its contents into a buffer, loading it, and byte |
| 2370 | compiling it. |
| 2371 | |
| 2372 | @node File Archives |
| 2373 | @section File Archives |
| 2374 | @cindex mode, tar |
| 2375 | @cindex Tar mode |
| 2376 | @cindex Archive mode |
| 2377 | @cindex mode, archive |
| 2378 | @cindex @code{arc} |
| 2379 | @cindex @code{jar} |
| 2380 | @cindex @code{zip} |
| 2381 | @cindex @code{lzh} |
| 2382 | @cindex @code{zoo} |
| 2383 | @pindex tar |
| 2384 | @pindex arc |
| 2385 | @pindex jar |
| 2386 | @pindex zip |
| 2387 | @pindex lzh |
| 2388 | @pindex zoo |
| 2389 | |
| 2390 | If you visit a file with extension @samp{.tar}, it is assumed to be an |
| 2391 | `archive' made by the @code{tar} program and it is viewed in a Tar mode |
| 2392 | buffer. This provides a Dired-like listing of the contents. |
| 2393 | @xref{Dired}. You can move around the component files as in Dired to |
| 2394 | visit and manipulate them. |
| 2395 | |
| 2396 | The keys @kbd{e}, @kbd{f} and @kbd{RET} all extract a component file |
| 2397 | into its own buffer. You can edit it there and when you save the buffer |
| 2398 | the edited version will replace the version in the Tar buffer. @var{v} |
| 2399 | extracts a file into a buffer in View mode. @kbd{d} marks a file for |
| 2400 | deletion when you later use @kbd{x}, as in Dired. @kbd{C} copies a file |
| 2401 | from the archive to disk and @kbd{R} renames a file. |
| 2402 | |
| 2403 | Saving the Tar buffer writes a new version of the archive to disk with |
| 2404 | the changes you made to the components. |
| 2405 | |
| 2406 | If you enable Auto Compression mode (@pxref{Compressed Files}), then Tar |
| 2407 | mode will be used also for compressed archives in files with extensions |
| 2408 | @samp{.tgz}, @code{.tar.Z} and @code{.tar.gz}. |
| 2409 | |
| 2410 | It is not necessary to have the @code{tar} program available to use Tar |
| 2411 | mode or Archive mode---Emacs reads the archives directly. |
| 2412 | |
| 2413 | @cindex @code{arc} |
| 2414 | @cindex @code{jar} |
| 2415 | @cindex @code{zip} |
| 2416 | @cindex @code{lzh} |
| 2417 | @cindex @code{zoo} |
| 2418 | @pindex tar |
| 2419 | @pindex arc |
| 2420 | @pindex jar |
| 2421 | @pindex zip |
| 2422 | @pindex lzh |
| 2423 | @pindex zoo |
| 2424 | @cindex Java class archives |
| 2425 | A separate but similar Archive mode, is used for archives produced by |
| 2426 | the programs @code{arc}, @code{zip}, @code{lzh} and @code{zoo} which |
| 2427 | have extensions corresponding to the program names. These archiving |
| 2428 | programs are typically used on MS-DOS and MS-Windows systems. Java |
| 2429 | class archives with extension @samp{.jar} are also recognized. The |
| 2430 | keybindings in Archive mode are similar to those in Tar mode. |
| 2431 | |
| 2432 | Unlike Tar mode, Archive mode runs the appropriate program to unpack and |
| 2433 | repack archives. Details of the program names and their options can be |
| 2434 | set in the `Archive' Customize group. |
| 2435 | |
| 2436 | @node Remote Files |
| 2437 | @section Remote Files |
| 2438 | |
| 2439 | @cindex FTP |
| 2440 | @cindex remote file access |
| 2441 | You can refer to files on other machines using a special file name syntax: |
| 2442 | |
| 2443 | @example |
| 2444 | @group |
| 2445 | /@var{host}:@var{filename} |
| 2446 | /@var{user}@@@var{host}:@var{filename} |
| 2447 | /@var{user}@@@var{host}#@var{port}:@var{filename} |
| 2448 | @end group |
| 2449 | @end example |
| 2450 | |
| 2451 | @noindent |
| 2452 | When you do this, Emacs uses the FTP program to read and write files on |
| 2453 | the specified host. It logs in through FTP using your user name or the |
| 2454 | name @var{user}. It may ask you for a password from time to time; this |
| 2455 | is used for logging in on @var{host}. The form using @var{port} allows |
| 2456 | you to access servers running on a non-default TCP port. |
| 2457 | |
| 2458 | @cindex ange-ftp |
| 2459 | @vindex ange-ftp-default-user |
| 2460 | Normally, if you do not specify a user name in a remote file name, |
| 2461 | that means to use your own user name. But if you set the variable |
| 2462 | @code{ange-ftp-default-user} to a string, that string is used instead. |
| 2463 | (The Emacs package that implements FTP file access is called |
| 2464 | @code{ange-ftp}.) |
| 2465 | |
| 2466 | @vindex file-name-handler-alist |
| 2467 | You can entirely turn off the FTP file name feature by removing the |
| 2468 | entries @var{ange-ftp-completion-hook-function} and |
| 2469 | @var{ange-ftp-hook-function} from the variable |
| 2470 | @code{file-name-handler-alist}. You can turn off the feature in |
| 2471 | individual cases by quoting the file name with @samp{/:} (@pxref{Quoted |
| 2472 | File Names}). |
| 2473 | |
| 2474 | @node Quoted File Names |
| 2475 | @section Quoted File Names |
| 2476 | |
| 2477 | @cindex quoting file names |
| 2478 | You can @dfn{quote} an absolute file name to prevent special |
| 2479 | characters and syntax in it from having their special effects. |
| 2480 | The way to do this is to add @samp{/:} at the beginning. |
| 2481 | |
| 2482 | For example, you can quote a local file name which appears remote, to |
| 2483 | prevent it from being treated as a remote file name. Thus, if you have |
| 2484 | a directory named @file{/foo:} and a file named @file{bar} in it, you |
| 2485 | can refer to that file in Emacs as @samp{/:/foo:/bar}. |
| 2486 | |
| 2487 | @samp{/:} can also prevent @samp{~} from being treated as a special |
| 2488 | character for a user's home directory. For example, @file{/:/tmp/~hack} |
| 2489 | refers to a file whose name is @file{~hack} in directory @file{/tmp}. |
| 2490 | |
| 2491 | Likewise, quoting with @samp{/:} is one way to enter in the minibuffer |
| 2492 | a file name that contains @samp{$}. However, the @samp{/:} must be at |
| 2493 | the beginning of the buffer in order to quote @samp{$}. |
| 2494 | |
| 2495 | @cindex wildcard characters in file names |
| 2496 | You can also quote wildcard characters with @samp{/:}, for visiting. |
| 2497 | For example, @file{/:/tmp/foo*bar} visits the file @file{/tmp/foo*bar}. |
| 2498 | However, in most cases you can simply type the wildcard characters for |
| 2499 | themselves. For example, if the only file name in @file{/tmp} that |
| 2500 | starts with @samp{foo} and ends with @samp{bar} is @file{foo*bar}, then |
| 2501 | specifying @file{/tmp/foo*bar} will visit just @file{/tmp/foo*bar}. |
| 2502 | Another way is to specify @file{/tmp/foo[*]bar}. |