From 00934a6beca726283a3fc34dae6a60ecbb096326 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 3 Nov 2018 10:28:49 +0100 Subject: [PATCH] [Org] Move helper functions back to db-org New approach: all custom helper functions go to db-org, and all actual configuration will move to init.el (someday). --- init.el | 51 +++++---------------------------------------- site-lisp/db-org.el | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/init.el b/init.el index a99d2dd..1c0b433 100644 --- a/init.el +++ b/init.el @@ -647,6 +647,11 @@ _h_ _l_ _o_k _y_ank ;; * Org +(use-package db-org + :commands (db/find-parent-task + db/ensure-running-clock + db/org-current-task)) + (use-package org :commands (org-agenda org-capture @@ -685,55 +690,9 @@ _h_ _l_ _o_k _y_ank :group 'personal-settings :type 'string) -;; Helper Functions for Clocking - -(defun db/find-parent-task () - ;; http://doc.norang.ca/org-mode.html#Clocking - "Return point of the nearest parent task, and NIL if no such task exists." - (save-mark-and-excursion - (save-restriction - (widen) - (let ((parent-task nil)) - (or (org-at-heading-p) - (org-back-to-heading t)) - (while (and (not parent-task) - (org-up-heading-safe)) - (let ((tags (nth 5 (org-heading-components)))) - (unless (and tags (member "NOP" (split-string tags ":" t))) - (setq parent-task (point))))) - parent-task)))) - -(defun db/ensure-running-clock () - "Clocks in into the parent task, if it exists, or the default task." - (when (and (not org-clock-clocking-in) - (not org-clock-resolving-clocks-due-to-idleness)) - (let ((parent-task (db/find-parent-task))) - (save-mark-and-excursion - (cond - (parent-task - ;; found parent task - (org-with-point-at parent-task - (org-clock-in))) - ((and (markerp org-clock-default-task) - (marker-buffer org-clock-default-task)) - ;; default task is set - (org-with-point-at org-clock-default-task - (org-clock-in))) - (t - (org-clock-in '(4)))))))) - (defvar db/org-clock-current-task-file "~/.org-current-task") -(defun db/org-current-task () - "Format currently clocked task and write it to -`db/org-clock-current-task-file'." - (with-temp-file db/org-clock-current-task-file - (let ((clock-buffer (marker-buffer org-clock-marker))) - (if (null clock-buffer) - (insert "No running clock") - (insert org-clock-heading))))) - (use-package org-clock :init (setq org-clock-history-length 23 org-clock-in-resume t diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index af44af4..832a0aa 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -621,6 +621,53 @@ In ~%s~: (add-hook 'org-after-todo-state-change-hook 'org-reset-checkbox-state-maybe) + +;; Helper Functions for Clocking + +(defun db/find-parent-task () + ;; http://doc.norang.ca/org-mode.html#Clocking + "Return point of the nearest parent task, and NIL if no such task exists." + (save-mark-and-excursion + (save-restriction + (widen) + (let ((parent-task nil)) + (or (org-at-heading-p) + (org-back-to-heading t)) + (while (and (not parent-task) + (org-up-heading-safe)) + (let ((tags (nth 5 (org-heading-components)))) + (unless (and tags (member "NOP" (split-string tags ":" t))) + (setq parent-task (point))))) + parent-task)))) + +(defun db/ensure-running-clock () + "Clocks in into the parent task, if it exists, or the default task." + (when (and (not org-clock-clocking-in) + (not org-clock-resolving-clocks-due-to-idleness)) + (let ((parent-task (db/find-parent-task))) + (save-mark-and-excursion + (cond + (parent-task + ;; found parent task + (org-with-point-at parent-task + (org-clock-in))) + ((and (markerp org-clock-default-task) + (marker-buffer org-clock-default-task)) + ;; default task is set + (org-with-point-at org-clock-default-task + (org-clock-in))) + (t + (org-clock-in '(4)))))))) + +(defun db/org-current-task () + "Format currently clocked task and write it to +`db/org-clock-current-task-file'." + (with-temp-file db/org-clock-current-task-file + (let ((clock-buffer (marker-buffer org-clock-marker))) + (if (null clock-buffer) + (insert "No running clock") + (insert org-clock-heading))))) + ;;; Fixes