From 92f79c78e15170663b79d6466c5a6f0046ef0c2c Mon Sep 17 00:00:00 2001 From: jjanzen Date: Mon, 10 Mar 2025 13:24:27 -0500 Subject: [PATCH] initial commit --- pomodoro-mode.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 pomodoro-mode.el diff --git a/pomodoro-mode.el b/pomodoro-mode.el new file mode 100644 index 0000000..fa232ae --- /dev/null +++ b/pomodoro-mode.el @@ -0,0 +1,61 @@ +;; -*- lexical-binding: t -*- + +(defvar pomodoro-start-time 0) +(defvar pomodoro-state 'working) +(defconst pomodoro-work-time (* 25 60)) +(defconst pomodoro-break-time (* 5 60)) +(defconst pomodoro-work-symbol "🍅") +(defconst pomodoro-break-symbol "🥫") + +(defgroup pomodoro nil + "Pomodoro timer" + :group 'convenience) + +(defun pomodoro-get-status-string () + (defvar pomodoro-curr-time) + (defvar pomodoro-symbol) + (defvar pomodoro-delta) + (defvar pomodoro-max-time) + (defvar pomodoro-minutes) + (defvar pomodoro-seconds) + + (setq pomodoro-curr-time (floor (float-time))) + (setq pomodoro-delta (- pomodoro-curr-time pomodoro-start-time)) + (cond ((equal pomodoro-state 'working) + (setq pomodoro-symbol pomodoro-work-symbol) + (setq pomodoro-max-time pomodoro-work-time)) + ((equal pomodoro-state 'break) + (setq pomodoro-symbol pomodoro-break-symbol) + (setq pomodoro-max-time pomodoro-break-time)) + (t + (setq pomodoro-symbol "") + (setq pomodoro-max-time 0))) + (if (>= pomodoro-delta pomodoro-max-time) + (setq pomodoro-delta 0) + (setq pomodoro-delta (- pomodoro-max-time pomodoro-delta))) + (setq pomodoro-minutes (/ pomodoro-delta 60)) + (setq pomodoro-seconds (% pomodoro-delta 60)) + + (if (= pomodoro-delta 0) + (progn + (cond ((equal pomodoro-state 'working) + (setq pomodoro-state 'break)) + ((equal pomodoro-state 'break) + (setq pomodoro-state 'working)) + (t (message "should not occur"))) + (setq pomodoro-start-time (floor (float-time))))) + (format " %s (%02d:%02d)" pomodoro-symbol pomodoro-minutes pomodoro-seconds)) + +(progn + (setq pomodoro-start-time (- (floor (float-time)) 100)) + (pomodoro-get-status-string)) + +(define-minor-mode pomodoro-mode + "run a pomodoro timer" + :init-value nil + :lighter (:eval (pomodoro-get-status-string))) + +(define-globalized-minor-mode global-pomodoro-mode + pomodoro-mode pomodoro-mode + (setq pomodoro-state 'working) + (setq pomodoro-start-time (floor (float-time))))