Mercurial > hg > xemacs-beta
diff lisp/subr.el @ 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 | 1b114504fa80 |
children | 1b0339b048ce |
line wrap: on
line diff
--- 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.