Skip to content

Instantly share code, notes, and snippets.

@doitian
Last active February 3, 2018 12:59
Show Gist options
  • Save doitian/4352441 to your computer and use it in GitHub Desktop.
Save doitian/4352441 to your computer and use it in GitHub Desktop.
org-pomodoro: estimate using # pomodoro, see clocksum using # pomodoro, show timer in modelline TODO: make it a package
(defvar org-pomodoro-minutes 25)
(defvar org-pomodoro-cancelling nil)
(defvar org-pomodoro-command (locate-file "pomodoro" exec-path))
(defun org-pomodoro-on-org-load ()
(push (cons "p" org-pomodoro-minutes) org-effort-durations)
(push '("Effort_ALL" . "1p 2p 3p 4p 5p 6p 7p 8p") org-global-properties)
(define-key org-mode-map "\C-c\C-x'" 'org-pomodoro-columns)
(define-key org-agenda-mode-map "\C-c\C-x'" 'org-pomodoro-agenda-columns))
(eval-after-load "org" '(org-pomodoro-on-org-load))
(defadvice org-minutes-to-hh:mm-string (around org-pomodoro-minutes-to-pomodoros activate)
(setq ad-return-value (format "%dp" (round (/ m (float org-pomodoro-minutes))))))
(defadvice org-columns-number-to-string (around org-pomodoro-minutes-to-pomodoros activate)
(if (memq fmt '(add_times max_times min_times mean_times))
(setq ad-return-value (format "%dp" (round (/ (* n 60) org-pomodoro-minutes))))
ad-do-it))
(defun org-pomodoro-after-clock-in ()
(when (not org-timer-current-timer)
(org-timer-set-timer org-pomodoro-minutes)))
(defun org-pomodoro-after-clock-out ()
(unless org-pomodoro-cancelling
(org-pomodoro-cancel-timer-safe)))
(defun org-pomodoro-is-indivisible! ()
(let ((org-clock-out-remove-zero-time-clocks nil)
(org-pomodoro-cancelling t)
(buffer (current-buffer))
(point (point)))
(when (org-clock-is-active)
(setq buffer (marker-buffer org-clock-marker)
point (marker-position org-clock-marker))
(org-clock-out))
(save-excursion
(with-current-buffer buffer
(save-restriction
(widen)
(goto-char point)
(beginning-of-line 1)
(when (and (not remove)
(looking-at (concat "[ \t]*" org-keyword-time-regexp))
(equal (match-string 1) org-clock-string))
(goto-char (match-end 0))
(beginning-of-line 1)
(kill-line 1)
(message "Pomodoro is cancelled")))))))
(defun org-pomodoro-done ()
(when (org-clock-is-active) (org-clock-out)))
(defun org-pomodoro-cancel-timer-safe ()
(when org-timer-current-timer (org-timer-cancel-timer)))
(add-hook 'org-timer-pause-hook 'org-pomodoro-cancel-timer-safe)
(add-hook 'org-timer-continue-hook 'org-pomodoro-cancel-timer-safe)
(add-hook 'org-timer-stop-hook 'org-pomodoro-cancel-timer-safe)
(add-hook 'org-timer-cancel-hook 'org-pomodoro-is-indivisible!)
(add-hook 'org-timer-done-hook 'org-pomodoro-done)
(add-hook 'org-clock-in-hook 'org-pomodoro-after-clock-in)
(add-hook 'org-clock-out-hook 'org-pomodoro-after-clock-out)
(defvar org-pomodoro-columns-format
"%22SCHEDULED %CATEGORY %42ITEM %3Effort(E){:} %3CLOCKSUM_T(R) %POMODORO_INTERRUPTIONS(I){+}")
(defun org-pomodoro-columns ()
(interactive)
(org-columns org-pomodoro-columns-format))
(defun org-pomodoro-agenda-columns ()
(interactive)
(let ((org-agenda-overriding-columns-format org-pomodoro-columns-format))
(org-agenda-columns)))
(defun org-pomodoro-record-interuptions (char)
(interactive (list
(if (string=
"internal"
(completing-read "type: " '("internal" "external") nil t nil nil "internal"))
?' ?-)))
(if (and org-clock-current-task org-clock-marker)
(save-excursion
(with-current-buffer (marker-buffer org-clock-marker)
(goto-char org-clock-marker)
(let ((value (concat (sort (cons char (string-to-list (org-entry-get nil "POMODORO_INTERUPTIONS"))) '<))))
(org-entry-put nil "POMODORO_INTERUPTIONS" value)
(org-entry-put nil "POMODORO_INTERUPTIONS_COUNT" (number-to-string (length value)))
(message "Interuptions: %s" value))))
(error "no active pomodoro")))
(provide 'org-pomodoro)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment