From: Sean McAfee <eefacm@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Function to download a URL and return it as a string
Date: Sun, 09 Dec 2012 16:59:11 -0800 [thread overview]
Message-ID: <m2fw3een8g.fsf@gmail.com> (raw)
In-Reply-To: mailman.14907.1355031511.855.help-gnu-emacs@gnu.org
"Drew Adams" <drew.adams@oracle.com> writes:
>> (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))))
> Dunno anything about whether there is a better way, but consider using
> `unwind-protect', with `kill-buffer' as your cleanup part.
My original implementation used unwind-protect, but on reflection it
seemed quite unnecessary when there was no way for the protected form to
ever raise an exception.
I suppose there's a future-proofing argument to be made, but it's hard
to see this code evolving to the point where an exception ever could
occur.
prev parent reply other threads:[~2012-12-10 0:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2fw3een8g.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.
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).