John Paul Wallington <jpw(a)shootybangbang.com> writes:
Hrvoje Niksic <hniksic(a)xemacs.org> wrote:[1]
> I propose this version, which is similar to FSF's, but with
additional
> safety of using unwind-protect to guard against temp buffer leakage.
>
> (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*"))))
> (unwind-protect
> (progn
> ;; LET guards the value of standard-output should BODY
> ;; change it.
> (let ((standard-output standard-output))
> ,@body)
> (buffer-string standard-output))
> (kill-buffer standard-output))))
Excuse my putting it bluntly, but, at least for me, this code does not
work any better than the code in the distribution.
To test it, I fired up a fresh XEmacs[2] via xemacs -vanilla and evaluated
the above (defmacro ...).
Now I used the following code to open 10 temporary buffers with the
new `with-output-to-string' and count the survivors.
(progn
(let ((i 0))
(while (< i 10)
;(insert (number-to-string i))
(shell-command-to-string "ls")
(setq i ( + i 1))))
(let ((i 0)
(buffers (buffer-list)))
(while buffers
(if (string-match "string-output" (buffer-name(car buffers)))
(setq i (+ i 1)))
(setq buffers (cdr buffers)))
i))
For me this evaluates to ten, none of the temporary buffers had been
duly killed in the process.
Looks good. Someone should install it.
Would someone please tell me, that this works for him, so that I can
search for a bug in my local setup?
Alexander
Footnotes:
[1] Sorry for following up on this message, but Hrovje's mail has
already expired here.
[2] "XEmacs 21.4 (patch 9) \"Informed Management\" [Lucid]
(i386-unknown-freebsd4.5, Mule) of Wed Aug 28 2002 on
deepspace.reinwarth.com"
"XEmacs 21.5 (beta9) \"brussels sprouts\" (+CVS-20020918) [Lucid]
(i386-unknown-freebsd4.5, Mule) of Thu Sep 19 2002 on
deepspace.reinwarth.com"
--
To boldly frobnicate what no newbie has grokked before. -
http://my.gnus.org