comparison lisp/subr.el @ 44945:27acb2b2a2a9

(make-temp-file): New arg SUFFIX.
author Richard M. Stallman <rms@gnu.org>
date Sun, 28 Apr 2002 22:29:38 +0000
parents e4975d9c93ff
children 5eb4aa56b278
comparison
equal deleted inserted replaced
44944:dbacf99cccc4 44945:27acb2b2a2a9
1841 (if (eq (car (car tail)) key) 1841 (if (eq (car (car tail)) key)
1842 (setq alist (delq (car tail) alist))) 1842 (setq alist (delq (car tail) alist)))
1843 (setq tail (cdr tail))) 1843 (setq tail (cdr tail)))
1844 alist)) 1844 alist))
1845 1845
1846 (defun make-temp-file (prefix &optional dir-flag) 1846 (defun make-temp-file (prefix &optional dir-flag suffix)
1847 "Create a temporary file. 1847 "Create a temporary file.
1848 The returned file name (created by appending some random characters at the end 1848 The returned file name (created by appending some random characters at the end
1849 of PREFIX, and expanding against `temporary-file-directory' if necessary, 1849 of PREFIX, and expanding against `temporary-file-directory' if necessary,
1850 is guaranteed to point to a newly created empty file. 1850 is guaranteed to point to a newly created empty file.
1851 You can then use `write-region' to write new data into the file. 1851 You can then use `write-region' to write new data into the file.
1852 1852
1853 If DIR-FLAG is non-nil, create a new empty directory instead of a file." 1853 If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1854
1855 If SUFFIX is non-nil, add that at the end of the file name."
1854 (let (file) 1856 (let (file)
1855 (while (condition-case () 1857 (while (condition-case ()
1856 (progn 1858 (progn
1857 (setq file 1859 (setq file
1858 (make-temp-name 1860 (make-temp-name
1859 (expand-file-name prefix temporary-file-directory))) 1861 (expand-file-name prefix temporary-file-directory)))
1862 (if suffix
1863 (setq file (concat file suffix)))
1860 (if dir-flag 1864 (if dir-flag
1861 (make-directory file) 1865 (make-directory file)
1862 (write-region "" nil file nil 'silent nil 'excl)) 1866 (write-region "" nil file nil 'silent nil 'excl))
1863 nil) 1867 nil)
1864 (file-already-exists t)) 1868 (file-already-exists t))