diff options
author | Richard M. Stallman <rms@gnu.org> | 1996-09-24 20:03:15 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1996-09-24 20:03:15 +0000 |
commit | 7bf98e340ecb5d278461ae1b46f4fe45c96a4fd1 (patch) | |
tree | a93bad7e4e4205fc5fc0369caab9e6fe3c21fec6 /lisp/subr.el | |
parent | 947487bf72319dfaecc05741ab22e2542fa800e3 (diff) | |
download | emacs-7bf98e340ecb5d278461ae1b46f4fe45c96a4fd1.tar.gz |
(with-output-to-string): New macro.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index c1ab778f38a..34cd3e7abe0 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -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 |