diff --git a/README.md b/README.md index 473c237..57be62f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,25 @@ # egg-timer.el +## Introduction to the fork + +This is a fork of the excellent and original egg-timer.el because I really liked the simplicity of the interface here but I wanted to be able to free form enter text for choosing a timer's time as well as select from a list with completion, also I wanted to make it work on systems where I didn't have access to DBUS notifications (remote terminal machines, windows machines, etc) so I wanted to +make the notification system more customisable if I wanted too, and then I wanted the ability to list/modify the timers running... so I sort of took the original incredibly simple and beautiful code and mangled it with complexity. + +But the users experience of it should remain very simple. + +This version exposes four functions to the user: + +* `egg-timer-schedule` lets you schedule a timer either from a completing read or entering any time string that looks right enough according to `timer-duration-words` so writing "3 seconds" or "3 hours" would give you a timer for "3 second" or "3 hour" because it trims off -s and things. If there is any text after the second word this is appended to the label of your timer as a reason for its existence, so "25 minutes turn down oven" would let you know why you got a notification at that point with the context. +* `egg-timer-p` tells you if you have running timers +* `egg-timer-list` lists your running timers +* `egg-timer-cancel` lets you choose a timer to cancel + +There is also a variable `egg-timer-notification-method` that lets you choose now notifications work, by default it uses `notifications-notify` but it can be set to `'buffer` to pop up buffer showing when the timer completes or `'message` to just display a message. If it is linked to a function then it will call that function and pass it the label of the timer to display, this can be either a lambda or a #'my-function + +Everything below here is the original documentation + +--- + [![MELPA](https://melpa.org/packages/egg-timer-badge.svg)](https://melpa.org/#/egg-timer) Use Emacs to set timers. diff --git a/egg-timer.el b/egg-timer.el index 5d8c3b7..61e5c84 100644 --- a/egg-timer.el +++ b/egg-timer.el @@ -2,7 +2,7 @@ ;; Author: William Carroll ;; URL: https://github.com/wpcarro/egg-timer.el -;; Version: 0.0.1 +;; Version: 0.0.2 ;; Package-Requires: ((emacs "25.1")) ;; This file is NOT part of GNU Emacs. @@ -34,6 +34,21 @@ ;; message when the timer completes. Since this depends on ;; `notifications-notify', ensure that your Emacs is compiled with dbus ;; support. +;; + +;; 2023-12-04 https://github.com/twitchy-ears/egg-timer.el +;; +;; I really liked the simplicity of the interface here but I wanted to +;; be able to free form enter text for choosing a timer's time as well +;; as select from a list with completion, also I wanted to make it +;; work on systems where I didn't have access to DBUS notifications +;; (remote terminal machines, windows machines, etc) so I wanted to +;; make the notification system more customisable if I wanted too, and +;; then I wanted the ability to list/modify the timers running... so I +;; sort of took the original incredibly simple and beautiful code and +;; mangled it with complexity. +;; +;; But the users experience of it should remain very simple. ;;; Code: @@ -68,27 +83,280 @@ :type '(alist :key-type string :value-type integer) :group 'egg-timer) -(defun egg-timer-do-schedule (minutes &optional label) - "Schedule a timer to go off in MINUTES. -Provide LABEL to change the notifications, which defaults to \"MINUTES -minutes\"." +(cl-defstruct egg-timer-event + "An egg timer event that is stored in the list of events" + id + timer-item + label) + +(defvar egg-timer-notification-method 'notify + "Backup notification method if 'notifications-notify' isn't + available, can be one of: + * 'notify (use notifications-notify if possible) + * 'buffer (pop up a buffer with a message in) + * 'message (just use the message function) + * #'your-function in which case it'll run the function and + pass it the label + +It will fall back to message if nothing else works.") + +(defvar egg-timer-running-timers nil "Stores the running timers for egg-timer.el") + +(defun egg-timer-p () + "Return nil if an egg timer isn't running, t if one is." (interactive) - (unless label (setq label (format "%s minutes" minutes))) - (run-at-time - (format "%s minutes" minutes) - nil - (lambda () - (notifications-notify - :title "egg-timer.el" - :body (format "%s timer complete." label)))) - (message "%s timer scheduled." label)) + (if (and (not (equal egg-timer-running-timers nil)) + (listp egg-timer-running-timers) + (not (seq-empty-p egg-timer-running-timers))) + + ;; Yes timers + (progn + (if (called-interactively-p 'any) + (message "egg-timer-p: t")) + t) + + ;; No timers + (progn + (if (called-interactively-p 'any) + (message "egg-timer-p: nil")) + nil))) + +(defun egg-timer-list () + "Returns a list of all currently running egg-timer-events if +called interactively messages this list formatted with +'