emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christophe Schockaert <R3vLibre@citadels.eu>
To: Emacs Orgmode <emacs-orgmode@gnu.org>
Subject: Cascading Org-Capture templates
Date: Sat, 16 Apr 2022 23:44:26 +0200	[thread overview]
Message-ID: <1add5505fd7731fb5feeda5806e98d7a@citadels.eu> (raw)

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	other threads:[~2022-04-16 21:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-16 21:44 Christophe Schockaert [this message]
2022-04-17  8:48 ` Cascading Org-Capture templates Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1add5505fd7731fb5feeda5806e98d7a@citadels.eu \
    --to=r3vlibre@citadels.eu \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).