From 768abdb2b3316fd07628a5e65d7343077ba89e95 Mon Sep 17 00:00:00 2001 From: Blake Romero Date: Sun, 19 Oct 2025 02:18:14 +0100 Subject: Add dynamic datetree capture for planner --- emacs-config.org | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'emacs-config.org') diff --git a/emacs-config.org b/emacs-config.org index 5f36861..f424eee 100644 --- a/emacs-config.org +++ b/emacs-config.org @@ -1320,16 +1320,34 @@ Personal capture templates. :empty-lines-after 1) org-capture-templates) + (defun +find-or-create-datetree-heading (heading) + "Find HEADING within datetree structure and create it if it doesn't exist. + This prevents duplicate headings when inserting under a datetree via the + file+function target in `org-capture-templates'." + (org-datetree-find-date-create + (org-date-to-gregorian (org-today)) t) + (unless (re-search-forward (concat "^\\*.+ " heading) nil t) + (end-of-buffer) + (delete-blank-lines) + (insert (format "**** %s" heading)))) + (cl-pushnew '("pp" "Plan Today" checkitem - (file+olp+datetree "agenda/planner.org") - nil - :empty-lines-after 1 - :jump-to-captured t) + (file+function "agenda/planner.org" + (lambda () (+find-or-create-datetree-heading "Plan"))) + nil :empty-lines-after 1) + org-capture-templates) + + (cl-pushnew + '("pn" "Planner Note" plain + (file+function "agenda/planner.org" + (lambda () (+find-or-create-datetree-heading "Note"))) + nil :empty-lines-after 1) org-capture-templates) (cl-pushnew - '("pn" "Note" entry (file "notes/notes.org") + '("pN" "Note" entry + (file "notes/notes.org") <> :empty-lines-after 1) org-capture-templates) -- cgit