Support ~org-roam~ recipes based on tempel

Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
Magic_RB 2023-09-16 19:33:11 +02:00
parent ca4d125b23
commit 07ffaccb58

View file

@ -47,25 +47,78 @@ So the process for capturing is to trigger the capture with ~C-c o c~ and then q
"${body}")
:target (file+olp "inbox.org" ("Shopping list")))))
(defun org-roam-tempel-recipe ()
"."
(setq-local org-roam-node org-roam-capture--node)
(org-entry-delete nil "ID")
(tempel-insert
'(":PROPERTIES:" n
":CREATED: " (org-capture-fill-template "%U")
":ID: " (org-roam-node-id org-roam-node) n
":servings: " p n
":prep-time: " (s prep-time) " m" n
":cook-time: " (s cook-time) " m" n
":ready-in: " (when-let ((prep (and prep-time (string-to-number prep-time)))
(cook (and cook-time (string-to-number cook-time))))
(number-to-string (+ prep cook))) " m" n
":END:" n
"#+title: " (org-roam-node-title org-roam-node) n
"#+filetags: :recipe:" n
"* Ingredients" n
" - " r n
"* Directions" n
" - " n)))
(defun org-roam-tempel-web-resource ()
"."
(setq-local org-roam-node org-roam-capture--node)
(org-entry-delete nil "ID")
(tempel-insert
'(":PROPERTIES:" n
":CREATED: " (org-capture-fill-template "%U") n
":ID: " (org-roam-node-id org-roam-node) n
":ROAM_REFS: " (completing-read \"URL for resource: \" nil nil nil nil nil (or (substring-no-properties (car kill-ring)) nil)) n
":END:" n
"#+title: " (org-roam-node-title org-roam-node) n
"#+filetags: :resource:" n n)))
(defun org-roam-tempel-node (standalone)
"."
(setq-local org-roam-node org-roam-capture--node)
(org-entry-delete nil "ID")
(tempel-insert
`(,@(unless standalone '("* ${title} :inbox:" n))
":PROPERTIES:" n
":ID: " (org-roam-node-id org-roam-node) n
":CREATED: " (org-capture-fill-template "%U")
":END:" n
"#+setupfile: ~/roam/emacs-lisp/setupfiles/latex-base.org" n
,@(when standalone '("#+title: " (org-roam-node-title org-roam-node) n)) n
)))
(defun org-roam-tempel-task ()
"."
(setq-local org-roam-node org-roam-capture--node)
(setf (org-roam-node-id org-roam-node) (org-id-uuid))
(tempel-insert
`(":PROPERTIES:" n
":CREATED: " (org-capture-fill-template "%U")
":ID: " (org-roam-node-id org-roam-node) n
":Effort: " p n
":END:" n
)))
(setq org-roam-capture-templates
`(("i" "Inbox" entry
,(concat "* ${title} :inbox:\n"
":PROPERTIES:\n"
":CREATED: %U\n"
":ID: %(org-id-uuid)\n"
":END:\n"
"#+setupfile: ~/roam/emacs-lisp/setupfiles/latex-base.org\n\n"
"%?")
:target (file+olp "inbox.org" ("Shopping list")))
("f" "File" plain "%?"
:target (file+head "${slug}.org"
,(concat ":PROPERTIES:\n"
":CREATED: %U\n"
":ID: %(org-id-uuid)\n"
":END:\n"
"#+setupfile: ~/roam/emacs-lisp/setupfiles/latex-base.org\n\n"
"#+title: ${title}\n"
"")))
"%?"
:target (file+olp "inbox.org" ("Shopping list"))
:hook (lambda () (org-roam-tempel-node nil)))
("f" "File" plain
"%?"
:target (file "${slug}.org")
:hook (lambda () (org-roam-tempel-node t)))
("@" "Inbox [mu4e]" entry
,(concat "* Process \"%a\" %? :inbox:\n"
":PROPERTIES:\n"
@ -74,23 +127,26 @@ So the process for capturing is to trigger the capture with ~C-c o c~ and then q
":END:\n\n"
"%?")
:target (file+olp "inbox.org" ("All")))
("t" "TODO" entry
,(concat "* TODO ${title} :inbox:\n"
":PROPERTIES:\n"
":CREATED: %U\n"
":ID: %(org-id-uuid)\n"
":END:\n\n"
("t" "Task" entry
,(concat "* TODO ${title}\n"
"%?")
:target (file+olp "inbox.org" ("Todo")))
:target (file "tasks.org")
:empty-lines 1
:hook org-roam-tempel-task)
("r" "Resource")
("rw" "Web resource" entry
,(concat "* ${title} :resource:inbox:\n"
":PROPERTIES:\n"
":CREATED: %U\n"
":ROAM_REFS: %(completing-read \"URL for resource: \" nil nil nil nil nil (or (substring-no-properties (car kill-ring)) nil))\n"
":ID: %(org-id-uuid)\n"
":END:\n\n")
:target (file+olp "inbox.org" ("Resources" "Web")))
("rw" "Web resource" plain
"%?"
:target (file "web-${slug}.org")
:hook org-roam-tempel-web-resource)
("rr" "Recipe" plain
"%?"
:target (file "recipe-${slug}.org")
:hook org-roam-tempel-recipe)
("E" "Event" entry
,(concat "* ${title} :event:inbox:\n"
":PROPERTIES:\n"
@ -237,37 +293,23 @@ Now the fun part. I only define one unified agenda view for now. It allows
(setq org-agenda-custom-commands
'(("g" "Get Things Done (GTD)"
((agenda ""
((org-agenda-skip-function
'(org-agenda-skip-entry-if 'deadline))
(org-deadline-warning-days 0)))
(todo "INPROGRESS"
((org-agenda-skip-function
'(org-agenda-skip-entry-if 'deadline))
(org-agenda-prefix-format " %i %-12:c [%e] ")
(org-agenda-overriding-header "\nTasks started\n")))
(todo "NEXT"
((org-agenda-skip-function
'(org-agenda-skip-entry-if 'deadline))
(org-agenda-prefix-format " %i %-12:c [%e] ")
(org-agenda-overriding-header "\nTasks planned\n")))
(agenda nil
((org-agenda-entry-types '(:deadline))
(org-agenda-format-date "")
(org-deadline-warning-days 21)
(org-agenda-skip-function
'(org-agenda-skip-entry-if 'notregexp "\\* NEXT"))
(org-agenda-overriding-header "\nDeadlines")))
(todo "TODO"
((org-agenda-prefix-format " %?-12t% s")
(org-agenda-skip-function
'(my/org-agenda-skip-without-match "-inbox"))
(org-agenda-overriding-header "\nTo be done\n")))
(tags "inbox"
((org-agenda-prefix-format " %?-12t% s")
(org-agenda-overriding-header "\nInbox\n")))
(tags "CLOSED>=\"<today>\""
((org-agenda-overriding-header "\nCompleted today\n")))))))
((agenda "")
(org-ql-block '(and (todo "INPROGRESS")
(not (deadline)))
((org-ql-block-header "Tasks Started")))
(org-ql-block '(and (todo "NEXT")
(not (deadline)))
((org-ql-block-header "Tasks Planned")))
(org-ql-block '(and (deadline "21d")
(not (or (todo "NEXT") (todo "CANCELLED") (todo "DONE"))))
((org-ql-block-header "Deadlines")))
(org-ql-block '(and (todo "TODO")
(not (deadline)))
((org-ql-block-header "To be Done")))
(org-ql-block '(and (tags "inbox"))
((org-ql-block-header "Inbox")))
(org-ql-block '(and (or (todo "CANCELLED") (todo "DONE")) (closed :on today))
((org-ql-block-header "Completed today")))))))
#+END_SRC
** Keybindings
@ -292,3 +334,11 @@ Now the fun part. I only define one unified agenda view for now. It allows
:keymaps '(mu4e-headers-mode-map mu4e-view-mode-map)
"C-c i" 'org-capture-mail)
#+end_src
** Org QL
#+begin_src emacs-lisp
(use-package org-ql
:straight (org-ql :fetcher github :repo "alphapapa/org-ql"
:files (:defaults (:exclude "helm-org-ql.el"))))
#+end_src