help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function to download a URL and return it as a string


From: Sean McAfee
Subject: Re: Function to download a URL and return it as a string
Date: Sun, 09 Dec 2012 16:59:11 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.94 (darwin)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]