[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tmr 183cbff598 13/21: Make 'tmr' and 'tmr-cancel' use l
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tmr 183cbff598 13/21: Make 'tmr' and 'tmr-cancel' use list of timers |
Date: |
Thu, 21 Apr 2022 14:58:10 -0400 (EDT) |
branch: externals/tmr
commit 183cbff59857ac3d1f4d241a00b91e1f37368652
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Make 'tmr' and 'tmr-cancel' use list of timers
---
tmr.el | 49 +++++++++++++++++++++++++++++++++----------------
1 file changed, 33 insertions(+), 16 deletions(-)
diff --git a/tmr.el b/tmr.el
index f20a683a2d..38559562ae 100644
--- a/tmr.el
+++ b/tmr.el
@@ -124,18 +124,30 @@ Optionally include DESCRIPTION."
(unless (plist-get (notifications-get-capabilities) :sound)
(tmr--play-sound))))
-;; TODO 2021-09-21: Maybe we should use a list instead of storing just
-;; the last one?
-(defvar tmr--last-timer nil
- "Last timer object, used by `tmr-cancel'.")
+(defvar tmr--timers nil
+ "List of timer objects.
+Populated by `tmr' and then operated on by `tmr-cancel'.")
;;;###autoload
-(defun tmr-cancel ()
- "Cancel last timer object set with `tmr' command."
- (interactive)
- (if tmr--last-timer
- (cancel-timer tmr--last-timer)
- (message "No `tmr' to cancel")))
+(defun tmr-cancel (&optional select)
+ "Cancel last timer object set with `tmr' command.
+With optional SELECT as a prefix (\\[universal-argument])
+argument, prompt for selection among available timers."
+ (declare (interactive-only t))
+ (interactive "P")
+ (if-let ((timers tmr--timers))
+ (cond
+ ((= (length timers) 1)
+ (let ((object (cdr (car timers))))
+ (cancel-timer object)
+ (setq tmr--timers nil)))
+ ((or select (> (length timers) 1))
+ (let* ((selection (completing-read "Cancel timer: " (mapc #'car
timers) nil t))
+ (cell (assoc selection timers #'string-match-p))
+ (object (cdr cell)))
+ (cancel-timer object)
+ (setq tmr--timers (delete cell tmr--timers)))))
+ (user-error "No `tmr' to cancel")))
(defun tmr--echo-area (time &optional description)
"Produce `message' for current `tmr' TIME.
@@ -187,13 +199,18 @@ To cancel the timer, use the `tmr-cancel' command."
(list
(read-string "N minutes for timer (append `h' or `s' for other units): ")
(when current-prefix-arg (tmr--description-prompt))))
- (let ((start (format-time-string "%T"))
- (unit (tmr--unit time)))
+ (let* ((start (format-time-string "%T"))
+ (unit (tmr--unit time))
+ (object-desc (if description
+ (format "Started at %s with unit %s and description
'%s'" start unit description)
+ (format "Started at %s with unit %s" start unit))))
(tmr--echo-area time description)
- (setq tmr--last-timer
- (run-with-timer
- unit nil
- 'tmr--notify-send start description))))
+ (push (cons
+ object-desc
+ (run-with-timer
+ unit nil
+ 'tmr--notify-send start description))
+ tmr--timers)))
(provide 'tmr)
;;; tmr.el ends here
- [elpa] externals/tmr 80007165bb 12/21: Use local variable in function, (continued)
- [elpa] externals/tmr 80007165bb 12/21: Use local variable in function, ELPA Syncer, 2022/04/21
- [elpa] externals/tmr cba45349dc 16/21: Tweak tmr--notify-send, ELPA Syncer, 2022/04/21
- [elpa] externals/tmr f48af7b5ff 14/21: Use 'format' instead of 'concat', ELPA Syncer, 2022/04/21
- [elpa] externals/tmr 5b759f7387 19/21: Rewrite documentation, ELPA Syncer, 2022/04/21
- [elpa] externals/tmr 1081feb0b9 11/21: Add comment on Emacs 'play-sound', ELPA Syncer, 2022/04/21
- [elpa] externals/tmr 71b835d71b 15/21: Add message log in "*tmr-messages*" buffer, ELPA Syncer, 2022/04/21
- [elpa] externals/tmr 807933dd08 01/21: Create tmr.el repository, ELPA Syncer, 2022/04/21
- [elpa] externals/tmr 4c4025e8b4 02/21: Use https link to repo for read access, ELPA Syncer, 2022/04/21
- [elpa] externals/tmr 2749935a01 10/21: Clarify wording of error message, ELPA Syncer, 2022/04/21
- [elpa] externals/tmr 11c3da3559 08/21: Add FSF as copyright holder, ELPA Syncer, 2022/04/21
- [elpa] externals/tmr 183cbff598 13/21: Make 'tmr' and 'tmr-cancel' use list of timers,
ELPA Syncer <=