Function: with-temp-file
with-temp-file is a macro defined in subr.el.gz.
Signature
(with-temp-file FILE &rest BODY)
Documentation
Create a new buffer, evaluate BODY there, and write the buffer to FILE.
The value returned is the value of the last form in BODY.
The buffer does not run the hooks kill-buffer-hook,
kill-buffer-query-functions, and buffer-list-update-hook.
See also with-temp-buffer.
Probably introduced at or before Emacs version 20.1.
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defmacro with-temp-file (file &rest body)
"Create a new buffer, evaluate BODY there, and write the buffer to FILE.
The value returned is the value of the last form in BODY.
The buffer does not run the hooks `kill-buffer-hook',
`kill-buffer-query-functions', and `buffer-list-update-hook'.
See also `with-temp-buffer'."
(declare (indent 1) (debug t))
(let ((temp-file (make-symbol "temp-file"))
(temp-buffer (make-symbol "temp-buffer")))
`(let ((,temp-file ,file)
(,temp-buffer (generate-new-buffer " *temp file*" t)))
(unwind-protect
(prog1
(with-current-buffer ,temp-buffer
,@body)
(with-current-buffer ,temp-buffer
(write-region nil nil ,temp-file nil 0)))
(and (buffer-name ,temp-buffer)
(kill-buffer ,temp-buffer))))))