unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Function to download a URL and return it as a string
@ 2012-12-09  5:17 Sean McAfee
  2012-12-09  5:38 ` Drew Adams
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Sean McAfee @ 2012-12-09  5:17 UTC (permalink / raw)
  To: help-gnu-emacs

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.)


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-12-10  0:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-09  5:17 Function to download a URL and return it as a string Sean McAfee
2012-12-09  5:38 ` Drew Adams
2012-12-09 13:12 ` Pascal J. Bourguignon
2012-12-09 15:13 ` jun net
2012-12-09 19:26 ` Jambunathan K
     [not found] ` <mailman.14907.1355031511.855.help-gnu-emacs@gnu.org>
2012-12-10  0:59   ` Sean McAfee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).