comparison lispref/backups.texi @ 54711:12ff04cae768

Various small changes in addition to: (Making Backups): Mention return value of `backup-buffer'. (Auto-Saving): Mention optional FORCE argument to `delete-auto-save-file-if-necessary'. (Reverting): Mention optional PRESERVE-MODES argument to `revert-buffer'. Correct description of `revert-buffer-function'.
author Luc Teirlinck <teirllm@auburn.edu>
date Mon, 05 Apr 2004 01:28:57 +0000
parents 1a5c50faf357
children de3d06856d87
comparison
equal deleted inserted replaced
54710:a02f0e9c16be 54711:12ff04cae768
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
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 154 This variable's value is a function to use for making backups instead
147 of the default @code{make-backup-file-name}. A value of @code{nil} 155 of the default @code{make-backup-file-name}. A value of @code{nil}
148 gives the default @code{make-backup-file-name} behaviour. 156 gives the default @code{make-backup-file-name} behaviour.
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 two 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
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}.
516 This exists as a separate function so that you can redefine it to 526 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 527 customize the naming convention for auto-save files. Be sure to
518 change @code{auto-save-file-name-p} in a corresponding way. 528 change @code{auto-save-file-name-p} in a corresponding way.
519 @end defun 529 @end defun
520 530
521 @defvar auto-save-visited-file-name 531 @defopt auto-save-visited-file-name
522 If this variable is non-@code{nil}, Emacs auto-saves buffers in 532 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 533 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 534 file that you are editing. Normally, this variable is @code{nil}, so
525 auto-save files have distinct names that are created by 535 auto-save files have distinct names that are created by
526 @code{make-auto-save-file-name}. 536 @code{make-auto-save-file-name}.
528 When you change the value of this variable, the new value does not take 538 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 539 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 540 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 541 continue to go in the same file name until @code{auto-save-mode} is
532 called again. 542 called again.
533 @end defvar 543 @end defopt
534 544
535 @defun recent-auto-save-p 545 @defun recent-auto-save-p
536 This function returns @code{t} if the current buffer has been 546 This function returns @code{t} if the current buffer has been
537 auto-saved since the last time it was read in or saved. 547 auto-saved since the last time it was read in or saved.
538 @end defun 548 @end defun
545 555
546 @defopt auto-save-interval 556 @defopt auto-save-interval
547 The value of this variable specifies how often to do auto-saving, in 557 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 558 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 559 events are read, Emacs does auto-saving for all buffers in which that is
550 enabled. 560 enabled. Setting this to zero disables autosaving based on the
561 number of characters typed.
551 @end defopt 562 @end defopt
552 563
553 @defopt auto-save-timeout 564 @defopt auto-save-timeout
554 The value of this variable is the number of seconds of idle time that 565 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, 566 should cause auto-saving. Each time the user pauses for this long,
584 595
585 If @var{current-only} is non-@code{nil}, only the current buffer 596 If @var{current-only} is non-@code{nil}, only the current buffer
586 is auto-saved. 597 is auto-saved.
587 @end deffn 598 @end deffn
588 599
589 @defun delete-auto-save-file-if-necessary 600 @defun delete-auto-save-file-if-necessary &optional force
590 This function deletes the current buffer's auto-save file if 601 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 602 @code{delete-auto-save-files} is non-@code{nil}. It is called every
592 time a buffer is saved. 603 time a buffer is saved.
593 @end defun 604
594 605 Unless @var{force} is non-@code{nil}, this function only deletes the
595 @defvar delete-auto-save-files 606 file if it was written by the current Emacs session since the last
607 true save.
608 @end defun
609
610 @defopt delete-auto-save-files
596 This variable is used by the function 611 This variable is used by the function
597 @code{delete-auto-save-file-if-necessary}. If it is non-@code{nil}, 612 @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 613 Emacs deletes auto-save files when a true save is done (in the visited
599 file). This saves disk space and unclutters your directory. 614 file). This saves disk space and unclutters your directory.
600 @end defvar 615 @end defopt
601 616
602 @defun rename-auto-save-file 617 @defun rename-auto-save-file
603 This function adjusts the current buffer's auto-save file name if the 618 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 619 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 620 file, if it was made in the current Emacs session. If the visited
606 nothing. 621 file name has not changed, this function does nothing.
607 @end defun 622 @end defun
608 623
609 @defvar buffer-saved-size 624 @defvar buffer-saved-size
610 The value of this buffer-local variable is the length of the current 625 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 626 buffer, when it was last read in, saved, or auto-saved. This is
652 If you have made extensive changes to a file and then change your mind 667 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 668 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, , 669 of the file with the @code{revert-buffer} command. @xref{Reverting, ,
655 Reverting a Buffer, emacs, The GNU Emacs Manual}. 670 Reverting a Buffer, emacs, The GNU Emacs Manual}.
656 671
657 @deffn Command revert-buffer &optional ignore-auto noconfirm 672 @deffn Command revert-buffer &optional ignore-auto noconfirm preserve-modes
658 This command replaces the buffer text with the text of the visited 673 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 674 file on disk. This action undoes all changes since the file was visited
660 or saved. 675 or saved.
661 676
662 By default, if the latest auto-save file is more recent than the visited 677 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. 682 interactive default is not to check the auto-save file.
668 683
669 Normally, @code{revert-buffer} asks for confirmation before it changes 684 Normally, @code{revert-buffer} asks for confirmation before it changes
670 the buffer; but if the argument @var{noconfirm} is non-@code{nil}, 685 the buffer; but if the argument @var{noconfirm} is non-@code{nil},
671 @code{revert-buffer} does not ask for confirmation. 686 @code{revert-buffer} does not ask for confirmation.
687
688 Normally, this command reinitializes the file's major and minor modes
689 using @code{normal-mode}. But if @var{preserve-modes} is
690 non-@code{nil}, the modes remain unchanged.
672 691
673 Reverting tries to preserve marker positions in the buffer by using the 692 Reverting tries to preserve marker positions in the buffer by using the
674 replacement feature of @code{insert-file-contents}. If the buffer 693 replacement feature of @code{insert-file-contents}. If the buffer
675 contents and the file contents are identical before the revert 694 contents and the file contents are identical before the revert
676 operation, reverting preserves all the markers. If they are not 695 operation, reverting preserves all the markers. If they are not
680 @end deffn 699 @end deffn
681 700
682 You can customize how @code{revert-buffer} does its work by setting 701 You can customize how @code{revert-buffer} does its work by setting
683 the variables described in the rest of this section. 702 the variables described in the rest of this section.
684 703
685 @defvar revert-without-query 704 @defopt revert-without-query
686 This variable holds a list of files that should be reverted without 705 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 706 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 707 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} 708 on disk but the buffer is not modified, then @code{revert-buffer}
690 reverts the file without asking the user for confirmation. 709 reverts the file without asking the user for confirmation.
691 @end defvar 710 @end defopt
692 711
693 Some major modes customize @code{revert-buffer} by making 712 Some major modes customize @code{revert-buffer} by making
694 buffer-local bindings for these variables: 713 buffer-local bindings for these variables:
695 714
696 @defvar revert-buffer-function 715 @defvar revert-buffer-function
697 The value of this variable is the function to use to revert this buffer. 716 The value of this variable is the function to use to revert this
698 If non-@code{nil}, it is called as a function with no arguments to do 717 buffer. If non-@code{nil}, it should be a function with two optional
699 the work of reverting. If the value is @code{nil}, reverting works the 718 arguments to do the work of reverting. The two optional arguments,
700 usual way. 719 @var{ignore-auto} and @var{noconfirm}, are the arguments that
720 @code{revert-buffer} received. If the value is @code{nil}, reverting
721 works the usual way.
701 722
702 Modes such as Dired mode, in which the text being edited does not 723 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 724 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 725 fashion, can give this variable a buffer-local value that is a function to
705 regenerate the contents. 726 regenerate the contents.