From e45d8d77d38dfa85aa95be5758e8fb5b235e53d2 Mon Sep 17 00:00:00 2001 From: yamaoka Date: Mon, 31 Aug 1998 09:48:35 +0000 Subject: [PATCH] emu.el (with-temp-file): New macro. --- ChangeLog | 5 +++++ emu.el | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9158047..5a2b38d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1998-08-31 Katsumi Yamoaka + + * emu.el (with-temp-file): New macro (Emacs 20/XEmacs 20 + emulating macro). + 1998-08-29 Tanaka Akira * emu-e20.el: require 'ccl only for byte-compile time. diff --git a/emu.el b/emu.el index 73721c5..493c773 100644 --- a/emu.el +++ b/emu.el @@ -287,6 +287,26 @@ See also `with-temp-buffer'." (,@ body)))) ;; This macro was imported Emacs 20.2. +(defmacro-maybe with-temp-file (file &rest forms) + "Create a new buffer, evaluate FORMS there, and write the buffer to FILE. +The value of the last form in FORMS is returned, like `progn'. +See also `with-temp-buffer'." + (let ((temp-file (make-symbol "temp-file")) + (temp-buffer (make-symbol "temp-buffer"))) + `(let ((,temp-file ,file) + (,temp-buffer + (get-buffer-create (generate-new-buffer-name " *temp file*")))) + (unwind-protect + (prog1 + (with-current-buffer ,temp-buffer + ,@forms) + (with-current-buffer ,temp-buffer + (widen) + (write-region (point-min) (point-max) ,temp-file nil 0))) + (and (buffer-name ,temp-buffer) + (kill-buffer ,temp-buffer)))))) + +;; This macro was imported Emacs 20.2. (defmacro-maybe with-temp-buffer (&rest forms) "Create a temporary buffer, and evaluate FORMS there like `progn'. See also `with-temp-file' and `with-output-to-string'." -- 1.7.10.4