all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sean McAfee <eefacm@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Function to download a URL and return it as a string
Date: Sat, 08 Dec 2012 21:17:38 -0800	[thread overview]
Message-ID: <m2k3srerd9.fsf@gmail.com> (raw)

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


             reply	other threads:[~2012-12-09  5:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-09  5:17 Sean McAfee [this message]
2012-12-09  5:38 ` Function to download a URL and return it as a string 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2k3srerd9.fsf@gmail.com \
    --to=eefacm@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.