1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<h4 class="subsection">Naming Backup Files</h4> <p>The functions in this section are documented mainly because you can customize the naming conventions for backup files by redefining them. If you change one, you probably need to change the rest. </p> <dl> <dt id="backup-file-name-p">Function: <strong>backup-file-name-p</strong> <em>filename</em>
</dt> <dd>
<p>This function returns a non-<code>nil</code> value if <var>filename</var> is a possible name for a backup file. It just checks the name, not whether a file with the name <var>filename</var> exists. </p> <div class="example"> <pre class="example">(backup-file-name-p "foo")
⇒ nil
</pre>
<pre class="example">(backup-file-name-p "foo~")
⇒ 3
</pre>
</div> <p>The standard definition of this function is as follows: </p> <div class="example"> <pre class="example">(defun backup-file-name-p (file)
"Return non-nil if FILE is a backup file \
name (numeric or not)..."
(string-match "~\\'" file))
</pre>
</div> <p>Thus, the function returns a non-<code>nil</code> value if the file name ends with a ‘<samp>~</samp>’. (We use a backslash to split the documentation string’s first line into two lines in the text, but produce just one line in the string itself.) </p> <p>This simple expression is placed in a separate function to make it easy to redefine for customization. </p>
</dd>
</dl> <dl> <dt id="make-backup-file-name">Function: <strong>make-backup-file-name</strong> <em>filename</em>
</dt> <dd>
<p>This function returns a string that is the name to use for a non-numbered backup file for file <var>filename</var>. On Unix, this is just <var>filename</var> with a tilde appended. </p> <p>The standard definition of this function, on most operating systems, is as follows: </p> <div class="example"> <pre class="example">(defun make-backup-file-name (file)
"Create the non-numeric backup file name for FILE..."
(concat file "~"))
</pre>
</div> <p>You can change the backup-file naming convention by redefining this function. The following example redefines <code>make-backup-file-name</code> to prepend a ‘<samp>.</samp>’ in addition to appending a tilde: </p> <div class="example"> <pre class="example">(defun make-backup-file-name (filename)
(expand-file-name
(concat "." (file-name-nondirectory filename) "~")
(file-name-directory filename)))
</pre>
<pre class="example">(make-backup-file-name "backups.texi")
⇒ ".backups.texi~"
</pre>
</div> <p>Some parts of Emacs, including some Dired commands, assume that backup file names end with ‘<samp>~</samp>’. If you do not follow that convention, it will not cause serious problems, but these commands may give less-than-desirable results. </p>
</dd>
</dl> <dl> <dt id="find-backup-file-name">Function: <strong>find-backup-file-name</strong> <em>filename</em>
</dt> <dd>
<p>This function computes the file name for a new backup file for <var>filename</var>. It may also propose certain existing backup files for deletion. <code>find-backup-file-name</code> returns a list whose <small>CAR</small> is the name for the new backup file and whose <small>CDR</small> is a list of backup files whose deletion is proposed. The value can also be <code>nil</code>, which means not to make a backup. </p> <p>Two variables, <code>kept-old-versions</code> and <code>kept-new-versions</code>, determine which backup versions should be kept. This function keeps those versions by excluding them from the <small>CDR</small> of the value. See <a href="numbered-backups">Numbered Backups</a>. </p> <p>In this example, the value says that <samp>~rms/foo.~5~</samp> is the name to use for the new backup file, and <samp>~rms/foo.~3~</samp> is an excess version that the caller should consider deleting now. </p> <div class="example"> <pre class="example">(find-backup-file-name "~rms/foo")
⇒ ("~rms/foo.~5~" "~rms/foo.~3~")
</pre>
</div> </dd>
</dl> <dl> <dt id="file-backup-file-names">Function: <strong>file-backup-file-names</strong> <em>filename</em>
</dt> <dd><p>This function returns a list of all the backup file names for <var>filename</var>, or <code>nil</code> if there are none. The files are sorted by modification time, descending, so that the most recent files are first. </p></dd>
</dl> <dl> <dt id="file-newest-backup">Function: <strong>file-newest-backup</strong> <em>filename</em>
</dt> <dd>
<p>This function returns the first element of the list returned by <code>file-backup-file-names</code>. </p> <p>Some file comparison commands use this function so that they can automatically compare a file with its most recent backup. </p>
</dd>
</dl><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Backup-Names.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Backup-Names.html</a>
</p>
</div>
|