Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add org-pomodoro-before-start-hook. #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions org-pomodoro.el
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ whether to reset the pomodoro count next time you call `org-pomodoro'."
:type 'boolean)

;; Hooks
(defvar org-pomodoro-before-start-hook nil
"Hooks run before a pomodoro is started.")

(defvar org-pomodoro-started-hook nil
"Hooks run when a pomodoro is started.")
Expand Down Expand Up @@ -441,9 +443,18 @@ invokes the handlers for finishing."
(setq org-pomodoro-state state
org-pomodoro-end-time
(cl-case state
(:pomodoro (time-add (current-time) (* 60 org-pomodoro-length)))
(:short-break (time-add (current-time) (* 60 org-pomodoro-short-break-length)))
(:long-break (time-add (current-time) (* 60 org-pomodoro-long-break-length))))
(:pomodoro
(time-add (current-time)
(* 60 (string-to-int (read-string "Pomodoro duration: "
(format "%s" org-pomodoro-length))))))
(:short-break
(time-add (current-time)
(* 60 (string-to-int (read-string "Short break duration: "
(format "%s" org-pomodoro-short-break-length))))))
(:long-break
(time-add (current-time)
(* 60 (string-to-int (read-string "Long break duration: "
(format "%s" org-pomodoro-long-break-length)))))))
org-pomodoro-timer (run-with-timer t 1 'org-pomodoro-tick)))

(defun org-pomodoro-start (&optional state)
Expand All @@ -457,6 +468,8 @@ The argument STATE is optional. The default state is `:pomodoro`."
(setq global-mode-string (append global-mode-string
'(org-pomodoro-mode-line))))

(run-hooks 'org-pomodoro-before-start-hook)

(org-pomodoro-set (or state :pomodoro))

(when (eq org-pomodoro-state :pomodoro)
Expand Down Expand Up @@ -488,8 +501,10 @@ This may send a notification, play a sound and start a pomodoro break."
(org-pomodoro-maybe-play-sound :pomodoro)
(setq org-pomodoro-count (+ org-pomodoro-count 1))
(if (zerop (mod org-pomodoro-count org-pomodoro-long-break-frequency))
(org-pomodoro-start :long-break)
(org-pomodoro-start :short-break))
(when (yes-or-no-p "Do you want to start a long break?")
(org-pomodoro-start :long-break))
(when (yes-or-no-p "Do you want to start a short break?")
(org-pomodoro-start :short-break)))
(org-pomodoro-notify "Pomodoro completed!" "Time for a break.")
(org-pomodoro-update-mode-line)
(org-agenda-maybe-redo)
Expand Down