mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-18 06:01:22 -08:00
(with-output-to-string): New macro.
This commit is contained in:
parent
a878555182
commit
5db7925ddc
1 changed files with 15 additions and 0 deletions
15
lisp/subr.el
15
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue