diff options
author | Case Duckworth | 2022-05-12 22:38:33 -0500 |
---|---|---|
committer | Case Duckworth | 2022-05-12 22:38:33 -0500 |
commit | 02addc0aff6863007646bc02a53a182ed44678fe (patch) | |
tree | e80289503085ab76d1ce7ea7ca4c4f0e3e384cfa /lisp | |
parent | meh (diff) | |
download | emacs-02addc0aff6863007646bc02a53a182ed44678fe.tar.gz emacs-02addc0aff6863007646bc02a53a182ed44678fe.zip |
Add timers
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/acdw.el | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lisp/acdw.el b/lisp/acdw.el index 3052976..9b3ab93 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el | |||
@@ -457,5 +457,56 @@ sort order." | |||
457 | (car args)) | 457 | (car args)) |
458 | (cdr args))) | 458 | (cdr args))) |
459 | 459 | ||
460 | |||
461 | ;;; Timers! | ||
462 | ;; inspired by [[https://git.sr.ht/~protesilaos/tmr/tree/main/item/tmr.el][prot's tmr.el package]] | ||
463 | |||
464 | (defvar +timer-string nil) | ||
465 | (defvar +timer-timer nil) | ||
466 | |||
467 | (defcustom +timer-running-string "⏰" | ||
468 | "What to display when the timer is running." | ||
469 | :type 'string) | ||
470 | (defcustom +timer-done-string "❗" | ||
471 | "What to display when the timer is done." | ||
472 | :type 'string) | ||
473 | |||
474 | (defun +timer (time) | ||
475 | "Set a timer for TIME." | ||
476 | (interactive (list (read-string "Set a timer for how long? "))) | ||
477 | (let ((secs (cond ((natnump time) (* time 60)) | ||
478 | ((and (stringp time) | ||
479 | (string-match-p "[0-9]\\'" time)) | ||
480 | (* (string-to-number time) 60)) | ||
481 | (t (let ((secs 0) | ||
482 | (time time)) | ||
483 | (save-match-data | ||
484 | (while (string-match "\\([0-9.]+\\)\\([hms]\\)" time) | ||
485 | (cl-incf secs | ||
486 | (* (string-to-number (match-string 1 time)) | ||
487 | (pcase (match-string 2 time) | ||
488 | ("h" 3600) | ||
489 | ("m" 60) | ||
490 | ("s" 1)))) | ||
491 | (setq time (substring time (match-end 0))))) | ||
492 | secs))))) | ||
493 | (message "Setting timer for \"%s\" (%S seconds)..." time secs) | ||
494 | (setq +timer-string +timer-running-string) | ||
495 | (setq +timer-timer (run-with-timer secs nil | ||
496 | (lambda () | ||
497 | (message "%S-second timer DONE!" secs) | ||
498 | (setq +timer-string +timer-done-string) | ||
499 | (ding)))))) | ||
500 | |||
501 | (defun +timer-cancel () | ||
502 | "Cancel the running timer." | ||
503 | (interactive) | ||
504 | (cond ((not +timer-timer) | ||
505 | (message "No timer found!")) | ||
506 | (t | ||
507 | (cancel-timer +timer-timer) | ||
508 | (message "Timer canceled."))) | ||
509 | (setq +timer-string nil)) | ||
510 | |||
460 | (provide 'acdw) | 511 | (provide 'acdw) |
461 | ;;; acdw.el ends here | 512 | ;;; acdw.el ends here |