changeset 1037:3a01f3148bff

[xemacs-hg @ 2002-10-08 03:24:18 by youngs] 2002-09-03 John Paul Wallington <jpw@shootybangbang.com> * subr.el (with-output-to-string): Synch with GNU Emacs 21; avoids leaking temp buffers by killing rather than erasing them, and doesn't execute BODY in temporary `standard-output' buffer.
author youngs
date Tue, 08 Oct 2002 03:24:22 +0000
parents b33a835c21cc
children 4bc5bb3ea5ad
files lisp/ChangeLog lisp/subr.el
diffstat 2 files changed, 17 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Oct 08 03:11:49 2002 +0000
+++ b/lisp/ChangeLog	Tue Oct 08 03:24:22 2002 +0000
@@ -1,3 +1,10 @@
+2002-09-03  John Paul Wallington  <jpw@shootybangbang.com>
+
+	* subr.el (with-output-to-string): Synch with GNU Emacs 21;
+	avoids leaking temp buffers by killing rather than erasing
+	them, and doesn't execute BODY in temporary `standard-output'
+	buffer.
+
 2002-10-07  Katsumi Yamaoka  <yamaoka@jpl.org>
 
 	* keydefs.el (global-map): Bind C-xrd to delete-rectangle per GNU.
--- a/lisp/subr.el	Tue Oct 08 03:11:49 2002 +0000
+++ b/lisp/subr.el	Tue Oct 08 03:24:22 2002 +0000
@@ -446,20 +446,16 @@
 ;					      path-separator))))
 ;  (split-string-by-char path (aref separator 0)))
 
-(defmacro with-output-to-string (&rest forms)
-  "Collect output to `standard-output' while evaluating FORMS and return
-it as a string."
-  ;; by "William G. Dubuque" <wgd@zurich.ai.mit.edu> w/ mods from Stig
-  `(with-current-buffer (get-buffer-create
-			 (generate-new-buffer-name " *string-output*"))
-     (setq buffer-read-only nil)
-     (buffer-disable-undo (current-buffer))
-     (erase-buffer)
-     (let ((standard-output (current-buffer)))
-       ,@forms)
-     (prog1
-	 (buffer-string)
-       (erase-buffer))))
+(defmacro with-output-to-string (&rest body)
+  "Execute BODY, return the text it sent to `standard-output', as a string."
+  `(let ((standard-output
+	  (get-buffer-create (generate-new-buffer-name " *string-output*"))))
+     (let ((standard-output standard-output))
+       ,@body)
+     (with-current-buffer standard-output
+       (prog1
+	   (buffer-string)
+	 (kill-buffer nil)))))
 
 (defmacro with-current-buffer (buffer &rest body)
   "Temporarily make BUFFER the current buffer and execute the forms in BODY.