Add timers
This commit is contained in:
parent
b3c2d9ded9
commit
02addc0aff
51
lisp/acdw.el
51
lisp/acdw.el
|
@ -457,5 +457,56 @@ sort order."
|
|||
(car args))
|
||||
(cdr args)))
|
||||
|
||||
|
||||
;;; Timers!
|
||||
;; inspired by [[https://git.sr.ht/~protesilaos/tmr/tree/main/item/tmr.el][prot's tmr.el package]]
|
||||
|
||||
(defvar +timer-string nil)
|
||||
(defvar +timer-timer nil)
|
||||
|
||||
(defcustom +timer-running-string "⏰"
|
||||
"What to display when the timer is running."
|
||||
:type 'string)
|
||||
(defcustom +timer-done-string "❗"
|
||||
"What to display when the timer is done."
|
||||
:type 'string)
|
||||
|
||||
(defun +timer (time)
|
||||
"Set a timer for TIME."
|
||||
(interactive (list (read-string "Set a timer for how long? ")))
|
||||
(let ((secs (cond ((natnump time) (* time 60))
|
||||
((and (stringp time)
|
||||
(string-match-p "[0-9]\\'" time))
|
||||
(* (string-to-number time) 60))
|
||||
(t (let ((secs 0)
|
||||
(time time))
|
||||
(save-match-data
|
||||
(while (string-match "\\([0-9.]+\\)\\([hms]\\)" time)
|
||||
(cl-incf secs
|
||||
(* (string-to-number (match-string 1 time))
|
||||
(pcase (match-string 2 time)
|
||||
("h" 3600)
|
||||
("m" 60)
|
||||
("s" 1))))
|
||||
(setq time (substring time (match-end 0)))))
|
||||
secs)))))
|
||||
(message "Setting timer for \"%s\" (%S seconds)..." time secs)
|
||||
(setq +timer-string +timer-running-string)
|
||||
(setq +timer-timer (run-with-timer secs nil
|
||||
(lambda ()
|
||||
(message "%S-second timer DONE!" secs)
|
||||
(setq +timer-string +timer-done-string)
|
||||
(ding))))))
|
||||
|
||||
(defun +timer-cancel ()
|
||||
"Cancel the running timer."
|
||||
(interactive)
|
||||
(cond ((not +timer-timer)
|
||||
(message "No timer found!"))
|
||||
(t
|
||||
(cancel-timer +timer-timer)
|
||||
(message "Timer canceled.")))
|
||||
(setq +timer-string nil))
|
||||
|
||||
(provide 'acdw)
|
||||
;;; acdw.el ends here
|
||||
|
|
Loading…
Reference in New Issue