diff options
| author | Stefan Kangas | 2020-09-03 12:54:30 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2020-09-03 12:54:30 +0200 |
| commit | d37861535dfd452f7c2255ae5edcf7686b75fe5a (patch) | |
| tree | 4f5d60be468481c877d84dcf0aad0dfdbdb78621 | |
| parent | 18ae12e053c8e4dd7ea21f8d94a7f51a78648e64 (diff) | |
| download | emacs-d37861535dfd452f7c2255ae5edcf7686b75fe5a.tar.gz emacs-d37861535dfd452f7c2255ae5edcf7686b75fe5a.zip | |
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'.
| -rw-r--r-- | lisp/time.el | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lisp/time.el b/lisp/time.el index 1ab992adb45..5ced9205523 100644 --- a/lisp/time.el +++ b/lisp/time.el | |||
| @@ -523,6 +523,8 @@ See `world-clock'." | |||
| 523 | (setq-local revert-buffer-function #'world-clock-update) | 523 | (setq-local revert-buffer-function #'world-clock-update) |
| 524 | (setq show-trailing-whitespace nil)) | 524 | (setq show-trailing-whitespace nil)) |
| 525 | 525 | ||
| 526 | (defvar world-clock-timer nil) | ||
| 527 | |||
| 526 | (defun world-clock-display (alist) | 528 | (defun world-clock-display (alist) |
| 527 | "Replace current buffer text with times in various zones, based on ALIST." | 529 | "Replace current buffer text with times in various zones, based on ALIST." |
| 528 | (let ((inhibit-read-only t) | 530 | (let ((inhibit-read-only t) |
| @@ -561,12 +563,20 @@ To turn off the world time display, go to the window and type `\\[quit-window]'. | |||
| 561 | (interactive) | 563 | (interactive) |
| 562 | (when (and world-clock-timer-enable | 564 | (when (and world-clock-timer-enable |
| 563 | (not (get-buffer world-clock-buffer-name))) | 565 | (not (get-buffer world-clock-buffer-name))) |
| 564 | (run-at-time t world-clock-timer-second #'world-clock-update)) | 566 | (setq world-clock-timer |
| 567 | (run-at-time t world-clock-timer-second #'world-clock-update)) | ||
| 568 | (add-hook 'kill-buffer-hook #'world-clock-cancel-timer)) | ||
| 565 | (pop-to-buffer world-clock-buffer-name) | 569 | (pop-to-buffer world-clock-buffer-name) |
| 566 | (world-clock-display (time--display-world-list)) | 570 | (world-clock-display (time--display-world-list)) |
| 567 | (world-clock-mode) | 571 | (world-clock-mode) |
| 568 | (fit-window-to-buffer)) | 572 | (fit-window-to-buffer)) |
| 569 | 573 | ||
| 574 | (defun world-clock-cancel-timer () | ||
| 575 | "Cancel the world clock timer." | ||
| 576 | (when world-clock-timer | ||
| 577 | (cancel-timer world-clock-timer) | ||
| 578 | (setq world-clock-timer nil))) | ||
| 579 | |||
| 570 | (defun world-clock-update (&optional _arg _noconfirm) | 580 | (defun world-clock-update (&optional _arg _noconfirm) |
| 571 | "Update the `world-clock' buffer." | 581 | "Update the `world-clock' buffer." |
| 572 | (if (get-buffer world-clock-buffer-name) | 582 | (if (get-buffer world-clock-buffer-name) |