There is a function I can't remember exactly. Maybe with-temp-string? Like with-current-buffer, but makes all output to a temp string.
ÔÚ 2012-12-9 ÏÂÎç1:20£¬"Sean McAfee" <eefacm@gmail.com>дµÀ£º
>
> I recently wanted to be able to download a document from a URL and
> return it as a string. I couldn't find a function that did that
> precisely, but I was able to construct my own:
>
> (defun download (url)
> (with-current-buffer (url-retrieve-synchronously url)
> (prog2
> (when (not (search-forward-regexp "^$" nil t))
> (error "Unable to locate downloaded data"))
> (buffer-substring (1+ (point)) (point-max))
> (kill-buffer))))
>
> This seems rather busy for such a basic-seeming operation--in
> particular, having to take care to delete the buffer created by
> url-retrieve-synchronously. Is there a better way to do it?
>
> (On the other hand, this way I get to use prog2, which I almost never
> do.)