From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jambunathan K Newsgroups: gmane.emacs.help Subject: Re: Function to download a URL and return it as a string Date: Mon, 10 Dec 2012 00:56:05 +0530 Message-ID: <878v976n8y.fsf@gmail.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1355080991 8628 80.91.229.3 (9 Dec 2012 19:23:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Dec 2012 19:23:11 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Sean McAfee Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 09 20:23: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 1ThmTE-00030j-2G for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Dec 2012 20:23:24 +0100 Original-Received: from localhost ([::1]:43012 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThmT1-0007fV-FP for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Dec 2012 14:23:11 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:45128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThmSw-0007fM-B7 for help-gnu-emacs@gnu.org; Sun, 09 Dec 2012 14:23:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ThmSs-000823-OS for help-gnu-emacs@gnu.org; Sun, 09 Dec 2012 14:23:06 -0500 Original-Received: from mail-pb0-f41.google.com ([209.85.160.41]:46306) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThmSs-00081z-IJ for help-gnu-emacs@gnu.org; Sun, 09 Dec 2012 14:23:02 -0500 Original-Received: by mail-pb0-f41.google.com with SMTP id xa7so1364887pbc.0 for ; Sun, 09 Dec 2012 11:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=hLwSGCefr+s2ZhqATd0QMHS2i38PrKO23d1M7mUHZHY=; b=t74F0AUEa4JAgjHKyrkkNWw48Duam3kaUTgo/uDRCD2opDytHsq5zWFr6gTjNfcZs7 iClldPS/hiiyy9ioxxjAuw7ytwpMCJ0E2wFCZ2X6JUWjvKO2/148S7irtDyWUSCaICjf G5Qa97w48LCjdKQVzr4CStrr5eEh3qTRMmKQVcNMJWru/iGo+n2QKVhdw5sdrXawBmcz ZghevM2bWqPfiY6Wq6FI/vfjcTBhzUeW+AmW5NZ0OQbry70X6oCyUMIZYfh3yu10wZVp eIZtsp2+JOGKAaL3wYtsaqJyHi07qY7of8QtwVqnk1ewq2poDdVyQUSaO/xtu1oikZFf nMMg== Original-Received: by 10.68.233.196 with SMTP id ty4mr33270277pbc.23.1355080981858; Sun, 09 Dec 2012 11:23:01 -0800 (PST) Original-Received: from debian-6.05 ([115.184.102.31]) by mx.google.com with ESMTPS id gv9sm10456056pbc.21.2012.12.09.11.22.58 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 09 Dec 2012 11:23:01 -0800 (PST) In-Reply-To: (Sean McAfee's message of "Sat, 08 Dec 2012 21:17:38 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.41 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:88105 Archived-At: May be you can steal some stuff from M-x find-library RET package.el specifically C-h f package--with-work-buffer Or You can file an enhancement request so that some of this stuff could be moved out of package.el to someother library. ps: I know nothing about handling HTTP requests. Just pitching in with few pennies. Sean McAfee writes: > 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.) > --