# HG changeset patch # User youngs # Date 1034047462 0 # Node ID 3a01f3148bff07ee55d18f5f101940a2c36846ee # Parent b33a835c21cc3820177b20533fe38f4a703a9362 [xemacs-hg @ 2002-10-08 03:24:18 by youngs] 2002-09-03 John Paul Wallington * 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. diff -r b33a835c21cc -r 3a01f3148bff lisp/ChangeLog --- 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 + + * 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 * keydefs.el (global-map): Bind C-xrd to delete-rectangle per GNU. diff -r b33a835c21cc -r 3a01f3148bff lisp/subr.el --- 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" 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.