all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: Sean McAfee <eefacm@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Function to download a URL and return it as a string
Date: Mon, 10 Dec 2012 00:56:05 +0530	[thread overview]
Message-ID: <878v976n8y.fsf@gmail.com> (raw)
In-Reply-To: <m2k3srerd9.fsf@gmail.com> (Sean McAfee's message of "Sat, 08 Dec 2012 21:17:38 -0800")


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 <eefacm@gmail.com> 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.)
>

-- 



  parent reply	other threads:[~2012-12-09 19:26 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 [this message]
     [not found] ` <mailman.14907.1355031511.855.help-gnu-emacs@gnu.org>
2012-12-10  0:59   ` Sean McAfee

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878v976n8y.fsf@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.