| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Some programs need to write temporary files. Here is the usual way to construct a name for such a file, starting in Emacs 21:
(make-temp-file name-of-application) |
The job of make-temp-file is to prevent two different users or
two different jobs from trying to use the exact same file name.
temporary-file-directory.
(make-temp-file "foo")
=> "/tmp/foo232J6v"
|
When make-temp-file returns, the file has been created and is
empty. At that point, you should write the intended contents into the
file.
If dir-flag is non-nil, make-temp-file creates
an empty directory instead of an empty file.
To prevent conflicts among different libraries running in the same
Emacs, each Lisp program that uses make-temp-file should have its
own prefix. The number added to the end of prefix
distinguishes between the same application running in different Emacs
jobs. Additional added characters permit a large number of distinct
names even in one Emacs job.
The default directory for temporary files is controlled by the
variable temporary-file-directory. This variable gives the user
a uniform way to specify the directory for all temporary files. Some
programs use small-temporary-file-directory instead, if that is
non-nil. To use it, you should expand the prefix against
the proper directory before calling make-temp-file.
In older Emacs versions where make-temp-file does not exist,
you should use make-temp-name instead:
(make-temp-name
(expand-file-name name-of-application
temporary-file-directory))
|
make-temp-file except
that it just constructs a name, and does not create a file. On MS-DOS,
the string prefix can be truncated to fit into the 8+3 file-name
limits.
expand-file-name is a good way to achieve that.
The default value is determined in a reasonable way for your operating
system; it is based on the TMPDIR, TMP and TEMP
environment variables, with a fall-back to a system-dependent name if
none of these variables is defined.
Even if you do not use make-temp-name to choose the temporary
file's name, you should still use this variable to decide which
directory to put the file in. However, if you expect the file to be
small, you should use small-temporary-file-directory first if
that is non-nil.
If you want to write a temporary file which is likely to be small, you should compute the directory like this:
(make-temp-file
(expand-file-name prefix
(or small-temporary-file-directory
temporary-file-directory)))
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |