Mercurial > emacs
comparison lisp/subr.el @ 16311:a56a8c6f2d8f
(with-output-to-string): New macro.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 24 Sep 1996 20:03:15 +0000 |
parents | 07cfbdac7ec5 |
children | c72b7ee606a3 |
comparison
equal
deleted
inserted
replaced
16310:c987c025d448 | 16311:a56a8c6f2d8f |
---|---|
738 The value returned is the value of the last form in BODY." | 738 The value returned is the value of the last form in BODY." |
739 `(save-current-buffer | 739 `(save-current-buffer |
740 (set-buffer ,buffer) | 740 (set-buffer ,buffer) |
741 . ,body)) | 741 . ,body)) |
742 | 742 |
743 (defmacro with-output-to-string (&rest body) | |
744 "Execute BODY, return the text it sent to `standard-output', as a string." | |
745 `(let ((standard-output (get-buffer-create " *string-output*"))) | |
746 (save-excursion | |
747 (set-buffer standard-output) | |
748 (buffer-disable-undo (current-buffer)) | |
749 (let ((inhibit-read-only t)) | |
750 (erase-buffer)) | |
751 (setq buffer-read-only nil)) | |
752 (let ((standard-output standard-output)) | |
753 ,@body) | |
754 (save-excursion | |
755 (set-buffer standard-output) | |
756 (buffer-string)))) | |
757 | |
743 (defvar save-match-data-internal) | 758 (defvar save-match-data-internal) |
744 | 759 |
745 ;; We use save-match-data-internal as the local variable because | 760 ;; We use save-match-data-internal as the local variable because |
746 ;; that works ok in practice (people should not use that variable elsewhere). | 761 ;; that works ok in practice (people should not use that variable elsewhere). |
747 ;; We used to use an uninterned symbol; the compiler handles that properly | 762 ;; We used to use an uninterned symbol; the compiler handles that properly |