Commit f21394ca107c

Vincent Demeester <vincent@sbr.pm>
2020-03-11 18:57:02
org-mode: update clocking
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 70b28f2
Changed files (2)
config/setup-org.el
@@ -295,7 +295,94 @@
   :after org
   :commands (org-clock-in org-clock-out org-clock-goto)
   :config
-  (setq org-clock-clocked-in-display nil)
+  ;; Setup hooks for clock persistance
+  (org-clock-persistence-insinuate)
+  (setq org-clock-clocked-in-display nil
+        ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
+        org-clock-history-length 23
+        ;; Change tasks to STARTED when clocking in
+        org-clock-in-switch-to-state 'vde/clock-in-to-started
+        ;; Clock out when moving task to a done state
+        org-clock-out-when-done t
+        ;; Save the running clock and all clock history when exiting Emacs, load it on startup
+        org-clock-persist t)
+  (use-package find-lisp)
+  (defun vde/is-project-p ()
+    "Any task with a todo keyword subtask"
+    (save-restriction
+      (widen)
+      (let ((has-subtask)
+            (subtree-end (save-excursion (org-end-of-subtree t)))
+            (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
+        (save-excursion
+          (forward-line 1)
+          (while (and (not has-subtask)
+                      (< (point) subtree-end)
+                      (re-search-forward "^\*+ " subtree-end t))
+            (when (member (org-get-todo-state) org-todo-keywords-1)
+              (setq has-subtask t))))
+        (and is-a-task has-subtask))))
+
+  (defun vde/is-project-subtree-p ()
+    "Any task with a todo keyword that is in a project subtree.
+Callers of this function already widen the buffer view."
+    (let ((task (save-excursion (org-back-to-heading 'invisible-ok)
+                                (point))))
+      (save-excursion
+        (vde/find-project-task)
+        (if (equal (point) task)
+            nil
+          t))))
+
+  (defun vde/find-project-task ()
+    "Move point to the parent (project) task if any"
+    (save-restriction
+      (widen)
+      (let ((parent-task (save-excursion (org-back-to-heading 'invisible-ok) (point))))
+        (while (org-up-heading-safe)
+          (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
+            (setq parent-task (point))))
+        (goto-char parent-task)
+        parent-task)))
+
+  (defun vde/is-task-p ()
+    "Any task with a todo keyword and no subtask"
+    (save-restriction
+      (widen)
+      (let ((has-subtask)
+            (subtree-end (save-excursion (org-end-of-subtree t)))
+            (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
+        (save-excursion
+          (forward-line 1)
+          (while (and (not has-subtask)
+                      (< (point) subtree-end)
+                      (re-search-forward "^\*+ " subtree-end t))
+            (when (member (org-get-todo-state) org-todo-keywords-1)
+              (setq has-subtask t))))
+        (and is-a-task (not has-subtask)))))
+
+  (defun vde/is-subproject-p ()
+    "Any task which is a subtask of another project"
+    (let ((is-subproject)
+          (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
+      (save-excursion
+        (while (and (not is-subproject) (org-up-heading-safe))
+          (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
+            (setq is-subproject t))))
+      (and is-a-task is-subproject)))
+
+  (defun vde/clock-in-to-started (kw)
+    "Switch a task from TODO to STARTED when clocking in.
+Skips capture tasks, projects, and subprojects.
+Switch projects and subprojects from STARTED back to TODO"
+    (when (not (and (boundp 'org-capture-mode) org-capture-mode))
+      (cond
+       ((and (member (org-get-todo-state) (list "TODO"))
+             (vde/is-task-p))
+        "STARTED")
+       ((and (member (org-get-todo-state) (list "STARTED"))
+             (vde/is-project-p))
+        "TODO"))))
   :bind (("<f11>" . org-clock-goto)))
 ;; -OrgClock
 
@@ -367,94 +454,6 @@
   :defer t
   :ensure org-plus-contrib
   :config
-  (use-package find-lisp)
-
-  (defun vde/is-project-p ()
-    "Any task with a todo keyword subtask"
-    (save-restriction
-      (widen)
-      (let ((has-subtask)
-            (subtree-end (save-excursion (org-end-of-subtree t)))
-            (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
-        (save-excursion
-          (forward-line 1)
-          (while (and (not has-subtask)
-                      (< (point) subtree-end)
-                      (re-search-forward "^\*+ " subtree-end t))
-            (when (member (org-get-todo-state) org-todo-keywords-1)
-              (setq has-subtask t))))
-        (and is-a-task has-subtask))))
-
-  (defun vde/is-project-subtree-p ()
-    "Any task with a todo keyword that is in a project subtree.
-Callers of this function already widen the buffer view."
-    (let ((task (save-excursion (org-back-to-heading 'invisible-ok)
-                                (point))))
-      (save-excursion
-        (vde/find-project-task)
-        (if (equal (point) task)
-            nil
-          t))))
-
-  (defun vde/find-project-task ()
-    "Move point to the parent (project) task if any"
-    (save-restriction
-      (widen)
-      (let ((parent-task (save-excursion (org-back-to-heading 'invisible-ok) (point))))
-        (while (org-up-heading-safe)
-          (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
-            (setq parent-task (point))))
-        (goto-char parent-task)
-        parent-task)))
-
-  (defun vde/is-task-p ()
-    "Any task with a todo keyword and no subtask"
-    (save-restriction
-      (widen)
-      (let ((has-subtask)
-            (subtree-end (save-excursion (org-end-of-subtree t)))
-            (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
-        (save-excursion
-          (forward-line 1)
-          (while (and (not has-subtask)
-                      (< (point) subtree-end)
-                      (re-search-forward "^\*+ " subtree-end t))
-            (when (member (org-get-todo-state) org-todo-keywords-1)
-              (setq has-subtask t))))
-        (and is-a-task (not has-subtask)))))
-
-  (defun vde/is-subproject-p ()
-    "Any task which is a subtask of another project"
-    (let ((is-subproject)
-          (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
-      (save-excursion
-        (while (and (not is-subproject) (org-up-heading-safe))
-          (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
-            (setq is-subproject t))))
-      (and is-a-task is-subproject)))
-
-  (org-clock-persistence-insinuate)
-  ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
-  (setq org-clock-history-length 23)
-  ;; Change tasks to STARTED when clocking in
-  (setq org-clock-in-switch-to-state 'vde/clock-in-to-started)
-  ;; Clock out when moving task to a done state
-  (setq org-clock-out-when-done t)
-  ;; Save the running clock and all clock history when exiting Emacs, load it on startup
-  (setq org-clock-persist t)
-
-  (defun vde/clock-in-to-started (kw)
-    "Switch a task from TODO to STARTED when clocking in.
-Skips capture tasks, projects, and subprojects.
-Switch projects and subprojects from STARTED back to TODO"
-    (when (not (and (boundp 'org-capture-mode) org-capture-mode))
-      (cond
-       ((and (member (org-get-todo-state) (list "TODO"))
-             (vde/is-task-p))
-        "STARTED")
-       ((and (member (org-get-todo-state) (list "STARTED"))
-             (vde/is-project-p))
-        "TODO"))))
 
   (defvar org-capture-templates (list))
   (setq org-protocol-default-template-key "l")
emacs.org
@@ -837,37 +837,50 @@
 
 #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgProtocol" :range-end "-OrgProtocol" :lines "289-291"
 
-*** TODO Clocking
+*** Clocking
 :PROPERTIES:
 :CUSTOM_ID: h:264afe05-79e3-4bff-aafc-9fc726c4034b
 :END:
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgClock" :range-end "-OrgClock" :lines "294-300"
+I am heavily using the clocking along with =org-agenda=. My usual workflow, related to
+clocking is :
+
+- I bring the Agenda up
+- I clock the task I am working on, using =I= in the agenda
+- When I stop working on the task
+  + if the task is completed, I use =t d= to mark it as done, the clock should
+    automatically stop.
+  + if the task is not completed, I use =O= to stop the clock
+
+In addition to that workflow, I want to switch the state of the task to =STARTED= when I
+am clocking-in, if it's not already =STARTED=.
+
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgClock" :range-end "-OrgClock" :lines "294-387"
 
 *** TODO Links
 :PROPERTIES:
 :CUSTOM_ID: h:afc81fbb-f7a0-401c-8b56-19f51edebd88
 :END:
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgAttach" :range-end "-OrgAttach" :lines "303-306"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgAttach" :range-end "-OrgAttach" :lines "390-393"
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgLinks" :range-end "-OrgLinks" :lines "309-334"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgLinks" :range-end "-OrgLinks" :lines "396-421"
 
 *** TODO Litterate programming
 :PROPERTIES:
 :CUSTOM_ID: h:b5f6beba-6195-4ff0-a194-502ac2a9e3da
 :END:
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgBabel" :range-end "-OrgBabel" :lines "337-345"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgBabel" :range-end "-OrgBabel" :lines "424-432"
 
 *** TODO Exporting
 :PROPERTIES:
 :CUSTOM_ID: h:afad00e0-367c-4c7b-b191-e3ed72be754b
 :END:
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgExportConstants" :range-end "-OrgExportConstants" :lines "348-350"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgExportConstants" :range-end "-OrgExportConstants" :lines "435-437"
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgExportCfg" :range-end "-OrgExportCfg" :lines "353-364"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgExportCfg" :range-end "-OrgExportCfg" :lines "440-451"
 
 ** TODO Email and newsgroup
 :PROPERTIES: