comparison lispref/backups.texi @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 23a1cea22d13
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 @c -*-texinfo-*- 1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual. 2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1999 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2002, 2003, 2004,
4 @c Free Software Foundation, Inc. 4 @c 2005 Free Software Foundation, Inc.
5 @c See the file elisp.texi for copying conditions. 5 @c See the file elisp.texi for copying conditions.
6 @setfilename ../info/backups 6 @setfilename ../info/backups
7 @node Backups and Auto-Saving, Buffers, Files, Top 7 @node Backups and Auto-Saving, Buffers, Files, Top
8 @chapter Backups and Auto-Saving 8 @chapter Backups and Auto-Saving
9 9
53 53
54 @defun backup-buffer 54 @defun backup-buffer
55 This function makes a backup of the file visited by the current 55 This function makes a backup of the file visited by the current
56 buffer, if appropriate. It is called by @code{save-buffer} before 56 buffer, if appropriate. It is called by @code{save-buffer} before
57 saving the buffer the first time. 57 saving the buffer the first time.
58
59 If a backup was made by renaming, the return value is a cons cell of
60 the form (@var{modes} . @var{backupname}), where @var{modes} are the
61 mode bits of the original file, as returned by @code{file-modes}
62 (@pxref{File Attributes,, Other Information about Files}), and
63 @var{backupname} is the name of the backup. In all other cases, that
64 is, if a backup was made by copying or if no backup was made, this
65 function returns @code{nil}.
58 @end defun 66 @end defun
59 67
60 @defvar buffer-backed-up 68 @defvar buffer-backed-up
61 This buffer-local variable indicates whether this buffer's file has 69 This buffer-local variable indicates whether this buffer's file has
62 been backed up on account of this buffer. If it is non-@code{nil}, then 70 been backed up on account of this buffer. If it is non-@code{nil}, then
88 @end defopt 96 @end defopt
89 97
90 @defvar backup-enable-predicate 98 @defvar backup-enable-predicate
91 This variable's value is a function to be called on certain occasions to 99 This variable's value is a function to be called on certain occasions to
92 decide whether a file should have backup files. The function receives 100 decide whether a file should have backup files. The function receives
93 one argument, a file name to consider. If the function returns 101 one argument, an absolute file name to consider. If the function returns
94 @code{nil}, backups are disabled for that file. Otherwise, the other 102 @code{nil}, backups are disabled for that file. Otherwise, the other
95 variables in this section say whether and how to make backups. 103 variables in this section say whether and how to make backups.
96 104
97 @findex normal-backup-enable-predicate 105 @findex normal-backup-enable-predicate
98 The default value is @code{normal-backup-enable-predicate}, which checks 106 The default value is @code{normal-backup-enable-predicate}, which checks
141 ignored. 149 ignored.
142 @end defvar 150 @end defvar
143 151
144 @defvar make-backup-file-name-function 152 @defvar make-backup-file-name-function
145 @tindex make-backup-file-name-function 153 @tindex make-backup-file-name-function
146 This variable's value is a function to use for making backups instead of 154 This variable's value is a function to use for making backups instead
147 the default @code{make-backup-file-name}. A value of nil gives the 155 of the default @code{make-backup-file-name}. A value of @code{nil}
148 default @code{make-backup-file-name} behaviour. 156 gives the default @code{make-backup-file-name} behavior.
157 @xref{Backup Names,, Naming Backup Files}.
149 158
150 This could be buffer-local to do something special for specific 159 This could be buffer-local to do something special for specific
151 files. If you define it, you may need to change 160 files. If you define it, you may need to change
152 @code{backup-file-name-p} and @code{file-name-sans-versions} too. 161 @code{backup-file-name-p} and @code{file-name-sans-versions} too.
153 @end defvar 162 @end defvar
182 the second method, which is to copy the original file and overwrite it 191 the second method, which is to copy the original file and overwrite it
183 with the new buffer contents. The variable @code{file-precious-flag}, 192 with the new buffer contents. The variable @code{file-precious-flag},
184 if non-@code{nil}, also has this effect (as a sideline of its main 193 if non-@code{nil}, also has this effect (as a sideline of its main
185 significance). @xref{Saving Buffers}. 194 significance). @xref{Saving Buffers}.
186 195
187 @defvar backup-by-copying 196 @defopt backup-by-copying
188 If this variable is non-@code{nil}, Emacs always makes backup files by 197 If this variable is non-@code{nil}, Emacs always makes backup files by
189 copying. 198 copying.
190 @end defvar 199 @end defopt
191 200
192 The following two variables, when non-@code{nil}, cause the second 201 The following three variables, when non-@code{nil}, cause the second
193 method to be used in certain special cases. They have no effect on the 202 method to be used in certain special cases. They have no effect on the
194 treatment of files that don't fall into the special cases. 203 treatment of files that don't fall into the special cases.
195 204
196 @defvar backup-by-copying-when-linked 205 @defopt backup-by-copying-when-linked
197 If this variable is non-@code{nil}, Emacs makes backups by copying for 206 If this variable is non-@code{nil}, Emacs makes backups by copying for
198 files with multiple names (hard links). 207 files with multiple names (hard links).
199 208
200 This variable is significant only if @code{backup-by-copying} is 209 This variable is significant only if @code{backup-by-copying} is
201 @code{nil}, since copying is always used when that variable is 210 @code{nil}, since copying is always used when that variable is
202 non-@code{nil}. 211 non-@code{nil}.
203 @end defvar 212 @end defopt
204 213
205 @defvar backup-by-copying-when-mismatch 214 @defopt backup-by-copying-when-mismatch
206 If this variable is non-@code{nil}, Emacs makes backups by copying in cases 215 If this variable is non-@code{nil}, Emacs makes backups by copying in cases
207 where renaming would change either the owner or the group of the file. 216 where renaming would change either the owner or the group of the file.
208 217
209 The value has no effect when renaming would not alter the owner or 218 The value has no effect when renaming would not alter the owner or
210 group of the file; that is, for files which are owned by the user and 219 group of the file; that is, for files which are owned by the user and
212 user. 221 user.
213 222
214 This variable is significant only if @code{backup-by-copying} is 223 This variable is significant only if @code{backup-by-copying} is
215 @code{nil}, since copying is always used when that variable is 224 @code{nil}, since copying is always used when that variable is
216 non-@code{nil}. 225 non-@code{nil}.
217 @end defvar 226 @end defopt
218 227
219 @defvar backup-by-copying-when-privileged-mismatch 228 @defopt backup-by-copying-when-privileged-mismatch
220 This variable, if non-@code{nil}, specifies the same behavior as 229 This variable, if non-@code{nil}, specifies the same behavior as
221 @code{backup-by-copying-when-mismatch}, but only for certain user-id 230 @code{backup-by-copying-when-mismatch}, but only for certain user-id
222 values: namely, those less than or equal to a certain number. You set 231 values: namely, those less than or equal to a certain number. You set
223 this variable to that number. 232 this variable to that number.
224 233
225 Thus, if you set @code{backup-by-copying-when-privileged-mismatch} 234 Thus, if you set @code{backup-by-copying-when-privileged-mismatch}
226 to 0, backup by copying is done for the superuser only, 235 to 0, backup by copying is done for the superuser only,
227 when necessary to prevent a change in the owner of the file. 236 when necessary to prevent a change in the owner of the file.
228 237
229 The default is 200. 238 The default is 200.
230 @end defvar 239 @end defopt
231 240
232 @node Numbered Backups 241 @node Numbered Backups
233 @subsection Making and Deleting Numbered Backup Files 242 @subsection Making and Deleting Numbered Backup Files
234 243
235 If a file's name is @file{foo}, the names of its numbered backup 244 If a file's name is @file{foo}, the names of its numbered backup
242 file or multiple numbered backups. 251 file or multiple numbered backups.
243 252
244 @table @asis 253 @table @asis
245 @item @code{nil} 254 @item @code{nil}
246 Make numbered backups if the visited file already has numbered backups; 255 Make numbered backups if the visited file already has numbered backups;
247 otherwise, do not. 256 otherwise, do not. This is the default.
248 257
249 @item @code{never} 258 @item @code{never}
250 Do not make numbered backups. 259 Do not make numbered backups.
251 260
252 @item @var{anything else} 261 @item @var{anything else}
377 @defun find-backup-file-name filename 386 @defun find-backup-file-name filename
378 This function computes the file name for a new backup file for 387 This function computes the file name for a new backup file for
379 @var{filename}. It may also propose certain existing backup files for 388 @var{filename}. It may also propose certain existing backup files for
380 deletion. @code{find-backup-file-name} returns a list whose @sc{car} is 389 deletion. @code{find-backup-file-name} returns a list whose @sc{car} is
381 the name for the new backup file and whose @sc{cdr} is a list of backup 390 the name for the new backup file and whose @sc{cdr} is a list of backup
382 files whose deletion is proposed. 391 files whose deletion is proposed. The value can also be @code{nil},
392 which means not to make a backup.
383 393
384 Two variables, @code{kept-old-versions} and @code{kept-new-versions}, 394 Two variables, @code{kept-old-versions} and @code{kept-new-versions},
385 determine which backup versions should be kept. This function keeps 395 determine which backup versions should be kept. This function keeps
386 those versions by excluding them from the @sc{cdr} of the value. 396 those versions by excluding them from the @sc{cdr} of the value.
387 @xref{Numbered Backups}. 397 @xref{Numbered Backups}.
413 423
414 Emacs periodically saves all files that you are visiting; this is 424 Emacs periodically saves all files that you are visiting; this is
415 called @dfn{auto-saving}. Auto-saving prevents you from losing more 425 called @dfn{auto-saving}. Auto-saving prevents you from losing more
416 than a limited amount of work if the system crashes. By default, 426 than a limited amount of work if the system crashes. By default,
417 auto-saves happen every 300 keystrokes, or after around 30 seconds of 427 auto-saves happen every 300 keystrokes, or after around 30 seconds of
418 idle time. @xref{Auto-Save, Auto-Save, Auto-Saving: Protection Against 428 idle time. @xref{Auto Save, Auto Save, Auto-Saving: Protection Against
419 Disasters, emacs, The GNU Emacs Manual}, for information on auto-save 429 Disasters, emacs, The GNU Emacs Manual}, for information on auto-save
420 for users. Here we describe the functions used to implement auto-saving 430 for users. Here we describe the functions used to implement auto-saving
421 and the variables that control them. 431 and the variables that control them.
422 432
423 @defvar buffer-auto-save-file-name 433 @defvar buffer-auto-save-file-name
491 (make-auto-save-file-name) 501 (make-auto-save-file-name)
492 @result{} "/xcssun/users/rms/lewis/#backups.texi#" 502 @result{} "/xcssun/users/rms/lewis/#backups.texi#"
493 @end group 503 @end group
494 @end example 504 @end example
495 505
496 The standard definition of this function is as follows: 506 Here is a simplified version of the standard definition of this
507 function:
497 508
498 @example 509 @example
499 @group 510 @group
500 (defun make-auto-save-file-name () 511 (defun make-auto-save-file-name ()
501 "Return file name to use for auto-saves \ 512 "Return file name to use for auto-saves \
516 This exists as a separate function so that you can redefine it to 527 This exists as a separate function so that you can redefine it to
517 customize the naming convention for auto-save files. Be sure to 528 customize the naming convention for auto-save files. Be sure to
518 change @code{auto-save-file-name-p} in a corresponding way. 529 change @code{auto-save-file-name-p} in a corresponding way.
519 @end defun 530 @end defun
520 531
521 @defvar auto-save-visited-file-name 532 @defopt auto-save-visited-file-name
522 If this variable is non-@code{nil}, Emacs auto-saves buffers in 533 If this variable is non-@code{nil}, Emacs auto-saves buffers in
523 the files they are visiting. That is, the auto-save is done in the same 534 the files they are visiting. That is, the auto-save is done in the same
524 file that you are editing. Normally, this variable is @code{nil}, so 535 file that you are editing. Normally, this variable is @code{nil}, so
525 auto-save files have distinct names that are created by 536 auto-save files have distinct names that are created by
526 @code{make-auto-save-file-name}. 537 @code{make-auto-save-file-name}.
528 When you change the value of this variable, the new value does not take 539 When you change the value of this variable, the new value does not take
529 effect in an existing buffer until the next time auto-save mode is 540 effect in an existing buffer until the next time auto-save mode is
530 reenabled in it. If auto-save mode is already enabled, auto-saves 541 reenabled in it. If auto-save mode is already enabled, auto-saves
531 continue to go in the same file name until @code{auto-save-mode} is 542 continue to go in the same file name until @code{auto-save-mode} is
532 called again. 543 called again.
533 @end defvar 544 @end defopt
534 545
535 @defun recent-auto-save-p 546 @defun recent-auto-save-p
536 This function returns @code{t} if the current buffer has been 547 This function returns @code{t} if the current buffer has been
537 auto-saved since the last time it was read in or saved. 548 auto-saved since the last time it was read in or saved.
538 @end defun 549 @end defun
545 556
546 @defopt auto-save-interval 557 @defopt auto-save-interval
547 The value of this variable specifies how often to do auto-saving, in 558 The value of this variable specifies how often to do auto-saving, in
548 terms of number of input events. Each time this many additional input 559 terms of number of input events. Each time this many additional input
549 events are read, Emacs does auto-saving for all buffers in which that is 560 events are read, Emacs does auto-saving for all buffers in which that is
550 enabled. 561 enabled. Setting this to zero disables autosaving based on the
562 number of characters typed.
551 @end defopt 563 @end defopt
552 564
553 @defopt auto-save-timeout 565 @defopt auto-save-timeout
554 The value of this variable is the number of seconds of idle time that 566 The value of this variable is the number of seconds of idle time that
555 should cause auto-saving. Each time the user pauses for this long, 567 should cause auto-saving. Each time the user pauses for this long,
556 Emacs does auto-saving for all buffers in which that is enabled. (If 568 Emacs does auto-saving for all buffers in which that is enabled. (If
557 the current buffer is large, the specified timeout is multiplied by a 569 the current buffer is large, the specified timeout is multiplied by a
558 factor that increases as the size increases; for a million-byte 570 factor that increases as the size increases; for a million-byte
559 buffer, the factor is almost 4.) 571 buffer, the factor is almost 4.)
560 572
561 If the value is zero or nil, then auto-saving is not done as a result 573 If the value is zero or @code{nil}, then auto-saving is not done as a
562 of idleness, only after a certain number of input events 574 result of idleness, only after a certain number of input events as
563 as specified by @code{auto-save-interval}. 575 specified by @code{auto-save-interval}.
564 @end defopt 576 @end defopt
565 577
566 @defvar auto-save-hook 578 @defvar auto-save-hook
567 This normal hook is run whenever an auto-save is about to happen. 579 This normal hook is run whenever an auto-save is about to happen.
568 @end defvar 580 @end defvar
575 @deffn Command do-auto-save &optional no-message current-only 587 @deffn Command do-auto-save &optional no-message current-only
576 This function auto-saves all buffers that need to be auto-saved. It 588 This function auto-saves all buffers that need to be auto-saved. It
577 saves all buffers for which auto-saving is enabled and that have been 589 saves all buffers for which auto-saving is enabled and that have been
578 changed since the previous auto-save. 590 changed since the previous auto-save.
579 591
580 Normally, if any buffers are auto-saved, a message that says 592 If any buffers are auto-saved, @code{do-auto-save} normally displays a
581 @samp{Auto-saving...} is displayed in the echo area while auto-saving is 593 message saying @samp{Auto-saving...} in the echo area while
582 going on. However, if @var{no-message} is non-@code{nil}, the message 594 auto-saving is going on. However, if @var{no-message} is
583 is inhibited. 595 non-@code{nil}, the message is inhibited.
584 596
585 If @var{current-only} is non-@code{nil}, only the current buffer 597 If @var{current-only} is non-@code{nil}, only the current buffer
586 is auto-saved. 598 is auto-saved.
587 @end deffn 599 @end deffn
588 600
589 @defun delete-auto-save-file-if-necessary 601 @defun delete-auto-save-file-if-necessary &optional force
590 This function deletes the current buffer's auto-save file if 602 This function deletes the current buffer's auto-save file if
591 @code{delete-auto-save-files} is non-@code{nil}. It is called every 603 @code{delete-auto-save-files} is non-@code{nil}. It is called every
592 time a buffer is saved. 604 time a buffer is saved.
593 @end defun 605
594 606 Unless @var{force} is non-@code{nil}, this function only deletes the
595 @defvar delete-auto-save-files 607 file if it was written by the current Emacs session since the last
608 true save.
609 @end defun
610
611 @defopt delete-auto-save-files
596 This variable is used by the function 612 This variable is used by the function
597 @code{delete-auto-save-file-if-necessary}. If it is non-@code{nil}, 613 @code{delete-auto-save-file-if-necessary}. If it is non-@code{nil},
598 Emacs deletes auto-save files when a true save is done (in the visited 614 Emacs deletes auto-save files when a true save is done (in the visited
599 file). This saves disk space and unclutters your directory. 615 file). This saves disk space and unclutters your directory.
600 @end defvar 616 @end defopt
601 617
602 @defun rename-auto-save-file 618 @defun rename-auto-save-file
603 This function adjusts the current buffer's auto-save file name if the 619 This function adjusts the current buffer's auto-save file name if the
604 visited file name has changed. It also renames an existing auto-save 620 visited file name has changed. It also renames an existing auto-save
605 file. If the visited file name has not changed, this function does 621 file, if it was made in the current Emacs session. If the visited
606 nothing. 622 file name has not changed, this function does nothing.
607 @end defun 623 @end defun
608 624
609 @defvar buffer-saved-size 625 @defvar buffer-saved-size
610 The value of this buffer-local variable is the length of the current 626 The value of this buffer-local variable is the length of the current
611 buffer, when it was last read in, saved, or auto-saved. This is 627 buffer, when it was last read in, saved, or auto-saved. This is
631 can look in the file to find all the auto-save files that might contain 647 can look in the file to find all the auto-save files that might contain
632 work that was otherwise lost. The @code{recover-session} command uses 648 work that was otherwise lost. The @code{recover-session} command uses
633 this file to find them. 649 this file to find them.
634 650
635 The default name for this file specifies your home directory and starts 651 The default name for this file specifies your home directory and starts
636 with @samp{.saves-}. It also contains the Emacs process @sc{id} and the 652 with @samp{.saves-}. It also contains the Emacs process @acronym{ID} and the
637 host name. 653 host name.
638 @end defvar 654 @end defvar
639 655
640 @defvar auto-save-list-file-prefix 656 @defvar auto-save-list-file-prefix
641 @tindex auto-save-list-file-prefix 657 @tindex auto-save-list-file-prefix
652 If you have made extensive changes to a file and then change your mind 668 If you have made extensive changes to a file and then change your mind
653 about them, you can get rid of them by reading in the previous version 669 about them, you can get rid of them by reading in the previous version
654 of the file with the @code{revert-buffer} command. @xref{Reverting, , 670 of the file with the @code{revert-buffer} command. @xref{Reverting, ,
655 Reverting a Buffer, emacs, The GNU Emacs Manual}. 671 Reverting a Buffer, emacs, The GNU Emacs Manual}.
656 672
657 @deffn Command revert-buffer &optional ignore-auto noconfirm 673 @deffn Command revert-buffer &optional ignore-auto noconfirm preserve-modes
658 This command replaces the buffer text with the text of the visited 674 This command replaces the buffer text with the text of the visited
659 file on disk. This action undoes all changes since the file was visited 675 file on disk. This action undoes all changes since the file was visited
660 or saved. 676 or saved.
661 677
662 By default, if the latest auto-save file is more recent than the visited 678 By default, if the latest auto-save file is more recent than the visited
667 interactive default is not to check the auto-save file. 683 interactive default is not to check the auto-save file.
668 684
669 Normally, @code{revert-buffer} asks for confirmation before it changes 685 Normally, @code{revert-buffer} asks for confirmation before it changes
670 the buffer; but if the argument @var{noconfirm} is non-@code{nil}, 686 the buffer; but if the argument @var{noconfirm} is non-@code{nil},
671 @code{revert-buffer} does not ask for confirmation. 687 @code{revert-buffer} does not ask for confirmation.
688
689 Normally, this command reinitializes the file's major and minor modes
690 using @code{normal-mode}. But if @var{preserve-modes} is
691 non-@code{nil}, the modes remain unchanged.
672 692
673 Reverting tries to preserve marker positions in the buffer by using the 693 Reverting tries to preserve marker positions in the buffer by using the
674 replacement feature of @code{insert-file-contents}. If the buffer 694 replacement feature of @code{insert-file-contents}. If the buffer
675 contents and the file contents are identical before the revert 695 contents and the file contents are identical before the revert
676 operation, reverting preserves all the markers. If they are not 696 operation, reverting preserves all the markers. If they are not
680 @end deffn 700 @end deffn
681 701
682 You can customize how @code{revert-buffer} does its work by setting 702 You can customize how @code{revert-buffer} does its work by setting
683 the variables described in the rest of this section. 703 the variables described in the rest of this section.
684 704
685 @defvar revert-without-query 705 @defopt revert-without-query
686 This variable holds a list of files that should be reverted without 706 This variable holds a list of files that should be reverted without
687 query. The value is a list of regular expressions. If the visited file 707 query. The value is a list of regular expressions. If the visited file
688 name matches one of these regular expressions, and the file has changed 708 name matches one of these regular expressions, and the file has changed
689 on disk but the buffer is not modified, then @code{revert-buffer} 709 on disk but the buffer is not modified, then @code{revert-buffer}
690 reverts the file without asking the user for confirmation. 710 reverts the file without asking the user for confirmation.
691 @end defvar 711 @end defopt
692 712
693 Some major modes customize @code{revert-buffer} by making 713 Some major modes customize @code{revert-buffer} by making
694 buffer-local bindings for these variables: 714 buffer-local bindings for these variables:
695 715
696 @defvar revert-buffer-function 716 @defvar revert-buffer-function
697 The value of this variable is the function to use to revert this buffer. 717 @anchor{Definition of revert-buffer-function}
698 If non-@code{nil}, it is called as a function with no arguments to do 718 The value of this variable is the function to use to revert this
699 the work of reverting. If the value is @code{nil}, reverting works the 719 buffer. If non-@code{nil}, it should be a function with two optional
700 usual way. 720 arguments to do the work of reverting. The two optional arguments,
721 @var{ignore-auto} and @var{noconfirm}, are the arguments that
722 @code{revert-buffer} received. If the value is @code{nil}, reverting
723 works the usual way.
701 724
702 Modes such as Dired mode, in which the text being edited does not 725 Modes such as Dired mode, in which the text being edited does not
703 consist of a file's contents but can be regenerated in some other 726 consist of a file's contents but can be regenerated in some other
704 fashion, can give this variable a buffer-local value that is a function to 727 fashion, can give this variable a buffer-local value that is a function to
705 regenerate the contents. 728 regenerate the contents.
727 @defvar after-revert-hook 750 @defvar after-revert-hook
728 This normal hook is run by @code{revert-buffer} after inserting 751 This normal hook is run by @code{revert-buffer} after inserting
729 the modified contents---but only if @code{revert-buffer-function} is 752 the modified contents---but only if @code{revert-buffer-function} is
730 @code{nil}. 753 @code{nil}.
731 @end defvar 754 @end defvar
755
756 @ignore
757 arch-tag: 295a6321-e5ab-46d5-aef5-0bb4f447a67f
758 @end ignore