emacs-devel
[Top][All Lists]
Advanced

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

Re: with-url


From: Lars Ingebrigtsen
Subject: Re: with-url
Date: Thu, 29 Dec 2016 17:35:07 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

>>   (with-url (headers "http://fsf.org/";)
>>     (message "The size of the FSF front page is %s" (buffer-size)))
>
> I'm probably missing something, but why do you need a macro?  The
> description seems to say that BODY is executed with point in a buffer
> with the response, so why not just set up that buffer and return with
> it as the current buffer?

The body is executed synchronously or as a callback later, depending on
whether you put a :wait t in the parameter list or not.  I don't see how
that's possibly without using a macro.  (I mean, without radically
rewriting the call if you want a synchronous/asynchronous execution.)

> As for the syntax, this macro looks unusual to me, certainly wrt other
> with-SOMETHING macros, in that it accepts a list of arguments of
> variable length and contents.  But that's me.

We haven't done that much in Emacs Lisp, but it's a common idiom in
Common Lisp, and I think it's kinda nice.

  (with-open-file (s "/tmp/foo"
                   :direction :output
                   :if-exists :rename)
    (princ :foo s))

> A few comments to the doc string:
>
>> :headers ALIST
>> Add ALIST to the headers sent over to the server.  This should typically
>> look like
>> 
>>   (("User-Agent" "Emacs"))
>
> What about unibyte/multibyte issue in the headers?  Should that be
> encoded by the caller?

I think that question is answered by your next comment?  :-)

>> Additional elements in this alist are interpreted as the
>> charset (defaulting to utf-8) and the encoding method (defaulting
>> to url-encode).
>
> Please don't use "charset" when you really mean "coding-system".  In
> Emacs parlance, "charset" means something very different (and "utf-8"
> is not a charset in that meaning), so this will spread confusion.

True, I'll reword that.

> Also, why should the default be UTF-8?  Isn't the system locale's
> codeset a better default?  The URL doesn't have to be on another
> machine, right?

No, but utf-8 is the normal default in network communication these days.

>> :method GET/POST/etc
>> The method to use for retrieving an HTTP(S) resource.  This defaults
>> to GET, and other popular values are POST, UPDATE and PUT.
>
> Does thus mean this macro is only for HTTP/HTTPS?

No, it'll work for file: and ftp:, too.  I should probably group the
HTTP(S)-only options.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



reply via email to

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