From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sean McAfee Newsgroups: gmane.emacs.help Subject: Re: Function to download a URL and return it as a string Date: Sun, 09 Dec 2012 16:59:11 -0800 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1355101214 30377 80.91.229.3 (10 Dec 2012 01:00:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Dec 2012 01:00:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 10 02:00:28 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ThrjQ-0001h9-6Y for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Dec 2012 02:00:28 +0100 Original-Received: from localhost ([::1]:42909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThrjD-0004NS-Kj for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Dec 2012 20:00:15 -0500 Original-Path: usenet.stanford.edu!goblin3!goblin.stu.neva.ru!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 19 Injection-Info: mx04.eternal-september.org; posting-host="ef68efb1f7721d7db6930f2433a74691"; logging-data="22470"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wckhP0LBProxZFiEkXvU1LTJk/K7Lp7w=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.94 (darwin) Cancel-Lock: sha1:Po8NwygaDoEBj8v2S68bSODiWRM= sha1:EAsFnKLqM2xxQIbxeKQvri9ORDw= Original-Xref: usenet.stanford.edu gnu.emacs.help:195790 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:88108 Archived-At: "Drew Adams" 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.