[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).
This commit is contained in:
Daniel - 2018-11-03 10:28:49 +01:00
parent 9f00c24c28
commit 00934a6bec
Signed by: dbo
GPG Key ID: 4F63DB96D45AA9C6
2 changed files with 52 additions and 46 deletions

51
init.el
View File

@ -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

View File

@ -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