]> git.eshelyaron.com Git - emacs.git/commitdiff
(with-output-to-string): New macro.
authorRichard M. Stallman <rms@gnu.org>
Tue, 24 Sep 1996 20:03:15 +0000 (20:03 +0000)
committerRichard M. Stallman <rms@gnu.org>
Tue, 24 Sep 1996 20:03:15 +0000 (20:03 +0000)
lisp/subr.el

index c1ab778f38a25749c69c69622fbc2b0d6db9f072..34cd3e7abe0b0dc4bad4fed589015bb7b31da2db 100644 (file)
@@ -740,6 +740,21 @@ The value returned is the value of the last form in BODY."
     (set-buffer ,buffer)
     . ,body))
 
+(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 " *string-output*")))
+     (save-excursion
+       (set-buffer standard-output)
+       (buffer-disable-undo (current-buffer))
+       (let ((inhibit-read-only t))
+        (erase-buffer))
+       (setq buffer-read-only nil))
+     (let ((standard-output standard-output))
+       ,@body)
+     (save-excursion
+       (set-buffer standard-output)
+       (buffer-string))))
+
 (defvar save-match-data-internal)
 
 ;; We use save-match-data-internal as the local variable because