Skip to content

Commit

Permalink
Merge pull request #37 from wandersoncferreira/feature/long-break
Browse files Browse the repository at this point in the history
add feature long breaks
  • Loading branch information
TatriX committed May 13, 2020
2 parents f93b09e + fe1a9e9 commit 308a438
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## v.06 06/05/2020
Add pomidor long breaks after `pomidor-breaks-before-long` with
`pomidor-long-break-seconds` amount of time.

## v.05 04/05/2020
Add `pomidor-hold` and `pomidor-unhold` functions to keep a period of
time without working on your pomidor sessions and resume when needed.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -113,6 +113,12 @@ To change timer duration:
```

To change behavior of long breaks:
``` elisp
(setq pomidor-breaks-before-long 4) ; wait 4 short breaks before long break
(setq pomidor-long-break-seconds (* 20 60)) ; 20 minutes long break time
```

To disable or configure sounds:
```elisp
(setq pomidor-sound-tick nil
Expand Down
40 changes: 36 additions & 4 deletions pomidor.el
Expand Up @@ -100,13 +100,24 @@
:type '(file :must-match t)
:group 'pomidor)

(defcustom pomidor-breaks-before-long 4
"How many short breaks before the long break."
:type 'integer :group 'pomidor)

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

;; 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
((and (pomidor-overwork-p) (pomidor-should-long-break-p))
(format "Take a long break!\nOverwork: [%s]"
(format-time-string "%H:%M:%S" (pomidor-overwork-duration) t)))
((pomidor-overwork-p)
(format "Take a break!\nOverwork: [%s]"
(format-time-string "%H:%M:%S" (pomidor-overwork-duration) t)))
Expand Down Expand Up @@ -207,6 +218,9 @@ To disable sounds, set to nil."
(defvar pomidor--current-history-session nil
"Hold the current visible pomidor history snapshot.")

(defvar pomidor--count-short-breaks 0
"Pomidor integer of how many short breaks we have before a long break.")

(defvar pomidor--system-on-hold-p nil
"Pomidor control of hold in system.")

Expand Down Expand Up @@ -279,6 +293,10 @@ It's either stopped time or current time."
(overwork (pomidor--overwork-duration state)))
(and overwork (null (pomidor--break state)))))

(defun pomidor-should-long-break-p ()
"Return t if current state should take a long break."
(equalp pomidor--count-short-breaks (1+ pomidor-breaks-before-long)))

(defun pomidor-break-over-notify-p ()
"Return t if current break is over and user should be notified about it.
To snooze the notification use `pomidor-break'."
Expand All @@ -287,8 +305,11 @@ To snooze the notification use `pomidor-break'."
(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))))
(break (pomidor--break-duration state))
(expected-break-seconds (if (pomidor-should-long-break-p)
pomidor-long-break-seconds
pomidor-break-seconds)))
(and break (> (time-to-seconds break) expected-break-seconds))))

(defun pomidor-snooze-p ()
"Return t if user snooze end of break alarm."
Expand Down Expand Up @@ -525,6 +546,11 @@ TIME may be nil."
(when (y-or-n-p "Are you sure you want to turn off pomidor? ")
(kill-buffer (pomidor--get-buffer-create))))

(defun pomidor--reset-long-break-counter ()
"Reset the pomidor counter after `pomidor-breaks-before-long' short breaks."
(when (pomidor-should-long-break-p)
(setq pomidor--count-short-breaks 0)))

(defun pomidor-break ()
"Break current working pomidor."
(interactive)
Expand All @@ -534,20 +560,25 @@ TIME may be nil."
(plist-put state :snooze t)
(when (or (not pomidor-confirm-end-break)
(yes-or-no-p "Stop break and start new pomidor?"))
(pomidor-stop)))
(plist-put state :break (current-time)))))
(pomidor-stop))
(pomidor--reset-long-break-counter))
(progn
(plist-put state :break (current-time))
(setq pomidor--count-short-breaks (1+ pomidor--count-short-breaks))))))

(defun pomidor-reset ()
"Delete current global state."
(interactive)
(when (y-or-n-p "Are you sure you want reset pomidors? ")
(setq pomidor--count-short-breaks 0)
(pomidor--reset)))

(defun pomidor-stop ()
"Stop current working pomidor."
(interactive)
(let ((state (pomidor--current-state)))
(plist-put state :stopped (current-time)))
(pomidor--reset-long-break-counter)
(nconc pomidor-global-state (list (pomidor--make-state))))

(defun pomidor-hold ()
Expand Down Expand Up @@ -675,6 +706,7 @@ TIME may be nil."
(interactive)
(switch-to-buffer (pomidor--get-buffer-create))
(unless (eq major-mode 'pomidor-mode)
(setq pomidor--count-short-breaks 0)
(pomidor-mode))
(pomidor--update))

Expand Down

0 comments on commit 308a438

Please sign in to comment.