Mercurial > hg > xemacs-beta
comparison lisp/files.el @ 4266:c5a2b80bc4fa
[xemacs-hg @ 2007-11-14 18:51:20 by aidan]
Import make-temp-name (the functionality of mkstemp(3)) from GNU.
author | aidan |
---|---|
date | Wed, 14 Nov 2007 18:51:31 +0000 |
parents | 346788f5aa64 |
children | 555e21a66d51 |
comparison
equal
deleted
inserted
replaced
4265:dc697b1b786f | 4266:c5a2b80bc4fa |
---|---|
161 :type '(choice (const nil) integer) | 161 :type '(choice (const nil) integer) |
162 :group 'backup) | 162 :group 'backup) |
163 | 163 |
164 (defun normal-backup-enable-predicate (name) | 164 (defun normal-backup-enable-predicate (name) |
165 "Default `backup-enable-predicate' function. | 165 "Default `backup-enable-predicate' function. |
166 Checks for files in `temporary-file-directory' or | 166 Checks for files in the directory returned by `temp-directory' or specified |
167 `small-temporary-file-directory'." | 167 by `small-temporary-file-directory'." |
168 (let ((temporary-file-directory (temp-directory))) | 168 (let ((temporary-file-directory (temp-directory))) |
169 (not (or (let ((comp (compare-strings temporary-file-directory 0 nil | 169 (not (or (let ((comp (compare-strings temporary-file-directory 0 nil |
170 name 0 nil))) | 170 name 0 nil))) |
171 ;; Directory is under temporary-file-directory. | 171 ;; Directory is under temporary-file-directory. |
172 (and (not (eq comp t)) | 172 (and (not (eq comp t)) |
328 matching part with REPLACEMENT. | 328 matching part with REPLACEMENT. |
329 All the transforms in the list are tried, in the order they are listed. | 329 All the transforms in the list are tried, in the order they are listed. |
330 When one transform applies, its result is final; | 330 When one transform applies, its result is final; |
331 no further transforms are tried. | 331 no further transforms are tried. |
332 | 332 |
333 The default value is set up to put the auto-save file into the | 333 The default value is set up to put the auto-save file into the temporary |
334 temporary directory (see the variable `temporary-file-directory') for | 334 directory (see the function `temp-directory') for editing a remote file." |
335 editing a remote file." | |
336 :group 'auto-save | 335 :group 'auto-save |
337 :type '(repeat (list (string :tag "Regexp") (string :tag "Replacement"))) | 336 :type '(repeat (list (string :tag "Regexp") (string :tag "Replacement"))) |
338 ;:version "21.1" | 337 ;:version "21.1" |
339 ) | 338 ) |
340 | 339 |
713 (directory-file-name | 712 (directory-file-name |
714 (file-name-directory newname)))))))) | 713 (file-name-directory newname)))))))) |
715 (setq newname (expand-file-name tem (file-name-directory newname))) | 714 (setq newname (expand-file-name tem (file-name-directory newname))) |
716 (setq count (1- count)))) | 715 (setq count (1- count)))) |
717 newname)) | 716 newname)) |
717 | |
718 (defun make-temp-file (prefix &optional dir-flag suffix) | |
719 "Create a temporary file. | |
720 The returned file name (created by appending some random characters at the | |
721 end of PREFIX, and expanding against the return value of `temp-directory' if | |
722 necessary), is guaranteed to point to a newly created empty file. You can | |
723 then use `write-region' to write new data into the file. | |
724 | |
725 If DIR-FLAG is non-nil, create a new empty directory instead of a file. | |
726 | |
727 If SUFFIX is non-nil, add that at the end of the file name. | |
728 | |
729 This function is analagous to mkstemp(3) under POSIX, avoiding the race | |
730 condition between testing for the existence of the generated filename (under | |
731 POSIX with mktemp(3), under Emacs Lisp with `make-temp-name') and creating | |
732 it." | |
733 (let ((umask (default-file-modes)) | |
734 (temporary-file-directory (temp-directory)) | |
735 file) | |
736 (unwind-protect | |
737 (progn | |
738 ;; Create temp files with strict access rights. It's easy to | |
739 ;; loosen them later, whereas it's impossible to close the | |
740 ;; time-window of loose permissions otherwise. | |
741 (set-default-file-modes #o700) | |
742 (while (condition-case () | |
743 (progn | |
744 (setq file | |
745 (make-temp-name | |
746 (expand-file-name prefix | |
747 temporary-file-directory))) | |
748 (if suffix | |
749 (setq file (concat file suffix))) | |
750 (if dir-flag | |
751 (make-directory file) | |
752 (write-region "" nil file nil 'silent nil 'excl)) | |
753 nil) | |
754 (file-already-exists t)) | |
755 ;; the file was somehow created by someone else between | |
756 ;; `make-temp-name' and `write-region', let's try again. | |
757 nil) | |
758 file) | |
759 ;; Reset the umask. | |
760 (set-default-file-modes umask)))) | |
761 | |
718 | 762 |
719 (defun switch-to-other-buffer (arg) | 763 (defun switch-to-other-buffer (arg) |
720 "Switch to the previous buffer. With a numeric arg, n, switch to the nth | 764 "Switch to the previous buffer. With a numeric arg, n, switch to the nth |
721 most recent buffer. With an arg of 0, buries the current buffer at the | 765 most recent buffer. With an arg of 0, buries the current buffer at the |
722 bottom of the buffer stack." | 766 bottom of the buffer stack." |