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: Function to download a URL and return it as a string Date: Sat, 08 Dec 2012 21:17:38 -0800 Organization: A noiseless patient Spider Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1355030411 31741 80.91.229.3 (9 Dec 2012 05:20:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Dec 2012 05:20:11 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 09 06:20:25 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 1ThZJR-0001gu-6C for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Dec 2012 06:20:25 +0100 Original-Received: from localhost ([::1]:37152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThZJE-0007dl-PP for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Dec 2012 00:20:12 -0500 Original-Path: usenet.stanford.edu!news.kjsl.com!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 18 Injection-Info: mx04.eternal-september.org; posting-host="038645e85864f4f98f038f25a2a74806"; logging-data="16549"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JrHYAWXJV6Cp5A1fn3d1ksxV39tdx1f0=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.94 (darwin) Cancel-Lock: sha1:Nq+K1FtdQQtP9Hamklc6ZzEPrgM= sha1:vb8AVVKDjQMkn+CKeG8NF4wZA0g= Original-Xref: usenet.stanford.edu gnu.emacs.help:195779 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:88097 Archived-At: 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.)