[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: with-output-to-string improvement
From: |
Richard Stallman |
Subject: |
Re: with-output-to-string improvement |
Date: |
Fri, 04 Apr 2003 01:58:40 -0500 |
(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)))))
One feature here is that the ambient current buffer is still currnet
in BODY.
(defmacro with-output-to-string (&rest body)
"Execute BODY, return the text it sent to `standard-output', as a
string."
! `(with-temp-buffer
! (let ((standard-output (current-buffer)))
! (with-temp-buffer ; in case body inserts anything
! ,@body)
! (buffer-string))))
This does not have that feature, so it is not as good.
There is no need to protect against BODY's inserting anything, I think.