help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: kill buffer created by url-retrieve-synchronously


From: Peter Münster
Subject: Re: kill buffer created by url-retrieve-synchronously
Date: Sat, 27 Feb 2016 18:55:44 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

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




reply via email to

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