diff options
| author | Richard M. Stallman | 1999-09-11 01:08:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1999-09-11 01:08:15 +0000 |
| commit | cdd9f64394f26d60c2c0ffe99719f8df9586ed80 (patch) | |
| tree | 0f7ec636b39c9c3b5e418d4eefb92e4e0a4ac45a | |
| parent | e596094db5644575a362e7cbbd233d3f6432e81f (diff) | |
| download | emacs-cdd9f64394f26d60c2c0ffe99719f8df9586ed80.tar.gz emacs-cdd9f64394f26d60c2c0ffe99719f8df9586ed80.zip | |
(make-temp-file): New function.
| -rw-r--r-- | lisp/subr.el | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 7f145861ab3..8ade8bc85de 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1302,4 +1302,28 @@ Return the modified alist." | |||
| 1302 | (setq tail (cdr tail))) | 1302 | (setq tail (cdr tail))) |
| 1303 | alist)) | 1303 | alist)) |
| 1304 | 1304 | ||
| 1305 | (defun make-temp-file (prefix &optional dir-flag) | ||
| 1306 | "Create a temporary file. | ||
| 1307 | The returned file name (created by appending some random characters at the end | ||
| 1308 | of PREFIX, and expanding against `temporary-file-directory' if necessary, | ||
| 1309 | is guaranteed to point to a newly created empty file. | ||
| 1310 | You can then use `write-region' to write new data into the file. | ||
| 1311 | |||
| 1312 | If DIR-FLAG is non-nil, create a new empty directory instead of a file." | ||
| 1313 | (let (file) | ||
| 1314 | (while (condition-case () | ||
| 1315 | (progn | ||
| 1316 | (setq file | ||
| 1317 | (make-temp-name | ||
| 1318 | (expand-file-name prefix temporary-file-directory))) | ||
| 1319 | (if dir-flag | ||
| 1320 | (make-directory file) | ||
| 1321 | (write-region "" nil file nil 'silent nil 'excl)) | ||
| 1322 | nil) | ||
| 1323 | (file-already-exists t)) | ||
| 1324 | ;; the file was somehow created by someone else between | ||
| 1325 | ;; `make-temp-name' and `write-region', let's try again. | ||
| 1326 | nil) | ||
| 1327 | file)) | ||
| 1328 | |||
| 1305 | ;;; subr.el ends here | 1329 | ;;; subr.el ends here |