summaryrefslogtreecommitdiff
path: root/lisp/time.el
diff options
context:
space:
mode:
authorStefan Kangas <stefankangas@gmail.com>2020-09-03 17:19:15 +0200
committerStefan Kangas <stefankangas@gmail.com>2020-09-03 18:56:52 +0200
commit54070a5e207f11fbea5adef1dbd7709f42232f0b (patch)
tree31d2088b68b6500466980a1fb29df70bb8d5df81 /lisp/time.el
parent8cb15183aa8faba4af52d7b87e5ee4dcd3b1104f (diff)
downloademacs-54070a5e207f11fbea5adef1dbd7709f42232f0b.tar.gz
emacs-54070a5e207f11fbea5adef1dbd7709f42232f0b.tar.bz2
emacs-54070a5e207f11fbea5adef1dbd7709f42232f0b.zip
Fix my previous change to cancel world-clock timer
* lisp/time.el (subr-x): Require when compiling. (world-clock): Set 'kill-buffer-hook' buffer locally only. (world-clock-update): Break out timer cancellation from here... (world-clock-cancel-timer): ...to here, and don't rely on variable to find the timer to cancel. (world-clock-timer): Delete now superfluous variable.
Diffstat (limited to 'lisp/time.el')
-rw-r--r--lisp/time.el33
1 files changed, 15 insertions, 18 deletions
diff --git a/lisp/time.el b/lisp/time.el
index 5ced9205523..534f1283429 100644
--- a/lisp/time.el
+++ b/lisp/time.el
@@ -29,6 +29,8 @@
;;; Code:
+(eval-when-compile (require 'subr-x))
+
(defgroup display-time nil
"Display time and load in mode line of Emacs."
:group 'mode-line
@@ -523,8 +525,6 @@ See `world-clock'."
(setq-local revert-buffer-function #'world-clock-update)
(setq show-trailing-whitespace nil))
-(defvar world-clock-timer nil)
-
(defun world-clock-display (alist)
"Replace current buffer text with times in various zones, based on ALIST."
(let ((inhibit-read-only t)
@@ -561,34 +561,31 @@ See `world-clock'."
The variable `world-clock-list' specifies which time zones to use.
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)))
- (setq world-clock-timer
- (run-at-time t world-clock-timer-second #'world-clock-update))
- (add-hook 'kill-buffer-hook #'world-clock-cancel-timer))
- (pop-to-buffer world-clock-buffer-name)
+ (if-let ((buffer (get-buffer world-clock-buffer-name)))
+ (pop-to-buffer buffer)
+ (pop-to-buffer world-clock-buffer-name)
+ (when world-clock-timer-enable
+ (run-at-time t world-clock-timer-second #'world-clock-update)
+ (add-hook 'kill-buffer-hook #'world-clock-cancel-timer nil t)))
(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)))
+ (let ((list timer-list))
+ (while list
+ (let ((elt (pop list)))
+ (when (equal (symbol-name (timer--function elt))
+ "world-clock-update")
+ (cancel-timer elt))))))
(defun world-clock-update (&optional _arg _noconfirm)
"Update the `world-clock' buffer."
(if (get-buffer world-clock-buffer-name)
(with-current-buffer (get-buffer world-clock-buffer-name)
(world-clock-display (time--display-world-list)))
- ;; cancel timer
- (let ((list timer-list))
- (while list
- (let ((elt (pop list)))
- (when (equal (symbol-name (timer--function elt))
- "world-clock-update")
- (cancel-timer elt)))))))
+ (world-clock-cancel-timer)))
;;;###autoload
(defun emacs-uptime (&optional format)