emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Cascading Org-Capture templates
@ 2022-04-16 21:44 Christophe Schockaert
  2022-04-17  8:48 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe Schockaert @ 2022-04-16 21:44 UTC (permalink / raw)
  To: Emacs Orgmode

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] <---------------<<<<


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Cascading Org-Capture templates
  2022-04-16 21:44 Cascading Org-Capture templates Christophe Schockaert
@ 2022-04-17  8:48 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2022-04-17  8:48 UTC (permalink / raw)
  To: Christophe Schockaert; +Cc: Emacs Orgmode

Christophe Schockaert <R3vLibre@citadels.eu> writes:

> ...
> 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.
> ...
> 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.

An important thing you need to know about org-capture is that it is
using a global capture state. If you call capture inside capture,
unexpected things are going to happen because the recursive call will
modify current capture data.

I would try to save the value `org-capture-plist' in
lisp/cascading-capture and restore it after calling recursive capture.

Best,
Ihor


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-17  8:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-16 21:44 Cascading Org-Capture templates Christophe Schockaert
2022-04-17  8:48 ` Ihor Radchenko

Code repositories for project(s) associated with this 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).