Insert checklists at end of subtrees, before possible children

This commit is contained in:
Daniel Borchmann 2023-03-19 13:00:23 +01:00
parent a01bbe28e7
commit efa55cb75d
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625

View File

@ -878,6 +878,9 @@ determined."
(defun db/org-insert-checklist (arg) (defun db/org-insert-checklist (arg)
"Insert checklist for Org Mode item at point. "Insert checklist for Org Mode item at point.
Checklists are inserted before the first child, if existent, or
at the end of the subtree.
The checklist consists of a listing of relevant backlinks of the The checklist consists of a listing of relevant backlinks of the
current item and its parents (without archives) as well as a current item and its parents (without archives) as well as a
template. template.
@ -931,9 +934,19 @@ inserting the checklist."
;; point. ;; point.
(db/org-goto-checklist-item-of-point)) (db/org-goto-checklist-item-of-point))
(t (t ;; Default action: insert complete checklist.
;; Default action: insert complete checklist. Start with inserting
;; relevant backlinks, when available. ;; Checklists are inserted directly before first child, if existent, or
;; at end of subtree
(org-show-subtree)
(or (org-goto-first-child)
(org-end-of-subtree 'invisible-ok 'to-heading))
;; Move back from heading, unless we are at the end of the buffer
(when (org-at-heading-p)
;; Go to end of line before heading
(forward-char -1))
;; Insert relevant backlinks, when available.
(let ((parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil) (let ((parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
(string-to-number it))) (string-to-number it)))
number-of-backlinks number-of-backlinks
@ -976,7 +989,7 @@ inserting the checklist."
(let ((template-marker (db/org--find-template))) (let ((template-marker (db/org--find-template)))
(insert "\n\nTemplate:") (insert "\n\nTemplate:")
(if (not template-marker) (if (not template-marker)
(insert " none.") (insert " none.\n")
(db/org-copy-body-from-item-to-point template-marker)))))) (db/org-copy-body-from-item-to-point template-marker))))))
(define-obsolete-function-alias 'db/org-copy-template (define-obsolete-function-alias 'db/org-copy-template