emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cascading Org-Capture templates


From: Christophe Schockaert
Subject: Cascading Org-Capture templates
Date: Sat, 16 Apr 2022 23:44:26 +0200

Hi Org Fellows,


I am revisiting my Org workflow, and I feel like that in order to make it the way I wish, I need to cascade capture templates.
And after trying several approaches, I am not able to make it work.

I know about the "don’t use every extra Org features", but this is what I came with, and how I like it :)

So, these are the two things I want to achieve :

1) In an Org file, capture a new entry and clock it, this entry being a link to a new Org-Roam note

2) In an Org Journal file (org-journal), capture a new timestamp entry, which is a link to a newly captured entry in an Org file


I first tried the first case, but I am stuck with the "Org Roam capture within the Org Capture", so I tried to figure out if I could make the "Org Capture within Org Capture" of the second case work, but without any success eventhough I am not far I think.

In order to do this, I wrote this :

(defun lisp/cascading-capture ()
  (let* ((title "Cascading capture Heading"))
    (with-temp-buffer (org-capture nil "gc"))
    title))

(defun lisp/link-new-roam-log ()
  (let* ((title "Note title from Heading")
         (node (org-roam-node-create :title title)))
    (org-roam-capture-
     :node node
     :props '(:immediate-finish t)
     :templates '(("d" "default" plain "%?"
:target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
                   :unnarrowed t)))
    (org-link-make-string (concat "id:" (org-roam-node-id node))
                          title)))

(setq org-capture-templates
      '(("g" "Org – GTD")
("gM" "Mails test-cascade" entry (file+olp+datetree cfg/org-gtd-inbox-file "Incoming") "* %U %i%? %(lisp/cascading-capture) :MAILS:\n** Réf. %a" :tree-type week)
        ("gL" "Log (new roam note - test)" ; Track progress of selected task
entry (function org-back-to-heading-or-point-min) ; Create entry at beginning of current heading
         "* LOG lisp/link-new-roam-log\n%i%?"
         :immediate-finish t)))


So, "gM" is related to the second case (2), and I end up with the following error : "Capture abort: Buffer is read-only: #<buffer *doom*". As you see, I am using Doom Emacs, but I think it’s related with what I am trying to do anyway.

I thought I was close because when I am calling (with-temp-buffer (org-capture nil "gc")) directly, it indeed creates the note. When I didn’t use the (with-temp-buffer), the capture went into a sort of loop, and after aborting with C-g, I got the content of the active buffer in the Capture template, so I tried with that.

For the first case (1) with "gL", I started with a call to (org-roam-insert), and I used (with-temp-buffer ... (buffer-string)) to get the link. It worked fine when I called the lisp/link-new-roam-log directly, but I couldn’t make it work within the Capture Template, so I tried to split things as written there, then I decided to explore case (2) as I need to go through cascading Org Capture anyway.

To me, this goes to the internals of Emacs, and how things work together, and this is beyond my understanding of the whole picture for now :) Maybe, there is also another way to achieve that goal, which I don’t think about.


I would be grateful if you have any hints or solution to solve this :)

Christophe S.

--
--------------->  https://www.citadels.earth
Once it's perfectly aimed, the flying arrow goes straight to its target.
Thus, don't worry when things go right.
There will be enough time to worry about if they go wrong.
Then, it's time to fire a new arrow towards another direction.
Don't sink.  Adapt yourself !  The archer has to shoot accurately and
quickly.
[Words of Erenthar, the bowman ranger] <---------------<<<<



reply via email to

[Prev in Thread] Current Thread [Next in Thread]