Skip to content

Instantly share code, notes, and snippets.

@xcodebuild
Created August 12, 2015 05:50
Show Gist options
  • Select an option

  • Save xcodebuild/4e7a46f42c8db053c258 to your computer and use it in GitHub Desktop.

Select an option

Save xcodebuild/4e7a46f42c8db053c258 to your computer and use it in GitHub Desktop.
;; This piece is taken from:
;; http://sachachua.com/blog/2007/12/clocking-time-with-emacs-org/
(eval-after-load'org
'(progn
(defun wicked/org-clock-in-if-starting ()
"Clock in when the task is marked STARTED."
(when (and (string= org-state "STARTED")
(not (string= org-last-state org-state)))
(org-clock-in)))
(add-hook'org-after-todo-state-change-hook
'wicked/org-clock-in-if-starting)
(defadvice org-clock-in (after wicked activate)
"Set this task's status to'STARTED'."
(org-todo "STARTED"))
(defun wicked/org-clock-out-if-waiting ()
"Clock out when the task is marked WAITING or PAUSED."
(when (and (or (string= org-state "WAITING")
(string= org-state "PAUSED"))
(equal (marker-buffer org-clock-marker) (current-buffer))
(<(point) org-clock-marker)
(> (save-excursion (outline-next-heading) (point))
org-clock-marker)
(not (string= org-last-state org-state)))
(org-clock-out)))
(add-hook'org-after-todo-state-change-hook
'wicked/org-clock-out-if-waiting)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment