all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: master d378615: Cancel timer when world-clock buffer is killed
Date: Thu, 03 Sep 2020 14:46:34 +0100	[thread overview]
Message-ID: <87sgbzrn0l.fsf@tcd.ie> (raw)
In-Reply-To: <20200903105450.8CD2D20A15@vcs0.savannah.gnu.org> (Stefan Kangas's message of "Thu, 3 Sep 2020 06:54:50 -0400 (EDT)")

stefankangas@gmail.com (Stefan Kangas) writes:

> branch: master
> commit d37861535dfd452f7c2255ae5edcf7686b75fe5a
> Author: Stefan Kangas <stefankangas@gmail.com>
> Commit: Stefan Kangas <stefankangas@gmail.com>
>
>     Cancel timer when world-clock buffer is killed
>     
>     * lisp/time.el (world-clock-timer): New variable.
>     (world-clock-cancel-timer): New defun.
>     (world-clock): Add 'world-clock-cancel-timer' to 'kill-buffer-hook'.
> ---
>  lisp/time.el | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/lisp/time.el b/lisp/time.el
> index 1ab992a..5ced920 100644
> --- a/lisp/time.el
> +++ b/lisp/time.el
> @@ -523,6 +523,8 @@ See `world-clock'."
>    (setq-local revert-buffer-function #'world-clock-update)
>    (setq show-trailing-whitespace nil))
>  
> +(defvar world-clock-timer nil)

Should this be given an internal name (and docstring)?

>  (defun world-clock-display (alist)
>    "Replace current buffer text with times in various zones, based on ALIST."
>    (let ((inhibit-read-only t)
> @@ -561,12 +563,20 @@ To turn off the world time display, go to the window and type `\\[quit-window]'.
>    (interactive)
>    (when (and world-clock-timer-enable
>               (not (get-buffer world-clock-buffer-name)))
> -    (run-at-time t world-clock-timer-second #'world-clock-update))
> +    (setq world-clock-timer
> +          (run-at-time t world-clock-timer-second #'world-clock-update))
> +    (add-hook 'kill-buffer-hook #'world-clock-cancel-timer))

Should this be hooked buffer-locally?

>    (pop-to-buffer world-clock-buffer-name)
>    (world-clock-display (time--display-world-list))
>    (world-clock-mode)
>    (fit-window-to-buffer))
>  
> +(defun world-clock-cancel-timer ()
> +  "Cancel the world clock timer."
> +  (when world-clock-timer
> +    (cancel-timer world-clock-timer)
> +    (setq world-clock-timer nil)))
> +
>  (defun world-clock-update (&optional _arg _noconfirm)
>    "Update the `world-clock' buffer."
>    (if (get-buffer world-clock-buffer-name)

Actually, doesn't world-clock-update already try to cancel itself when
world-clock-buffer-name no longer names an existing buffer?

It seems to me that world-clock-cancel-timer and world-clock-update are
duplicating each other.  Or am I missing something?

Thanks,

-- 
Basil



       reply	other threads:[~2020-09-03 13:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200903105449.22858.36474@vcs0.savannah.gnu.org>
     [not found] ` <20200903105450.8CD2D20A15@vcs0.savannah.gnu.org>
2020-09-03 13:46   ` Basil L. Contovounesios [this message]
2020-09-03 17:22     ` master d378615: Cancel timer when world-clock buffer is killed Stefan Kangas
2020-09-04  9:58       ` Basil L. Contovounesios
2020-09-06 15:38         ` Stefan Kangas
2020-09-06 15:55           ` Basil L. Contovounesios

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=87sgbzrn0l.fsf@tcd.ie \
    --to=contovob@tcd.ie \
    --cc=emacs-devel@gnu.org \
    --cc=stefankangas@gmail.com \
    /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.