Skip to content

Commit

Permalink
Add break configuration and notification
Browse files Browse the repository at this point in the history
  • Loading branch information
TatriX committed Mar 12, 2018
1 parent 3d14591 commit 3f9186e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,2 @@
## v0.2 12/03/2018
Add break duration config and notification. See `pomidor-break-seconds`.
20 changes: 12 additions & 8 deletions README.md
Expand Up @@ -54,13 +54,21 @@ This cycle goes on forever.

## Customization

You can customize pomidor with `M-x customize-group RET pomidor`.
You can customize pomidor with `M-x customize-group RET pomidor` or just edit your `.emacs`.

To disable sounds add to your .emacs:
To change timer length:
```lisp
(setq pomidor-seconds (* 25 60)) ; 25 minutes
(setq pomidor-break-seconds (* 5 60)) ; 5 minutes
```

To disable or configure sounds:
```lisp
(setq pomidor-sound-tick nil
pomidor-sound-tack nil
pomidor-sound-overwork nil)
pomidor-sound-overwork (expand-file-name (concat pomidor-dir "overwork.wav"))
pomidor-sound-break-over (expand-file-name (concat (getenv "HOME") "/Music/overwork.wav")))
```

To change appearance you may you `customize` or set faces via theme or directly:
Expand Down Expand Up @@ -102,13 +110,9 @@ To change notification you can set `pomidor-alert` variable (defaults to `pomido
```

Also you can set `pomidor-update-hook` to do some work on every update.
For example to be notified of break end:
```lisp
(defun my-pomidor-update-hook ()
(let ((break-duration 2) ;; seconds
(ellapsed (time-to-seconds (pomidor-break-duration))))
(when (and (> ellapsed break-duration) (pomidor--break (pomidor--current-state)))
(pomidor-play-sound-file-async pomidor-sound-overwork))))
(alert "Zzz"))
(add-hook 'pomidor-update-hook #'my-pomidor-update-hook)
```
Expand Down
55 changes: 41 additions & 14 deletions pomidor.el
Expand Up @@ -3,7 +3,7 @@
;; Author: TatriX <tatrics@gmail.com>
;; URL: https://github.com/TatriX/pomidor
;; Keywords: tools, time, applications, pomodoro technique
;; Version: 0.1
;; Version: 0.2
;; Package-Requires: ((emacs "24.3") (alert "1.2"))

;; This program is free software; you can redistribute it and/or modify
Expand All @@ -27,6 +27,7 @@
;;; Code:

(require 'cl-lib)
(require 'alert)

;;; Customs
(defgroup pomidor nil
Expand All @@ -41,6 +42,10 @@
"Time length of a Podomoro round."
:type 'integer :group 'pomidor)

(defcustom pomidor-break-seconds (* 5 60)
"Time length of a Podomoro break."
:type 'integer :group 'pomidor)

(defcustom pomidor-update-interval 60
"Interval in seconds when pomidor should run hooks and play overwork sounds."
:type 'integer :group 'pomidor)
Expand All @@ -63,21 +68,34 @@
"Tick sound during a pomoro run.")

(defvar pomidor-sound-overwork (expand-file-name (concat pomidor-dir "overwork.wav"))
"Tack sound during an overwork.")
"Overwork sound.")

(defvar pomidor-sound-break-over (expand-file-name (concat pomidor-dir "overwork.wav"))
"Break over sound.")

;; libnotify for some reason can't display svg
(defvar pomidor-icon (concat data-directory "images/icons/hicolor/16x16/apps/emacs.png")
"Default pomidor icon.")

(defun pomidor-default-alert-message ()
"Default pomidor alert message if any."
(cond
((pomidor-overwork-p)
(format "Take a break!\nOverwork: [%s]"
(format-time-string "%H:%M:%S" (pomidor-overwork-duration) t)))
((pomidor-break-over-p)
(format "Go back to work!\nBreak: [%s]"
(format-time-string "%H:%M:%S" (pomidor-break-duration) t)))))

(defun pomidor-default-alert ()
"Default pomidor alert."
(when (pomidor-overwork-p)
(alert (format "Take a break!\nOverwork: [%s]"
(format-time-string "%H:%M:%S" (pomidor-overwork-duration) t))
:severity 'normal
:icon pomidor-icon
:title "Pomidor"
:category 'pomidor)))
(let ((message (pomidor-default-alert-message)))
(when message
(alert message
:severity 'normal
:icon pomidor-icon
:title "Pomidor"
:category 'pomidor))))

(defvar pomidor-alert #'pomidor-default-alert
"Pomidor alert function.")
Expand Down Expand Up @@ -165,11 +183,13 @@
(plist-get state :break))

(defun pomidor--stopped (state)
"Return stopped time for STATE."
"Return stopped time for STATE.
It's a time when user started a new timer after this one."
(plist-get state :stopped))

(defun pomidor--ended (state)
"Return ended time for STATE."
"Return ended time for STATE.
It's either stopped time or current time."
(or (pomidor--stopped state) (current-time)))

(defun pomidor--work-duration (state)
Expand All @@ -183,7 +203,7 @@
max)))

(defun pomidor--overwork-duration (state)
"Return overwork time for STATE."
"Return overwork time for STATE or nil."
;; (cur - started) - (cur - break) - max
(let* ((started (pomidor--started state))
(break (or (pomidor--break state) (pomidor--ended state)))
Expand All @@ -202,6 +222,12 @@
(overwork (pomidor--overwork-duration state)))
(and overwork (null (pomidor--break state)))))

(defun pomidor-break-over-p ()
"Return t if current break is over."
(let* ((state (pomidor--current-state))
(break (pomidor--break-duration state)))
(and break (> (time-to-seconds break) pomidor-break-seconds))))

(defun pomidor--total-duration (state)
"Return total time for STATE."
(time-subtract (pomidor--ended state) (pomidor--started state)))
Expand Down Expand Up @@ -287,8 +313,9 @@ TIME may be nil."
(when (functionp pomidor-alert)
(funcall pomidor-alert))
(run-hooks 'pomidor-update-hook)
(when (pomidor-overwork-p)
(pomidor--play-sound-file pomidor-sound-overwork))))
(cond
((pomidor-overwork-p) (pomidor--play-sound-file pomidor-sound-overwork))
((pomidor-break-over-p) (pomidor--play-sound-file pomidor-sound-break-over)))))
(pomidor--render))

(defun pomidor--render ()
Expand Down

0 comments on commit 3f9186e

Please sign in to comment.