Some programs need to write temporary files. Here is the usual way to construct a name for such a file:
(make-temp-name (expand-file-name name-of-application temporary-file-directory))
The job of make-temp-name
is to prevent two different users or
two different jobs from trying to use the exact same file name. This
example uses the variable temporary-file-directory
to decide
where to put the temporary file. All Emacs Lisp programs should
use temporary-file-directory
for this purpose, to give the user
a uniform way to specify the directory for all temporary files.
(make-temp-name "/tmp/foo") => "/tmp/foo232J6v"
To prevent conflicts among different libraries running in the same
Emacs, each Lisp program that uses make-temp-name
should have its
own string. The number added to the end of string
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.
expand-file-name
is a good way to achieve that.
The default value is determined in a reasonable way for your operating
system; on GNU and Unix systems it is based on the TMP
and
TMPDIR
environment variables.
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.
Go to the first, previous, next, last section, table of contents.