* kill buffer created by url-retrieve-synchronously
@ 2016-02-26 11:25 Peter Münster
0 siblings, 0 replies; 4+ messages in thread
From: Peter Münster @ 2016-02-26 11:25 UTC (permalink / raw
To: help-gnu-emacs
Hi,
A timer calls periodically this function:
--8<---------------cut here---------------start------------->8---
(defun pm/get-json (url)
"Copied from
http://frozenlock.org/2012/07/07/url-retrieve-and-json-api/."
(let* ((url-mime-encoding-string "identity")
(buffer (with-timeout (3 nil) (url-retrieve-synchronously url)))
(result
(with-current-buffer buffer
(goto-char (point-min))
(re-search-forward "^$")
(json-read))))
(kill-buffer buffer)
result))
--8<---------------cut here---------------end--------------->8---
Sometimes, the buffers created by url-retrieve-synchronously are not
killed, because I see them in (buffer-list).
What should I do to ensure, that these buffers are always killed at the
end of the function please?
TIA for any help,
--
Peter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: kill buffer created by url-retrieve-synchronously
[not found] <mailman.5945.1456485979.843.help-gnu-emacs@gnu.org>
@ 2016-02-27 3:58 ` Lars Magne Ingebrigtsen
2016-02-27 17:55 ` Peter Münster
[not found] ` <mailman.6062.1456595760.843.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 4+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-02-27 3:58 UTC (permalink / raw
To: Peter Münster; +Cc: help-gnu-emacs
Peter Münster <pmlists@free.fr> writes:
> What should I do to ensure, that these buffers are always killed at the
> end of the function please?
Slap an `unwind-protect' around the main part of your function, and have
the `kill-buffer' in the unwind forms.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: kill buffer created by url-retrieve-synchronously
2016-02-27 3:58 ` Lars Magne Ingebrigtsen
@ 2016-02-27 17:55 ` Peter Münster
[not found] ` <mailman.6062.1456595760.843.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 4+ messages in thread
From: Peter Münster @ 2016-02-27 17:55 UTC (permalink / raw
To: help-gnu-emacs
On Sat, Feb 27 2016, Lars Magne Ingebrigtsen wrote:
> Slap an `unwind-protect' around the main part of your function, and have
> the `kill-buffer' in the unwind forms.
Thanks. But it still does not work. Just an idea: Is it possible, that
the with-timeout form kills the url-retrieve-synchronously function
because of the timeout, but the buffer has already been created?
Here my new function:
--8<---------------cut here---------------start------------->8---
(defun pm/get-json (url)
"Copied from
http://frozenlock.org/2012/07/07/url-retrieve-and-json-api/."
(let (my-json-buffer)
(unwind-protect
(let ((url-mime-encoding-string "identity"))
(setq my-json-buffer (with-timeout (3 nil)
(url-retrieve-synchronously url)))
(with-current-buffer my-json-buffer
(goto-char (point-min))
(re-search-forward "^$")
(json-read)))
(if my-json-buffer
(kill-buffer my-json-buffer)))))
--8<---------------cut here---------------end--------------->8---
--
Peter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: kill buffer created by url-retrieve-synchronously
[not found] ` <mailman.6062.1456595760.843.help-gnu-emacs@gnu.org>
@ 2016-02-28 3:52 ` Lars Magne Ingebrigtsen
0 siblings, 0 replies; 4+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-02-28 3:52 UTC (permalink / raw
To: Peter Münster; +Cc: help-gnu-emacs
Peter Münster <pmlists@free.fr> writes:
> Thanks. But it still does not work. Just an idea: Is it possible, that
> the with-timeout form kills the url-retrieve-synchronously function
> because of the timeout, but the buffer has already been created?
Sorry; I didn't notice the `with-timeout' thing at all.
[...]
> (let ((url-mime-encoding-string "identity"))
> (setq my-json-buffer (with-timeout (3 nil)
> (url-retrieve-synchronously url)))
[...]
> (if my-json-buffer
> (kill-buffer my-json-buffer)))))
Yes, the `with-timeout' is the reason the buffer isn't killed. Because
it'll just return nil when timing out, and there's no way to get at the
buffer url.el created.
For reasons like this, `with-timeout' isn't recommended.
`url-retrieve-synchronously' should have a timeout parameter. Feel free
to submit that as a wishlist bug report with `M-x report-emacs-bug'.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-28 3:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-26 11:25 kill buffer created by url-retrieve-synchronously Peter Münster
[not found] <mailman.5945.1456485979.843.help-gnu-emacs@gnu.org>
2016-02-27 3:58 ` Lars Magne Ingebrigtsen
2016-02-27 17:55 ` Peter Münster
[not found] ` <mailman.6062.1456595760.843.help-gnu-emacs@gnu.org>
2016-02-28 3:52 ` Lars Magne Ingebrigtsen
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.