Next: temporary-file-directory—a user option, Previous: with-temp-file, Up: Writing to Files [Index]
Some programs need to write temporary files. Here is the usual way to
construct a name for such a file. 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.
This function creates a temporary file and returns its name by adding to PREFIX some random characters that are different in each Emacs job.
a user-provided string that should be unique to this program; this helps Emacs generate a unique file name despite numerous programs in different jobs running simultaneously and using this macro.
if non-nil, create a new, empty directory instead of a file.
if non-nil, it is added to the end of the file name.
if a string, insert it into the new file before returning; DIR-FLAG should be nil;
if nil, leave the file empty.
the newly-created file name pointing to a new-created file that is empty unless TEXT contains a string, in which case the file contains TEXT.
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)))