;; Use ID for storing links (setq org-link-to-org-use-id t) ;; trigger a capture on done (add-hook 'org-after-todo-state-change-hook 'my-todo-state-change-hook) ;; DONE on a todo item triggers a capture rule "x" (defun my-todo-state-change-hook () "" (when (member state org-done-keywords) (org-capture-setup "x"))) ;; org-capture-templates ;; Rule-x does this ;; - creates an entry in conversation.org ;; - saves a link to the parent TODO entry in the new conversation node ;; - exits with a call to my-update-todo-node defun (setq org-capture-templates '(("x" "Create conversation node" entry (file+headline "~/conversation.org" "Conversations") "** Conversation-%(int-to-string (random))\n TODO Context: %a\n %?" :prepend t :empty-lines 1 :exit (my-update-todo-node)))) ;; my-update-todo-node does this ;; - visits the last captured node (ie, the conversation node) ;; - installs a makeshift capture rule and invokes it ;; ;; makeshift capture rule installs a link to the newly created ;; conversation node in the todo node. (defun my-update-todo-node () (when (not org-note-abort) (let (org-capture-templates) (with-current-buffer (marker-buffer org-capture-last-stored-marker) (save-excursion (goto-char (marker-position org-capture-last-stored-marker)) (setq org-capture-templates `(("*" "Makeshift" plain (id ,(my-id-from-id-link (org-capture-get :annotation))) " %a %U\n %?"))) (org-capture nil "*")))))) ;; this is a library routine used by makeshift capture rule (defun my-id-from-id-link (id-link) "" (let (link type path) (when (string-match org-bracket-link-regexp id-link) (setq link (match-string-no-properties 1 id-link))) (when (and link (string-match org-link-re-with-space3 link)) (setq type (match-string 1 link) path (match-string 2 link))) path)) ;; (setq hyperlink "[[id:1766a3bb-d717-4779-ac33-98510ada95aa][Conversations]]")