Skip to content

Instantly share code, notes, and snippets.

@bravosierrasierra
Last active August 1, 2021 15:56
Show Gist options
  • Save bravosierrasierra/1d98a89a7bcb618ef70c6c4a92af1a96 to your computer and use it in GitHub Desktop.
Save bravosierrasierra/1d98a89a7bcb618ef70c6c4a92af1a96 to your computer and use it in GitHub Desktop.
;; see https://github.com/lolownia/org-pomodoro
;; and use case from http://headhole.org/organisation/2012/08/22/org-mode-gtd-and-the-pomodoro-technique/
(use-package org-pomodoro
:config
(global-set-key (kbd "M-<f11>") 'org-pomodoro)
(global-set-key (kbd "s-<f11>") 'org-pomodoro)
;; (global-set-key (kbd "C-c C-x C-i") 'org-pomodoro)
;; (global-set-key (kbd "C-c C-x C-o") 'org-pomodoro)
;; (defun bss/custom-org-agenda-mode-defaults ()
;; (org-defkey org-agenda-mode-map "I" 'org-pomodoro)
;; (org-defkey org-agenda-mode-map "O" 'org-pomodoro)
;; (org-defkey org-agenda-mode-map (kbd "C-c C-x C-i") 'org-pomodoro)
;; (org-defkey org-agenda-mode-map (kbd "C-c C-x C-o") 'org-pomodoro))
;; (add-hook 'org-agenda-mode-hook 'bss/custom-org-agenda-mode-defaults 'append)
(setq org-pomodoro-play-sounds t
org-pomodoro-start-sound-p t
org-pomodoro-finished-sound-p t
org-pomodoro-killed-sound-p t
org-pomodoro-short-break-sound-p t
org-pomodoro-long-break-sound-p t
org-pomodoro-finished-sound (expand-file-name "~/.emacs.d/manual-addons/sounds/end.wav")
;; org-pomodoro-finished-sound ""
org-pomodoro-short-break-sound (expand-file-name "~/.emacs.d/manual-addons/sounds/horn_attack.wav")
org-pomodoro-long-break-sound (expand-file-name "~/.emacs.d/manual-addons/sounds/horn_attack.wav")
org-pomodoro-ticking-sound (expand-file-name "~/.emacs.d/manual-addons/pomidor/tick.wav")
org-pomodoro-ticking-sound-p t)
;; platform-specific settings
(cond ((eq system-type 'darwin)
(setq org-pomodoro-audio-player "/usr/bin/afplay")
)
((eq system-type 'windows-nt)
;;(add-to-list 'exec-path "C:/emacs/mplayer/")
(setq org-pomodoro-audio-player "C:/emacs/bin/swavplayer.exe"
org-pomodoro-start-sound-args ""
org-pomodoro-finished-sound-args ""
org-pomodoro-killed-sound-args ""
pomodoro-short-break-sound-args ""
pomodoro-long-break-sound-args ""
pomodoro-ticking-sound-args ""))
(t (setq org-pomodoro-audio-player "/usr/bin/aplay")))
;;--------------------------------------------------
(setq org-pomodoro-plus-enabled t
pomodoro-kicker-timer nil ;; "Actual timer for pomodoro-kicker-timer."
)
;; replace original sound play
(if org-pomodoro-plus-enabled
(setq org-pomodoro-play-sounds nil
;; (setq org-pomodoro-play-sounds t) ;; debug
pomodoro-kicker-timer-idle-minutes 10 ;; "Maximum idle time for procrastination, minutes"
;; (setq pomodoro-kicker-timer-idle-minutes 1) ; debug
org-pomodoro-plus-kicker-enabled t
org-pomodoro-plus-sound-enabled t ;; "use long sound file instead tick every second"
org-pomodoro-plus-break-ticking-volume "0.1" ;; macos only
org-pomodoro-plus-main-ticking-volume "0.3" ;; macos only
org-pomodoro-1h-ticking-sound (expand-file-name "~/.emacs.d/manual-addons/sounds/ticktack1h.mp3")
org-pomodoro-plus-go-to-work-sound (expand-file-name "~/.emacs.d/manual-addons/sounds/horn_attack.wav")
org-pomodoro-stop-procrastination-sound (expand-file-name "~/.emacs.d/manual-addons/sounds/horn_attack.wav")
org-pomodoro-plus-end-sound (expand-file-name "~/.emacs.d/manual-addons/sounds/end.wav")
org-pomodoro-plus-ticktack-process-name (format "org-pomodoro plus play %s"
(file-name-nondirectory org-pomodoro-1h-ticking-sound ))
org-pomodoro-finished-sound "" ;; disable original org-pomodoro sound
;; Текст всплывающих сообщений
;; org-poodoro-plus-pomodoro-finished-msg-title (format "Pomodoro: перерыв %s минут" (format-seconds "%m" org-pomodoro-countdown))
org-pomodoro-plus-pomodoro-finished-msg-title "Pomodoro: перерыв %s минут"
org-pomodoro-plus-pomodoro-finished-msg-text "Сделай перерыв, иначе закопаешься в неважном!"
org-pomodoro-plus-pomodoro-stopped-msg-title "Pomodoro: к станку, вечер близко!"
org-pomodoro-plus-pomodoro-stopped-msg-text "Ограничь каждую активность timebox-ом, делай MVP, обеспечь перерывы."
;; "Делай MVP, переключайся между важным и вовремя останавливайся.")
org-pomodoro-plus-pomodoro-kicker-msg-title "Pomodoro: что ты сейчас делаешь?"
org-pomodoro-plus-pomodoro-kicker-msg-text "Зачем ты это делаешь?\nНе отлыниваешь ли ты от задачи?"
)
)
;; debug helping commands
;; (setq org-pomodoro-length 25)
;; (setq org-pomodoro-length 1)
;; (setq org-pomodoro-short-break-length 5)
;; (setq org-pomodoro-short-break-length 1)
;; (setq org-pomodoro-long-break-length 20)
;; (setq org-pomodoro-long-break-length 1)
(defun org-pomodoro-plus-play-sound (snd)
;; (interactive)
(setq procname (format "org-pomodoro plus play %s" (file-name-nondirectory snd)))
(cond ((eq system-type 'darwin)
(setq org-pomodoro-plus-needed-volume org-pomodoro-plus-main-ticking-volume)
(if (or (eq org-pomodoro-state :short-break)
(eq org-pomodoro-state :long-break))
(setq org-pomodoro-plus-needed-volume org-pomodoro-plus-break-ticking-volume))
(start-process procname "mybufname" org-pomodoro-audio-player "-v" org-pomodoro-plus-needed-volume snd)
)
(t (start-process procname nil org-pomodoro-audio-player snd)))
(if (get-process procname )
(set-process-query-on-exit-flag (get-process procname) nil))
)
;; ------------------ Begin pomodoro kicker ------------------
(defun pomodoro-kicker-timer-mode-start ()
"Start pomodoro kicker timer mode"
(interactive)
(setq org-pomodoro-plus-kicker-enabled t)
(pomodoro-kicker-start-timer)
)
(defun pomodoro-kicker-timer-mode-stop ()
"Stop pomodoro kicker timer mode"
(interactive)
(setq org-pomodoro-plus-kicker-enabled nil)
(pomodoro-kicker-stop-timer)
)
(defun pomodoro-kicker-timer-alert()
"Alert for antiprocrastination"
(interactive)
(when org-pomodoro-plus-kicker-enabled
(org-pomodoro-plus-play-sound org-pomodoro-stop-procrastination-sound)
(message "Procrastination limit reached. Go to pomodoro!")
(djcb-popup org-pomodoro-plus-pomodoro-kicker-msg-title
org-pomodoro-plus-pomodoro-kicker-msg-text)
(pomodoro-kicker-start-timer)
)
)
(defun pomodoro-kicker-start-timer()
"start procrastination idle timer"
;; (interactive)
;; stop previous if exist
(when (timerp pomodoro-kicker-timer)
(cancel-timer pomodoro-kicker-timer))
(when org-pomodoro-plus-kicker-enabled
(message (format "Procrastination timer started %s"
(format-time-string "%a %H:%M:%S" (current-time))))
(setq pomodoro-kicker-timer (run-with-timer (* 60 pomodoro-kicker-timer-idle-minutes) nil 'pomodoro-kicker-timer-alert))
)
)
(defun pomodoro-kicker-stop-timer()
"stop procrastination idle timer"
;; (interactive)
(when (timerp pomodoro-kicker-timer)
(cancel-timer pomodoro-kicker-timer))
)
;; ------------------ End pomodoro kicker ------------------
(defun bss/is-workday-p ()
"Is today a workday?"
(interactive)
(let ((day-of-week (nth 6 (decode-time (current-time)))))
(if (member day-of-week
;; Mon Tue Wed Thu Fri
'(1 2 3 4 5))
;; (message "Today is a workday")
)
))
;; ---------- org-pomodoro-plus sound management replacement ----------
(setq org-pomodoro-plus-end-timer nil)
(defun org-pomodoro-plus-end-signal ()
;; (interactive)
(org-pomodoro-plus-play-sound org-pomodoro-plus-end-sound)
)
(defun org-pomodoro-plus-go-to-work-signal ()
"Breack ended. Go to work!"
;; (interactive)
(org-pomodoro-plus-play-sound org-pomodoro-plus-go-to-work-sound)
)
;; (defun org-pomodoro-plus-around (orig-fun &rest args)
;; (apply orig-fun args)))
;; (advice-add 'evil-next-line :around 'evil-next-line--check-visual-line-mode)
(defun org-pomodoro-plus-pomodoro-started-hook ()
(interactive)
;; stop procrastination timer to pomodoro break end
(pomodoro-kicker-stop-timer)
;; start background playing long ticktack file
(if (get-process org-pomodoro-plus-ticktack-process-name )
(delete-process org-pomodoro-plus-ticktack-process-name ))
(when (timerp org-pomodoro-plus-end-timer)
(cancel-timer org-pomodoro-plus-end-timer))
(setq org-pomodoro-plus-end-timer (run-with-timer (- (* 60 org-pomodoro-length) 6) nil 'org-pomodoro-plus-end-signal))
(org-pomodoro-plus-play-sound org-pomodoro-1h-ticking-sound)
)
(defun org-pomodoro-plus-pomodoro-stopped-hook ()
(interactive)
;; start procrastination timer
(pomodoro-kicker-start-timer)
;; stop background playing long ticktack file
(if (get-process org-pomodoro-plus-ticktack-process-name )
(delete-process org-pomodoro-plus-ticktack-process-name ))
;; say user to go to work
(djcb-popup org-pomodoro-plus-pomodoro-stopped-msg-title
org-pomodoro-plus-pomodoro-stopped-msg-text)
)
(defun org-pomodoro-plus-pomodoro-finished-hook ()
"play 5s end sound"
(interactive)
(org-pomodoro-plus-play-sound org-pomodoro-finished-sound)
;; say user to get break
(djcb-popup (format org-pomodoro-plus-pomodoro-finished-msg-title (format-seconds "%m" org-pomodoro-countdown))
org-pomodoro-plus-pomodoro-finished-msg-text)
;; restart ticking process with different volume
(if (get-process org-pomodoro-plus-ticktack-process-name )
(delete-process org-pomodoro-plus-ticktack-process-name ))
(org-pomodoro-plus-play-sound org-pomodoro-1h-ticking-sound)
)
(defun org-pomodoro-plus-pomodoro-killed-hook ()
"stop any sounds"
(interactive)
;; (message (format "pomodoro-kicker-killed-hook() called at %s"
;; (format-time-string "%a %H:%M:%S" (current-time))))
(if (get-process org-pomodoro-plus-ticktack-process-name )
(delete-process org-pomodoro-plus-ticktack-process-name ))
;; start procrastination timer
(pomodoro-kicker-start-timer)
)
(defun org-pomodoro-plus-stop-ticking ()
"stop ticking for this pomodoro"
(interactive)
(if (get-process org-pomodoro-plus-ticktack-process-name )
(delete-process org-pomodoro-plus-ticktack-process-name ))
)
(defun org-pomodoro-plus-restore-ticking ()
"restore ticking for this pomodoro"
(interactive)
(if (get-process org-pomodoro-plus-ticktack-process-name )
(delete-process org-pomodoro-plus-ticktack-process-name ))
(if (not (eq org-pomodoro-state :none))
(org-pomodoro-plus-play-sound org-pomodoro-1h-ticking-sound))
)
(if org-pomodoro-plus-enabled
(progn
(add-hook 'org-pomodoro-started-hook #'org-pomodoro-plus-pomodoro-started-hook)
(add-hook 'org-pomodoro-finished-hook #'org-pomodoro-plus-pomodoro-finished-hook)
(add-hook 'org-pomodoro-break-finished-hook #'org-pomodoro-plus-go-to-work-signal)
(add-hook 'org-pomodoro-short-break-finished-hook #'org-pomodoro-plus-pomodoro-stopped-hook)
(add-hook 'org-pomodoro-long-break-finished-hook #'org-pomodoro-plus-pomodoro-stopped-hook)
(add-hook 'org-pomodoro-killed-hook #'org-pomodoro-plus-pomodoro-killed-hook)
(run-at-time "9:30" 86400 '(lambda ()
(if (and org-pomodoro-plus-enabled ;; may be not enabled at timer run time
(member (nth 6 (decode-time (current-time))) '(1 2 3 4 5))
(not (eq org-pomodoro-state :none)) ;; we may be already in pomodoro
;; (eq org-pomodoro-state :none) ;; we may be already in pomodoro
) ;; check if workday
(pomodoro-kicker-timer-mode-start))))
(run-at-time "17:30" 86400 '(lambda ()
(if (and org-pomodoro-plus-enabled ;; may be not enabled at timer run time
(member (nth 6 (decode-time (current-time))) '(1 2 3 4 5))) ;; check if workday
(pomodoro-kicker-timer-mode-stop))))
)
)
;; ---------- org-pomodoro-plus sound management replacement ----------
)
(defhydra hydra-org-clock (:hint nil)
"
^Clock:^ ^In/out^ ^Edit^ ^Summary^ | ^Timers:^ ^Run^ ^Insert
-^-^-----^-^----------^-^------^-^----------|--^-^------^-^-------------^------
(_?_) _i_n _e_dit _g_oto entry | (_z_) _r_elative ti_m_e
^ ^ _c_ontinue _Q_uit _d_isplay | ^ ^ cou_n_tdown it_E_m
^ ^ _o_ut ^ ^ _R_eport | ^ ^ _p_ause toggle
^ ^ h_I_story ^ ^ ^ ^ | ^ ^ _s_top
------------------------------------------------------------------------------
^Pomodoro:^
_k_icker state: %(if org-pomodoro-plus-kicker-enabled \"Enabled\" \"Disabled\") _t_icking state: %(if (get-process org-pomodoro-plus-ticktack-process-name) \"Enabled\" \"Disabled\")
"
("t" (if (get-process org-pomodoro-plus-ticktack-process-name) (org-pomodoro-plus-stop-ticking) (org-pomodoro-plus-restore-ticking)))
("k" (if org-pomodoro-plus-kicker-enabled (pomodoro-kicker-timer-mode-stop) (pomodoro-kicker-timer-mode-start)))
("i" org-clock-in)
;; ("I" (lambda () (interactive) (let ((current-prefix-arg '(4))) ((org-clock-in)))))
("I" (org-clock-in '(4) t))
("c" org-clock-in-last)
("o" org-clock-out)
("e" org-clock-modify-effort-estimate)
("Q" org-clock-cancel)
("g" org-clock-goto)
("d" org-clock-display)
("R" org-clock-report)
("?" (org-info "Clocking commands"))
;; ("k" pomodoro-kicker-timer-mode-start)
;; ("K" pomodoro-kicker-timer-mode-stop)
("D" org-pomodoro-plus-stop-ticking)
("E" org-pomodoro-plus-restore-ticking)
("r" org-timer-start)
("n" org-timer-set-timer)
("p" org-timer-pause-or-continue)
("s" org-timer-stop)
("m" org-timer)
("E" org-timer-item)
("z" (org-info "Timers")))
(bind-key "C-c w" 'hydra-org-clock/body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment